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

import cn.bunny.dao.dto.financial.debtTracking.DebtTrackingAddDto;
import cn.bunny.dao.dto.financial.debtTracking.DebtTrackingDto;
import cn.bunny.dao.dto.financial.debtTracking.DebtTrackingUpdateDto;
import cn.bunny.dao.entity.financial.DebtTracking;
import cn.bunny.dao.pojo.result.PageResult;
import cn.bunny.dao.vo.financial.admin.DebtTrackingVo;
import cn.bunny.services.mapper.financial.DebtTrackingMapper;
import cn.bunny.services.service.financial.DebtTrackingService;
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:36:31
 */
@Service
public class DebtTrackingServiceImpl extends ServiceImpl<DebtTrackingMapper, DebtTracking> implements DebtTrackingService {

    /**
     * * 债务追踪 服务实现类
     *
     * @param pageParams 债务追踪分页查询page对象
     * @param dto        债务追踪分页查询对象
     * @return 查询分页债务追踪返回对象
     */
    @Override
    public PageResult<DebtTrackingVo> getDebtTrackingList(Page<DebtTracking> pageParams, DebtTrackingDto dto) {
        IPage<DebtTrackingVo> page = baseMapper.selectListByPage(pageParams, dto);

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

    /**
     * 添加债务追踪
     *
     * @param dto 债务追踪添加
     */
    @Override
    public void addDebtTracking(@Valid DebtTrackingAddDto dto) {
        // 保存数据
        DebtTracking debtTracking = new DebtTracking();
        BeanUtils.copyProperties(dto, debtTracking);
        save(debtTracking);
    }

    /**
     * 更新债务追踪
     *
     * @param dto 债务追踪更新
     */
    @Override
    public void updateDebtTracking(@Valid DebtTrackingUpdateDto dto) {
        // 更新内容
        DebtTracking debtTracking = new DebtTracking();
        BeanUtils.copyProperties(dto, debtTracking);
        updateById(debtTracking);
    }

    /**
     * 删除|批量删除债务追踪
     *
     * @param ids 删除id列表
     */
    @Override
    public void deleteDebtTracking(List<Long> ids) {
        baseMapper.deleteBatchIdsWithPhysics(ids);
    }
}
