【Flowable】任务监听器(五)

前言

之前有需要使用到Flowable,鉴于网上的资料不是很多也不是很全也是捣鼓了半天,因此争取能在这里简单分享一下经验,帮助有需要的朋友,也非常欢迎大家指出不足的地方。

一、监听器

在Flowable中,我们可以使用监听器来完成很多流程业务,比如指定任务处理人、任务通知提醒等操作,在这里我们来简单尝试一下监听器的使用,我们在上篇文章中使用的请假流程中来创建监听器。

在这里插入图片描述
在这里插入图片描述
如上图所示:

  • 事件
    • create:任务创建的时候触发。
    • assignment:在分配处理人的时候触发。
    • complete:处理完成之后触发。
    • all:所有的行为都会触发

我们创建一下监听器:指定一下事件类型这里用create,其中org.flowable.TestTaskListener为自定义的一个java类
在这里插入图片描述
这里也提供了更新之后的xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:flowable="http://flowable.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.flowable.org/processdef" exporter="Flowable Open Source Modeler" exporterVersion="6.7.2"><process id="MyHoliday" name="MyHoliday" isExecutable="true"><startEvent id="startEvent1" name="开始" flowable:formFieldValidation="true"></startEvent><userTask id="sid-320C4AED-D9F4-4C53-B2B6-D4ACCBA155F5" name="直线审批" flowable:formFieldValidation="true"><extensionElements><flowable:taskListener event="create" class="org.flowable.TestTaskListener"></flowable:taskListener></extensionElements></userTask><sequenceFlow id="sid-422764E6-61F4-454A-BF08-9CF973E1E67D" sourceRef="startEvent1" targetRef="sid-320C4AED-D9F4-4C53-B2B6-D4ACCBA155F5"></sequenceFlow><userTask id="sid-873E297E-9E6B-4F4E-AF6A-2E085F1806B1" name="部门审批" flowable:formFieldValidation="true"><extensionElements><flowable:taskListener event="create" class="org.flowable.TestTaskListener"></flowable:taskListener></extensionElements></userTask><sequenceFlow id="sid-A0869337-10D3-43BC-90C1-036C9719308E" sourceRef="sid-320C4AED-D9F4-4C53-B2B6-D4ACCBA155F5" targetRef="sid-873E297E-9E6B-4F4E-AF6A-2E085F1806B1"></sequenceFlow><endEvent id="sid-CAB64925-F653-4167-8E12-ED956B723D2E" name="结束"></endEvent><sequenceFlow id="sid-91D96B3A-3408-4504-A23D-8F0C2AFE19A7" sourceRef="sid-873E297E-9E6B-4F4E-AF6A-2E085F1806B1" targetRef="sid-CAB64925-F653-4167-8E12-ED956B723D2E"></sequenceFlow></process><bpmndi:BPMNDiagram id="BPMNDiagram_MyHoliday"><bpmndi:BPMNPlane bpmnElement="MyHoliday" id="BPMNPlane_MyHoliday"><bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1"><omgdc:Bounds height="30.0" width="30.0" x="89.99999731779107" y="149.99999552965178"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-320C4AED-D9F4-4C53-B2B6-D4ACCBA155F5" id="BPMNShape_sid-320C4AED-D9F4-4C53-B2B6-D4ACCBA155F5"><omgdc:Bounds height="80.0" width="100.00000000000003" x="164.99999731779107" y="124.99999552965178"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-873E297E-9E6B-4F4E-AF6A-2E085F1806B1" id="BPMNShape_sid-873E297E-9E6B-4F4E-AF6A-2E085F1806B1"><omgdc:Bounds height="80.00000000000001" width="100.0" x="299.99999105930357" y="119.99999642372141"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="sid-CAB64925-F653-4167-8E12-ED956B723D2E" id="BPMNShape_sid-CAB64925-F653-4167-8E12-ED956B723D2E"><omgdc:Bounds height="28.0" width="28.0" x="464.9999861419205" y="145.9999920725826"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNEdge bpmnElement="sid-91D96B3A-3408-4504-A23D-8F0C2AFE19A7" id="BPMNEdge_sid-91D96B3A-3408-4504-A23D-8F0C2AFE19A7" flowable:sourceDockerX="50.0" flowable:sourceDockerY="40.00000000000001" flowable:targetDockerX="14.0" flowable:targetDockerY="14.0"><omgdi:waypoint x="399.94999034668683" y="159.99999473723344"></omgdi:waypoint><omgdi:waypoint x="464.99998600932435" y="159.99999254311274"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-A0869337-10D3-43BC-90C1-036C9719308E" id="BPMNEdge_sid-A0869337-10D3-43BC-90C1-036C9719308E" flowable:sourceDockerX="50.000000000000014" flowable:sourceDockerY="40.0" flowable:targetDockerX="50.0" flowable:targetDockerY="40.00000000000001"><omgdi:waypoint x="264.9499973177909" y="163.1481439230865"></omgdi:waypoint><omgdi:waypoint x="299.9999910593035" y="161.8499961786801"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-422764E6-61F4-454A-BF08-9CF973E1E67D" id="BPMNEdge_sid-422764E6-61F4-454A-BF08-9CF973E1E67D" flowable:sourceDockerX="15.0" flowable:sourceDockerY="15.0" flowable:targetDockerX="50.000000000000014" flowable:targetDockerY="40.0"><omgdi:waypoint x="119.94999580774865" y="164.99999552965178"></omgdi:waypoint><omgdi:waypoint x="164.9999973177828" y="164.99999552965178"></omgdi:waypoint></bpmndi:BPMNEdge></bpmndi:BPMNPlane></bpmndi:BPMNDiagram>
</definitions>

