其他分享
首页 > 其他分享> > activiti 生成当前任务图片PNG

activiti 生成当前任务图片PNG

作者:互联网

    /**生成当前任务节点流程图片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;
        }
    }
 

 

标签:bpmnModel,activiti,流程,当前任务,INST,PROC,ID,PNG
来源: https://www.cnblogs.com/m170981362621/p/15493130.html