package cn.bunny.services.service.financial.impl;

import cn.bunny.dao.dto.financial.savingGoal.SavingGoalAddDto;
import cn.bunny.dao.dto.financial.savingGoal.SavingGoalDto;
import cn.bunny.dao.dto.financial.savingGoal.SavingGoalUpdateDto;
import cn.bunny.dao.entity.financial.SavingGoal;
import cn.bunny.dao.pojo.result.PageResult;
import cn.bunny.dao.vo.financial.admin.SavingGoalVo;
import cn.bunny.services.mapper.financial.SavingGoalMapper;
import cn.bunny.services.service.financial.SavingGoalService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.validation.Valid;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户储值 服务实现类
 * </p>
 *
 * @author Bunny
 * @since 2024-11-11 16:49:29
 */
@Service
public class SavingGoalServiceImpl extends ServiceImpl<SavingGoalMapper, SavingGoal> implements SavingGoalService {

    /**
     * * 用户储值 服务实现类
     *
     * @param pageParams 用户储值分页查询page对象
     * @param dto        用户储值分页查询对象
     * @return 查询分页用户储值返回对象
     */
    @Override
    public PageResult<SavingGoalVo> getSavingGoalList(Page<SavingGoal> pageParams, SavingGoalDto dto) {
        IPage<SavingGoalVo> page = baseMapper.selectListByPage(pageParams, dto);

        return PageResult.<SavingGoalVo>builder()
                .list(page.getRecords())
                .pageNo(page.getCurrent())
                .pageSize(page.getSize())
                .total(page.getTotal())
                .build();
    }

    /**
     * 添加用户储值
     *
     * @param dto 用户储值添加
     */
    @Override
    public void addSavingGoal(@Valid SavingGoalAddDto dto) {
        // 保存数据
        SavingGoal savingGoal = new SavingGoal();
        BeanUtils.copyProperties(dto, savingGoal);
        save(savingGoal);
    }

    /**
     * 更新用户储值
     *
     * @param dto 用户储值更新
     */
    @Override
    public void updateSavingGoal(@Valid SavingGoalUpdateDto dto) {
        // 更新内容
        SavingGoal savingGoal = new SavingGoal();
        BeanUtils.copyProperties(dto, savingGoal);
        updateById(savingGoal);
    }

    /**
     * 删除|批量删除用户储值
     *
     * @param ids 删除id列表
     */
    @Override
    public void deleteSavingGoal(List<Long> ids) {
        baseMapper.deleteBatchIdsWithPhysics(ids);
    }
}
