Quellcode durchsuchen

样品单、交接单变更逻辑更改

caozj vor 1 Jahr
Ursprung
Commit
c361cef9e8

+ 9 - 0
hx-sale/src/main/java/com/fjhx/sale/entity/sample/po/Sample.java

@@ -250,6 +250,15 @@ public class Sample extends BasePo {
      */
     private String effective;
 
+    /**
+     * 旧样品单ID
+     */
+    private Long oldSampleId;
+
+    /**
+     * 是否变更
+     */
+    private String isChange;
 
     /**
      * 交接单附件列表

+ 1 - 2
hx-sale/src/main/java/com/fjhx/sale/flow/ContractFlow.java

@@ -101,8 +101,7 @@ public class ContractFlow extends FlowDelegate {
         if (ObjectUtils.isEmpty(contract)) {
             throw new ServiceException("合同不存在");
         }
-
-        // 修改采购状态为审批通过
+        // 修改合同状态为审批通过
         contract.setStatus(FlowStatusEnum1.PASS.getKey());
         contract.setApprovedDate(new Date());
         contractService.updateById(contract);

+ 86 - 39
hx-sale/src/main/java/com/fjhx/sale/flow/ContractUpdateFlow.java

@@ -2,21 +2,31 @@ package com.fjhx.sale.flow;
 
 import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson2.JSON;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.fjhx.common.enums.FlowStatusEnum1;
 import com.fjhx.common.utils.Assert;
 import com.fjhx.flow.core.FlowDelegate;
+import com.fjhx.item.entity.product.po.ProductInfoEhsdJson;
 import com.fjhx.sale.entity.contract.dto.ContractDto;
 import com.fjhx.sale.entity.contract.po.Contract;
 import com.fjhx.sale.entity.contract.po.ContractProduct;
+import com.fjhx.sale.entity.contract.po.ContractProject;
+import com.fjhx.sale.entity.contract.po.ContractShipment;
 import com.fjhx.sale.service.contract.ContractProductService;
+import com.fjhx.sale.service.contract.ContractProjectService;
 import com.fjhx.sale.service.contract.ContractService;
+import com.fjhx.sale.service.contract.ContractShipmentService;
 import com.ruoyi.common.core.domain.BaseIdPo;
 import com.ruoyi.common.exception.ServiceException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.math.BigDecimal;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.function.Function;
@@ -39,6 +49,12 @@ public class ContractUpdateFlow extends FlowDelegate {
     @Autowired
     private ContractProductService contractProductService;
 
+    @Autowired
+    private ContractProjectService contractProjectService;
+
+    @Autowired
+    private ContractShipmentService contractShipmentService;
+
     @Override
     public String getFlowKey() {
         return "contract_update_flow";
@@ -61,10 +77,24 @@ public class ContractUpdateFlow extends FlowDelegate {
         if (oldContractId == null) {
             throw new ServiceException("原合同id不能为空");
         }
-
-        //变更 用原来合同号加后缀
+        //查询原合同
         Contract oldContract = contractService.getById(contract.getOldContractId());
-        Assert.notEmpty(oldContract, "查询不到原合同信息");
+        if(ObjectUtil.isEmpty(oldContract)){
+            throw new ServiceException("查询不到原合同信息");
+        }
+        //查询旧合同的订单产品
+        List<ContractProduct> oldContractProductList = contractProductService.list(q -> q.eq(ContractProduct::getContractId, oldContractId));
+        if(CollectionUtils.isEmpty(oldContractProductList)){
+            throw new ServiceException("原合同没有产品");
+        }
+        Map<Long,List<ContractProduct>> oldContractProductMap = oldContractProductList.stream().collect(Collectors.groupingBy(ContractProduct::getId));
+        List<ContractProduct> newContractProductList = contract.getContractProductList();
+        if(CollectionUtils.isEmpty(newContractProductList)){
+            throw new ServiceException("变更合同产品不能为空");
+        }
+        /**
+         * 赋值新的变更合同号
+         */
         String code = oldContract.getCode();
         Matcher matcher = Pattern.compile(".*\\((.*?)\\)$").matcher(code);
         int index = 2;
@@ -73,35 +103,32 @@ public class ContractUpdateFlow extends FlowDelegate {
             code = code.substring(0, code.lastIndexOf("("));
         }
         contract.setCode(code + "(" + index + ")");
-
-
-        List<ContractProduct> list = contractProductService.list(q -> q.eq(ContractProduct::getContractId, oldContractId));
-
-        // 赋值待处理数量
-        if (CollectionUtils.isNotEmpty(list)) {
-
-            List<ContractProduct> contractProductList = contract.getContractProductList();
-
-            if (ObjectUtil.isEmpty(contractProductList)) {
-                throw new ServiceException("没有合同产品");
-            }
-
-            Map<Long, ContractProduct> contractProductMap = contractProductList
-                    .stream()
-                    .filter(item -> ObjectUtil.isNotEmpty(item.getId()))
-                    .collect(Collectors.toMap(BaseIdPo::getId, Function.identity()));
-
-
-            for (ContractProduct item : list) {
-                ContractProduct contractProduct = contractProductMap.get(item.getId());
-                if (ObjectUtil.isNotEmpty(contractProduct)) {
-                    BigDecimal expendQuantity = item.getExpendQuantity().subtract(item.getQuantity().subtract(contractProduct.getQuantity()));
-                    contractProduct.setExpendQuantity(expendQuantity);
+        /**
+         * 计算新合同的剩余数量
+         */
+        for(ContractProduct newCp:newContractProductList){
+
+            if(ObjectUtil.isNotEmpty(newCp.getId())){//如果新合同产品ID不为空
+                //取出旧合同
+                ContractProduct oldContractProduct = oldContractProductMap.getOrDefault(newCp.getId(),null).get(0);
+                //取出旧合同包装方式
+                JSONObject oldJson = JSONObject.parseObject(oldContractProduct.getEhsdJson());
+                String oldPackMethod = oldJson.getOrDefault("packMethod",null)==null?null:oldJson.getOrDefault("packMethod",null).toString();
+                //取出新合同包装方式
+                JSONObject newJson = JSONObject.parseObject(newCp.getEhsdJson());
+                String newPackMethod = newJson.getOrDefault("packMethod",null)==null?null:oldJson.getOrDefault("packMethod",null).toString();
+                /**
+                 * 商品英文名、尺寸、包装方式、数量 没有变更---取原本的剩余数量
+                 */
+                if(oldContractProduct.getQuantity().compareTo(newCp.getQuantity())==0
+                        && StringUtils.equals(oldContractProduct.getProductName(), newCp.getProductName())
+                        && StringUtils.equals(oldContractProduct.getProductModel(),newCp.getProductModel())
+                        && StringUtils.equals(oldPackMethod,newPackMethod)){
+                    //取出旧的剩余数量
+                    newCp.setExpendQuantity(oldContractProduct.getExpendQuantity());
                 }
             }
-
         }
-
         return contractFlow.start(contract);
     }
 
@@ -114,21 +141,41 @@ public class ContractUpdateFlow extends FlowDelegate {
      */
     @Override
     public void end(Long flowId, Long businessId, JSONObject submitData) {
-
-        contractFlow.end(flowId, businessId, submitData);
-
-        // 通过业务id查询合同数据
-        Contract contract = contractService.getById(businessId);
-
-        // 原合同改为作废状态
-        Long oldContractId = contract.getOldContractId();
+        // 通过业务ID查询合同数据
+        Contract newContract = contractService.getById(businessId);
+        if (ObjectUtils.isEmpty(newContract)) {
+            throw new ServiceException("合同不存在");
+        }
+        long  oldContractId = newContract.getOldContractId();//取出旧的合同ID
         Contract oldContract = contractService.getById(oldContractId);
         if (oldContract == null) {
             throw new ServiceException("原合同不存在");
         }
+        /**
+         * 处理新合同---
+         */
+        newContract.setId(oldContractId);//id赋值为旧合同的id
+        newContract.setStatus(FlowStatusEnum1.PASS.getKey());
+        newContract.setApprovedDate(new Date());
+        contractService.update(newContract,Wrappers.<Contract>query().lambda().eq(Contract::getId,businessId));
+        //修改合同产品相关数据
+        contractProductService.update(Wrappers.<ContractProduct>update().lambda().set(ContractProduct::getContractId,oldContractId).eq(ContractProduct::getContractId,businessId));
+        //修改合同收费相关数据
+        contractProjectService.update(Wrappers.<ContractProject>update().lambda().set(ContractProject::getContractId,oldContractId).eq(ContractProject::getContractId,businessId));
+        //修改合同出货相关数据
+        contractShipmentService.update(Wrappers.<ContractShipment>update().lambda().set(ContractShipment::getContractId,oldContractId).eq(ContractShipment::getContractId,businessId));
+        /**
+         * 处理旧的合同---
+         */
+        oldContract.setId(businessId);
         oldContract.setStatus(FlowStatusEnum1.UPDATE.getKey());
         oldContract.setIsChange("1");
-        contractService.updateById(oldContract);
+        contractService.update(oldContract,Wrappers.<Contract>query().lambda().eq(Contract::getId,oldContractId));
+        //修改合同产品相关数据
+        contractProductService.update(Wrappers.<ContractProduct>update().lambda().set(ContractProduct::getContractId,businessId).eq(ContractProduct::getContractId,oldContractId));
+        //修改合同收费相关数据
+        contractProjectService.update(Wrappers.<ContractProject>update().lambda().set(ContractProject::getContractId,businessId).eq(ContractProject::getContractId,oldContractId));
+        //修改合同出货相关数据
+        contractShipmentService.update(Wrappers.<ContractShipment>update().lambda().set(ContractShipment::getContractId,businessId).eq(ContractShipment::getContractId,oldContractId));
     }
-
 }

+ 20 - 5
hx-sale/src/main/java/com/fjhx/sale/flow/SampleFlow.java

@@ -43,6 +43,18 @@ public class SampleFlow extends FlowDelegate {
     @Autowired
     private CodingRuleService codingRuleService;
 
+    @Autowired
+    private SampleService sampleService;
+
+    @Autowired
+    private SampleProductService sampleProductService;
+
+    @Autowired
+    private SampleProjectService sampleProjectService;
+
+    @Autowired
+    private SampleShipmentService sampleShipmentService;
+
     @Override
     public String getFlowKey() {
         return "sample_flow";
@@ -59,13 +71,17 @@ public class SampleFlow extends FlowDelegate {
     @Override
     @DSTransactional
     public Long start(Long flowId, JSONObject submitData) {
-        SampleService sampleService = SpringUtil.getBean(SampleService.class);
-        SampleProductService sampleProductService = SpringUtil.getBean(SampleProductService.class);
-        SampleProjectService sampleProjectService = SpringUtil.getBean(SampleProjectService.class);
-        SampleShipmentService sampleShipmentService = SpringUtil.getBean(SampleShipmentService.class);
+//        SampleService sampleService = SpringUtil.getBean(SampleService.class);
+//        SampleProductService sampleProductService = SpringUtil.getBean(SampleProductService.class);
+//        SampleProjectService sampleProjectService = SpringUtil.getBean(SampleProjectService.class);
+//        SampleShipmentService sampleShipmentService = SpringUtil.getBean(SampleShipmentService.class);
 //        Sample sample = submitData.toJavaObject(Sample.class);
 
         SampleDto sample = submitData.toJavaObject(SampleDto.class);
+        long id = start(sample);
+        return id;
+    }
+    public Long start(SampleDto sample){
         //赋值城市省份信息
         CustomizeAreaUtil.setAreaId(sample);
         sample.setBuyCityId(sample.getCityId());
@@ -106,7 +122,6 @@ public class SampleFlow extends FlowDelegate {
         //包装附件
         ObsFileUtil.saveFile(sample.getPackageFileList(),sample.getId(),2);
         return sample.getId();
-
     }
 
     /**

+ 175 - 0
hx-sale/src/main/java/com/fjhx/sale/flow/SampleUpdateFlow.java

@@ -0,0 +1,175 @@
+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.ObjectUtils;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.fjhx.common.enums.FlowStatusEnum1;
+import com.fjhx.flow.core.FlowDelegate;
+import com.fjhx.sale.entity.sample.dto.SampleDto;
+import com.fjhx.sale.entity.sample.po.Sample;
+import com.fjhx.sale.entity.sample.po.SampleProduct;
+import com.fjhx.sale.entity.sample.po.SampleProject;
+import com.fjhx.sale.entity.sample.po.SampleShipment;
+import com.fjhx.sale.service.sample.SampleProductService;
+import com.fjhx.sale.service.sample.SampleProjectService;
+import com.fjhx.sale.service.sample.SampleService;
+import com.fjhx.sale.service.sample.SampleShipmentService;
+import com.ruoyi.common.exception.ServiceException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+/**
+ * 样品单变更流程
+ */
+@Component
+public class SampleUpdateFlow extends FlowDelegate {
+
+    @Autowired
+    private SampleFlow sampleFlow;
+
+    @Autowired
+    private SampleService sampleService;
+
+    @Autowired
+    private SampleProductService sampleProductService;
+
+    @Autowired
+    private SampleProjectService sampleProjectService;
+
+    @Autowired
+    private SampleShipmentService sampleShipmentService;
+
+    @Override
+    public String getFlowKey() {
+        return "sample_update_flow";
+    }
+
+    /**
+     * 发起流程
+     *
+     * @param flowId     流程ID
+     * @param submitData 样品单数据
+     * @return
+     */
+    @Override
+    public Long start(Long flowId, JSONObject submitData) {
+
+        SampleDto newSample = submitData.toJavaObject(SampleDto.class);
+
+        // 原样品单id不能为空
+        Long oldSampleId = newSample.getOldSampleId();
+        if (oldSampleId == null) {
+            throw new ServiceException("原样品单id不能为空");
+        }
+        //查询原样品单
+        Sample oldSample = sampleService.getById(newSample.getOldSampleId());
+        if(ObjectUtil.isEmpty(oldSample)){
+            throw new ServiceException("查询不到原样品单信息");
+        }
+        //查询旧样品单的订单产品
+        List<SampleProduct> oldSampleProductList = sampleProductService.list(q -> q.eq(SampleProduct::getSampleId, oldSampleId));
+        if(CollectionUtils.isEmpty(oldSampleProductList)){
+            throw new ServiceException("原样品单没有产品");
+        }
+        Map<Long,List<SampleProduct>> oldSampleMap = oldSampleProductList.stream().collect(Collectors.groupingBy(SampleProduct::getId));
+        List<SampleProduct> newSampleProductList = newSample.getSampleProductList();
+        if(CollectionUtils.isEmpty(newSampleProductList)){
+            throw new ServiceException("变更样品单产品不能为空");
+        }
+        /**
+         * 赋值新的变更样品单号
+         */
+        String code = oldSample.getCode();
+        Matcher matcher = Pattern.compile(".*\\((.*?)\\)$").matcher(code);
+        int index = 2;
+        if (matcher.find()) {
+            index = (Integer.parseInt(matcher.group(1)) + 1);
+            code = code.substring(0, code.lastIndexOf("("));
+        }
+        newSample.setCode(code + "(" + index + ")");
+        /**
+         * 计算新样品单的剩余数量
+         */
+        for(SampleProduct newCp:newSampleProductList){
+
+            if(ObjectUtil.isNotEmpty(newCp.getId())){//如果新样品单产品ID不为空
+                //取出旧样品单
+                SampleProduct oldSampleProduct = oldSampleMap.getOrDefault(newCp.getId(),null).get(0);
+                //取出旧样品单包装方式
+                JSONObject oldJson = JSONObject.parseObject(oldSampleProduct.getEhsdJson());
+                String oldPackMethod = oldJson.getOrDefault("packMethod",null)==null?null:oldJson.getOrDefault("packMethod",null).toString();
+                //取出新样品单包装方式
+                JSONObject newJson = JSONObject.parseObject(newCp.getEhsdJson());
+                String newPackMethod = newJson.getOrDefault("packMethod",null)==null?null:oldJson.getOrDefault("packMethod",null).toString();
+                /**
+                 * 商品英文名、尺寸、包装方式、数量 没有变更---取原本的剩余数量
+                 */
+                if(oldSampleProduct.getQuantity().compareTo(newCp.getQuantity())==0
+                        && StringUtils.equals(oldSampleProduct.getProductName(), newCp.getProductName())
+                        && StringUtils.equals(oldSampleProduct.getProductModel(),newCp.getProductModel())
+                        && StringUtils.equals(oldPackMethod,newPackMethod)){
+                    //取出旧的剩余数量
+                    newCp.setExpendQuantity(oldSampleProduct.getExpendQuantity());
+                }
+            }
+        }
+        return sampleFlow.start(newSample);
+    }
+
+    /**
+     * 结束流程
+     *
+     * @param flowId     流程ID
+     * @param businessId 业务ID
+     * @param submitData 数据
+     */
+    @Override
+    public void end(Long flowId, Long businessId, JSONObject submitData) {
+        // 通过业务ID查询样品单数据
+        Sample newSample = sampleService.getById(businessId);
+        if (ObjectUtils.isEmpty(newSample)) {
+            throw new ServiceException("样品单不存在");
+        }
+        long  oldSampleId = newSample.getOldSampleId();//取出旧的样品单ID
+        Sample oldSample = sampleService.getById(oldSampleId);
+        if (oldSample == null) {
+            throw new ServiceException("原样品单不存在");
+        }
+        /**
+         * 处理新样品单---
+         */
+        newSample.setId(oldSampleId);//id赋值为旧样品单的id
+        newSample.setStatus(FlowStatusEnum1.PASS.getKey());
+        newSample.setApprovedDate(new Date());
+        sampleService.update(newSample,Wrappers.<Sample>query().lambda().eq(Sample::getId,businessId));
+        //修改样品单产品相关数据
+        sampleProductService.update(Wrappers.<SampleProduct>update().lambda().set(SampleProduct::getSampleId,oldSampleId).eq(SampleProduct::getSampleId,businessId));
+        //修改样品单收费相关数据
+        sampleProjectService.update(Wrappers.<SampleProject>update().lambda().set(SampleProject::getSampleId,oldSampleId).eq(SampleProject::getSampleId,businessId));
+        //修改样品单出货相关数据
+        sampleShipmentService.update(Wrappers.<SampleShipment>update().lambda().set(SampleShipment::getSampleId,oldSampleId).eq(SampleShipment::getSampleId,businessId));
+        /**
+         * 处理旧的样品单---
+         */
+        oldSample.setId(businessId);
+        oldSample.setStatus(FlowStatusEnum1.UPDATE.getKey());
+        oldSample.setIsChange("1");
+        sampleService.update(oldSample,Wrappers.<Sample>query().lambda().eq(Sample::getId,oldSampleId));
+        //修改样品单产品相关数据
+        sampleProductService.update(Wrappers.<SampleProduct>update().lambda().set(SampleProduct::getSampleId,businessId).eq(SampleProduct::getSampleId,oldSampleId));
+        //修改样品单收费相关数据
+        sampleProjectService.update(Wrappers.<SampleProject>update().lambda().set(SampleProject::getSampleId,businessId).eq(SampleProject::getSampleId,oldSampleId));
+        //修改样品单出货相关数据
+        sampleShipmentService.update(Wrappers.<SampleShipment>update().lambda().set(SampleShipment::getSampleId,businessId).eq(SampleShipment::getSampleId,oldSampleId));
+    }
+}