潘志宝
2024-12-03 51c1c2c9fa28fb1765dd6e81c70b78566792aebe
提交 | 用户 | 时间
e7c126 1 package com.iailab.module.bpm.framework.flowable.core.behavior;
H 2
3 import com.iailab.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateInvoker;
4 import com.iailab.module.bpm.framework.flowable.core.util.FlowableUtils;
5 import lombok.Setter;
6 import org.flowable.bpmn.model.Activity;
7 import org.flowable.engine.delegate.DelegateExecution;
8 import org.flowable.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior;
9 import org.flowable.engine.impl.bpmn.behavior.SequentialMultiInstanceBehavior;
10
11 import java.util.LinkedHashSet;
12 import java.util.Set;
13
14 /**
15  * 自定义的【串行】的【多个】流程任务的 assignee 负责人的分配
16  *
17  * 本质上,实现和 {@link BpmParallelMultiInstanceBehavior} 一样,只是继承的类不一样
18  *
19  * @author iailab
20  */
21 @Setter
22 public class BpmSequentialMultiInstanceBehavior extends SequentialMultiInstanceBehavior {
23
24     private BpmTaskCandidateInvoker taskCandidateInvoker;
25
26     public BpmSequentialMultiInstanceBehavior(Activity activity, AbstractBpmnActivityBehavior innerActivityBehavior) {
27         super(activity, innerActivityBehavior);
28     }
29
30     /**
31      * 逻辑和 {@link BpmParallelMultiInstanceBehavior#resolveNrOfInstances(DelegateExecution)} 类似
32      *
33      * 差异的点:是在【第二步】的时候,需要返回 LinkedHashSet 集合!因为它需要有序!
34      */
35     @Override
36     protected int resolveNrOfInstances(DelegateExecution execution) {
37         // 第一步,设置 collectionVariable 和 CollectionVariable
38         // 从  execution.getVariable() 读取所有任务处理人的 key
39         super.collectionExpression = null; // collectionExpression 和 collectionVariable 是互斥的
40         super.collectionVariable = FlowableUtils.formatExecutionCollectionVariable(execution.getCurrentActivityId());
41         // 从 execution.getVariable() 读取当前所有任务处理的人的 key
42         super.collectionElementVariable = FlowableUtils.formatExecutionCollectionElementVariable(execution.getCurrentActivityId());
43
44         // 第二步,获取任务的所有处理人
45         Set<Long> assigneeUserIds = new LinkedHashSet<>(taskCandidateInvoker.calculateUsers(execution)); // 保证有序!!!
46         execution.setVariable(super.collectionVariable, assigneeUserIds);
47         return assigneeUserIds.size();
48     }
49
50 }