将此xml文件放置项目的资源目录下

二、创建监听类

package org.flowable;import org.flowable.engine.delegate.TaskListener;
import org.flowable.task.service.delegate.DelegateTask;/*** Author:hyy* Date:2023/9/15* Description:*/
public class TestTaskListener implements TaskListener {@Overridepublic void notify(DelegateTask delegateTask) {System.err.println("============= 监听器执行 ================= ");if("create".equals(delegateTask.getEventName()) ){System.out.println("你的业务操作....");}}
}

创建TestTaskListener实现TaskListener,我们发现这个方法的关键信息都是从DelegateTask中获取,name我们来看一下这个类

public interface DelegateTask extends VariableScope {//任务IDString getId();//任务名称String getName();void setName(String name);//描述String getDescription();void setDescription(String description);//优先级int getPriority();void setPriority(int priority);//实例IDString getProcessInstanceId();//流程定义IDString getProcessDefinitionId();Date getCreateTime();//任务主键String getTaskDefinitionKey();//是否终断boolean isSuspended();//租户IDString getTenantId();//表单keyString getFormKey();void setFormKey(String formKey);//事件String getEventName();//....... 
}

三、重新部署流程

在上一篇文章示例中,我们在重新部署一下这个流程

   @Testpublic void testDeploy() {//1.获取ProcessEngine 对象ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();//2.获取RepositoryServiceRepositoryService repositoryService = processEngine.getRepositoryService();//3.完成流程部署操作Deployment deploy = repositoryService.createDeployment().addClasspathResource("MyHoliday.bpmn20.xml") //关联要部署的流程名称.name("请假流程").deploy(); //部署流程System.out.println("id: " + deploy.getId()); System.out.println("name: " + deploy.getName());System.out.println("key: " + deploy.getKey());}

这里去ACT_RE_PROCDEF中找到部署ID为代码打印的ID数据我这里是35001,拿到他的ID_字段MyHoliday:2:35004去启动流程
在这里插入图片描述

四、启动流程

@Testpublic void startTest() {ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine();RuntimeService runtimeService = defaultProcessEngine.getRuntimeService();Map<String, Object> variables = new HashMap<>();variables.put("firstAssigne", "张三");variables.put("deptAssigne", "李四");ProcessInstance processInstance = runtimeService.startProcessInstanceById("MyHoliday:2:35004", variables);System.out.println("processInstance.getProcessInstanceId() = " + processInstance.getProcessInstanceId());}

发现控制台打印如下日志,表示监听器执行完成
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/109795.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C++(day4)

思维导图 封装Mystring #include <iostream> #include<cstring>using namespace std;class Mystring{ public://无参构造函数Mystring():size(10){strnew char[size];strcpy(str,"");cout<<"无参构造函数"<<endl;}//有参构造函数…

中小企业建设数字化工厂,选择集成还是重构

随着科技的飞速发展和市场竞争的日益激烈&#xff0c;数字化工厂管理系统已成为中小企业未来发展的必经之路。然而&#xff0c;对于许多中小企业来说&#xff0c;建设数字化工厂并非易事。在建设数字化工厂的过程中&#xff0c;企业需要面对许多问题&#xff0c;其中最关键的问…

Zynq UltraScale+ XCZU3EG 纯VHDL解码 IMX214 MIPI 视频,2路视频拼接输出,提供vivado工程源码和技术支持

目录 1、前言免责声明 2、我这里已有的 MIPI 编解码方案3、本 MIPI CSI2 模块性能及其优越性4、详细设计方案设计原理框图IMX214 摄像头及其配置D-PHY 模块CSI-2-RX 模块Bayer转RGB模块伽马矫正模块VDMA图像缓存Video Scaler 图像缓存DP 输出 5、vivado工程详解PL端FPGA硬件设计…

【栈与队列面试题】有效的括号(动图演示)

leetcode20.括号匹配问题 前言&#xff1a; &#x1f4a5;&#x1f388;个人主页:​​​​​​Dream_Chaser&#xff5e; &#x1f388;&#x1f4a5; ✨✨刷题专栏:http://t.csdn.cn/UlvTc ⛳⛳本篇内容:力扣上栈与队列的面试OJ题目 目录 leetcode20.括号匹配问题 1.问题描…

jmeter接口测试及详细步骤以及项目实战教程

在接口测试项目实战中&#xff0c;JMeter是一款非常强大和流行的自动化测试工具&#xff0c;它可以测试各种类型的应用程序&#xff0c;并通过采样和报告来识别性能瓶颈和API的问题。本文将为你提供一个基于实际项目的JMeter接口测试项目实战教程&#xff0c;指导你如何使用JMe…

性能测试之性能监控和性能优化

目录 一.概述二.jconsole和jvisualvm三.jconsole四.visualvm1.输入命令提示 jvisualvm不是内部或外部命令&#xff0c;也不是可运行的程序或批处理文件2.打开jvisualvm里面不包含GC监控 五.性能优化1.优化中间件&#xff08;中间件越多&#xff0c;系统性能越差&#xff09;2.优…

【AIGC专题】Stable Diffusion 从入门到企业级实战0601

一、前言 本章是《Stable Diffusion 从入门到企业级实战》系列的第六部分Prompt专题篇《Stable Diffusion Prompt 专题》第01节 《Stable Diffusion Prompt 通用画风操作实战》。本部分内容&#xff0c;位于整个Stable Diffusion生态体系的位置如下图黄色部分所示&#xff1a;…

重新认识交叉编译

1. 我以前对交叉编译的认知 引用正点原子的话来讲就是: 说得对&#xff0c;但是不全面&#xff0c;直到最近项目中遇到了一个例子我才重新认识什么是交叉编译。 2. build/host/target的概念 参考: Cross-Compilation (automake) 参考: Specifying Target Triplets (Autocon…

leetcode:70. 爬楼梯

一、题目 函数原型&#xff1a;int climbStairs(int n) 二、思路 此题运用递归思想。当只有1个台阶&#xff0c;那么只有1种方法爬到楼顶——跨一个台阶&#xff1b;当有2个台阶时&#xff0c;有2种方法爬到楼顶——跨一个台阶跨两次或直接跨两个台阶。当有3个台阶或更多台阶时…

每日刷题-6

目录 一、选择题 二、算法题 1.Fibonacci数列 2.合法括号序列判断 一、选择题 1、 解析&#xff1a;内联函数是一种可以提高函数执行效率的方法&#xff0c;它的原理是编译时在函数调用点直接展开函数体的代码&#xff0c;从而避免了函数调用的开销。 但是&#xff0c;内联函…

华为云云耀云服务器L实例评测|华为云云耀云服务器L实例开展性能评测

作者简介&#xff1a; 辭七七&#xff0c;目前大二&#xff0c;正在学习C/C&#xff0c;Java&#xff0c;Python等 作者主页&#xff1a; 七七的个人主页 文章收录专栏&#xff1a; 七七的闲谈 欢迎大家点赞 &#x1f44d; 收藏 ⭐ 加关注哦&#xff01;&#x1f496;&#x1f…

Pico-I / O嵌入式模块提供48点数字I / O接口

WinSystems的PCO-UIO48-G是具有中断事件检测功能的48点数字I / O接口。Pico-I / O嵌入式模块旨在为Pico-ITXe单板计算机提供低成本的I / O扩展。该产品的主要功能之一是&#xff0c;它可以监视24个上升和下降的数字边沿转换&#xff0c;将其锁存&#xff0c;然后向主机处理器发…