600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > [13]深入浅出工作开源框架Camunda:多实例并行用户任务

[13]深入浅出工作开源框架Camunda:多实例并行用户任务

时间:2020-03-28 16:16:52

相关推荐

[13]深入浅出工作开源框架Camunda:多实例并行用户任务

Camunda提供了多实例并行用户任务,比如下面的并行多任务流程!

必须选择三条竖杠。

选择之后,就可以让“并行会签预审批”任务同时由多个人处理~

参考《基于camunda如何实现会签:camunda会签流程配置与原理解析》 大神写的文章,里面对并行用户任务

的主要参数配置进行了说明:

loop cardinality:循环基数。可选项。可以直接填整数,表示会签的人数。Collection:集合。可选项。会签人数的集合,通常为list,和loop cardinality二选一。Element variable:元素变量。选择Collection时必选,为collection集合每次遍历的元素。Completion condition:完成条件。可选。比如设置一个人完成后会签结束,那么其他人的代办任务都会消失。

但是如果直接把上面的流程部署并启动,在“申请”用户任务点击"Complete[完成]"的时候,其会抛出下面的错误!

原因是没有对“并行会签预审批”任务里面的assigneeList 列表对象赋值!因为其会从流程实例的执行上下文中获取其对象。 解决的办法是加入一个动态的脚本:在任何一个Activity(活动)节点加入下面的一段脚本,比如启动任务。

def userList = ['user1', 'user2', 'user3'];execution.setVariable("assigneeList", userList);

重新部署。

其整个BPMN的流程文件如下:

<?xml version="1.0" encoding="UTF-8"?><bpmn:definitions xmlns:bpmn="/spec/BPMN/0524/MODEL" xmlns:bpmndi="/spec/BPMN/0524/DI" xmlns:dc="/spec/DD/0524/DC" xmlns:camunda="/schema/1.0/bpmn" xmlns:di="/spec/DD/0524/DI" xmlns:modeler="/schema/modeler/1.0" id="Definitions_0gyepnf" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.11.1" modeler:executionPlatform="Camunda Platform" modeler:executionPlatformVersion="7.15.0"><bpmn:process id="Process_Parallel-Multiple-Instance-0001" name="并行多实例会签" isExecutable="true"><bpmn:startEvent id="StartEvent_1" name="开始"><bpmn:extensionElements><camunda:executionListener event="start"><camunda:script scriptFormat="groovy">def userList = ['user1', 'user2', 'user3'];execution.setVariable("assigneeList", userList);</camunda:script></camunda:executionListener></bpmn:extensionElements><bpmn:outgoing>Flow_0cwup88</bpmn:outgoing></bpmn:startEvent><bpmn:sequenceFlow id="Flow_0cwup88" sourceRef="StartEvent_1" targetRef="Activity_04suznt" /><bpmn:userTask id="Activity_04suznt" name="申请"><bpmn:incoming>Flow_0cwup88</bpmn:incoming><bpmn:outgoing>Flow_10688hr</bpmn:outgoing></bpmn:userTask><bpmn:sequenceFlow id="Flow_10688hr" sourceRef="Activity_04suznt" targetRef="Activity_huiqian0001" /><bpmn:sequenceFlow id="Flow_0kw2ac2" sourceRef="Activity_huiqian0001" targetRef="Activity_1k8djx2" /><bpmn:userTask id="Activity_huiqian0001" name="并行会签预审批" camunda:assignee="${assignee}"><bpmn:incoming>Flow_10688hr</bpmn:incoming><bpmn:outgoing>Flow_0kw2ac2</bpmn:outgoing><bpmn:multiInstanceLoopCharacteristics camunda:collection="assigneeList" camunda:elementVariable="assignee" /></bpmn:userTask><bpmn:endEvent id="Event_1sk7n99" name="结束"><bpmn:incoming>Flow_1qdyb0n</bpmn:incoming></bpmn:endEvent><bpmn:sequenceFlow id="Flow_1qdyb0n" sourceRef="Activity_1k8djx2" targetRef="Event_1sk7n99" /><bpmn:userTask id="Activity_1k8djx2" name="CEO审批"><bpmn:incoming>Flow_0kw2ac2</bpmn:incoming><bpmn:outgoing>Flow_1qdyb0n</bpmn:outgoing></bpmn:userTask></bpmn:process><bpmndi:BPMNDiagram id="BPMNDiagram_1"><bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_Parallel-Multiple-Instance-0001"><bpmndi:BPMNEdge id="Flow_0cwup88_di" bpmnElement="Flow_0cwup88"><di:waypoint x="215" y="117" /><di:waypoint x="270" y="117" /></bpmndi:BPMNEdge><bpmndi:BPMNEdge id="Flow_10688hr_di" bpmnElement="Flow_10688hr"><di:waypoint x="370" y="117" /><di:waypoint x="430" y="117" /></bpmndi:BPMNEdge><bpmndi:BPMNEdge id="Flow_0kw2ac2_di" bpmnElement="Flow_0kw2ac2"><di:waypoint x="530" y="117" /><di:waypoint x="590" y="117" /></bpmndi:BPMNEdge><bpmndi:BPMNEdge id="Flow_1qdyb0n_di" bpmnElement="Flow_1qdyb0n"><di:waypoint x="690" y="117" /><di:waypoint x="752" y="117" /></bpmndi:BPMNEdge><bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1"><dc:Bounds x="179" y="99" width="36" height="36" /><bpmndi:BPMNLabel><dc:Bounds x="186" y="142" width="23" height="14" /></bpmndi:BPMNLabel></bpmndi:BPMNShape><bpmndi:BPMNShape id="Activity_08yisz7_di" bpmnElement="Activity_04suznt"><dc:Bounds x="270" y="77" width="100" height="80" /></bpmndi:BPMNShape><bpmndi:BPMNShape id="Activity_0hve660_di" bpmnElement="Activity_huiqian0001"><dc:Bounds x="430" y="77" width="100" height="80" /></bpmndi:BPMNShape><bpmndi:BPMNShape id="Event_1sk7n99_di" bpmnElement="Event_1sk7n99"><dc:Bounds x="752" y="99" width="36" height="36" /><bpmndi:BPMNLabel><dc:Bounds x="759" y="142" width="23" height="14" /></bpmndi:BPMNLabel></bpmndi:BPMNShape><bpmndi:BPMNShape id="Activity_0hql8n4_di" bpmnElement="Activity_1k8djx2"><dc:Bounds x="590" y="77" width="100" height="80" /></bpmndi:BPMNShape></bpmndi:BPMNPlane></bpmndi:BPMNDiagram></bpmn:definitions>

