赞
踩
我们在项目中需要使用到Flowable,鉴于之前对流程引擎并不是很了解,这里准备写一篇作为入门文章。
这次例子是基于springboot + Flowable ,springboot 的版本是2.3.4.RELEASE,Flowable 的版本为6.3.0
1、依赖
<!--flowable工作流依赖--> <dependency> <groupId>org.flowable</groupId> <artifactId>flowable-spring-boot-starter</artifactId> <version>6.3.0</version> <exclusions> <exclusion> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> </exclusion> </exclusions> </dependency> <!-- 加载jdbc连接数据库 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <!-- 加载mybatis jar包 --> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.3.2</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.10</version> <scope>compile</scope> </dependency>
2、依赖(主要添加数据库和flowable相关依赖)
server: port: 8082 spring: datasource: driverClassName: com.mysql.cj.jdbc.Driver type: com.zaxxer.hikari.HikariDataSource url: jdbc:mysql://localhost:3306/test_mybatis?serverTimezone=Asia/Shanghai username: root password: 123456 hikari: read-only: false #客户端等待连接池连接的最大毫秒数 connection-timeout: 60000 #允许连接在连接池中空闲的最长时间(以毫秒为单位) idle-timeout: 60000 #连接将被测试活动的最大时间量 validation-timeout: 3000 #池中连接关闭后的最长生命周期 max-lifetime: 60000 #最大池大小 maximum-pool-size: 60 #连接池中维护的最小空闲连接数 minimum-idle: 10 #从池返回的连接的默认自动提交行为。默认值为true auto-commit: true #如果您的驱动程序支持JDBC4,我们强烈建议您不要设置此属性 connection-test-query: SELECT 1 #自定义连接池名称 pool-name: myHikarCp flowable: database-schema-update: false #关闭定时任务JOB async-executor-activate: false
3、如何定义xml
flowable建议采用业界标准BPMN2.0的XML来描述需要定义的工作流。所以我们需要在项目中创建一个流程定义,下面这个是我创建的一个xml定义,
很多文章上面并没有如何定义BPMN2.0的XML的操作(主要需要 tomcat 和下载flower)
(1) 下载tomcat
[tomcat 下载官网](https://tomcat.apache.org/download-80.cgi)
(2) 下载flowable的zip文件
https://github.com/flowable/flowable-engine/releases/download/flowable-6.4.0/flowable-6.4.0.zip 下载flowable的zip文件
下载下来解压之后,我们把flowable-6.4.0/wars 下的所有war包复制到tomcat/webapps下面:
拷入
(3)登录编辑流程图
启动成功之后,可以登陆创建流程:http://localhost:8080/flowable-modeler :
默认账号密码:admin 密码 test
BPMN2.0 图有两个需要注意的地方,确定Flowable 中的审批,驳回放置内容(这里例子用的${taskUser} ,也可以用其他的,决定放置到那个地方)
这里判断之后走那个流程需要(${finishFlag==“NO”} 或者 ${finishFlag==“YES”} )选择走那个方向,这里的这两个都是自定义的
3、例子使用BPMN2.0的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:xsd="http://www.w3.org/2001/XMLSchema" 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="adviceApply" name="投诉建议" isExecutable="true">
<documentation>投诉建议流程</documentation>
<startEvent id="startEvent1" name="开始" flowable:formFieldValidation="true"></startEvent>
<userTask id="customerService" name="客服代表" flowable:candidateGroups="${customerServiceId}" flowable:formFieldValidation="true"></userTask>
<sequenceFlow id="sid-C443333F-D5FF-41E4-9F84-AA4B33BC57AB" sourceRef="startEvent1" targetRef="customerService"></sequenceFlow>
<userTask id="department" name="部门领导" flowable:assignee="${taskUser}" flowable:formFieldValidation="true">
<extensionElements>
<modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
</extensionElements>
</userTask>
<userTask id="support" name="专业主管" flowable:assignee="${taskUser}" flowable:formFieldValidation="true">
<extensionElements>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。