当前位置:网站首页>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
边栏推荐
- 为什么一定要从DevOps走向BizDevOps?
- Export and import of incluxdb on WIN platform
- 达梦数据冲刺科创板:拟募资24亿 冯裕才曾为华科教授
- I'd like to know where I can open an account in Guangzhou? Is it safe to open an account online now?
- In June 2022, it was the first programming language?!
- "Target detection" + "visual understanding" to realize the understanding and translation of the input image (with source code)
- flutter path_ Provider: ^2.0.10 can get temporary directory
- 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)
- 我国蜂窝物联网用户已达 15.9 亿,年内有望超越移动电话用户
- 关于Keil编译程序出现“File has been changed outside the editor,reload?”的解决方法
猜你喜欢

Spam filtering challenges

Combinaison Oracle et json

The exclusive collection of China lunar exploration project is limited to sale!

JS foundation -- data type

node版本管理器nvm安装及切换

网站源码整站下载 网站模板源代码下载

CPI教程-异步接口创建及使用

移动硬盘驱动器读到,但不显示盘符

Applymiddleware principle

LeetCode. 515. Find the maximum value in each tree row___ BFS + DFS + BFS by layer
随机推荐
MIT's latest paper, "the need for interpretable features: motivation and classification": building interpretability in the constituent elements of machine learning models
Get key code
node版本管理器nvm安装及切换
Give up high paying jobs in Shenzhen and go back home
Personal mall two open Xiaoyao B2C mall system source code - Commercial Version / group shopping discount seckill source code
No statements may be issued when any streaming result sets are open and in use on a given connection
证券账户随便哪里开都能使用吗 开户安全吗
数据库实验报告(二)
Tianrunyun, invested by Tian Suning, was listed: its market value was 2.2 billion Hong Kong, and its first year profit decreased by 75%
金融壹账通拟7月4日香港上市:2年亏近30亿 市值蒸发超90%
Crawler (2) - requests (1) | deep parsing of requests module
提问:测试工程师应该具备哪些职业素养?
CVPR22 |CMT:CNN和Transformer的高效结合(开源)
关于Keil编译程序出现“File has been changed outside the editor,reload?”的解决方法
索引失效的几种情况
云上“视界” 创新无限 | 2022阿里云直播峰会正式上线
个人商城二开逍遥B2C商城系统源码-可商用版/拼团拼购优惠折扣秒杀源码
MySQL IN 和 NOT IN () 空列表报错
Website source code whole site download website template source code download
京东与腾讯续签合作:向腾讯发行A类股 价值最高达2.2亿美元