使用SpringBoot整合Activiti6工作流的操作方法
1.idea安裝actibpm流程設(shè)計(jì)器
打開(kāi)idea插件搜索actibpm,安裝成功后重啟idea

2.創(chuàng)建maven項(xiàng)目,導(dǎo)入相關(guān)依賴,添加配置文件

pom.xml依賴
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dongmen</groupId>
<artifactId>testActSpringBoot</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<activiti.version>6.0.0</activiti.version>
<mysql.version>5.1.29</mysql.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-rest-api</artifactId>
<version>${activiti.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
配置文件
#啟動(dòng)端口 server.port=81 spring.datasource.url=jdbc:mysql://localhost:3306/acttest?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true spring.datasource.username=root spring.datasource.password=123456 spring.datasource.driver-class-name=com.mysql.jdbc.Driver #1.false,默認(rèn)值,acticiti啟動(dòng)時(shí)對(duì)比數(shù)據(jù)庫(kù)表中保存的版本,如果沒(méi)有表或者版本不匹配,將拋出異常 #2.true,acticiti會(huì)對(duì)數(shù)據(jù)中所有的表進(jìn)行更新操作,如果表不存在,則自動(dòng)創(chuàng)建 #3.create_drop,在acticiti啟動(dòng)時(shí)創(chuàng)建表,關(guān)閉時(shí)刪除表(必須手動(dòng)關(guān)閉引擎才能刪除表) #4.drop_create,在acticiti啟動(dòng)時(shí)刪除原來(lái)的表,然后創(chuàng)建新表(不需要手動(dòng)關(guān)閉引擎) spring.activiti.database-schema-update=true #檢測(cè)歷史表是否存在,acticit7默認(rèn)沒(méi)有開(kāi)啟歷史記錄信息 spring.activiti.db-history-used=true #歷史記錄等級(jí) #1.none:不保存任何歷史記錄,因此在流程執(zhí)行過(guò)程中,這是最高效的 #2.acticiti:級(jí)別高于none,保存流程實(shí)例與流程行為,其他數(shù)據(jù)不保存 #3.audit:除activiti級(jí)別會(huì)保存的數(shù)據(jù)外,還會(huì)保存全部的流程任務(wù)及其屬性,audit為默認(rèn)值 #4.full:保存歷史數(shù)據(jù)的最高級(jí)別,除了保存audit級(jí)別的數(shù)據(jù)外,還會(huì)保存其他流程相關(guān)的細(xì)節(jié)數(shù)據(jù),包括一些流程參數(shù)等 spring.activiti.history-level=full #默認(rèn)true,效驗(yàn)流程文件,默認(rèn)效驗(yàn)resources下的processes文件夾里的流程,為true自動(dòng)部署流程,為false則不部署 #spring.activiti.check-process-definitions=false
3.新增啟動(dòng)類(lèi),剔除掉activiti默認(rèn)集成springsecurity
package com.dongmen;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* @author TANGSHUAI
* @version 1.0
* @date 2021-12-13 11:13
* 項(xiàng)目啟動(dòng)會(huì)自動(dòng)部署processes文件夾的bpmn文件
* 剔除springsecurity
*/
@SpringBootApplication(exclude = {
org.activiti.spring.boot.SecurityAutoConfiguration.class,
org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class})
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
4.新建文件夾processes(名稱不能更改),新增Bpmn文件,畫(huà)流程圖

這里我們用到了三種標(biāo)簽,



連接下一個(gè)標(biāo)簽的線條,需要鼠標(biāo)移動(dòng)到標(biāo)簽中間來(lái)獲取線條

畫(huà)好流程圖后點(diǎn)擊空白處,左邊會(huì)出現(xiàn)流程參數(shù),這里我們只需要設(shè)置流程的id與name即可

設(shè)置審批用戶信息,這里我第一個(gè)節(jié)點(diǎn)設(shè)置的時(shí)zhangsan,第二個(gè)節(jié)點(diǎn)設(shè)置的是lisi,設(shè)置成功后保存

左側(cè)菜單介紹

5.創(chuàng)建Controller
package com.dongmen.controller;
import org.activiti.engine.HistoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @author TANGSHUAI
* @version 1.0
* @date 2021-12-13 13:21
*/
@RestController
public class TestController {
@Autowired
private RuntimeService runtimeService;
@Autowired
private TaskService taskService;
@Autowired
private HistoryService historyService;
//啟動(dòng)流程
@RequestMapping("/startAct")
public void startAct() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("myProcess_1");
System.out.println(processInstance.getId());
}
//查詢代辦任務(wù)
@RequestMapping("taskAgents")
public void taskAgents(){
String user="zhangsan";
List<Task> list = taskService.createTaskQuery().taskAssignee(user).list();
for (Task task : list) {
System.out.println("任務(wù)id:"+task.getId());
System.out.println("當(dāng)前審批用戶:"+task.getAssignee());
System.out.println("任務(wù)名稱:"+task.getName());
}
}
//審批流程
@RequestMapping("/approvalProcess")
public void approvalProcess() {
String key = "myProcess_1";
String user="zhangsan";
//流程實(shí)例id,有多個(gè)流程時(shí)傳遞,單個(gè)不需要傳,act_ru_task表id
String id="2505";
//根據(jù)流程key,與用戶名稱查詢審批
Task task = taskService.createTaskQuery()
.processDefinitionKey(key)
.taskAssignee(user)
.taskId(id)
.singleResult();
if(task!=null){
//審批流程
taskService.complete(task.getId());
System.out.println("審批成功!");
}
}
//查詢已辦任務(wù)
@RequestMapping("/hasToDoTasks")
public void hasToDoTasks(){
String user="zhangsan";
List<HistoricTaskInstance> list = historyService.createHistoricTaskInstanceQuery().taskAssignee(user).list();
for (HistoricTaskInstance historicTaskInstance : list) {
System.out.println("開(kāi)始時(shí)間"+historicTaskInstance.getStartTime()+",結(jié)束時(shí)間:"+historicTaskInstance.getEndTime());
System.out.println("流程名稱"+historicTaskInstance.getName());
}
}
}
6.啟動(dòng)項(xiàng)目,Activiti會(huì)自動(dòng)創(chuàng)建28張表,自動(dòng)部署processes目錄Bpnm文件
表結(jié)構(gòu)介紹

