package com.fjhx.purchase.service.pay.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.fjhx.common.constant.SourceConstant;
import com.fjhx.purchase.entity.pay.po.PayDetail;
import com.fjhx.purchase.mapper.pay.PayDetailMapper;
import com.fjhx.purchase.service.pay.PayDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.purchase.entity.pay.vo.PayDetailVo;
import com.fjhx.purchase.entity.pay.dto.PayDetailSelectDto;
import com.ruoyi.common.utils.wrapper.IWrapper;
import com.fjhx.purchase.entity.pay.dto.PayDetailDto;
import cn.hutool.core.bean.BeanUtil;

import java.util.List;


/**
 * <p>
 * 采购付款明细 服务实现类
 * </p>
 *
 * @author 
 * @since 2023-04-13
 */
@Service
public class PayDetailServiceImpl extends ServiceImpl<PayDetailMapper, PayDetail> implements PayDetailService {

    @Override
    public Page<PayDetailVo> getPage(PayDetailSelectDto dto) {
        IWrapper<PayDetail> wrapper = getWrapper();
        wrapper.orderByDesc("pd", PayDetail::getId);
        Page<PayDetailVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
        return page;
    }

    @Override
    public PayDetailVo detail(Long id) {
        PayDetail PayDetail = this.getById(id);
        PayDetailVo result = BeanUtil.toBean(PayDetail, PayDetailVo.class);
        return result;
    }

    @Override
    public void add(PayDetailDto payDetailDto) {
        this.save(payDetailDto);
    }

    @Override
    public void edit(PayDetailDto payDetailDto) {
        this.updateById(payDetailDto);
    }

    @Override
    public void delete(Long id) {
        this.removeById(id);
    }

    /**
     * 付款
     * @param purchaseIds
     * @return
     */
    @Override
    public List<PayDetailVo> getSumMoneyByPurchaseIds(List<Long> purchaseIds) {
        return baseMapper.getSumMoneyByPurchaseIds(purchaseIds);
    }

}
