flowable

news2024/10/3 4:34:09

flowable

  • 介绍
  • 表介绍
  • 实战

介绍

  • 定义

    为开发人员、系统管理员和业务用户提供紧凑且高效的工作流程和业务流程管理 (BPM) 平台。
    一个用 Java 编写的闪电般快速、经过尝试和测试的 BPMN 2 流程引擎。它是 Apache 2.0 许可的开源软件,拥有忠诚的社区。
    可以嵌入在 Java 应用程序中运行,也可以作为服务器、集群和云中的服务运行。它与 Spring 完美结合。凭借丰富的 Java 和 REST API,它是编排人类或系统活动的理想引擎

  • 其它
    文档:https: //www.flowable.org/
    jdk:支持java8-17+

本文以flowable 7.0.0 版本介绍

表介绍

Flowable 的数据库名称均以ACT_开头。第二部分是表用例的双字符标识。此用例也将大致匹配服务 API。

ACT_RE_ *:“RE”代表存储库。带有此前缀的表包含“静态”信息,例如流程定义和流程资源(图像、规则等)。

ACT_RU_ *:“RU”代表运行时。这些是运行时表,包含流程实例、用户任务、变量、作业等的运行时数据。Flowable仅在流程实例执行期间存储运行时数据,并在流程实例结束时删除记录。这使得运行时表小而快。

ACT_HI_ *:“HI”代表历史。这些表包含历史数据,例如过去的流程实例、变量、任务等。

ACT_GE_ *:通用数据,用于各种用例

在这里插入图片描述
在这里插入图片描述

