Processing of Activiti6 with 6 Parallel Gateway under Springboot

Posted by cainscripter on Wed, 09 Oct 2019 14:38:40 +0200

Explain

If parallel approval is required in the process, we can use parallel gateway to process, such as the following flow chart:

The xml information is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" id="Definitions_1n8y69f" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.2.3">
  <bpmn:process id="Process_2aplvep" name="Parallel gateway 2" isExecutable="true">
    <bpmn:startEvent id="StartEvent_1" name="start">
      <bpmn:outgoing>SequenceFlow_0c2pil9</bpmn:outgoing>
    </bpmn:startEvent>
    <bpmn:parallelGateway id="ExclusiveGateway_0844kui">
      <bpmn:incoming>SequenceFlow_1f2fg8q</bpmn:incoming>
      <bpmn:outgoing>SequenceFlow_1hmea8p</bpmn:outgoing>
      <bpmn:outgoing>SequenceFlow_1jugour</bpmn:outgoing>
    </bpmn:parallelGateway>
    <bpmn:sequenceFlow id="SequenceFlow_0c2pil9" sourceRef="StartEvent_1" targetRef="Task_1sngwtw" />
    <bpmn:sequenceFlow id="SequenceFlow_1hmea8p" sourceRef="ExclusiveGateway_0844kui" targetRef="Task_192utdd" />
    <bpmn:sequenceFlow id="SequenceFlow_1f2fg8q" sourceRef="Task_1sngwtw" targetRef="ExclusiveGateway_0844kui" />
    <bpmn:exclusiveGateway id="ExclusiveGateway_09fakrp">
      <bpmn:incoming>SequenceFlow_17aq8lk</bpmn:incoming>
      <bpmn:outgoing>SequenceFlow_1wtykc2</bpmn:outgoing>
      <bpmn:outgoing>SequenceFlow_1wig4cz</bpmn:outgoing>
    </bpmn:exclusiveGateway>
    <bpmn:sequenceFlow id="SequenceFlow_17aq8lk" sourceRef="Task_0cohxnk" targetRef="ExclusiveGateway_09fakrp" />
    <bpmn:sequenceFlow id="SequenceFlow_1wtykc2" name="Agree" sourceRef="ExclusiveGateway_09fakrp" targetRef="ExclusiveGateway_00xcx0f">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${status==1}</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:parallelGateway id="ExclusiveGateway_00xcx0f">
      <bpmn:incoming>SequenceFlow_1wtykc2</bpmn:incoming>
      <bpmn:incoming>SequenceFlow_007ko9l</bpmn:incoming>
      <bpmn:outgoing>SequenceFlow_11tofc3</bpmn:outgoing>
    </bpmn:parallelGateway>
    <bpmn:sequenceFlow id="SequenceFlow_007ko9l" sourceRef="Task_192utdd" targetRef="ExclusiveGateway_00xcx0f" />
    <bpmn:sequenceFlow id="SequenceFlow_11tofc3" sourceRef="ExclusiveGateway_00xcx0f" targetRef="Task_04q1eiq" />
    <bpmn:userTask id="Task_0cohxnk" name="ddd Approval" camunda:assignee="bbb">
      <bpmn:incoming>SequenceFlow_0m21w2m</bpmn:incoming>
      <bpmn:outgoing>SequenceFlow_17aq8lk</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:userTask id="Task_192utdd" name="ccc Joint trial" camunda:assignee="ccc">
      <bpmn:incoming>SequenceFlow_1hmea8p</bpmn:incoming>
      <bpmn:outgoing>SequenceFlow_007ko9l</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:userTask id="Task_04q1eiq" name="ddd Chief judge" camunda:assignee="ddd">
      <bpmn:incoming>SequenceFlow_11tofc3</bpmn:incoming>
      <bpmn:outgoing>SequenceFlow_1rhjcy1</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:userTask id="Task_1sngwtw" name="User submits application form" camunda:assignee="aaa">
      <bpmn:incoming>SequenceFlow_0c2pil9</bpmn:incoming>
      <bpmn:outgoing>SequenceFlow_1f2fg8q</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:endEvent id="EndEvent_1bb9yrt" name="End">
      <bpmn:incoming>SequenceFlow_1rhjcy1</bpmn:incoming>
    </bpmn:endEvent>
    <bpmn:sequenceFlow id="SequenceFlow_1rhjcy1" sourceRef="Task_04q1eiq" targetRef="EndEvent_1bb9yrt" />
    <bpmn:userTask id="Task_0sals6h" name="bbb Approval" camunda:assignee="bbb">
      <bpmn:incoming>SequenceFlow_1wig4cz</bpmn:incoming>
      <bpmn:incoming>SequenceFlow_1jugour</bpmn:incoming>
      <bpmn:outgoing>SequenceFlow_0m21w2m</bpmn:outgoing>
    </bpmn:userTask>
    <bpmn:sequenceFlow id="SequenceFlow_0m21w2m" sourceRef="Task_0sals6h" targetRef="Task_0cohxnk" />
    <bpmn:sequenceFlow id="SequenceFlow_1wig4cz" name="Reject" sourceRef="ExclusiveGateway_09fakrp" targetRef="Task_0sals6h">
      <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${status!=1}</bpmn:conditionExpression>
    </bpmn:sequenceFlow>
    <bpmn:sequenceFlow id="SequenceFlow_1jugour" sourceRef="ExclusiveGateway_0844kui" targetRef="Task_0sals6h" />
  </bpmn:process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_1">
    <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_2aplvep">
      <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
        <dc:Bounds x="122" y="322" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="129" y="365" width="23" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="ParallelGateway_1xoycei_di" bpmnElement="ExclusiveGateway_0844kui">
        <dc:Bounds x="375" y="315" width="50" height="50" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="SequenceFlow_0c2pil9_di" bpmnElement="SequenceFlow_0c2pil9">
        <di:waypoint x="158" y="340" />
        <di:waypoint x="220" y="340" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="SequenceFlow_1hmea8p_di" bpmnElement="SequenceFlow_1hmea8p">
        <di:waypoint x="400" y="365" />
        <di:waypoint x="400" y="490" />
        <di:waypoint x="480" y="490" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="SequenceFlow_1f2fg8q_di" bpmnElement="SequenceFlow_1f2fg8q">
        <di:waypoint x="320" y="340" />
        <di:waypoint x="375" y="340" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="ExclusiveGateway_09fakrp_di" bpmnElement="ExclusiveGateway_09fakrp" isMarkerVisible="true">
        <dc:Bounds x="755" y="195" width="50" height="50" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="SequenceFlow_17aq8lk_di" bpmnElement="SequenceFlow_17aq8lk">
        <di:waypoint x="720" y="220" />
        <di:waypoint x="755" y="220" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="SequenceFlow_1wtykc2_di" bpmnElement="SequenceFlow_1wtykc2">
        <di:waypoint x="780" y="245" />
        <di:waypoint x="780" y="340" />
        <di:waypoint x="825" y="340" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="784" y="290" width="22" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="ParallelGateway_0bzo5c0_di" bpmnElement="ExclusiveGateway_00xcx0f">
        <dc:Bounds x="825" y="315" width="50" height="50" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="SequenceFlow_007ko9l_di" bpmnElement="SequenceFlow_007ko9l">
        <di:waypoint x="580" y="490" />
        <di:waypoint x="850" y="490" />
        <di:waypoint x="850" y="365" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="SequenceFlow_11tofc3_di" bpmnElement="SequenceFlow_11tofc3">
        <di:waypoint x="875" y="340" />
        <di:waypoint x="930" y="340" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="UserTask_14wprwz_di" bpmnElement="Task_0cohxnk">
        <dc:Bounds x="620" y="180" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="UserTask_1rqfm55_di" bpmnElement="Task_192utdd">
        <dc:Bounds x="480" y="450" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="UserTask_1408z3i_di" bpmnElement="Task_04q1eiq">
        <dc:Bounds x="930" y="300" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="UserTask_0h4eaek_di" bpmnElement="Task_1sngwtw">
        <dc:Bounds x="220" y="300" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape id="EndEvent_1bb9yrt_di" bpmnElement="EndEvent_1bb9yrt">
        <dc:Bounds x="1082" y="322" width="36" height="36" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="1090" y="365" width="20" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="SequenceFlow_1rhjcy1_di" bpmnElement="SequenceFlow_1rhjcy1">
        <di:waypoint x="1030" y="340" />
        <di:waypoint x="1082" y="340" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNShape id="UserTask_0mp1d6n_di" bpmnElement="Task_0sals6h">
        <dc:Bounds x="480" y="180" width="100" height="80" />
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge id="SequenceFlow_0m21w2m_di" bpmnElement="SequenceFlow_0m21w2m">
        <di:waypoint x="580" y="220" />
        <di:waypoint x="620" y="220" />
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="SequenceFlow_1wig4cz_di" bpmnElement="SequenceFlow_1wig4cz">
        <di:waypoint x="780" y="195" />
        <di:waypoint x="780" y="110" />
        <di:waypoint x="550" y="110" />
        <di:waypoint x="550" y="180" />
        <bpmndi:BPMNLabel>
          <dc:Bounds x="654" y="92" width="22" height="14" />
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge id="SequenceFlow_1jugour_di" bpmnElement="SequenceFlow_1jugour">
        <di:waypoint x="400" y="315" />
        <di:waypoint x="400" y="210" />
        <di:waypoint x="480" y="210" />
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</bpmn:definitions>

