Commit 11e19414b17a75a4ae5c8c8e966b1b9034fc4ae7

Authored by 芋道源码
Committed by Gitee
2 parents 696463d9 6816821e

!1494 refactor(bpm): 优化并行和串行多实例行为实现

Merge pull request !1494 from ssw/master-jdk17
yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/behavior/BpmParallelMultiInstanceBehavior.java
@@ -14,6 +14,7 @@ import org.flowable.bpmn.model.UserTask; @@ -14,6 +14,7 @@ import org.flowable.bpmn.model.UserTask;
14 import org.flowable.engine.delegate.DelegateExecution; 14 import org.flowable.engine.delegate.DelegateExecution;
15 import org.flowable.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior; 15 import org.flowable.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior;
16 import org.flowable.engine.impl.bpmn.behavior.ParallelMultiInstanceBehavior; 16 import org.flowable.engine.impl.bpmn.behavior.ParallelMultiInstanceBehavior;
  17 +import org.flowable.common.engine.api.delegate.Expression;
17 18
18 import java.util.List; 19 import java.util.List;
19 import java.util.Set; 20 import java.util.Set;
@@ -56,14 +57,7 @@ public class BpmParallelMultiInstanceBehavior extends ParallelMultiInstanceBehav @@ -56,14 +57,7 @@ public class BpmParallelMultiInstanceBehavior extends ParallelMultiInstanceBehav
56 protected int resolveNrOfInstances(DelegateExecution execution) { 57 protected int resolveNrOfInstances(DelegateExecution execution) {
57 // 情况一:UserTask 节点 58 // 情况一:UserTask 节点
58 if (execution.getCurrentFlowElement() instanceof UserTask) { 59 if (execution.getCurrentFlowElement() instanceof UserTask) {
59 - // 第一步,设置 collectionVariable 和 CollectionVariable  
60 - // 从 execution.getVariable() 读取所有任务处理人的 key  
61 - super.collectionExpression = null; // collectionExpression 和 collectionVariable 是互斥的  
62 - super.collectionVariable = FlowableUtils.formatExecutionCollectionVariable(execution.getCurrentActivityId());  
63 - // 从 execution.getVariable() 读取当前所有任务处理的人的 key  
64 - super.collectionElementVariable = FlowableUtils.formatExecutionCollectionElementVariable(execution.getCurrentActivityId());  
65 -  
66 - // 第二步,获取任务的所有处理人 60 + // 获取任务的所有处理人
67 @SuppressWarnings("unchecked") 61 @SuppressWarnings("unchecked")
68 Set<Long> assigneeUserIds = (Set<Long>) execution.getVariable(super.collectionVariable, Set.class); 62 Set<Long> assigneeUserIds = (Set<Long>) execution.getVariable(super.collectionVariable, Set.class);
69 if (assigneeUserIds == null) { 63 if (assigneeUserIds == null) {
@@ -94,4 +88,21 @@ public class BpmParallelMultiInstanceBehavior extends ParallelMultiInstanceBehav @@ -94,4 +88,21 @@ public class BpmParallelMultiInstanceBehavior extends ParallelMultiInstanceBehav
94 return super.resolveNrOfInstances(execution); 88 return super.resolveNrOfInstances(execution);
95 } 89 }
96 90
  91 + // ========== 屏蔽解析器覆写 ==========
  92 +
  93 + @Override
  94 + public void setCollectionExpression(Expression collectionExpression) {
  95 + // 保持自定义变量名,忽略解析器写入的 collection 表达式
  96 + }
  97 +
  98 + @Override
  99 + public void setCollectionVariable(String collectionVariable) {
  100 + // 保持自定义变量名,忽略解析器写入的 collection 变量名
  101 + }
  102 +
  103 + @Override
  104 + public void setCollectionElementVariable(String collectionElementVariable) {
  105 + // 保持自定义变量名,忽略解析器写入的单元素变量名
  106 + }
  107 +
97 } 108 }
yudao-module-bpm/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/behavior/BpmSequentialMultiInstanceBehavior.java
@@ -47,14 +47,7 @@ public class BpmSequentialMultiInstanceBehavior extends SequentialMultiInstanceB @@ -47,14 +47,7 @@ public class BpmSequentialMultiInstanceBehavior extends SequentialMultiInstanceB
47 protected int resolveNrOfInstances(DelegateExecution execution) { 47 protected int resolveNrOfInstances(DelegateExecution execution) {
48 // 情况一:UserTask 节点 48 // 情况一:UserTask 节点
49 if (execution.getCurrentFlowElement() instanceof UserTask) { 49 if (execution.getCurrentFlowElement() instanceof UserTask) {
50 - // 第一步,设置 collectionVariable 和 CollectionVariable  
51 - // 从 execution.getVariable() 读取所有任务处理人的 key  
52 - super.collectionExpression = null; // collectionExpression 和 collectionVariable 是互斥的  
53 - super.collectionVariable = FlowableUtils.formatExecutionCollectionVariable(execution.getCurrentActivityId());  
54 - // 从 execution.getVariable() 读取当前所有任务处理的人的 key  
55 - super.collectionElementVariable = FlowableUtils.formatExecutionCollectionElementVariable(execution.getCurrentActivityId());  
56 -  
57 - // 第二步,获取任务的所有处理人 50 + // 获取任务的所有处理人
58 // 不使用 execution.getVariable 原因:目前依次审批任务回退后 collectionVariable 变量没有清理, 如果重新进入该任务不会重新分配审批人 51 // 不使用 execution.getVariable 原因:目前依次审批任务回退后 collectionVariable 变量没有清理, 如果重新进入该任务不会重新分配审批人
59 @SuppressWarnings("unchecked") 52 @SuppressWarnings("unchecked")
60 Set<Long> assigneeUserIds = (Set<Long>) execution.getVariableLocal(super.collectionVariable, Set.class); 53 Set<Long> assigneeUserIds = (Set<Long>) execution.getVariableLocal(super.collectionVariable, Set.class);