7.測(cè)試Controller
localhost:81/startAct–啟動(dòng)流程,查看數(shù)據(jù)表act_ru_task

localhost:81/taskAgents–查詢待辦任務(wù),訪問(wèn)后查看后臺(tái)打印

localhost:81/approvalProcess–審批流程,點(diǎn)擊審批流程后變成第二個(gè)節(jié)點(diǎn)審批

localhost:81/hasToDoTasks–查詢已辦任務(wù),

到此這篇關(guān)于使用SpringBoot整合Activiti6(工作流)的文章就介紹到這了,更多相關(guān)SpringBoot整合Activiti6內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
前端如何調(diào)用后端接口進(jìn)行數(shù)據(jù)交互詳解(axios和SpringBoot)
一般來(lái)講前端不會(huì)給后端接口,而是后端給前端接口的情況比較普遍,下面這篇文章主要給大家介紹了關(guān)于前端如何調(diào)用后端接口進(jìn)行數(shù)據(jù)交互的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-03-03
JAVA實(shí)現(xiàn)經(jīng)典掃雷游戲的示例代碼
windows自帶的游戲《掃雷》是陪伴了無(wú)數(shù)人的經(jīng)典游戲,本程序參考《掃雷》的規(guī)則進(jìn)行了簡(jiǎn)化,用java語(yǔ)言實(shí)現(xiàn),采用了swing技術(shù)進(jìn)行了界面化處理。感興趣的可以學(xué)習(xí)一下2022-01-01
Maven將Jar包打入本地倉(cāng)庫(kù)的實(shí)現(xiàn)
項(xiàng)目需要用到一個(gè)Jar包,不能從遠(yuǎn)程倉(cāng)庫(kù)拉取,只有一個(gè)Jar包,所以需要將Jar包打入到本地倉(cāng)庫(kù)才能引入項(xiàng)目,本文主要介紹了Maven將Jar包打入本地倉(cāng)庫(kù)的實(shí)現(xiàn),感興趣的可以了解一下2023-12-12
Java 實(shí)戰(zhàn)項(xiàng)目錘煉之嘟嘟健身房管理系統(tǒng)的實(shí)現(xiàn)流程
讀萬(wàn)卷書(shū)不如行萬(wàn)里路,只學(xué)書(shū)上的理論是遠(yuǎn)遠(yuǎn)不夠的,只有在實(shí)戰(zhàn)中才能獲得能力的提升,本篇文章手把手帶你用java+SSM+jsp+mysql+maven實(shí)現(xiàn)一個(gè)健身房管理系統(tǒng),大家可以在過(guò)程中查缺補(bǔ)漏,提升水平2021-11-11
深入聊一聊springboot項(xiàng)目全局異常處理那些事兒
最近在做項(xiàng)目時(shí)需要對(duì)異常進(jìn)行全局統(tǒng)一處理,所以下面這篇文章主要給大家介紹了關(guān)于springboot項(xiàng)目全局異常處理那些事兒,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-01-01
Spring Cloud基于zuul實(shí)現(xiàn)網(wǎng)關(guān)過(guò)程解析
這篇文章主要介紹了Spring Cloud基于zuul實(shí)現(xiàn)網(wǎng)關(guān)過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-12-12
java 將數(shù)據(jù)加載到內(nèi)存中的操作
這篇文章主要介紹了java 將數(shù)據(jù)加載到內(nèi)存中的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-09-09

