activiti实现跳转节点的方法
生活随笔
收集整理的這篇文章主要介紹了
activiti实现跳转节点的方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.通過代碼實現,即獲取到當前節點,然后退回到已走過的指定節點。代碼如下:
| @RequestMapping("/returnNode")public String returnNode(String taskId) {// 取得當前任務.當前任務節點HistoricTaskInstance currTask = historyService.createHistoricTaskInstanceQuery().taskId(taskId).singleResult();// 取得所有歷史任務按時間降序排序List<HistoricTaskInstance> hisInstances = historyService.createHistoricTaskInstanceQuery().processInstanceId(currTask.getProcessInstanceId()).orderByTaskCreateTime().desc().list();if(ObjectUtils.isEmpty(hisInstances)||hisInstances.size()<2){return "fail";}//目的節點HistoricTaskInstance lastTask = null;//所有目的節點的歷史記錄List<HistoricTaskInstance> 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<HistoricActivityInstance> 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<SequenceFlow> oriSequenceFlows = new ArrayList<>();oriSequenceFlows.addAll(curFlowNode.getOutgoingFlows());//清理活動方向curFlowNode.getOutgoingFlows().clear();//建立新方向List<SequenceFlow> 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節點還是結束。?
注意,方法一不會自動刪除流程中的參數,需要手動刪除,如果通過網關退回,可以實現退回后之前的流程變量自動被刪除。
總結
以上是生活随笔為你收集整理的activiti实现跳转节点的方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: activiti配置实现用户多实例
- 下一篇: Java实现string转byte