소스 검색

审核流

gongdecai 3 년 전
부모
커밋
37b040e20f

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

@@ -87,6 +87,15 @@ public class PurchasePrice extends BaseModel<PurchasePrice> {
      * 状态
      */
     private String status;
+    /**
+     * 审核流
+     */
+    private String workflowId;
+
+    /**
+     * 审核状态
+     */
+    private String approveStatus;
 
     /**
      * 通过时间
@@ -96,6 +105,8 @@ public class PurchasePrice extends BaseModel<PurchasePrice> {
     @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date passDate;
 
+    @TableField(exist = false)
+    private String taskId;
     @Override
     protected Serializable pkVal() {
         return this.id;

+ 71 - 0
winsea-haixin-plugin-yiliangyiyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/service/impl/PurchasePriceServiceImpl.java

@@ -1,17 +1,24 @@
 package com.yh.saas.plugin.yiliangyiyun.service.impl;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.mapper.EntityWrapper;
 import com.baomidou.mybatisplus.plugins.Page;
 import com.google.common.collect.Lists;
+import com.winsea.svc.base.workflow.entity.Workflow;
 import com.yh.saas.common.support.util.IdGenerator;
 import com.yh.saas.plugin.yiliangyiyun.constant.StatusEnum;
 import com.yh.saas.plugin.yiliangyiyun.entity.*;
+import com.yh.saas.plugin.yiliangyiyun.exception.YException;
+import com.yh.saas.plugin.yiliangyiyun.exception.YExceptionEnum;
 import com.yh.saas.plugin.yiliangyiyun.mapper.*;
+import com.yh.saas.plugin.yiliangyiyun.service.INewWorkflowService;
 import com.yh.saas.plugin.yiliangyiyun.service.IPurchasePriceService;
 import com.baomidou.mybatisplus.service.impl.ServiceImpl;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
 
 import java.util.HashMap;
 import java.util.List;
@@ -34,6 +41,8 @@ public class PurchasePriceServiceImpl extends ServiceImpl<PurchasePriceMapper, P
     private PurchasePriceDetailPrintMapper purchasePriceDetailPrintMapper;
     @Autowired
     private WarehouseBaseInfoMapper warehouseBaseInfoMapper;
+    @Autowired
+    private INewWorkflowService workflowService;
     @Override
     public Page<PurchasePrice> purchasePriceList(PurchasePrice purchasePrice) {
 
@@ -51,6 +60,19 @@ public class PurchasePriceServiceImpl extends ServiceImpl<PurchasePriceMapper, P
 
         Integer dataCount = this.baseMapper.purchasePriceListCount(pageView);
 
+        if (!CollectionUtils.isEmpty(dataList)) {
+            dataList.forEach(purchasePrice1 -> {
+
+                String taskId = "";
+                // 只有待审核状态才有taskId
+                if (StringUtils.isNotBlank(purchasePrice1.getWorkflowId())) {
+                    JSONObject jsonObject = workflowService.getActiveTask(Lists.newArrayList(purchasePrice1.getWorkflowId()), purchasePrice1.getId());
+                    taskId = jsonObject.getString("taskId");
+                    purchasePrice1.setTaskId(taskId);
+                }
+            });
+
+        }
         Page<PurchasePrice> page = new Page<>();
         page.setRecords(dataList == null ? Lists.newArrayList() : dataList);
         page.setTotal(dataCount == null ? 0 : dataCount);
@@ -70,6 +92,31 @@ public class PurchasePriceServiceImpl extends ServiceImpl<PurchasePriceMapper, P
             purchasePrice.setStatusFlag(StatusEnum.PURCHASE_REVIEWED.getFlag());
             // 操作主表数据
             this.insert(purchasePrice);
+            boolean isStartWorkflow = StringUtils.isBlank(purchasePrice.getWorkflowId());
+            // 不是退回的单子
+            if (isStartWorkflow) {
+                Workflow workflow = workflowService
+                        .findLatestWorkflowByBusinessCodeByApp(purchasePrice.getCompId(), "PROCUREMENT-PRICE-APPROVE");
+                // 没配置审核流程,直接结束并处理信息
+                if (workflow == null) {
+                    throw new YException(YExceptionEnum.PURCHASE_ORDER_ERROR);
+                }
+                // 开启审核流
+                else {
+
+                    // 设置状态 已提交审核
+                    purchasePrice.setWorkflowId(workflow.getId());
+                    this.updateById(purchasePrice);
+                    workflowService.startInstance(workflow.getId(), purchasePrice.getId());
+                }
+            }
+            // 退回的单子 再启用
+            else {
+
+                this.updateById(purchasePrice);
+                workflowService.activateInstance(purchasePrice.getWorkflowId(), purchasePrice.getId());
+            }
+
             // 操作明细表数据
             for(PurchasePriceDetail tmp : purchasePrice.getDetails()){
                 tmp.setId(IdGenerator.generateUUID());
@@ -123,6 +170,30 @@ public class PurchasePriceServiceImpl extends ServiceImpl<PurchasePriceMapper, P
             tmp.setMainId(purchasePrice.getId());
             this.purchasePriceDetailPrintMapper.insert(tmp);
         }
+        boolean isStartWorkflow = StringUtils.isBlank(purchasePrice.getWorkflowId());
+        // 不是退回的单子
+        if (isStartWorkflow) {
+            Workflow workflow = workflowService
+                    .findLatestWorkflowByBusinessCodeByApp(purchasePrice.getCompId(), "PROCUREMENT-PRICE-APPROVE");
+            // 没配置审核流程,直接结束并处理信息
+            if (workflow == null) {
+                throw new YException(YExceptionEnum.PURCHASE_ORDER_ERROR);
+            }
+            // 开启审核流
+            else {
+
+                // 设置状态 已提交审核
+                purchasePrice.setWorkflowId(workflow.getId());
+                this.updateById(purchasePrice);
+                workflowService.startInstance(workflow.getId(), purchasePrice.getId());
+            }
+        }
+        // 退回的单子 再启用
+        else {
+
+            this.updateById(purchasePrice);
+            workflowService.activateInstance(purchasePrice.getWorkflowId(), purchasePrice.getId());
+        }
         return "ok";
     }