工作流版本使用6.0,参数为任务id(task中主键),目标节点ID(比如userTask1),以及业务主键信息(businessKey)。
/**
* 任务节点跳转
* @param taskId 当前任务id
* @param flowElementId 跳转的目标节点的id
*/
public void taskBack(String taskId,String flowElementId,Map<String, Object> variables){
ProcessEngine processEngine = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml").buildProcessEngine();
//当前任务
Task currentTask = processEngine.getTaskService().createTaskQuery().taskId(taskId).singleResult();
//更新业务信息
processEngine.getTaskService().setVariables(taskId , variables);
//获取流程定义
org.activiti.bpmn.model.Process process = processEngine.getRepositoryService().getBpmnModel(currentTask.getProcessDefinitionId()).getMainProcess();
//获取目标节点定义
FlowNode targetNode = (FlowNode)process.getFlowElement(flowElementId);
//删除当前运行任务
String executionEntityId =processEngine.getManagementService().executeCommand(new DeleteTaskCommand(currentTask.getId()));
//流程执行到来源节点
processEngine.getManagementService().executeCommand(new JumpCommand(targetNode, executionEntityId));
}
/**
* 删除当前运行时任务命令
* 这里继承了NeedsActiveTaskCmd,主要是很多跳转业务场景下,要求不能时挂起任务。可以直接继承Command即可
*/
public class DeleteTaskCommand extends NeedsActiveTaskCmd<String> {
public DeleteTaskCommand(String taskId){
super(taskId);
}
@Override
public String execute(CommandContext commandContext, TaskEntity currentTask){
//获取所需服务
TaskEntityManagerImpl taskEntityManager = (TaskEntityManagerImpl)commandContext.getTaskEntityManager();
//获取当前任务的来源任务及来源节点信息
ExecutionEntity executionEntity = currentTask.getExecution();
//删除当前任务,来源任务
taskEntityManager.deleteTask(currentTask, "jumpReason", false, false);
return executionEntity.getId();
}
@Override
public String getSuspendedTaskException() {
return "挂起的任务不能跳转";
}
}
/**
* 根据提供节点和执行对象id,进行跳转命令
*/
public class JumpCommand implements Command<Void> {
private FlowNode flowElement;
private String executionId;
public JumpCommand(FlowNode flowElement, String executionId){
this.flowElement = flowElement;
this.executionId = executionId;
}
@Override
public Void execute(CommandContext commandContext){
//获取目标节点的来源连线
List<SequenceFlow> flows = flowElement.getIncomingFlows();
if(flows==null || flows.size()<1){
throw new ActivitiException("操作错误,目标节点没有来源连线");
}
//随便选一条连线来执行,时当前执行计划为,从连线流转到目标节点,实现跳转
ExecutionEntity executionEntity = commandContext.getExecutionEntityManager().findById(executionId);
executionEntity.setCurrentFlowElement(flows.get(0));
commandContext.getAgenda().planTakeOutgoingSequenceFlowsOperation(executionEntity, true);
return null;
}
}
最新评论
你们创作的校园二手交易平台和之前的有什么区别有什么区别
论文要求springMVc,这个可以用吗
公众号关注不了,微信二维码太小扫不到
兄弟想要系统可以发给我吗
代码讲解视频有吗
奈斯
这个有论文文档吗
当地