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

import cn.bunny.dao.dto.financial.debtRepaymentPlan.DebtRepaymentPlanAddDto;
import cn.bunny.dao.dto.financial.debtRepaymentPlan.DebtRepaymentPlanDto;
import cn.bunny.dao.dto.financial.debtRepaymentPlan.DebtRepaymentPlanUpdateDto;
import cn.bunny.dao.entity.financial.DebtRepaymentPlan;
import cn.bunny.dao.pojo.result.PageResult;
import cn.bunny.dao.vo.financial.admin.DebtRepaymentPlanVo;
import cn.bunny.services.mapper.financial.DebtRepaymentPlanMapper;
import cn.bunny.services.service.financial.DebtRepaymentPlanService;
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 14:59:53
 */
@Service
public class DebtRepaymentPlanServiceImpl extends ServiceImpl<DebtRepaymentPlanMapper, DebtRepaymentPlan> implements DebtRepaymentPlanService {

    /**
     * * 债务还款计划表 服务实现类
     *
     * @param pageParams 债务还款计划表分页查询page对象
     * @param dto        债务还款计划表分页查询对象
     * @return 查询分页债务还款计划表返回对象
     */
    @Override
    public PageResult<DebtRepaymentPlanVo> getDebtRepaymentPlanList(Page<DebtRepaymentPlan> pageParams, DebtRepaymentPlanDto dto) {
        IPage<DebtRepaymentPlanVo> page = baseMapper.selectListByPage(pageParams, dto);

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

    /**
     * 添加债务还款计划表
     *
     * @param dto 债务还款计划表添加
     */
    @Override
    public void addDebtRepaymentPlan(@Valid DebtRepaymentPlanAddDto dto) {
        // 保存数据
        DebtRepaymentPlan debtRepaymentPlan = new DebtRepaymentPlan();
        BeanUtils.copyProperties(dto, debtRepaymentPlan);
        save(debtRepaymentPlan);
    }

    /**
     * 更新债务还款计划表
     *
     * @param dto 债务还款计划表更新
     */
    @Override
    public void updateDebtRepaymentPlan(@Valid DebtRepaymentPlanUpdateDto dto) {
        // 更新内容
        DebtRepaymentPlan debtRepaymentPlan = new DebtRepaymentPlan();
        BeanUtils.copyProperties(dto, debtRepaymentPlan);
        updateById(debtRepaymentPlan);
    }

    /**
     * 删除|批量删除债务还款计划表
     *
     * @param ids 删除id列表
     */
    @Override
    public void deleteDebtRepaymentPlan(List<Long> ids) {
        baseMapper.deleteBatchIdsWithPhysics(ids);
    }
}
