Browse Source

Merge branch 'master' into dev

# Conflicts:
#	hx-sale/src/main/java/com/fjhx/sale/flow/ContractUpdateFlow.java
#	hx-sale/src/main/java/com/fjhx/sale/mapper/contract/ContractMapper.java
#	hx-sale/src/main/java/com/fjhx/sale/service/contract/ContractService.java
#	hx-sale/src/main/java/com/fjhx/sale/service/contract/impl/ContractServiceImpl.java
#	hx-sale/src/main/resources/mapper/contract/ContractMapper.xml
caozj 1 year ago
parent
commit
3ebb2b5dcc

+ 1 - 0
hx-common/src/main/java/com/fjhx/common/enums/FlowStatusEnum1.java

@@ -17,6 +17,7 @@ public enum FlowStatusEnum1 {
     UNDER_REVIEW(10, "审批中"),
     REJECT(20, "驳回"),
     PASS(30, "通过"),
+    UPDATE_LOADING(60, "变更中"),
     UPDATE(70, "变更"),
     CANCELLATION(88, "作废"),
     TERMINATION(99, "终止"),

+ 2 - 1
hx-purchase/src/main/resources/mapper/pay/PayDetailMapper.xml

@@ -48,8 +48,9 @@
         pay_detail t1
         LEFT JOIN pay t2 ON t1.pay_id = t2.id
         <where>
+            pay_type != 3
             <if test="purchaseIds neq null and purchaseIds.size() > 0">
-                <foreach collection="purchaseIds" item="purchaseId" open="purchase_id IN (" separator="," close=")">
+                <foreach collection="purchaseIds" item="purchaseId" open="AND purchase_id IN (" separator="," close=")">
                     #{purchaseId}
                 </foreach>
             </if>

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

@@ -324,6 +324,15 @@ public class Contract extends BasePo {
     private Integer versions;
 
     /**
+     * 是否显示
+     */
+    private Integer isShow;
+
+
+    @TableField(exist = false)
+    private Long upId;
+
+    /**
      * 交接单附件列表
      */
     @TableField(exist = false)

+ 202 - 27
hx-sale/src/main/java/com/fjhx/sale/flow/ContractUpdateFlow.java

@@ -2,9 +2,11 @@ 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.*;
+import com.fjhx.area.utils.CustomizeAreaUtil;
 import com.fjhx.common.enums.FlowStatusEnum1;
 import com.fjhx.common.utils.Assert;
+import com.fjhx.file.utils.ObsFileUtil;
 import com.fjhx.flow.core.FlowDelegate;
 import com.fjhx.flow.enums.FlowStatusEnum;
 import com.fjhx.sale.entity.claim.po.ClaimContract;
@@ -15,9 +17,12 @@ import com.fjhx.sale.entity.contract.po.ContractProject;
 import com.fjhx.sale.entity.contract.po.ContractShipment;
 import com.fjhx.sale.service.claim.ClaimContractService;
 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.core.domain.BasePo;
+import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.SecurityUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -49,6 +54,13 @@ public class ContractUpdateFlow extends FlowDelegate {
     @Autowired
     private ClaimContractService claimContractService;
 
+
+    @Autowired
+    private ContractProjectService contractProjectService;
+
+    @Autowired
+    private ContractShipmentService contractShipmentService;
+
     @Override
     public String getFlowKey() {
         return "contract_update_flow";
@@ -63,14 +75,34 @@ public class ContractUpdateFlow extends FlowDelegate {
      */
     @Override
     public Long start(Long flowId, JSONObject submitData) {
-
         ContractDto contract = submitData.toJavaObject(ContractDto.class);
 
-        Assert.notEmpty(contract.getOldContractId(), "原合同id不能为空");
-
-        //变更 用原来合同号加后缀
+        // 原合同id不能为空
+        Long oldContractId = contract.getOldContractId();
+        if (oldContractId == null) {
+            throw new ServiceException("原合同id不能为空");
+        }
+        //查询原合同
         Contract oldContract = contractService.getById(contract.getOldContractId());
-        Assert.notEmpty(oldContract, "查询不到原合同信息");
+        if(ObjectUtil.isEmpty(oldContract)){
+            throw new ServiceException("查询不到原合同信息");
+        }
+        //更新原样品单状态为变更中
+        oldContract.setStatus(FlowStatusEnum1.UPDATE_LOADING.getKey());
+        contractService.updateById(oldContract);
+        //查询旧合同的订单产品
+        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;
@@ -79,29 +111,89 @@ public class ContractUpdateFlow extends FlowDelegate {
             code = code.substring(0, code.lastIndexOf("("));
         }
         contract.setCode(code + "(" + index + ")");
-
-        //变更合同提前操作数据
-        contract = opDate(contract);
-
-        //清空id 方便后面生成新合同
-        contract.setId(null);
-        // 清空合同产品id
+        contract.setIsShow(1);//隐藏当前数据
+        /**
+         * 计算新合同的剩余数量
+         */
+        for(ContractProduct newCp:newContractProductList){
+            newCp.setExpendQuantity(newCp.getQuantity());
+            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 update(contract);
+    }
+    /**
+     * 变更
+     * @param contract
+     * @return
+     */
+    public Long update(ContractDto contract) {
+        // 赋值城市省份信息
+        CustomizeAreaUtil.setAreaId(contract);
+        SysUser loginUser = SecurityUtils.getLoginUser().getUser();
+        contract.setUserName(loginUser.getNickName());
+        contract.setBuyCityId(contract.getCityId());
+        contract.setBuyCountryId(contract.getCountryId());
+        contract.setBuyProvinceId(contract.getProvinceId());
+        contract.setStatus(FlowStatusEnum1.UNDER_REVIEW.getKey());
+//        contract.setRate(ExchangeRateUtil.getCnyToCodeRate(contract.getCurrency()));
+        contractService.save(contract);
+
+        // 保存合同产品
         List<ContractProduct> contractProductList = contract.getContractProductList();
         if (CollectionUtils.isNotEmpty(contractProductList)) {
-            contractProductList.forEach(item -> item.setId(null));
+            for (ContractProduct c : contractProductList) {
+                c.setId(IdWorker.getId());
+                c.setContractId(contract.getId());
+//                ObsFileUtil.saveFile(c.getFileList(), c.getId());
+            }
+            contractProductService.saveBatch(contractProductList);
         }
-        // 清空收费项目id
+
+        // 保存收费项目
         List<ContractProject> contractProjectList = contract.getContractProjectList();
         if (CollectionUtils.isNotEmpty(contractProjectList)) {
-            contractProjectList.forEach(item -> item.setId(null));
+            for (ContractProject c : contractProjectList) {
+                c.setId(IdWorker.getId());
+                c.setContractId(contract.getId());
+            }
+            contractProjectService.saveBatch(contractProjectList);
         }
-        // 清空自定义出货id
+
+        // 保存自定义出货
         List<ContractShipment> contractShipmentList = contract.getContractShipmentList();
         if (CollectionUtils.isNotEmpty(contractShipmentList)) {
-            contractShipmentList.forEach(item -> item.setId(null));
+            for (ContractShipment c : contractShipmentList) {
+                c.setId(IdWorker.getId());
+                c.setContractId(contract.getId());
+            }
+            contractShipmentService.saveBatch(contractShipmentList);
         }
 
-        contract = contractFlow.commStart(contract, 0);
+        // 交接单附件列表
+        ObsFileUtil.copyFileAndSave(contract.getFileList(), contract.getId(), 1);
+
+        // 包装指示附件列表
+        ObsFileUtil.copyFileAndSave(contract.getPackageFileList(), contract.getId(), 2);
+
         return contract.getId();
     }
 
@@ -114,32 +206,115 @@ 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("原合同不存在");
         }
+        //替换新数据ID为临时ID
+        long temNewId = IdWorker.getId();
+        Contract temNewUpContract = new Contract();
+        temNewUpContract.setId(temNewId);
+        temNewUpContract.setUpId(businessId);
+        contractService.updateContract(temNewUpContract);
+
+        long temOldId = IdWorker.getId();
+        Contract temOldUpContract = new Contract();
+        temOldUpContract.setId(temOldId);
+        temOldUpContract.setUpId(oldContractId);
+        contractService.updateContract(temOldUpContract);
+
+
+        //查询新数据产品、收费、出货
+        List<Long> newContractProductIds = contractProductService.list(Wrappers.<ContractProduct>query().lambda().select(ContractProduct::getId).eq(ContractProduct::getContractId,businessId)).stream().map(ContractProduct::getId).collect(Collectors.toList());
+        List<Long> newContractProjectIds = contractProjectService.list(Wrappers.<ContractProject>query().lambda().select(ContractProject::getId).eq(ContractProject::getContractId,businessId)).stream().map(ContractProject::getId).collect(Collectors.toList());
+        List<Long> newContractShipmentIds = contractShipmentService.list(Wrappers.<ContractShipment>query().lambda().select(ContractShipment::getId).eq(ContractShipment::getContractId,businessId)).stream().map(ContractShipment::getId).collect(Collectors.toList());
+
+
+        //查询旧数据产品、收费、出货
+        List<Long> oldContractProductIds = contractProductService.list(Wrappers.<ContractProduct>query().lambda().select(ContractProduct::getId).eq(ContractProduct::getContractId,oldContractId)).stream().map(ContractProduct::getId).collect(Collectors.toList());
+        List<Long> oldContractProjectIds = contractProjectService.list(Wrappers.<ContractProject>query().lambda().select(ContractProject::getId).eq(ContractProject::getContractId,oldContractId)).stream().map(ContractProject::getId).collect(Collectors.toList());
+        List<Long> oldContractShipmentIds = contractShipmentService.list(Wrappers.<ContractShipment>query().lambda().select(ContractShipment::getId).eq(ContractShipment::getContractId,oldContractId)).stream().map(ContractShipment::getId).collect(Collectors.toList());
+
+
+        /**
+         * 处理新合同---
+         */
+        newContract.setId(oldContractId);//id赋值为旧合同的id
+        newContract.setStatus(FlowStatusEnum1.PASS.getKey());
+        newContract.setApprovedDate(new Date());
+        newContract.setUpId(temNewId);
+        newContract.setOldContractId(businessId);
+        newContract.setIsShow(0);//显示新合同
+        contractService.updateContract(newContract);
+        //修改合同产品相关数据
+        if(CollectionUtils.isNotEmpty(newContractProductIds)){
+            contractProductService.update(Wrappers.<ContractProduct>update().lambda().set(ContractProduct::getContractId,oldContractId).in(ContractProduct::getId,newContractProductIds));
+        }
+        //修改合同收费相关数据
+        if(CollectionUtils.isNotEmpty(newContractProjectIds)){
+            contractProjectService.update(Wrappers.<ContractProject>update().lambda().set(ContractProject::getContractId,oldContractId).in(ContractProject::getId,newContractProjectIds));
+        }
+        //修改合同出货相关数据
+        if(CollectionUtils.isNotEmpty(newContractShipmentIds)){
+            contractShipmentService.update(Wrappers.<ContractShipment>update().lambda().set(ContractShipment::getContractId,oldContractId).in(ContractShipment::getId,newContractShipmentIds));
+        }
+
+        /**
+         * 处理旧的合同---
+         */
+        oldContract.setId(businessId);
         oldContract.setStatus(FlowStatusEnum1.UPDATE.getKey());
         oldContract.setIsChange("1");
         contractService.updateById(oldContract);
 
         //删除到账认领数据
         claimContractService.remove(q -> q.eq(ClaimContract::getContractId, oldContractId));
+        oldContract.setUpId(temOldId);
+        oldContract.setIsShow(1);//隐藏旧合同
+        contractService.updateContract(oldContract);
+        //修改合同产品相关数据
+        if(CollectionUtils.isNotEmpty(oldContractProductIds)){
+            contractProductService.update(Wrappers.<ContractProduct>update().lambda().set(ContractProduct::getContractId,businessId).in(ContractProduct::getId,oldContractProductIds));
+        }
+        //修改合同出货相关数据
+        if(CollectionUtils.isNotEmpty(oldContractProjectIds)){
+            //修改合同收费相关数据
+            contractProjectService.update(Wrappers.<ContractProject>update().lambda().set(ContractProject::getContractId,businessId).in(ContractProject::getId,oldContractProjectIds));
+        }
+        //修改合同出货相关数据
+        if(CollectionUtils.isNotEmpty(oldContractShipmentIds)){
+            //修改合同出货相关数据
+            contractShipmentService.update(Wrappers.<ContractShipment>update().lambda().set(ContractShipment::getContractId,businessId).in(ContractShipment::getId,oldContractShipmentIds));
+        }
+        ObsFileUtil.exchangeBusinessId(oldContractId,businessId);
     }
 
+    /**
+     * 重新发起
+     * @param flowId
+     * @param businessId
+     * @param flowStatus
+     * @param submitData
+     */
     @Override
     public void relaunch(Long flowId, Long businessId, FlowStatusEnum flowStatus, JSONObject submitData) {
         super.relaunch(flowId, businessId, flowStatus, submitData);
         reStart(submitData);
     }
 
+
+    /**
+     * 驳回
+     * @param flowId
+     * @param businessId
+     * @param flowStatus
+     */
     @Override
     public void reject(Long flowId, Long businessId, FlowStatusEnum flowStatus) {
         super.reject(flowId, businessId, flowStatus);

+ 1 - 0
hx-sale/src/main/java/com/fjhx/sale/mapper/contract/ContractMapper.java

@@ -97,4 +97,5 @@ public interface ContractMapper extends BaseMapper<Contract> {
     List<AccountRunningWaterVo> getAccountRunningWaterByContractId(@Param("contractId") Long contractId);
 
     List<ContractVo> getCustomerMoney();
+    void updateContract(Contract contract);
 }

+ 2 - 0
hx-sale/src/main/java/com/fjhx/sale/service/contract/ContractService.java

@@ -187,4 +187,6 @@ public interface ContractService extends BaseService<Contract> {
      * @return
      */
     Map<String,Object> getHeadCustomerStatistics();
+
+    void updateContract(Contract contract);
 }

+ 12 - 0
hx-sale/src/main/java/com/fjhx/sale/service/contract/impl/ContractServiceImpl.java

@@ -89,6 +89,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.security.core.context.SecurityContext;
 import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
 import java.math.RoundingMode;
@@ -1615,6 +1616,17 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
     }
 
     /**
+     * 修改合同
+     *
+     * @param contract
+     */
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void updateContract(Contract contract) {
+        baseMapper.updateContract(contract);
+    }
+
+    /**
      * 头部统计客户金额
      * @return
      */

+ 13 - 0
hx-sale/src/main/resources/mapper/contract/ContractMapper.xml

@@ -238,4 +238,17 @@
             AND t1.`status` &lt; 70
         GROUP BY sell_corporation_id
     </select>
+    <update id="updateContract" parameterType="com.fjhx.sale.entity.contract.po.Contract">
+        update contract
+        <set>
+            <if test="id != null">id = #{id},</if>
+            <if test="status != null">status = #{status},</if>
+            <if test="isChange != null">is_change = #{isChange},</if>
+            <if test="isShow != null">is_show = #{isShow},</if>
+            <if test="oldContractId != null">old_contract_id = #{oldContractId},</if>
+            <if test="approvedDate != null">approved_date = DATE_FORMAT(NOW(),'%Y-%m-%d %H:%m:%s'),</if>
+            update_time = sysdate()
+        </set>
+        where id = #{upId}
+    </update>
 </mapper>