98 lines
3.2 KiB
Markdown
98 lines
3.2 KiB
Markdown
---
|
||
title: 6.流程引擎
|
||
description: activiti流程引擎模块的使用
|
||
published: true
|
||
date: 2022-04-23T07:02:24.961Z
|
||
tags: wg-basic, activiti
|
||
editor: markdown
|
||
dateCreated: 2021-09-01T09:28:31.684Z
|
||
---
|
||
|
||
# 说明
|
||
|
||
流程引擎模块引入了 **activiti** 框架,目前可以完成流程的绘制、部署与流程图的查看。模块自带流程绘制功能,无需再使用插件绘制流程文件。
|
||
|
||
该模块需要手动添加管理菜案
|
||
|
||
> 绘制 OA 流程时,动态表单需要先设计,并且表单类型为 **OA**。
|
||
> 非 OA 流程正常绘制流程图即可。
|
||
{.is-info}
|
||
|
||
|
||
# 更新
|
||
|
||
- 20220423:增加了OA流程管理,结合动态表单与流程绘制中的OA节点管理可完成无代码OA表单流转。
|
||
|
||
# 依赖
|
||
```xml
|
||
<dependency>
|
||
<groupId>ink.wgink</groupId>
|
||
<artifactId>module-activiti</artifactId>
|
||
<version>1.0-SNAPSHOT</version>
|
||
</dependency>
|
||
```
|
||
|
||
# 配置说明
|
||
|
||
```yaml
|
||
spring:
|
||
# 流程引擎
|
||
activiti:
|
||
# flase: 默认值。activiti在启动时,会对比数据库表中保存的版本,如果没有表或者版本不匹配,将抛出异常。
|
||
# true: activiti会对数据库中所有表进行更新操作。如果表不存在,则自动创建。
|
||
# create_drop: 在activiti启动时创建表,在关闭时删除表(必须手动关闭引擎,才能删除表)。
|
||
# drop-create: 在activiti启动时删除原来的旧表,然后在创建新表(不需要手动关闭引擎)
|
||
database-schema-update: true
|
||
#检测历史表是否存在
|
||
db-history-used: true
|
||
# 记录历史等级 可配置的历史级别有none, acitivity, audit, all
|
||
history-level: full
|
||
# 检查流程定义
|
||
check-process-definitions: false
|
||
rest-api-enabled: true
|
||
rest-api-servlet-name: activiti-swagger-document
|
||
SpringProcessEngineConfiguration:
|
||
activityFontName: 宋体
|
||
labelFontName: 宋体
|
||
dataSource: datasource
|
||
```
|
||
|
||
注意:`spring.datasource.druid.url` 配置中需要追加 **nullCatalogMeansCurrent=true** 参数用于防止项目启动自动建表失败的
|
||
|
||
# 启动类
|
||
|
||
启动类需要增加配置
|
||
`@SpringBootApplication` 注解增加 `exclude=SecurityAutoConfiguration.class`
|
||
|
||
```
|
||
@SpringBootApplication(exclude = SecurityAutoConfiguration.class)
|
||
```
|
||
|
||
# 添加菜单
|
||
|
||
流程模型:`/route/activiti/list`
|
||
流程定义:`/route/activiti/procdef/list`
|
||
发起流程:`/route/oa/list-procdef`
|
||
我的待办:`/route/oa/list-task-of-mine`
|
||
我的已办:`/route/oa/list-history-task-of-mine`
|
||
|
||
表单管理:`/route/form/list`
|
||
|
||
|
||
# 如何启动流程
|
||
|
||
1. 在流程管理菜单下将流程绘制好并部署后,会生成 **部署ID(deploymentId)**
|
||
2. 使用如下代码启动流程
|
||
|
||
```java
|
||
// 获取流程定义
|
||
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
|
||
// 获取流程定义ID
|
||
String processDefinitionId = processDefinition.getId();
|
||
// 流程变量(如果需要)
|
||
Map<String, Object> variableMap = new HashMap<>();
|
||
// 业务ID(如果需要)
|
||
String businessId = "businessId";
|
||
// 启动流程
|
||
ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinitionId, "businessId", variableMap);
|
||
``` |