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);
}
相关推荐
PD我是你的真爱粉12 天前
Vue 3 生命周期完全指南:从流程图到最佳实践
前端·vue.js·流程图
CORNERSTONE36512 天前
生产质量管理体系全过程流程图
流程图·质量管理·管理流程·生产质量
Blockbuater_drug12 天前
Amber分子动力学模拟5.3: 冷冻电镜结构评估与选用
流程图·分子动力学模拟·cryo-em结构·蛋白结构评估·冷冻电镜结构
分享牛19 天前
下一代BPMN
人工智能·语言模型·流程图
xiami_world22 天前
drawio文件如何在线打开?7种解决方案汇总
流程图·开源软件·甘特图·draw.io
分享牛23 天前
Camunda 7停止维护后,bpm开源流程引擎新局面
流程图·流程引擎·bpmn·cmmn
imbackneverdie23 天前
从机制图、流程图到数据图,覆盖《Cell》《Nature》级期刊插图
图像处理·人工智能·ai·aigc·流程图·科研绘图
TYFHVB1224 天前
11款CRM数字化方案横评:获客-履约-复购全链路能力对决
大数据·人工智能·架构·自动化·流程图
Loo国昌25 天前
SmartArchitect:AI 驱动的设计平台,让想法秒变流程图
人工智能·后端·设计模式·流程图
川西胖墩墩1 个月前
AI音乐创作工具完全指南:从旋律生成到人声合成的AIGC音乐制作全流程图
人工智能·aigc·流程图