Activiti Workflow Getting Started + Source Code

definition

Workflow is "the automation of part or the whole of the business process in the computer application environment", which mainly solves the problem of "transmitting documents, information or tasks among multiple participants according to certain predefined rules". process automatically in order to achieve, or facilitate the achievement of, some desired business objective.”

Automatically generate data tables

Activiti can automatically create the required 23 tables through code. 

Run the following main method to automatically create the tables required by Activiti.

package com.xsz.demo;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;

public class InitActiviti {

    public static void main(String[] args) throws Exception {

        ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
        //定义连接mysql数据库
        configuration.setJdbcDriver("com.mysql.cj.jdbc.Driver");
        configuration.setJdbcUrl("jdbc:mysql://localhost:3306/db_activitidemo?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true");
        configuration.setJdbcUsername("root");
        configuration.setJdbcPassword("XSZ202006a");

       /*  public static final String DB_SCHEMA_UPDATE_FALSE = "false";操作activiti23张表的时候,如果表不存在,就抛出异常,不能自动创建23张表
         public static final String DB_SCHEMA_UPDATE_CREATE_DROP = "create-drop";每次操作,都会先删除表,再创建表
         public static final String DB_SCHEMA_UPDATE_TRUE = "true";
         如果表不存在,就创建表,如果表存在,就直接操作		*/

        configuration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_CREATE_DROP);
        //activiti核心对象(流程引擎)
        ProcessEngine processEngine = configuration.buildProcessEngine();
        System.out.println("processEngine:"+processEngine);

    }
}

Data Sheet Introduction

Table structure operation:

3.3.1: Repository process rule table
1) act_re_deployment deployment information table

2) act_re_model process design model deployment table

3) act_re_procdef process definition data table

3.3.2: runtime database table
1) act_ru_execution runtime process execution instance table

2) act_ru_identitylink runtime process personnel table, which mainly stores information about task nodes and participants

3) act_ru_task runtime task node table

4) act_ru_variable runtime process variable data table

3.3.3: Historical database table
1) act_hi_actinst historical node table

2) act_hi_attachment historical attachment table

3) act_hi_comment historical comment form

4) act_hi_identitylink historical process personnel table

5) act_hi_detail historical detail table, providing query of historical variables

6) act_hi_procinst historical process instance table

7) act_hi_taskinst historical task instance table

8) act_hi_varinst historical variable table

3.3.4: Organization table
1) act_id_group user group information table

2) act_id_info user extension information table

3) act_id_membership user and user group corresponding information table

4) act_id_user user information table

These four tables are very common. For basic organizational management, it is recommended to develop a set of user authentication. The functions of the components are too simple, and there are many needs that are difficult to meet in use.

3.3.5: General data table
1) act_ge_bytearray binary data table

2) The act_ge_property attribute data table stores the data of the entire process engine level. When the table structure is initialized, three records will be inserted by default.

get bpmn file

You can draw the business process through the drawing tool, and then export the xml file. Then change the suffix of the xml file to bpmn.

The content of the final exported bpmn file