实战

  • 依赖
  <!-- mysql -->
        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>
      <!--  <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-spring-boot3-starter</artifactId>
            <version>3.5.4</version>
        </dependency>-->
        <dependency>
            <groupId>org.flowable</groupId>
            <artifactId>flowable-spring-boot-starter</artifactId>
            <version>7.0.0</version>
        </dependency>
  • bpmn.xml
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:flowable="http://flowable.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
             xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI"
             typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath"
             targetNamespace="http://www.flowable.org/processdef">
    <process id="Expense" name="ExpenseProcess" isExecutable="true">
        <documentation>报销流程</documentation>
        <startEvent id="start" name="开始"></startEvent>
        <userTask id="fillTask" name="出差报销" flowable:assignee="${taskUser}">
            <extensionElements>
                <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler">
                    <![CDATA[false]]></modeler:initiator-can-complete>
            </extensionElements>
        </userTask>
        <exclusiveGateway id="judgeTask"></exclusiveGateway>
        <userTask id="directorTak" name="经理审批">
            <extensionElements>
                <flowable:taskListener event="create"
                                       class="com.gz.jelly.security.flowable.listener.ManagerTaskHandler"></flowable:taskListener>
            </extensionElements>
        </userTask>
        <userTask id="bossTask" name="老板审批">
            <extensionElements>
                <flowable:taskListener event="create"
                                       class="com.gz.jelly.security.flowable.listener.BossTaskHandler"></flowable:taskListener>
            </extensionElements>
        </userTask>
        <endEvent id="end" name="结束"></endEvent>
        <sequenceFlow id="directorNotPassFlow" name="驳回" sourceRef="directorTak" targetRef="fillTask">
            <conditionExpression xsi:type="tFormalExpression"><![CDATA[${outcome=='驳回'}]]></conditionExpression>
        </sequenceFlow>
        <sequenceFlow id="bossNotPassFlow" name="驳回" sourceRef="bossTask" targetRef="fillTask">
            <conditionExpression xsi:type="tFormalExpression"><![CDATA[${outcome=='驳回'}]]></conditionExpression>
        </sequenceFlow>
        <sequenceFlow id="flow1" sourceRef="start" targetRef="fillTask"></sequenceFlow>
        <sequenceFlow id="flow2" sourceRef="fillTask" targetRef="judgeTask"></sequenceFlow>
        <sequenceFlow id="judgeMore" name="大于500元" sourceRef="judgeTask" targetRef="bossTask">
            <conditionExpression xsi:type="tFormalExpression"><![CDATA[${money > 500}]]></conditionExpression>
        </sequenceFlow>
        <sequenceFlow id="bossPassFlow" name="通过" sourceRef="bossTask" targetRef="end">
            <conditionExpression xsi:type="tFormalExpression"><![CDATA[${outcome=='通过'}]]></conditionExpression>
        </sequenceFlow>
        <sequenceFlow id="directorPassFlow" name="通过" sourceRef="directorTak" targetRef="end">
            <conditionExpression xsi:type="tFormalExpression"><![CDATA[${outcome=='通过'}]]></conditionExpression>
        </sequenceFlow>
        <sequenceFlow id="judgeLess" name="小于500元" sourceRef="judgeTask" targetRef="directorTak">
            <conditionExpression xsi:type="tFormalExpression"><![CDATA[${money <= 500}]]></conditionExpression>
        </sequenceFlow>
    </process>
    <bpmndi:BPMNDiagram id="BPMNDiagram_Expense">
        <bpmndi:BPMNPlane bpmnElement="Expense" id="BPMNPlane_Expense">
            <bpmndi:BPMNShape bpmnElement="start" id="BPMNShape_start">
                <omgdc:Bounds height="30.0" width="30.0" x="285.0" y="135.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="fillTask" id="BPMNShape_fillTask">
                <omgdc:Bounds height="80.0" width="100.0" x="405.0" y="110.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="judgeTask" id="BPMNShape_judgeTask">
                <omgdc:Bounds height="40.0" width="40.0" x="585.0" y="130.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="directorTak" id="BPMNShape_directorTak">
                <omgdc:Bounds height="80.0" width="100.0" x="735.0" y="110.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="bossTask" id="BPMNShape_bossTask">
                <omgdc:Bounds height="80.0" width="100.0" x="555.0" y="255.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="end" id="BPMNShape_end">
                <omgdc:Bounds height="28.0" width="28.0" x="771.0" y="281.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
                <omgdi:waypoint x="315.0" y="150.0"></omgdi:waypoint>
                <omgdi:waypoint x="405.0" y="150.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
                <omgdi:waypoint x="505.0" y="150.16611295681062"></omgdi:waypoint>
                <omgdi:waypoint x="585.4333333333333" y="150.43333333333334"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="judgeLess" id="BPMNEdge_judgeLess">
                <omgdi:waypoint x="624.5530726256983" y="150.44692737430168"></omgdi:waypoint>
                <omgdi:waypoint x="735.0" y="150.1392757660167"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="directorNotPassFlow" id="BPMNEdge_directorNotPassFlow">
                <omgdi:waypoint x="785.0" y="110.0"></omgdi:waypoint>
                <omgdi:waypoint x="785.0" y="37.0"></omgdi:waypoint>
                <omgdi:waypoint x="455.0" y="37.0"></omgdi:waypoint>
                <omgdi:waypoint x="455.0" y="110.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="bossPassFlow" id="BPMNEdge_bossPassFlow">
                <omgdi:waypoint x="655.0" y="295.0"></omgdi:waypoint>
                <omgdi:waypoint x="771.0" y="295.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="judgeMore" id="BPMNEdge_judgeMore">
                <omgdi:waypoint x="605.4340277777778" y="169.56597222222223"></omgdi:waypoint>
                <omgdi:waypoint x="605.1384083044983" y="255.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="directorPassFlow" id="BPMNEdge_directorPassFlow">
                <omgdi:waypoint x="785.0" y="190.0"></omgdi:waypoint>
                <omgdi:waypoint x="785.0" y="281.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="bossNotPassFlow" id="BPMNEdge_bossNotPassFlow">
                <omgdi:waypoint x="555.0" y="295.0"></omgdi:waypoint>
                <omgdi:waypoint x="455.0" y="295.0"></omgdi:waypoint>
                <omgdi:waypoint x="455.0" y="190.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
        </bpmndi:BPMNPlane>
    </bpmndi:BPMNDiagram>
</definitions>

  • listener
