Activiti7工作流引擎:实战篇(一) 准备工作

2023-11-21 09:59

本文主要是介绍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=GMTusername: rootpassword: root123driver-class-name: com.mysql.cj.jdbc.Driveractiviti:#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, fullhistory-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;@Overridepublic Collection<? extends GrantedAuthority> getAuthorities() {return null;}@Overridepublic String getPassword() {return password;}@Overridepublic String getUsername() {return username;}@Overridepublic boolean isAccountNonExpired() {return false;}@Overridepublic boolean isAccountNonLocked() {return false;}@Overridepublic boolean isCredentialsNonExpired() {return false;}@Overridepublic 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="55.0" width="85.0" x="0.0" y="0.0"/></bpmndi:BPMNLabel></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="_4" id="Shape-_4"><omgdc:Bounds height="55.0" width="85.0" x="265.0" y="150.0"/><bpmndi:BPMNLabel><omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/></bpmndi:BPMNLabel></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="_5" id="Shape-_5"><omgdc:Bounds height="55.0" width="85.0" x="480.0" y="115.0"/><bpmndi:BPMNLabel><omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/></bpmndi:BPMNLabel></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="_6" id="Shape-_6"><omgdc:Bounds height="55.0" width="85.0" x="485.0" y="260.0"/><bpmndi:BPMNLabel><omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/></bpmndi:BPMNLabel></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="_7" id="Shape-_7"><omgdc:Bounds height="32.0" width="32.0" x="655.0" y="265.0"/><bpmndi:BPMNLabel><omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/></bpmndi:BPMNLabel></bpmndi:BPMNShape><bpmndi:BPMNEdge bpmnElement="_13" id="BPMNEdge__13" sourceElement="_6" targetElement="_7"><omgdi:waypoint x="570.0" y="287.5"/><omgdi:waypoint x="655.0" y="281.0"/><bpmndi:BPMNLabel><omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/></bpmndi:BPMNLabel></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="_12" id="BPMNEdge__12" sourceElement="_5" targetElement="_6"><omgdi:waypoint x="525.0" y="170.0"/><omgdi:waypoint x="525.0" y="260.0"/><bpmndi:BPMNLabel><omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/></bpmndi:BPMNLabel></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="_8" id="BPMNEdge__8" sourceElement="_2" targetElement="_3"><omgdi:waypoint x="37.0" y="176.0"/><omgdi:waypoint x="100.0" y="177.5"/><bpmndi:BPMNLabel><omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/></bpmndi:BPMNLabel></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="_9" id="BPMNEdge__9" sourceElement="_3" targetElement="_4"><omgdi:waypoint x="185.0" y="177.5"/><omgdi:waypoint x="265.0" y="177.5"/><bpmndi:BPMNLabel><omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/></bpmndi:BPMNLabel></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="_11" id="BPMNEdge__11" sourceElement="_4" targetElement="_5"><omgdi:waypoint x="350.0" y="177.5"/><omgdi:waypoint x="480.0" y="142.5"/><bpmndi:BPMNLabel><omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/></bpmndi:BPMNLabel></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="_10" id="BPMNEdge__10" sourceElement="_4" targetElement="_6"><omgdi:waypoint x="350.0" y="177.5"/><omgdi:waypoint x="485.0" y="287.5"/><bpmndi:BPMNLabel><omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/></bpmndi:BPMNLabel></bpmndi:BPMNEdge></bpmndi:BPMNPlane></bpmndi:BPMNDiagram>
</definitions>

6. main

配置Mapper扫描包。

@SpringBootApplication
@MapperScan("com.example.demo.mapper")
public class SpringbootActivitiApplication {public static void main(String[] args) {SpringApplication.run(SpringbootActivitiApplication.class, args);}
}

知识传送门 》》》》》》》》》》》》》》》》》》》

这篇关于Activiti7工作流引擎:实战篇(一) 准备工作的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/401594

相关文章

SpringBoot整合Flowable实现工作流的详细流程