File name: process.bpmn20.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/processdef">
  <process id="process2021729" isExecutable="true">
    <startEvent id="start"/>
    <exclusiveGateway id="sid-8F55A260-8EB3-415D-A873-2E34E916216E"/>
    <userTask id="sid-3D71CBED-A50E-4B50-A4D2-D20763A51D66" name="经理审批2" activiti:candidateGroups="manageGroup"/>
    <userTask id="sid-850B7D8F-AABD-49FE-9CFB-843513146281" name="总监审批2" activiti:candidateGroups="dirGroup"/>
    <endEvent id="sid-A8887E8A-9ADE-43D0-91A2-B20450113D41"/>
    <sequenceFlow id="sid-AF3E3C93-B7F4-40BD-9ACF-699C31E5B034" sourceRef="sid-3D71CBED-A50E-4B50-A4D2-D20763A51D66" targetRef="sid-A8887E8A-9ADE-43D0-91A2-B20450113D41"/>
    <sequenceFlow id="sid-1CAA4B9B-E7B0-41D8-ADC4-19F0F21DF11F" sourceRef="sid-850B7D8F-AABD-49FE-9CFB-843513146281" targetRef="sid-A8887E8A-9ADE-43D0-91A2-B20450113D41"/>
    <sequenceFlow id="sid-AD5B6BBA-E3ED-4E2F-B67E-DC2FDB2DF204" sourceRef="sid-8F55A260-8EB3-415D-A873-2E34E916216E" targetRef="sid-850B7D8F-AABD-49FE-9CFB-843513146281">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${days <= 3}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="sid-AC1BD940-A9EB-4E3C-B91A-DD1774F30F60" sourceRef="sid-8F55A260-8EB3-415D-A873-2E34E916216E" targetRef="sid-3D71CBED-A50E-4B50-A4D2-D20763A51D66">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${days > 3}]]></conditionExpression>
    </sequenceFlow>
    <userTask id="sid-7F648C16-A3F9-4836-BC07-7289719F732A" name="申请请假" activiti:candidateGroups="empGroup"/>
    <sequenceFlow id="sid-054FF766-3536-464F-8FD5-8567FD76721C" sourceRef="start" targetRef="sid-7F648C16-A3F9-4836-BC07-7289719F732A"/>
    <sequenceFlow id="sid-D5DC465E-DD41-4011-9AA9-5C5627A87FE6" sourceRef="sid-7F648C16-A3F9-4836-BC07-7289719F732A" targetRef="sid-8F55A260-8EB3-415D-A873-2E34E916216E"/>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_process">
    <bpmndi:BPMNPlane bpmnElement="process" id="BPMNPlane_process">
      <bpmndi:BPMNShape bpmnElement="start" id="BPMNShape_start">
        <omgdc:Bounds height="30.0" width="30.0" x="30.0" y="162.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-8F55A260-8EB3-415D-A873-2E34E916216E" id="BPMNShape_sid-8F55A260-8EB3-415D-A873-2E34E916216E">
        <omgdc:Bounds height="40.0" width="40.0" x="390.0" y="137.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-3D71CBED-A50E-4B50-A4D2-D20763A51D66" id="BPMNShape_sid-3D71CBED-A50E-4B50-A4D2-D20763A51D66">
        <omgdc:Bounds height="80.0" width="100.0" x="609.0" y="50.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-850B7D8F-AABD-49FE-9CFB-843513146281" id="BPMNShape_sid-850B7D8F-AABD-49FE-9CFB-843513146281">
        <omgdc:Bounds height="80.0" width="100.0" x="617.0" y="222.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-A8887E8A-9ADE-43D0-91A2-B20450113D41" id="BPMNShape_sid-A8887E8A-9ADE-43D0-91A2-B20450113D41">
        <omgdc:Bounds height="28.0" width="28.0" x="943.0" y="163.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="sid-7F648C16-A3F9-4836-BC07-7289719F732A" id="BPMNShape_sid-7F648C16-A3F9-4836-BC07-7289719F732A">
        <omgdc:Bounds height="80.0" width="100.0" x="180.0" y="137.0"/>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="sid-054FF766-3536-464F-8FD5-8567FD76721C" id="BPMNEdge_sid-054FF766-3536-464F-8FD5-8567FD76721C">
        <omgdi:waypoint x="60.0" y="177.0"/>
        <omgdi:waypoint x="180.0" y="177.0"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-AF3E3C93-B7F4-40BD-9ACF-699C31E5B034" id="BPMNEdge_sid-AF3E3C93-B7F4-40BD-9ACF-699C31E5B034">
        <omgdi:waypoint x="709.0" y="104.59731543624162"/>
        <omgdi:waypoint x="943.5610106253332" y="173.07653665907378"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-D5DC465E-DD41-4011-9AA9-5C5627A87FE6" id="BPMNEdge_sid-D5DC465E-DD41-4011-9AA9-5C5627A87FE6">
        <omgdi:waypoint x="280.0" y="171.44444444444446"/>
        <omgdi:waypoint x="392.0" y="159.0"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-AC1BD940-A9EB-4E3C-B91A-DD1774F30F60" id="BPMNEdge_sid-AC1BD940-A9EB-4E3C-B91A-DD1774F30F60">
        <omgdi:waypoint x="426.2278481012658" y="153.22784810126583"/>
        <omgdi:waypoint x="609.0" y="103.5814889336016"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-1CAA4B9B-E7B0-41D8-ADC4-19F0F21DF11F" id="BPMNEdge_sid-1CAA4B9B-E7B0-41D8-ADC4-19F0F21DF11F">
        <omgdi:waypoint x="717.0" y="247.3448275862069"/>
        <omgdi:waypoint x="943.565200385607" y="180.93778609387383"/>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="sid-AD5B6BBA-E3ED-4E2F-B67E-DC2FDB2DF204" id="BPMNEdge_sid-AD5B6BBA-E3ED-4E2F-B67E-DC2FDB2DF204">
        <omgdi:waypoint x="424.0" y="163.0"/>
        <omgdi:waypoint x="617.0" y="241.62962962962962"/>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

test

source code

https://gitee.com/bseaworkspace/study_java_web/tree/master/springboot-activiti