Flowable
环境准备
下载flowableUI http://www.flowable.org/downloads.html
将Flowable发行包中,wars文件夹下的flowable-admin.war、flowable-idm.war、flowable-modeler.war与flowable-task.war文件,复制到Tomcat的webapps文件夹下。启动Tomcat http://localhost:8080/flowable-modeler
画一个简单的流程,用到的组件是空启动事件,用户任务,结束事件。用户任务找到属性 分配用户 写一个固定值张三。
依赖包
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-engine</artifactId>
<version>6.6.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.17</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
部署文件在flowableUI画图然后下载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">
<process id="test" name="test" isExecutable="true">
<startEvent id="startEvent1" flowable:formFieldValidation="true"></startEvent>
<endEvent id="sid-AE73931C-2613-4921-B261-B36F8BB44634"></endEvent>
<userTask id="sid-61FFEED3-15E6-48AE-8AEB-69DADA19FDEF" flowable:assignee="张三三" flowable:formFieldValidation="true">
<extensionElements>
<modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
</extensionElements>
</userTask>
<sequenceFlow id="sid-1233E313-7452-4387-9759-2945706CC53A" sourceRef="startEvent1" targetRef="sid-61FFEED3-15E6-48AE-8AEB-69DADA19FDEF"></sequenceFlow>
<sequenceFlow id="sid-9EB64796-FE9E-4EB8-B3E0-EE358480B3F3" sourceRef="sid-61FFEED3-15E6-48AE-8AEB-69DADA19FDEF" targetRef="sid-AE73931C-2613-4921-B261-B36F8BB44634"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_test">
<bpmndi:BPMNPlane bpmnElement="test" id="BPMNPlane_test">
<bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1">
<omgdc:Bounds height="30.0" width="30.0" x="150.0" y="120.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-AE73931C-2613-4921-B261-B36F8BB44634" id="BPMNShape_sid-AE73931C-2613-4921-B261-B36F8BB44634">
<omgdc:Bounds height="28.0" width="28.0" x="480.0" y="121.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-61FFEED3-15E6-48AE-8AEB-69DADA19FDEF" id="BPMNShape_sid-61FFEED3-15E6-48AE-8AEB-69DADA19FDEF">
<omgdc:Bounds height="80.0" width="100.0" x="281.41668016049545" y="95.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sid-1233E313-7452-4387-9759-2945706CC53A" id="BPMNEdge_sid-1233E313-7452-4387-9759-2945706CC53A">
<omgdi:waypoint x="179.94999934004048" y="135.0"></omgdi:waypoint>
<omgdi:waypoint x="281.41668016045776" y="135.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-9EB64796-FE9E-4EB8-B3E0-EE358480B3F3" id="BPMNEdge_sid-9EB64796-FE9E-4EB8-B3E0-EE358480B3F3">
<omgdi:waypoint x="381.36668016046605" y="135.0"></omgdi:waypoint>
<omgdi:waypoint x="480.0" y="135.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
部署流程
连接数据库(会产生很多系统业务表)返回ProcessEngine所有操作都依赖于这个对象
ProcessEngine processEngine; @BeforeEach public void before() { ProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration() .setJdbcUrl("jdbc:mysql://ip:3306/flowabledb?autoReconnect=true&useSSL=false&characterEncoding=utf-8&serverTimezone=Asia/Shanghai") .setJdbcUsername("root") .setJdbcPassword("123456") .setJdbcDriver("com.mysql.cj.jdbc.Driver") .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE); processEngine = cfg.buildProcessEngine(); }
部署流程需要流程描述的xml重要属性<process id="test">标记xml的唯一性如果ID相同则产生不同的version
@Test
public void deploy() {
RepositoryService repositoryService = processEngine.getRepositoryService();
Deployment deployment = repositoryService.createDeployment()
.addClasspathResource("static/test.bpmn20.xml")
.deploy();
Assert.assertNotNull(deployment);
}
创建流程实例
RuntimeService.startProcessInstanceByKey(str)传入已部署的流程的key。对应的是xml中<process id="key">创建流程实例会影响8张表。
这里转载一份flowable数据表的说明博客 https://www.cnblogs.com/xiohao/p/11446622.html
@Test
public void instances() {
RuntimeService runtimeService = processEngine.getRuntimeService();
runtimeService.startProcessInstanceByKey("test2");
}
查询用户任务
流程中有一个步骤是用户任务,用户任务是flowable的核心功能。每一个流程实例从任务开始沿顺序流(线)往前走,在用户任务步骤处停顿,直到该任务的执行人执行了该任务,流程才会继续往下走。在上边这个简单的流程里用户任务是分配给 张三三 这个用户的。虽然这里声明了 张三三 是一个用户实际上flowable并没有帮我们维护用户,只是该任务的完成人是 张三三。
查询的表是 select distinct RES.* from ACT_RU_TASK RES WHERE RES.ASSIGNEE_ = '张三三' order by RES.ID_ asc
@Test public void queryTask() { TaskService taskService = processEngine.getTaskService(); TaskQuery taskQuery = taskService.createTaskQuery(); List<Task> tasks = taskQuery.taskAssignee("张三三").list(); Assert.assertNotNull(tasks); }
用户执行任务
通过任务id(任务ID从数据库中查询)完成该任务,参数是ACT_RU_TASK表中的id,任务一旦完成会删除ACT_RU_TASK行记录并更改ACT_HI_TASKINST行记录。
@Test public void completeTask(){ TaskService taskService = processEngine.getTaskService(); taskService.complete("20006"); }
启动事件-空启动事件-执行监听器
空启动事件是启动事件的一种,它有两个执行监听器分别是start,end。分别代表开始结束。
<?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"> <process id="test1" name="test1" isExecutable="true"> <startEvent id="startEvent1" flowable:formFieldValidation="true"> <extensionElements> <flowable:executionListener event="start" class="com.datang.qqboark.listener.StartListenerStep1"></flowable:executionListener> <flowable:executionListener event="end" class="com.datang.qqboark.listener.EndListenerStep1"></flowable:executionListener> </extensionElements> </startEvent> <userTask id="sid-FDE59E3A-E8F6-4FD1-B9E0-A466C8D4E2DA" flowable:assignee="张三" flowable:formFieldValidation="true"> <extensionElements> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> </userTask> <endEvent id="sid-B7589522-0B7B-4786-88F8-11D0418EBAED"> <extensionElements> </extensionElements> </endEvent> <sequenceFlow id="sid-C53AC5AF-40EA-4C28-83A8-291D17337E66" sourceRef="startEvent1" targetRef="sid-FDE59E3A-E8F6-4FD1-B9E0-A466C8D4E2DA"></sequenceFlow> <sequenceFlow id="sid-38F74A2C-051D-4A29-91C2-190C6AA77B8E" sourceRef="sid-FDE59E3A-E8F6-4FD1-B9E0-A466C8D4E2DA" targetRef="sid-B7589522-0B7B-4786-88F8-11D0418EBAED"></sequenceFlow> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_test1"> <bpmndi:BPMNPlane bpmnElement="test1" id="BPMNPlane_test1"> <bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1"> <omgdc:Bounds height="30.0" width="30.0" x="90.0" y="150.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-FDE59E3A-E8F6-4FD1-B9E0-A466C8D4E2DA" id="BPMNShape_sid-FDE59E3A-E8F6-4FD1-B9E0-A466C8D4E2DA"> <omgdc:Bounds height="80.0" width="100.0" x="240.0" y="125.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-B7589522-0B7B-4786-88F8-11D0418EBAED" id="BPMNShape_sid-B7589522-0B7B-4786-88F8-11D0418EBAED"> <omgdc:Bounds height="28.0" width="28.0" x="435.0" y="151.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNEdge bpmnElement="sid-C53AC5AF-40EA-4C28-83A8-291D17337E66" id="BPMNEdge_sid-C53AC5AF-40EA-4C28-83A8-291D17337E66"> <omgdi:waypoint x="119.94999946593475" y="165.0"></omgdi:waypoint> <omgdi:waypoint x="240.0" y="165.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-38F74A2C-051D-4A29-91C2-190C6AA77B8E" id="BPMNEdge_sid-38F74A2C-051D-4A29-91C2-190C6AA77B8E"> <omgdi:waypoint x="339.95000000000005" y="165.0"></omgdi:waypoint> <omgdi:waypoint x="435.0" y="165.0"></omgdi:waypoint> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>
package com.datang.qqboark.listener; import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.ExecutionListener; /** * @author 顶风少年 * @date 2022/2/28 */ public class EndListenerStep1 implements ExecutionListener { @Override public void notify(DelegateExecution delegateExecution) { System.out.println("step1-end---------------------"); } }
package com.datang.qqboark.listener; import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.ExecutionListener; /** * @author 顶风少年 * @date 2022/2/28 */ public class StartListenerStep1 implements ExecutionListener { @Override public void notify(DelegateExecution delegateExecution) { System.out.println("step1-start---------------------"); } }
活动-用户任务-执行监听器
用户任务是活动的一种,它有两个执行监听器分别是start,end。分别代表开始结束。
<?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"> <process id="test1" name="test1" isExecutable="true"> <startEvent id="startEvent1" flowable:formFieldValidation="true"> <extensionElements> </extensionElements> </startEvent> <userTask id="sid-FDE59E3A-E8F6-4FD1-B9E0-A466C8D4E2DA" flowable:assignee="张三" flowable:formFieldValidation="true"> <extensionElements> <flowable:executionListener event="start" class="com.datang.qqboark.listener.StartListenerStep2"></flowable:executionListener> <flowable:executionListener event="end" class="com.datang.qqboark.listener.EndListenerStep2"></flowable:executionListener> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> </userTask> <endEvent id="sid-B7589522-0B7B-4786-88F8-11D0418EBAED"> <extensionElements> </extensionElements> </endEvent> <sequenceFlow id="sid-C53AC5AF-40EA-4C28-83A8-291D17337E66" sourceRef="startEvent1" targetRef="sid-FDE59E3A-E8F6-4FD1-B9E0-A466C8D4E2DA"></sequenceFlow> <sequenceFlow id="sid-38F74A2C-051D-4A29-91C2-190C6AA77B8E" sourceRef="sid-FDE59E3A-E8F6-4FD1-B9E0-A466C8D4E2DA" targetRef="sid-B7589522-0B7B-4786-88F8-11D0418EBAED"></sequenceFlow> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_test1"> <bpmndi:BPMNPlane bpmnElement="test1" id="BPMNPlane_test1"> <bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1"> <omgdc:Bounds height="30.0" width="30.0" x="90.0" y="150.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-FDE59E3A-E8F6-4FD1-B9E0-A466C8D4E2DA" id="BPMNShape_sid-FDE59E3A-E8F6-4FD1-B9E0-A466C8D4E2DA"> <omgdc:Bounds height="80.0" width="100.0" x="240.0" y="125.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-B7589522-0B7B-4786-88F8-11D0418EBAED" id="BPMNShape_sid-B7589522-0B7B-4786-88F8-11D0418EBAED"> <omgdc:Bounds height="28.0" width="28.0" x="435.0" y="151.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNEdge bpmnElement="sid-C53AC5AF-40EA-4C28-83A8-291D17337E66" id="BPMNEdge_sid-C53AC5AF-40EA-4C28-83A8-291D17337E66"> <omgdi:waypoint x="119.94999946593475" y="165.0"></omgdi:waypoint> <omgdi:waypoint x="240.0" y="165.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-38F74A2C-051D-4A29-91C2-190C6AA77B8E" id="BPMNEdge_sid-38F74A2C-051D-4A29-91C2-190C6AA77B8E"> <omgdi:waypoint x="339.95000000000005" y="165.0"></omgdi:waypoint> <omgdi:waypoint x="435.0" y="165.0"></omgdi:waypoint> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>
package com.datang.qqboark.listener; import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.ExecutionListener; /** * @author 顶风少年 * @date 2022/2/28 */ public class EndListenerStep2 implements ExecutionListener { @Override public void notify(DelegateExecution delegateExecution) { System.out.println("step2-end---------------------"); } }
package com.datang.qqboark.listener; import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.ExecutionListener; /** * @author 顶风少年 * @date 2022/2/28 */ public class StartListenerStep2 implements ExecutionListener { @Override public void notify(DelegateExecution delegateExecution) { System.out.println("step2-start---------------------"); } }
活动-用户任务-任务监听器
用户活动有4种任务监听器顺序分别为assignment(指派),create(创建),complete(完成),delete(删除)。注意assignment在create之前执行。如果任务没有指派用户则assignment监听器不会启动。
<?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"> <process id="test1" name="test1" isExecutable="true"> <startEvent id="startEvent1" flowable:formFieldValidation="true"> <extensionElements> </extensionElements> </startEvent> <userTask id="sid-FDE59E3A-E8F6-4FD1-B9E0-A466C8D4E2DA" flowable:assignee="张三" flowable:formFieldValidation="true"> <extensionElements> <flowable:taskListener event="assignment" class="com.datang.qqboark.listener.AssignmentListenerStep2"></flowable:taskListener> <flowable:taskListener event="complete" class="com.datang.qqboark.listener.CompleteListenerStep2"></flowable:taskListener> <flowable:taskListener event="delete" class="com.datang.qqboark.listener.DeleteListenerStep2"></flowable:taskListener> <flowable:taskListener event="create" class="com.datang.qqboark.listener.CreateListenerStep2"></flowable:taskListener> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> </userTask> <endEvent id="sid-B7589522-0B7B-4786-88F8-11D0418EBAED"> <extensionElements> </extensionElements> </endEvent> <sequenceFlow id="sid-C53AC5AF-40EA-4C28-83A8-291D17337E66" sourceRef="startEvent1" targetRef="sid-FDE59E3A-E8F6-4FD1-B9E0-A466C8D4E2DA"></sequenceFlow> <sequenceFlow id="sid-38F74A2C-051D-4A29-91C2-190C6AA77B8E" sourceRef="sid-FDE59E3A-E8F6-4FD1-B9E0-A466C8D4E2DA" targetRef="sid-B7589522-0B7B-4786-88F8-11D0418EBAED"></sequenceFlow> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_test1"> <bpmndi:BPMNPlane bpmnElement="test1" id="BPMNPlane_test1"> <bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1"> <omgdc:Bounds height="30.0" width="30.0" x="90.0" y="150.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-FDE59E3A-E8F6-4FD1-B9E0-A466C8D4E2DA" id="BPMNShape_sid-FDE59E3A-E8F6-4FD1-B9E0-A466C8D4E2DA"> <omgdc:Bounds height="80.0" width="100.0" x="240.0" y="125.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-B7589522-0B7B-4786-88F8-11D0418EBAED" id="BPMNShape_sid-B7589522-0B7B-4786-88F8-11D0418EBAED"> <omgdc:Bounds height="28.0" width="28.0" x="435.0" y="151.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNEdge bpmnElement="sid-C53AC5AF-40EA-4C28-83A8-291D17337E66" id="BPMNEdge_sid-C53AC5AF-40EA-4C28-83A8-291D17337E66"> <omgdi:waypoint x="119.94999946593475" y="165.0"></omgdi:waypoint> <omgdi:waypoint x="240.0" y="165.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-38F74A2C-051D-4A29-91C2-190C6AA77B8E" id="BPMNEdge_sid-38F74A2C-051D-4A29-91C2-190C6AA77B8E"> <omgdi:waypoint x="339.95000000000005" y="165.0"></omgdi:waypoint> <omgdi:waypoint x="435.0" y="165.0"></omgdi:waypoint> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>
package com.datang.qqboark.listener; import org.flowable.task.service.delegate.DelegateTask; import org.flowable.task.service.delegate.TaskListener; /** * @author 顶风少年 * @date 2022/2/28 */ public class AssignmentListenerStep2 implements TaskListener { @Override public void notify(DelegateTask delegateTask) { System.out.println("step2-assignment2---------------------"); } }
package com.datang.qqboark.listener; import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.ExecutionListener; import org.flowable.task.service.delegate.DelegateTask; import org.flowable.task.service.delegate.TaskListener; /** * @author 顶风少年 * @date 2022/2/28 */ public class CompleteListenerStep2 implements TaskListener { @Override public void notify(DelegateTask delegateTask) { System.out.println("step2-complete2---------------------"); } }
package com.datang.qqboark.listener; import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.ExecutionListener; import org.flowable.task.service.delegate.DelegateTask; import org.flowable.task.service.delegate.TaskListener; /** * @author 顶风少年 * @date 2022/2/28 */ public class CreateListenerStep2 implements TaskListener { @Override public void notify(DelegateTask delegateTask) { System.out.println("step2-create2---------------------"); } }
package com.datang.qqboark.listener; import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.ExecutionListener; import org.flowable.task.service.delegate.DelegateTask; import org.flowable.task.service.delegate.TaskListener; /** * @author 顶风少年 * @date 2022/2/28 */ public class DeleteListenerStep2 implements TaskListener { @Override public void notify(DelegateTask delegateTask) { System.out.println("step2-delete2---------------------"); } }
结束事件-结束事件-执行监听器
结束任务是结束任务的一种,它有两个执行监听器分别是start,end。分别代表开始结束。
<?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"> <process id="test1" name="test1" isExecutable="true"> <startEvent id="startEvent1" flowable:formFieldValidation="true"> <extensionElements> </extensionElements> </startEvent> <userTask id="sid-FDE59E3A-E8F6-4FD1-B9E0-A466C8D4E2DA" flowable:assignee="张三" flowable:formFieldValidation="true"> <extensionElements> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"> <![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> </userTask> <endEvent id="sid-B7589522-0B7B-4786-88F8-11D0418EBAED"> <extensionElements> <flowable:executionListener event="start" class="com.datang.qqboark.listener.StartListenerStep3"></flowable:executionListener> <flowable:executionListener event="end" class="com.datang.qqboark.listener.EndListenerStep3"></flowable:executionListener> </extensionElements> </endEvent> <sequenceFlow id="sid-C53AC5AF-40EA-4C28-83A8-291D17337E66" sourceRef="startEvent1" targetRef="sid-FDE59E3A-E8F6-4FD1-B9E0-A466C8D4E2DA"></sequenceFlow> <sequenceFlow id="sid-38F74A2C-051D-4A29-91C2-190C6AA77B8E" sourceRef="sid-FDE59E3A-E8F6-4FD1-B9E0-A466C8D4E2DA" targetRef="sid-B7589522-0B7B-4786-88F8-11D0418EBAED"></sequenceFlow> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_test1"> <bpmndi:BPMNPlane bpmnElement="test1" id="BPMNPlane_test1"> <bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1"> <omgdc:Bounds height="30.0" width="30.0" x="90.0" y="150.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-FDE59E3A-E8F6-4FD1-B9E0-A466C8D4E2DA" id="BPMNShape_sid-FDE59E3A-E8F6-4FD1-B9E0-A466C8D4E2DA"> <omgdc:Bounds height="80.0" width="100.0" x="240.0" y="125.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-B7589522-0B7B-4786-88F8-11D0418EBAED" id="BPMNShape_sid-B7589522-0B7B-4786-88F8-11D0418EBAED"> <omgdc:Bounds height="28.0" width="28.0" x="435.0" y="151.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNEdge bpmnElement="sid-C53AC5AF-40EA-4C28-83A8-291D17337E66" id="BPMNEdge_sid-C53AC5AF-40EA-4C28-83A8-291D17337E66"> <omgdi:waypoint x="119.94999946593475" y="165.0"></omgdi:waypoint> <omgdi:waypoint x="240.0" y="165.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-38F74A2C-051D-4A29-91C2-190C6AA77B8E" id="BPMNEdge_sid-38F74A2C-051D-4A29-91C2-190C6AA77B8E"> <omgdi:waypoint x="339.95000000000005" y="165.0"></omgdi:waypoint> <omgdi:waypoint x="435.0" y="165.0"></omgdi:waypoint> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>
package com.datang.qqboark.listener; import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.ExecutionListener; /** * @author 顶风少年 * @date 2022/2/28 */ public class EndListenerStep3 implements ExecutionListener { @Override public void notify(DelegateExecution delegateExecution) { System.out.println("step3-end---------------------"); } }
package com.datang.qqboark.listener; import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.ExecutionListener; /** * @author 顶风少年 * @date 2022/2/28 */ public class StartListenerStep3 implements ExecutionListener { @Override public void notify(DelegateExecution delegateExecution) { System.out.println("step3-start---------------------"); } }
流程执行-执行监听器
执行流程就是在步骤之间的线条,有三种执行监听器start,tack(转移到下个步骤),end。
<?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"> <process id="test1" name="test1" isExecutable="true"> <startEvent id="startEvent1" flowable:formFieldValidation="true"></startEvent> <userTask id="sid-FDE59E3A-E8F6-4FD1-B9E0-A466C8D4E2DA" flowable:assignee="张三" flowable:formFieldValidation="true"> <extensionElements> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> </userTask> <endEvent id="sid-B7589522-0B7B-4786-88F8-11D0418EBAED"></endEvent> <sequenceFlow id="sid-38F74A2C-051D-4A29-91C2-190C6AA77B8E" sourceRef="sid-FDE59E3A-E8F6-4FD1-B9E0-A466C8D4E2DA" targetRef="sid-B7589522-0B7B-4786-88F8-11D0418EBAED"></sequenceFlow> <sequenceFlow id="sid-C53AC5AF-40EA-4C28-83A8-291D17337E66" sourceRef="startEvent1" targetRef="sid-FDE59E3A-E8F6-4FD1-B9E0-A466C8D4E2DA"> <extensionElements> <flowable:executionListener event="start" class="com.datang.qqboark.listener.StartSequenceFlow1"></flowable:executionListener> <flowable:executionListener event="end" class="com.datang.qqboark.listener.EndSequenceFlow1"></flowable:executionListener> <flowable:executionListener event="take" class="com.datang.qqboark.listener.TakeSequenceFlow1"></flowable:executionListener> </extensionElements> </sequenceFlow> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_test1"> <bpmndi:BPMNPlane bpmnElement="test1" id="BPMNPlane_test1"> <bpmndi:BPMNShape bpmnElement="startEvent1" id="BPMNShape_startEvent1"> <omgdc:Bounds height="30.0" width="30.0" x="90.0" y="150.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-FDE59E3A-E8F6-4FD1-B9E0-A466C8D4E2DA" id="BPMNShape_sid-FDE59E3A-E8F6-4FD1-B9E0-A466C8D4E2DA"> <omgdc:Bounds height="80.0" width="100.0" x="240.0" y="125.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-B7589522-0B7B-4786-88F8-11D0418EBAED" id="BPMNShape_sid-B7589522-0B7B-4786-88F8-11D0418EBAED"> <omgdc:Bounds height="28.0" width="28.0" x="435.0" y="151.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNEdge bpmnElement="sid-C53AC5AF-40EA-4C28-83A8-291D17337E66" id="BPMNEdge_sid-C53AC5AF-40EA-4C28-83A8-291D17337E66"> <omgdi:waypoint x="119.94999946593475" y="165.0"></omgdi:waypoint> <omgdi:waypoint x="240.0" y="165.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-38F74A2C-051D-4A29-91C2-190C6AA77B8E" id="BPMNEdge_sid-38F74A2C-051D-4A29-91C2-190C6AA77B8E"> <omgdi:waypoint x="339.95000000000005" y="165.0"></omgdi:waypoint> <omgdi:waypoint x="435.0" y="165.0"></omgdi:waypoint> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>
package com.datang.qqboark.listener; import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.ExecutionListener; /** * @author 顶风少年 * @date 2022/3/1 */ public class StartSequenceFlow1 implements ExecutionListener { @Override public void notify(DelegateExecution execution) { System.out.println("StartSequenceFlow1---------------------------"); } }
package com.datang.qqboark.listener; import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.ExecutionListener; /** * @author 顶风少年 * @date 2022/3/1 */ public class TakeSequenceFlow1 implements ExecutionListener { @Override public void notify(DelegateExecution execution) { System.out.println("TakeSequenceFlow1---------------------------"); } }
package com.datang.qqboark.listener; import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.ExecutionListener; /** * @author 顶风少年 * @date 2022/3/1 */ public class EndSequenceFlow1 implements ExecutionListener { @Override public void notify(DelegateExecution execution) { System.out.println("EndSequenceFlow1---------------------------"); } }
条件顺序流
流程实例启动后设置name为病假则任务交由张三处理,设置成婚假则是李四处理。
<?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"> <process id="test1" name="test1" isExecutable="true"> <endEvent id="sid-B7589522-0B7B-4786-88F8-11D0418EBAED"></endEvent> <startEvent id="sid-671720BC-24F3-46F8-B485-20A33C8790C1" flowable:formFieldValidation="true"> <extensionElements> <flowable:executionListener event="start" class="com.datang.qqboark.listener.StartListener"></flowable:executionListener> </extensionElements> </startEvent> <userTask id="sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA" flowable:assignee="张三" flowable:formFieldValidation="true"> <extensionElements> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"> <![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> </userTask> <userTask id="sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7" flowable:assignee="李四" flowable:formFieldValidation="true"> <extensionElements> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"> <![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> </userTask> <sequenceFlow id="sid-03112A9C-B57D-4F6F-8143-4B02F0258EC9" sourceRef="sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA" targetRef="sid-B7589522-0B7B-4786-88F8-11D0418EBAED"></sequenceFlow> <sequenceFlow id="sid-1E7A95B5-EB07-427A-ADD9-A9F15208F8AC" sourceRef="sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7" targetRef="sid-B7589522-0B7B-4786-88F8-11D0418EBAED"></sequenceFlow> <sequenceFlow id="sid-1ACB9184-D272-4297-9A32-84CB8C86C969" sourceRef="sid-671720BC-24F3-46F8-B485-20A33C8790C1" targetRef="sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${name=='婚假'}]]></conditionExpression> </sequenceFlow> <sequenceFlow id="sid-8A717A65-0012-4E81-A1CA-71F0DA1DB3F4" sourceRef="sid-671720BC-24F3-46F8-B485-20A33C8790C1" targetRef="sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${name=='病假'}]]></conditionExpression> </sequenceFlow> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_test1"> <bpmndi:BPMNPlane bpmnElement="test1" id="BPMNPlane_test1"> <bpmndi:BPMNShape bpmnElement="sid-B7589522-0B7B-4786-88F8-11D0418EBAED" id="BPMNShape_sid-B7589522-0B7B-4786-88F8-11D0418EBAED"> <omgdc:Bounds height="28.0" width="28.0" x="435.0" y="167.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-671720BC-24F3-46F8-B485-20A33C8790C1" id="BPMNShape_sid-671720BC-24F3-46F8-B485-20A33C8790C1"> <omgdc:Bounds height="30.0" width="30.0" x="150.0" y="166.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA" id="BPMNShape_sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA"> <omgdc:Bounds height="80.0" width="100.0" x="270.0" y="90.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7" id="BPMNShape_sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7"> <omgdc:Bounds height="80.0" width="100.0" x="270.0" y="195.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNEdge bpmnElement="sid-1ACB9184-D272-4297-9A32-84CB8C86C969" id="BPMNEdge_sid-1ACB9184-D272-4297-9A32-84CB8C86C969"> <omgdi:waypoint x="179.12069239952643" y="185.91978825027397"></omgdi:waypoint> <omgdi:waypoint x="270.0" y="217.58064516129033"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-1E7A95B5-EB07-427A-ADD9-A9F15208F8AC" id="BPMNEdge_sid-1E7A95B5-EB07-427A-ADD9-A9F15208F8AC"> <omgdi:waypoint x="369.95000000000005" y="214.06976744186045"></omgdi:waypoint> <omgdi:waypoint x="436.08246713374206" y="186.3880274132089"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-03112A9C-B57D-4F6F-8143-4B02F0258EC9" id="BPMNEdge_sid-03112A9C-B57D-4F6F-8143-4B02F0258EC9"> <omgdi:waypoint x="369.95" y="149.74767441860467"></omgdi:waypoint> <omgdi:waypoint x="435.9677973382153" y="175.85140054967482"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-8A717A65-0012-4E81-A1CA-71F0DA1DB3F4" id="BPMNEdge_sid-8A717A65-0012-4E81-A1CA-71F0DA1DB3F4"> <omgdi:waypoint x="179.20487632490386" y="176.3105058967236"></omgdi:waypoint> <omgdi:waypoint x="270.0" y="146.43516129032258"></omgdi:waypoint> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>
@Test public void instances() { RuntimeService runtimeService = processEngine.getRuntimeService(); ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("test1"); }
package com.datang.qqboark.listener; import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.ExecutionListener; /** * @author 顶风少年 * @date 2022/2/28 */ public class StartListener implements ExecutionListener { @Override public void notify(DelegateExecution delegateExecution) { delegateExecution.setVariable("name","病假"); } }
默认顺序流
比上个流程多一个默认的流,设置name为丧假则流向王五。
<?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"> <process id="test1" name="test1" isExecutable="true"> <endEvent id="sid-B7589522-0B7B-4786-88F8-11D0418EBAED"></endEvent> <startEvent id="sid-671720BC-24F3-46F8-B485-20A33C8790C1" flowable:formFieldValidation="true"> <extensionElements> <flowable:executionListener event="start" class="com.datang.qqboark.listener.StartListener"></flowable:executionListener> </extensionElements> </startEvent> <userTask id="sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA" flowable:assignee="张三" flowable:formFieldValidation="true"> <extensionElements> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"> <![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> </userTask> <userTask id="sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7" flowable:assignee="李四" flowable:formFieldValidation="true"> <extensionElements> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"> <![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> </userTask> <sequenceFlow id="sid-03112A9C-B57D-4F6F-8143-4B02F0258EC9" sourceRef="sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA" targetRef="sid-B7589522-0B7B-4786-88F8-11D0418EBAED"></sequenceFlow> <sequenceFlow id="sid-1E7A95B5-EB07-427A-ADD9-A9F15208F8AC" sourceRef="sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7" targetRef="sid-B7589522-0B7B-4786-88F8-11D0418EBAED"></sequenceFlow> <sequenceFlow id="sid-8A717A65-0012-4E81-A1CA-71F0DA1DB3F4" sourceRef="sid-671720BC-24F3-46F8-B485-20A33C8790C1" targetRef="sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${name=='病假'}]]></conditionExpression> </sequenceFlow> <sequenceFlow id="sid-1ACB9184-D272-4297-9A32-84CB8C86C969" sourceRef="sid-671720BC-24F3-46F8-B485-20A33C8790C1" targetRef="sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${name=='婚假'}]]></conditionExpression> </sequenceFlow> <userTask id="sid-46859086-D8D6-4E3F-A2FA-5D2242903E3E" flowable:assignee="王五" flowable:formFieldValidation="true"> <extensionElements> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"> <![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> </userTask> <sequenceFlow id="sid-72417965-8FDC-45ED-86E7-B7B52488C779" sourceRef="sid-671720BC-24F3-46F8-B485-20A33C8790C1" targetRef="sid-46859086-D8D6-4E3F-A2FA-5D2242903E3E"></sequenceFlow> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_test1"> <bpmndi:BPMNPlane bpmnElement="test1" id="BPMNPlane_test1"> <bpmndi:BPMNShape bpmnElement="sid-B7589522-0B7B-4786-88F8-11D0418EBAED" id="BPMNShape_sid-B7589522-0B7B-4786-88F8-11D0418EBAED"> <omgdc:Bounds height="28.0" width="28.0" x="435.0" y="167.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-671720BC-24F3-46F8-B485-20A33C8790C1" id="BPMNShape_sid-671720BC-24F3-46F8-B485-20A33C8790C1"> <omgdc:Bounds height="30.0" width="30.0" x="150.0" y="166.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA" id="BPMNShape_sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA"> <omgdc:Bounds height="80.0" width="100.0" x="270.0" y="90.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7" id="BPMNShape_sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7"> <omgdc:Bounds height="80.0" width="100.0" x="270.0" y="300.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-46859086-D8D6-4E3F-A2FA-5D2242903E3E" id="BPMNShape_sid-46859086-D8D6-4E3F-A2FA-5D2242903E3E"> <omgdc:Bounds height="80.0" width="100.0" x="270.0" y="195.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNEdge bpmnElement="sid-1ACB9184-D272-4297-9A32-84CB8C86C969" id="BPMNEdge_sid-1ACB9184-D272-4297-9A32-84CB8C86C969"> <omgdi:waypoint x="175.43573938023428" y="191.70500648102572"></omgdi:waypoint> <omgdi:waypoint x="281.00628930817606" y="300.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-72417965-8FDC-45ED-86E7-B7B52488C779" id="BPMNEdge_sid-72417965-8FDC-45ED-86E7-B7B52488C779"> <omgdi:waypoint x="179.12069239952643" y="185.91978825027397"></omgdi:waypoint> <omgdi:waypoint x="270.0" y="217.58064516129033"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-1E7A95B5-EB07-427A-ADD9-A9F15208F8AC" id="BPMNEdge_sid-1E7A95B5-EB07-427A-ADD9-A9F15208F8AC"> <omgdi:waypoint x="352.4122641509434" y="300.0"></omgdi:waypoint> <omgdi:waypoint x="440.1791423256009" y="191.83339056746553"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-03112A9C-B57D-4F6F-8143-4B02F0258EC9" id="BPMNEdge_sid-03112A9C-B57D-4F6F-8143-4B02F0258EC9"> <omgdi:waypoint x="369.95" y="149.74767441860467"></omgdi:waypoint> <omgdi:waypoint x="435.9677973382153" y="175.85140054967482"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-8A717A65-0012-4E81-A1CA-71F0DA1DB3F4" id="BPMNEdge_sid-8A717A65-0012-4E81-A1CA-71F0DA1DB3F4"> <omgdi:waypoint x="179.20487632490386" y="176.3105058967236"></omgdi:waypoint> <omgdi:waypoint x="270.0" y="146.43516129032258"></omgdi:waypoint> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>
package com.datang.qqboark.listener; import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.ExecutionListener; /** * @author 顶风少年 * @date 2022/2/28 */ public class StartListener implements ExecutionListener { @Override public void notify(DelegateExecution delegateExecution) { delegateExecution.setVariable("name","丧假"); } }
满足多个流条件
流1若flag1为true则发布任务给张三,流2若flag2为true则发布任务给李四,流3若flag3为true则发布任务给王五。在监听器中设置flag1,flag2为true,flag3为false。可以看到多个条件满足时会流向多条线路。
<?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"> <process id="test1" name="test1" isExecutable="true"> <endEvent id="sid-B7589522-0B7B-4786-88F8-11D0418EBAED"></endEvent> <startEvent id="sid-671720BC-24F3-46F8-B485-20A33C8790C1" flowable:formFieldValidation="true"> <extensionElements> <flowable:executionListener event="start" class="com.datang.qqboark.listener.StartListener"></flowable:executionListener> </extensionElements> </startEvent> <userTask id="sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA" flowable:assignee="张三" flowable:formFieldValidation="true"> <extensionElements> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> </userTask> <userTask id="sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7" flowable:assignee="李四" flowable:formFieldValidation="true"> <extensionElements> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> </userTask> <sequenceFlow id="sid-03112A9C-B57D-4F6F-8143-4B02F0258EC9" sourceRef="sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA" targetRef="sid-B7589522-0B7B-4786-88F8-11D0418EBAED"></sequenceFlow> <sequenceFlow id="sid-1E7A95B5-EB07-427A-ADD9-A9F15208F8AC" sourceRef="sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7" targetRef="sid-B7589522-0B7B-4786-88F8-11D0418EBAED"></sequenceFlow> <userTask id="sid-6245BCCB-0A1B-4AA3-8E37-560D2B3F7E7C" flowable:assignee="王五" flowable:formFieldValidation="true"> <extensionElements> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> </userTask> <sequenceFlow id="sid-8A717A65-0012-4E81-A1CA-71F0DA1DB3F4" sourceRef="sid-671720BC-24F3-46F8-B485-20A33C8790C1" targetRef="sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${flag1}]]></conditionExpression> </sequenceFlow> <sequenceFlow id="sid-E3CC1963-3F15-41CF-AC6F-C7621D01CF89" sourceRef="sid-671720BC-24F3-46F8-B485-20A33C8790C1" targetRef="sid-6245BCCB-0A1B-4AA3-8E37-560D2B3F7E7C"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${flag3}]]></conditionExpression> </sequenceFlow> <sequenceFlow id="sid-1ACB9184-D272-4297-9A32-84CB8C86C969" sourceRef="sid-671720BC-24F3-46F8-B485-20A33C8790C1" targetRef="sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${flag2}]]></conditionExpression> </sequenceFlow> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_test1"> <bpmndi:BPMNPlane bpmnElement="test1" id="BPMNPlane_test1"> <bpmndi:BPMNShape bpmnElement="sid-B7589522-0B7B-4786-88F8-11D0418EBAED" id="BPMNShape_sid-B7589522-0B7B-4786-88F8-11D0418EBAED"> <omgdc:Bounds height="28.0" width="28.0" x="435.0" y="167.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-671720BC-24F3-46F8-B485-20A33C8790C1" id="BPMNShape_sid-671720BC-24F3-46F8-B485-20A33C8790C1"> <omgdc:Bounds height="30.0" width="30.0" x="150.0" y="166.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA" id="BPMNShape_sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA"> <omgdc:Bounds height="80.0" width="100.0" x="270.0" y="90.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7" id="BPMNShape_sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7"> <omgdc:Bounds height="80.0" width="100.0" x="270.0" y="210.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-6245BCCB-0A1B-4AA3-8E37-560D2B3F7E7C" id="BPMNShape_sid-6245BCCB-0A1B-4AA3-8E37-560D2B3F7E7C"> <omgdc:Bounds height="80.0" width="100.0" x="270.0" y="316.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNEdge bpmnElement="sid-E3CC1963-3F15-41CF-AC6F-C7621D01CF89" id="BPMNEdge_sid-E3CC1963-3F15-41CF-AC6F-C7621D01CF89"> <omgdi:waypoint x="174.91248883962206" y="192.19133827354838"></omgdi:waypoint> <omgdi:waypoint x="284.57142857142856" y="316.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-1ACB9184-D272-4297-9A32-84CB8C86C969" id="BPMNEdge_sid-1ACB9184-D272-4297-9A32-84CB8C86C969"> <omgdi:waypoint x="178.66033919253852" y="187.08145904953523"></omgdi:waypoint> <omgdi:waypoint x="270.0" y="227.74193548387098"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-1E7A95B5-EB07-427A-ADD9-A9F15208F8AC" id="BPMNEdge_sid-1E7A95B5-EB07-427A-ADD9-A9F15208F8AC"> <omgdi:waypoint x="369.95000000000005" y="223.25581395348837"></omgdi:waypoint> <omgdi:waypoint x="436.652595815618" y="187.58083826013137"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-03112A9C-B57D-4F6F-8143-4B02F0258EC9" id="BPMNEdge_sid-03112A9C-B57D-4F6F-8143-4B02F0258EC9"> <omgdi:waypoint x="369.95" y="149.74767441860467"></omgdi:waypoint> <omgdi:waypoint x="435.9677973382153" y="175.85140054967482"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-8A717A65-0012-4E81-A1CA-71F0DA1DB3F4" id="BPMNEdge_sid-8A717A65-0012-4E81-A1CA-71F0DA1DB3F4"> <omgdi:waypoint x="179.20487632490386" y="176.3105058967236"></omgdi:waypoint> <omgdi:waypoint x="270.0" y="146.43516129032258"></omgdi:waypoint> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>
package com.datang.qqboark.listener; import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.ExecutionListener; /** * @author 顶风少年 * @date 2022/2/28 */ public class StartListener implements ExecutionListener { @Override public void notify(DelegateExecution delegateExecution) { delegateExecution.setVariable("flag1", true); delegateExecution.setVariable("flag2", true); delegateExecution.setVariable("flag3", false); } }
排他网关
排他网关不需要额外的设置,它判断出流向的条件选择一条为true的流如果有多个则只会选择最先定义。下边的demo流1和流2都为true但只选择了最先定义的李四。
<?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"> <process id="test1" name="test1" isExecutable="true"> <startEvent id="sid-671720BC-24F3-46F8-B485-20A33C8790C1" flowable:formFieldValidation="true"> <extensionElements> <flowable:executionListener event="start" class="com.datang.qqboark.listener.StartListener"></flowable:executionListener> </extensionElements> </startEvent> <userTask id="sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7" flowable:assignee="李四" flowable:formFieldValidation="true"> <extensionElements> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> </userTask> <userTask id="sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA" flowable:assignee="张三" flowable:formFieldValidation="true"> <extensionElements> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> </userTask> <userTask id="sid-6245BCCB-0A1B-4AA3-8E37-560D2B3F7E7C" flowable:assignee="王五" flowable:formFieldValidation="true"> <extensionElements> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> </userTask> <exclusiveGateway id="sid-00BCCAF3-33E1-47F0-A5E3-8DD2111EB811"></exclusiveGateway> <endEvent id="sid-AFD10B32-F844-4F33-A370-D8D57DD2BA6F"></endEvent> <sequenceFlow id="sid-B2DC5D9D-9882-45B9-AE09-1EAD67D32113" sourceRef="sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA" targetRef="sid-AFD10B32-F844-4F33-A370-D8D57DD2BA6F"></sequenceFlow> <sequenceFlow id="sid-1BE338B7-783D-4882-9755-EADB1159522F" sourceRef="sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7" targetRef="sid-AFD10B32-F844-4F33-A370-D8D57DD2BA6F"></sequenceFlow> <sequenceFlow id="sid-16008AF9-33DC-4494-89E4-DFD8F9EE097F" sourceRef="sid-6245BCCB-0A1B-4AA3-8E37-560D2B3F7E7C" targetRef="sid-AFD10B32-F844-4F33-A370-D8D57DD2BA6F"></sequenceFlow> <sequenceFlow id="sid-1ACB9184-D272-4297-9A32-84CB8C86C969" sourceRef="sid-00BCCAF3-33E1-47F0-A5E3-8DD2111EB811" targetRef="sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${flag2}]]></conditionExpression> </sequenceFlow> <sequenceFlow id="sid-8A717A65-0012-4E81-A1CA-71F0DA1DB3F4" sourceRef="sid-00BCCAF3-33E1-47F0-A5E3-8DD2111EB811" targetRef="sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${flag1}]]></conditionExpression> </sequenceFlow> <sequenceFlow id="sid-E3CC1963-3F15-41CF-AC6F-C7621D01CF89" sourceRef="sid-00BCCAF3-33E1-47F0-A5E3-8DD2111EB811" targetRef="sid-6245BCCB-0A1B-4AA3-8E37-560D2B3F7E7C"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${flag3}]]></conditionExpression> </sequenceFlow> <sequenceFlow id="sid-BE25B4D7-3D0D-430B-8CAD-41204BD23064" sourceRef="sid-671720BC-24F3-46F8-B485-20A33C8790C1" targetRef="sid-00BCCAF3-33E1-47F0-A5E3-8DD2111EB811"></sequenceFlow> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_test1"> <bpmndi:BPMNPlane bpmnElement="test1" id="BPMNPlane_test1"> <bpmndi:BPMNShape bpmnElement="sid-671720BC-24F3-46F8-B485-20A33C8790C1" id="BPMNShape_sid-671720BC-24F3-46F8-B485-20A33C8790C1"> <omgdc:Bounds height="30.0" width="30.0" x="15.0" y="180.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA" id="BPMNShape_sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA"> <omgdc:Bounds height="80.0" width="100.0" x="315.0" y="90.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7" id="BPMNShape_sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7"> <omgdc:Bounds height="80.0" width="100.0" x="315.0" y="210.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-6245BCCB-0A1B-4AA3-8E37-560D2B3F7E7C" id="BPMNShape_sid-6245BCCB-0A1B-4AA3-8E37-560D2B3F7E7C"> <omgdc:Bounds height="80.0" width="100.0" x="315.0" y="330.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-00BCCAF3-33E1-47F0-A5E3-8DD2111EB811" id="BPMNShape_sid-00BCCAF3-33E1-47F0-A5E3-8DD2111EB811"> <omgdc:Bounds height="40.0" width="40.0" x="120.0" y="175.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-AFD10B32-F844-4F33-A370-D8D57DD2BA6F" id="BPMNShape_sid-AFD10B32-F844-4F33-A370-D8D57DD2BA6F"> <omgdc:Bounds height="28.0" width="28.0" x="555.5" y="221.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNEdge bpmnElement="sid-B2DC5D9D-9882-45B9-AE09-1EAD67D32113" id="BPMNEdge_sid-B2DC5D9D-9882-45B9-AE09-1EAD67D32113"> <omgdi:waypoint x="414.95000000000005" y="155.6466992665037"></omgdi:waypoint> <omgdi:waypoint x="557.0338275701733" y="228.60404181208295"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-E3CC1963-3F15-41CF-AC6F-C7621D01CF89" id="BPMNEdge_sid-E3CC1963-3F15-41CF-AC6F-C7621D01CF89"> <omgdi:waypoint x="151.16204585316962" y="203.787656641604"></omgdi:waypoint> <omgdi:waypoint x="315.0" y="331.1358574610245"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-1ACB9184-D272-4297-9A32-84CB8C86C969" id="BPMNEdge_sid-1ACB9184-D272-4297-9A32-84CB8C86C969"> <omgdi:waypoint x="155.05272847316797" y="199.8967191133828"></omgdi:waypoint> <omgdi:waypoint x="314.9999999999999" y="238.0676199422867"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-BE25B4D7-3D0D-430B-8CAD-41204BD23064" id="BPMNEdge_sid-BE25B4D7-3D0D-430B-8CAD-41204BD23064"> <omgdi:waypoint x="44.9499984899576" y="195.0"></omgdi:waypoint> <omgdi:waypoint x="120.0" y="195.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-16008AF9-33DC-4494-89E4-DFD8F9EE097F" id="BPMNEdge_sid-16008AF9-33DC-4494-89E4-DFD8F9EE097F"> <omgdi:waypoint x="414.95000000000005" y="336.9926650366748"></omgdi:waypoint> <omgdi:waypoint x="557.8149707932783" y="242.68628405652325"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-1BE338B7-783D-4882-9755-EADB1159522F" id="BPMNEdge_sid-1BE338B7-783D-4882-9755-EADB1159522F"> <omgdi:waypoint x="414.9499999999998" y="246.33251833740832"></omgdi:waypoint> <omgdi:waypoint x="555.5368902201365" y="236.0205313044326"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-8A717A65-0012-4E81-A1CA-71F0DA1DB3F4" id="BPMNEdge_sid-8A717A65-0012-4E81-A1CA-71F0DA1DB3F4"> <omgdi:waypoint x="155.94405172413792" y="190.98275862068965"></omgdi:waypoint> <omgdi:waypoint x="315.0" y="144.57338530066812"></omgdi:waypoint> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>
package com.datang.qqboark.listener; import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.ExecutionListener; /** * @author 顶风少年 * @date 2022/2/28 */ public class StartListener implements ExecutionListener { @Override public void notify(DelegateExecution delegateExecution) { delegateExecution.setVariable("flag1", true); delegateExecution.setVariable("flag2", true); delegateExecution.setVariable("flag3", false); } }
并行网关-分支
以下并行网关有三条分支,流1,流2的条件为true流3的条件为false但是最终三个分支都会执行。如果连接到并行网关的顺序流上定义了条件,会直接忽略该条件
<?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"> <process id="test1" name="test1" isExecutable="true"> <startEvent id="sid-671720BC-24F3-46F8-B485-20A33C8790C1" flowable:formFieldValidation="true"> <extensionElements> <flowable:executionListener event="start" class="com.datang.qqboark.listener.StartListener"></flowable:executionListener> </extensionElements> </startEvent> <userTask id="sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA" flowable:assignee="张三" flowable:formFieldValidation="true"> <extensionElements> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> </userTask> <userTask id="sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7" flowable:assignee="李四" flowable:formFieldValidation="true"> <extensionElements> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> </userTask> <userTask id="sid-6245BCCB-0A1B-4AA3-8E37-560D2B3F7E7C" flowable:assignee="王五" flowable:formFieldValidation="true"> <extensionElements> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> </userTask> <endEvent id="sid-AFD10B32-F844-4F33-A370-D8D57DD2BA6F"></endEvent> <sequenceFlow id="sid-B2DC5D9D-9882-45B9-AE09-1EAD67D32113" sourceRef="sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA" targetRef="sid-AFD10B32-F844-4F33-A370-D8D57DD2BA6F"></sequenceFlow> <sequenceFlow id="sid-1BE338B7-783D-4882-9755-EADB1159522F" sourceRef="sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7" targetRef="sid-AFD10B32-F844-4F33-A370-D8D57DD2BA6F"></sequenceFlow> <sequenceFlow id="sid-16008AF9-33DC-4494-89E4-DFD8F9EE097F" sourceRef="sid-6245BCCB-0A1B-4AA3-8E37-560D2B3F7E7C" targetRef="sid-AFD10B32-F844-4F33-A370-D8D57DD2BA6F"></sequenceFlow> <parallelGateway id="sid-7DC3454E-24B5-46BD-8044-15DD73DBF39B"></parallelGateway> <sequenceFlow id="sid-BE25B4D7-3D0D-430B-8CAD-41204BD23064" sourceRef="sid-671720BC-24F3-46F8-B485-20A33C8790C1" targetRef="sid-7DC3454E-24B5-46BD-8044-15DD73DBF39B"></sequenceFlow> <sequenceFlow id="sid-1ACB9184-D272-4297-9A32-84CB8C86C969" sourceRef="sid-7DC3454E-24B5-46BD-8044-15DD73DBF39B" targetRef="sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${flag2}]]></conditionExpression> </sequenceFlow> <sequenceFlow id="sid-E3CC1963-3F15-41CF-AC6F-C7621D01CF89" sourceRef="sid-7DC3454E-24B5-46BD-8044-15DD73DBF39B" targetRef="sid-6245BCCB-0A1B-4AA3-8E37-560D2B3F7E7C"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${flag3}]]></conditionExpression> </sequenceFlow> <sequenceFlow id="sid-8A717A65-0012-4E81-A1CA-71F0DA1DB3F4" sourceRef="sid-7DC3454E-24B5-46BD-8044-15DD73DBF39B" targetRef="sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${flag1}]]></conditionExpression> </sequenceFlow> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_test1"> <bpmndi:BPMNPlane bpmnElement="test1" id="BPMNPlane_test1"> <bpmndi:BPMNShape bpmnElement="sid-671720BC-24F3-46F8-B485-20A33C8790C1" id="BPMNShape_sid-671720BC-24F3-46F8-B485-20A33C8790C1"> <omgdc:Bounds height="30.0" width="30.0" x="135.0" y="235.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA" id="BPMNShape_sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA"> <omgdc:Bounds height="80.0" width="100.0" x="435.0" y="90.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7" id="BPMNShape_sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7"> <omgdc:Bounds height="80.0" width="100.0" x="435.0" y="210.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-6245BCCB-0A1B-4AA3-8E37-560D2B3F7E7C" id="BPMNShape_sid-6245BCCB-0A1B-4AA3-8E37-560D2B3F7E7C"> <omgdc:Bounds height="80.0" width="100.0" x="435.0" y="330.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-AFD10B32-F844-4F33-A370-D8D57DD2BA6F" id="BPMNShape_sid-AFD10B32-F844-4F33-A370-D8D57DD2BA6F"> <omgdc:Bounds height="28.0" width="28.0" x="660.0" y="236.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-7DC3454E-24B5-46BD-8044-15DD73DBF39B" id="BPMNShape_sid-7DC3454E-24B5-46BD-8044-15DD73DBF39B"> <omgdc:Bounds height="40.0" width="40.0" x="255.0" y="230.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNEdge bpmnElement="sid-B2DC5D9D-9882-45B9-AE09-1EAD67D32113" id="BPMNEdge_sid-B2DC5D9D-9882-45B9-AE09-1EAD67D32113"> <omgdi:waypoint x="534.95" y="161.71428571428578"></omgdi:waypoint> <omgdi:waypoint x="662.1717770936712" y="242.4949362025688"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-E3CC1963-3F15-41CF-AC6F-C7621D01CF89" id="BPMNEdge_sid-E3CC1963-3F15-41CF-AC6F-C7621D01CF89"> <omgdi:waypoint x="287.5661577028259" y="257.38305471124625"></omgdi:waypoint> <omgdi:waypoint x="435.0" y="341.4797136038187"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-1ACB9184-D272-4297-9A32-84CB8C86C969" id="BPMNEdge_sid-1ACB9184-D272-4297-9A32-84CB8C86C969"> <omgdi:waypoint x="294.4907819225251" y="250.45454545454547"></omgdi:waypoint> <omgdi:waypoint x="434.99999999999426" y="250.1192124105012"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-BE25B4D7-3D0D-430B-8CAD-41204BD23064" id="BPMNEdge_sid-BE25B4D7-3D0D-430B-8CAD-41204BD23064"> <omgdi:waypoint x="164.94985958140524" y="250.0595614374583"></omgdi:waypoint> <omgdi:waypoint x="255.41999999999686" y="250.42"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-16008AF9-33DC-4494-89E4-DFD8F9EE097F" id="BPMNEdge_sid-16008AF9-33DC-4494-89E4-DFD8F9EE097F"> <omgdi:waypoint x="534.95" y="338.25396825396825"></omgdi:waypoint> <omgdi:waypoint x="662.1795233622603" y="257.4782607301075"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-1BE338B7-783D-4882-9755-EADB1159522F" id="BPMNEdge_sid-1BE338B7-783D-4882-9755-EADB1159522F"> <omgdi:waypoint x="534.9499999998601" y="250.0"></omgdi:waypoint> <omgdi:waypoint x="660.0" y="250.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-8A717A65-0012-4E81-A1CA-71F0DA1DB3F4" id="BPMNEdge_sid-8A717A65-0012-4E81-A1CA-71F0DA1DB3F4"> <omgdi:waypoint x="288.16522727272724" y="243.1969696969697"></omgdi:waypoint> <omgdi:waypoint x="435.0" y="158.7301909307876"></omgdi:waypoint> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>
package com.datang.qqboark.listener; import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.ExecutionListener; /** * @author 顶风少年 * @date 2022/2/28 */ public class StartListener implements ExecutionListener { @Override public void notify(DelegateExecution delegateExecution) { delegateExecution.setVariable("flag1", true); delegateExecution.setVariable("flag2", true); delegateExecution.setVariable("flag3", false); } }
并向网关-合并
所有到达并行网关的并行执行都会在网关处等待,直到每一条入口顺序流都到达了并行网关。然后流程经过该合并网关继续。A1执行了两个任务后才分裂出了三个任务。
package com.datang.qqboark.listener; import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.ExecutionListener; /** * @author 顶风少年 * @date 2022/2/28 */ public class StartListener implements ExecutionListener { @Override public void notify(DelegateExecution delegateExecution) { delegateExecution.setVariable("flag1", true); delegateExecution.setVariable("flag2", true); delegateExecution.setVariable("flag3", false); } }
包容网关-合并
和并行网关一样,到达并行网关的并行执行都会在网关处等待,直到每一条入口顺序流都到达了包容网关。才会继续执行。
<?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"> <process id="test1" name="test1" isExecutable="true"> <startEvent id="sid-671720BC-24F3-46F8-B485-20A33C8790C1" flowable:formFieldValidation="true"> <extensionElements> <flowable:executionListener event="start" class="com.datang.qqboark.listener.StartListener"></flowable:executionListener> </extensionElements> </startEvent> <userTask id="sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA" flowable:assignee="张三" flowable:formFieldValidation="true"> <extensionElements> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> </userTask> <userTask id="sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7" flowable:assignee="李四" flowable:formFieldValidation="true"> <extensionElements> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> </userTask> <userTask id="sid-6245BCCB-0A1B-4AA3-8E37-560D2B3F7E7C" flowable:assignee="王五" flowable:formFieldValidation="true"> <extensionElements> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> </userTask> <endEvent id="sid-AFD10B32-F844-4F33-A370-D8D57DD2BA6F"></endEvent> <sequenceFlow id="sid-B2DC5D9D-9882-45B9-AE09-1EAD67D32113" sourceRef="sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA" targetRef="sid-AFD10B32-F844-4F33-A370-D8D57DD2BA6F"></sequenceFlow> <sequenceFlow id="sid-1BE338B7-783D-4882-9755-EADB1159522F" sourceRef="sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7" targetRef="sid-AFD10B32-F844-4F33-A370-D8D57DD2BA6F"></sequenceFlow> <sequenceFlow id="sid-16008AF9-33DC-4494-89E4-DFD8F9EE097F" sourceRef="sid-6245BCCB-0A1B-4AA3-8E37-560D2B3F7E7C" targetRef="sid-AFD10B32-F844-4F33-A370-D8D57DD2BA6F"></sequenceFlow> <sequenceFlow id="sid-1ACB9184-D272-4297-9A32-84CB8C86C969" sourceRef="sid-B88D80BB-BDDE-401C-A146-8517716764DF" targetRef="sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${flag2}]]></conditionExpression> </sequenceFlow> <sequenceFlow id="sid-E3CC1963-3F15-41CF-AC6F-C7621D01CF89" sourceRef="sid-B88D80BB-BDDE-401C-A146-8517716764DF" targetRef="sid-6245BCCB-0A1B-4AA3-8E37-560D2B3F7E7C"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${flag3}]]></conditionExpression> </sequenceFlow> <userTask id="sid-C2BCDA45-B418-4D47-9920-70AC88EB73BC" flowable:assignee="A1" flowable:formFieldValidation="true"> <extensionElements> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> </userTask> <userTask id="sid-F135425B-21CD-4026-8EE5-314ABC26B5BF" flowable:assignee="A1" flowable:formFieldValidation="true"> <extensionElements> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> </userTask> <sequenceFlow id="sid-B1984468-F77F-4519-A0F2-15B0813B7ECC" sourceRef="sid-C2BCDA45-B418-4D47-9920-70AC88EB73BC" targetRef="sid-B88D80BB-BDDE-401C-A146-8517716764DF"></sequenceFlow> <sequenceFlow id="sid-0DDAF6FD-80A0-43BF-B56F-61D096C66CDF" sourceRef="sid-F135425B-21CD-4026-8EE5-314ABC26B5BF" targetRef="sid-B88D80BB-BDDE-401C-A146-8517716764DF"></sequenceFlow> <sequenceFlow id="sid-D8D147D4-A5CD-4E63-86A2-6A2676FF4294" sourceRef="sid-671720BC-24F3-46F8-B485-20A33C8790C1" targetRef="sid-C2BCDA45-B418-4D47-9920-70AC88EB73BC"></sequenceFlow> <sequenceFlow id="sid-2DC4E4EF-E16B-40B3-9227-051C0D104899" sourceRef="sid-671720BC-24F3-46F8-B485-20A33C8790C1" targetRef="sid-F135425B-21CD-4026-8EE5-314ABC26B5BF"></sequenceFlow> <sequenceFlow id="sid-8A717A65-0012-4E81-A1CA-71F0DA1DB3F4" sourceRef="sid-B88D80BB-BDDE-401C-A146-8517716764DF" targetRef="sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${flag1}]]></conditionExpression> </sequenceFlow> <inclusiveGateway id="sid-B88D80BB-BDDE-401C-A146-8517716764DF"></inclusiveGateway> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_test1"> <bpmndi:BPMNPlane bpmnElement="test1" id="BPMNPlane_test1"> <bpmndi:BPMNShape bpmnElement="sid-671720BC-24F3-46F8-B485-20A33C8790C1" id="BPMNShape_sid-671720BC-24F3-46F8-B485-20A33C8790C1"> <omgdc:Bounds height="30.0" width="30.0" x="120.0" y="235.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA" id="BPMNShape_sid-3565FF8B-52BE-45DA-A7A4-3FFE24AD66DA"> <omgdc:Bounds height="80.0" width="100.0" x="435.0" y="90.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7" id="BPMNShape_sid-6F7503F4-B3C9-4C55-90D6-D6FAEB4842A7"> <omgdc:Bounds height="80.0" width="100.0" x="435.0" y="210.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-6245BCCB-0A1B-4AA3-8E37-560D2B3F7E7C" id="BPMNShape_sid-6245BCCB-0A1B-4AA3-8E37-560D2B3F7E7C"> <omgdc:Bounds height="80.0" width="100.0" x="435.0" y="330.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-AFD10B32-F844-4F33-A370-D8D57DD2BA6F" id="BPMNShape_sid-AFD10B32-F844-4F33-A370-D8D57DD2BA6F"> <omgdc:Bounds height="28.0" width="28.0" x="660.0" y="236.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-C2BCDA45-B418-4D47-9920-70AC88EB73BC" id="BPMNShape_sid-C2BCDA45-B418-4D47-9920-70AC88EB73BC"> <omgdc:Bounds height="80.0" width="100.0" x="195.0" y="120.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-F135425B-21CD-4026-8EE5-314ABC26B5BF" id="BPMNShape_sid-F135425B-21CD-4026-8EE5-314ABC26B5BF"> <omgdc:Bounds height="80.0" width="100.0" x="195.0" y="280.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-B88D80BB-BDDE-401C-A146-8517716764DF" id="BPMNShape_sid-B88D80BB-BDDE-401C-A146-8517716764DF"> <omgdc:Bounds height="40.0" width="40.0" x="345.0" y="240.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNEdge bpmnElement="sid-B2DC5D9D-9882-45B9-AE09-1EAD67D32113" id="BPMNEdge_sid-B2DC5D9D-9882-45B9-AE09-1EAD67D32113"> <omgdi:waypoint x="534.95" y="161.71428571428578"></omgdi:waypoint> <omgdi:waypoint x="662.1717770936712" y="242.4949362025688"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-E3CC1963-3F15-41CF-AC6F-C7621D01CF89" id="BPMNEdge_sid-E3CC1963-3F15-41CF-AC6F-C7621D01CF89"> <omgdi:waypoint x="379.8290133835567" y="265.12098401050633"></omgdi:waypoint> <omgdi:waypoint x="444.8885577248844" y="330.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-B1984468-F77F-4519-A0F2-15B0813B7ECC" id="BPMNEdge_sid-B1984468-F77F-4519-A0F2-15B0813B7ECC"> <omgdi:waypoint x="292.8962953754351" y="199.95"></omgdi:waypoint> <omgdi:waypoint x="354.0456806874717" y="250.9502262443439"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-0DDAF6FD-80A0-43BF-B56F-61D096C66CDF" id="BPMNEdge_sid-0DDAF6FD-80A0-43BF-B56F-61D096C66CDF"> <omgdi:waypoint x="294.95000000000005" y="295.31120331950206"></omgdi:waypoint> <omgdi:waypoint x="352.1111111111111" y="267.09458333333333"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-2DC4E4EF-E16B-40B3-9227-051C0D104899" id="BPMNEdge_sid-2DC4E4EF-E16B-40B3-9227-051C0D104899"> <omgdi:waypoint x="147.61337934016487" y="258.0272975560688"></omgdi:waypoint> <omgdi:waypoint x="195.0" y="288.1818181818182"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-D8D147D4-A5CD-4E63-86A2-6A2676FF4294" id="BPMNEdge_sid-D8D147D4-A5CD-4E63-86A2-6A2676FF4294"> <omgdi:waypoint x="146.57100778681632" y="240.50114896467048"></omgdi:waypoint> <omgdi:waypoint x="196.11111111111114" y="199.95"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-1ACB9184-D272-4297-9A32-84CB8C86C969" id="BPMNEdge_sid-1ACB9184-D272-4297-9A32-84CB8C86C969"> <omgdi:waypoint x="379.8071238395733" y="265.1225396007759"></omgdi:waypoint> <omgdi:waypoint x="434.99999999999994" y="257.18562218842345"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-16008AF9-33DC-4494-89E4-DFD8F9EE097F" id="BPMNEdge_sid-16008AF9-33DC-4494-89E4-DFD8F9EE097F"> <omgdi:waypoint x="534.95" y="338.25396825396825"></omgdi:waypoint> <omgdi:waypoint x="662.1795233622603" y="257.4782607301075"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-1BE338B7-783D-4882-9755-EADB1159522F" id="BPMNEdge_sid-1BE338B7-783D-4882-9755-EADB1159522F"> <omgdi:waypoint x="534.9499999998601" y="250.0"></omgdi:waypoint> <omgdi:waypoint x="660.0" y="250.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-8A717A65-0012-4E81-A1CA-71F0DA1DB3F4" id="BPMNEdge_sid-8A717A65-0012-4E81-A1CA-71F0DA1DB3F4"> <omgdi:waypoint x="370.2965007507647" y="245.3214308744877"></omgdi:waypoint> <omgdi:waypoint x="445.22298084375143" y="169.95"></omgdi:waypoint> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>
包容网关-分支
当A1,A2两个任务执行完毕后。会分裂出两个任务,这与并行网关是有区别的,包容网关允许有条件,只有条件满足的流才会分裂任务。
Create任务监听器初始化参数
在实际应用中我们肯定不会将任务的具体细节写死到xml中,在create中可以分配用户,设置任务过期时间。注意,任务过期时间只是一个时间标记,它并不会将已经过期的任务清理。可以使用API查询任务是否过期Task.getDueDate()
<?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">
<process id="test1" name="test1" isExecutable="true">
<startEvent id="sid-EF35DFED-A65D-4F8E-88D1-134B190EAD48" flowable:formFieldValidation="true"></startEvent>
<userTask id="sid-DCF82270-9F6D-409E-9EA2-08729708878A" flowable:formFieldValidation="true" flowable:assignee="张三">
<extensionElements>
<flowable:taskListener event="create" class="com.datang.qqboark.listener.CreateListener"></flowable:taskListener>
</extensionElements>
</userTask>
<endEvent id="sid-23C01770-D012-4FA8-8553-0A26B1BD3AB2"></endEvent>
<sequenceFlow id="sid-55EB6B28-7930-4572-B7B6-FBE1F85A1F07" sourceRef="sid-DCF82270-9F6D-409E-9EA2-08729708878A" targetRef="sid-23C01770-D012-4FA8-8553-0A26B1BD3AB2"></sequenceFlow>
<sequenceFlow id="sid-83904D0D-E219-49F9-A91E-6F752F0ED4D3" sourceRef="sid-EF35DFED-A65D-4F8E-88D1-134B190EAD48" targetRef="sid-DCF82270-9F6D-409E-9EA2-08729708878A"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_test1">
<bpmndi:BPMNPlane bpmnElement="test1" id="BPMNPlane_test1">
<bpmndi:BPMNShape bpmnElement="sid-EF35DFED-A65D-4F8E-88D1-134B190EAD48" id="BPMNShape_sid-EF35DFED-A65D-4F8E-88D1-134B190EAD48">
<omgdc:Bounds height="30.0" width="30.0" x="315.0" y="181.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-DCF82270-9F6D-409E-9EA2-08729708878A" id="BPMNShape_sid-DCF82270-9F6D-409E-9EA2-08729708878A">
<omgdc:Bounds height="80.0" width="100.0" x="390.0" y="156.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="sid-23C01770-D012-4FA8-8553-0A26B1BD3AB2" id="BPMNShape_sid-23C01770-D012-4FA8-8553-0A26B1BD3AB2">
<omgdc:Bounds height="28.0" width="28.0" x="540.0" y="182.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="sid-83904D0D-E219-49F9-A91E-6F752F0ED4D3" id="BPMNEdge_sid-83904D0D-E219-49F9-A91E-6F752F0ED4D3">
<omgdi:waypoint x="344.9499984899576" y="196.0"></omgdi:waypoint>
<omgdi:waypoint x="390.0" y="196.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="sid-55EB6B28-7930-4572-B7B6-FBE1F85A1F07" id="BPMNEdge_sid-55EB6B28-7930-4572-B7B6-FBE1F85A1F07">
<omgdi:waypoint x="489.94999999999595" y="196.0"></omgdi:waypoint>
<omgdi:waypoint x="540.0" y="196.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
package com.datang.qqboark.listener; import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.ExecutionListener; import org.flowable.task.service.delegate.DelegateTask; import org.flowable.task.service.delegate.TaskListener; import java.util.Calendar; import java.util.Date; /** * @author 顶风少年 * @date 2022/2/28 */ public class CreateListener implements TaskListener { @Override public void notify(DelegateTask delegateTask) { Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); calendar.add(Calendar.MINUTE,1); delegateTask.setDueDate(calendar.getTime()); delegateTask.setAssignee("管理员1"); } }
用户任务多实例
可以将一个任务分配给多个执行人.需要设置flowable:collection="assigneesList" flowable:elementVariable="assignee".collection是集合的名字,elementVariable是集合中每个执行人的变量,需要注意的是elementVariable必须和assignee相同,设置collection必须在流程任务监听器前,也就是只能在执行监听器start时初始化.isSequential="false"表示分裂的任务并行创建.如果为true则任务串行创建(第一个执行后才会创建第二个).<completionCondition>接受一个表达式,表示用户任务完成的时机.如果不写则需要全部任务执行结束.
-
nrOfInstances:实例总数。
-
nrOfActiveInstances:当前活动的(即未完成的),实例数量。对于顺序多实例,这个值总为1。
-
nrOfCompletedInstances:已完成的实例数量。
以上三个为系统内置的变量,可以使用表达式 ${nrOfCompletedInstances/nrOfInstances >= 0.5} 它表示有一半的人执该任务则任务就算执行完毕,进行下一个流程.
<?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"> <process id="test1" name="test1" isExecutable="true"> <startEvent id="sid-EF35DFED-A65D-4F8E-88D1-134B190EAD48" flowable:formFieldValidation="true"></startEvent> <userTask id="sid-DCF82270-9F6D-409E-9EA2-08729708878A" flowable:assignee="${assignee}" flowable:formFieldValidation="true"> <extensionElements> <flowable:executionListener event="start" class="com.datang.qqboark.listener.StartListener"></flowable:executionListener> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> <multiInstanceLoopCharacteristics isSequential="false" flowable:collection="assigneesList" flowable:elementVariable="assignee"> <completionCondition>${nrOfCompletedInstances/nrOfInstances >= 0.5}</completionCondition> </multiInstanceLoopCharacteristics> </userTask> <endEvent id="sid-23C01770-D012-4FA8-8553-0A26B1BD3AB2"></endEvent> <sequenceFlow id="sid-83904D0D-E219-49F9-A91E-6F752F0ED4D3" sourceRef="sid-EF35DFED-A65D-4F8E-88D1-134B190EAD48" targetRef="sid-DCF82270-9F6D-409E-9EA2-08729708878A"></sequenceFlow> <sequenceFlow id="sid-55EB6B28-7930-4572-B7B6-FBE1F85A1F07" sourceRef="sid-DCF82270-9F6D-409E-9EA2-08729708878A" targetRef="sid-23C01770-D012-4FA8-8553-0A26B1BD3AB2"></sequenceFlow> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_test1"> <bpmndi:BPMNPlane bpmnElement="test1" id="BPMNPlane_test1"> <bpmndi:BPMNShape bpmnElement="sid-EF35DFED-A65D-4F8E-88D1-134B190EAD48" id="BPMNShape_sid-EF35DFED-A65D-4F8E-88D1-134B190EAD48"> <omgdc:Bounds height="30.0" width="30.0" x="405.0" y="180.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-DCF82270-9F6D-409E-9EA2-08729708878A" id="BPMNShape_sid-DCF82270-9F6D-409E-9EA2-08729708878A"> <omgdc:Bounds height="80.0" width="100.0" x="490.0" y="156.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-23C01770-D012-4FA8-8553-0A26B1BD3AB2" id="BPMNShape_sid-23C01770-D012-4FA8-8553-0A26B1BD3AB2"> <omgdc:Bounds height="28.0" width="28.0" x="640.0" y="182.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNEdge bpmnElement="sid-83904D0D-E219-49F9-A91E-6F752F0ED4D3" id="BPMNEdge_sid-83904D0D-E219-49F9-A91E-6F752F0ED4D3"> <omgdi:waypoint x="434.9499898986103" y="195.0"></omgdi:waypoint> <omgdi:waypoint x="462.5" y="195.0"></omgdi:waypoint> <omgdi:waypoint x="462.5" y="196.0"></omgdi:waypoint> <omgdi:waypoint x="490.0" y="196.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-55EB6B28-7930-4572-B7B6-FBE1F85A1F07" id="BPMNEdge_sid-55EB6B28-7930-4572-B7B6-FBE1F85A1F07"> <omgdi:waypoint x="589.949999999996" y="196.0"></omgdi:waypoint> <omgdi:waypoint x="640.0" y="196.0"></omgdi:waypoint> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>
package com.datang.qqboark.listener; import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.ExecutionListener; import org.flowable.task.service.delegate.DelegateTask; import org.flowable.task.service.delegate.TaskListener; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; /** * @author 顶风少年 * @date 2022/2/28 */ public class StartListener implements ExecutionListener { @Override public void notify(DelegateExecution delegateTask) { ArrayList<String> assignees = new ArrayList<>(); assignees.add("张三"); assignees.add("李四"); assignees.add("王五"); delegateTask.setVariable("assigneesList",assignees); } }
用户任务多实例-自定义完成条件
以下案例用户任务会分配给三个用户,设置的转移条件是flag如果flag为true则触发转移.定义了任务监听器complete判断已执行次数,然后设置flag但flag这个变量也必须在执行监听器start中设置.
<?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"> <process id="test1" name="test1" isExecutable="true"> <startEvent id="sid-EF35DFED-A65D-4F8E-88D1-134B190EAD48" flowable:formFieldValidation="true"></startEvent> <userTask id="sid-DCF82270-9F6D-409E-9EA2-08729708878A" flowable:assignee="${assignee}" flowable:formFieldValidation="true"> <extensionElements> <flowable:executionListener event="start" class="com.datang.qqboark.listener.StartListener"></flowable:executionListener> <flowable:taskListener event="complete" class="com.datang.qqboark.listener.CompleteListener"></flowable:taskListener> <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete> </extensionElements> <multiInstanceLoopCharacteristics isSequential="false" flowable:collection="assigneesList" flowable:elementVariable="assignee"> <completionCondition>${flag}</completionCondition> </multiInstanceLoopCharacteristics> </userTask> <endEvent id="sid-23C01770-D012-4FA8-8553-0A26B1BD3AB2"></endEvent> <sequenceFlow id="sid-83904D0D-E219-49F9-A91E-6F752F0ED4D3" sourceRef="sid-EF35DFED-A65D-4F8E-88D1-134B190EAD48" targetRef="sid-DCF82270-9F6D-409E-9EA2-08729708878A"></sequenceFlow> <sequenceFlow id="sid-55EB6B28-7930-4572-B7B6-FBE1F85A1F07" sourceRef="sid-DCF82270-9F6D-409E-9EA2-08729708878A" targetRef="sid-23C01770-D012-4FA8-8553-0A26B1BD3AB2"></sequenceFlow> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_test1"> <bpmndi:BPMNPlane bpmnElement="test1" id="BPMNPlane_test1"> <bpmndi:BPMNShape bpmnElement="sid-EF35DFED-A65D-4F8E-88D1-134B190EAD48" id="BPMNShape_sid-EF35DFED-A65D-4F8E-88D1-134B190EAD48"> <omgdc:Bounds height="30.0" width="30.0" x="405.0" y="180.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-DCF82270-9F6D-409E-9EA2-08729708878A" id="BPMNShape_sid-DCF82270-9F6D-409E-9EA2-08729708878A"> <omgdc:Bounds height="80.0" width="100.0" x="490.0" y="156.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="sid-23C01770-D012-4FA8-8553-0A26B1BD3AB2" id="BPMNShape_sid-23C01770-D012-4FA8-8553-0A26B1BD3AB2"> <omgdc:Bounds height="28.0" width="28.0" x="640.0" y="182.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNEdge bpmnElement="sid-83904D0D-E219-49F9-A91E-6F752F0ED4D3" id="BPMNEdge_sid-83904D0D-E219-49F9-A91E-6F752F0ED4D3"> <omgdi:waypoint x="434.9499898986103" y="195.0"></omgdi:waypoint> <omgdi:waypoint x="462.5" y="195.0"></omgdi:waypoint> <omgdi:waypoint x="462.5" y="196.0"></omgdi:waypoint> <omgdi:waypoint x="490.0" y="196.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="sid-55EB6B28-7930-4572-B7B6-FBE1F85A1F07" id="BPMNEdge_sid-55EB6B28-7930-4572-B7B6-FBE1F85A1F07"> <omgdi:waypoint x="589.949999999996" y="196.0"></omgdi:waypoint> <omgdi:waypoint x="640.0" y="196.0"></omgdi:waypoint> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>
package com.datang.qqboark.listener; import org.flowable.engine.delegate.DelegateExecution; import org.flowable.engine.delegate.ExecutionListener; import org.flowable.task.service.delegate.DelegateTask; import org.flowable.task.service.delegate.TaskListener; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; /** * @author 顶风少年 * @date 2022/2/28 */ public class StartListener implements ExecutionListener { @Override public void notify(DelegateExecution delegateTask) { ArrayList<String> assignees = new ArrayList<>(); assignees.add("张三"); assignees.add("李四"); assignees.add("王五"); delegateTask.setVariable("assigneesList",assignees); delegateTask.setVariable("flag",false); } }
package com.datang.qqboark.listener; import org.flowable.engine.delegate.DelegateExecution; import org.flowable.task.service.delegate.DelegateTask; import org.flowable.task.service.delegate.TaskListener; import java.util.ArrayList; /** * @author 顶风少年 * @date 2022/2/28 */ public class CompleteListener implements TaskListener { @Override public void notify(DelegateTask delegateTask) { Integer i = (Integer) delegateTask.getVariable("nrOfCompletedInstances"); if (i == 1) { delegateTask.setVariable("flag", true); } } }