mysql数据库

目录

  • 1.部署流程
  • 2.引入流程引擎
  • 3.启动流程
  • 4.查询待办列表
  • 5.审批通过
  • 6.查询已办列表
  • 7.查询发起列表

1.部署流程

举例:部署一个如下图的流程

在src/main/resources下创建processes文件夹,然后新建bpmn20.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:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:flowable="http://flowable.org/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.flowable.org/processdef"><!-- 流程定义信息id:在数据库里会存在key_字段中name:流程名字--><process id="process_fzoauj5k" name="审核流程"><!--开始事件:流程的起点id:开始节点的IDname:开始节点的名称outgoing:记录连线的顺序流,outgoing表示从该节点输出的线--><startEvent id="startNode1" name="开始"><outgoing>Flow_0ksehsm</outgoing></startEvent><!--结束事件:流程的终点id:结束节点的IDname:结束节点的名称incoming:记录连线的顺序流,incoming表示输入该节点的线--><endEvent id="Event_08rzeth" name="结束"><incoming>Flow_18upiqx</incoming></endEvent><!--顺序流:执行时会从一个节点流向另一个节点id:顺序流的IDsourceRef:源头节点IDtargetRef:目标节点ID--><sequenceFlow id="Flow_0ksehsm" sourceRef="startNode1" targetRef="Activity_01fk1po" /><sequenceFlow id="Flow_1huwgzm" sourceRef="Activity_01fk1po" targetRef="Activity_0ipmowu" /><sequenceFlow id="Flow_18upiqx" sourceRef="Activity_0ipmowu" targetRef="Event_08rzeth" /><!--用户任务:需要指定用户来执行flowable:assignee:任务受理人,这里先写为固定,设受理人的用户ID为1incoming:记录连线的顺序流,incoming表示输入该节点的线outgoing:记录连线的顺序流,outgoing表示从该节点输出的线--><userTask id="Activity_01fk1po" name="申请" flowable:assignee="1"><incoming>Flow_0ksehsm</incoming><outgoing>Flow_1huwgzm</outgoing></userTask><!--用户任务:需要指定用户来执行flowable:assignee:任务受理人,这里先写为固定,设受理人的用户ID为2--><userTask id="Activity_0ipmowu" name="审核" flowable:assignee="2"><incoming>Flow_1huwgzm</incoming><outgoing>Flow_18upiqx</outgoing></userTask></process><!--节点在流程图中的位置,没有前端可不写--><bpmndi:BPMNDiagram id="BPMNDiagram_flow"><bpmndi:BPMNPlane id="BPMNPlane_flow" bpmnElement="process_fzoauj5k"><bpmndi:BPMNEdge id="Flow_0ksehsm_di" bpmnElement="Flow_0ksehsm"><di:waypoint x="-15" y="190" /><di:waypoint x="70" y="190" /></bpmndi:BPMNEdge><bpmndi:BPMNEdge id="Flow_1huwgzm_di" bpmnElement="Flow_1huwgzm"><di:waypoint x="170" y="190" /><di:waypoint x="260" y="190" /></bpmndi:BPMNEdge><bpmndi:BPMNEdge id="Flow_18upiqx_di" bpmnElement="Flow_18upiqx"><di:waypoint x="360" y="190" /><di:waypoint x="452" y="190" /></bpmndi:BPMNEdge><bpmndi:BPMNShape id="BPMNShape_startNode1" bpmnElement="startNode1"><omgdc:Bounds x="-45" y="175" width="30" height="30" /><bpmndi:BPMNLabel><omgdc:Bounds x="-42" y="212" width="22" height="14" /></bpmndi:BPMNLabel></bpmndi:BPMNShape><bpmndi:BPMNShape id="Event_08rzeth_di" bpmnElement="Event_08rzeth"><omgdc:Bounds x="452" y="172" width="36" height="36" /><bpmndi:BPMNLabel><omgdc:Bounds x="459" y="215" width="22" height="14" /></bpmndi:BPMNLabel></bpmndi:BPMNShape><bpmndi:BPMNShape id="Activity_19z5ig5_di" bpmnElement="Activity_01fk1po"><omgdc:Bounds x="70" y="150" width="100" height="80" /></bpmndi:BPMNShape><bpmndi:BPMNShape id="Activity_09wpg3z_di" bpmnElement="Activity_0ipmowu"><omgdc:Bounds x="260" y="150" width="100" height="80" /></bpmndi:BPMNShape></bpmndi:BPMNPlane></bpmndi:BPMNDiagram></definitions>