public class BossTaskHandler implements TaskListener {
    @Override
    public void notify(DelegateTask delegateTask) {
        delegateTask.setAssignee("老板");
    }
}
public class ManagerTaskHandler implements TaskListener {
    @Override
    public void notify(DelegateTask delegateTask) {
        delegateTask.setAssignee("经理");
    }
}
  • controller
package com.gz.jelly.security.flowable.controller;

import jakarta.servlet.http.HttpServletResponse;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.engine.*;
import org.flowable.engine.runtime.Execution;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.image.ProcessDiagramGenerator;
import org.flowable.task.api.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping(value = "expense")
public class ExpenseController {
    @Autowired
    private RuntimeService runtimeService;
    @Autowired
    private TaskService taskService;
    @Autowired
    private RepositoryService repositoryService;
    @Autowired
    private ProcessEngine processEngine;

/***************此处为业务代码******************/

    /**
     * 添加报销
     *
     * @param userId    用户Id
     * @param money     报销金额
     * @param descption 描述
     */
    @RequestMapping(value = "add")
    @ResponseBody
    public String addExpense(String userId, Integer money, String descption) {
        //启动流程
        HashMap<String, Object> map = new HashMap<>();
        map.put("taskUser", userId);
        map.put("money", money);
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("Expense", map);
        return "提交成功.流程Id为:" + processInstance.getId();
    }

    /**
     * 获取审批管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String userId) {
        List<Task> tasks = taskService.createTaskQuery().taskAssignee(userId).orderByTaskCreateTime().desc().list();
        for (Task task : tasks) {
            System.out.println(task.toString());
        }
        return tasks.toArray().toString();
    }
    /**
     * 批准
     *
     * @param taskId 任务ID
     */
    @RequestMapping(value = "apply")
    @ResponseBody
    public String apply(String taskId) {
        Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
        if (task == null) {
            throw new RuntimeException("流程不存在");
        }
        //通过审核
        HashMap<String, Object> map = new HashMap<>();
        map.put("outcome", "通过");
        taskService.complete(taskId, map);
        return "processed ok!";
    }
    /**
     * 拒绝
     */
    @ResponseBody
    @RequestMapping(value = "reject")
    public String reject(String taskId) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("outcome", "驳回");
        taskService.complete(taskId, map);
        return "reject";
    }
    /**
     * 生成流程图
     *
     * @param processId 任务ID
     */
    @RequestMapping(value = "processDiagram")
    public void genProcessDiagram(HttpServletResponse httpServletResponse, String processId) throws Exception {
        ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(processId).singleResult();

        //流程走完的不显示图
        if (pi == null) {
            return;
        }
        Task task = taskService.createTaskQuery().processInstanceId(pi.getId()).singleResult();
        //使用流程实例ID,查询正在执行的执行对象表,返回流程实例对象
        String InstanceId = task.getProcessInstanceId();
        List<Execution> executions = runtimeService
                .createExecutionQuery()
                .processInstanceId(InstanceId)
                .list();

        //得到正在执行的Activity的Id
        List<String> activityIds = new ArrayList<>();
        List<String> flows = new ArrayList<>();
        for (Execution exe : executions) {
            List<String> ids = runtimeService.getActiveActivityIds(exe.getId());
            activityIds.addAll(ids);
        }

        //获取流程图
        BpmnModel bpmnModel = repositoryService.getBpmnModel(pi.getProcessDefinitionId());
        ProcessEngineConfiguration engconf = processEngine.getProcessEngineConfiguration();
        ProcessDiagramGenerator diagramGenerator = engconf.getProcessDiagramGenerator();
        InputStream in = diagramGenerator
                .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();
            }
        }
    }





}


本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1179972.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

8.spark自适应查询-AQE之自适应调整Shuffle分区数量

概述 自适应查询执行&#xff08;AQE&#xff09;是 Spark SQL中的一种优化技术&#xff0c;它利用运行时统计信息来选择最高效的查询执行计划&#xff0c;自Apache Spark 3.2.0以来默认启用该计划。从Spark 3.0开始&#xff0c;AQE有三个主要功如下 自适应查询AQE(Adaptive …

