flowable流程详解

图例解释

在这里插入图片描述

  • 开始事件:图中用细线圆圈来表示,是流程实例的开始点
  • 箭头:表示节点之间的流转指向。
  • 用户任务: 在图中用左上角有人的圆角矩形表示,这些是需要用户来操作的节点。图中有两个,第一个表示需要经理进行审批来同意或拒绝,
    第二个表示用户来确认销假。
  • 排它网关: 用叉形符号填充的菱形表示,从该图中出来的箭头往往有多个,但只有一个满足条件,流程会沿着满足条件的方向流转。
  • 自动化任务 :左上角有齿轮形状的的圆角矩形,表示自动执行的节点。图中上面的表示请假被经理同意后自动注册通知到外部系统,下面的表示请假被经理拒绝后自动发邮件通知给申请人。
  • 结束事件: 图中用粗线圆圈表示,表示流程的结束。图中上面的结束事件表示请假成功结束,下面的表示请假失败结束。

请假流程

bpmn20.xml文件

Flowable引擎需要流程定义为BPMN 2.0格式,这是一个业界广泛接受的XML标准。 在Flowable术语中,我们将其称为一个流程定义(process definition)。一个流程定义可以启动多个流程实例(process instance)。流程定义可以看做是重复执行流程的蓝图。

请假流程示例

在这里插入图片描述

