当前位置:网站首页>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
边栏推荐
- [AI information monthly] 350 + resources! All the information and trends that can't be missed in June are here! < Download attached >
- China's cellular Internet of things users have reached 1.59 billion, and are expected to surpass mobile phone users within this year
- 力扣(LeetCode)181. 超过经理收入的员工(2022.06.29)
- 优雅地翻转数组
- 持续交付-Pipeline入门
- Compliance management of fund managers
- 華為設備配置大型網絡WLAN基本業務
- CVPR 2022 | Virtual Correspondence: Humans as a Cue for Extreme-View Geometry
- mysql如何把 一个数据库中的表数据 复制到 另一个数据库中(两个数据库不在同一个数据库链接下)
- PHP有哪些优势和劣势
猜你喜欢

How does MySQL copy table data from one database to another (two databases are not linked to the same database)

索引失效的几种情况

Tempest HDMI leak receive 5

LeetCode. 515. Find the maximum value in each tree row___ BFS + DFS + BFS by layer

Harbor webhook从原理到构建

Oracle和JSON的结合

applyMiddleware 原理

金融壹账通拟7月4日香港上市:2年亏近30亿 市值蒸发超90%

Spam filtering challenges

商汤进入解禁期:核心管理层自愿禁售 强化公司长期价值信心
随机推荐
kubernetes之ingress探索实践
Matrix of numpy
kafuka学习之路(一)kafuka安装和简单使用
[AI information monthly] 350 + resources! All the information and trends that can't be missed in June are here! < Download attached >
【MAUI】为 Label、Image 等控件添加点击事件
No statements may be issued when any streaming result sets are open and in use on a given connection
Website source code whole site download website template source code download
索引失效的几种情况
TEMPEST HDMI泄漏接收 3
金融壹账通拟7月4日香港上市:2年亏近30亿 市值蒸发超90%
Shangtang entered the lifting period: the core management voluntarily banned and strengthened the company's long-term value confidence
Unittest框架中跳过要执行的测试用例
tmux使用
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)
Internal control of fund managers
flutter Uint8List格式的图片和File格式图片的互相转换
Huawei equipment is configured with large network WLAN basic services
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%
Face detection and recognition system based on mtcnn+facenet
LeetCode.515. 在每个树行中找最大值___逐一BFS+DFS+按层BFS