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

FH-Admin發表於2021-10-29
    /**獲取當前任務流程圖片的輸入流
     * @param PROC_INST_ID_    //流程例項ID
     * @from  fhadmin.cn
     */
    private InputStream getResourceDiagramInputStream(String PROC_INST_ID_){
        try {
            HistoricProcessInstance hip = historyService.createHistoricProcessInstanceQuery().processInstanceId(PROC_INST_ID_).singleResult();             //獲取歷史流程例項
            List<HistoricActivityInstance> hai = historyService.createHistoricActivityInstanceQuery().processInstanceId(PROC_INST_ID_)
                                                                                                     .orderByHistoricActivityInstanceId().asc().list();    //獲取流程中已經執行的節點,按照執行先後順序排序
            List<String> executedActivityIdList = new ArrayList<String>();                        // 構造已執行的節點ID集合
            for (HistoricActivityInstance activityInstance : hai) {
                executedActivityIdList.add(activityInstance.getActivityId());
            }
            BpmnModel bpmnModel = repositoryService.getBpmnModel(hip.getProcessDefinitionId()); // 獲取bpmnModel
            List<String> flowIds = this.getExecutedFlows(bpmnModel, hai);                        // 獲取流程已發生流轉的線ID集合
            ProcessDiagramGenerator processDiagramGenerator = processEngine.getProcessEngineConfiguration().getProcessDiagramGenerator();    
            InputStream imageStream = processDiagramGenerator.generateDiagram(bpmnModel, "png", executedActivityIdList, flowIds, "宋體", "微軟雅黑", "黑體", null, 2.0);    //使用預設配置獲得流程圖表生成器,並生成追蹤圖片字元流
            return imageStream;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章