flowable 獲取當前任務流程圖片的輸入流

FH-Admin發表於2021-11-08
/**
     * 獲取當前任務流程圖片的輸入流
     * @param PROC_INST_ID_ 流程例項ID
     * @from  fhadmin.cn
     */
    public InputStream genProcessDiagram(String PROC_INST_ID_, String type){
        /* 獲得活動的節點  */
        String processDefinitionId = "";
        if (this.isFinished(PROC_INST_ID_)) {    // 如果流程已經結束,則得到結束節點
            HistoricProcessInstance pi = historyService.createHistoricProcessInstanceQuery().processInstanceId(PROC_INST_ID_).singleResult();
            processDefinitionId=pi.getProcessDefinitionId();
        } else {                            // 如果流程沒有結束,則取當前活動節點
            /* 根據流程例項ID獲得當前處於活動狀態的ActivityId合集  */
            ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(PROC_INST_ID_).singleResult();
            processDefinitionId = pi.getProcessDefinitionId();
        }
        /* 獲得活動的節點物件  */
        List<HistoricActivityInstance> highLightedActivitList =  historyService.createHistoricActivityInstanceQuery().processInstanceId(PROC_INST_ID_).orderByHistoricActivityInstanceStartTime().asc().list();
        List<String> highLightedActivitis = new ArrayList<String>();                //節點物件ID
        for(HistoricActivityInstance tempActivity : highLightedActivitList){
            String activityId = tempActivity.getActivityId();
            highLightedActivitis.add(activityId);
        }
        BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);    //獲取流程圖
        ProcessEngineConfiguration engconf = processEngine.getProcessEngineConfiguration();
        /* 獲得活動的連線物件  */
        List<String> flows = new ArrayList<>();                                        //連線ID
        if("RU".equals(type)) {
            List<ActivityInstance> highLightedFlowInstances = runtimeService.createActivityInstanceQuery().activityType(BpmnXMLConstants.ELEMENT_SEQUENCE_FLOW).processInstanceId(PROC_INST_ID_).list();
            for(ActivityInstance ai : highLightedFlowInstances) {
                flows.add(ai.getActivityId());    
            }
        }else {
            List<HistoricActivityInstance> highLightedFlowInstances = historyService.createHistoricActivityInstanceQuery().activityType(BpmnXMLConstants.ELEMENT_SEQUENCE_FLOW).processInstanceId(PROC_INST_ID_).list();
            for(HistoricActivityInstance ha : highLightedFlowInstances) {
                flows.add(ha.getActivityId());    
            }
        }
        ProcessDiagramGenerator diagramGenerator = engconf.getProcessDiagramGenerator();
        InputStream in = diagramGenerator.generateDiagram(bpmnModel, "png", highLightedActivitis, flows, engconf.getActivityFontName(), engconf.getLabelFontName(), engconf.getAnnotationFontName(), engconf.getClassLoader(), 1.0, true);
        return in;
     }
本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章