Jelajahi Sumber

流程配置

24282 2 tahun lalu
induk
melakukan
d68aff27fd

+ 0 - 44
hx-flow/src/main/java/com/fjhx/flow/core/FlowThreadLocalData.java

@@ -1,44 +0,0 @@
-package com.fjhx.flow.core;
-
-import com.alibaba.fastjson.JSONObject;
-import com.fjhx.flow.enums.HandleTypeEnum;
-import lombok.Getter;
-import lombok.Setter;
-
-import java.util.Map;
-
-@Getter
-@Setter
-public class FlowThreadLocalData {
-
-    /**
-     * 流程id
-     */
-    private Long flowId;
-
-    /**
-     * 业务id
-     */
-    private Long businessId;
-
-    /**
-     * 当前节点提交参数
-     */
-    private JSONObject currentData;
-
-    /**
-     * 发起流程提交参数
-     */
-    private JSONObject startData;
-
-    /**
-     * 模板配置参数
-     */
-    private Map<String, Object> templateData;
-
-    /**
-     * 处理类型
-     */
-    private HandleTypeEnum handleTypeEnum;
-
-}

+ 107 - 24
hx-flow/src/main/java/com/fjhx/flow/core/FlowThreadLocalUtil.java

@@ -1,6 +1,7 @@
 package com.fjhx.flow.core;
 
 import com.alibaba.fastjson.JSONObject;
+import com.fjhx.flow.enums.FlowStatusEnum;
 import com.fjhx.flow.enums.HandleTypeEnum;
 import org.springframework.core.NamedThreadLocal;
 
