当前位置:网站首页>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
边栏推荐
- Website source code whole site download website template source code download
- 放弃深圳高薪工作回老家
- 转义字符串
- Mutual conversion of pictures in fluent uint8list format and pictures in file format
- Combination of Oracle and JSON
- flutter Uint8List格式的图片和File格式图片的互相转换
- Ten years of sharpening a sword: unveiling the secrets of ant group's observability platform antmonitor
- Paxos 入门
- Personal mall two open Xiaoyao B2C mall system source code - Commercial Version / group shopping discount seckill source code
- kubernetes之ingress探索实践
猜你喜欢

名创拟7月13日上市:最高发行价22.1港元 单季净利下降19%

【MAUI】为 Label、Image 等控件添加点击事件

TEMPEST HDMI泄漏接收 5

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

"Target detection" + "visual understanding" to realize the understanding and translation of the input image (with source code)

田溯宁投的天润云上市:市值22亿港元 年利润下降75%

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%

关于Keil编译程序出现“File has been changed outside the editor,reload?”的解决方法

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

编译调试Net6源码
随机推荐
CVPR 2022 | Virtual Correspondence: Humans as a Cue for Extreme-View Geometry
"Target detection" + "visual understanding" to realize the understanding and translation of the input image (with source code)
达梦数据冲刺科创板:拟募资24亿 冯裕才曾为华科教授
为什么一定要从DevOps走向BizDevOps?
JS基础--数据类型
证券账户随便哪里开都能使用吗 开户安全吗
Yoda unified data application -- Exploration and practice of fusion computing in ant risk scenarios
编译调试Net6源码
索引失效的几种情况
英特爾實驗室公布集成光子學研究新進展
TEMPEST HDMI泄漏接收 3
VScode快捷键(最全)[通俗易懂]
Mutual conversion of pictures in fluent uint8list format and pictures in file format
力扣(LeetCode)181. 超过经理收入的员工(2022.06.29)
Tempest HDMI leak receive 3
十年磨一剑:蚂蚁集团可观测性平台 AntMonitor 揭秘
数据库实验报告(一)
小米手机解BL锁教程
Skip the test cases to be executed in the unittest framework
商汤进入解禁期:核心管理层自愿禁售 强化公司长期价值信心