<?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="Leave" name="请假流程" isExecutable="true">
        <documentation>请假流程</documentation>
        <startEvent id="start" name="开始" flowable:initiator="applyUser"></startEvent>
        <userTask id="hrTask" name="人事审批" flowable:assignee="${taskUser}">
            <extensionElements>
                <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
            </extensionElements>
        </userTask>
        <exclusiveGateway id="judgeTask"></exclusiveGateway>
        <userTask id="managerTak" name="经理审批" flowable:candidateGroups="manager"></userTask>
        <userTask id="bossTask" name="老板审批" flowable:candidateGroups="boss"></userTask>
        <endEvent id="end" name="结束"></endEvent>
        <sequenceFlow id="flow1" sourceRef="start" targetRef="hrTask"></sequenceFlow>
        <sequenceFlow id="managerPassFlow" name="通过" sourceRef="managerTak" targetRef="end">
            <conditionExpression xsi:type="tFormalExpression"><![CDATA[${pass}]]></conditionExpression>
        </sequenceFlow>
        <userTask id="userTask" name="调整申请" flowable:assignee="${applyUser}">
            <extensionElements>
                <modeler:initiator-can-complete xmlns:modeler="http://flowable.org/modeler"><![CDATA[false]]></modeler:initiator-can-complete>
            </extensionElements>
        </userTask>
        <sequenceFlow id="bossPassFlow" name="通过" sourceRef="bossTask" targetRef="end">
            <conditionExpression xsi:type="tFormalExpression"><![CDATA[${pass}]]></conditionExpression>
        </sequenceFlow>
        <sequenceFlow id="judgeMore" name="大于3天" sourceRef="judgeTask" targetRef="bossTask">
            <conditionExpression xsi:type="tFormalExpression"><![CDATA[${days > 3}]]></conditionExpression>
        </sequenceFlow>
        <sequenceFlow id="managerNotPassFlow" name="驳回" sourceRef="managerTak" targetRef="userTask">
            <conditionExpression xsi:type="tFormalExpression"><![CDATA[${!pass}]]></conditionExpression>
        </sequenceFlow>
        <sequenceFlow id="bossNotPassFlow" name="驳回" sourceRef="bossTask" targetRef="userTask">
            <conditionExpression xsi:type="tFormalExpression"><![CDATA[${!pass}]]></conditionExpression>
        </sequenceFlow>
        <sequenceFlow id="hrPassFlow" name="同意" sourceRef="hrTask" targetRef="judgeTask">
            <conditionExpression xsi:type="tFormalExpression"><![CDATA[${pass}]]></conditionExpression>
        </sequenceFlow>
        <sequenceFlow id="hrNotPassFlow" name="驳回" sourceRef="hrTask" targetRef="userTask">
            <conditionExpression xsi:type="tFormalExpression"><![CDATA[${!pass}]]></conditionExpression>
        </sequenceFlow>
        <sequenceFlow id="judgeLess" name="小于3天" sourceRef="judgeTask" targetRef="managerTak">
            <conditionExpression xsi:type="tFormalExpression"><![CDATA[${days <= 3}]]></conditionExpression>
        </sequenceFlow>
        <sequenceFlow id="userPassFlow" name="重新申请" sourceRef="userTask" targetRef="hrTask">
            <conditionExpression xsi:type="tFormalExpression"><![CDATA[${pass}]]></conditionExpression>
        </sequenceFlow>
        <sequenceFlow id="userNotPassFlow" name="关闭申请" sourceRef="userTask" targetRef="end">
            <conditionExpression xsi:type="tFormalExpression"><![CDATA[${!pass}]]></conditionExpression>
        </sequenceFlow>
    </process>
    <bpmndi:BPMNDiagram id="BPMNDiagram_Leave">
        <bpmndi:BPMNPlane bpmnElement="Leave" id="BPMNPlane_Leave">
            <bpmndi:BPMNShape bpmnElement="start" id="BPMNShape_start">
                <omgdc:Bounds height="30.0" width="30.0" x="300.0" y="135.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="hrTask" id="BPMNShape_hrTask">
                <omgdc:Bounds height="80.0" width="100.0" x="360.0" y="165.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="judgeTask" id="BPMNShape_judgeTask">
                <omgdc:Bounds height="40.0" width="40.0" x="255.0" y="300.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="managerTak" id="BPMNShape_managerTak">
                <omgdc:Bounds height="80.0" width="100.0" x="555.0" y="75.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="bossTask" id="BPMNShape_bossTask">
                <omgdc:Bounds height="80.0" width="100.0" x="450.0" y="420.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="end" id="BPMNShape_end">
                <omgdc:Bounds height="28.0" width="28.0" x="705.0" y="390.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNShape bpmnElement="userTask" id="BPMNShape_userTask">
                <omgdc:Bounds height="80.0" width="100.0" x="510.0" y="270.0"></omgdc:Bounds>
            </bpmndi:BPMNShape>
            <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
                <omgdi:waypoint x="327.9390183144677" y="157.4917313275668"></omgdi:waypoint>
                <omgdi:waypoint x="360.0" y="176.05263157894737"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="hrPassFlow" id="BPMNEdge_hrPassFlow">
                <omgdi:waypoint x="363.04347826086956" y="244.95000000000002"></omgdi:waypoint>
                <omgdi:waypoint x="285.77299999999997" y="310.79999999999995"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="hrNotPassFlow" id="BPMNEdge_hrNotPassFlow">
                <omgdi:waypoint x="459.95" y="236.21875000000006"></omgdi:waypoint>
                <omgdi:waypoint x="513.9794844818516" y="270.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="judgeLess" id="BPMNEdge_judgeLess">
                <omgdi:waypoint x="274.3359375" y="300.66397214564284"></omgdi:waypoint>
                <omgdi:waypoint x="274.3359375" y="115.0"></omgdi:waypoint>
                <omgdi:waypoint x="554.9999999999982" y="115.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="userPassFlow" id="BPMNEdge_userPassFlow">
                <omgdi:waypoint x="510.0" y="310.0"></omgdi:waypoint>
                <omgdi:waypoint x="411.0" y="310.0"></omgdi:waypoint>
                <omgdi:waypoint x="411.0" y="244.95000000000002"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="bossPassFlow" id="BPMNEdge_bossPassFlow">
                <omgdi:waypoint x="549.9499999999998" y="447.2146118721461"></omgdi:waypoint>
                <omgdi:waypoint x="705.4331577666419" y="407.4567570622598"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="judgeMore" id="BPMNEdge_judgeMore">
                <omgdi:waypoint x="287.29730895645025" y="327.65205479452055"></omgdi:waypoint>
                <omgdi:waypoint x="450.0" y="428.8888888888889"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="managerPassFlow" id="BPMNEdge_managerPassFlow">
                <omgdi:waypoint x="620.7588235294118" y="154.95"></omgdi:waypoint>
                <omgdi:waypoint x="713.8613704477151" y="390.96328050279476"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="userNotPassFlow" id="BPMNEdge_userNotPassFlow">
                <omgdi:waypoint x="609.95" y="339.5301886792453"></omgdi:waypoint>
                <omgdi:waypoint x="706.9383699359797" y="396.87411962686997"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="bossNotPassFlow" id="BPMNEdge_bossNotPassFlow">
                <omgdi:waypoint x="515.98" y="420.0"></omgdi:waypoint>
                <omgdi:waypoint x="544.0" y="349.95000000000005"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
            <bpmndi:BPMNEdge bpmnElement="managerNotPassFlow" id="BPMNEdge_managerNotPassFlow">
                <omgdi:waypoint x="595.438344721373" y="154.95"></omgdi:waypoint>
                <omgdi:waypoint x="567.9366337262223" y="270.0"></omgdi:waypoint>
            </bpmndi:BPMNEdge>
        </bpmndi:BPMNPlane>
    </bpmndi:BPMNDiagram>
</definitions>

第2至8行是一种样板文件,在大多数的流程定义中都是一样的。需要与BPMN 2.0标准规范完全一致。

每一个步骤(在BPMN 2.0术语中称作活动(activity))都有一个id属性,为其提供一个在XML文件中唯一的标识符。所有的活动都可以设置一个名字,以提高流程图的可读性。

活动之间通过顺序流(sequence flow)连接,在流程图中是一个有向箭头。在执行流程实例时,执行(execution)会从启动事件沿着顺序流流向下一个活动。

离开排他网关(带有X的菱形)的顺序流很特别:都以表达式(expression)的形式定义了条件(condition) (例:<![CDATA[${pass}]]>)。当流程实例的执行到达这个网关时,会计算条件,并使用第一个计算为true的顺序流。这就是排他的含义:只选择一个。当然如果需要不同的路由策略,可以使用其他类型的网关。

这里用作条件的表达式为${pass},这是${pass== true}的简写。变量’pass’被称作流程变量(process variable)。流程变量是持久化的数据,与流程实例存储在一起,并可以在流程实例的生命周期中使用。在这个例子里,我们需要在特定的地方(当经理用户任务提交时,或者以Flowable的术语来说,完成(complete)时)设置这个流程变量,因为这不是流程实例启动时就能获取的数据。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值