|
@@ -5,17 +5,21 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.fjhx.common.enums.FlowStatusEnum1;
|
|
|
import com.fjhx.flow.core.FlowDelegate;
|
|
|
+import com.fjhx.flow.enums.FlowStatusEnum;
|
|
|
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.core.domain.BasePo;
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
|
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;
|
|
@@ -53,6 +57,54 @@ public class ContractUpdateFlow extends FlowDelegate {
|
|
|
|
|
|
ContractDto contract = submitData.toJavaObject(ContractDto.class);
|
|
|
|
|
|
+ //变更合同提前操作数据
|
|
|
+ contract = opDate(contract);
|
|
|
+
|
|
|
+ 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(FlowStatusEnum1.UPDATE.getKey());
|
|
|
+ oldContract.setIsChange("1");
|
|
|
+ contractService.updateById(oldContract);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void defaultMethod(Long flowId, Long businessId, FlowStatusEnum flowStatusEnum, JSONObject submitData) {
|
|
|
+ //重新发起
|
|
|
+ if (FlowStatusEnum.READY_START.equals(flowStatusEnum)) {
|
|
|
+ reStart(submitData);
|
|
|
+ }
|
|
|
+ //驳回
|
|
|
+ if (FlowStatusEnum.REJECT.equals(flowStatusEnum)) {
|
|
|
+ reject(businessId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 变更合同时执行的数据操作公共代码
|
|
|
+ */
|
|
|
+ private ContractDto opDate(ContractDto contract) {
|
|
|
// 原合同id不能为空
|
|
|
Long oldContractId = contract.getOldContractId();
|
|
|
if (oldContractId == null) {
|
|
@@ -72,20 +124,12 @@ public class ContractUpdateFlow extends FlowDelegate {
|
|
|
|
|
|
Map<Long, ContractProduct> contractProductMap = contractProductList
|
|
|
.stream()
|
|
|
-// .peek(item -> {
|
|
|
-// if (item.getId() == null) {
|
|
|
-// throw new ServiceException("合同产品id不能为空");
|
|
|
-// }
|
|
|
-// })
|
|
|
.filter(item -> ObjectUtil.isNotEmpty(item.getId()))
|
|
|
.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() + "未上传");
|
|
|
-// }
|
|
|
if (ObjectUtil.isNotEmpty(contractProduct)) {
|
|
|
BigDecimal expendQuantity = item.getExpendQuantity().subtract(item.getQuantity().subtract(contractProduct.getQuantity()));
|
|
|
contractProduct.setExpendQuantity(expendQuantity);
|
|
@@ -93,39 +137,31 @@ public class ContractUpdateFlow extends FlowDelegate {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
-
|
|
|
- return contractFlow.start(contract);
|
|
|
+ return contract;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 结束流程
|
|
|
- *
|
|
|
- * @param flowId 流程ID
|
|
|
- * @param businessId 业务ID
|
|
|
- * @param submitData 数据
|
|
|
+ * 重新发起
|
|
|
*/
|
|
|
- @Override
|
|
|
- public void end(Long flowId, Long businessId, JSONObject submitData) {
|
|
|
-
|
|
|
- contractFlow.end(flowId, businessId, submitData);
|
|
|
+ private void reStart(JSONObject submitData) {
|
|
|
+ ContractDto contract = submitData.toJavaObject(ContractDto.class);
|
|
|
|
|
|
- // 通过业务id查询合同数据
|
|
|
- Contract contract = contractService.getById(businessId);
|
|
|
+ //变更合同需要提前操作数据
|
|
|
+ contract = opDate(contract);
|
|
|
|
|
|
- // 原合同改为作废状态
|
|
|
- Long oldContractId = contract.getOldContractId();
|
|
|
- Contract oldContract = contractService.getById(oldContractId);
|
|
|
- if (oldContract == null) {
|
|
|
- throw new ServiceException("原合同不存在");
|
|
|
- }
|
|
|
- oldContract.setStatus(FlowStatusEnum1.UPDATE.getKey());
|
|
|
- oldContract.setIsChange("1");
|
|
|
- contractService.updateById(oldContract);
|
|
|
+ contractFlow.reStart1(contract);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void defaultMethod(Long flowId, Long businessId, com.fjhx.flow.enums.FlowStatusEnum flowStatusEnum, JSONObject submitData) {
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 驳回
|
|
|
+ */
|
|
|
+ private void reject(Long businessId) {
|
|
|
+ contractService.update(q -> q
|
|
|
+ .eq(Contract::getId, businessId)
|
|
|
+ .set(Contract::getStatus, FlowStatusEnum1.REJECT.getKey())//20为驳回
|
|
|
+ .set(BasePo::getUpdateTime, new Date())
|
|
|
+ .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
}
|