BPM:新增顺序会签、或签的能力

This commit is contained in:
YunaiV 2024-03-15 21:08:43 +08:00
parent f5f73adcbb
commit a1defeb48a
4 changed files with 63 additions and 8 deletions

View File

@ -6,6 +6,7 @@ import org.flowable.bpmn.model.Activity;
import org.flowable.bpmn.model.UserTask; import org.flowable.bpmn.model.UserTask;
import org.flowable.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior; import org.flowable.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior;
import org.flowable.engine.impl.bpmn.behavior.ParallelMultiInstanceBehavior; import org.flowable.engine.impl.bpmn.behavior.ParallelMultiInstanceBehavior;
import org.flowable.engine.impl.bpmn.behavior.SequentialMultiInstanceBehavior;
import org.flowable.engine.impl.bpmn.behavior.UserTaskActivityBehavior; import org.flowable.engine.impl.bpmn.behavior.UserTaskActivityBehavior;
import org.flowable.engine.impl.bpmn.parser.factory.DefaultActivityBehaviorFactory; import org.flowable.engine.impl.bpmn.parser.factory.DefaultActivityBehaviorFactory;
@ -28,11 +29,16 @@ public class BpmActivityBehaviorFactory extends DefaultActivityBehaviorFactory {
@Override @Override
public ParallelMultiInstanceBehavior createParallelMultiInstanceBehavior(Activity activity, public ParallelMultiInstanceBehavior createParallelMultiInstanceBehavior(Activity activity,
AbstractBpmnActivityBehavior innerActivityBehavior) { AbstractBpmnActivityBehavior behavior) {
return new BpmParallelMultiInstanceBehavior(activity, innerActivityBehavior) return new BpmParallelMultiInstanceBehavior(activity, behavior)
.setTaskCandidateInvoker(taskCandidateInvoker); .setTaskCandidateInvoker(taskCandidateInvoker);
} }
// TODO @keSequentialMultiInstanceBehavior 这个抽空也可以看看 @Override
public SequentialMultiInstanceBehavior createSequentialMultiInstanceBehavior(Activity activity,
AbstractBpmnActivityBehavior behavior) {
return new BpmSequentialMultiInstanceBehavior(activity, behavior)
.setTaskCandidateInvoker(taskCandidateInvoker);
}
} }

View File

@ -3,7 +3,6 @@ package cn.iocoder.yudao.module.bpm.framework.flowable.core.behavior;
import cn.iocoder.yudao.framework.flowable.core.util.FlowableUtils; import cn.iocoder.yudao.framework.flowable.core.util.FlowableUtils;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateInvoker; import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateInvoker;
import lombok.Setter; import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.flowable.bpmn.model.Activity; import org.flowable.bpmn.model.Activity;
import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior; import org.flowable.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior;
@ -17,12 +16,11 @@ import java.util.Set;
* 第二步多个任务候选人们设置到 DelegateExecution collectionVariable 变量中以便 BpmUserTaskActivityBehavior 使用它 * 第二步多个任务候选人们设置到 DelegateExecution collectionVariable 变量中以便 BpmUserTaskActivityBehavior 使用它
* *
* @author kemengkai * @author kemengkai
* @date 2022-04-21 16:57 * @since 2022-04-21 16:57
*/ */
@Slf4j @Setter
public class BpmParallelMultiInstanceBehavior extends ParallelMultiInstanceBehavior { public class BpmParallelMultiInstanceBehavior extends ParallelMultiInstanceBehavior {
@Setter
private BpmTaskCandidateInvoker taskCandidateInvoker; private BpmTaskCandidateInvoker taskCandidateInvoker;
public BpmParallelMultiInstanceBehavior(Activity activity, public BpmParallelMultiInstanceBehavior(Activity activity,

View File

@ -0,0 +1,50 @@
package cn.iocoder.yudao.module.bpm.framework.flowable.core.behavior;
import cn.iocoder.yudao.framework.flowable.core.util.FlowableUtils;
import cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.BpmTaskCandidateInvoker;
import lombok.Setter;
import org.flowable.bpmn.model.Activity;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior;
import org.flowable.engine.impl.bpmn.behavior.SequentialMultiInstanceBehavior;
import java.util.LinkedHashSet;
import java.util.Set;
/**
* 自定义的串行多个流程任务的 assignee 负责人的分配
*
* 本质上实现和 {@link BpmParallelMultiInstanceBehavior} 一样只是继承的类不一样
*
* @author 芋道源码
*/
@Setter
public class BpmSequentialMultiInstanceBehavior extends SequentialMultiInstanceBehavior {
private BpmTaskCandidateInvoker taskCandidateInvoker;
public BpmSequentialMultiInstanceBehavior(Activity activity, AbstractBpmnActivityBehavior innerActivityBehavior) {
super(activity, innerActivityBehavior);
}
/**
* 逻辑和 {@link BpmParallelMultiInstanceBehavior#resolveNrOfInstances(DelegateExecution)} 类似
*
* 差异的点是在第二步的时候需要返回 LinkedHashSet 集合因为它需要有序
*/
@Override
protected int resolveNrOfInstances(DelegateExecution execution) {
// 第一步设置 collectionVariable CollectionVariable
// execution.getVariable() 读取所有任务处理人的 key
super.collectionExpression = null; // collectionExpression collectionVariable 是互斥的
super.collectionVariable = FlowableUtils.formatCollectionVariable(execution.getCurrentActivityId());
// execution.getVariable() 读取当前所有任务处理的人的 key
super.collectionElementVariable = FlowableUtils.formatCollectionElementVariable(execution.getCurrentActivityId());
// 第二步获取任务的所有处理人
Set<Long> assigneeUserIds = new LinkedHashSet<>(taskCandidateInvoker.calculateUsers(execution)); // 保证有序
execution.setVariable(super.collectionVariable, assigneeUserIds);
return assigneeUserIds.size();
}
}

View File

@ -47,7 +47,8 @@ public class BpmUserTaskActivityBehavior extends UserTaskActivityBehavior {
} }
private Long calculateTaskCandidateUsers(DelegateExecution execution) { private Long calculateTaskCandidateUsers(DelegateExecution execution) {
// 情况一如果是多实例的任务例如说会签或签等情况则从 Variable 中获取它的任务处理人在 BpmParallelMultiInstanceBehavior 中已经被分配了 // 情况一如果是多实例的任务例如说会签或签等情况则从 Variable 中获取
// 顺序审批可见 BpmSequentialMultiInstanceBehavior并发审批可见 BpmSequentialMultiInstanceBehavior
if (super.multiInstanceActivityBehavior != null) { if (super.multiInstanceActivityBehavior != null) {
return execution.getVariable(super.multiInstanceActivityBehavior.getCollectionElementVariable(), Long.class); return execution.getVariable(super.multiInstanceActivityBehavior.getCollectionElementVariable(), Long.class);
} }