启动springboot,resource/processes/下的bpmn文件将会自动载入,数据会保存在act_re_deployment和act_re_procdef表中。

act_re_deployment( 部署信息表)

字段 字段名称 字段默认值 数据类型 备注
ID_ 主键 varchar
NAME_ 名称 varchar
CATEGORY_ 分类 varchar
TENANT_ID_ 租户ID varchar
DEPLOY_TIME_ 部署时间 timestamp

act_re_procdef( 流程定义数据表)

字段 字段名称 字段默认值 数据类型 备注
ID_ 主键 varchar
REV_ 版本号 int
CATEGORY_ 分类 varchar
NAME_ 名称 varchar
KEY_ 标识 varchar
VERSION_ 版本 int
DEPLOYMENT_ID_ 部署ID varchar
RESOURCE_NAME_ 资源名称 varchar
DGRM_RESOURCE_NAME_ 图片资源名称 varchar
DESCRIPTION_ 描述 varchar
HAS_START_FORM_KEY_ 表单是否有开始节点的标识 tinyint start节点是否存在formKey
0否 1是
HAS_GRAPHICAL_NOTATION_ 拥有图形信息 tinyint
SUSPENSION_STATE_ 挂起状态 int
暂停状态 1激活 2暂停
TENANT_ID_ 租户ID varchar

2.引入流程引擎

FlowServiceFactory.java

package com.example.demo.factory;import org.flowable.engine.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.flowable.form.api.FormService;import javax.annotation.Resource;/*** flowable 引擎注入封装*/
@Component
public class FlowServiceFactory {@Resourceprotected RepositoryService repositoryService;@Resourceprotected RuntimeService runtimeService;@Resourceprotected IdentityService identityService;@Resourceprotected TaskService taskService;@Resourceprotected FormService formService;@Resourceprotected HistoryService historyService;@Resourceprotected ManagementService managementService;@Qualifier("processEngine")@Resourceprotected ProcessEngine processEngine;public RepositoryService getRepositoryService() {return repositoryService;}public RuntimeService getRuntimeService() {return runtimeService;}public IdentityService getIdentityService() {return identityService;}public TaskService getTaskService() {return taskService;}public FormService getFormService() {return formService;}public HistoryService getHistoryService() {return historyService;}public ManagementService getManagementService() {return managementService;}public ProcessEngine getProcessEngine() {return processEngine;}
}

3.启动流程

上面引入的xml文件相当于定义了一套工作流程,大家都可以使用这个流程。
拿请假流程举例:人员A和B都申请请假,那么就认为A启动了一次流程,B也启动了一次流程。这一套流程就拥有了两个流程实例。

