Bläddra i källkod

子节点逻辑修改

ye-zhaojia 1 dag sedan
förälder
incheckning
331a9d6088

+ 1 - 0
src/main/java/com/qqflow/engine/domain/flow/model/SubNodeConfig.java

@@ -12,6 +12,7 @@ public class SubNodeConfig {
 
     private String id;
     private String name;
+    private String assigneeType;
     private String assigneeValue;
     private String approveMode;
     private Integer timeoutHours;

+ 28 - 11
src/main/java/com/qqflow/engine/domain/flow/service/impl/FlowEngineServiceImpl.java

@@ -259,15 +259,6 @@ public class FlowEngineServiceImpl implements FlowEngineService {
         return -1;
     }
 
-    private List<Long> calculateSubNodeAssignees(SubNodeConfig subNode, FlowNode parentNode, ProcessInstance instance) {
-        String assigneeValue = subNode.getAssigneeValue();
-        if (assigneeValue == null || assigneeValue.isBlank()) {
-            // 子节点未配置审批人时,回退到父节点配置
-            return this.calculateAssignees(parentNode, instance);
-        }
-        return this.doCalculateAssignees(ASSIGNEE_TYPE_ROLE, assigneeValue, instance);
-    }
-
     private String getSubNodeApproveMode(SubNodeConfig subNode) {
         String mode = subNode.getApproveMode();
         return mode != null ? mode : "or";
@@ -912,8 +903,24 @@ public class FlowEngineServiceImpl implements FlowEngineService {
     }
 
     private void createSubNodeTask(ProcessInstance instance, FlowNode parentNode, SubNodeConfig subNode, FlowModel model) {
-        List<Long> assignees = this.calculateSubNodeAssignees(subNode, parentNode, instance);
-        String taskAssigneeType = ASSIGNEE_TYPE_ROLE;
+        String subAssigneeType = subNode.getAssigneeType();
+        if (subAssigneeType == null || subAssigneeType.isBlank()) {
+            subAssigneeType = ASSIGNEE_TYPE_ROLE;
+        }
+        String subAssigneeValue = subNode.getAssigneeValue();
+        List<Long> assignees;
+        String taskAssigneeType;
+        if ("SELF".equals(subAssigneeType)) {
+            assignees = this.doCalculateAssignees("SELF", null, instance);
+            taskAssigneeType = ASSIGNEE_TYPE_USER;
+        } else if (subAssigneeValue != null && !subAssigneeValue.isBlank()) {
+            assignees = this.doCalculateAssignees(subAssigneeType, subAssigneeValue, instance);
+            taskAssigneeType = "USER".equals(subAssigneeType) ? ASSIGNEE_TYPE_USER : ASSIGNEE_TYPE_ROLE;
+        } else {
+            // 子节点未配置审批人时,回退到父节点配置
+            assignees = this.calculateAssignees(parentNode, instance);
+            taskAssigneeType = this.getNodeAssigneeType(parentNode);
+        }
         if (assignees.isEmpty()) {
             assignees = Collections.singletonList(instance.getApplicantId());
             taskAssigneeType = ASSIGNEE_TYPE_USER;
@@ -931,6 +938,16 @@ public class FlowEngineServiceImpl implements FlowEngineService {
         }
     }
 
+    private String getNodeAssigneeType(FlowNode node) {
+        Map<String, Object> props = node.getProperties();
+        if (props == null) {
+            return ASSIGNEE_TYPE_ROLE;
+        }
+        Object typeObj = props.get("assigneeType");
+        String type = typeObj != null ? typeObj.toString() : ASSIGNEE_TYPE_ROLE;
+        return ("SELF".equals(type) || "USER".equals(type)) ? ASSIGNEE_TYPE_USER : ASSIGNEE_TYPE_ROLE;
+    }
+
     /**
      * 处理子节点审批通过。
      * 返回 true 表示父节点已可继续推进主流程;false 表示仍需等待其他子节点。

+ 4 - 4
src/test/java/com/qqflow/engine/domain/flow/service/FlowSubNodeServiceTest.java

@@ -269,8 +269,8 @@ class FlowSubNodeServiceTest {
     }
 
     private Long createDefinitionWithSubNodes(String subNodeMode) {
-        String subNodes = "[{\"id\":\"sub1\",\"name\":\"初审\",\"assigneeValue\":\"super_admin\",\"approveMode\":\"or\"}"
-                + ",{\"id\":\"sub2\",\"name\":\"复审\",\"assigneeValue\":\"super_admin\",\"approveMode\":\"or\"}]";
+        String subNodes = "[{\"id\":\"sub1\",\"name\":\"初审\",\"assigneeType\":\"ROLE\",\"assigneeValue\":\"super_admin\",\"approveMode\":\"or\"}"
+                + ",{\"id\":\"sub2\",\"name\":\"复审\",\"assigneeType\":\"ROLE\",\"assigneeValue\":\"super_admin\",\"approveMode\":\"or\"}]";
         String modelJson = "{\"nodes\":[" +
                 "{\"id\":\"start\",\"type\":\"start\"}" +
                 ", {\"id\":\"approval\",\"type\":\"approval\",\"name\":\"审批\"," +
@@ -322,8 +322,8 @@ class FlowSubNodeServiceTest {
     }
 
     private Long createDefinitionWithSubNodesAndNextApproval() {
-        String subNodes = "[{\"id\":\"sub1\",\"name\":\"初审\",\"assigneeValue\":\"super_admin\",\"approveMode\":\"or\"}" +
-                ",{\"id\":\"sub2\",\"name\":\"复审\",\"assigneeValue\":\"super_admin\",\"approveMode\":\"or\"}]";
+        String subNodes = "[{\"id\":\"sub1\",\"name\":\"初审\",\"assigneeType\":\"ROLE\",\"assigneeValue\":\"super_admin\",\"approveMode\":\"or\"}" +
+                ",{\"id\":\"sub2\",\"name\":\"复审\",\"assigneeType\":\"ROLE\",\"assigneeValue\":\"super_admin\",\"approveMode\":\"or\"}]";
         String modelJson = "{\"nodes\":["
                 + "{\"id\":\"start\",\"type\":\"start\"}"
                 + ", {\"id\":\"approval\",\"type\":\"approval\",\"name\":\"一级审批\","