flowable学习笔记(四):动态多实例
1.定义流程模板
【测试用户任务多实例】任务节点配置了以下属性:
集合(多实例):userList。这个创建流程实例时入参需要加上这个参数。
元素变量(多实例):user。工作流创建多实例时会将集合(多实例)的值拆分成元素变量(多实例),这个例子每个实例会有一个入参变量名称是user。
多实例类型:我设置成Parallel(并行)。
完成条件(多实例):${nrOfCompletedInstances/nrOfInstances == 1}
表示全部实例通过提交才算完成。${nrOfCompletedInstances/nrOfInstances >= 0.5}
表示一半的实例通过提交才算完成。
nrOfCompletedInstances:完成实例数。number of Completed Instances
nrOfInstances:总实例数。number of Instances
执行监听器:配置一个执行监听器CommonMoreInstancesExecutionListener,用于打印流程变量。
任务监听器:配置一个任务监听器CommonMoreInstancesTaskListener,用于打印流程变量。
结束节点配置了以下属性:
执行监听器:配置一个执行监听器CommonEndExecutionListener,用于判断任务节点结束条件。
2.代码
(1)CommonMoreInstancesExecutionListener
package gdut.listener;import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.springframework.stereotype.Component;import java.util.Map;
import java.util.Random;@Component
public class CommonMoreInstancesExecutionListener implements ExecutionListener {@Overridepublic void notify(DelegateExecution delegateExecution) {System.out.println("CommonMoreInstancesExecutionListener start");Map<String, Object> variables = delegateExecution.getVariables();System.out.println("CommonMoreInstancesExecutionListener variables is:" + variables);System.out.println("CommonMoreInstancesExecutionListener executionId is:" + delegateExecution.getId());}
}
(2)CommonMoreInstancesTaskListener
package gdut.listener;import org.flowable.engine.delegate.TaskListener;
import org.flowable.task.service.delegate.DelegateTask;
import org.springframework.stereotype.Component;import java.util.Map;@Component
public class CommonMoreInstancesTaskListener implements TaskListener {@Overridepublic void notify(DelegateTask delegateTask) {System.out.println("CommonMoreInstancesTaskListener start");Map<String, Object> variables = delegateTask.getVariables();System.out.println("CommonMoreInstancesTaskListener variables is:" + variables);System.out.println("CommonMoreInstancesTaskListener executionId is:" + delegateTask.getExecutionId());System.out.println("CommonMoreInstancesTaskListener taskId is:" + delegateTask.getId());}
}
(3)创建流程实例接口
//创建流程实例@PostMapping("/createFlowInstanceByMap")public String createFlowInstanceByMap(@RequestBody JSONObject params) {String flowDefinitionName = params.getStr("flowDefinitionName");Map<String, Object> paramsMap = BeanUtil.beanToMap(params);ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(flowDefinitionName, paramsMap);System.out.println("createFlowInstanceByMap instanceId is:" + processInstance.getProcessInstanceId());return processInstance.getProcessInstanceId();}
3.测试
部署流程定义:
http://localhost:8081/flowable/deployFlowDefinition?fileName=TestMoreInstances.bpmn20.xml
创建流程实例:
http://localhost:8081/flowable/createFlowInstanceByMap
{
“flowDefinitionName”:“TestMoreInstances”,
“userList”:[“liufeifei”, “liushanshan”, “liuhao”]
}
打印输出:
CommonStartExecutionListener start
CommonStartExecutionListener variables is:{userList=["liufeifei","liushanshan","liuhao"], flowDefinitionName=TestMoreInstances}
CommonMoreInstancesExecutionListener start
CommonMoreInstancesExecutionListener variables is:{userList=["liufeifei","liushanshan","liuhao"], flowDefinitionName=TestMoreInstances, commonStartExecutionListener=CommonStartExecutionListener}
CommonMoreInstancesExecutionListener executionId is:caa751e3-875b-11ed-a341-c03c5949a6ca
CommonMoreInstancesExecutionListener start
CommonMoreInstancesExecutionListener variables is:{nrOfActiveInstances=3, userList=["liufeifei","liushanshan","liuhao"], flowDefinitionName=TestMoreInstances, commonStartExecutionListener=CommonStartExecutionListener, loopCounter=0, user=liufeifei, nrOfInstances=3, nrOfCompletedInstances=0}
CommonMoreInstancesExecutionListener executionId is:caaaad4b-875b-11ed-a341-c03c5949a6ca
CommonMoreInstancesTaskListener start
CommonMoreInstancesTaskListener variables is:{nrOfActiveInstances=3, userList=["liufeifei","liushanshan","liuhao"], flowDefinitionName=TestMoreInstances, commonStartExecutionListener=CommonStartExecutionListener, loopCounter=0, user=liufeifei, nrOfInstances=3, nrOfCompletedInstances=0}
CommonMoreInstancesTaskListener executionId is:caaaad4b-875b-11ed-a341-c03c5949a6ca
CommonMoreInstancesTaskListener taskId is:caab4993-875b-11ed-a341-c03c5949a6ca
CommonMoreInstancesExecutionListener start
CommonMoreInstancesExecutionListener variables is:{nrOfActiveInstances=3, userList=["liufeifei","liushanshan","liuhao"], flowDefinitionName=TestMoreInstances, commonStartExecutionListener=CommonStartExecutionListener, loopCounter=1, user=liushanshan, nrOfInstances=3, nrOfCompletedInstances=0}
CommonMoreInstancesExecutionListener executionId is:caaaad4c-875b-11ed-a341-c03c5949a6ca
CommonMoreInstancesTaskListener start
CommonMoreInstancesTaskListener variables is:{nrOfActiveInstances=3, userList=["liufeifei","liushanshan","liuhao"], flowDefinitionName=TestMoreInstances, commonStartExecutionListener=CommonStartExecutionListener, loopCounter=1, user=liushanshan, nrOfInstances=3, nrOfCompletedInstances=0}
CommonMoreInstancesTaskListener executionId is:caaaad4c-875b-11ed-a341-c03c5949a6ca
CommonMoreInstancesTaskListener taskId is:caae7de6-875b-11ed-a341-c03c5949a6ca
CommonMoreInstancesExecutionListener start
CommonMoreInstancesExecutionListener variables is:{nrOfActiveInstances=3, userList=["liufeifei","liushanshan","liuhao"], flowDefinitionName=TestMoreInstances, commonStartExecutionListener=CommonStartExecutionListener, loopCounter=2, user=liuhao, nrOfInstances=3, nrOfCompletedInstances=0}
CommonMoreInstancesExecutionListener executionId is:caaaad4d-875b-11ed-a341-c03c5949a6ca
CommonMoreInstancesTaskListener start
CommonMoreInstancesTaskListener variables is:{nrOfActiveInstances=3, userList=["liufeifei","liushanshan","liuhao"], flowDefinitionName=TestMoreInstances, commonStartExecutionListener=CommonStartExecutionListener, loopCounter=2, user=liuhao, nrOfInstances=3, nrOfCompletedInstances=0}
CommonMoreInstancesTaskListener executionId is:caaaad4d-875b-11ed-a341-c03c5949a6ca
CommonMoreInstancesTaskListener taskId is:cab02b99-875b-11ed-a341-c03c5949a6ca
createFlowInstanceByMap instanceId is:caa5a42e-875b-11ed-a341-c03c5949a6ca
总结:
(1)从上面的打印输出可以发现:flowable是先调用了一次执行监听器,再创建了3个用户任务实例(我请求的参数userList数组长度是3)。
(2)创建的多实例的执行监听器和任务监听器获取到的流程参数,除了创建流程实例的入参,还增加了以下几个变量:
nrOfActiveInstances 活跃的实例数
loopCounter 类似for循环下标 for(int i = 0;i < userList.size();i++) 表示i的值。
nrOfInstances 总的实例数
nrOfCompletedInstances 完成实例数
user 元素变量 获取userList.get(i)的值。
(3)查看flowable数据库表ACT_RU_TASK有三条记录:
select * from ACT_RU_TASK where PROC_INST_ID_ = ‘caa5a42e-875b-11ed-a341-c03c5949a6ca’;
提交任务
http://localhost:8081/flowable/completeTaskId?taskId=caab4993-875b-11ed-a341-c03c5949a6ca
完成一个任务,结束节点监听器没有执行。ACT_RU_TASK表还有2条记录。
http://localhost:8081/flowable/completeTaskId?taskId=caae7de6-875b-11ed-a341-c03c5949a6ca
完成第二个任务,结束节点监听器没有执行。ACT_RU_TASK表还有1条记录。
http://localhost:8081/flowable/completeTaskId?taskId=cab02b99-875b-11ed-a341-c03c5949a6ca
提交第三个任务,结束节点监听器执行了,ACT_RU_TASK表没有记录。
结束节点执行监听器打印输出:
CommonEndExecutionListener end
CommonEndExecutionListener variables is:{userList=["liufeifei","liushanshan","liuhao"], flowDefinitionName=TestMoreInstances, commonStartExecutionListener=CommonStartExecutionListener}
符合我配置的完成条件,3个实例全部完成,该任务节点才算通过。
bpmn.xml
(1)TestMoreInstances.bpmn20.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="TestMoreInstances" name="TestMoreInstances" isExecutable="true"><documentation>测试多实例</documentation><startEvent id="testMoreInstancesStart" name="测试用户任务多实例开始节点" flowable:formFieldValidation="true"><extensionElements><flowable:executionListener event="start" delegateExpression="${commonStartExecutionListener}"></flowable:executionListener></extensionElements></startEvent><userTask id="TestMoreUserTaskInstances" name="测试用户任务多实例" flowable:formFieldValidation="true"><extensionElements><flowable:executionListener event="start" delegateExpression="${commonMoreInstancesExecutionListener}"></flowable:executionListener><flowable:taskListener event="create" delegateExpression="${commonMoreInstancesTaskListener}"></flowable:taskListener></extensionElements><multiInstanceLoopCharacteristics isSequential="false" flowable:collection="userList" flowable:elementVariable="user"><extensionElements></extensionElements><completionCondition>${nrOfCompletedInstances/nrOfInstances == 1}</completionCondition></multiInstanceLoopCharacteristics></userTask><endEvent id="testMoreInstancesEnd" name="测试用户任务多实例结束节点"><extensionElements><flowable:executionListener event="start" delegateExpression="${commonEndExecutionListener}"></flowable:executionListener></extensionElements></endEvent><sequenceFlow id="sid-FF142143-F573-4FD7-905A-BBA5E118F13F" sourceRef="testMoreInstancesStart" targetRef="TestMoreUserTaskInstances"></sequenceFlow><sequenceFlow id="sid-90EEDCBB-5375-4A8E-A1C3-C239743F9D96" sourceRef="TestMoreUserTaskInstances" targetRef="testMoreInstancesEnd"></sequenceFlow></process><bpmndi:BPMNDiagram id="BPMNDiagram_TestMoreInstances"><bpmndi:BPMNPlane bpmnElement="TestMoreInstances" id="BPMNPlane_TestMoreInstances"><bpmndi:BPMNShape bpmnElement="testMoreInstancesStart" id="BPMNShape_testMoreInstancesStart"><omgdc:Bounds height="30.0" width="30.0" x="135.0" y="70.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="TestMoreUserTaskInstances" id="BPMNShape_TestMoreUserTaskInstances"><omgdc:Bounds height="80.0" width="100.0" x="285.0" y="45.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNShape bpmnElement="testMoreInstancesEnd" id="BPMNShape_testMoreInstancesEnd"><omgdc:Bounds height="28.0" width="28.0" x="510.0" y="71.0"></omgdc:Bounds></bpmndi:BPMNShape><bpmndi:BPMNEdge bpmnElement="sid-FF142143-F573-4FD7-905A-BBA5E118F13F" id="BPMNEdge_sid-FF142143-F573-4FD7-905A-BBA5E118F13F" flowable:sourceDockerX="15.0" flowable:sourceDockerY="15.0" flowable:targetDockerX="50.0" flowable:targetDockerY="40.0"><omgdi:waypoint x="164.94999946593478" y="85.0"></omgdi:waypoint><omgdi:waypoint x="285.0" y="85.0"></omgdi:waypoint></bpmndi:BPMNEdge><bpmndi:BPMNEdge bpmnElement="sid-90EEDCBB-5375-4A8E-A1C3-C239743F9D96" id="BPMNEdge_sid-90EEDCBB-5375-4A8E-A1C3-C239743F9D96" flowable:sourceDockerX="50.0" flowable:sourceDockerY="40.0" flowable:targetDockerX="14.0" flowable:targetDockerY="14.0"><omgdi:waypoint x="384.94999999998174" y="85.0"></omgdi:waypoint><omgdi:waypoint x="510.0" y="85.0"></omgdi:waypoint></bpmndi:BPMNEdge></bpmndi:BPMNPlane></bpmndi:BPMNDiagram>
</definitions>
参考
flowable 报错 Waiting for changelog lock…
flowable多实例任务注意事项
Flowable—多实例任务:会签
flowable学习笔记(四):动态多实例相关推荐
- Flowable学习笔记(二、BPMN 2.0-基础 )
转载自 Flowable学习笔记(二.BPMN 2.0-基础 ) 1.BPMN简介 业务流程模型和标记法(BPMN, Business Process Model and Notation)是一套图 ...
- Flowable学习笔记(一、入门)
转载自 Flowable学习笔记(一.入门) 一.Flowable简介 1.Flowable是什么 Flowable是一个使用Java编写的轻量级业务流程引擎.Flowable流程引擎可用于部署BP ...
- C#可扩展编程之MEF学习笔记(四):见证奇迹的时刻
前面三篇讲了MEF的基础和基本到导入导出方法,下面就是见证MEF真正魅力所在的时刻.如果没有看过前面的文章,请到我的博客首页查看. 前面我们都是在一个项目中写了一个类来测试的,但实际开发中,我们往往要 ...
- MySQL高级学习笔记(四)
文章目录 MySQL高级学习笔记(四) 1. MySql中常用工具 1.1 mysql 1.1.1 连接选项 1.1.2 执行选项 1.2 mysqladmin 1.3 mysqlbinlog 1.4 ...
- IOS学习笔记(四)之UITextField和UITextView控件学习
IOS学习笔记(四)之UITextField和UITextView控件学习(博客地址:http://blog.csdn.net/developer_jiangqq) Author:hmjiangqq ...
- RabbitMQ学习笔记四:RabbitMQ命令(附疑难问题解决)
RabbitMQ学习笔记四:RabbitMQ命令(附疑难问题解决) 参考文章: (1)RabbitMQ学习笔记四:RabbitMQ命令(附疑难问题解决) (2)https://www.cnblogs. ...
- xcode 学习笔记2:动态添加view
xcode 学习笔记2:动态添加view 2011-07-06 16:48:39| 分类: 计算机学习|字号 订阅 前面说的都是用的Interface Builder来编辑.xib文件来给窗口添加各 ...
- JSP学习笔记(四十九):抛弃POI,使用iText生成Word文档
POI操作excel的确很优秀,操作word的功能却不敢令人恭维.我们可以利用iText生成rtf文档,扩展名使用doc即可. 使用iText生成rtf,除了iText的包外,还需要额外的一个支持rt ...
- Ethernet/IP 学习笔记四
Ethernet/IP 学习笔记四 EtherNet/IP Quick Start for Vendors Handbook (PUB213R0): https://www.odva.org/Port ...
最新文章
- 贝塞尔曲线动画demo(仿美人相机效果)
- 韩国遭 Lazarus Group 供应链攻击
- 第九讲 函数间接展开成幂级数
- 在deepin 上安装佳能MF 4700打印机驱动
- 幼儿园进行计算机培训心得体会,幼儿园家园共育的开展感受和体会
- W5500 dns域名解析
- 得到平面设计师进阶之路
- Files的常用方法都有哪些?
- 「深度」视觉的层次化处理过时了吗?
- 论文阅读:RGCF: Refined Graph Convolution Collaborative Filering with Concise and Expressive Embedding
- 哪些方法能减轻打呼噜的症状呢?
- 抖音如何快速涨粉?李佳琦涨粉技巧揭秘
- 佩尔(Pell)方程最小正整数解
- java编译器下载_java手机版编译器下载
- mybatis实战:一、mybatis入门(配置、一些问题的解决)
- 白嫖正版《极客时间》课程的正确姿势
- VC驿站《实用C++》教程开篇
- JAVA进阶之CopyOnArrayList,线程安全集合
- 从软件隐喻到设计模式的思考(thinking in software metaphors)
- LRU缓存机制,你想知道的这里都有
热门文章
- 短视频营销为什么能火起来?
- 数字藏品具有纪念意义和收藏价值
- 【Win11家庭中文版本Docker Desktop安装指北】
- 【洛谷题解】P5734 【深基6.例6】文字处理软件(C语言)
- 修改视频文件“ 日期”(不是创建日期、修改日期、访问日期)
- 用pandas库提取IBTrACS中特定条件的热带气旋最佳路径数据
- 【CANN训练营第三季】基于昇腾PyTorch框架的模型训练调优
- ROS2之DDS问题汇集
- 数字化浪潮催生新组织关系,看用友云人力服务如何应对?
- 8TB高速存储卡,6GB/s的读写速率,适合高速流盘、信号采集存储的各种应用场景