《SpringBoot整合Flowable实现工作流的详细流程》Flowable是一个使用Java编写的轻量级业务流程引擎,Flowable流程引擎可用于部署BPMN2.0流程定义,创建这些流程定义的... 目录1、流程引擎介绍2、创建项目3、画流程图4、开发接口4.1 Java 类梳理4.2 查看流程图4

LiteFlow轻量级工作流引擎使用示例详解

《LiteFlow轻量级工作流引擎使用示例详解》:本文主要介绍LiteFlow是一个灵活、简洁且轻量的工作流引擎,适合用于中小型项目和微服务架构中的流程编排,本文给大家介绍LiteFlow轻量级工... 目录1. LiteFlow 主要特点2. 工作流定义方式3. LiteFlow 流程示例4. LiteF

SpringBoot集成LiteFlow实现轻量级工作流引擎的详细过程

《SpringBoot集成LiteFlow实现轻量级工作流引擎的详细过程》LiteFlow是一款专注于逻辑驱动流程编排的轻量级框架,它以组件化方式快速构建和执行业务流程,有效解耦复杂业务逻辑,下面给大... 目录一、基础概念1.1 组件(Component)1.2 规则(Rule)1.3 上下文(Conte

Python基于微信OCR引擎实现高效图片文字识别

《Python基于微信OCR引擎实现高效图片文字识别》这篇文章主要为大家详细介绍了一款基于微信OCR引擎的图片文字识别桌面应用开发全过程,可以实现从图片拖拽识别到文字提取,感兴趣的小伙伴可以跟随小编一... 目录一、项目概述1.1 开发背景1.2 技术选型1.3 核心优势二、功能详解2.1 核心功能模块2.

详解如何使用Python构建从数据到文档的自动化工作流

《详解如何使用Python构建从数据到文档的自动化工作流》这篇文章将通过真实工作场景拆解,为大家展示如何用Python构建自动化工作流,让工具代替人力完成这些数字苦力活,感兴趣的小伙伴可以跟随小编一起... 目录一、Excel处理:从数据搬运工到智能分析师二、PDF处理:文档工厂的智能生产线三、邮件自动化:

基于Python开发一个有趣的工作时长计算器

《基于Python开发一个有趣的工作时长计算器》随着远程办公和弹性工作制的兴起,个人及团队对于工作时长的准确统计需求日益增长,本文将使用Python和PyQt5打造一个工作时长计算器,感兴趣的小伙伴可... 目录概述功能介绍界面展示php软件使用步骤说明代码详解1.窗口初始化与布局2.工作时长计算核心逻辑3

RabbitMQ工作模式中的RPC通信模式详解

《RabbitMQ工作模式中的RPC通信模式详解》在RabbitMQ中,RPC模式通过消息队列实现远程调用功能,这篇文章给大家介绍RabbitMQ工作模式之RPC通信模式,感兴趣的朋友一起看看吧... 目录RPC通信模式概述工作流程代码案例引入依赖常量类编写客户端代码编写服务端代码RPC通信模式概述在R

MySQL 存储引擎 MyISAM详解(最新推荐)

《MySQL存储引擎MyISAM详解(最新推荐)》使用MyISAM存储引擎的表占用空间很小,但是由于使用表级锁定,所以限制了读/写操作的性能,通常用于中小型的Web应用和数据仓库配置中的只读或主要... 目录mysql 5.5 之前默认的存储引擎️‍一、MyISAM 存储引擎的特性️‍二、MyISAM 的主

Go 语言中的select语句详解及工作原理

《Go语言中的select语句详解及工作原理》在Go语言中,select语句是用于处理多个通道(channel)操作的一种控制结构,它类似于switch语句,本文给大家介绍Go语言中的select语... 目录Go 语言中的 select 是做什么的基本功能语法工作原理示例示例 1:监听多个通道示例 2:带

kotlin中的模块化结构组件及工作原理

《kotlin中的模块化结构组件及工作原理》本文介绍了Kotlin中模块化结构组件,包括ViewModel、LiveData、Room和Navigation的工作原理和基础使用,本文通过实例代码给大家... 目录ViewModel 工作原理LiveData 工作原理Room 工作原理Navigation 工