工业物联网模块应用之砂芯库桁架机器人远程无线控制

一、应用背景 在铸管车间无线技改项目中&#xff0c;客户需要构建智能化砂芯库&#xff0c;要求各库存的规格、数量、位置坐标等数据实时可显。此外&#xff0c;还需具备自动入库及出库功能&#xff0c;用于将出炉后的成摞砂芯及时码放至砂芯库的预设位置&#xff0c;当离心机…

你犯过程序员容易犯的这些错误吗?快来看看!

一、前言 写了20多年代码&#xff0c;我见过不下于4位数的程序员&#xff0c;我觉得程序员的能力水平可以分为4个阶段&#xff1a;线性级、逻辑级、架构级和工程级。 同样的在这些人当中&#xff0c;我也发现了8个程序员最常见的陋习&#xff0c;基本上可以覆盖90%的人&#…

vue 配置绕过跨域问题

第一种&#xff1a;在代码里加上metaInfo后面这段 // 属性计算computed:{},metaInfo() {return {title: 八方批量创建,meta: [{ name: referrer, content: no-referrer },],};}, 第二种&#xff1a;配置vue.config.js videoData:[/video/26519f026fc012521605563015227403.m…

【手册上新】迅为RK3588开发板多屏显示手册

iTOP-RK3588开发板采用四核Cortex-A76处理器和Cortex-A55架构&#xff0c;芯片内置VOP控制器&#xff0c;最多可以支持7个屏幕显示&#xff0c;支持HDMI、LVDS、MIPI、EDP四种显示接口的多屏同显、异显和异触&#xff0c;可有效提高行业定制的拓展性。 iTOP-RK3588开发板支持以…

修改iframe生成的pdf的比例

如图想要设置这里的默认比例 在iframe连接后面加上#zoom50即可&#xff0c;50是可以随便设置的&#xff0c;设置多少就是多少比例 <iframe src"name.pdf#zoom50" height"100%" width"100%"></iframe>

免费的运维监控系统PIGOSS BS基础版,欢迎下载使用

中小企业运维现状 当前多数中小型企业IT运维现状基本分为两部分&#xff1a; 1. 依靠传统的人工运维方式&#xff0c;无有效的监控工具辅助&#xff0c;导致故障发现不及时&#xff0c; 无法实时掌握IT运行状态。 2. 使用开源工具&#xff1a;开源工具因没有专业的售后技术…

Ubuntu18.04安装pcl-1.12.1,make时报错:/usr/bin/ld: cannot find -lvtkIOMPIImage

解决方案&#xff1a; 在vtk安装包中&#xff0c;重新打开cmake-gui&#xff0c;然后勾选上VTK_Group_MPI和VTK_Group_Imaging。 cd VTK-8.2.0 cd build cmake-gui然后重新编译生成。 make -j8 # 或者j4,量力而行。 sudo make install 就可以解决了。 然后重新回到pcl安装…

JAVA前端开发介绍

以一个网站为例包括网站设计、前端开发、程序开发等。网站设计就是网站的外观&#xff0c;平面的东西。程序开发也好理解就是功能实现。而前端开发&#xff0c;简单来说&#xff0c;就是把平面效果图转换成网页&#xff0c;把静态转换成动态。它的工作包括了:切图、写样式、做鼠…

如何选购适合自己的内衣洗衣机?性价比高的迷你洗衣机推荐

随着现代社会的快速发展&#xff0c;清洗内衣是一件相对比较麻烦的事情。在清洗的过程中&#xff0c;一定要用热水来消毒&#xff0c;这样才能彻底的清洗衣物&#xff0c;并避免细菌的滋生。所以&#xff0c;有一个小型的内裤洗衣机是很有必要的。专用的内衣洗衣机&#xff0c;…

针对目标重识别的大规模训练集搜索:Large-scale Training Data Search for Object Re-identification

本文介绍一篇发表于CVPR 2023的论文 《Large-scale Training Data Search for Object Re-identification》 。这篇文章主要介绍了澳大利亚国立大学新推出的训练集搜索任务&#xff0c;和相应的训练集搜索算法&#xff08;SnP&#xff09;。 论文链接: https://arxiv.org/pdf/2…