package com.example.demo.controller;import org.flowable.engine.IdentityService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.runtime.ProcessInstance;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;@RestController
public class ProcessController {private final RuntimeService runtimeService;private final IdentityService identityService;public ProcessController(RuntimeService runtimeService, IdentityService identityService) {this.runtimeService = runtimeService;this.identityService = identityService;}@PostMapping("/start")@Transactional(rollbackFor = Exception.class)public String start(@RequestParam String key) {try {// 设置流程启动用户identityService.setAuthenticatedUserId("1");//根据key启动(还可以根据ID、TENANT_ID_启动),返回流程实例(正在运行的流程)ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(key);String processInstanceId = processInstance.getProcessInstanceId();//返回流程实例IDreturn processInstanceId;} catch (Exception e) {e.printStackTrace();return "启动失败!";}}}

使用postman访问接口,其中key为xml中的流程id

启动完成之后,返回了流程实例ID,运行中的流程数据会保存到act_ru_actinst、act_ru_execution、act_ru_identitylink、act_ru_task表中

act_ru_actinst:存储运行中各个节点的信息:

act_ru_identitylink: 存储候选用户、处理人相关数据

act_ru_task :存储审批代办相关信息

Flowable包下的常用服务类:
RuntimeService :用于查询运行中的流程实例相关信息。
TaskService:用于查询代办、代签、签收、办理等操作。
HistoryService:用于查询流程相关历史数据。

4.查询待办列表

@Autowiredprivate TaskService taskService;/**获取指定用户的待办的任务列表* 代办* */@GetMapping("/getNeedDoTasks")@Transactional(rollbackFor = Exception.class)public String getNeedDoTasks() {//设当前登录用户IDString userId = "1";//taskCandidateOrAssigned 表示不管是任务的候选人还是直接分配的人都可以查到List<Task> tasks = taskService.createTaskQuery().taskCandidateOrAssigned(userId).list();if (!tasks.isEmpty()) {List<Map<String, Object>> list = new ArrayList<>();for (Task task : tasks) {Map<String, Object> map = new HashMap<>();//代办idString taskId = task.getId();//代办节点名称String taskName = task.getName();//创建时间Date createTime = task.getCreateTime();map.put("taskId", taskId);map.put("taskName", taskName);map.put("createTime", createTime);list.add(map);}return listToString(list,',');}return "当前用户在当前流程实例中并无待办!";}// 列表转字符串public String listToString(List list, char separator) {StringBuilder sb = new StringBuilder();for (int i = 0; i < list.size(); i++) {sb.append(list.get(i)).append(separator);}return sb.toString().substring(0,sb.toString().length()-1);}

发起查询

可以看到用户“1”有一条待办任务,任务ID为71a2deb3-b25b-11ec-9428-d46a6adef6a5
接下来我们去审批这个任务。

5.审批通过

/**审批通过并跳转流程*/@GetMapping("/audit")@Transactional(rollbackFor = Exception.class)public String audit(@RequestParam String taskId) {try {//跳转流程taskService.complete(taskId);return "已审批";} catch (Exception e) {e.printStackTrace();return "跳转失败!";}}

访问接口:

审批成功后我们再查询一下待办任务列表看看还有没有待办

可以看到,审批通过后,在用户“1”的待办任务里已经查不到刚才的任务了。
接下来我们去看看用户“1”的已办任务列表。

6.查询已办列表

    @Autowiredprivate HistoryService historyService;/**获取已办任务列表* 已办* */@GetMapping("/getAlreadyDoTasks")@Transactional(rollbackFor = Exception.class)public String getAlreadyDoTasks() {//获取当前登录用户IDlong userId = 1L;List<HistoricTaskInstance> taskInstanceQuery = historyService.createHistoricTaskInstanceQuery().includeProcessVariables().finished().taskAssignee(userId+"").orderByHistoricTaskInstanceEndTime().desc().list();if (!taskInstanceQuery.isEmpty()) {List<Map<String, Object>> list = new ArrayList<>();for (HistoricTaskInstance task : taskInstanceQuery) {Map<String, Object> map = new HashMap<>();//代办idString taskId = task.getId();//代办节点名称String taskName = task.getName();//创建时间Date createTime = task.getCreateTime();map.put("taskId", taskId);map.put("taskName", taskName);map.put("createTime", createTime);list.add(map);}return listToString(list,',');}return "暂无已办";}

访问接口:

可以看到刚才的申请任务已经进入到了已办列表。

7.查询发起列表

/**获取我发起的流程列表* 发起* 流程列表* */@GetMapping("/getMyStartUpProcesses")@Transactional(rollbackFor = Exception.class)public String getMyStartUpProcesses() {List<HistoricProcessInstance> historicProcessInstanceList=historyService.createHistoricProcessInstanceQuery().startedBy("1").includeProcessVariables().orderByProcessInstanceStartTime().desc().list();return listToString(historicProcessInstanceList,',');}

访问接口:

可以看到用户“1”,发起了一个【审核流程】。

完事了,下一节写动态设置审批人。

springboot+flowable第二节(流程基本操作)相关推荐

  1. springboot+flowable请假详细流程

    1. flowable-ui 目前flowable-ui主要用于画流程图,流程图画完之后,再对XML做适当的修改 docker安装使用flowable docker run -d -p 8080:80 ...

  2. C语言基础第六课——第二节if语句(if-else格式、不带else的if结构)、借例题简述写代码流程、从键盘上输入三个整数,求出其中的最大数(打擂法、三目运算符、排序)、if语句的嵌套计算个人所得税

    C语言基础第六课--第二节 一.if语句概述 二.标准if-else格式 三.借例题简述写代码流程 四.不带else的if结构 五.例题:从键盘上输入三个整数,求出其中的最大数.(打擂法.三目运算符. ...

  3. SpringBoot+flowable快速实现工作流,so easy!

    欢迎关注方志朋的博客,回复"666"获面试宝典 来源:blog.csdn.net/zhan107876/article/ details/120815560 总览 使用flowab ...

  4. 工作流引擎 SpringBoot+flowable完美结合,快速实现工作流,so easy

    flowable 起源 在2016.7~2017.5期间activiti团队内部已经产生了重大的分歧.关于新的activiti新团队与原有的团队重要开发人员我们罗列一下,细节如下: 上图是Tijs R ...

  5. iHRM 人力资源管理系统_第9章_文件上传与PDF报表入门_第二节_PDF报表入门

    iHRM 人力资源管理系统_第9章_文件上传与PDF报表入门_第二节_PDF报表入门 文章目录 iHRM 人力资源管理系统_第9章_文件上传与PDF报表入门_第二节_PDF报表入门 PDF报表入门 3 ...

  6. 第二节:SpingBoot单元测试

    SpingBoot 365计划开始更新了,计划手敲365个SpringBoot案例回顾总结形成知识体系.目前已经输出了32节的内容.所有源码托管在GitHub和Gitee上. 1.第一节:创建Spri ...

  7. 第二节认识计算机教案,第二章 第二节 局域网的构建 教学设计_博客

    <第二章 第二节 局域网的构建 教学设计_博客>由会员分享,可在线阅读,更多相关<第二章 第二节 局域网的构建 教学设计_博客(3页珍藏版)>请在装配图网上搜索. 1.第二章 ...

  8. 真是没想到,Springboot + Flowable 开发工作流会这么简单!

    " 程序员是块砖,哪里需要哪里搬. " 公司内部的OA系统最近要升级改造,由于人手不够就把我借调过去了,但说真的我还没做过这方面的功能,第一次接触工作流的开发,还是有点好奇是个怎样 ...

  9. 《如何搭建小微企业风控模型》第二节 建模所需知识

    <如何搭建小微企业风控模型>第二节 建模所需知识 第一章 小微企业数据风控技术的框架 小微企业数据贷发展情况概述 搭建小微企业风控模型所需知识 风控模型概览 第二章 强相关变量:企业经营数 ...

最新文章

  1. 端云一体人工智能开发平台整体架构
  2. Centos7上yum安装redis
  3. leetcode算法题--逆波兰表达式求值
  4. Matlab画三维曲线入门
  5. dl 系列服务器,DL系列服务器内存总结..doc
  6. Java项目 常用包的命名及理解【dao包、domain包、service包、utils包、web包、impl包】
  7. Python字符串讲解举例—工资字符串
  8. 芝麻信用_别忘查看支付宝芝麻信用分,这些特权别浪费
  9. Hey, everybody!
  10. python求散点曲线下方面积
  11. loadrunner简介
  12. 两本关于sharepoint 2010的书值得参考
  13. spring-cloud-sleuth 和 分布式链路跟踪系统
  14. [从零开始学FPGA编程-2]:本系列主要内容预览(持续更新):快速入门篇、提升篇、高阶篇
  15. 有关白鹭egret引擎EUI Editor 打开项目报错问题的解决
  16. 精通使用K米短信教程
  17. 一个偶然发现还挺有意思的逻辑题
  18. 15_Elasticsearch 内部原理详细解析(下篇)
  19. win+e替换为xyplorer打开
  20. telegram怎么搜索机器人_telegram机器人

热门文章

  1. 多元线性回归matlab代码例题_多元线性回归matlab程序
  2. java中IO流的标准异常处理代码
  3. Python生成随机高斯模糊图片
  4. Tornado是为何物
  5. ExtJs2.0学习系列(15)--extjs换肤
  6. C++ C# 中作用域限定符
  7. 钉钉免登陆前端操作详解
  8. [深度学习-实践]CycleGAN的入门例子-Tensorflow2.1-keras
  9. python做定时任务的方式及优缺点_Python3-定时任务四种实现方式
  10. 深度学习的实用层面 —— 1.8 其它正则化方法