日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Activiti6驳回上一节点

發布時間:2023/12/20 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Activiti6驳回上一节点 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Activiti6駁回上一節點

主要是通過獲取,通過遍歷節點集合,通過上級節點對象的信息來判斷上級節點是什么節點(網關、用戶、開始、結束),來對不同的節點做不同的操作,目前只做一個互斥網關,用戶,開始,和結束,其他的網關還沒做,目前沒用到。

我目前是SpringBoot整合的activiti6+Activiti Modeler在線流程編輯


注意:在進行駁回的時候要注意節點的上級活下級是不是起點或終點,如果是的話,是無法駁回的。
主要代碼:

/*** 節點駁回操作*/@Overridepublic Result nodeReject(String taskId, String processInstanceId) {//獲取倉庫服務RepositoryService repositoryService = processEngine.getRepositoryService();//獲取任務服務TaskService taskService = processEngine.getTaskService();ManagementService managementService = processEngine.getManagementService();//獲取當前任務對象Task currentTask = taskService.createTaskQuery().taskId(taskId).singleResult();if (currentTask == null) {throw new ActivitiException("當前任務不存在或已被辦理完成,回退失敗!");}//獲取流程定義idString processDefinitionId = currentTask.getProcessDefinitionId();//獲取bpmn模板BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);//獲取當前任務信息Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();//獲取目標節點定義FlowNode flowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(task.getTaskDefinitionKey());//獲取輸入節點集合List<SequenceFlow> incomingFlows = flowNode.getIncomingFlows();//遍歷輸入節點集合for (SequenceFlow incomingFlow : incomingFlows) {//上級節點的sourceRef-(sid)String sourceRef = incomingFlow.getSourceRef();//通過上級節點對象的信息來判斷上級節點是什么節點(網關、用戶、開始、結束)FlowNode flowElement = (FlowNode) bpmnModel.getMainProcess().getFlowElement(sourceRef);//上級節點判斷,用戶節點if (flowElement instanceof UserTask) {//返回上一個節點信息(可以刪除)Result result = lastNodeMessage(processInstanceId);//刪除當前運行任務String executionEntityId = managementService.executeCommand(new ActivitiNodeUtil.DeleteTaskCmd(currentTask.getId()));//流程執行到目標節點managementService.executeCommand(new ActivitiNodeUtil.setFLowNodeAndGoCmd(flowElement, executionEntityId));return result; //(可以刪除)//上級節點判斷,互斥網關節點} else if (flowElement instanceof ExclusiveGateway) {//獲取輸入節點集合List<SequenceFlow> incomingFlows1 = flowElement.getIncomingFlows();//遍歷輸入節點集合,找到輸入的上級節點idfor (SequenceFlow sequenceFlow : incomingFlows1) {//上級節點的sourceRef-(sid)String flowSourceRef = sequenceFlow.getSourceRef();//通過上級節點的sid獲取節點對象信息FlowNode flowNodeUser = (FlowNode) bpmnModel.getFlowElement(flowSourceRef);//通過上級節點對象的信息來判斷上級節點是什么節點(網關、用戶、開始、結束)if (flowNodeUser instanceof UserTask) {Result result = lastNodeMessage(processInstanceId);//刪除當前運行任務String executionEntityId = managementService.executeCommand(new ActivitiNodeUtil.DeleteTaskCmd(currentTask.getId()));//流程執行到目標節點managementService.executeCommand(new ActivitiNodeUtil.setFLowNodeAndGoCmd(flowNodeUser, executionEntityId));//返回上一個節點信息return result;//上級節點判斷,流程起點節點} else if (flowElement instanceof StartEvent) {throw new ActivitiException("上級節點是流程開始節點無法駁回,駁回失敗!");}}//上級節點判斷,流程起點節點} else if (flowElement instanceof StartEvent) {throw new ActivitiException("上級節點是流程開始節點無法駁回,駁回失敗!");}}return null;} /*** 刪除當前運行時任務命令,并返回當前任務的執行對象id* 這里繼承了NeedsActiveTaskCmd,主要時很多跳轉業務場景下,要求不能是掛起任務。可以直接繼承Command即可*/public static class DeleteTaskCmd extends NeedsActiveTaskCmd<String> {public DeleteTaskCmd(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 static class setFLowNodeAndGoCmd implements Command<Void> {private FlowNode flowElement;private String executionId;public setFLowNodeAndGoCmd(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;}}

主要需要兩個參數一個任務Id一個流程Id,

總結

以上是生活随笔為你收集整理的Activiti6驳回上一节点的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。