当前位置:网站首页>Flowable workflow
Flowable workflow
2022-06-12 00:58:00 【Mengzhu】
1 Quick start case
1.1 maven rely on
<dependencies>
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-engine</artifactId>
<version>6.6.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.20</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.22</version>
</dependency>
</dependencies>
1.2 Basic operation
1.2.1 Coding preparation
Here is an example of the official website leave process 
- We assume that the process starts by providing some information , For example, employee name 、 Number and description of vacation requested . Of course , This can be modeled as a separate first step in the process . however , By taking it as the “ input data ”, Process instances are actually created only when an actual request is made . In another case , Users can change their minds and cancel before submitting , But the process instance is now there . In some cases , This may be valuable information ( for example , The number of times a request to start has not been completed ), It depends on the business objectives .
- The circle on the left is called the start event . It is the starting point for process instances .
- The first rectangle is the user task . This is a step in the process that human users must perform . under these circumstances , The manager needs to approve or reject the request .
- According to the manager's decision , Dedicated gateway ( A diamond with a cross ) The process instance is routed to the approve or reject path .
- If approved , We must register the request in some external system , Then perform the user task for the original employee again , Inform them of the decision . Of course , This can be replaced by email .
- If rejected , Will send an email to the employee , Tell them this .
resources Under the table of contents Create a new one holiday-request.bpmn20.xml file
<?xml version="1.0" encoding="UTF-8"?>
<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: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" xmlns:flowable="http://flowable.org/bpmn" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.flowable.org/processdef">
<process id="holidayRequest" name="Holiday Request" isExecutable="true">
<startEvent id="startEvent"/>
<sequenceFlow sourceRef="startEvent" targetRef="approveTask"/>
<userTask id="approveTask" name="Approve or reject request"/>
<sequenceFlow sourceRef="approveTask" targetRef="decision"/>
<exclusiveGateway id="decision"/>
<sequenceFlow sourceRef="decision" targetRef="externalSystemCall">
<conditionExpression xsi:type="tFormalExpression">
<![CDATA[ ${approved} ]]>
</conditionExpression>
</sequenceFlow>
<sequenceFlow sourceRef="decision" targetRef="sendRejectionMail">
<conditionExpression xsi:type="tFormalExpression">
<![CDATA[ ${!approved} ]]>
</conditionExpression>
</sequenceFlow>
<serviceTask id="externalSystemCall" name="Enter holidays in external system" flowable:class="org.flowable.CallExternalSystemDelegate"/>
<sequenceFlow sourceRef="externalSystemCall" targetRef="holidayApprovedTask"/>
<userTask id="holidayApprovedTask" name="Holiday approved"/>
<sequenceFlow sourceRef="holidayApprovedTask" targetRef="approveEnd"/>
<serviceTask id="sendRejectionMail" name="Send out rejection email" flowable:class="org.flowable.SendRejectionMail"/>
<sequenceFlow sourceRef="sendRejectionMail" targetRef="rejectEnd"/>
<endEvent id="approveEnd"/>
<endEvent id="rejectEnd"/>
</process>
</definitions>
1.2.2 initialization DB
@Before
public void init() {
ProcessEngineConfiguration configuration = new StandaloneInMemProcessEngineConfiguration();
configuration.setJdbcDriver("com.mysql.cj.jdbc.Driver");
configuration.setJdbcUsername("root");
configuration.setJdbcPassword("hwl123456");
configuration.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/flowable?allowMultiQueries=true&useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&nullCatalogMeansCurrent=true");
configuration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
engine = configuration.buildProcessEngine();
}
After running the script, the related tables will be initialized , A little bit later 
1.2.3 Deployment process
@Test
public void testDeploy() {
RepositoryService repositoryService = engine.getRepositoryService();
// Deployment process , After deployment, the act_re_deployment and act_ge_bytearray Add records to the table
Deployment deployment = repositoryService.createDeployment()
.addClasspathResource("holiday-request.bpmn20.xml")
// Specify the process name
.name(" Leave process ")
.deploy();
System.out.println(JSONUtil.toJsonPrettyStr(deployment));
}
see act_re_deployment surface 
see act_ge_bytearray, Record xml Text byte array , adopt deployment_id relation ,
1.2.4 Query process
@Test
public void testQuery() {
RepositoryService repositoryService = engine.getRepositoryService();
Deployment deployment = repositoryService.createDeploymentQuery()
.deploymentId("1")
.singleResult();
System.out.println(deployment.getName());
}
Check out the relevant api There are list queries 、 Paging query, etc
1.2.3 Delete process
@Test
public void testDelete() {
// If the deployed process has been started, it cannot be deleted
engine.getRepositoryService().deleteDeployment("1");
// If the process has been started, the related tasks will be deleted
engine.getRepositoryService().deleteDeployment("1", true);
}
1.2.4 Initiate process
modify holiday-request.bpmn20 file , Add an approver 
@Test
public void testStart() {
RuntimeService runtimeService = engine.getRuntimeService();
Map<String, Object> param = new HashMap<>(8);
param.put("employee", " Zhang San ");
param.put("days", 3);
param.put("description", " Ask for leave to go home ");
// Start process instance
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("holidayRequest", param);
// After starting act_ru_variable Record parameter information in the table
System.out.println(processInstance.getName());
}
Process instance table after process initiation act_hi_procinst
Process task list act_ru_task, adopt proc_inst_id Associated with process instances 
Process execution process act_ru_execution, adopt proc_inst_id Associated with process instances 
Submit the parameter table act_ru_variable, adopt proc_inst_id Associated with process instances , adopt execution_id Associated with the execution process 
1.2.5 Query process tasks
@Test
public void testQueryTask() {
TaskService taskService = engine.getTaskService();
List<Task> list = taskService.createTaskQuery()
// Specify the process type
.processDefinitionKey("holidayRequest")
// Designated handler , Usually used to query my to-do list
.taskAssignee("zhangsan")
.list();
System.out.println(JSONUtil.toJsonPrettyStr(list));
}
1.2.6 Perform tasks
according to xml File configuration reject process send mail class 
@Test
public void testHandleTask() {
TaskService taskService = engine.getTaskService();
Map<String, Object> param = new HashMap<>();
param.put("approved", false);
// To complete the task
taskService.complete("2509", param);
}
After execution, you will see that the console outputs a reject message
View the process instance table act_hi_procinst
There are process durations 、 Start node 、 The end node
View the process task table act_ru_task 、 Process execution process act_ru_execution And submit the parameter table act_ru_variable Has been emptied
1.2.7 View historical information
After the process is approved , The relevant intermediate data has been cleaned up . If you want to view the process submission record, you need to view the historical information
@Test
public void testGetHistory() {
HistoryService historyService = engine.getHistoryService();
List<HistoricActivityInstance> list = historyService.createHistoricActivityInstanceQuery().processDefinitionId("holidayRequest:1:3")
// Closed process
.finished()
// Sort by end time in reverse order
.orderByHistoricActivityInstanceEndTime().desc()
.list();
for (HistoricActivityInstance instance: list) {
System.out.println(JSONUtil.toJsonStr(instance));
}
}
Historical execution record table act_hi_actinst
History form parameter table act_hi_varinst
边栏推荐
- Anfulai embedded weekly report (issue 254): February 21, 2022 to February 27, 2022
- 一、Flutter 入门学习写一简单客户端
- C language string and pointer - learning 25
- LabVIEW Arduino electronic weighing system (project Part-1)
- Zhangxiaobai takes you to install MySQL 5.7 on Huawei cloud ECS server
- Win jar package setting boot auto start
- Intel trimbert: tailor Bert for trade-offs
- Lambda中间操作limit
- Global and Chinese nonene market operation research and future prospect forecast report 2022 ~ 2028
- Exploration of qunar risk control safety products
猜你喜欢

