Flowable 生成流程图

java 复制代码
/**
 * 生成流程图
 *
 * @param processId 任务ID
 */
@RequestMapping("/diagram/{processId}")
public void genProcessDiagram(HttpServletResponse response,
                              @PathVariable("processId") String processId) {
    InputStream inputStream = flowTaskService.diagram(processId);
    OutputStream os = null;
    BufferedImage image = null;
    try {
        image = ImageIO.read(inputStream);
        response.setContentType("image/png");
        os = response.getOutputStream();
        if (image != null) {
            ImageIO.write(image, "png", os);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (os != null) {
                os.flush();
                os.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
java 复制代码
/**
 * 获取流程过程图
 */
public InputStream diagram(String processId) {
    String processDefinitionId;
    // 获取当前的流程实例
    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processId).singleResult();
    // 如果流程已经结束,则得到结束节点
    if (Objects.isNull(processInstance)) {
        HistoricProcessInstance pi = historyService.createHistoricProcessInstanceQuery().processInstanceId(processId).singleResult();

        processDefinitionId = pi.getProcessDefinitionId();
    } else {// 如果流程没有结束,则取当前活动节点
        // 根据流程实例ID获得当前处于活动状态的ActivityId合集
        ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(processId).singleResult();
        processDefinitionId = pi.getProcessDefinitionId();
    }

    // 获得活动的节点
    List<HistoricActivityInstance> highLightedFlowList = historyService.createHistoricActivityInstanceQuery()
        .processInstanceId(processId).orderByHistoricActivityInstanceStartTime().asc().list();

    List<String> highLightedFlows = new ArrayList<>();
    List<String> highLightedNodes = new ArrayList<>();
    //高亮线
    for (HistoricActivityInstance tempActivity : highLightedFlowList) {
        if ("sequenceFlow".equals(tempActivity.getActivityType())) {
            //高亮线
            highLightedFlows.add(tempActivity.getActivityId());
        } else {
            //高亮节点
            highLightedNodes.add(tempActivity.getActivityId());
        }
    }

    //获取流程图
    BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
    ProcessEngineConfiguration configuration = processEngine.getProcessEngineConfiguration();
    //获取自定义图片生成器
    ProcessDiagramGenerator diagramGenerator = new CustomProcessDiagramGenerator();
    return diagramGenerator.generateDiagram(bpmnModel, "png", highLightedNodes, highLightedFlows, configuration.getActivityFontName(),
        configuration.getLabelFontName(), configuration.getAnnotationFontName(), configuration.getClassLoader(), 1.0, true);
}
相关推荐
Coder_Boy_12 小时前
基于SpringAI的在线考试系统-核心业务流程图(续)
java·大数据·人工智能·spring boot·流程图
灵活用工平台13 小时前
灵活用工平台注册流程图
python·流程图
檐下翻书17316 小时前
在线自定义跨职能流程图工具 PC免费
大数据·人工智能·架构·html·流程图·论文笔记
一枝小雨2 天前
【OTA专题】17 打通Bootloader与App逻辑之间的通信
stm32·单片机·嵌入式·流程图·freertos·ota·bootloader
简道云平台2 天前
采购、供应商、订单三条线怎么打通?用一张流程图讲透协同逻辑
流程图
杨江2 天前
腾讯元宝生成draw.io流程图,draw.io在线版本在线编辑
流程图·draw.io
CG大魔王2 天前
kv cache在推理过程的流程图
流程图
檐下翻书1733 天前
PC端免费跨职能流程图模板大全 中文
大数据·人工智能·架构·流程图·论文笔记
程途拾光1583 天前
中文界面跨职能泳道图制作教程 PC
大数据·论文阅读·人工智能·信息可视化·流程图
数说星榆1814 天前
在线简单画泳道图工具 PC端无水印
大数据·论文阅读·人工智能·架构·流程图·论文笔记