当前位置:网站首页>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
边栏推荐
- 小米手机解BL锁教程
- Database experiment report (II)
- Neurips 2022 | cell image segmentation competition officially launched!
- MIT's latest paper, "the need for interpretable features: motivation and classification": building interpretability in the constituent elements of machine learning models
- The first anniversary of the data security law, which four major changes are coming?
- CVPR 2022 | Virtual Correspondence: Humans as a Cue for Extreme-View Geometry
- 索引失效的几种情况
- The project bar on the left side of CodeBlocks disappears, workspace automatically saves the project, default workspace, open the last workspace, workspace (Graphic tutorial, solved)
- kubernetes之ingress探索实践
- LeetCode 438. Find all letter ectopic words in the string__ sliding window
猜你喜欢

个人商城二开逍遥B2C商城系统源码-可商用版/拼团拼购优惠折扣秒杀源码

Applymiddleware principle

In June 2022, it was the first programming language?!

Huawei Equipment configure les services de base du réseau WLAN à grande échelle

Mingchuang plans to be listed on July 13: the highest issue price is HK $22.1, and the net profit in a single quarter decreases by 19%

The first anniversary of the data security law, which four major changes are coming?

Combinaison Oracle et json

Google's new paper Minerva: solving quantitative reasoning problems with language models

达梦数据冲刺科创板:拟募资24亿 冯裕才曾为华科教授

索引失效的几种情况
随机推荐
NeurIPS 2022 | 细胞图像分割竞赛正式启动!
价值1000毕业设计校园信息发布平台网站源码
《数据安全法》出台一周年,看哪四大变化来袭?
编译调试Net6源码
Oneconnect plans to be listed in Hong Kong on July 4: a loss of nearly 3 billion in two years, with a market capitalization evaporation of more than 90%
十年磨一剑:蚂蚁集团可观测性平台 AntMonitor 揭秘
放弃深圳高薪工作回老家
Value 1000 graduation project campus information publishing platform website source code
CVPR22 |CMT:CNN和Transformer的高效结合(开源)
Unittest 框架介绍及第一个demo
今天开户今天能买股票吗?在线开户是很安全么?
优雅地翻转数组
How to realize the four isolation levels of MySQL (brief)
Huawei equipment is configured with large network WLAN basic services
TEMPEST HDMI泄漏接收 3
CVPR 2022 | 基于密度与深度分解的自增强非成对图像去雾
流动性质押挖矿系统开发如何制作,dapp丨defi丨nft丨lp流动性质押挖矿系统开发案例分析及源码
CVPR 2022 | Virtual Correspondence: Humans as a Cue for Extreme-View Geometry
mysql如何把 一个数据库中的表数据 复制到 另一个数据库中(两个数据库不在同一个数据库链接下)
y48.第三章 Kubernetes从入门到精通 -- Pod的状态和探针(二一)