package com.fjhx.sale.service.contract.impl;

import com.fjhx.sale.entity.contract.po.ContractInvoiceDetails;
import com.fjhx.sale.mapper.contract.ContractInvoiceDetailsMapper;
import com.fjhx.sale.service.contract.ContractInvoiceDetailsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.sale.entity.contract.vo.ContractInvoiceDetailsVo;
import com.fjhx.sale.entity.contract.dto.ContractInvoiceDetailsSelectDto;
import com.ruoyi.common.utils.wrapper.IWrapper;
import com.fjhx.sale.entity.contract.dto.ContractInvoiceDetailsDto;
import cn.hutool.core.bean.BeanUtil;

import java.util.List;


/**
 * <p>
 * 合同发票明细 服务实现类
 * </p>
 *
 * @author
 * @since 2023-09-08
 */
@Service
public class ContractInvoiceDetailsServiceImpl extends ServiceImpl<ContractInvoiceDetailsMapper, ContractInvoiceDetails> implements ContractInvoiceDetailsService {

    @Override
    public Page<ContractInvoiceDetailsVo> getPage(ContractInvoiceDetailsSelectDto dto) {
        IWrapper<ContractInvoiceDetails> wrapper = getWrapper();
        wrapper.orderByDesc("cid", ContractInvoiceDetails::getId);
        Page<ContractInvoiceDetailsVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
        return page;
    }

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

    @Override
    public void add(ContractInvoiceDetailsDto contractInvoiceDetailsDto) {
        this.save(contractInvoiceDetailsDto);
    }

    @Override
    public void edit(ContractInvoiceDetailsDto contractInvoiceDetailsDto) {
        this.updateById(contractInvoiceDetailsDto);
    }

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

    /**
     * 根据发票查询明细
     *
     * @param invoiceId
     * @return
     */
    @Override
    public List<ContractInvoiceDetailsVo> getDetail(Long invoiceId) {
        return baseMapper.getDetail(invoiceId);
    }

    /**
     * getSumMoneyByContractIds
     *
     * @param contractIds
     * @return
     */
    @Override
    public List<ContractInvoiceDetailsVo> getSumMoneyByContractIds(List<Long> contractIds) {
        return baseMapper.getSumMoneyByContractIds(contractIds);
    }

}
