Ver Fonte

合同变更

24282 há 2 anos atrás
pai
commit
65a3503de2

+ 17 - 27
hx-common/src/main/java/com/fjhx/common/enums/FlowStatusEnum.java

@@ -1,6 +1,7 @@
 package com.fjhx.common.enums;
 
-import org.apache.commons.collections4.MapUtils;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
 
 import java.util.LinkedHashMap;
 import java.util.Map;
@@ -8,46 +9,35 @@ import java.util.Map;
 /**
  * 流程审批状态--数据状态枚举
  */
+@Getter
+@AllArgsConstructor
 public enum FlowStatusEnum {
+
     DRAFT(0, "草稿"),
     UNDER_REVIEW(10, "审批中"),
     REJECT(20, "驳回"),
-    PASS(30,"通过"),
-    CANCELLATION(88,"作废"),
-    TERMINATION(99,"终止"),
+    PASS(30, "通过"),
+    UPDATE(70, "变更"),
+    CANCELLATION(88, "作废"),
+    TERMINATION(99, "终止"),
     ;
-    private int key;
-
-    private String value;
 
-    private static Map<Integer, String> map = new LinkedHashMap<>();
+    private static final Map<Integer, String> map = new LinkedHashMap<>();
 
-    FlowStatusEnum(int key, String value) {
-        this.key = key;
-        this.value = value;
+    static {
+        for (FlowStatusEnum ms : values()) {
+            map.put(ms.key, ms.value);
+        }
     }
 
+    private final int key;
+    private final String value;
+
     /**
      * 获取枚举map
-     *
-     * @return
      */
     public static Map<Integer, String> getMap() {
-        if (MapUtils.isNotEmpty(map)) {
-            return map;
-        }
-        for (FlowStatusEnum ms : values()) {
-            map.put(ms.key, ms.value);
-        }
         return map;
     }
 
-    public int getKey() {
-        return key;
-    }
-
-    public String getValue() {
-        return value;
-    }
-
 }

+ 6 - 0
hx-sale/src/main/java/com/fjhx/sale/entity/contract/po/Contract.java

@@ -287,6 +287,12 @@ public class Contract extends BasePo {
      * 利润结算表备注
      */
     private String profitClearingRemark;
+
+    /**
+     * 原合同id
+     */
+    private Long oldContractId;
+
     /**
      * 版本号
      */

+ 85 - 52
hx-sale/src/main/java/com/fjhx/sale/flow/ContractFlow.java

@@ -1,14 +1,10 @@
 package com.fjhx.sale.flow;
 
-import cn.hutool.extra.spring.SpringUtil;
 import com.alibaba.fastjson.JSONObject;
-import com.baomidou.dynamic.datasource.annotation.DS;
-import com.baomidou.dynamic.datasource.annotation.DSTransactional;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.fjhx.area.utils.CustomizeAreaUtil;
-import com.fjhx.common.constant.SourceConstant;
 import com.fjhx.common.enums.CodingRuleEnum;
 import com.fjhx.common.enums.FlowStatusEnum;
 import com.fjhx.common.service.coding.CodingRuleService;
@@ -33,95 +29,132 @@ import java.util.List;
 
 /**
  * 外销合同流程
+ *
  * @Author:caozj
  * @DATE:2023/4/3 17:38
  */
-@DS(SourceConstant.SALE)
 @Component
 public class ContractFlow extends FlowDelegate {
 
     @Autowired
     private CodingRuleService codingRuleService;
 
+    @Autowired
+    private ContractService contractService;
+
+    @Autowired
+    private ContractProductService contractProductService;
+
+    @Autowired
+    private ContractProjectService contractProjectService;
+
+    @Autowired
+    private ContractShipmentService contractShipmentService;
+
     @Override
     public String getFlowKey() {
         return "contract_flow";
     }
 
-
-
     /**
      * 发起流程
-     * @param flowId 流程ID
+     *
+     * @param flowId     流程ID
      * @param submitData 采购付款数据
-     * @return
+     * @return 业务id
      */
     @Override
-    @DSTransactional
     public Long start(Long flowId, JSONObject submitData) {
-        ContractService contractService = SpringUtil.getBean(ContractService.class);
-        ContractProductService contractProductService = SpringUtil.getBean(ContractProductService.class);
-        ContractProjectService contractProjectService = SpringUtil.getBean(ContractProjectService.class);
-        ContractShipmentService contractShipmentService = SpringUtil.getBean(ContractShipmentService.class);
         ContractDto contract = submitData.toJavaObject(ContractDto.class);
-        //赋值城市省份信息
+
+        // 保存合同产品
+        List<ContractProduct> contractProductList = contract.getContractProductList();
+
+        // 赋值待处理数量
+        if (CollectionUtils.isNotEmpty(contractProductList)) {
+            contractProductList.forEach(item -> item.setExpendQuantity(item.getQuantity()));
+        }
+
+        return start(contract);
+    }
+
+    /**
+     * 结束流程
+     *
+     * @param flowId     流程ID
+     * @param businessId 业务ID
+     * @param submitData 数据
+     */
+    @Override
+    public void end(Long flowId, Long businessId, JSONObject submitData) {
+
+        // 通过业务ID查询合同数据
+        Contract contract = contractService.getById(businessId);
+
+        if (ObjectUtils.isEmpty(contract)) {
+            throw new ServiceException("合同不存在");
+        }
+
+        // 修改采购状态为审批通过
+        contract.setStatus(FlowStatusEnum.PASS.getKey());
+        contract.setApprovedDate(new Date());
+        contractService.updateById(contract);
+    }
+
+    public Long start(ContractDto contract) {
+
+        long contractId = IdWorker.getId();
+
+        // 赋值城市省份信息
         CustomizeAreaUtil.setAreaId(contract);
-        contract.setCode(codingRuleService.createCode(CodingRuleEnum.CONTRACT.getKey(),contract.getBuyCorporationId()));
+
+        contract.setId(contractId);
+        contract.setCode(codingRuleService.createCode(CodingRuleEnum.CONTRACT.getKey(), contract.getBuyCorporationId()));
         contract.setUserName(SecurityUtils.getUsername());
         contract.setStatus(FlowStatusEnum.UNDER_REVIEW.getKey());
         contract.setBuyCityId(contract.getCityId());
         contract.setBuyCountryId(contract.getCountryId());
         contract.setBuyProvinceId(contract.getProvinceId());
-
         contractService.save(contract);
+
+        // 保存合同产品
         List<ContractProduct> contractProductList = contract.getContractProductList();
-        if(CollectionUtils.isNotEmpty(contractProductList)){//保存合同产品
-            for(ContractProduct c : contractProductList){
+        if (CollectionUtils.isNotEmpty(contractProductList)) {
+            for (ContractProduct c : contractProductList) {
                 c.setId(IdWorker.getId());
-                c.setContractId(contract.getId());
-                c.setExpendQuantity(c.getQuantity());
-                ObsFileUtil.saveFile(c.getFileList(),c.getId());
+                c.setContractId(contractId);
+                ObsFileUtil.saveFile(c.getFileList(), c.getId());
             }
             contractProductService.saveBatch(contractProductList);
         }
+
+        // 保存收费项目
         List<ContractProject> contractProjectList = contract.getContractProjectList();
-        if(CollectionUtils.isNotEmpty(contractProjectList)){//保存收费项目
-            for(ContractProject c : contractProjectList){
-                c.setContractId(contract.getId());
+        if (CollectionUtils.isNotEmpty(contractProjectList)) {
+            for (ContractProject c : contractProjectList) {
+                c.setId(IdWorker.getId());
+                c.setContractId(contractId);
             }
             contractProjectService.saveBatch(contractProjectList);
         }
+
+        // 保存自定义出货
         List<ContractShipment> contractShipmentList = contract.getContractShipmentList();
-        if(CollectionUtils.isNotEmpty(contractShipmentList)){//保存自定义出货
-            for(ContractShipment c : contractShipmentList){
-                c.setContractId(contract.getId());
+        if (CollectionUtils.isNotEmpty(contractShipmentList)) {
+            for (ContractShipment c : contractShipmentList) {
+                c.setId(IdWorker.getId());
+                c.setContractId(contractId);
             }
             contractShipmentService.saveBatch(contractShipmentList);
         }
-        //交接单附件列表
-        ObsFileUtil.saveFile(contract.getFileList(),contract.getId(),1);
-        //包装指示附件列表
-        ObsFileUtil.saveFile(contract.getPackageFileList(),contract.getId(),2);
-        return contract.getId();
-    }
 
-    /**
-     * 结束流程
-     * @param flowId 流程ID
-     * @param businessId 业务ID
-     * @param submitData 数据
-     */
-    @Override
-    public void end(Long flowId, Long businessId, JSONObject submitData) {
-        ContractService contractService = SpringUtil.getBean(ContractService.class);
-        //通过业务ID查询合同数据
-        Contract contract = contractService.getById(businessId);
-        if(ObjectUtils.isEmpty(contract)){
-            throw new ServiceException("合同不存在");
-        }
-        //修改采购状态为审批通过
-        contract.setStatus(FlowStatusEnum.PASS.getKey());
-        contract.setApprovedDate(new Date());
-        contractService.updateById(contract);
+        // 交接单附件列表
+        ObsFileUtil.saveFile(contract.getFileList(), contractId, 1);
+
+        // 包装指示附件列表
+        ObsFileUtil.saveFile(contract.getPackageFileList(), contractId, 2);
+
+        return contractId;
     }
+
 }

+ 126 - 0
hx-sale/src/main/java/com/fjhx/sale/flow/ContractUpdateFlow.java

@@ -0,0 +1,126 @@
+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.fjhx.common.enums.FlowStatusEnum;
+import com.fjhx.flow.core.FlowDelegate;
+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.service.contract.ContractProductService;
+import com.fjhx.sale.service.contract.ContractService;
+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.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+/**
+ * 合同变更流程
+ */
+@Component
+public class ContractUpdateFlow extends FlowDelegate {
+
+    @Autowired
+    private ContractFlow contractFlow;
+
+    @Autowired
+    private ContractService contractService;
+
+    @Autowired
+    private ContractProductService contractProductService;
+
+    @Override
+    public String getFlowKey() {
+        return "contract_update_flow";
+    }
+
+    /**
+     * 发起流程
+     *
+     * @param flowId     流程ID
+     * @param submitData 采购付款数据
+     * @return
+     */
+    @Override
+    public Long start(Long flowId, JSONObject submitData) {
+
+        ContractDto contract = submitData.toJavaObject(ContractDto.class);
+
+        // 原合同id不能为空
+        Long oldContractId = contract.getOldContractId();
+        if (oldContractId == null) {
+            throw new ServiceException("原合同id不能为空");
+        }
+
+        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()
+                    .peek(item -> {
+                        if (item.getId() == null) {
+                            throw new ServiceException("合同产品id不能为空");
+                        }
+                    })
+                    .collect(Collectors.toMap(BaseIdPo::getId, Function.identity()));
+
+
+            for (ContractProduct item : list) {
+                ContractProduct contractProduct = contractProductMap.get(item.getId());
+                if (contractProduct == null) {
+                    throw new ServiceException("产品id为" + item.getId() + "未上传");
+                }
+                BigDecimal expendQuantity = item.getExpendQuantity().subtract(item.getQuantity().subtract(contractProduct.getQuantity()));
+                contractProduct.setExpendQuantity(expendQuantity);
+            }
+
+        }
+
+        return contractFlow.start(contract);
+    }
+
+    /**
+     * 结束流程
+     *
+     * @param flowId     流程ID
+     * @param businessId 业务ID
+     * @param submitData 数据
+     */
+    @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();
+        Contract oldContract = contractService.getById(oldContractId);
+        if (oldContract == null) {
+            throw new ServiceException("原合同不存在");
+        }
+        oldContract.setStatus(FlowStatusEnum.UPDATE.getKey());
+        contractService.updateById(oldContract);
+
+        // TODO 已认领数据清空,但需要保留原认领记录
+
+
+    }
+
+}

+ 1 - 3
hx-sale/src/main/java/com/fjhx/sale/mapper/contract/ContractProductMapper.java

@@ -1,8 +1,8 @@
 package com.fjhx.sale.mapper.contract;
 
-import com.fjhx.sale.entity.contract.po.ContractProduct;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fjhx.sale.entity.contract.po.ContractProduct;
 import com.fjhx.sale.entity.contract.vo.ContractProductVo;
 import com.ruoyi.common.utils.wrapper.IWrapper;
 import org.apache.ibatis.annotations.Param;
@@ -27,8 +27,6 @@ public interface ContractProductMapper extends BaseMapper<ContractProduct> {
 
     /**
      * 根据合同产品ID集合查询合同产品
-     * @param ids
-     * @return
      */
     List<ContractProductVo> getListByIds(@Param("ew") IWrapper<ContractProduct> wrapper);
 

+ 0 - 8
hx-sale/src/main/java/com/fjhx/sale/service/contract/impl/ContractProductServiceImpl.java

@@ -18,8 +18,6 @@ import com.fjhx.sale.entity.contract.po.ContractProduct;
 import com.fjhx.sale.entity.contract.vo.ContractProductVo;
 import com.fjhx.sale.mapper.contract.ContractProductMapper;
 import com.fjhx.sale.service.contract.ContractProductService;
-import com.fjhx.sale.service.quality.EhsdQualityService;
-import com.fjhx.supply.service.supplier.SupplierInfoService;
 import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.wrapper.IWrapper;
@@ -59,12 +57,6 @@ public class ContractProductServiceImpl extends ServiceImpl<ContractProductMappe
     private CustomerService customerService;
 
     @Autowired
-    private SupplierInfoService supplierInfoService;
-
-    @Autowired
-    private EhsdQualityService ehsdQualityService;
-
-    @Autowired
     private CorporationService corporationService;
 
     /**

+ 6 - 6
hx-sale/src/main/resources/mapper/contract/ContractProductMapper.xml

@@ -6,16 +6,16 @@
         SELECT t1.id,
                t1.contract_id,
                t1.product_id,
-               t2.`code`                                                                                            AS contractCode,
-               t2.user_name                                                                                         AS userName,
-               t2.version                                                                                           AS contractVersion,
-               t1.expend_quantity                                                                                   AS expendQuantity,
+               t2.`code`          AS contractCode,
+               t2.user_name       AS userName,
+               t2.version         AS contractVersion,
+               t1.expend_quantity AS expendQuantity,
                (SELECT create_time
                 FROM claim_contract
                 WHERE contract_id = t2.id
                 ORDER BY create_time DESC
-                LIMIT 1)                                                                                            AS claimTime,
-               t2.corporation_id                                                                                    as corporationId
+                LIMIT 1)          AS claimTime,
+               t2.corporation_id  AS corporationId
         FROM contract_product t1
                  LEFT JOIN contract t2 ON t1.contract_id = t2.id
             ${ew.customSqlSegment}