当前位置:网站首页>Activiti常見操作數據錶關系
Activiti常見操作數據錶關系
2022-07-04 07:34: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為流程部署IDresource_name為act_ge_bytearray錶中NAME_列的值使用repositoryService的getDeploymentResourceNames方法可以獲取指定部署下得所有文件的名稱使用repositoryService的getResourceAsStream方法傳入部署ID和資源圖片名稱可以獲取部署下指定名稱文件的輸入流
最後的將輸入流中的圖片資源進行輸出。
边栏推荐
- 论文学习——基于极值点特征的时间序列相似性查询方法
- Splicing plain text into JSON strings - easy language method
- tornado项目之路由装饰器
- Improve the accuracy of 3D reconstruction of complex scenes | segmentation of UAV Remote Sensing Images Based on paddleseg
- OKR vs. KPI 一次搞清楚这两大概念!
- 大学阶段总结
- Computer connects raspberry pie remotely through putty
- 【Kubernetes系列】Kubernetes 上安装 KubeSphere
- Project 1 household accounting software (goal + demand description + code explanation + basic fund and revenue and expenditure details record + realization of keyboard access)
- 时序数据库 InfluxDB 2.2 初探
猜你喜欢

时序数据库 InfluxDB 2.2 初探

The crackdown on Huawei prompted made in China to join forces to fight back, and another enterprise announced to invest 100 billion in R & D

window上用.bat文件启动项目

Zephyr Learning note 2, Scheduling

Pangu open source: multi support and promotion, the wave of chip industry

Unity opens the explorer from the inspector interface, selects and records the file path

BUUCTF(4)

Guoguo took you to write a linked list, and the primary school students said it was good after reading it

Oceanbase is the leader in the magic quadrant of China's database in 2021

The cloud native programming challenge ended, and Alibaba cloud launched the first white paper on application liveliness technology in the field of cloud native
随机推荐
Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
It's healthy to drink medicinal wine like this. Are you drinking it right
User login function: simple but difficult
Splicing plain text into JSON strings - easy language method
Types of references in BibTex
University stage summary
Zephyr Learning note 2, Scheduling
Xcode 14之大变化详细介绍
提升复杂场景三维重建精度 | 基于PaddleSeg分割无人机遥感影像
如何用MOS管来实现电源防反接电路
Finishing (III) - Exercise 2
[Flink] temporal semantics and watermark
socket inet_ pton() inet_ Ntop() function (a new network address translation function, which converts the expression format and numerical format to each other. The old ones are inet_aton(), INET_ ntoa
Would you like to go? Go! Don't hesitate if you like it
Distributed transaction management DTM: the little helper behind "buy buy buy"
SQL foundation 9 [grouping data]
Node connection MySQL access denied for user 'root' @ 'localhost' (using password: yes
Pangu open source: multi support and promotion, the wave of chip industry
在所有SwiftUI版本(1.0-4.0)中原生实现Charts图表视图之思路
电脑通过Putty远程连接树莓派