<?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="excelusiveGateWay" name="excelusiveGateWay" isExecutable="true">
<startEvent id="startevent1" name="Start"></startEvent>
<userTask id="usertask1" name="审批【部门经理】" activiti:assignee="赵小六"></userTask>
<userTask id="usertask2" name="财务" activiti:assignee="胡小八"></userTask>
<userTask id="usertask3" name="审批【总经理】" activiti:assignee="田小七"></userTask>
<userTask id="usertask4" name="费用报销申请" activiti:assignee="王小五"></userTask>
<sequenceFlow id="flow1" sourceRef="startevent1" targetRef="usertask4"></sequenceFlow>
<exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway" default="默认执行财务"></exclusiveGateway>
<sequenceFlow id="flow2" sourceRef="usertask4" targetRef="exclusivegateway1"></sequenceFlow>
<sequenceFlow id="flow3" name="金额小于等于1000,大于等于500" sourceRef="exclusivegateway1" targetRef="usertask1">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${money>=500 && money<=1000}]]></conditionExpression>
</sequenceFlow>
<sequenceFlow id="默认执行财务" name="默认执行财务" sourceRef="exclusivegateway1" targetRef="usertask2"></sequenceFlow>
<sequenceFlow id="flow5" name="金额大于1000元" sourceRef="exclusivegateway1" targetRef="usertask3">
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${money>1000}]]></conditionExpression>
</sequenceFlow>
<endEvent id="endevent1" name="End"></endEvent>
<sequenceFlow id="flow6" sourceRef="usertask1" targetRef="endevent1"></sequenceFlow>
<sequenceFlow id="flow7" sourceRef="usertask2" targetRef="endevent1"></sequenceFlow>
<sequenceFlow id="flow8" sourceRef="usertask3" targetRef="endevent1"></sequenceFlow>
</process>
<bpmndi:BPMNDiagram id="BPMNDiagram_excelusiveGateWay">
<bpmndi:BPMNPlane bpmnElement="excelusiveGateWay" id="BPMNPlane_excelusiveGateWay">
<bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
<omgdc:Bounds height="35.0" width="35.0" x="390.0" y="10.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
<omgdc:Bounds height="55.0" width="105.0" x="90.0" y="300.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
<omgdc:Bounds height="55.0" width="105.0" x="355.0" y="300.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3">
<omgdc:Bounds height="55.0" width="105.0" x="610.0" y="300.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="usertask4" id="BPMNShape_usertask4">
<omgdc:Bounds height="55.0" width="105.0" x="355.0" y="90.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="BPMNShape_exclusivegateway1">
<omgdc:Bounds height="40.0" width="40.0" x="387.0" y="190.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
<omgdc:Bounds height="35.0" width="35.0" x="390.0" y="450.0"></omgdc:Bounds>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
<omgdi:waypoint x="407.0" y="45.0"></omgdi:waypoint>
<omgdi:waypoint x="407.0" y="90.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
<omgdi:waypoint x="407.0" y="145.0"></omgdi:waypoint>
<omgdi:waypoint x="407.0" y="190.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
<omgdi:waypoint x="407.0" y="230.0"></omgdi:waypoint>
<omgdi:waypoint x="142.0" y="300.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="42.0" width="100.0" x="231.0" y="222.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="默认执行财务" id="BPMNEdge_默认执行财务">
<omgdi:waypoint x="407.0" y="230.0"></omgdi:waypoint>
<omgdi:waypoint x="407.0" y="300.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="14.0" width="100.0" x="370.0" y="269.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
<omgdi:waypoint x="407.0" y="230.0"></omgdi:waypoint>
<omgdi:waypoint x="662.0" y="300.0"></omgdi:waypoint>
<bpmndi:BPMNLabel>
<omgdc:Bounds height="14.0" width="100.0" x="510.0" y="250.0"></omgdc:Bounds>
</bpmndi:BPMNLabel>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
<omgdi:waypoint x="142.0" y="355.0"></omgdi:waypoint>
<omgdi:waypoint x="407.0" y="450.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
<omgdi:waypoint x="407.0" y="355.0"></omgdi:waypoint>
<omgdi:waypoint x="407.0" y="450.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
<bpmndi:BPMNEdge bpmnElement="flow8" id="BPMNEdge_flow8">
<omgdi:waypoint x="662.0" y="355.0"></omgdi:waypoint>
<omgdi:waypoint x="407.0" y="450.0"></omgdi:waypoint>
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</definitions>
package com.ljw.b_excelusiveGateWay;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.Test;
/**
* 排他网关
* @author lenovo
*
*/
public class excelusiveGateWayTest {
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
// 部署流程定义(classpath)
@Test
public void deploymentProcessDefinition_inputStream() {
InputStream bpmn = this.getClass().getResourceAsStream("excelusiveGateWay.bpmn");
InputStream png = this.getClass().getResourceAsStream("excelusiveGateWay.png");
Deployment deployment = processEngine.getRepositoryService()// 与流程定义和部署对象相关的sevices
.createDeployment()// 创建一个部署对象
.name("排他网关")// 添加部署名称
.addInputStream("excelusiveGateWay.bpmn", bpmn)
.addInputStream("excelusiveGateWay.png", png)
.deploy();
System.out.println("部署ID:" + deployment.getId());
System.out.println("部署名称:" + deployment.getName());
}
// 启动流程实例
@Test
public void deploymentProcessInstance() {
String key = "excelusiveGateWay";
ProcessInstance pi = processEngine.getRuntimeService()// 与正在执行的流程是咧和执行对象相关的services
.startProcessInstanceByKey(key);// 使用流程定义的key启动流程实例key对呀的helloworld.bnpm文件里的id的属性值
System.out.println("流程实例ID:" + pi.getId());
System.out.println("流程定义ID:" + pi.getProcessDefinitionId());
}
// 查询当前人的个人任务
@Test
public void findMyPersonalTask() {
String assingnee = "胡小八";
List<Task> list = processEngine.getTaskService()// 与正在执行的任务管理相关的services
.createTaskQuery()// 创建任务查询对象
/** 查询条件(where部分) */
.taskAssignee(assingnee)// 指定个人任务查询,指定
// .taskCandidateUser(candidateUser)//组任务的班里人查询
// .processDefinitionId(processDefinitionId)//使用流程定义ID查询
// .processInstanceId(processInstanceId)//使用流程实例额ID查询
// .executionId(executionId)//使用执行对象ID查询
/** 排序 */
.orderByTaskCreateTime().asc()// 创建时间升序排序
/** 返回结果集 */
// .singleResult()//返回唯一结果集
// .count()//返回结果集的数量
// .listPage(firstResult, maxResults)//分页查询
.list();
if (list != null && list.size() > 0) {
for (Task task : list) {
System.out.println("任务ID:" + task.getId());
System.out.println("任务名称:" + task.getName());
System.out.println("任务的创建时间:" + task.getCreateTime());
System.out.println("任务的办理人:" + task.getAssignee());
System.out.println("流程实例ID:" + task.getProcessInstanceId());
System.out.println("执行对象ID:" + task.getExecutionId());
System.out.println("流程定义ID:" + task.getProcessDefinitionId());
}
}
}
// 完成我的任务
@Test
public void completeMyPersonalTask() {
// 任务ID
String taskId = "105004";
//完成任务的同时,设置流程变量,使用流程变量用来指定完成任务后,下一个连线,对应sequenceFlow.bpmn文件中${money>1000}
Map<String, Object> variables=new HashMap<String, Object>();
variables.put("money", 200);
processEngine.getTaskService()// 与正在执行的任务管理相关的services
.complete(taskId,variables);
System.out.println("任务完成,任务ID:" + taskId);
}
}