文章目录
- 一.activiti
-
- 1.什么是activiti7
- 2.activiti7所需的安装环境
- 3.Activiti自动创建数据库表
- 4.Activiti各表的意义
- 5.创建流程引擎
- 6.service服务接口
-
- (1)service创建方式
- (2)service总览
- 7.流程定义
- 8.流程部署
-
- (1)部署代码
- (2)部署影响的数据库表
- (3)zip流程部署的方式
- 9.启动流程实例
-
- (1)启动代码
- (2)操作数据库表
- 10.查询个人待执行的任务
-
- (1)代码
- 11.完成个人待办任务
-
- (1)代码
- 12.查询流程定义
- 13.删除流程部署
- 14.下载部署文件
- 15.查看历史信息
- 16.activiti与业务系统集成
-
- (1)添加businesskey到activiti表中
- (2)挂起和激活过程
- 17.个人任务
-
- (1)任务分配负责人
- 二.监听器
-
- 1.任务监听器
-
- (1)定义
- (2)xml文件配置
- (3)监听器指定任务负责人
- 2.执行监听器
-
- (1)定义
- 三.流程变量
-
- 1.定义
- 2.流程变量支持的类型
- 3.流程变量作用域
-
- (1)globa变量
- (2)local变量
- 4.流程变量的使用方法
-
- (1)使用属性UEL表达式
- (2)在线使用UEL表达式
- 5.测试全局流程变量
-
- (1)在启动过程中设置变量
- (2)任务处理时设置变量
- (3)通过当前流程实例设置变量
- (4)设置当前任务
- 6.测试local局部变量
-
- (1)办理任务时设置
- (2)设置当前任务
- 四.组任务
-
- 1.需求
- 2.xml文件
- 3.组任务处理流程
-
- (1)查询组的任务
- (2)拾取(claim)任务
- (3)查询个人任务
- (4)办理个人任务
- (5)归还任务到组任务
- (6)任务交接
- 五.网关
-
- 1、排他网关ExclusiveGateway
- 2、并行网关parallelGateway
- 3.包含网关inclusiveGateway
- 4.事件网关
- 六.activiti与第三方整合
-
- 1.和spring整合
-
- (1)pom.xml引入
- (2)创建activiti和spring集成配置文件activiti-spring.xml
- 2.和springboot整合
-
- (1)pom.xml引入
- (2)配置文件application.yml
- (3)添加springsecurity安全框架集成配置
- (4)添加DemoApplicationConfig类
一.activiti
1.什么是activiti7
业务流程管理项目(BPM)
activiti,它是一种工作流引擎,可以提取业务系统中复杂的业务流程,并使用特殊的建模语言BPMN2.0定义业务流程按照预定义流程执行,实现系统流程activiti管理,减少业务系统因流程变化而升级的工作量,从而提高系统的健康度。
2.activiti7所需的安装环境
(1)所需jar包
1、activiti-engine-7.0.0.beta1.jar
2、activiti 依赖的 jar 包: mybatis、 alf4j、 log4j 等
3、activiti 依赖的 spring 包
4、mysql数据库驱动(数据库驱动可以根据自己的需要进行更多的变化,详细参考activiti支持的数据库)
5.第三方数据连接池 dbcp
6、单元测试 Junit-4.12.jar(用于测试activiti)
(2)pom.xml
<properties> <slf4j.version>1.6.6</slf4j.version> <log4j.version>1.2.12</log4j.version> <activiti.version>7.0.0.Beta1</activiti.version> </properties> <dependencies> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-engine</artifactId> <version>${
activiti.version}</version> </dependency> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-spring</artifactId> <version>${
activiti.version}</version> </dependency> <!-- bpmn 模型处理 --> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-bpmn-model</artifactId> <version>${
activiti.version}</version> </dependency> <!-- bpmn 转换 --> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-bpmn-converter</artifactId> <version>${
activiti.version}</version> </dependency> <!-- bpmn json数据转换 --> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-json-converter</artifactId> <version>${
activiti.version}</version> </dependency> <!-- bpmn 布局 --> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-bpmn-layout</artifactId> <version>${
activiti.version}</version> </dependency> <!-- activiti 云支持 --> <dependency> <groupId>org.activiti.cloud</groupId> <artifactId>activiti-cloud-services-api</artifactId> <version>${
activiti.version}</version> </dependency> <!-- mysql驱动 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.40</version> </dependency> <!-- mybatis --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.4.5</version> </dependency> <!-- 链接池 --> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>1.4</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> <!-- log start --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>${
log4j.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>${
slf4j.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${
slf4j.version}</version> </dependency> </dependencies>
(3)在resources文件夹下创建日志配置文件以及activiti所需配置文件activiti.cfg.xml
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/contex http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<!--dbcp连接池-->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/activiti?serverTimezone=GMT&nullCatalogMeansCurrent=true"/>
<property name="username" value="root"/>
<property name="password" value="19980420"/>
<property name="maxActive" value="3"/>
<property name="maxIdle" value="1"/>
</bean>
<!--在默认方式下,bean的id固定为processEngineConfiguration-->
<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<!--配置数据库连接池-->
<property name="dataSource" ref="dataSource"/>
<!-- 配置数据库相关内容-->
<!-- <property name="jdbcDriver" value="com.mysql.cj.jdbc.Driver"/>-->
<!-- <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activiti?serverTimezone=GMT&nullCatalogMeansCurrent=true"/>-->
<!-- <property name="jdbcUsername" value="root"/>-->
<!-- <property name="jdbcPassword" value="19980420"/>-->
<!-- activiti在创建数据库时的策略,为true时,若存在相应的表,则使用,若不存在则创建-->
<property name="databaseSchemaUpdate" value="true"/>
</bean>
</beans>
日志配置文件
# Set root category priority to INFO and its only appender to CONSOLE.
#log4j.rootCategory=INFO, CONSOLE debug info warn error fatal
log4j.rootCategory=debug, CONSOLE, LOGFILE
# Set the enterprise logger category to FATAL and its only appender to CONSOLE.
log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE
# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{
ISO8601} %-6r[%15.15t] %-5p %30.30c %x - %m\n
# LOGFILE is set to be a File appender using a PatternLayout.
log4j.appender.LOGFILE=org.apache.log4j.FileAppender
log4j.appender.LOGFILE.File=f:\act\activiti.log
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=%d{
ISO8601} %-6r[%15.15t] %-5p %30.30c %x - %m\n
3.Activiti数据库表的自动创建
第一次运行这个代码时自动创建
public class TestCreate {
// 使用activiti提供的默认方法来创建数据库
@Test
public void testCreateDbTable(){
//需要使用activiti的工具类ProcessEngines,使用方法getDefaultProcessEngine,
//getDefaultProcessEngine会默认读取从resources下的activiti.cfg.xml文件中
// 在创建processEngine时,就会创建数据库的表
ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
System.out.println(engine);
}
@Test
public void test1() {
//使用下面这种方式生成表的条件
//1.activiti配置文件名称必须为activiti.cfg.xml
//2.activiti.cfg.xml中bean的id必须为"processEngineConfiguration"
ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
System.out.println(engine );
}
@Test
public void test2() {
//1.创建ProcessEngineConfiguration对象
ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml");
//2.创建ProcessEngine对象
ProcessEngine processEngine = configuration.buildProcessEngine();
System.out.println(processEngine);
}

4.Activiti各表的意义
| 表分类 | 表名 | 解释 |
| 一般数据 | ||
| [ACT_GE_BYTEARRAY] | 通用的流程定义和流程资源,例如bpmn对应的xml文件以及png文件 | |
| [ACT_GE_PROPERTY] | 系统相关属性 | |
| 流程历史记录 | ||
| [ACT_HI_ACTINST] | 历史的流程实例 | |
| [ACT_HI_ATTACHMENT] | 历史的流程附件 | |
| [ACT_HI_COMMENT] | 历史的说明性信息 | |
| [ACT_HI_DETAIL] | 历史的流程运行中的细节信息 | |
| [ACT_HI_IDENTITYLINK] | 历史的流程运行过程中用户关系 | |
| [ACT_HI_PROCINST] | 历史的流程实例 | |
| [ACT_HI_TASKINST] | 历史的任务实例 | |
| [ACT_HI_VARINST] | 历史的流程运行中的变量信息 | |
| 流程定义表 | ||
| [ACT_RE_DEPLOYMENT] | 部署单元信息,流程部署表,每部署一次都会新增一条记录 | |
| [ACT_RE_MODEL] | 模型信息 | |
| [ACT_RE_PROCDEF] | 已部署的流程定义,流程定义表, | |
| 运行实例表 | ||
| [ACT_RU_EVENT_SUBSCR] | 运行时事件 | |
| [ACT_RU_EXECUTION] | 运行时流程执行实例 | |
| [ACT_RU_IDENTITYLINK] | 运行时用户关系信息,存储任务节点与参与者的相关信息 | |
| [ACT_RU_JOB] | 运行时作业 | |
| [ACT_RU_TASK] | 运行时任务 | |
| [ACT_RU_VARIABLE] | 运行时变量表 |
5.创建流程引擎
(1)默认方法
//1.activiti配置文件名称必须为activiti.cfg.xml
//2.activiti.cfg.xml中bean的id必须为"processEngineConfiguration"
ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
System.out.println(engine );
(2)自定义方法 配置文件名称可以自定义,bean的名称也可以自定义
//1.创建ProcessEngineConfiguration对象
ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml",processEngineConfiguration);
//2.创建ProcessEngine对象
ProcessEngine processEngine = configuration.buildProcessEngine();
System.out.println(processEngine);
6.service服务接口
(1)service创建方式
HistoryService historyService = processEngine.getHistoryService();
ManagementService managementService = processEngine.getManagementService();
RepositoryService repositoryService = processEngine.getRepositoryService();
(2)service总览
| service名称 | service作用 |
| RepositoryService | activiti资源管理类 |
| HistoryService | activiti历史管理类 |
| RunTimeService | activiti流程运行管理类 |
| TaskService | activiti任务管理类 |
| ManageService | activiti引擎管理类 |
7.流程定义
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <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: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" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/processdef"> <process id="evection_1" name="evection" isExecutable="true"> <startEvent id="_2" name="StartEvent"/> <userTask activiti:assignee="zhangsan" activiti:exclusive="true" id="_3" name="创建出差申请"/> <userTask activiti:assignee="jerry" activiti:exclusive="true" id="_4" name="经理审批"/> <userTask activiti:assignee="jack" activiti:exclusive="true" id="_5" name="总经理审批"/> <userTask activiti:assignee="rose" activiti:exclusive="true" id="_6" name="财务审批"/> <endEvent id="_7" name="EndEvent"/> <sequenceFlow id="_8" sourceRef="_2" targetRef="_3"/> <sequenceFlow id="_9" sourceRef="_3" targetRef="_4"/> <sequenceFlow id="_10" sourceRef="_4" targetRef="_5"/> <sequenceFlow id="_11" sourceRef="_5" targetRef="_6"/> <sequenceFlow id="_12" sourceRef="_6" targetRef="_7"/> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_evection"> <bpmndi:BPMNPlane bpmnElement="evection_1" id="BPMNPlane_evection"> </bpmndi:BPMNPlane> < 标签:502100alf连接器