超然楼 超然楼
首页
开源
分享
  • 技术文档
  • GitHub技巧
  • Nodejs
  • 博客搭建
关于
友链
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

soft1314

首页
开源
分享
  • 技术文档
  • GitHub技巧
  • Nodejs
  • 博客搭建
关于
友链
收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 技术

    • 开源后台管理系统解决方案 boot-admin 简介
    • vue-element-admin动态菜单改造
    • Springboot整合Flowable6.x导出bpmn20
      • Flowable导出查看跟踪流程图(1)
      • Flowable导出查看跟踪流程图(2)
      • 整合flowable官方editor-app源码BPMN2建模(1)
      • 整合flowable官方editor-app源码BPMN2建模(2)
      • Oracle逻辑备份exp导出指定表名时需要加括号吗?
      • boot-admin整合Quartz实现动态管理定时任务
      • boot-admin整合Liquibase实现数据库版本管理
      • boot-admin开源项目中有关后端参数校验的最佳实践
      • boot-admin项目数据库缺省字段设计之最佳实践
      • 代码审计工具Fortify基本使用
      • 记一次Oracle归档日志异常增长问题的排查过程
      • 填一个Mybatis-plus动态数据源切换失效的坑
      • Springboot使用AOP编程简介
      • Oracle也有回收站
      • 使用OpenFeign传递二进制流
      • 使用 Spring Security 保护您的 WebFlux 应用程序
    • 生活

    • 思考

    • 博客
    • 技术
    Soft1314
    2023-04-16
    目录

    Springboot整合Flowable6.x导出bpmn20

    源码仓库

    Github (opens new window) Gitee (opens new window)

    BPMN2.0(Business Process Model and Notation)是一套业务流程模型与符号建模标准,以XML为载体,以符号可视化业务,支持精准的执行语义来描述元素的操作。 Flowable诞生于Activiti,是一个使用Java编写的轻量级业务流程引擎。Flowable流程引擎可用于部署BPMN 2.0流程定义,可以十分灵活地加入你的应用/服务/构架。 本文给出两种从flowable导出流程定义bpmn20.xml的方式。

    # 导入Maven依赖

            <dependency>
                <groupId>org.flowable</groupId>
                <artifactId>flowable-spring-boot-starter-basic</artifactId>
                <version>6.4.1</version>
            </dependency>
            <dependency>
                <groupId>org.flowable</groupId>
                <artifactId>flowable-json-converter</artifactId>
                <version>6.4.1</version>
            </dependency>
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10

    # 从流程模型导出流程定义bpmn20.xml

    通过流程编辑器制作的流程模型(如下图所示), 可以通过模型ID(Model.id),调用flowable 的 RepositoryService 来生成bpmn20.xml。

    @Service
    public class MyModelServiceImpl implements MyModelService {
        @Autowired
        private RepositoryService repositoryService;
    
        /**
         * 通过模型ID,生成模型BPMN20.xml
         * @param guid 模型id,即model.id
         * @return
         * @throws Exception
         */
        @Override
        public ResultDTO genXml(String guid) throws Exception {
            /**通过ID获取模型 **/
            Model modelData = repositoryService.getModel(guid);
            byte[] bytes = repositoryService.getModelEditorSource(modelData.getId());
            if (bytes == null) {
                return ResultDTO.failureCustom("模型数据为空,请先设计流程并成功保存,再进行发布。");
            }
            JsonNode modelNode = new ObjectMapper().readTree(bytes);
            BpmnModel model = new BpmnJsonConverter().convertToBpmnModel(modelNode);
            if (model.getProcesses().size() == 0) {
                return ResultDTO.failureCustom("数据模型不符要求,请至少设计一条主线流程。");
            }
            /** 设置名称 **/
            model.getMainProcess().setName(modelData.getName());
            /** 设置 targetNamespace **/
            if(StringUtils.isNotBlank(modelData.getCategory())) {
                model.setTargetNamespace(modelData.getCategory());
            }
            byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(model);
            String xml = new String(bpmnBytes, "UTF-8");
            return ResultDTO.success(xml);
        }
    }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35

    运行效果如下: 导出效果

    # 从流程定义导出流程定义bpmn20.xml

    对于flowable已经部署的流程,可根据流程定义(ProcessDefinition.id),调用flowable 的RepositoryService来导出其bpmn20.xml。

    @RestController
    @Slf4j
    public class ProcessController {
        @Autowired
        private MyProcessService processService;
        
        /**
         * 通过processDefinition.id和resType导出流程XML或图片资源
         * @param id processDefinition.id
         * @param resType 取值 “image/png”或“text/xml”
         * @param response
         * @throws Exception
         */
        @GetMapping(value = "/res/exp")
        @ApiOperation("通过processDefinition.id和resType导出流程XML或图片资源")
        public void resourceRead(@RequestParam("id") String id,@RequestParam("resType") String resType, HttpServletResponse response) throws Exception {
            /** resType取值 “image/png”或“text/xml” **/
            InputStream resourceAsStream = processService.resourceRead(id,resType);
            byte[] b = new byte[1024];
            int len = -1;
            while ((len = resourceAsStream.read(b, 0, 1024)) != -1) {
                response.getOutputStream().write(b, 0, len);
            }
        }
    }
    
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    @Service
    public class MyProcessServiceImpl implements MyProcessService {
        @Autowired
        private RepositoryService repositoryService;
        
        @Override
        public InputStream resourceRead(String id, String resType) throws Exception {
            ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(id).singleResult();
            String resourceName = "";
            if (resType.equals("image/png")) {
                resourceName = processDefinition.getDiagramResourceName();
            } else if (resType.equals("text/xml")) {
                resourceName = processDefinition.getResourceName();
            }
            InputStream resourceAsStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), resourceName);
            return resourceAsStream;
        }
    }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18

    运行效果如下: 导出效果 项目源码仓库 (opens new window)

    编辑 (opens new window)
    上次更新: 2024/04/18
    vue-element-admin动态菜单改造
    Flowable导出查看跟踪流程图(1)

    ← vue-element-admin动态菜单改造 Flowable导出查看跟踪流程图(1)→

    最近更新
    01
    使用 Spring Security 保护您的 WebFlux 应用程序
    02-07
    02
    Oracle也有回收站
    07-31
    03
    Springboot使用AOP编程简介
    07-31
    更多文章>
    Theme by Vdoing | Copyright © 2023-2024 Soft1314 | MIT License
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式