|
@@ -0,0 +1,100 @@
|
|
|
+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.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
+import com.fjhx.common.constant.SourceConstant;
|
|
|
+import com.fjhx.flow.core.FlowDelegate;
|
|
|
+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.enums.FlowStatusEnum;
|
|
|
+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.fjhx.sale.util.code.CodeEnum;
|
|
|
+import com.obs.services.internal.ServiceException;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 采购付款流程
|
|
|
+ * @Author:caozj
|
|
|
+ * @DATE:2023/4/3 17:38
|
|
|
+ */
|
|
|
+@DS(SourceConstant.SALE)
|
|
|
+@Component
|
|
|
+public class ContractFlow extends FlowDelegate {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getFlowKey() {
|
|
|
+ return "contract_flow";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发起流程
|
|
|
+ * @param flowId 流程ID
|
|
|
+ * @param submitData 采购付款数据
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ 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);
|
|
|
+ Contract contract = submitData.toJavaObject(Contract.class);
|
|
|
+ contract.setCode(CodeEnum.CONTRACT.getCode());
|
|
|
+ contract.setStatus(FlowStatusEnum.UNDER_REVIEW.getKey());
|
|
|
+ contractService.save(contract);
|
|
|
+ List<ContractProduct> contractProductList = contract.getContractProductList();
|
|
|
+ if(CollectionUtils.isNotEmpty(contractProductList)){//保存合同产品
|
|
|
+ for(ContractProduct c : contractProductList){
|
|
|
+ c.setContractId(contract.getId());
|
|
|
+ }
|
|
|
+ contractProductService.saveBatch(contractProductList);
|
|
|
+ }
|
|
|
+ List<ContractProject> contractProjectList = contract.getContractProjectList();
|
|
|
+ if(CollectionUtils.isNotEmpty(contractProjectList)){//保存合同产品
|
|
|
+ for(ContractProject c : contractProjectList){
|
|
|
+ c.setContractId(contract.getId());
|
|
|
+ }
|
|
|
+ contractProjectService.saveBatch(contractProjectList);
|
|
|
+ }
|
|
|
+ List<ContractShipment> contractShipmentList = contract.getContractShipmentList();
|
|
|
+ if(CollectionUtils.isNotEmpty(contractShipmentList)){//保存合同产品
|
|
|
+ for(ContractShipment c : contractShipmentList){
|
|
|
+ c.setContractId(contract.getId());
|
|
|
+ }
|
|
|
+ contractShipmentService.saveBatch(contractShipmentList);
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+}
|