exclusiveGateWay.bpmn
设置连线判断条件
设置id和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:activiti="http://activiti.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.activiti.org/test">
<process id="exclusiveGateWay" name="exclusiveGateWayProcess" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<userTask id="usertask1" name="请假申请" activiti:assignee="员工A"></userTask>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
<userTask id="usertask2" name="组长审批" activiti:assignee="小黄"></userTask>
<userTask id="usertask3" name="部门经理审批" activiti:assignee="陈经理"></userTask>
<userTask id="usertask4" name="总经理审批" activiti:assignee="陈总裁"></userTask>
<exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway"></exclusiveGateway>
<sequenceFlow id="flow2" sourceRef="usertask1" targetRef="exclusivegateway1"></sequenceFlow>
<sequenceFlow id="flow5" name="大于7天" sourceRef="exclusivegateway1" targetRef="usertask4">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${day>7}]]></conditionExpression>
</sequenceFlow>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow6" sourceRef="usertask2" targetRef="endevent1"></sequenceFlow>
<sequenceFlow id="flow7" sourceRef="usertask3" targetRef="endevent1"></sequenceFlow>
<sequenceFlow id="flow8" sourceRef="usertask4" targetRef="endevent1"></sequenceFlow>
<sequenceFlow id="flow9" name="小于7天" sourceRef="exclusivegateway1" targetRef="usertask3">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${day<7&&day>2}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="flow10" name="小于2天" sourceRef="exclusivegateway1" targetRef="usertask2">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${day<2}]]></conditionExpression>
</sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_exclusiveGateWay">
<bpmndi:BPMNPlane bpmnElement="exclusiveGateWay" id="BPMNPlane_exclusiveGateWay">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="340.0" y="50.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="105.0" x="305.0" y="140.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
<omgdc:Bounds height="55.0" width="105.0" x="80.0" y="390.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3">
<omgdc:Bounds height="55.0" width="105.0" x="305.0" y="390.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask4" id="BPMNShape_usertask4">
<omgdc:Bounds height="55.0" width="105.0" x="550.0" y="380.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="BPMNShape_exclusivegateway1">
<omgdc:Bounds height="40.0" width="40.0" x="337.0" y="260.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="340.0" y="560.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="357.0" y="85.0"></omgdi:waypoint>
<omgdi:waypoint x="357.0" y="140.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="357.0" y="195.0"></omgdi:waypoint>
<omgdi:waypoint x="357.0" y="260.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
<omgdi:waypoint x="357.0" y="300.0"></omgdi:waypoint>
<omgdi:waypoint x="602.0" y="380.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="14.0" width="42.0" x="436.0" y="330.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
<omgdi:waypoint x="132.0" y="445.0"></omgdi:waypoint>
<omgdi:waypoint x="357.0" y="560.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
<omgdi:waypoint x="357.0" y="445.0"></omgdi:waypoint>
<omgdi:waypoint x="357.0" y="560.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow8" id="BPMNEdge_flow8">
<omgdi:waypoint x="602.0" y="435.0"></omgdi:waypoint>
<omgdi:waypoint x="357.0" y="560.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow9" id="BPMNEdge_flow9">
<omgdi:waypoint x="357.0" y="300.0"></omgdi:waypoint>
<omgdi:waypoint x="357.0" y="390.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="14.0" width="42.0" x="368.0" y="332.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow10" id="BPMNEdge_flow10">
<omgdi:waypoint x="357.0" y="300.0"></omgdi:waypoint>
<omgdi:waypoint x="132.0" y="390.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="14.0" width="100.0" x="227.0" y="328.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
测试的数据
/**部署流程定义(从inputStream)*/
@Test
public void deploymentProcessDefinition_inputStream(){
InputStream inputStreamBpmn = this.getClass().getResourceAsStream("exclusiveGateWay.bpmn");
InputStream inputStreamPng = this.getClass().getResourceAsStream("exclusiveGateWay.png");
Deployment deployment = processEngine.getRepositoryService()//与流程定义和部署对象相关的Service
.createDeployment()//创建一个部署对象
.name("排他网关")//添加部署的名称
.addInputStream("exclusiveGateWay.bpmn", inputStreamBpmn)//
.addInputStream("exclusiveGateWay.png", inputStreamPng)//
.deploy();//完成部署
System.out.println("部署ID:"+deployment.getId());
System.out.println("部署名称:"+deployment.getName());
System.out.println("部署时间:"+deployment.getDeploymentTime());
// 部署ID:2901
// 部署名称:排他网关
// 部署时间:Wed Sep 06 20:49:24 CST 2017
}
/**启动流程实例*/
@Test
public void startProcessInstance(){
//流程定义的key.,key对应helloworld.bpmn文件中id的属性值,使用key值启动,默认是按照最新版本的流程定义启动
String processDefinitionKey = "exclusiveGateWay";
ProcessInstance pi = processEngine.getRuntimeService()//与正在执行的流程实例和执行对象相关的Service
.startProcessInstanceByKey(processDefinitionKey);//使用流程定义的key启动流程实例,
System.out.println("流程实例ID:"+pi.getId());//
System.out.println("流程定义ID:"+pi.getProcessDefinitionId());//
// 流程实例ID:3001
// 流程定义ID:exclusiveGateWay:1:2904
}
测试
用户已经走到请假申请节点,下面用户完成请假申请节点任务,并通过设置变量day来设置走哪条路线。
完成任务,设置变量
/**完成我的任务*/
@Test
public void completeMyPersonalTask(){
//任务ID
String taskId = "3004";
//完成任务的同时,设置流程变量,使用流程变量用来指定完成任务后,下一个连线,对应exclusiveGateWay.bpmn文件中${money>1000}
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("day", 4);//走陈经理审批节点
processEngine.getTaskService()//与正在执行的任务管理相关的Service
.complete(taskId,variables);
System.out.println("完成任务:任务ID:"+taskId);
// 完成任务:任务ID:3004
}
查看数据库任务
可以看到任务走到陈经理,而陈经理就是能处理请假天数在2到7天的人。流程没有走错。