Commit 8a3264cfd34b37fe49081c906d50615a1742e5e1
1 parent
5e15a100
review: 代码审查,方法抽取
Showing
1 changed file
with
46 additions
and
47 deletions
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/util/BpmnModelUtils.java
| ... | ... | @@ -808,53 +808,26 @@ public class BpmnModelUtils { |
| 808 | 808 | // 情况:ExclusiveGateway 排它,只有一个满足条件的。如果没有,就走默认的 |
| 809 | 809 | if (currentElement instanceof ExclusiveGateway) { |
| 810 | 810 | // 查找满足条件的 SequenceFlow 路径 |
| 811 | - Gateway gateway = (Gateway) currentElement; | |
| 812 | - // TODO @小北:当一个网关节点下存在多个满足的并行节点时,只查询一个节点流程流转会存在问题。需要优化,具体见issue:https://github.com/YunaiV/ruoyi-vue-pro/issues/761 | |
| 813 | - SequenceFlow matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(), | |
| 814 | - flow -> ObjUtil.notEqual(gateway.getDefaultFlow(), flow.getId()) | |
| 815 | - && (evalConditionExpress(variables, flow.getConditionExpression()))); | |
| 816 | - if (matchSequenceFlow == null) { | |
| 817 | - matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(), | |
| 818 | - flow -> ObjUtil.equal(gateway.getDefaultFlow(), flow.getId())); | |
| 819 | - // 特殊:没有默认的情况下,并且只有 1 个条件,则认为它是默认的 | |
| 820 | - if (matchSequenceFlow == null && gateway.getOutgoingFlows().size() == 1) { | |
| 821 | - matchSequenceFlow = gateway.getOutgoingFlows().get(0); | |
| 822 | - } | |
| 823 | - } | |
| 811 | + SequenceFlow matchSequenceFlow = findMatchSequenceFlow((Gateway) currentElement, variables); | |
| 824 | 812 | // 遍历满足条件的 SequenceFlow 路径 |
| 825 | 813 | if (matchSequenceFlow != null) { |
| 826 | 814 | simulateNextFlowElements(matchSequenceFlow.getTargetFlowElement(), variables, resultElements, visitElements); |
| 827 | 815 | } |
| 828 | - return; | |
| 829 | 816 | } |
| 830 | - | |
| 831 | 817 | // 情况:InclusiveGateway 包容,多个满足条件的。如果没有,就走默认的 |
| 832 | - if (currentElement instanceof InclusiveGateway) { | |
| 818 | + else if (currentElement instanceof InclusiveGateway) { | |
| 833 | 819 | // 查找满足条件的 SequenceFlow 路径 |
| 834 | - Gateway gateway = (Gateway) currentElement; | |
| 835 | - Collection<SequenceFlow> matchSequenceFlows = CollUtil.filterNew(gateway.getOutgoingFlows(), | |
| 836 | - flow -> ObjUtil.notEqual(gateway.getDefaultFlow(), flow.getId()) | |
| 837 | - && evalConditionExpress(variables, flow.getConditionExpression())); | |
| 838 | - if (CollUtil.isEmpty(matchSequenceFlows)) { | |
| 839 | - matchSequenceFlows = CollUtil.filterNew(gateway.getOutgoingFlows(), | |
| 840 | - flow -> ObjUtil.equal(gateway.getDefaultFlow(), flow.getId())); | |
| 841 | - // 特殊:没有默认的情况下,并且只有 1 个条件,则认为它是默认的 | |
| 842 | - if (CollUtil.isEmpty(matchSequenceFlows) && gateway.getOutgoingFlows().size() == 1) { | |
| 843 | - matchSequenceFlows = gateway.getOutgoingFlows(); | |
| 844 | - } | |
| 845 | - } | |
| 820 | + Collection<SequenceFlow> matchSequenceFlows = findMatchSequenceFlows((Gateway) currentElement, variables); | |
| 846 | 821 | // 遍历满足条件的 SequenceFlow 路径 |
| 847 | 822 | matchSequenceFlows.forEach( |
| 848 | 823 | flow -> simulateNextFlowElements(flow.getTargetFlowElement(), variables, resultElements, visitElements)); |
| 849 | 824 | } |
| 850 | - | |
| 851 | 825 | // 情况:ParallelGateway 并行,都满足,都走 |
| 852 | - if (currentElement instanceof ParallelGateway) { | |
| 826 | + else if (currentElement instanceof ParallelGateway) { | |
| 853 | 827 | Gateway gateway = (Gateway) currentElement; |
| 854 | 828 | // 遍历子节点 |
| 855 | 829 | gateway.getOutgoingFlows().forEach( |
| 856 | 830 | nextElement -> simulateNextFlowElements(nextElement.getTargetFlowElement(), variables, resultElements, visitElements)); |
| 857 | - return; | |
| 858 | 831 | } |
| 859 | 832 | } |
| 860 | 833 | |
| ... | ... | @@ -911,8 +884,25 @@ public class BpmnModelUtils { |
| 911 | 884 | */ |
| 912 | 885 | private static void handleExclusiveGateway(Gateway gateway, BpmnModel bpmnModel, |
| 913 | 886 | Map<String, Object> variables, List<FlowNode> nextFlowNodes) { |
| 914 | - // TODO @小北: 这里和 simulateNextFlowElements 中有重复代码,是否重构??每个网关节点拆分出方法应该比较合理化,@芋艿 | |
| 915 | - // TODO @小北:ok,把 simulateNextFlowElements 里面处理网关的,复用这个方法,可以么? | |
| 887 | + // 查找满足条件的 SequenceFlow 路径 | |
| 888 | + SequenceFlow matchSequenceFlow = findMatchSequenceFlow(gateway, variables); | |
| 889 | + // 遍历满足条件的 SequenceFlow 路径 | |
| 890 | + if (matchSequenceFlow != null) { | |
| 891 | + FlowElement targetElement = bpmnModel.getFlowElement(matchSequenceFlow.getTargetRef()); | |
| 892 | + if (targetElement instanceof FlowNode) { | |
| 893 | + nextFlowNodes.add((FlowNode) targetElement); | |
| 894 | + } | |
| 895 | + } | |
| 896 | + } | |
| 897 | + | |
| 898 | + /** | |
| 899 | + * 处理排它网关(Exclusive Gateway),选择符合条件的路径 | |
| 900 | + * | |
| 901 | + * @param gateway 排他网关 | |
| 902 | + * @param variables 流程变量 | |
| 903 | + * @return 符合条件的路径 | |
| 904 | + */ | |
| 905 | + private static SequenceFlow findMatchSequenceFlow(Gateway gateway, Map<String, Object> variables){ | |
| 916 | 906 | SequenceFlow matchSequenceFlow = CollUtil.findOne(gateway.getOutgoingFlows(), |
| 917 | 907 | flow -> ObjUtil.notEqual(gateway.getDefaultFlow(), flow.getId()) |
| 918 | 908 | && (evalConditionExpress(variables, flow.getConditionExpression()))); |
| ... | ... | @@ -924,13 +914,7 @@ public class BpmnModelUtils { |
| 924 | 914 | matchSequenceFlow = gateway.getOutgoingFlows().get(0); |
| 925 | 915 | } |
| 926 | 916 | } |
| 927 | - // 遍历满足条件的 SequenceFlow 路径 | |
| 928 | - if (matchSequenceFlow != null) { | |
| 929 | - FlowElement targetElement = bpmnModel.getFlowElement(matchSequenceFlow.getTargetRef()); | |
| 930 | - if (targetElement instanceof FlowNode) { | |
| 931 | - nextFlowNodes.add((FlowNode) targetElement); | |
| 932 | - } | |
| 933 | - } | |
| 917 | + return matchSequenceFlow; | |
| 934 | 918 | } |
| 935 | 919 | |
| 936 | 920 | /** |
| ... | ... | @@ -943,6 +927,26 @@ public class BpmnModelUtils { |
| 943 | 927 | */ |
| 944 | 928 | private static void handleInclusiveGateway(Gateway gateway, BpmnModel bpmnModel, |
| 945 | 929 | Map<String, Object> variables, List<FlowNode> nextFlowNodes) { |
| 930 | + // 查找满足条件的 SequenceFlow 路径集合 | |
| 931 | + Collection<SequenceFlow> matchSequenceFlows = findMatchSequenceFlows(gateway, variables); | |
| 932 | + // 遍历满足条件的 SequenceFlow 路径,获取目标节点 | |
| 933 | + matchSequenceFlows.forEach(flow -> { | |
| 934 | + FlowElement targetElement = bpmnModel.getFlowElement(flow.getTargetRef()); | |
| 935 | + if (targetElement instanceof FlowNode) { | |
| 936 | + nextFlowNodes.add((FlowNode) targetElement); | |
| 937 | + } | |
| 938 | + }); | |
| 939 | + } | |
| 940 | + | |
| 941 | + /** | |
| 942 | + * 处理排它网关(Inclusive Gateway),选择符合条件的路径 | |
| 943 | + * | |
| 944 | + * @param gateway 排他网关 | |
| 945 | + * @param variables 流程变量 | |
| 946 | + * @return 符合条件的路径 | |
| 947 | + */ | |
| 948 | + private static Collection<SequenceFlow> findMatchSequenceFlows(Gateway gateway, Map<String, Object> variables) { | |
| 949 | + // 查找满足条件的 SequenceFlow 路径 | |
| 946 | 950 | Collection<SequenceFlow> matchSequenceFlows = CollUtil.filterNew(gateway.getOutgoingFlows(), |
| 947 | 951 | flow -> ObjUtil.notEqual(gateway.getDefaultFlow(), flow.getId()) |
| 948 | 952 | && evalConditionExpress(variables, flow.getConditionExpression())); |
| ... | ... | @@ -954,15 +958,10 @@ public class BpmnModelUtils { |
| 954 | 958 | matchSequenceFlows = gateway.getOutgoingFlows(); |
| 955 | 959 | } |
| 956 | 960 | } |
| 957 | - // 遍历满足条件的 SequenceFlow 路径,获取目标节点 | |
| 958 | - matchSequenceFlows.forEach(flow -> { | |
| 959 | - FlowElement targetElement = bpmnModel.getFlowElement(flow.getTargetRef()); | |
| 960 | - if (targetElement instanceof FlowNode) { | |
| 961 | - nextFlowNodes.add((FlowNode) targetElement); | |
| 962 | - } | |
| 963 | - }); | |
| 961 | + return matchSequenceFlows; | |
| 964 | 962 | } |
| 965 | 963 | |
| 964 | + | |
| 966 | 965 | /** |
| 967 | 966 | * 处理并行网关 |
| 968 | 967 | * | ... | ... |