activity6.0+ 獲取當前審批節點的上一級/下一級審批節點的信息

public   FlowElement getNextUserFlowElement(String processInstanceId){
        Task task=taskService.createTaskQuery().processInstanceId(processInstanceId).singleResult();
        if (task==null){
            throw new ServiceException("流程未啓動或已執行完成");
        }
        // 取得已提交的任務
        HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery()
                .taskId(task.getId()).singleResult();
        // 取得正在流轉的流程實例,若已完成則爲null
//getRuntimeProcessInstance是自己封裝的獲取流程實例的方法
        ProcessInstance processInstance =getRuntimeProcessInstance(historicTaskInstance.getProcessInstanceId());
        //每個流程實例只有一個executionId
        //獲得流程定義
        ProcessDefinition processDefinition=repositoryService.getProcessDefinition(historicTaskInstance.getProcessDefinitionId());
 
        //獲得當前流程的活動ID
        ExecutionQuery executionQuery =runtimeService.createExecutionQuery();
        Execution execution =executionQuery.executionId(historicTaskInstance.getExecutionId()).singleResult();
        String activityId=execution.getActivityId();
UserTask userTask =null;
        while (true){
            //根據活動節點獲取當前的組件信息
            FlowNode flowNode =getFlowNode(processDefinition.getId(),activityId);
            //獲取該流程組件的之後/之前的組件信息
            List<SequenceFlow> sequenceFlowListOutGoing=flowNode.getOutgoingFlows();
//        List<SequenceFlow> sequenceFlowListIncoming=flowNode.getIncomingFlows();
 
            //獲取的下個節點不一定是userTask的任務節點,所以要判斷是否是任務節點
            //sequenceFlowListOutGoing數量可能大於1,可以自己做判斷,此處只取第一個
            FlowElement flowElement =sequenceFlowListOutGoing.get(0).getTargetFlowElement();
            if (flowElement instanceof UserTask){
                userTask =(UserTask)flowElement;
                System.out.println("獲取該任務節點的審批信息...");
                break;
            }else {
                //下一節點不是任務userTask的任務節點,所以要獲取再下一個節點的信息,直到獲取到userTask任務節點信息
                String flowElementId=flowElement.getId();
                activityId=flowElementId;
                continue;
            }
        }
 
    }
    //根據活動節點和流程定義ID獲取該活動節點的組件信息
 
    public FlowNode getFlowNode(String processDefinitionId,String activityId){
        BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
        FlowNode flowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(activityId);
        return flowNode;
    }

轉載地址: https://blog.csdn.net/weixin_39102174/article/details/93982104

發佈了97 篇原創文章 · 獲贊 31 · 訪問量 19萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章