gongdecai 3 年之前
父节点
当前提交
1d82194d46

+ 5 - 0
winsea-haixin-plugin-yiliangyiyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/entity/ContractManagementInfo.java

@@ -269,6 +269,11 @@ public class ContractManagementInfo extends BaseModel<ContractManagementInfo> {
      */
     @TableField(exist = false)
     private String goodsNameKey;
+
+
+    @TableField(exist = false)
+    private String taskId;
+
     /**
      * 品级
      */

+ 130 - 2
winsea-haixin-plugin-yiliangyiyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/service/impl/ContractManagementInfoServiceImpl.java

@@ -1,10 +1,12 @@
 package com.yh.saas.plugin.yiliangyiyun.service.impl;
 
 
+import com.alibaba.fastjson.JSONObject;
 import com.alipay.sofa.runtime.api.annotation.SofaService;
 import com.baomidou.mybatisplus.mapper.Wrapper;
 import com.winsea.svc.base.base.entity.CommonDepartment;
 import com.winsea.svc.base.base.util.DateUtils;
+import com.winsea.svc.base.workflow.entity.Workflow;
 import com.yh.saas.common.support.util.IdGenerator;
 import com.yh.saas.plugin.base.service.ICommonBillOperateHisService;
 import com.yh.saas.plugin.yiliangyiyun.constant.NumberConstant;
@@ -66,6 +68,8 @@ public class ContractManagementInfoServiceImpl extends ServiceImpl<ContractManag
     @Autowired
     private ITranCarInfoService tranCarInfoService;
     @Autowired
+    private INewWorkflowService workflowService;
+    @Autowired
     private IPriceConfirmationSheetService priceConfirmationSheetService;
     @Value("${file-root-path}")
     private String localPath;
@@ -82,8 +86,12 @@ public class ContractManagementInfoServiceImpl extends ServiceImpl<ContractManag
         // 主表信息新增
         // 新增主键id
         contractManagementInfo.setId(IdGenerator.generateUUID());
-        contractManagementInfo.setStatusFlag(StatusEnum.CONTRACT_WAIT.getFlag());
-        contractManagementInfo.setStatus(StatusEnum.CONTRACT_WAIT.getName());
+
+        // 期货插入状态
+        if("2".equals(contractManagementInfo.getGoodsType())){
+            contractManagementInfo.setStatusFlag(StatusEnum.CONTRACT_WAIT.getFlag());
+            contractManagementInfo.setStatus(StatusEnum.CONTRACT_WAIT.getName());
+        }
         //判断合同编号是否唯一
         List<ContractManagementInfo> contractManagementInfos =
                 contractManagementInfoService.selectList(new EntityWrapper<ContractManagementInfo>()
@@ -115,6 +123,63 @@ public class ContractManagementInfoServiceImpl extends ServiceImpl<ContractManag
         boolean one = this.insert(contractManagementInfo);
         boolean two = contractGoodsInfoService.insert(contractGoodsInfo);
         boolean three = contractProcessInfoService.insert(contractProcessInfo);
+
+        // 根据类型进入审核
+        if("1".equals(contractManagementInfo.getGoodsType())) {
+            if ("1".equals(contractManagementInfo.getContractType())) {
+                boolean isStartWorkflow = StringUtils.isBlank(contractManagementInfo.getWorkflowId());
+                // 不是退回的单子
+                if (isStartWorkflow) {
+                    Workflow workflow = workflowService
+                            .findLatestWorkflowByBusinessCodeByApp(contractManagementInfo.getCompId(), "SALE-CONTRACT-APPROVE");
+                    // 没配置审核流程,直接结束并处理信息
+                    if (workflow == null) {
+                        throw new YException(YExceptionEnum.PURCHASE_ORDER_ERROR);
+                    }
+                    // 开启审核流
+                    else {
+
+                        // 设置状态 已提交审核
+                        contractManagementInfo.setWorkflowId(workflow.getId());
+                        this.updateById(contractManagementInfo);
+                        workflowService.startInstance(workflow.getId(), contractManagementInfo.getId());
+                    }
+                }
+                // 退回的单子 再启用
+                else {
+
+                    this.updateById(contractManagementInfo);
+                    workflowService.activateInstance(contractManagementInfo.getWorkflowId(), contractManagementInfo.getId());
+                }
+            } else {
+
+                boolean isStartWorkflow = StringUtils.isBlank(contractManagementInfo.getWorkflowId());
+                // 不是退回的单子
+                if (isStartWorkflow) {
+                    Workflow workflow = workflowService
+                            .findLatestWorkflowByBusinessCodeByApp(contractManagementInfo.getCompId(), "BUY-CONTRACT-APPROVE");
+                    // 没配置审核流程,直接结束并处理信息
+                    if (workflow == null) {
+                        throw new YException(YExceptionEnum.PURCHASE_ORDER_ERROR);
+                    }
+                    // 开启审核流
+                    else {
+
+                        // 设置状态 已提交审核
+                        contractManagementInfo.setWorkflowId(workflow.getId());
+                        this.updateById(contractManagementInfo);
+                        workflowService.startInstance(workflow.getId(), contractManagementInfo.getId());
+                    }
+                }
+                // 退回的单子 再启用
+                else {
+
+                    this.updateById(contractManagementInfo);
+                    workflowService.activateInstance(contractManagementInfo.getWorkflowId(), contractManagementInfo.getId());
+                }
+
+            }
+        }
         // 假如 都成功返回ok
         if (one && two && three) {
             // 插入操作历史
@@ -182,6 +247,62 @@ public class ContractManagementInfoServiceImpl extends ServiceImpl<ContractManag
             warehouseBaseInfo.setPersonPhone(contractManagementInfo.getPersonPhone());
             warehouseBaseInfoService.updateById(warehouseBaseInfo);
         }
+        // 根据类型进入审核
+        if("1".equals(contractManagementInfo.getGoodsType())) {
+            if ("1".equals(contractManagementInfo.getContractType())) {
+                boolean isStartWorkflow = StringUtils.isBlank(contractManagementInfo.getWorkflowId());
+                // 不是退回的单子
+                if (isStartWorkflow) {
+                    Workflow workflow = workflowService
+                            .findLatestWorkflowByBusinessCodeByApp(contractManagementInfo.getCompId(), "SALE-CONTRACT-APPROVE");
+                    // 没配置审核流程,直接结束并处理信息
+                    if (workflow == null) {
+                        throw new YException(YExceptionEnum.PURCHASE_ORDER_ERROR);
+                    }
+                    // 开启审核流
+                    else {
+
+                        // 设置状态 已提交审核
+                        contractManagementInfo.setWorkflowId(workflow.getId());
+                        this.updateById(contractManagementInfo);
+                        workflowService.startInstance(workflow.getId(), contractManagementInfo.getId());
+                    }
+                }
+                // 退回的单子 再启用
+                else {
+
+                    this.updateById(contractManagementInfo);
+                    workflowService.activateInstance(contractManagementInfo.getWorkflowId(), contractManagementInfo.getId());
+                }
+            } else {
+
+                boolean isStartWorkflow = StringUtils.isBlank(contractManagementInfo.getWorkflowId());
+                // 不是退回的单子
+                if (isStartWorkflow) {
+                    Workflow workflow = workflowService
+                            .findLatestWorkflowByBusinessCodeByApp(contractManagementInfo.getCompId(), "BUY-CONTRACT-APPROVE");
+                    // 没配置审核流程,直接结束并处理信息
+                    if (workflow == null) {
+                        throw new YException(YExceptionEnum.PURCHASE_ORDER_ERROR);
+                    }
+                    // 开启审核流
+                    else {
+
+                        // 设置状态 已提交审核
+                        contractManagementInfo.setWorkflowId(workflow.getId());
+                        this.updateById(contractManagementInfo);
+                        workflowService.startInstance(workflow.getId(), contractManagementInfo.getId());
+                    }
+                }
+                // 退回的单子 再启用
+                else {
+
+                    this.updateById(contractManagementInfo);
+                    workflowService.activateInstance(contractManagementInfo.getWorkflowId(), contractManagementInfo.getId());
+                }
+
+            }
+        }
         // 货物信息编辑
         boolean two = contractGoodsInfoService.updateById(contractManagementInfo.getContractGoodsInfo());
         //流程编辑
@@ -311,6 +432,13 @@ public class ContractManagementInfoServiceImpl extends ServiceImpl<ContractManag
         ContractProcessInfo contractProcessInfo = contractProcessInfoService.selectOne(new EntityWrapper<ContractProcessInfo>().eq(ContractGoodsInfo.QueryFiles.CONTRACT_ID, id));
         contractManagementInfo.setContractGoodsInfo(contractGoodsInfo);
         contractManagementInfo.setContractProcessInfo(contractProcessInfo);
+        String taskId = "";
+        // 只有待审核状态才有taskId
+        if (StringUtils.isNotBlank(contractManagementInfo.getWorkflowId())) {
+            JSONObject jsonObject = workflowService.getActiveTask(Lists.newArrayList(contractManagementInfo.getWorkflowId()), contractManagementInfo.getId());
+            taskId = jsonObject.getString("taskId");
+            contractManagementInfo.setTaskId(taskId);
+        }
         return contractManagementInfo;
     }
 

+ 48 - 0
winsea-haixin-plugin-yiliangyiyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/workflow/BuyContractListener.java

@@ -0,0 +1,48 @@
+package com.yh.saas.plugin.yiliangyiyun.workflow;
+
+import com.yh.saas.common.support.workflow.AbstractWorkflowTaskListener;
+import com.yh.saas.common.support.workflow.annotation.WorkflowTaskListener;
+import com.yh.saas.plugin.yiliangyiyun.constant.StatusEnum;
+import com.yh.saas.plugin.yiliangyiyun.entity.ContractManagementInfo;
+import com.yh.saas.plugin.yiliangyiyun.service.IContractManagementInfoService;
+import org.springframework.beans.factory.annotation.Autowired;
+
+@WorkflowTaskListener(name = "合同管理", group = "采购合同")
+public class BuyContractListener extends AbstractWorkflowTaskListener {
+
+    private static final long serialVersionUID = 4103656734835351132L;
+
+    @Autowired
+    private IContractManagementInfoService contractManagementInfoService;
+
+    @Override
+    public void handleStatusChanged(String businessKey, String status, String statusEn, boolean processIsEnd) {
+        ContractManagementInfo contractManagementInfo = contractManagementInfoService.selectById(businessKey);
+        if (contractManagementInfo == null) {
+            return;
+        }
+        if (processIsEnd) {
+            contractManagementInfo.setStatusFlag(StatusEnum.CONTRACT_DO.getFlag());
+            contractManagementInfo.setStatus(StatusEnum.CONTRACT_DO.getName());
+            contractManagementInfo.setWorkflowId(null);
+            contractManagementInfo.setApproveStatus(null);
+        } else {
+            contractManagementInfo.setApproveStatus(status);
+        }
+        contractManagementInfoService.updateAllColumnById(contractManagementInfo);
+    }
+
+    @Override
+    public void handleRejectApplicationRepulsed(String workflowId, String businessKey, boolean needReapply) {
+        ContractManagementInfo contractManagementInfo = contractManagementInfoService.selectById(businessKey);
+        if (contractManagementInfo == null) {
+            return;
+        }
+        contractManagementInfo.setStatusFlag(StatusEnum.TASK_RETURN.getFlag());
+        contractManagementInfo.setStatus(StatusEnum.TASK_RETURN.getName());
+        contractManagementInfo.setApproveStatus(null);
+        contractManagementInfoService.updateAllColumnById(contractManagementInfo);
+
+    }
+
+}

+ 50 - 0
winsea-haixin-plugin-yiliangyiyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/workflow/SaleContractListener.java

@@ -0,0 +1,50 @@
+package com.yh.saas.plugin.yiliangyiyun.workflow;
+
+import com.yh.saas.common.support.workflow.AbstractWorkflowTaskListener;
+import com.yh.saas.common.support.workflow.annotation.WorkflowTaskListener;
+import com.yh.saas.plugin.yiliangyiyun.constant.StatusEnum;
+import com.yh.saas.plugin.yiliangyiyun.entity.ContractManagementInfo;
+import com.yh.saas.plugin.yiliangyiyun.entity.SaleOrder;
+import com.yh.saas.plugin.yiliangyiyun.service.IContractManagementInfoService;
+import com.yh.saas.plugin.yiliangyiyun.service.ISaleOrderService;
+import org.springframework.beans.factory.annotation.Autowired;
+
+@WorkflowTaskListener(name = "合同管理", group = "销售合同")
+public class SaleContractListener extends AbstractWorkflowTaskListener {
+
+    private static final long serialVersionUID = 4103656734835351132L;
+
+    @Autowired
+    private IContractManagementInfoService contractManagementInfoService;
+
+    @Override
+    public void handleStatusChanged(String businessKey, String status, String statusEn, boolean processIsEnd) {
+        ContractManagementInfo contractManagementInfo = contractManagementInfoService.selectById(businessKey);
+        if (contractManagementInfo == null) {
+            return;
+        }
+        if (processIsEnd) {
+            contractManagementInfo.setStatusFlag(StatusEnum.CONTRACT_DO.getFlag());
+            contractManagementInfo.setStatus(StatusEnum.CONTRACT_DO.getName());
+            contractManagementInfo.setWorkflowId(null);
+            contractManagementInfo.setApproveStatus(null);
+        } else {
+            contractManagementInfo.setApproveStatus(status);
+        }
+        contractManagementInfoService.updateAllColumnById(contractManagementInfo);
+    }
+
+    @Override
+    public void handleRejectApplicationRepulsed(String workflowId, String businessKey, boolean needReapply) {
+        ContractManagementInfo contractManagementInfo = contractManagementInfoService.selectById(businessKey);
+        if (contractManagementInfo == null) {
+            return;
+        }
+        contractManagementInfo.setStatusFlag(StatusEnum.TASK_RETURN.getFlag());
+        contractManagementInfo.setStatus(StatusEnum.TASK_RETURN.getName());
+        contractManagementInfo.setApproveStatus(null);
+        contractManagementInfoService.updateAllColumnById(contractManagementInfo);
+
+    }
+
+}