flowable 生成流程图高亮追踪

public ProcessEngine processEngine() {
        return ProcessEngines.getDefaultProcessEngine();
    }
/**
 * 生成流程图
 *
 * @param processId 流程部署id
 */
public void genProcessDiagram(HttpServletResponse httpServletResponse, String processId) throws Exception {
    ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(processId).singleResult();
    //流程走完的不显示图
    if (pi == null) {
        return;
    }

    List historyProcess = getHistoryProcess(processId);
    List activityIds = new ArrayList<>();
    List flows = new ArrayList<>();
    //获取流程图
    BpmnModel bpmnModel = repositoryService.getBpmnModel(pi.getProcessDefinitionId());
    for (HistoricActivityInstance hi : historyProcess) {
        String activityType = hi.getActivityType();
        if (activityType.equals("sequenceFlow") || activityType.equals("exclusiveGateway")) {
            flows.add(hi.getActivityId());
        } else if (activityType.equals("userTask") || activityType.equals("startEvent")) {
            activityIds.add(hi.getActivityId());
        }
    }
    List tasks = taskService.createTaskQuery().processInstanceId(processId).list();
    for (Task task : tasks) {
        activityIds.add(task.getTaskDefinitionKey());
    }
    ProcessEngineConfiguration engConf = processEngine().getProcessEngineConfiguration();
    //定义流程画布生成器
    ProcessDiagramGenerator processDiagramGenerator = engConf.getProcessDiagramGenerator();
    InputStream in = processDiagramGenerator.generateDiagram(bpmnModel, "png", activityIds, flows, engConf.getActivityFontName(), engConf.getLabelFontName(), engConf.getAnnotationFontName(), engConf.getClassLoader(), 1.0, true);
    OutputStream out = null;
    byte[] buf = new byte[1024];
    int legth = 0;
    try {
        out = httpServletResponse.getOutputStream();
        while ((legth = in.read(buf)) != -1) {
            out.write(buf, 0, legth);
        }
    } finally {
        if (in != null) {
            in.close();
        }
        if (out != null) {
            out.close();
        }
    }


}

  /**
     * 任务历史
     *
     * @param processId 部署id
     */
    public List getHistoryProcess(String processId) {
        List list = historyService // 历史相关Service
                .createHistoricActivityInstanceQuery() // 创建历史活动实例查询
                .processInstanceId(processId) // 执行流程实例id
                .finished()
                .list();
        return list;
    }

你可能感兴趣的:(flowable)