当前位置:网站首页>Activity workflow engine
Activity workflow engine
2022-07-01 11:16:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
workflow activity Engine introduction case
1、 What is workflow ? In short, workflow is to put a piece of information according to roles 、 Division of labor 、 The conditions are different, and the upward transmission is fixed , Data is transmitted in a fixed direction , Pass it on level by level , This kind of scene is OA , CRM / ERP There are many applications in . Usually, this operation itself can also be realized through logic , But the complexity is very high . And it's not easy to maintain . Therefore, the third-party engine framework is usually used to realize , Out of the engine itself simplifies the operation . More importantly, it is easy to maintain .
2、activity Workflow engine activity It is a relatively simple and easy workflow , The main operations are divided into the following steps
- utilize activity The plug-in draws the required logic flow chart
- Deployment process
- Start process
- Iterative processing flow
- End of the process
3、activity Environment building 1、 Create a new one maven project
2、 Import maven rely on
<dependencies>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>${jetty.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-management</artifactId>
<version>${jetty.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-engine</artifactId>
<version>5.21.0</version>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring</artifactId>
<version>5.21.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.3</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
</dependencies> 3、 Install the drawing plug-in , This operation is relatively simple , Baidu can receive , Offline installation is recommended A little ........... 4、activity It is a complete system , Various operations and database tables are provided by the framework itself , So the first step is to import ativity Table structure required stay resources Under the new activiti.cfg.xml file :
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">
<property name="databaseSchemaUpdate" value="true"/>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activiti"/>
<property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
<property name="jdbcUsername" value="root" />
<property name="jdbcPassword" value="root" />
</bean>
</beans>Create a new one java class 【CreateTable.java】
package com.test.activity.TestActi;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
public class CreateTable {
public static void main(String args[]){
ProcessEngine processEngine = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml")
.buildProcessEngine();
System.out.println("processEngine="+processEngine);
}
}Then the run will appear in the database as follows :
With the drawing plug-in and the table structure of the database , Even if the basic environment is built .
4、 Introduction case writing First step : Draw flow chart . Flow chart is the core operation , The later data trend will be transferred according to the flow chart . Take the reimbursement form as an example :
Pay attention when drawing , Load several modules in advance
properties Can pass window—showview Load it out , On the right is the drawing control , We all need 4 Nodes StartEvent : Start events
Select the icon and drag it to the left blank
Then click the arrow icon on the right , It means adding a new user task [UserTask],
Similarly, add manager approval in turn 、 Financial approval 、 End the event
Then modify the attributes of each module (properties):
Then save the flowchart , The drawing is complete . Be careful , The arrow path is the data flow . Here's the picture :
* Note here :* If there is no picture generated after saving , You need to start a configuration , Then save again
5、 Write code , Release 、 start-up 、 Query task 、 Processing tasks
/**
* Deployment process
*/
private static ProcessEngine processEngine =ProcessEngines.getDefaultProcessEngine();
public void delployFlow(){
Deployment deployment = processEngine.getRepositoryService()
.createDeployment()
.name(" Reimbursement process ") // Process name
.addClasspathResource("baoxiao.bpmn")
.addClasspathResource("baoxiao.png")
.deploy();
// Exist in the database act_re_procdef Of DEPLOYMENT_ID_
System.out.println(deployment.getId());
System.out.println(deployment.getName());
}It's easy to run , Build your own main Method: just run OK, give the result as follows :
View the database after deployment
Pay attention to key value : The next step is to use it 【 This is because demo, So we don't query the database , Direct value operation to view the effect 】
Start process code :
// Start process
public void flowStart(){
RuntimeService runtimeService = processEngine.getRuntimeService();
// use key When starting, start according to the latest version of the flowchart [ Database table =act_re_procdef In the process definition table KEY_ Field ]
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(" Employee reimbursement documents ");
}Check the database after running the code act_ru_task surface The position of the red box indicates the node information
We're looking for employe The task of :
public void findEmployeeTask(){
// Database relationships 》》》》ID【act_re_deployment】 == ID【act_ru_execution】 == ID【act_ru_task】 ==》【ASSIGNEE_(cwh)】
String assignee = "employee"; // Node assignee_
List<Task> taskList= processEngine.getTaskService()// Access to task service
.createTaskQuery()// Create query object
.taskAssignee(assignee)// Specify the inquirer
.list();
if(taskList.size()>0){
for (Task task : taskList){
System.out.println(" To act as an agent ID:"+task.getId());
System.out.println(" To act as an agent name:"+task.getName());
System.out.println(" Creation time of the delegated task :"+task.getCreateTime());
System.out.println(" Agent task handler :"+task.getAssignee());
System.out.println(" Process instance ID:"+task.getProcessInstanceId());
System.out.println(" Perform object ID:"+task.getExecutionId());
}
}
}We found out employee The next one is 5004 Your task is waiting to be processed , We deal directly with
/**
* Processing flow
*
* @Description:
*/
public void completeTask(){
// ID【act_ru_task】
String taskId = "5004";
processEngine.getTaskService().complete(taskId);// To complete the task
System.out.println(" To complete the task , Mission ID"+taskId);
}Then check the database effect
Obviously , Process from employee Transferred to manager below , Of course, this process will be clearer if you analyze it yourself ,,
The process only needs to see ru Related tables , This is the task information table being processed . Do not participate in recording data before processing ,
The rest is Repeat the operation .. 1、 Get the agent process of the manager – Processing flow 2、 Get the agency process of finance – Processing flow – End of the process
This is just a very simple initial demo, But we can basically figure it out activity Operation process and execution logic . And will probably apply to those scene . As for the follow-up , You can view documents or other materials to learn according to your needs .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/131683.html Link to the original text :https://javaforall.cn
边栏推荐
- Tianrunyun, invested by Tian Suning, was listed: its market value was 2.2 billion Hong Kong, and its first year profit decreased by 75%
- Mysql的四个隔离级别是如何实现的 (简要)
- applyMiddleware 原理
- 技术分享 | Linkis参数介绍
- IPlImage的width和widthStep
- Internal control of fund managers
- BAIC bluevale: performance under pressure, extremely difficult period
- Huawei equipment is configured with large network WLAN basic services
- 编译调试Net6源码
- Whether lending a bank card to others constitutes a crime
猜你喜欢

为什么一定要从DevOps走向BizDevOps?

Why must we move from Devops to bizdevops?

Applymiddleware principle

LeetCode.515. 在每个树行中找最大值___逐一BFS+DFS+按层BFS

TEMPEST HDMI泄漏接收 5

Network security learning notes 01 network security foundation

Value 1000 graduation project campus information publishing platform website source code

华为设备配置大型网络WLAN基本业务

Wonderful! MarkBERT

《数据安全法》出台一周年,看哪四大变化来袭?
随机推荐
LeetCode 438. Find all letter ectopic words in the string__ sliding window
JS基础--数据类型
Mall applet source code open source version - two open
Leetcode 181 Employees exceeding the manager's income (June 29, 2022)
放弃深圳高薪工作回老家
Development overview of fund internationalization
Jd.com renewed its cooperation with Tencent: issuing class A shares to Tencent with a maximum value of US $220million
CVPR 2022 | Virtual Correspondence: Humans as a Cue for Extreme-View Geometry
网站源码整站下载 网站模板源代码下载
Harbor webhook从原理到构建
流动性质押挖矿系统开发如何制作,dapp丨defi丨nft丨lp流动性质押挖矿系统开发案例分析及源码
Database experiment report (I)
y48.第三章 Kubernetes从入门到精通 -- Pod的状态和探针(二一)
"Target detection" + "visual understanding" to realize the understanding and translation of the input image (with source code)
The first anniversary of the data security law, which four major changes are coming?
华为设备配置大型网络WLAN基本业务
Flip the array gracefully
价值1000毕业设计校园信息发布平台网站源码
Can I open a securities account anywhere? Is it safe to open an account
node版本管理器nvm安装及切换