zhangyuewww 2 years ago
parent
commit
7fba7994bb

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

@@ -104,6 +104,8 @@ public class GeneralAuditInfo extends BaseModel<GeneralAuditInfo> {
      */
     @TableField(exist = false)
     private String searchKeyWord;
+    @TableField(exist = false)
+    private String taskId;
 
 
     @Override

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

@@ -1,16 +1,22 @@
 package com.yh.saas.plugin.yiliangyiyun.service.impl;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.plugins.Page;
 import com.google.common.collect.Lists;
 import com.winsea.svc.base.security.util.AuthSecurityUtils;
+import com.winsea.svc.base.workflow.entity.Workflow;
 import com.yh.saas.common.support.util.IdGenerator;
 import com.yh.saas.plugin.yiliangyiyun.entity.GeneralAuditInfo;
+import com.yh.saas.plugin.yiliangyiyun.exception.YException;
+import com.yh.saas.plugin.yiliangyiyun.exception.YExceptionEnum;
 import com.yh.saas.plugin.yiliangyiyun.mapper.GeneralAuditInfoMapper;
 import com.yh.saas.plugin.yiliangyiyun.service.IGeneralAuditInfoService;
 import com.baomidou.mybatisplus.service.impl.ServiceImpl;
 import com.yh.saas.plugin.yiliangyiyun.service.INewWorkflowService;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 
 import java.text.SimpleDateFormat;
 import java.util.*;
@@ -74,6 +80,17 @@ public class GeneralAuditInfoServiceImpl extends ServiceImpl<GeneralAuditInfoMap
         pageView.put("businessKeys", businessKeys);
         Integer dataCount = baseMapper.getCountByCondition(pageView);
         List<GeneralAuditInfo> dataList = baseMapper.getListByCondition(pageView);
+        if (!CollectionUtils.isEmpty(dataList)){
+            for (GeneralAuditInfo generalAuditInfo1:dataList){
+                String taskId = "";
+                // 只有待审核状态才有taskId
+                if (StringUtils.isNotBlank(generalAuditInfo1.getWorkflowId())) {
+                    JSONObject jsonObject = workflowService.getActiveTask(Lists.newArrayList(generalAuditInfo1.getWorkflowId()), generalAuditInfo1.getId());
+                    taskId = jsonObject.getString("taskId");
+                    generalAuditInfo1.setTaskId(taskId);
+                }
+            }
+        }
         Page<GeneralAuditInfo> page = new Page<>();
         page.setRecords(dataList == null ? Lists.newArrayList() : dataList);
         page.setTotal(dataCount == null ? 0 : dataCount);
@@ -121,6 +138,30 @@ public class GeneralAuditInfoServiceImpl extends ServiceImpl<GeneralAuditInfoMap
         generalAuditInfo.setAuditBusinessNo(no);
         // 操作主表数据
         this.insert(generalAuditInfo);
+        boolean isStartWorkflow = StringUtils.isBlank(generalAuditInfo.getWorkflowId());
+        // 不是退回的单子
+        if (isStartWorkflow) {
+            Workflow workflow = workflowService
+                    .findLatestWorkflowByBusinessCodeByApp(generalAuditInfo.getCompId(), "GENERAL-AUDIT-APPROVE");
+            // 没配置审核流程,直接结束并处理信息
+            if (workflow == null) {
+                throw new YException(YExceptionEnum.PURCHASE_ORDER_ERROR);
+            }
+            // 开启审核流
+            else {
+
+                // 设置状态 已提交审核
+                generalAuditInfo.setWorkflowId(workflow.getId());
+                this.updateById(generalAuditInfo);
+                workflowService.startInstance(workflow.getId(), generalAuditInfo.getId());
+            }
+        }
+        // 退回的单子 再启用
+        else {
+
+            this.updateById(generalAuditInfo);
+            workflowService.activateInstance(generalAuditInfo.getWorkflowId(), generalAuditInfo.getId());
+        }
         return generalAuditInfo.getId();
     }
 }