Intel trimbert: tailor Bert for trade-offs

What are the advantages of Tiktok applet

One article to show you how to understand the harmonyos application on the shelves

The latest report of Xinsi technology shows that 97% of applications have vulnerabilities

Detailed explanation of merge sorting

Flutter uses local pictures

Online Fox game server - room configuration wizard - component attribute and basic configuration assignment

Go out with a stream
![Is interface automation difficult? Take you from 0 to 1 to get started with interface automation test [0 basic can also understand series]](/img/78/f36cdc53b94dc7da576d114a3eb2a6.png)
Is interface automation difficult? Take you from 0 to 1 to get started with interface automation test [0 basic can also understand series]
![2022-06-11:注意本文件中,graph不是邻接矩阵的含义,而是一个二部图。 在长度为N的邻接矩阵matrix中,所有的点有N个,matrix[i][j]表示点i到点j的距离或者权重, 而在二部](/img/ab/b3044472561ac366f2cbd878268132.png)
2022-06-11:注意本文件中,graph不是邻接矩阵的含义,而是一个二部图。 在长度为N的邻接矩阵matrix中,所有的点有N个,matrix[i][j]表示点i到点j的距离或者权重, 而在二部
随机推荐
ROS2之OpenCV基础代码对比foxy~galactic~humble
leetcodeSQL:614. Secondary followers
What are the advantages of Tiktok applet
What is bonded warehouse and what is the difference between them
The long polling processing mechanism of the service end of the # yyds dry goods inventory # Nacos configuration center
Lambda中间操作map
C language bit operation - learning 26
How to optimize plantuml flow diagram (sequence diagram)
How to guarantee industrial control safety: system reinforcement
Xiaomu's interesting PWN
Invalid spacing setting before WPS Title segment solution
Zhangxiaobai takes you to install MySQL 5.7 on Huawei cloud ECS server
The latest report of Xinsi technology shows that 97% of applications have vulnerabilities
Win jar package setting boot auto start
be based on. NETCORE development blog project starblog - (11) access statistics
Is interface automation difficult? Take you from 0 to 1 to get started with interface automation test [0 basic can also understand series]
Bgfx multithreaded rendering
How to strengthen the prevention and control of major safety risks for chemical and dangerous goods enterprises in flood season
KV storage separation principle and performance evaluation of nebula graph
模块八-设计消息队列存储消息数据的 MySQL 表格