1. 程式人生 > >Activiti工作流--並行閘道器--之九

Activiti工作流--並行閘道器--之九

流程的業務描述 會議記錄會籤

並行閘道器是不需要設定流程變數的,並行閘道器不在流程變數的範圍內

比如: 在開完某個產品設計會以後,需要對會議約定一些事項進行簽字畫押涉及到兩個部門(產品部/研發部)的主管和經理 確認的順序: a:產品部的主管確認然後產品部的經理確認 b:研發部的主管確認 然後研發部的經理確認 注意:以上兩個處理步驟可以同時進行,都完成以後,代表流程結束

先獲取連線

private ProcessEngine processEngine;
	
@Before
public void intiProcessEngine(){
	processEngine = ProcessEngines.
getDefaultProcessEngine(); }
流程定義與部署
@Test
public void testProcessEngine(){
	Deployment deployment = processEngine.getRepositoryService()
								.createDeployment()
								.addClasspathResource("diagram/parallelGateWay.bpmn")
								.addClasspathResource("diagram/parallelGateWay.png")
								.name
("並行會籤") .deploy(); System.out.println("流程部署ID:"+deployment.getId());//152501 System.out.println("流程部署名稱:"+deployment.getName()); }

流程圖 parallelGateWay.bpmn程式碼

<?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="parallelGateWay" name="parallelGateWayProcess" isExecutable="true"> <startEvent id="startevent1" name="Start"></startEvent> <parallelGateway id="parallelgateway1" name="Parallel Gateway"></parallelGateway> <sequenceFlow id="flow1" sourceRef="startevent1" targetRef="parallelgateway1"></sequenceFlow> <userTask id="usertask1" name="產品主管確認" activiti:assignee="張三"></userTask> <sequenceFlow id="flow2" sourceRef="parallelgateway1" targetRef="usertask1"></sequenceFlow> <userTask id="usertask2" name="研發主管確認" activiti:assignee="王五"></userTask> <sequenceFlow id="flow3" sourceRef="parallelgateway1" targetRef="usertask2"></sequenceFlow> <userTask id="usertask3" name="產品經理確認" activiti:assignee="李四"></userTask> <sequenceFlow id="flow4" sourceRef="usertask1" targetRef="usertask3"></sequenceFlow> <userTask id="usertask4" name="研發經理確認" activiti:assignee="趙六"></userTask> <sequenceFlow id="flow5" sourceRef="usertask2" targetRef="usertask4"></sequenceFlow> <parallelGateway id="parallelgateway2" name="Parallel Gateway"></parallelGateway> <sequenceFlow id="flow6" sourceRef="usertask3" targetRef="parallelgateway2"></sequenceFlow> <sequenceFlow id="flow7" sourceRef="usertask4" targetRef="parallelgateway2"></sequenceFlow> <endEvent id="endevent1" name="End"></endEvent> <sequenceFlow id="flow8" sourceRef="parallelgateway2" targetRef="endevent1"></sequenceFlow> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_parallelGateWay"> <bpmndi:BPMNPlane bpmnElement="parallelGateWay" id="BPMNPlane_parallelGateWay"> <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1"> <omgdc:Bounds height="35.0" width="35.0" x="80.0" y="160.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="parallelgateway1" id="BPMNShape_parallelgateway1"> <omgdc:Bounds height="40.0" width="40.0" x="160.0" y="158.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1"> <omgdc:Bounds height="55.0" width="105.0" x="240.0" y="60.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2"> <omgdc:Bounds height="55.0" width="105.0" x="240.0" y="240.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="usertask3" id="BPMNShape_usertask3"> <omgdc:Bounds height="55.0" width="105.0" x="390.0" y="60.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="usertask4" id="BPMNShape_usertask4"> <omgdc:Bounds height="55.0" width="105.0" x="390.0" y="240.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="parallelgateway2" id="BPMNShape_parallelgateway2"> <omgdc:Bounds height="40.0" width="40.0" x="540.0" y="158.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1"> <omgdc:Bounds height="35.0" width="35.0" x="625.0" y="161.0"></omgdc:Bounds> </bpmndi:BPMNShape> <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1"> <omgdi:waypoint x="115.0" y="177.0"></omgdi:waypoint> <omgdi:waypoint x="160.0" y="178.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2"> <omgdi:waypoint x="180.0" y="158.0"></omgdi:waypoint> <omgdi:waypoint x="292.0" y="115.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3"> <omgdi:waypoint x="180.0" y="198.0"></omgdi:waypoint> <omgdi:waypoint x="292.0" y="240.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4"> <omgdi:waypoint x="345.0" y="87.0"></omgdi:waypoint> <omgdi:waypoint x="390.0" y="87.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5"> <omgdi:waypoint x="345.0" y="267.0"></omgdi:waypoint> <omgdi:waypoint x="390.0" y="267.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6"> <omgdi:waypoint x="442.0" y="115.0"></omgdi:waypoint> <omgdi:waypoint x="560.0" y="158.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7"> <omgdi:waypoint x="442.0" y="240.0"></omgdi:waypoint> <omgdi:waypoint x="560.0" y="198.0"></omgdi:waypoint> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="flow8" id="BPMNEdge_flow8"> <omgdi:waypoint x="580.0" y="178.0"></omgdi:waypoint> <omgdi:waypoint x="625.0" y="178.0"></omgdi:waypoint> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>

流程圖

啟動流程
@Test
public void testStartTask(){
	String processDefinitionKey = "parallelGateWay";
	ProcessInstance processInstance = processEngine.getRuntimeService()
			.startProcessInstanceByKey(processDefinitionKey);
	System.out.println("流程部署ID:"+processInstance.getDeploymentId());
	System.out.println("流程定義ID:"+processInstance.getProcessDefinitionId());
	System.out.println("流程例項ID:"+processInstance.getProcessInstanceId());//155001
}
查詢個人,完成個人任務
/**
 * 流程處理過程:查詢個人任務
 */
@Test
public void testTaskQuery(){
	String assignee = "趙六";
	String processInstanceId = "155001";
	List<Task> taskList = processEngine.getTaskService()
							.createTaskQuery()
							.taskAssignee(assignee)
							.processInstanceId(processInstanceId)
							.list();
	if (taskList != null && taskList.size() > 0) {
		for (Task task : taskList) {
			System.out.println("流程定義ID:"+task.getProcessDefinitionId());
			System.out.println("流程例項ID:"+task.getProcessInstanceId());
			System.out.println("執行物件ID:"+task.getExecutionId());
			System.out.println("任務ID:"+task.getId());//155007
			System.out.println("任務名稱:"+task.getName());
			System.out.println("任務建立時間:"+task.getCreateTime());
		}
	}
}

/**
 * 流程處理過程:完成個人任務
 */
@Test
public void testCompleteTask(){
	String taskId = "162502";
	processEngine.getTaskService().complete(taskId);
	System.out.println("財務主管審批完成");
}

/**
 * 在流程的執行過程中,我們需要查詢流程執行到了哪一個狀態
 * 查詢的是act_ru_execution  流程例項表
 * 當流程結束了  那麼在act_ru_execution 在這張表中就沒有了資料記錄
 */
@Test
public void testQueryProinsatanceState(){
	String processInstanceId = "155001";
	ProcessInstance singleResult = processEngine.getRuntimeService()
										.createProcessInstanceQuery()
										.processInstanceId(processInstanceId)
										.singleResult();
	if (singleResult != null) {
		System.out.println("流程執行到:"+singleResult.getActivityId());
	}else{
		System.out.println("流程執行完畢");
	}
}
總結

並行閘道器的分支和匯聚都是同一個圖元符號(圖示) 並行閘道器不會解析條件,所以流程變數的設定不會引起流程的其他選擇 並行閘道器的分支裡面可以再進行分支和聚合