简介:工作流开发过程中,因为国内的需求变态原因,会有流程图节点任意跳转的需求
一.普通的流程跳转设计
因为普通流程只需要根据连线进行节点跳转就行直接贴代码:
//获取流程定义
Process process = repositoryService.getBpmnModel(processDefinitionId).getMainProcess();
//获取目标节点定义
FlowNode targetNode = (FlowNode) process.getFlowElement(flowElementId);
List<Execution> executionList = runtimeService.createExecutionQuery().parentId(taskList.get(0).getProcessInstanceId()).list();
Execution newExecution = executionList.remove(0);
//流程执行到来源节点
managementService.executeCommand(new SetNodeAndGoCmd(targetNode, newExecution.getId()));
if (CollectionUtil.isNotEmpty(executionList)) {
List<String> ids = executionList.stream().map(Execution::getId).collect(Collectors.toList());
managementService.executeCommand(new DeleteExecutionCmd(ids));
}
//删除当前运行任务
for (Task currentTask : taskList) {
managementService.executeCommand(new DeleteTaskCmd(currentTask.getId()));
}
@Slf4j
public class SetNodeAndGoCmd implements Command<Void> {
private FlowNode flowElement;
private String executionId;
private String executionName;
private String startUserId;
public SetNodeAndGoCmd(FlowNode flowElement, String executionId) {
this.flowElement = flowElement;
this.executionId = executionId;
}
publ