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

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fjhx.common.utils.Assert;
import com.fjhx.item.service.product.ProductInfoService;
import com.fjhx.sale.entity.contract.dto.ContractProductBomDto;
import com.fjhx.sale.entity.contract.po.ContractProductBom;
import com.fjhx.sale.entity.contract.vo.ContractProductBomVo;
import com.fjhx.sale.mapper.contract.ContractProductBomMapper;
import com.fjhx.sale.service.contract.ContractProductBomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * <p>
 * 合同产品BOM 服务实现类
 * </p>
 *
 * @author
 * @since 2024-01-17
 */
@Service
public class ContractProductBomServiceImpl extends ServiceImpl<ContractProductBomMapper, ContractProductBom> implements ContractProductBomService {

    @Autowired
    private ProductInfoService productInfoService;

    @Override
    public List<ContractProductBomVo> getList(ContractProductBomDto dto) {
        Assert.notEmpty(dto.getContractId(), "合同id不能为空");
        List<ContractProductBomVo> contractProductBomVoList = baseMapper.getContractProductBomQuantitySum(dto.getContractId());

        //赋值产品信息
        productInfoService.attributeAssign(contractProductBomVoList, ContractProductBomVo::getMaterialId, (item, material) -> {
            item.setProductCode(material.getCustomCode());
            item.setProductName(material.getName());
        });

        return contractProductBomVoList;
    }

    @Override
    public List<ContractProductBomVo> getContractProductBomQuantitySum(Long contractId) {
        List<ContractProductBomVo> contractProductBomQuantitySum = baseMapper.getContractProductBomQuantitySum(contractId);
        return contractProductBomQuantitySum;
    }

}
