Introduction to Activiti7

Hello, everyone, I'm your CodeWorld. I'm busy recently. I haven't updated the article for a long time. Today, I'll give you a teaching of Activiti7
Don't say much, go straight to the

Opening premise

First of all, we need to know what Activiti is, how it is used and what problems it solves

Activiti introduction

What is workflow

Workflow is the automatic execution and management of business processes through computers. It mainly solves "the process of automatically transferring documents, information or tasks among multiple participants according to some predefined rules, so as to achieve an expected business goal or promote the realization of this goal".
In short, it is a task level relationship. If we have an employee asking for leave, he needs to fill in the leave request form - "submit application -" team leader approval - "manager approval -" boss approval. Such a process is called workflow. After the superior completes, it will automatically flow to the subordinate.

What is workflow system

A software system has the function of workflow. We call it workflow system.

Workflow usage scenarios

  • Key business processes: order, quotation processing, contract review, customer telephone processing, supply chain management, etc.
  • Administrative management: business trip application, overtime application, leave application, vehicle application, various office supplies application, purchase application, daily and weekly report and other administrative forms that were originally processed manually.
  • Finance related: payment application, reimbursement processing, budget plan approval, etc
    There are many scenarios that use workflow

Why learn workflow

Custom workflow

Employee leave cases:
Step 1: employees submit applications (status is set to 1)
Step 2: approved by the team leader (status is set to 2)
Step 3: the team leader fails to approve (status is set to 3)
Step 4: approved by the manager (status is set to 4)
Step 5: manager fails to approve (status is set to 5)
Step 6: approved by the boss (status is set to 6)
Step 7: boss fails to approve (status is set to 7)
. . . .
If there are a lot of task audit processes, we will set a lot of states. In this way, the coupling is very high. If the process changes, increase the audit level or remove a certain audit level, it is really a headache to change the code. Coupled with various state judgments, people are stupid

It's still written. Let's run away

When we encounter this situation, Activiti comes in handy and can solve the problems we encounter. When an employee submits a leave application, if it is approved by the team leader, it will be automatically transferred to the manager for approval; If the team leader fails to pass the review, it will automatically flow to the employee and fill in and submit again.
This solves the coupling of our code. If the process changes again, we only need to modify the flowchart.

Principle of workflow implementation

We can clearly see that each process corresponds to a record and is saved in our database. When we delete or add a process, it has nothing to do with our state.

Use steps

  • Introducing Activiti: Activiti is actually an open source framework developed in java. We should first use the corresponding pom dependency, and then we can operate through the classes and interfaces provided by Activiti
  • Process definition: use special process modeling tools to define the process and express the whole process in a graphical way. For example, both idea and eclipse have corresponding Activiti and corresponding processes.
  • Deployment of process definition: store the process drawn with tools. In fact, this process is transformed into specific data and stored in mysql.
  • Start a process instance: that is, start the operation of a business process. For example, Xiao Ming and Xiao Hong have to ask for leave. After they fill in the leave application, the system should start a process instance for both of them. Different process instances do not affect each other.
  • Users query to-do tasks: a task needs to go through multiple participants. Now where the task has arrived and who should handle it, we need to query it at this time. However, because we use Activiti, we don't need to write sql to query. We can directly use the interface provided by Activiti.
  • User handling task: after querying the to-do task, users can handle a task. If this task is completed, other users need to handle it. For example, after the purchase order is created, it is approved by the Department Manager. This process is also completed with the help of Activiti.

What is BPMN

BPMN defines a Business flow chart (Business Process Diagram), which is based on a flow chart designed to create a graphical model of business process operations. A Business Process Model refers to a mesh diagram composed of graphical objects, including activities and flow controls used to define the execution order of these activities

For example, this is the BPMN we draw

Let's look at the xml file again

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" 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" xmlns:tns="http://www.activiti.org/test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" expressionLanguage="http://www.w3.org/1999/XPath" id="m1639040573404" name="" targetNamespace="http://www.activiti.org/test" typeLanguage="http://www.w3.org/2001/XMLSchema">
  <process id="myProcess_1" isClosed="false" isExecutable="true" processType="None">
    <startEvent id="_2" name="start"/>
    <userTask activiti:exclusive="true" id="_3" name="Submit application"/>
    <sequenceFlow id="_4" sourceRef="_2" targetRef="_3"/>
    <userTask activiti:exclusive="true" id="_5" name="Group leader approval"/>
    <sequenceFlow id="_6" sourceRef="_3" targetRef="_5"/>
    <userTask activiti:exclusive="true" id="_7" name="Manager approval"/>
    <sequenceFlow id="_8" sourceRef="_5" targetRef="_7"/>
    <userTask activiti:exclusive="true" id="_9" name="Boss approval"/>
    <sequenceFlow id="_10" sourceRef="_7" targetRef="_9"/>
    <endEvent id="_11" name="end"/>
    <sequenceFlow id="_12" sourceRef="_9" targetRef="_11"/>
  </process>
  <bpmndi:BPMNDiagram documentation="background=#3C3F41;count=1;horizontalcount=1;orientation=0;width=842.4;height=1195.2;imageableWidth=832.4;imageableHeight=1185.2;imageableX=5.0;imageableY=5.0" id="Diagram-_1" name="New Diagram">
    <bpmndi:BPMNPlane bpmnElement="myProcess_1">
      <bpmndi:BPMNShape bpmnElement="_2" id="Shape-_2">
        <omgdc:Bounds height="32.0" width="32.0" x="325.0" y="20.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_3" id="Shape-_3">
        <omgdc:Bounds height="55.0" width="85.0" x="305.0" y="110.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_5" id="Shape-_5">
        <omgdc:Bounds height="55.0" width="85.0" x="310.0" y="220.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_7" id="Shape-_7">
        <omgdc:Bounds height="55.0" width="85.0" x="310.0" y="315.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_9" id="Shape-_9">
        <omgdc:Bounds height="55.0" width="85.0" x="315.0" y="420.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="_11" id="Shape-_11">
        <omgdc:Bounds height="32.0" width="32.0" x="340.0" y="530.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="_12" id="BPMNEdge__12" sourceElement="_9" targetElement="_11">
        <omgdi:waypoint x="356.0" y="475.0"/>
        <omgdi:waypoint x="356.0" y="530.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_4" id="BPMNEdge__4" sourceElement="_2" targetElement="_3">
        <omgdi:waypoint x="341.0" y="52.0"/>
        <omgdi:waypoint x="341.0" y="110.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_6" id="BPMNEdge__6" sourceElement="_3" targetElement="_5">
        <omgdi:waypoint x="350.0" y="165.0"/>
        <omgdi:waypoint x="350.0" y="220.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_8" id="BPMNEdge__8" sourceElement="_5" targetElement="_7">
        <omgdi:waypoint x="352.5" y="275.0"/>
        <omgdi:waypoint x="352.5" y="315.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="_10" id="BPMNEdge__10" sourceElement="_7" targetElement="_9">
        <omgdi:waypoint x="355.0" y="370.0"/>
        <omgdi:waypoint x="355.0" y="420.0"/>
        <bpmndi:BPMNLabel>
          <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/>
        </bpmndi:BPMNLabel>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

In this way, our flow chart is created. Let's start the code
We'll talk about it in the next section

OK, that's all for the technical analysis. If you think it's good, light up the little star codeworld-cloud-shop
I'm not a good boy if I just don't see something!!

Welcome to QQ group (964285437)

Welcome to the official account.

Keywords: Java Spring Boot

Added by Ajdija on Thu, 09 Dec 2021 12:46:56 +0200