当前位置:网站首页>activity工作流引擎
activity工作流引擎
2022-07-01 11:12:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
工作流activity引擎入门案例
1、工作流是什么? 简单来说工作流就是将一条信息根据角色、分工、条件不同进行固定的向上传递,数据是按照固定的流向进行传输,一级一级传递下去,这种场景在OA , CRM / ERP中应用的比较多。通常这种操作自己本身也可以通过逻辑来实现,但是复杂度很高。而且不方便维护。所以通常都采用第三方引擎框架来实现,出了引擎本身简化了操作以外。更重要的是维护起来很方便。
2、activity工作流引擎 activity是一个比较简单容易上手的工作流,主要操作分为一下步骤
- 利用activity插件画出需要的逻辑流程图
- 部署流程
- 启动流程
- 迭代处理流程
- 流程结束
3、activity环境搭建 1、新建一个maven项目
2、导入maven依赖
<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、安装画图插件,本操作比较简单, 百度能收到,建议采用离线安装 略。。。。。。。。。。。 4、activity是一套完成的体系,包含各种操作和数据库表都由框架本身提供,所以第一步先导入ativity需要的表结构 在resources下新建activiti.cfg.xml文件:
<?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>新建一个java类 【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);
}
}然后运行就会在数据库中就会出现如下:
有了画图插件和数据库的表结构,基本环境就算搭建完成。
4、入门案例编写 第一步:画流程图。 流程图是最核心的操作,后面的数据走向就会按流程图进行传递。 这里以报销单为例:
画图时要注意,提前吧几个模块加载出来
properties可以通过window—showview加载出来,右边的为画图的控件, 我们一共需要4个节点 StartEvent : 启动事件
选中图标拖拽到左边空白出即可
然后点击右边箭头图标,表示新增一个用户任务[UserTask],
同理在依次添加经理审批、财务审批、结束事件
然后修改各个模块属性(properties):
然后保存该流程图, 画图完成。注意,箭头路径就是数据流向。如下图:
*此处注意:*如果无保存后无图片生成,则需要开启一个配置,然后重新保存
5、编写代码,发布、启动、查询任务、处理任务
/**
* 部署流程
*/
private static ProcessEngine processEngine =ProcessEngines.getDefaultProcessEngine();
public void delployFlow(){
Deployment deployment = processEngine.getRepositoryService()
.createDeployment()
.name("报销流程") //流程名字
.addClasspathResource("baoxiao.bpmn")
.addClasspathResource("baoxiao.png")
.deploy();
// 存在在数据库 act_re_procdef的DEPLOYMENT_ID_
System.out.println(deployment.getId());
System.out.println(deployment.getName());
}运行很简单,自己建个main方法跑一下就OK,结果如下:
部署后查看数据库
注意此处的key值: 下一步需要使用它 【此处由于是demo,所以我们就不查询数据库,直接取值操作查看效果】
启动流程代码:
// 启动流程
public void flowStart(){
RuntimeService runtimeService = processEngine.getRuntimeService();
//用key启动时按照最新的流程图版本定义启动 [数据库表=act_re_procdef流程定义表中的KEY_字段]
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("员工报销单据");
}运行代码后查看数据库act_ru_task表 红框位置表示节点信息
我们在查询employe的任务:
public void findEmployeeTask(){
//数据库关系》》》》ID【act_re_deployment】 == ID【act_ru_execution】 == ID【act_ru_task】 ==》【ASSIGNEE_(cwh)】
String assignee = "employee"; //节点的assignee_
List<Task> taskList= processEngine.getTaskService()//获取任务service
.createTaskQuery()//创建查询对象
.taskAssignee(assignee)//指定查询人
.list();
if(taskList.size()>0){
for (Task task : taskList){
System.out.println("代办任务ID:"+task.getId());
System.out.println("代办任务name:"+task.getName());
System.out.println("代办任务创建时间:"+task.getCreateTime());
System.out.println("代办任务办理人:"+task.getAssignee());
System.out.println("流程实例ID:"+task.getProcessInstanceId());
System.out.println("执行对象ID:"+task.getExecutionId());
}
}
}我们查到employee下有一个5004的任务在等待处理,我们直接处理
/**
* 处理流程
*
* @Description:
*/
public void completeTask(){
// ID【act_ru_task】
String taskId = "5004";
processEngine.getTaskService().complete(taskId);//完成任务
System.out.println("完成任务,任务ID"+taskId);
}然后查看数据库效果
很明显,流程从employee流转到了 manager 下面, 当然这个过程自己分析一下会更清楚,,
处理流程只需要看 ru相关的表, 这是在处理的任务信息表。 在为处理完之前不参与记录数据,
剩下的就是 重复操作了。。 1、获取经理的代办流程 – 处理流程 2、获取财务的代办流程 – 处理流程 – 流程结束
这只是一个很简单的初始demo,但基本可以搞清楚activity的运行流程和执行逻辑。以及大概会应用到那些 场景。至于后续操作,可以查看文档或者其他资料根据需求学习。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/131683.html原文链接:https://javaforall.cn
边栏推荐
- Getting started with Paxos
- CVPR22 |CMT:CNN和Transformer的高效结合(开源)
- 选择在中金证券上炒股开户可以吗?安全吗?
- Spam filtering challenges
- Database experiment report (I)
- 关于Keil编译程序出现“File has been changed outside the editor,reload?”的解决方法
- Mall applet source code open source version - two open
- 【AI资讯月刊】350+资源大盘点!6月不容错过的资料和动态,都都都在这里啦!<附下载>
- The idea runs with an error command line is too long Shorten command line for...
- Goldfish rhca memoirs: do447 uses ansible to communicate with API -- using ansible tower API to start jobs
猜你喜欢

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%

Brief analysis of edgedb architecture

软件项目管理 9.2.软件项目配置管理过程

Face detection and recognition system based on mtcnn+facenet

Shangtang entered the lifting period: the core management voluntarily banned and strengthened the company's long-term value confidence

Huawei equipment is configured with large network WLAN basic services

BAIC bluevale: performance under pressure, extremely difficult period

TEMPEST HDMI泄漏接收 5

Database experiment report (II)

关于Keil编译程序出现“File has been changed outside the editor,reload?”的解决方法
随机推荐
转义字符串
No statements may be issued when any streaming result sets are open and in use on a given connection
[AI information monthly] 350 + resources! All the information and trends that can't be missed in June are here! < Download attached >
软件项目管理 9.2.软件项目配置管理过程
Tianrunyun, invested by Tian Suning, was listed: its market value was 2.2 billion Hong Kong, and its first year profit decreased by 75%
TEMPEST HDMI泄漏接收 4
Global filter (processing time format)
Mutual conversion of pictures in fluent uint8list format and pictures in file format
mysql如何把 一个数据库中的表数据 复制到 另一个数据库中(两个数据库不在同一个数据库链接下)
全局过滤器(处理时间格式)
Tempest HDMI leak receive 3
Combinaison Oracle et json
Applymiddleware principle
"Target detection" + "visual understanding" to realize the understanding and translation of the input image (with source code)
In June 2022, it was the first programming language?!
【MAUI】为 Label、Image 等控件添加点击事件
Intel Labs announces new progress in integrated photonics research
Win平台下influxDB导出、导入
Leetcode 181 Employees exceeding the manager's income (June 29, 2022)
Get key code