Commit 97cec2897b85c9afddc6f52c93118c23817c379e

Authored by jason
1 parent a4244ab9

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

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> {
35 35 // 50 ~ 条件分支
36 36 CONDITION_NODE(50, "条件", "sequenceFlow"), // 用于构建流转条件的表达式
37 37 CONDITION_BRANCH_NODE(51, "条件分支", "exclusiveGateway"),
38   - PARALLEL_BRANCH_NODE(52, "并行分支", "parallelGateway"),
  38 + PARALLEL_BRANCH_NODE(52, "并行分支", "inclusiveGateway"), // 并行分支使用包容网关实现,条件表达式结果设置为 true
39 39 INCLUSIVE_BRANCH_NODE(53, "包容分支", "inclusiveGateway"),
40 40 ROUTER_BRANCH_NODE(54, "路由分支", "exclusiveGateway")
41 41 ;
... ...
yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/SimpleModelUtils.java
... ... @@ -239,13 +239,13 @@ public class SimpleModelUtils {
239 239 // 3.1 分支有后续节点。即分支 1: A->B->C->D 的情况
240 240 if (isValidNode(conditionChildNode)) {
241 241 // 3.1.1 建立与后续的节点的连线。例如说,建立 A->B 的连线
242   - SequenceFlow sequenceFlow = ConditionNodeConvert.buildSequenceFlow(node.getId(), conditionChildNode.getId(), item);
  242 + SequenceFlow sequenceFlow = ConditionNodeConvert.buildSequenceFlow(node.getId(), conditionChildNode.getId(), nodeType, item);
243 243 process.addFlowElement(sequenceFlow);
244 244 // 3.1.2 递归调用后续节点连线。例如说,建立 B->C->D 的连线
245 245 traverseNodeToBuildSequenceFlow(process, conditionChildNode, branchEndNodeId);
246 246 } else {
247 247 // 3.2 分支没有后续节点。例如说,建立 A->D 的连线
248   - SequenceFlow sequenceFlow = ConditionNodeConvert.buildSequenceFlow(node.getId(), branchEndNodeId, item);
  248 + SequenceFlow sequenceFlow = ConditionNodeConvert.buildSequenceFlow(node.getId(), branchEndNodeId, nodeType, item);
249 249 process.addFlowElement(sequenceFlow);
250 250 }
251 251 }
... ... @@ -591,17 +591,22 @@ public class SimpleModelUtils {
591 591  
592 592 private static class ParallelBranchNodeConvert implements NodeConvert {
593 593  
  594 + /**
  595 + * 并行分支使用包容网关。需要设置所有出口条件表达式的值为 true.
  596 + * 参见: {@link ConditionNodeConvert#buildSequenceFlow}
  597 + */
594 598 @Override
595   - public List<ParallelGateway> convertList(BpmSimpleModelNodeVO node) {
596   - ParallelGateway parallelGateway = new ParallelGateway();
597   - parallelGateway.setId(node.getId());
  599 + public List<InclusiveGateway> convertList(BpmSimpleModelNodeVO node) {
  600 +
  601 + InclusiveGateway inclusiveGateway = new InclusiveGateway();
  602 + inclusiveGateway.setId(node.getId());
598 603 // TODO @jason:setName
599 604  
600   - // 并行聚合网关由程序创建,前端不需要传入
601   - ParallelGateway joinParallelGateway = new ParallelGateway();
  605 + // 合并网关 由程序创建,前端不需要传入
  606 + InclusiveGateway joinParallelGateway = new InclusiveGateway();
602 607 joinParallelGateway.setId(buildGatewayJoinId(node.getId()));
603 608 // TODO @jason:setName
604   - return CollUtil.newArrayList(parallelGateway, joinParallelGateway);
  609 + return CollUtil.newArrayList(inclusiveGateway, joinParallelGateway);
605 610 }
606 611  
607 612 @Override
... ... @@ -652,8 +657,14 @@ public class SimpleModelUtils {
652 657 }
653 658  
654 659 public static SequenceFlow buildSequenceFlow(String sourceId, String targetId,
655   - BpmSimpleModelNodeVO node) {
656   - String conditionExpression = buildConditionExpression(node.getConditionSetting());
  660 + BpmSimpleModelNodeTypeEnum nodeType, BpmSimpleModelNodeVO node) {
  661 + String conditionExpression;
  662 + // 并行分支,使用包容网关实现,强制设置条件表达式为 true
  663 + if (BpmSimpleModelNodeTypeEnum.PARALLEL_BRANCH_NODE == nodeType) {
  664 + conditionExpression ="${true}";
  665 + } else {
  666 + conditionExpression = buildConditionExpression(node.getConditionSetting());
  667 + }
657 668 return buildBpmnSequenceFlow(sourceId, targetId, node.getId(), node.getName(), conditionExpression);
658 669 }
659 670 }
... ... @@ -662,7 +673,6 @@ public class SimpleModelUtils {
662 673 * 构造条件表达式
663 674 */
664 675 public static String buildConditionExpression(BpmSimpleModelNodeVO.ConditionSetting conditionSetting) {
665   - // 并行网关不需要设置条件
666 676 if (conditionSetting == null) {
667 677 return null;
668 678 }
... ...