瀏覽代碼

feat: [BPM 工作流] 并行分支使用包容网关实现

jason 3 月之前
父節點
當前提交
97cec2897b

+ 1 - 1
yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/enums/definition/BpmSimpleModelNodeTypeEnum.java

@@ -35,7 +35,7 @@ public enum BpmSimpleModelNodeTypeEnum implements ArrayValuable<Integer> {
     // 50 ~ 条件分支
     CONDITION_NODE(50, "条件", "sequenceFlow"), // 用于构建流转条件的表达式
     CONDITION_BRANCH_NODE(51, "条件分支", "exclusiveGateway"),
-    PARALLEL_BRANCH_NODE(52, "并行分支", "parallelGateway"),
+    PARALLEL_BRANCH_NODE(52, "并行分支", "inclusiveGateway"), // 并行分支使用包容网关实现,条件表达式结果设置为 true
     INCLUSIVE_BRANCH_NODE(53, "包容分支", "inclusiveGateway"),
     ROUTER_BRANCH_NODE(54, "路由分支", "exclusiveGateway")
     ;

+ 21 - 11
yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/SimpleModelUtils.java

@@ -239,13 +239,13 @@ public class SimpleModelUtils {
                 // 3.1 分支有后续节点。即分支 1: A->B->C->D 的情况
                 if (isValidNode(conditionChildNode)) {
                     // 3.1.1 建立与后续的节点的连线。例如说,建立 A->B 的连线
-                    SequenceFlow sequenceFlow = ConditionNodeConvert.buildSequenceFlow(node.getId(), conditionChildNode.getId(), item);
+                    SequenceFlow sequenceFlow = ConditionNodeConvert.buildSequenceFlow(node.getId(), conditionChildNode.getId(), nodeType, item);
                     process.addFlowElement(sequenceFlow);
                     // 3.1.2 递归调用后续节点连线。例如说,建立 B->C->D 的连线
                     traverseNodeToBuildSequenceFlow(process, conditionChildNode, branchEndNodeId);
                 } else {
                     // 3.2 分支没有后续节点。例如说,建立 A->D 的连线
-                    SequenceFlow sequenceFlow = ConditionNodeConvert.buildSequenceFlow(node.getId(), branchEndNodeId, item);
+                    SequenceFlow sequenceFlow = ConditionNodeConvert.buildSequenceFlow(node.getId(), branchEndNodeId, nodeType, item);
                     process.addFlowElement(sequenceFlow);
                 }
             }
@@ -591,17 +591,22 @@ public class SimpleModelUtils {
 
     private static class ParallelBranchNodeConvert implements NodeConvert {
 
+        /**
+         * 并行分支使用包容网关。需要设置所有出口条件表达式的值为 true.
+         * 参见: {@link ConditionNodeConvert#buildSequenceFlow}
+         */
         @Override
-        public List<ParallelGateway> convertList(BpmSimpleModelNodeVO node) {
-            ParallelGateway parallelGateway = new ParallelGateway();
-            parallelGateway.setId(node.getId());
+        public List<InclusiveGateway> convertList(BpmSimpleModelNodeVO node) {
+
+            InclusiveGateway inclusiveGateway = new InclusiveGateway();
+            inclusiveGateway.setId(node.getId());
             // TODO @jason:setName
 
-            // 并行聚合网关由程序创建,前端不需要传入
-            ParallelGateway joinParallelGateway = new ParallelGateway();
+            // 并网关 由程序创建,前端不需要传入
+            InclusiveGateway joinParallelGateway = new InclusiveGateway();
             joinParallelGateway.setId(buildGatewayJoinId(node.getId()));
             // TODO @jason:setName
-            return CollUtil.newArrayList(parallelGateway, joinParallelGateway);
+            return CollUtil.newArrayList(inclusiveGateway, joinParallelGateway);
         }
 
         @Override
@@ -652,8 +657,14 @@ public class SimpleModelUtils {
         }
 
         public static SequenceFlow buildSequenceFlow(String sourceId, String targetId,
-                                                     BpmSimpleModelNodeVO node) {
-            String conditionExpression = buildConditionExpression(node.getConditionSetting());
+                                                     BpmSimpleModelNodeTypeEnum nodeType, BpmSimpleModelNodeVO node) {
+            String conditionExpression;
+            // 并行分支,使用包容网关实现,强制设置条件表达式为 true
+            if (BpmSimpleModelNodeTypeEnum.PARALLEL_BRANCH_NODE == nodeType) {
+                conditionExpression ="${true}";
+            } else {
+                conditionExpression = buildConditionExpression(node.getConditionSetting());
+            }
             return buildBpmnSequenceFlow(sourceId, targetId, node.getId(), node.getName(), conditionExpression);
         }
     }
@@ -662,7 +673,6 @@ public class SimpleModelUtils {
      * 构造条件表达式
      */
     public static String buildConditionExpression(BpmSimpleModelNodeVO.ConditionSetting conditionSetting) {
-        // 并行网关不需要设置条件
         if (conditionSetting == null) {
             return null;
         }