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>

Activiti工作流--并行网关--之九_第1张图片

启动流程
@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("流程执行完毕");
	}
}
总结

并行网关的分支和汇聚都是同一个图元符号(图标)
并行网关不会解析条件,所以流程变量的设置不会引起流程的其他选择
并行网关的分支里面可以再进行分支和聚合

【上一篇:Activiti工作流–流程变量的应用之二:排他网关–之八】
【下一篇:Activiti工作流–任务的分配–之十】

你可能感兴趣的:(Activiti工作流)