当申请用户任务完成后,其会瞬间生成三个并行用户任务: user1,user2,user3每人一个。

这个时候,到数据库里面看看~

select ID_,NAME_, REV_, TASK_DEF_KEY_,ASSIGNEE_ , SUSPENSION_STATE_ from ACT_RU_TASK art where PROC_DEF_ID_ ='be0baf2c-d2ab-11ec-87de-005056c00008';

再执行

select ID_, REV_,ACT_ID_ , ACT_INST_ID_ , IS_ACTIVE_, BUSINESS_KEY_, IS_SCOPE_ ,SEQUENCE_COUNTER_,SUSPENSION_STATE_ from ACT_RU_EXECUTION where PROC_DEF_ID_ ='be0baf2c-d2ab-11ec-87de-005056c00008';

(1)User03 登录,审批通过一个,再看看数据库变化~

(2)User02 登录,审批通过一个,再看看数据库变化~

此时的历史表如下:

select ID_, ACT_ID_ ,ASSIGNEE_,ACT_NAME_ ,ACT_TYPE_ , ACT_INST_STATE_ ,SEQUENCE_COUNTER_ ,START_TIME_ ,END_TIME_ from ACT_HI_ACTINST where PROC_DEF_ID_ ='be0baf2c-d2ab-11ec-87de-005056c00008';

(3)User01 登录,审批通过一个,再看看数据库变化~

用户任务进入下一步了~

用户执行也进入下一步任务了

在看历史状态

(4)最后,把最后一步CEO审批通过,在看数据变化

select ID_,NAME_, REV_, TASK_DEF_KEY_,ASSIGNEE_ , SUSPENSION_STATE_ from ACT_RU_TASK art where PROC_DEF_ID_ =‘be0baf2c-d2ab-11ec-87de-005056c00008’;

运行中的任务执行结果为空

运行中的执行也为空

看看流程历史表里的数据:

至此,全部结束~

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。