activiti实现跳转节点的方法

1.通过代码实现,即获取到当前节点,然后退回到已走过的指定节点。代码如下:

@RequestMapping("/returnNode")public String returnNode(String taskId) {// 取得当前任务.当前任务节点HistoricTaskInstance currTask = historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult();// 取得所有历史任务按时间降序排序List hisInstances = historyService.createHistoricTaskInstanceQuery().processInstanceId(currTask.getProcessInstanceId()).orderByTaskCreateTime().desc().list();if(ObjectUtils.isEmpty(hisInstances)||hisInstances.size()<2){return "fail";}//目的节点HistoricTaskInstance lastTask = null;//所有目的节点的历史记录List commitList = historyService.createHistoricTaskInstanceQuery().processInstanceId(currTask.getProcessInstanceId()).taskName("one").orderByTaskCreateTime().asc().list();lastTask=commitList.get(0);if (null==lastTask){return "fail";}// 目的节点的taskIdString lastTaskId = lastTask.getId();// 目的节点的executionIdString lastExecutionId = lastTask.getExecutionId();//目的节点对应的流程定义IDString processDefinitionId = lastTask.getProcessDefinitionId();//对应的流程图文件BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);String lastActivityId = null;//获取所有和目的节点任务名一样的已完成的历史记录List finishedList = historyService.createHistoricActivityInstanceQuery().executionId(lastExecutionId).finished().list();for (HistoricActivityInstance f: finishedList){if(lastTaskId.equals(f.getTaskId())){lastActivityId=f.getActivityId();break;}}FlowNode lastFlowNode = (FlowNode)bpmnModel.getMainProcess().getFlowElement(lastActivityId);
// 取得当前节点的信息// 当前节点的executionIdString curExecutionId = currTask.getExecutionId();Execution execution = runtimeService.createExecutionQuery().executionId(curExecutionId).singleResult();String curActivityId = execution.getActivityId();FlowNode curFlowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(curActivityId);//记录当前节点的原活动方向List oriSequenceFlows = new ArrayList<>();oriSequenceFlows.addAll(curFlowNode.getOutgoingFlows());//清理活动方向curFlowNode.getOutgoingFlows().clear();//建立新方向List newSequenceFlowList = new ArrayList<>();SequenceFlow newSequenceFlow = new SequenceFlow();newSequenceFlow.setId("newSequenceFlowId");newSequenceFlow.setSourceFlowElement(curFlowNode);newSequenceFlow.setTargetFlowElement(lastFlowNode);newSequenceFlowList.add(newSequenceFlow);curFlowNode.setOutgoingFlows(newSequenceFlowList);// 完成任务taskService.complete(taskId);//恢复原方向curFlowNode.setOutgoingFlows(oriSequenceFlows);return "成功";}

对应的流程图如下:

上述代码可以实现从two节点退回到one节点

2.通过排他网关实现,流程图如下:

通过设置two节点完成时的参数确定流程图是退回到one节点还是结束。 

注意,方法一不会自动删除流程中的参数,需要手动删除,如果通过网关退回,可以实现退回后之前的流程变量自动被删除。


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部