Quick start

In fact, the implementation logic is very similar to the node data flow mode in the previous section. We only need to set process variables before and after parallel gateway to record information. The following chart shows the setting of process variables.

The concrete realization is as follows:

Write a complete Service that handles user submissions

    @Autowired
    private TaskService taskService;

    public BaseDTO complete(Task task, Integer status, Map<String, String> map) {
        System.out.println("User 8 service");
        /**
         * User logic is written here
         */

        map.put("taskId", task.getId());

        List<Map<String, String>> list = new ArrayList<>();
        TaskDTO taskDTO = new TaskDTO();
        taskDTO.setStatus(status);
        taskDTO.setAgreeId(task.getId());
        taskDTO.setRejectId("");
        list.add(map);
        taskDTO.setListMap(list);
        taskService.setVariable(task.getId(), "taskDTO", JSON.toJSONString(taskDTO));
        taskService.complete(task.getId());
        return null;
    }

complete Service approved by bbb

    @Autowired
    private TaskService taskService;

    public BaseDTO complete(Task task, Integer status, Map<String, String> map) {
        System.out.println("user bbb Of service");
        /**
         * User logic is written here
         */

        String taskDtoBeforeName="taskDTO";
        String taskDtoAfterName="taskDTO1";
        String str;
        // If the value can be obtained from the name of the process variable after use, the task is rejected. The process information should be taken from the id after use rather than from the id before parallel gateway. Otherwise, the id from the previous gateway will be taken from the id.
        if (null == taskService.getVariable(task.getId(), taskDtoAfterName))
            str = (String) taskService.getVariable(task.getId(), taskDtoBeforeName);
        else str = (String) taskService.getVariable(task.getId(), taskDtoAfterName);

        TaskDTO taskDTO = JSON.parseObject(str, TaskDTO.class);
        map.put("taskId", task.getId());
        HashMap<String, Object> variables = new HashMap<>();
        // Branch Conditional Judgment Rejection or Consent
        variables.put("status", status);
        taskDTO.setStatus(status);
        // Disagree 0-agree 1
        if (status == 0) {
            taskDTO.setRejectId(task.getId());
            taskDTO.setAgreeId("");
        } else {
            taskDTO.setAgreeId(task.getId());
            taskDTO.setRejectId("");
        }
        taskDTO.getListMap().add(map);
        taskService.setVariable(task.getId(), taskDtoAfterName, JSON.toJSONString(taskDTO));
        taskService.complete(task.getId(), variables);
        return null;
    }

ddd approval is similar to bbb approval, not written

ccc approval only modifies taskDtoAfterName to taskDTO 2 and does not repeat

ddd general audit is also in accordance with the original way to go, need to obtain the data of the front node can be obtained through the following way

taskService.getVariable(task.getId(), "taskDTO1");
taskService.getVariable(task.getId(), "taskDTO2");

The above changes to the key Activiti table are:

act_ru_variable: A table of process variables being executed
act_hi_varinst: Process variable history table

The parallel gateway has been processed. In the next section, we will talk about the operation o() of the group.

Topics: JSON xml encoding