最近在用Camunda流程引擎做业务开发时,认识到了Camunda Modeler 流程工具有条件事件、定时事件这2个东西。那它们长什么样子,在流程中可以用来做什么,以及怎么用的?
1、先来看看它们长什么样子吧!!
2、继续来看看它们在流程中能有什么用?
-
启动流程 发起一个流程
-
连接任务节点 在流程图中充当一个节点
-
边界条件 充当一个条件,让流程转到下一个节点
3、流程中应该如何使用
说到使用,就是如何来配制其参数,下面先看看以条件事件做为记点的流程图:
具体的XML文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:modeler="http://camunda.org/schema/modeler/1.0" id="Definitions_0s1z5wy" 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_1pnqnm2" isExecutable="true">
<bpmn:startEvent id="Event_126uv9a">
<bpmn:outgoing>Flow_18fns5t</bpmn:outgoing>
<bpmn:conditionalEventDefinition id="ConditionalEventDefinition_1gm4pkp">
<bpmn:condition xsi:type="bpmn:tFormalExpression">${isStart==true}</bpmn:condition>
</bpmn:conditionalEventDefinition>
</bpmn:startEvent>
<bpmn:endEvent id="Event_11qvdk8" name="结束">
<bpmn:incoming>Flow_1r1naac</bpmn:incoming>
</bpmn:endEvent>
<bpmn:userTask id="Activity_1jxrygv" name="任务一" camunda:assignee="demo">
<bpmn:incoming>Flow_02ygcmk</bpmn:incoming>
<bpmn:outgoing>Flow_1v92nkr</bpmn:outgoing>
</bpmn:userTask>
<bpmn:userTask id="Activity_0ge95xj" name="任务二" camunda:assignee="demo">
<bpmn:incoming>Flow_1v92nkr</bpmn:incoming>
<bpmn:incoming>Flow_1gbyloh</bpmn:incoming>
<bpmn:incoming>Flow_0ssmwh2</bpmn:incoming>
<bpmn:outgoing>Flow_1r1naac</bpmn:outgoing>
</bpmn:userTask>
<bpmn:intermediateCatchEvent id="Event_19nx1hm">
<bpmn:incoming>Flow_18fns5t</bpmn:incoming>
<bpmn:outgoing>Flow_02ygcmk</bpmn:outgoing>
<bpmn:conditionalEventDefinition id="ConditionalEventDefinition_00p6dhv">
<bpmn:condition xsi:type="bpmn:tFormalExpression">#{isCount >0}</bpmn:condition>
</bpmn:conditionalEventDefinition>
</bpmn:intermediateCatchEvent>
<bpmn:boundaryEvent id="Event_1wh4ejq" name="超时自动流转" attachedToRef="Activity_1jxrygv">
<bpmn:outgoing>Flow_1gbyloh</bpmn:outgoing>
<bpmn:timerEventDefinition id="TimerEventDefinition_0v6fjke">
<bpmn:timeDuration xsi:type="bpmn:tFormalExpression">PT3M</bpmn:timeDuration>
</bpmn:timerEventDefinition>
</bpmn:boundaryEvent>
<bpmn:boundaryEvent id="Event_1oyel6i" attachedToRef="Activity_1jxrygv">
<bpmn:outgoing>Flow_0ssmwh2</bpmn:outgoing>
<bpmn:conditionalEventDefinition id="ConditionalEventDefinition_1wsjdfl">
<bpmn:condition xsi:type="bpmn:tFormalExpression">${isAutoCompleted == true}</bpmn:condition>
</bpmn:conditionalEventDefinition>
</bpmn:boundaryEvent>
<bpmn:sequenceFlow id="Flow_18fns5t" sourceRef="Event_126uv9a" targetRef="Event_19nx1hm" />
<bpmn:sequenceFlow id="Flow_1r1naac" sourceRef="Activity_0ge95xj" targetRef="Event_11qvdk8" />
<bpmn:sequenceFlow id="Flow_02ygcmk" sourceRef="Event_19nx1hm" targetRef="Activity_1jxrygv" />
<bpmn:sequenceFlow id="Flow_1v92nkr" sourceRef="Activity_1jxrygv" targetRef="Activity_0ge95xj" />
<bpmn:sequenceFlow id="Flow_1gbyloh" sourceRef="Event_1wh4ejq" targetRef="Activity_0ge95xj" />
<bpmn:sequenceFlow id="Flow_0ssmwh2" sourceRef="Event_1oyel6i" targetRef="Activity_0ge95xj" />
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1pnqnm2">
<bpmndi:BPMNEdge id="Flow_18fns5t_di" bpmnElement="Flow_18fns5t">
<di:waypoint x="188" y="160" />
<di:waypoint x="272" y="160" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1r1naac_di" bpmnElement="Flow_1r1naac">
<di:waypoint x="700" y="160" />
<di:waypoint x="762" y="160" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_02ygcmk_di" bpmnElement="Flow_02ygcmk">
<di:waypoint x="308" y="160" />
<di:waypoint x="380" y="160" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1v92nkr_di" bpmnElement="Flow_1v92nkr">
<di:waypoint x="480" y="160" />
<di:waypoint x="600" y="160" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_1gbyloh_di" bpmnElement="Flow_1gbyloh">
<di:waypoint x="440" y="218" />
<di:waypoint x="440" y="238" />
<di:waypoint x="650" y="238" />
<di:waypoint x="650" y="200" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge id="Flow_0ssmwh2_di" bpmnElement="Flow_0ssmwh2">
<di:waypoint x="440" y="102" />
<di:waypoint x="440" y="82" />
<di:waypoint x="650" y="82" />
<di:waypoint x="650" y="120" />
</bpmndi:BPMNEdge>
<bpmndi:BPMNShape id="Event_126uv9a_di" bpmnElement="Event_126uv9a">
<dc:Bounds x="152" y="142" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_11qvdk8_di" bpmnElement="Event_11qvdk8">
<dc:Bounds x="762" y="142" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="769" y="185" width="22" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_1jxrygv_di" bpmnElement="Activity_1jxrygv">
<dc:Bounds x="380" y="120" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0ge95xj_di" bpmnElement="Activity_0ge95xj">
<dc:Bounds x="600" y="120" width="100" height="80" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_19nx1hm_di" bpmnElement="Event_19nx1hm">
<dc:Bounds x="272" y="142" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1wh4ejq_di" bpmnElement="Event_1wh4ejq">
<dc:Bounds x="422" y="182" width="36" height="36" />
<bpmndi:BPMNLabel>
<dc:Bounds x="457" y="206" width="66" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_1oyel6i_di" bpmnElement="Event_1oyel6i">
<dc:Bounds x="422" y="102" width="36" height="36" />
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
4、在实际业务中,有那些实现的使用场景
1、条件启动事件:比如有些时候,需要根据一些条件发起流程
2、中间条件捕获异常事件: 可以根据捕获到的条件,决定是否下一步(如果不满足条件时,流程会停留在该节点,所以建议要用此控件,在前后建议用用户任务节点)
3、边界条件: 根据捕获到不同的条件进入到不同的下一步(比如在流程中,往前跳2个节点,或者回退到那个节点)
下面来说说定时事件,与条件事件一样,也有定时型事件、定时中间事件、定时边界事件,功能差不多,只是实现方式不一样,一个是根据条件、一个是根据时间。所以对定时器事件来说,最重要的就是如何配制时间参数:
重点:定时器有3种类型
1、 Date 固定的时间类型,指定年月日时分
2、Duration 间隔时间类型,以当前时间为起点,隔多少时间执行,也是只执行一次
3、周期性 需要指定什么时间开始,间隔时间,执行多少次。例如:R2/2022-02-28T14:20/PT1M 2022-02-28 下午2点20 每隔1分钟执行一次,共启动2次
要指定计时器在触发前应该运行多长时间,可以将时间持续时间指定为计时器事件定义的子元素。可以用两种不同的ISO 8601持续时间格式定义持续时间:
-
PnYnMnDTnHnMnS
-
PnW
间隔10天:P10D
3次重复,每次间隔10小时:R3/PT10H