当前位置:网站首页>Activiti常见操作数据表关系
Activiti常见操作数据表关系
2022-07-04 07:33:00 【MrJson-架构师】
1.流程定义部署后操作activiti的3张表如下:
act_re_deployment 流程定义部署表,每部署一次增加一条记录
act_re_procdef 流程定义表,部署每个新的流程定义都会在这张表中增加一条记录
act_ge_bytearray 流程资源表
注意:
act_re_deployment和act_re_procdef一对多关系,一次部署在流程部署表生成一条记录,但一次部署可以部署多个流程定义,每个流程定义在流程定义表生成一条记录。每一个流程定义在act_ge_bytearray会存在两个资源记录,bpmn和png。
建议:一次部署一个流程,这样部署表和流程定义表是一对一有关系,方便读取流程部署及流程定义信息。
2.启动流程实例操作数据表
act_hi_actinst 流程实例执行历史
act_hi_actinst与act_hi_identitylink通过PROC_INST_ID关联
act_hi_identitylink 流程的参与用户历史信息
act_hi_procinst 流程实例历史信息,业务ID到这里BUSINESS_KEY_
注意PROC_INST_ID_和PROC_DEF_ID_字段
act_hi_taskinst 流程任务历史信息
act_ru_execution 流程执行信息,业务ID到这里BUSINESS_KEY_
act_ru_identitylink 流程的参与用户信息
act_ru_task 任务信息
3.启动流程实例并添加Businesskey(业务标识)
流程定义部署在activiti后,就可以在系统中通过activiti去管理该流程的执行,执行流程表示流程的一次执行。
比如部署系统出差流程后,如果某用户要申请出差这时就需要执行这个流程,如果另外一个用户也要申请出差则也需要执行该流程,每个执行互不影响,每个执行是单独的流程实例。
启动流程实例时,指定的businesskey,就会在act_ru_execution #流程实例的执行表中存储businesskey。
Businesskey:业务标识,通常为业务表的主键,业务标识和流程实例一一对应。业务标识来源于业务系统。存储业务标识就是根据业务标识来关联查询业务系统的数据。
比如:出差流程启动一个流程实例,就可以将出差单的id作为业务标识存储到activiti中,将来查询activiti的流程实例信息就可以获取出差单的id从而关联查询业务系统数据库得到出差单信息。
/** * 启动流程实例,添加businessKey */
@Test
public void addBusinessKey(){
// 1、得到ProcessEngine
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
// 2、得到RunTimeService
RuntimeService runtimeService = processEngine.getRuntimeService();
// 3、启动流程实例,同时还要指定业务标识businessKey,也就是出差申请单id,这里是1001
ProcessInstance processInstance = runtimeService.
startProcessInstanceByKey("myEvection","1001");
// 4、输出processInstance相关属性
System.out.println("业务id=="+processInstance.getBusinessKey());
}
Activiti的act_ru_execution中存储业务标识:
操作数据库表
启动流程实例,操作如下数据库表:
SELECT * FROM act_ru_execution #流程实例执行表,记录当前流程实例的执行情况
说明:
流程实例执行,如果当前只有一个分支时,一个流程实例只有一条记录且执行表的主键id和流程实例id相同,如果当前有多个分支正在运行则该执行表中有多条记录,存在执行表的主键和流程实例id不相同的记录。不论当前有几个分支总会有一条记录的执行表的主键和流程实例id相同
一个流程实例运行完成,此表中与流程实例相关的记录删除。
SELECT * FROM act_ru_task #任务执行表,记录当前执行的任务
说明:启动流程实例,流程当前执行到第一个任务结点,此表会插入一条记录表示当前任务的执行情况,如果任务完成则记录删除。
SELECT * FROM act_ru_identitylink #任务参与者,记录当前参与任务的用户或组
SELECT * FROM act_hi_procinst #流程实例历史表
流程实例启动,会在此表插入一条记录,流程实例运行完成记录也不会删除。
SELECT * FROM act_hi_taskinst #任务历史表,记录所有任务
开始一个任务,不仅在act_ru_task表插入记录,也会在历史任务表插入一条记录,任务历史表的主键就是任务id,任务完成此表记录不删除。
SELECT * FROM act_hi_actinst #活动历史表,记录所有活动
活动包括任务,所以此表中不仅记录了任务,还记录了流程执行过程的其它活动,比如开始事件、结束事件。
获取流程businessKey(业务标识 )
String businessKey = processInstance.getBusinessKey();
在activiti的act_ru_execution表,字段BUSINESS_KEY就是存放业务KEY的。
4.流程删除
public void deleteDeployment() {
// 流程部署id
String deploymentId = "1";
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
// 通过流程引擎获取repositoryService
RepositoryService repositoryService = processEngine
.getRepositoryService();
//删除流程定义,如果该流程定义已有流程实例启动则删除时出错
repositoryService.deleteDeployment(deploymentId);
//设置true 级联删除流程定义,即使该流程有流程实例启动也可以删除,设置为false非级别删除方式,如果流程
//repositoryService.deleteDeployment(deploymentId, true);
}
说明:
使用repositoryService删除流程定义,历史表信息不会被删除
如果该流程定义下没有正在运行的流程,则可以用普通删除。
如果该流程定义下存在已经运行的流程,使用普通删除报错,可用级联删除方法将流程及相关记录全部删除。
先删除没有完成流程节点,最后就可以完全删除流程定义信息
项目开发中级联删除操作一般只开放给超级管理员使用.
5.流程资源下载
现在我们的流程资源文件已经上传到数据库了,如果其他用户想要查看这些资源文件,可以从数据库中把资源文件下载到本地。
解决方案有:
1、jdbc对blob类型,clob类型数据读取出来,保存到文件目录
2、使用activiti的api来实现
使用commons-io.jar 解决IO的操作
引入commons-io依赖包
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
通过流程定义对象获取流程定义资源,获取bpmn和png
import org.apache.commons.io.IOUtils;
@Test
public void deleteDeployment(){
// 获取引擎
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
// 获取repositoryService
RepositoryService repositoryService = processEngine.getRepositoryService();
// 根据部署id 删除部署信息,如果想要级联删除,可以添加第二个参数,true
repositoryService.deleteDeployment("1");
}
public void queryBpmnFile() throws IOException {
// 1、得到引擎
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
// 2、获取repositoryService
RepositoryService repositoryService = processEngine.getRepositoryService();
// 3、得到查询器:ProcessDefinitionQuery,设置查询条件,得到想要的流程定义
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
.processDefinitionKey("myEvection")
.singleResult();
// 4、通过流程定义信息,得到部署ID
String deploymentId = processDefinition.getDeploymentId();
// 5、通过repositoryService的方法,实现读取图片信息和bpmn信息
// png图片的流
InputStream pngInput = repositoryService.getResourceAsStream(deploymentId, processDefinition.getDiagramResourceName());
// bpmn文件的流
InputStream bpmnInput = repositoryService.getResourceAsStream(deploymentId, processDefinition.getResourceName());
// 6、构造OutputStream流
File file_png = new File("d:/evectionflow01.png");
File file_bpmn = new File("d:/evectionflow01.bpmn");
FileOutputStream bpmnOut = new FileOutputStream(file_bpmn);
FileOutputStream pngOut = new FileOutputStream(file_png);
// 7、输入流,输出流的转换
IOUtils.copy(pngInput,pngOut);
IOUtils.copy(bpmnInput,bpmnOut);
// 8、关闭流
pngOut.close();
bpmnOut.close();
pngInput.close();
bpmnInput.close();
}
说明:
deploymentId为流程部署ID
resource_name为act_ge_bytearray表中NAME_列的值
使用repositoryService的getDeploymentResourceNames方法可以获取指定部署下得所有文件的名称
使用repositoryService的getResourceAsStream方法传入部署ID和资源图片名称可以获取部署下指定名称文件的输入流
最后的将输入流中的图片资源进行输出。
边栏推荐
- Xcode 14之大变化详细介绍
- 论文学习——基于极值点特征的时间序列相似性查询方法
- 【森城市】GIS数据漫谈(一)
- 在所有SwiftUI版本(1.0-4.0)中原生实现Charts图表视图之思路
- jdbc连接es查询的时候,有遇到下面这种情况的大神嘛?
- Cell reports: Wei Fuwen group of the Institute of zoology, Chinese Academy of Sciences analyzes the function of seasonal changes in the intestinal flora of giant pandas
- User login function: simple but difficult
- Vulhub vulnerability recurrence 77_ zabbix
- L1-024 the day after tomorrow (5 points)
- 电脑通过Putty远程连接树莓派
猜你喜欢
Splicing plain text into JSON strings - easy language method
Pangu open source: multi support and promotion, the wave of chip industry
Zephyr learning notes 1, threads
Computer connects raspberry pie remotely through putty
博客停更声明
User login function: simple but difficult
大学阶段总结
Rhcsa the next day
The idea of implementing charts chart view in all swiftui versions (1.0-4.0) was born
The cloud native programming challenge ended, and Alibaba cloud launched the first white paper on application liveliness technology in the field of cloud native
随机推荐
L1-021 important words three times (5 points)
L1-027 rental (20 points)
University stage summary
L1-028 judging prime number (10 points)
Zephyr 学习笔记1,threads
Zabbix agent主动模式的实现
Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
[untitled] notice on holding "2022 traditional fermented food and modern brewing technology"
Rapidjson reading and writing JSON files
Electronic Association C language level 1 34, piecewise function
Zephyr study notes 2, scheduling
【Kubernetes系列】Kubernetes 上安装 KubeSphere
手写简易版flexible.js以及源码分析
提升复杂场景三维重建精度 | 基于PaddleSeg分割无人机遥感影像
JVM中堆概念
Introduction to sap commerce cloud B2B organization function
Four sets of APIs for queues
Directory of tornado
rapidjson读写json文件
【森城市】GIS数据漫谈(一)