Activiti技术中获取流程图片

在使用Activiti技术时,我们经常需要查看当前流程所属节点。针对流程图片获取,我使用一下方法:
1、在流程生成时,生成的流程id记为processId

/**
 * 获取流程图片方法
 * @param processId 
 * @return
 */
public InputStream getDiagramImageForAcivitiFlowsActiviti(String processId) {

    HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processId).singleResult();

    if(historicProcessInstance == null) {
        throw new RuntimeException("获取流程图异常");
    }else {

        BpmnModel bpmnModel = repositoryService.getBpmnModel(historicProcessInstance.getProcessDefinitionId());
        // 获取流程走过的节点
        List activitiyInstances = historyService.createHistoricActivityInstanceQuery().processInstanceId(processId).orderByHistoricActivityInstanceId().asc().list();

        InputStream is = processEngine.getProcessEngineConfiguration().getProcessDiagramGenerator().generateDiagram(bpmnModel, "png", runtimeService.getActiveActivityIds(processId),getHightedFlows(processId),
                processEngine.getProcessEngineConfiguration().getActivityFontName(), 
                processEngine.getProcessEngineConfiguration().getLabelFontName(), 
                processEngine.getProcessEngineConfiguration().getClassLoader(),1.0);            

        return is;  
    }   
}

2、Controller 获取图片路径(../image/processId = ?)

/**
 * 获取流程图片 
 * @param processId 
 * @return
 */
@RequestMapping("/image")
@ResponseBody
public void getImageTest(HttpServletResponse response,ActionValueAssistant actionValueAssistant) {
    try {
        String processId = actionValueAssistant.getString("processId");
        response.setContentType("image/jpeg");

        if(StringUtils.isNotBlank(processId)) {
//          response.setCharacterEncoding("GBK");
            InputStream inputstream = wTWorkFlowGetDiagram.getDiagramImageForAcivitiFlowsActiviti(processId);
            byte[] b = new byte[1024];
            int len = -1;
            while ((len = inputstream.read(b, 0, 1024)) != -1) {
                response.getOutputStream().write(b, 0, len);
            }
        }else {
            throw new RuntimeException("输出参数有误");
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

你可能感兴趣的:(Activiti技术)