1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > 工作流(Activiti 6.0)之自由驳回任务实现

工作流(Activiti 6.0)之自由驳回任务实现

时间:2021-05-02 17:29:47

相关推荐

工作流(Activiti 6.0)之自由驳回任务实现

工作流版本使用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);}@Overridepublic String execute(CommandContext commandContext, TaskEntity currentTask){//获取所需服务TaskEntityManagerImpl taskEntityManager = (TaskEntityManagerImpl)commandContext.getTaskEntityManager();//获取当前任务的来源任务及来源节点信息ExecutionEntity executionEntity = currentTask.getExecution();//删除当前任务,来源任务taskEntityManager.deleteTask(currentTask, "jumpReason", false, false);return executionEntity.getId();}@Overridepublic 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;}@Overridepublic 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;}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。