@@ -8,66 +9,148 @@ import java.util.Map;
 
 public class FlowThreadLocalUtil {
 
-    private static final ThreadLocal<FlowThreadLocalData> FLOW_HOLDER = new NamedThreadLocal<>("hx-flow");
-
+    private static final ThreadLocal<FlowThreadLocalUtil> FLOW_HOLDER = new NamedThreadLocal<>("hx-flow");
+
+    /**
+     * 流程id
+     */
+    private Long flowId;
+
+    /**
+     * 业务id
+     */
+    private Long businessId;
+
+    /**
+     * 当前节点提交参数
+     */
+    private JSONObject currentData;
+
+    /**
+     * 发起流程提交参数
+     */
+    private JSONObject startData;
+
+    /**
+     * 模板配置参数
+     */
+    private Map<String, Object> templateData;
+
+    /**
+     * 流程处理类型
+     */
+    private HandleTypeEnum handleTypeEnum;
+
+    /**
+     * 流程状态
+     */
+    private FlowStatusEnum flowStatusEnum;
+
+    /**
+     * 下个节点审批用户id
+     */
+    private Long nextHandleUserId;
+
+    // ===================================================
+    //  流程id
+    // ===================================================
     public static Long getFlowId() {
-        return getData().getFlowId();
+        return getData().flowId;
     }
+
     public static void setFlowId(Long flowId) {
-        getData().setFlowId(flowId);
+        getData().flowId = flowId;
     }
 
-
+    // ===================================================
+    //  业务id
+    // ===================================================
     public static Long getBusinessId() {
-        return getData().getBusinessId();
+        return getData().businessId;
     }
+
     public static void setBusinessId(Long businessId) {
-        getData().setBusinessId(businessId);
+        getData().businessId = businessId;
     }
 
-
+    // ===================================================
+    //  当前节点提交参数
+    // ===================================================
     public static JSONObject getCurrentData() {
-        return getData().getCurrentData();
+        return getData().currentData;
     }
+
     public static <T> T getCurrentData(Class<T> cls) {
-        return getData().getCurrentData().toJavaObject(cls);
+        return getData().currentData.toJavaObject(cls);
     }
+
     public static void setCurrentData(JSONObject currentData) {
-        getData().setCurrentData(currentData);
+        getData().currentData = currentData;
     }
 
-
+    // ===================================================
+    //  发起流程提交参数
+    // ===================================================
     public static JSONObject getStartData() {
-        return getData().getStartData();
+        return getData().startData;
     }
+
     public static <T> T getStartData(Class<T> cls) {
-        return getData().getStartData().toJavaObject(cls);
+        return getData().startData.toJavaObject(cls);
     }
+
     public static void setStartData(JSONObject startData) {
-        getData().setStartData(startData);
+        getData().startData = startData;
     }
 
-
+    // ===================================================
+    //  模板配置参数
+    // ===================================================
     public static Map<String, Object> getTemplateData() {
-        return getData().getTemplateData();
+        return getData().templateData;
     }
+
     public static void setTemplateData(Map<String, Object> templateData) {
-        getData().setTemplateData(templateData);
+        getData().templateData = templateData;
     }
 
-
+    // ===================================================
+    //  流程处理类型
+    // ===================================================
     public static HandleTypeEnum getHandleTypeEnum() {
-        return getData().getHandleTypeEnum();
+        return getData().handleTypeEnum;
     }
+
     public static void setHandleTypeEnum(HandleTypeEnum handleTypeEnum) {
-        getData().setHandleTypeEnum(handleTypeEnum);
+        getData().handleTypeEnum = handleTypeEnum;
+    }
+
+    // ===================================================
+    //  流程状态
+    // ===================================================
+    public static FlowStatusEnum getFlowStatusEnum() {
+        return getData().flowStatusEnum;
     }
 
+    public static void setFlowStatusEnum(FlowStatusEnum flowStatusEnum) {
+        getData().flowStatusEnum = flowStatusEnum;
+    }
+
+    // ===================================================
+    //  下个节点审批用户id
+    // ===================================================
+    public static Long getNextHandleUserId() {
+        return getData().nextHandleUserId;
+    }
+
+    public static void setNextHandleUserId(Long nextHandleUserId) {
+        getData().nextHandleUserId = nextHandleUserId;
+    }
 
-    private static FlowThreadLocalData getData() {
-        FlowThreadLocalData flowThreadLocalData = FLOW_HOLDER.get();
+    private static FlowThreadLocalUtil getData() {
+        FlowThreadLocalUtil flowThreadLocalData = FLOW_HOLDER.get();
         if (flowThreadLocalData == null) {
-            flowThreadLocalData = new FlowThreadLocalData();
+            flowThreadLocalData = new FlowThreadLocalUtil();
             FLOW_HOLDER.set(flowThreadLocalData);
         }
         return flowThreadLocalData;

+ 15 - 10
hx-flow/src/main/java/com/fjhx/flow/service/flow/impl/FlowProcessServiceImpl.java

@@ -114,12 +114,19 @@ public class FlowProcessServiceImpl implements FlowProcessService {
             // 如果下一节点处理用户只有1人,赋值用户id
             if (handleUser.getSuccess()) {
                 flowExample.setHandleUserId(handleUser.getUserId());
+                FlowThreadLocalUtil.setNextHandleUserId(handleUser.getUserId());
             }
             // 如果下一节点处理用户有多人,则返回用户列表让用户选择下一节点处理人id
             else {
                 return handleUser;
             }
-
+            // 流程已通过
+            flowExample.setStatus(FlowStatusEnum.HAVE_PASSED.getKey());
+            FlowThreadLocalUtil.setFlowStatusEnum(FlowStatusEnum.IN_PROGRESS);
+        } else {
+            // 流程进行中
+            flowExample.setStatus(FlowStatusEnum.IN_PROGRESS.getKey());
+            FlowThreadLocalUtil.setFlowStatusEnum(FlowStatusEnum.HAVE_PASSED);
         }
 
         // 执行开始流程方法
@@ -158,15 +165,6 @@ public class FlowProcessServiceImpl implements FlowProcessService {
             endExampleDetail.setFlowDefinitionNodeType(nextUserNode.getNodeType());
             endExampleDetail.setHandleType(HandleTypeEnum.OVER.getKey());
             flowExampleDetailList.add(endExampleDetail);
-
-            // 流程已通过
-            flowExample.setStatus(FlowStatusEnum.HAVE_PASSED.getKey());
-
-        } else {
-
-            // 流程进行中
-            flowExample.setStatus(FlowStatusEnum.IN_PROGRESS.getKey());
-
         }
 
         flowExample.setTitle(StrUtil.format(flowDefinition.getTitleTemplate(), templateMap, true));
@@ -248,6 +246,7 @@ public class FlowProcessServiceImpl implements FlowProcessService {
                 if (NodeTypeEnum.END.equals(NodeTypeEnum.getEnum(nextUserNode.getNodeType()))) {
                     // 流程已通过
                     flowExample.setStatus(FlowStatusEnum.HAVE_PASSED.getKey());
+                    FlowThreadLocalUtil.setFlowStatusEnum(FlowStatusEnum.HAVE_PASSED);
                 } else {
 
                     FlowResult handleUser = getHandleUser(nextUserNode, dto.getHandleUserId());
@@ -255,6 +254,7 @@ public class FlowProcessServiceImpl implements FlowProcessService {
                     // 如果下一节点处理用户只有1人,赋值用户id
                     if (handleUser.getSuccess()) {
                         flowExample.setHandleUserId(handleUser.getUserId());
+                        FlowThreadLocalUtil.setNextHandleUserId(handleUser.getUserId());
                     }
                     // 如果下一节点处理用户有多人,则返回用户列表让用户选择下一节点处理人id
                     else {
@@ -263,6 +263,7 @@ public class FlowProcessServiceImpl implements FlowProcessService {
 
                     // 流程进行中
                     flowExample.setStatus(FlowStatusEnum.IN_PROGRESS.getKey());
+                    FlowThreadLocalUtil.setFlowStatusEnum(FlowStatusEnum.IN_PROGRESS);
                 }
                 break;
 
@@ -274,19 +275,23 @@ public class FlowProcessServiceImpl implements FlowProcessService {
                 // 赋值流程所在id
                 flowExample.setDefinitionNodeId(lastOneFlowExampleDetail.getFlowDefinitionNodeId());
                 flowExample.setHandleUserId(lastOneFlowExampleDetail.getCreateUser());
+                FlowThreadLocalUtil.setNextHandleUserId(lastOneFlowExampleDetail.getCreateUser());
 
                 // 如果流程回退到开始节点
                 if (NodeTypeEnum.START.getKey().equals(lastOneFlowExampleDetail.getFlowDefinitionNodeType())) {
                     // 流程未发起
                     flowExample.setStatus(FlowStatusEnum.UNINITIATED.getKey());
+                    FlowThreadLocalUtil.setFlowStatusEnum(FlowStatusEnum.UNINITIATED);
                 } else {
                     // 流程进行中
                     flowExample.setStatus(FlowStatusEnum.IN_PROGRESS.getKey());
+                    FlowThreadLocalUtil.setFlowStatusEnum(FlowStatusEnum.IN_PROGRESS);
                 }
                 break;
 
             case OVER:
                 flowExample.setStatus(FlowStatusEnum.REJECTED.getKey());
+                FlowThreadLocalUtil.setFlowStatusEnum(FlowStatusEnum.REJECTED);
                 break;
 
             default: