Commit c93d7eb9c0f21603c22c14fe456ec18d6ea54ccc
1 parent
e8c9c2ee
【功能优化】工作流:增加 SimpleModelUtils 遍历逻辑
Showing
3 changed files
with
81 additions
and
6 deletions
yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/definition/BpmSimpleModelNodeType.java
| ... | ... | @@ -28,8 +28,8 @@ public enum BpmSimpleModelNodeType implements IntArrayValuable { |
| 28 | 28 | |
| 29 | 29 | // 50 ~ 条件分支 |
| 30 | 30 | CONDITION_NODE(50, "sequenceFlow", "条件节点"), // 用于构建流转条件的表达式 |
| 31 | - CONDITION_BRANCH_NODE(51, "parallelGateway", "条件分支节点"), | |
| 32 | - PARALLEL_BRANCH_NODE(52, "exclusiveGateway", "并行分支节点"), | |
| 31 | + CONDITION_BRANCH_NODE(51, "exclusiveGateway", "条件分支节点"), | |
| 32 | + PARALLEL_BRANCH_NODE(52, "parallelGateway", "并行分支节点"), | |
| 33 | 33 | INCLUSIVE_BRANCH_NODE(53, "inclusiveGateway", "包容分支节点"), |
| 34 | 34 | ; |
| 35 | 35 | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/BpmnModelUtils.java
| ... | ... | @@ -705,10 +705,10 @@ public class BpmnModelUtils { |
| 705 | 705 | || currentElement instanceof UserTask |
| 706 | 706 | || currentElement instanceof ServiceTask) { |
| 707 | 707 | // 添加元素 |
| 708 | - FlowNode startEvent = (FlowNode) currentElement; | |
| 709 | - resultElements.add(startEvent); | |
| 708 | + FlowNode flowNode = (FlowNode) currentElement; | |
| 709 | + resultElements.add(flowNode); | |
| 710 | 710 | // 遍历子节点 |
| 711 | - startEvent.getOutgoingFlows().forEach( | |
| 711 | + flowNode.getOutgoingFlows().forEach( | |
| 712 | 712 | nextElement -> simulateNextFlowElements(nextElement.getTargetFlowElement(), variables, resultElements, visitElements)); |
| 713 | 713 | return; |
| 714 | 714 | } |
| ... | ... | @@ -755,6 +755,7 @@ public class BpmnModelUtils { |
| 755 | 755 | flow -> simulateNextFlowElements(flow.getTargetFlowElement(), variables, resultElements, visitElements)); |
| 756 | 756 | } |
| 757 | 757 | |
| 758 | + // 情况:ParallelGateway 并行,都满足,都走 | |
| 758 | 759 | if (currentElement instanceof ParallelGateway) { |
| 759 | 760 | Gateway gateway = (Gateway) currentElement; |
| 760 | 761 | // 遍历子节点 |
| ... | ... | @@ -771,7 +772,7 @@ public class BpmnModelUtils { |
| 771 | 772 | * @param express 条件表达式 |
| 772 | 773 | * @return 是否满足条件 |
| 773 | 774 | */ |
| 774 | - private static boolean evalConditionExpress(Map<String, Object> variables, String express) { | |
| 775 | + public static boolean evalConditionExpress(Map<String, Object> variables, String express) { | |
| 775 | 776 | ManagementService managementService = SpringUtil.getBean(ManagementService.class); |
| 776 | 777 | if (express == null) { |
| 777 | 778 | return Boolean.FALSE; | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/SimpleModelUtils.java
| ... | ... | @@ -608,4 +608,78 @@ public class SimpleModelUtils { |
| 608 | 608 | return id + "_join"; |
| 609 | 609 | } |
| 610 | 610 | |
| 611 | + // ========== SIMPLE 流程预测相关的方法 ========== | |
| 612 | + | |
| 613 | + public static List<BpmSimpleModelNodeVO> simulateProcess(BpmSimpleModelNodeVO rootNode, Map<String, Object> variables) { | |
| 614 | + List<BpmSimpleModelNodeVO> resultNodes = new ArrayList<>(); | |
| 615 | + | |
| 616 | + // 从头开始遍历 | |
| 617 | + simulateNextNode(rootNode, variables, resultNodes); | |
| 618 | + return resultNodes; | |
| 619 | + } | |
| 620 | + | |
| 621 | + private static void simulateNextNode(BpmSimpleModelNodeVO currentNode, Map<String, Object> variables, | |
| 622 | + List<BpmSimpleModelNodeVO> resultNodes) { | |
| 623 | + // 如果不合法(包括为空),则直接结束 | |
| 624 | + if (!isValidNode(currentNode)) { | |
| 625 | + return; | |
| 626 | + } | |
| 627 | + BpmSimpleModelNodeType nodeType = BpmSimpleModelNodeType.valueOf(currentNode.getType()); | |
| 628 | + Assert.notNull(nodeType, "模型节点类型不支持"); | |
| 629 | + | |
| 630 | + // 情况:START_NODE/START_USER_NODE/APPROVE_NODE/END_NODE | |
| 631 | + if (nodeType == BpmSimpleModelNodeType.START_NODE | |
| 632 | + || nodeType == BpmSimpleModelNodeType.START_USER_NODE | |
| 633 | + || nodeType == BpmSimpleModelNodeType.APPROVE_NODE | |
| 634 | + || nodeType == BpmSimpleModelNodeType.END_NODE) { | |
| 635 | + // 添加元素 | |
| 636 | + resultNodes.add(currentNode); | |
| 637 | + } | |
| 638 | + | |
| 639 | + // 情况:CONDITION_BRANCH_NODE 排它,只有一个满足条件的。如果没有,就走默认的 | |
| 640 | + if (nodeType == BpmSimpleModelNodeType.CONDITION_BRANCH_NODE) { | |
| 641 | + // 查找满足条件的 BpmSimpleModelNodeVO 节点 | |
| 642 | + BpmSimpleModelNodeVO matchConditionNode = CollUtil.findOne(currentNode.getConditionNodes(), | |
| 643 | + conditionNode -> BooleanUtil.isFalse(currentNode.getDefaultFlow()) | |
| 644 | + && evalConditionExpress(variables, conditionNode)); | |
| 645 | + if (matchConditionNode == null) { | |
| 646 | + matchConditionNode = CollUtil.findOne(currentNode.getConditionNodes(), | |
| 647 | + conditionNode -> BooleanUtil.isTrue(conditionNode.getDefaultFlow())); | |
| 648 | + } | |
| 649 | + Assert.notNull(matchConditionNode, "找不到条件节点({})", currentNode); | |
| 650 | + // 遍历满足条件的 BpmSimpleModelNodeVO 节点 | |
| 651 | + simulateNextNode(matchConditionNode.getChildNode(), variables, resultNodes); | |
| 652 | + } | |
| 653 | + | |
| 654 | + // 情况:INCLUSIVE_BRANCH_NODE 包容,多个满足条件的。如果没有,就走默认的 | |
| 655 | + if (nodeType == BpmSimpleModelNodeType.INCLUSIVE_BRANCH_NODE) { | |
| 656 | + // 查找满足条件的 BpmSimpleModelNodeVO 节点 | |
| 657 | + Collection<BpmSimpleModelNodeVO> matchConditionNodes = CollUtil.filterNew(currentNode.getConditionNodes(), | |
| 658 | + conditionNode -> BooleanUtil.isFalse(currentNode.getDefaultFlow()) | |
| 659 | + && evalConditionExpress(variables, conditionNode)); | |
| 660 | + if (CollUtil.isEmpty(matchConditionNodes)) { | |
| 661 | + matchConditionNodes = CollUtil.filterNew(currentNode.getConditionNodes(), | |
| 662 | + conditionNode -> BooleanUtil.isTrue(conditionNode.getDefaultFlow())); | |
| 663 | + } | |
| 664 | + Assert.isTrue(!matchConditionNodes.isEmpty(), "找不到条件节点({})", currentNode); | |
| 665 | + // 遍历满足条件的 BpmSimpleModelNodeVO 节点 | |
| 666 | + matchConditionNodes.forEach(matchConditionNode -> | |
| 667 | + simulateNextNode(matchConditionNode.getChildNode(), variables, resultNodes)); | |
| 668 | + } | |
| 669 | + | |
| 670 | + // 情况:PARALLEL_BRANCH_NODE 并行,都满足,都走 | |
| 671 | + if (nodeType == BpmSimpleModelNodeType.PARALLEL_BRANCH_NODE) { | |
| 672 | + // 遍历所有 BpmSimpleModelNodeVO 节点 | |
| 673 | + currentNode.getConditionNodes().forEach(matchConditionNode -> | |
| 674 | + simulateNextNode(matchConditionNode.getChildNode(), variables, resultNodes)); | |
| 675 | + } | |
| 676 | + | |
| 677 | + // 遍历子节点 | |
| 678 | + simulateNextNode(currentNode.getChildNode(), variables, resultNodes); | |
| 679 | + } | |
| 680 | + | |
| 681 | + public static boolean evalConditionExpress(Map<String, Object> variables, BpmSimpleModelNodeVO conditionNode) { | |
| 682 | + return BpmnModelUtils.evalConditionExpress(variables, ConditionNodeConvert.buildConditionExpression(conditionNode)); | |
| 683 | + } | |
| 684 | + | |
| 611 | 685 | } | ... | ... |