默認路徑java
表達式:this
<process id="exclusiveGateWay" name="exclusiveGateWayProcess" isExecutable="true"> <startEvent id="startevent1" name="Start"></startEvent> <userTask id="usertask1" name="費用報銷申請" activiti:assignee="王小五"></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" default="默認執行財務"></exclusiveGateway> <sequenceFlow id="flow2" sourceRef="usertask1" targetRef="exclusivegateway1"></sequenceFlow> <sequenceFlow id="flow3" name="金額小於等於1000,大於等於500" sourceRef="exclusivegateway1" targetRef="usertask2"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${money>=500 && money<=1000}]]></conditionExpression> </sequenceFlow> <sequenceFlow id="默認執行財務" name="默認執行財務" sourceRef="exclusivegateway1" targetRef="usertask3"></sequenceFlow> <sequenceFlow id="flow5" name="金額大於1000元" sourceRef="exclusivegateway1" targetRef="usertask4"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${money>1000}]]></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> </process>
3.代碼:spa
public class ExclusiveGateWayTest { ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); /**部署流程定義(從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());// } /**啓動流程實例*/ @Test public void startProcessInstance(){ //流程定義的key String processDefinitionKey = "exclusiveGateWay"; ProcessInstance pi = processEngine.getRuntimeService()//與正在執行的流程實例和執行對象相關的Service .startProcessInstanceByKey(processDefinitionKey);//使用流程定義的key啓動流程實例,key對應helloworld.bpmn文件中id的屬性值,使用key值啓動,默認是按照最新版本的流程定義啓動 System.out.println("流程實例ID:"+pi.getId());//流程實例ID 101 System.out.println("流程定義ID:"+pi.getProcessDefinitionId());//流程定義ID helloworld:1:4 } /**查詢當前人的我的任務*/ @Test public void findMyPersonalTask(){ String assignee = "王小五"; List<Task> list = processEngine.getTaskService()//與正在執行的任務管理相關的Service .createTaskQuery()//建立任務查詢對象 /**查詢條件(where部分)*/ .taskAssignee(assignee)//指定我的任務查詢,指定辦理人 // .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()); System.out.println("########################################################"); } } /* 任務ID:25004 任務名稱:費用報銷申請 任務的建立時間:Tue Jan 10 13:29:40 CST 2017 任務的辦理人:王小五 流程實例ID:25001 執行對象ID:25001 流程定義ID:exclusiveGateWay:1:22504 ######################################################## */ } /**完成個人任務*/ @Test public void completeMyPersonalTask(){ //任務ID String taskId = "45004"; //完成任務的同時,設置流程變量,使用流程變量用來指定完成任務後,下一個連線,對應exclusiveGateWay.bpmn文件中${money>1000} Map<String, Object> variables = new HashMap<String, Object>(); variables.put("money", 1200); processEngine.getTaskService()//與正在執行的任務管理相關的Service .complete(taskId,variables); System.out.println("完成任務:任務ID:"+taskId); } }