activiti 生成當前任務圖片PNG

FH-Admin發表於2021-11-01
    /**生成當前任務節點流程圖片PNG
     * @param PROC_INST_ID_ //流程例項ID
     * @param FILENAME         //圖片名稱
     * @from fhadmin.cn 
     */
    protected void createXmlAndPngAtNowTask(String PROC_INST_ID_, String FILENAME) throws IOException{
        DelFileUtil.delFolder(PathUtil.getProjectpath()+"uploadFiles/activitiFile");     //生成先清空之前生成的檔案
        InputStream in = getResourceDiagramInputStream(PROC_INST_ID_); 
        FileUpload.copyFile(in,PathUtil.getProjectpath()+Const.FILEACTIVITI,FILENAME);//把檔案上傳到檔案目錄裡面
        in.close();  
    }

    /**獲取當前任務流程圖片的輸入流
     * @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 協議》,轉載必須註明作者和本文連結

相關文章