Activiti7工作流引擎:实战篇 准备工作
Posted vbirdbest
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Activiti7工作流引擎:实战篇 准备工作相关的知识,希望对你有一定的参考价值。
本来我是想买块肉的,但是现在我只能买块豆腐。
1. pom.xml
引入最新版本 activiti-spring-boot-starter依赖和spring-boot-starter-security。
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter</artifactId>
<version>7.1.0.M6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
2. application.yml
spring:
datasource:
url: jdbc:mysql://localhost:3306/activiti?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT
username: root
password: root123
driver-class-name: com.mysql.cj.jdbc.Driver
activiti:
#1.flase: 默认值。activiti在启动时,会对比数据库表中保存的版本,如果没有表或者版本不匹配,将抛出异常
#2.true: activiti会对数据库中所有表进行更新操作。如果表不存在,则自动创建
#3.create_drop: 在activiti启动时创建表,在关闭时删除表(必须手动关闭引擎,才能删除表)
#4.drop-create: 在activiti启动时删除原来的旧表,然后在创建新表(不需要手动关闭引擎)
database-schema-update: true
#检测历史表是否存在 activiti7默认没有开启数据库历史记录 启动数据库历史记录
db-history-used: true
#记录历史等级 可配置的历史级别有none, activity, audit, full
history-level: full
#校验流程文件,默认校验resources下的processes文件夹里的流程文件
check-process-definitions: false
3. database
-- 用户表,用于登录和Spring Security集成, 密码: 123456
CREATE TABLE `tb_user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`age` int(40) DEFAULT NULL,
`username` varchar(100) DEFAULT NULL,
`password` varchar(100) DEFAULT NULL,
`email` varchar(100) DEFAULT NULL,
`gender` int(40) DEFAULT NULL,
`role` varchar(100) DEFAULT NULL,
`rolegroup` varchar(100) DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;
INSERT INTO `tb_user` VALUES (1, 20, 'jack', '$2a$10$9FIX76XUZgIyiOTjy5iswe9fJrWuaxAwTLsJb0QFJAcu5OqTb/TJS', '123@123.com', 1, 'ADMIN', 'activiti_user');
INSERT INTO `tb_user` VALUES (2, 25, 'rose', '$2a$10$9FIX76XUZgIyiOTjy5iswe9fJrWuaxAwTLsJb0QFJAcu5OqTb/TJS', '234@234.com', 2, 'ADMIN', 'activiti_user');
INSERT INTO `tb_user` VALUES (3, 22, 'tom', '$2a$10$9FIX76XUZgIyiOTjy5iswe9fJrWuaxAwTLsJb0QFJAcu5OqTb/TJS', '345@35.com', 1, 'ADMIN', 'activiti_user');
INSERT INTO `tb_user` VALUES (4, 30, 'jerry', '$2a$10$9FIX76XUZgIyiOTjy5iswe9fJrWuaxAwTLsJb0QFJAcu5OqTb/TJS', '456@456.com', 2, 'ADMIN', 'activiti_user');
-- 出差表:保存业务相关数据
CREATE TABLE `tb_evection` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`evectionName` varchar(100) DEFAULT NULL,
`num` double DEFAULT NULL,
`destination` varchar(100) DEFAULT NULL,
`begindate` date DEFAULT NULL,
`enddate` date DEFAULT NULL,
`reson` varchar(100) DEFAULT NULL,
`state` int(4) DEFAULT NULL,
`userid` int(20) DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;
4. entity
需要实现SpringSecurity中的UserDetails接口。
@Data
public class User implements Serializable, UserDetails
private Long id;
private String username;
private String password;
private String email;
private Integer gender;
private Integer age;
private String role;
@Override
public Collection<? extends GrantedAuthority> getAuthorities()
return null;
@Override
public String getPassword()
return password;
@Override
public String getUsername()
return username;
@Override
public boolean isAccountNonExpired()
return false;
@Override
public boolean isAccountNonLocked()
return false;
@Override
public boolean isCredentialsNonExpired()
return false;
@Override
public boolean isEnabled()
return false;
/**
* 出差申请
*/
@Data
public class Evection implements Serializable
private Long id;
private Long userid;
/** 出差申请单名称 */
private String evectionName;
/** 出差天数 */
private Double num;
/** 预计开始时间 */
private Date beginDate;
/** 预计结束时间 */
private Date endDate;
/** 目的地 */
private String destination;
/** 出差事由 */
private String reson;
/** 0-初始录入,1-开始审批,2-审批完成 */
private int state;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result
private Integer status;
private String message;
5. bpmn
evection.bpmn
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.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" xmlns:tns="http://www.activiti.org/test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" expressionLanguage="http://www.w3.org/1999/XPath" id="m1585999805036" name="" targetNamespace="http://www.activiti.org/test" typeLanguage="http://www.w3.org/2001/XMLSchema">
<process id="evection" isClosed="false" isExecutable="true" name="出差申请" processType="None">
<startEvent id="_2" name="StartEvent"/>
<userTask activiti:assignee="$assignee0" activiti:exclusive="true" id="_3" name="创建出差申请">
<extensionElements>
<activiti:taskListener class="com.itheima.listener.MyTaskListener" event="assignment"/>
</extensionElements>
</userTask>
<userTask activiti:assignee="$assignee1" activiti:exclusive="true" id="_4" name="部门经理审核">
<extensionElements>
<activiti:taskListener class="com.itheima.listener.MyTaskListener" event="assignment"/>
</extensionElements>
</userTask>
<userTask activiti:assignee="$assignee2" activiti:exclusive="true" id="_5" name="总经理审批">
<extensionElements>
<activiti:taskListener class="com.itheima.listener.MyTaskListener" event="assignment"/>
</extensionElements>
</userTask>
<userTask activiti:assignee="$assignee3" activiti:exclusive="true" id="_6" name="财务审批">
<extensionElements>
<activiti:taskListener class="com.itheima.listener.MyTaskListener" event="assignment"/>
</extensionElements>
</userTask>
<endEvent id="_7" name="EndEvent">
<extensionElements>
<activiti:executionListener class="com.itheima.listener.MyExecutionListener" event="end"/>
</extensionElements>
</endEvent>
<sequenceFlow id="_8" sourceRef="_2" targetRef="_3"/>
<sequenceFlow id="_9" sourceRef="_3" targetRef="_4"/>
<sequenceFlow id="_10" sourceRef="_4" targetRef="_6">
<conditionExpression xsi:type="tFormalExpression">
<![CDATA[$evection.num<3]]>
</conditionExpression>
</sequenceFlow>
<sequenceFlow id="_11" sourceRef="_4" targetRef="_5">
<conditionExpression xsi:type="tFormalExpression">
<![CDATA[$evection.num>=3]]>
</conditionExpression>
</sequenceFlow>
<sequenceFlow id="_12" sourceRef="_5" targetRef="_6"/>
<sequenceFlow id="_13" sourceRef="_6" targetRef="_7"/>
</process>
<bpmndi:BPMNDiagram documentation="background=#FFFFFF;count=1;horizontalcount=1;orientation=0;width=842.4;height=1195.2;imageableWidth=832.4;imageableHeight=1185.2;imageableX=5.0;imageableY=5.0" id="Diagram-_1" name="New Diagram">
<bpmndi:BPMNPlane bpmnElement="evection">
<bpmndi:BPMNShape bpmnElement="_2" id="Shape-_2">
<omgdc:Bounds height="32.0" width="32.0" x="5.0" y="160.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="_3" id="Shape-_3">
<omgdc:Bounds height="55.0" width="85.0" x="100.0" y="150.0"/>
<bpmndi:BPMNLabel>
<omgdc:Bounds height=以上是关于Activiti7工作流引擎:实战篇 准备工作的主要内容,如果未能解决你的问题,请参考以下文章
Activiti7工作流引擎:实战篇 与SpringSecurity集成
Activiti7工作流引擎:实战篇 与SpringSecurity集成