|
@@ -1,5 +1,6 @@
|
|
|
package com.fjhx.sale.flow;
|
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
@@ -12,13 +13,17 @@ import com.fjhx.file.utils.ObsFileUtil;
|
|
|
import com.fjhx.flow.core.FlowDelegate;
|
|
|
import com.fjhx.flow.enums.FlowStatusEnum;
|
|
|
import com.fjhx.purchase.entity.purchase.enums.PurchaseStatusEnum;
|
|
|
+import com.fjhx.purchase.entity.subscribe.po.SubscribeDetail;
|
|
|
+import com.fjhx.purchase.service.subscribe.SubscribeDetailService;
|
|
|
import com.fjhx.sale.entity.contract.dto.ContractDto;
|
|
|
import com.fjhx.sale.entity.contract.dto.ContractProductDto;
|
|
|
import com.fjhx.sale.entity.contract.po.Contract;
|
|
|
import com.fjhx.sale.entity.contract.po.ContractProduct;
|
|
|
import com.fjhx.sale.entity.contract.po.ContractProductBom;
|
|
|
import com.fjhx.sale.entity.contract.po.ContractProject;
|
|
|
+import com.fjhx.sale.entity.purchase.vo.EhsdPurchaseProductVo;
|
|
|
import com.fjhx.sale.mapper.contract.ContractMapper;
|
|
|
+import com.fjhx.sale.mapper.purchase.EhsdPurchaseProductMapper;
|
|
|
import com.fjhx.sale.service.contract.ContractProductBomService;
|
|
|
import com.fjhx.sale.service.contract.ContractProductService;
|
|
|
import com.fjhx.sale.service.contract.ContractProjectService;
|
|
@@ -29,9 +34,13 @@ import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -52,6 +61,10 @@ public class ContractUpdateFlow extends FlowDelegate {
|
|
|
private ContractProjectService contractProjectService;
|
|
|
@Autowired
|
|
|
private ContractMapper contractMapper;
|
|
|
+ @Resource
|
|
|
+ private SubscribeDetailService subscribeDetailService;
|
|
|
+ @Resource
|
|
|
+ private EhsdPurchaseProductMapper ehsdPurchaseProductMapper;
|
|
|
|
|
|
@Override
|
|
|
public String getFlowKey() {
|
|
@@ -154,6 +167,86 @@ public class ContractUpdateFlow extends FlowDelegate {
|
|
|
oldContract.setStatus(FlowStatusEnum1.UPDATE.getKey());
|
|
|
contractService.updateById(oldContract);
|
|
|
|
|
|
+ //如果是业务自采 更新待采购数据
|
|
|
+ if (ObjectUtil.equals(oldContract.getProcessingMethod(), 10)) {
|
|
|
+ List<SubscribeDetail> oldSubscribeDetailList = subscribeDetailService.list(q -> q
|
|
|
+ .eq(SubscribeDetail::getContractId, oldContractId)
|
|
|
+ );
|
|
|
+ Map<Long, SubscribeDetail> oldSubscribeMap = oldSubscribeDetailList.stream()
|
|
|
+ .collect(Collectors.toMap(SubscribeDetail::getProductId, Function.identity()));
|
|
|
+
|
|
|
+ List<EhsdPurchaseProductVo> oldPurchaseQuantityList = ehsdPurchaseProductMapper
|
|
|
+ .getPurchaseQuantitySumByContractId(oldContractId, oldContract.getOfCompanyId());
|
|
|
+ Map<Long, BigDecimal> oldPurchaseMap = oldPurchaseQuantityList.stream()
|
|
|
+ .collect(Collectors.toMap(EhsdPurchaseProductVo::getProductId, EhsdPurchaseProductVo::getQuantity));
|
|
|
+
|
|
|
+ //根据新合同处理数据
|
|
|
+ List<ContractProduct> newProductList = contractProductService.list(q -> q.eq(ContractProduct::getContractId, businessId));
|
|
|
+ //处理被删除的产品
|
|
|
+ List<Long> newProductIds = newProductList.stream().map(ContractProduct::getProductId).collect(Collectors.toList());
|
|
|
+ List<SubscribeDetail> delSubscribeDetailList = oldSubscribeDetailList
|
|
|
+ .stream().filter(item -> !newProductIds.contains(item.getProductId())).collect(Collectors.toList());
|
|
|
+ for (SubscribeDetail subscribeDetail : delSubscribeDetailList) {
|
|
|
+ BigDecimal oldPurchaseQuantity = oldPurchaseMap.getOrDefault(subscribeDetail.getProductId(), BigDecimal.ZERO);
|
|
|
+ //采购数量为0直接删除
|
|
|
+ if (oldPurchaseQuantity.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ subscribeDetailService.removeById(subscribeDetail);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //直接修改为已采购数量并结束采购
|
|
|
+ if (subscribeDetail.getCount().compareTo(oldPurchaseQuantity) != 0) {
|
|
|
+ subscribeDetail.setCount(oldPurchaseQuantity);
|
|
|
+ subscribeDetail.setStatus(20);
|
|
|
+ subscribeDetailService.updateById(subscribeDetail);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //处理新数据
|
|
|
+ for (ContractProduct newProduct : newProductList) {
|
|
|
+ SubscribeDetail oldSubscribeDetail = oldSubscribeMap.get(newProduct.getProductId());
|
|
|
+
|
|
|
+ // 新合同不是自采的情况下
|
|
|
+ if (ObjectUtil.notEqual(newContract.getProcessingMethod(), 10) && ObjectUtil.isNotEmpty(oldSubscribeDetail)) {
|
|
|
+ BigDecimal oldPurchaseQuantity = oldPurchaseMap.getOrDefault(newProduct.getProductId(), BigDecimal.ZERO);
|
|
|
+ //直接修改为已采购数量并结束待采购
|
|
|
+ if (oldSubscribeDetail.getCount().compareTo(oldPurchaseQuantity) != 0) {
|
|
|
+ oldSubscribeDetail.setCount(oldPurchaseQuantity);
|
|
|
+ oldSubscribeDetail.setStatus(20);
|
|
|
+ subscribeDetailService.updateById(oldSubscribeDetail);
|
|
|
+ }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //新产品直接创建申购
|
|
|
+ BigDecimal newQuantity = newProduct.getQuantity();
|
|
|
+ if (ObjectUtil.isEmpty(oldSubscribeDetail)) {
|
|
|
+ SubscribeDetail newSubscribeDetail = new SubscribeDetail();
|
|
|
+ newSubscribeDetail.setContractId(newContract.getId());
|
|
|
+ newSubscribeDetail.setProductId(newProduct.getProductId());
|
|
|
+ newSubscribeDetail.setCount(newQuantity);
|
|
|
+ newSubscribeDetail.setStatus(15);//待采购
|
|
|
+ newSubscribeDetail.setDataType(1);
|
|
|
+ newSubscribeDetail.setCompanyId(newContract.getOfCompanyId());
|
|
|
+ subscribeDetailService.save(newSubscribeDetail);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //否则修改待采购数量
|
|
|
+ BigDecimal oldPurchaseQuantity = oldPurchaseMap.getOrDefault(newProduct.getProductId(), BigDecimal.ZERO);
|
|
|
+ if (newQuantity.compareTo(oldPurchaseQuantity) <= 0) {
|
|
|
+ //新数量<已采购
|
|
|
+ oldSubscribeDetail.setCount(oldPurchaseQuantity);
|
|
|
+ oldSubscribeDetail.setStatus(20);
|
|
|
+ } else {
|
|
|
+ oldSubscribeDetail.setCount(newQuantity);
|
|
|
+ oldSubscribeDetail.setStatus(15);
|
|
|
+ }
|
|
|
+ oldSubscribeDetail.setContractId(newContract.getId());
|
|
|
+ subscribeDetailService.updateById(oldSubscribeDetail);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //==============================================================================================================
|
|
|
+
|
|
|
//-----------------
|
|
|
//交换合同产品BOM中的合同id
|
|
|
List<ContractProductBom> oldCpbList = contractProductBomService.list(q -> q.eq(ContractProductBom::getContractId, oldContractId));
|