IDEA JAVA项目 导入JAR包,打JAR包 和 JAVA运行JAR命令提示没有主清单属性

一、导入JAR包 1、java项目在没有导入该jar包之前&#xff0c;如图&#xff1a;2、点击 File -> Project Structure&#xff08;快捷键 Ctrl Alt Shift s&#xff09;&#xff0c;点击Project Structure界面左侧的“Modules”如图&#xff1a;3.在 “Dependencies” 标签…

Instagram 早期技术架构

哈喽大家好&#xff0c;我是咸鱼 想必大家都听说过 Instagram &#xff0c;它是全球最受欢迎的社交媒体平台之一&#xff0c;拥有数十亿的活跃用户 Instagram 诞生于 2010 年&#xff0c;上线一周就坐拥 10 万注册用户&#xff0c;一年之内就拥有了 1400 万用户&#xff0c;可…

基于Springboot 智能公交站台系统-计算机毕设 附源码 37261

Springboot 智能公交站台系统 目 录 摘 要 1 绪论 1.1 研究背景 1.2研究意义 1.3相关技术介绍 1.4论文结构与章节安排 2 智能公交站台系统需求分析 2.1 可行性分析 2.1.1 技术可行性分析 2.1.2 经济可行性分析 2.1.3 操作可行性分析 2.1.4 法律可行性分析 2.2 系…

PostgreSQL 连接是否要通过SSL,为什么使用SSL 连接后,业务部门会投诉我?

开头还是介绍一下群&#xff0c;如果感兴趣PolarDB ,MongoDB ,MySQL ,PostgreSQL ,Redis, Oceanbase, Sql Server等有问题&#xff0c;有需求都可以加群群内有各大数据库行业大咖&#xff0c;CTO&#xff0c;可以解决你的问题。加群请联系 liuaustin3 &#xff0c;&#xff08;…

Ansys Speos | 如何利用Speos联合optiSLang进行光导优化设计

在本例中&#xff0c;我们将使用 Speos 和 optiSLang 实现光导的设计优化&#xff0c;以实现汽车日行灯、内饰氛围灯等的光导设计&#xff0c;并改善光导亮度的均匀性&#xff0c;以自动优化设计的方式实现更好的照明外观。 概述 在汽车照明应用中&#xff0c;日行灯是一个独特…

品牌化战略:跨境电商市场突破的关键

随着全球互联网的普及和数字化技术的不断发展&#xff0c;跨境电商已经成为了国际贸易中不可或缺的一部分。在这个竞争激烈的领域&#xff0c;成功突破市场的关键之一是采用品牌化战略。本文将深入探讨品牌化战略如何助力跨境电商实现市场突破。 品牌化战略的定义 品牌化是指将…

Java CAS原理和应用场景大揭秘:你掌握了吗?

一、&#x1f4d8;CAS概念 CAS&#xff08;Compare and Swap&#xff09;是一种乐观锁机制&#xff0c;它是一种基于硬件指令实现的原子操作&#xff0c;可以在不使用传统互斥锁的情况下&#xff0c;保证多线程对共享变量的安全访问。在Java中&#xff0c;我们可以使用Atomic类…

2023最新版本 FreeRTOS教程 -6-创建多个任务使用相同的任务函数

利用任务函数的传参即可实现多任务使用相同的任务函数 如下创建了三个任务 使用同一个任务的函数 通过传参实现不同的操作 参数的具体定义 定义结构体和结构体数组 任务函数的具体定义 验证 同一个任务函数输出了三个不同的参数&#xff08;实际改为不同的操作&#xff0…

UnityShader(四)

这次要只用顶点着色器和片元着色器实现水面效果&#xff0c;思路很简单&#xff0c;就是先把顶点坐标从模型空间转变到齐次裁剪空间&#xff0c;再左乘unity_ObjectToWorld矩阵转变到世界坐标&#xff0c;将世界坐标的y按照正弦规律变化即可得到水面的波涛汹涌的效果&#xff0…