|
@@ -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);
|