1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
| // 以下参考源码 org.flowable.engine.impl.bpmn.behavior.MultiInstanceActivityBehavior.java
// cleanupMiRoot 方法
public class DeleteMultiTaskCommond implements Command<Boolean>, Serializable {
private String executioinId;
public DeleteMultiTaskCommond(String executioinId){
this.executioinId=executioinId;
}
@Override
public Boolean execute(CommandContext commandContext) {
ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager(commandContext);
ExecutionEntity executionEntity = executionEntityManager.findById(executioinId);
// 删除 Execution
ExecutionEntity multiInstanceRootExecution = (ExecutionEntity) getMultiInstanceRootExecution(executionEntity);
FlowElement flowElement = multiInstanceRootExecution.getCurrentFlowElement();
Collection<String> executionIdsNotToSendCancelledEventsFor = executionEntity.isMultiInstanceRoot() ? null : Collections.singletonList(executionEntity.getId());
executionEntityManager.deleteChildExecutions(multiInstanceRootExecution, null, executionIdsNotToSendCancelledEventsFor, "user comeback", true, flowElement);
executionEntityManager.deleteRelatedDataForExecution(multiInstanceRootExecution, "user comeback");
executionEntityManager.delete(multiInstanceRootExecution);
return true;
}
protected DelegateExecution getMultiInstanceRootExecution(DelegateExecution executionEntity) {
DelegateExecution multiInstanceRootExecution = null;
DelegateExecution currentExecution = executionEntity;
while (currentExecution != null && multiInstanceRootExecution == null && currentExecution.getParent() != null) {
if (currentExecution.isMultiInstanceRoot()) {
multiInstanceRootExecution = currentExecution;
} else {
currentExecution = currentExecution.getParent();
}
}
return multiInstanceRootExecution;
}
}
// 如下方式调用,传入 会签节点 其中一个 ExecutionId
processEngine.getManagementService().executeCommand(new DeleteMultiTaskCommond("230013"));
|