|
@@ -0,0 +1,139 @@
|
|
|
+package com.fjhx.sale.service.quotation.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.common.utils.Assert;
|
|
|
+import com.fjhx.item.entity.product.ProcessesBo;
|
|
|
+import com.fjhx.item.entity.product.po.ProductInfo;
|
|
|
+import com.fjhx.item.service.product.ProductInfoService;
|
|
|
+import com.fjhx.sale.entity.quotation.dto.QuotationEstimateDto;
|
|
|
+import com.fjhx.sale.entity.quotation.po.QuotationEstimate;
|
|
|
+import com.fjhx.sale.entity.quotation.po.QuotationProduct;
|
|
|
+import com.fjhx.sale.entity.quotation.po.QuotationProductBom;
|
|
|
+import com.fjhx.sale.entity.quotation.vo.QuotationEstimateVo;
|
|
|
+import com.fjhx.sale.mapper.quotation.QuotationEstimateMapper;
|
|
|
+import com.fjhx.sale.service.quotation.QuotationEstimateService;
|
|
|
+import com.fjhx.sale.service.quotation.QuotationProductBomService;
|
|
|
+import com.fjhx.sale.service.quotation.QuotationProductService;
|
|
|
+import com.ruoyi.common.core.domain.BasePo;
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * <p>
|
|
|
+ * 报价评估 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author
|
|
|
+ * @since 2024-02-04
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class QuotationEstimateServiceImpl extends ServiceImpl<QuotationEstimateMapper, QuotationEstimate> implements QuotationEstimateService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private QuotationProductBomService quotationProductBomService;
|
|
|
+ @Autowired
|
|
|
+ private QuotationProductService quotationProductService;
|
|
|
+ @Autowired
|
|
|
+ private ProductInfoService productInfoService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<QuotationEstimateVo> detail(QuotationEstimateDto dto) {
|
|
|
+ Long quotationProductId = dto.getQuotationProductId();
|
|
|
+ Assert.notEmpty(quotationProductId, "报价明细id不能为空!");
|
|
|
+
|
|
|
+ QuotationProduct quotationProduct = quotationProductService.getById(quotationProductId);
|
|
|
+ Assert.notEmpty(quotationProduct, "查询不到报价明细信息!");
|
|
|
+
|
|
|
+
|
|
|
+ List<QuotationEstimate> quotationEstimateList = list(q -> q.eq(QuotationEstimate::getQuotationProductId, quotationProductId));
|
|
|
+ List<QuotationEstimateVo> quotationEstimateVos = BeanUtil.copyToList(quotationEstimateList, QuotationEstimateVo.class);
|
|
|
+
|
|
|
+
|
|
|
+ if (ObjectUtil.isEmpty(quotationEstimateVos)) {
|
|
|
+ quotationEstimateVos = new ArrayList<>();
|
|
|
+ List<QuotationProductBom> list1 = quotationProductBomService.list(q -> q.eq(QuotationProductBom::getQuotationProductId, quotationProductId));
|
|
|
+
|
|
|
+
|
|
|
+ for (QuotationProductBom quotationProductBom : list1) {
|
|
|
+ QuotationEstimateVo quotationEstimate = new QuotationEstimateVo();
|
|
|
+ quotationEstimate.setQuotationProductId(quotationProductBom.getQuotationProductId());
|
|
|
+ quotationEstimate.setProductId(quotationProductBom.getProductId());
|
|
|
+ quotationEstimate.setMaterialId(quotationProductBom.getMaterialId());
|
|
|
+ quotationEstimate.setType(quotationProductBom.getType());
|
|
|
+
|
|
|
+
|
|
|
+ if (ObjectUtil.notEqual(quotationProductBom.getType(), 1)) {
|
|
|
+ quotationEstimate.setQuantity(quotationProductBom.getQuantity());
|
|
|
+ }
|
|
|
+
|
|
|
+ quotationEstimateVos.add(quotationEstimate);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ productInfoService.attributeAssign(quotationEstimateVos, QuotationEstimateVo::getMaterialId, (detail, product) -> {
|
|
|
+ detail.setMaterialLength(product.getLength());
|
|
|
+ detail.setMaterialWidth(product.getWidth());
|
|
|
+ detail.setMaterialHeight(product.getHeight());
|
|
|
+ detail.setName(product.getName());
|
|
|
+ detail.setCode(product.getCode());
|
|
|
+ detail.setMaterialColor(product.getColor());
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ ProductInfo productInfo = productInfoService.getById(quotationProduct.getProductId());
|
|
|
+ Assert.notEmpty(productInfo, "查询不到工艺信息!");
|
|
|
+ List<ProcessesBo> processesList = productInfoService.getProcessesByTechnologyId(productInfo.getTechnologyId());
|
|
|
+ for (ProcessesBo processesBo : processesList) {
|
|
|
+ QuotationEstimateVo quotationEstimate = new QuotationEstimateVo();
|
|
|
+ quotationEstimate.setProcessesId(processesBo.getId());
|
|
|
+ quotationEstimate.setCode(processesBo.getCode());
|
|
|
+ quotationEstimate.setName(processesBo.getName());
|
|
|
+ quotationEstimate.setPrice(processesBo.getCostPrice());
|
|
|
+ quotationEstimate.setQuantity(BigDecimal.valueOf(1));
|
|
|
+ quotationEstimate.setType(3);
|
|
|
+
|
|
|
+ quotationEstimateVos.add(quotationEstimate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return quotationEstimateVos;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void addOrEdit(QuotationEstimateDto quotationEstimateDto) {
|
|
|
+ Long quotationProductId = quotationEstimateDto.getQuotationProductId();
|
|
|
+ Assert.notEmpty(quotationProductId, "报价明细id不能为空!");
|
|
|
+
|
|
|
+ QuotationProduct quotationProduct = quotationProductService.getById(quotationProductId);
|
|
|
+ Assert.notEmpty(quotationProduct, "查询不到报价明细信息!");
|
|
|
+
|
|
|
+ List<QuotationEstimate> quotationEstimateList = quotationEstimateDto.getQuotationEstimateList();
|
|
|
+
|
|
|
+
|
|
|
+ BigDecimal amount = quotationEstimateList.stream().map(QuotationEstimate::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal divide = amount.divide(quotationProduct.getQuantity(), 4, RoundingMode.HALF_UP);
|
|
|
+ quotationProductService.update(q -> q
|
|
|
+ .eq(QuotationProduct::getId, quotationProductId)
|
|
|
+ .set(QuotationProduct::getPrice, divide)
|
|
|
+ .set(BasePo::getUpdateTime, new Date())
|
|
|
+ .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
+ );
|
|
|
+
|
|
|
+ for (QuotationEstimate quotationEstimate : quotationEstimateList) {
|
|
|
+ quotationEstimate.setQuotationProductId(quotationProductId);
|
|
|
+ }
|
|
|
+ this.saveOrUpdateBatch(quotationEstimateList);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|