[22] springboot integration activiti7 (1) practical demonstration

        The following chapters of this chapter will integrate springboot+activiti7 to record your own learning process. Since the demo is too long, it will be described in several chapters. After finishing writing, links to the following chapters will be attached at the end of the article. This chapter mainly describes the requirements of the demo and a demonstration of the final effect. The specific construction and implementation will be described in turn in the following chapters.

Qq exchange group navigation ——> 231378628

Table of contents

1. Demo description

2. Preparation

3. Effect display


 The overall column of the springboot chapter: 


[1] springboot integrates swagger (super detailed

[2] springboot integrates swagger (custom) (super detailed)

[3] springboot integration token (super detailed)

[4] springboot integrates mybatis-plus (super detailed) (on)

[5] springboot integrates mybatis-plus (super detailed) (below)

[6] springboot integrates custom global exception handling

[7] springboot integrates redis (super detailed)

[8] springboot integrates AOP to realize log operation (super detailed)

[Nine] springboot integrated timing tasks (super detailed)

[10] springboot integrates redis to realize the startup service, that is, save the hotspot data in the global and redis (super detailed)

[Eleven] springboot integrates quartz to realize timing task optimization (super detailed)

[Twelve] springboot integrates thread pool to solve high concurrency (super detailed, keep you understanding)

[Thirteen] springboot integrates asynchronous calls and obtains return values ​​(super detailed)

[14] springboot integrates WebService (super detailed)

[Fifteen] springboot integrates WebService (about passing parameters) (super detailed)

[16] springboot integrates WebSocket (super detailed)

[Seventeen] springboot integrates WebSocket to realize chat room (super detailed)

[Eighteen] springboot implements custom global exception handling

[Nineteen] springboot integrates ElasticSearch actual combat (ten thousand characters)

[Twenty] springboot integration filter combat

[21] springboot integrates interceptors in actual combat and compares filters

[22] springboot integration activiti7 (1) practical demonstration

【23】springboot integrated spring business detailed explanation and actual combat

[24] springboot uses EasyExcel and thread pool to realize multi-threaded import of Excel data

[25] springboot integrates jedis and redisson Bloom filters to handle cache penetration

[26] springboot implements multi-threaded transaction processing_springboot multi-threaded transaction

[27] springboot realizes the function of saving the current login information like the session through the threadLocal+ parameter parser


1. Demo description

         Scenario: Assume that a certain company is currently undergoing a management rectification. If a product manager wants to raise a demand, in addition to satisfying Party A, he must also satisfy the coders. At this time, there can be an approval process. as follows:

ae1fed7d41ec4f828b47ade851c405b7.png        Later, the above approval process will be realized by integrating activiti.

        The achieved effect is: from the product manager to initiate the process, each subsequent node can be passed or returned, and the return is to return to the product manager step. Then implement a process record tracking and flow chart tracking function. Except for approval and return to the initial node, other operations will be empty later and then learn slowly.


2. Preparation

1. The first step

        Prepare the database.

You need activi's table and your own business table. Activiti's table will be automatically created when it is deployed. For now, the business tables involved in this demo are as follows:

Table Name describe
user user table
role role table
user_role User role association table
demand Request Form
CREATE TABLE `demand` (
  `id` varchar(100) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '主键',
  `status` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL COMMENT '流程状态,-1是未启动,0是填写表单,1是组长审批,2是开发经理审批,3是项目经理审批,4是结束',
  `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL COMMENT '需求名称',
  `content` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL COMMENT '需求具体内容',
  `salt` varchar(255) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL COMMENT '盐字段',
  `taskid` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '任务id',
  `createuser` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '发起人',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin;
CREATE TABLE `role` (
  `id` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '主键',
  `role` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '角色名称'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin;

1f85600967674a1480133b5bbd2999b0.png

CREATE TABLE `user` (
  `id` varchar(255) COLLATE utf8_bin NOT NULL COMMENT '主键',
  `username` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '用户名',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin;

c39ef4c1ea3749c88dbbd342f6b5b4cb.png

CREATE TABLE `user_role` (
  `id` varchar(255) COLLATE utf8_bin NOT NULL COMMENT '主键',
  `userid` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '用户id',
  `roleid` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT '角色id',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8_bin;

 e635816df9f84d09a7f6c4fc8892daea.png

2. The second step

        The idea installs the plug-in and draws a flow chart.

Draw a flow chart that activiti can recognize and implement deployment. By default, activiti can deploy files ending with .bpmn and **.bpmn20.xml.

idea has many plug-ins for drawing bpmn diagrams, and I chose activiti BPMN visualizer.

a9e728971b2c481683d934690c9dd523.png

After the installation is complete, restart the idea, and right-click to create the following file under the resources resource directory of the created springboot project.

d84b89221fe84608a4cb35f2e27df6de.png

 73d375cb201a44f59471949acc48967d.png

After the creation is complete, an xml file will be generated. Right-click on this file and select view... to open the flow chart.

5e91ea8ffe674542b608582a4d617eb2.png

Add to draw by right-clicking in the graph.

8f9575002cd84fc6862391ddd91fdf12.png

Finally, the above flow chart was drawn according to the demand scenario of the demo. Diamonds are exclusive gateways and rectangles are user events .

The specific parameters on each node and line will be discussed later. Here, let’s talk about one thing parameter , it is best not to use the same name , otherwise there will be problems. 

3. The third step

        Create a project and import required dependencies.

Here is the directory structure of my project :

ba719a1dbebc4ec4bc0e99b94f835c3c.png

Then import the dependencies required by this demo , as follows:

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!--    工作流依赖    -->
        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-spring-boot-starter</artifactId>
            <version>7.1.0.M3.1</version>
            <exclusions>
                <exclusion><!-- 排除activiti的mybatis,避免和外面的mybatis-plus冲突 -->
                    <!-- 重点坑,不然启动项目会报错mybatisplus缺少类   -->
                    <artifactId>mybatis</artifactId>
                    <groupId>org.mybatis</groupId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.4.2</version>
        </dependency>

        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>5.7.22</version>
        </dependency>

        <!--   数据依赖     -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.11</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>

        <!--流程图依赖-->
        <!--  试了几个版本的,有些版本的会导致图片展示不全,注意  -->
        <dependency>
            <groupId>org.activiti</groupId>
            <artifactId>activiti-image-generator</artifactId>
            <version>5.20.0</version>
        </dependency>

    </dependencies>

There are a few pitfalls that need to be paid attention to, which are marked in the remarks above, for example, the conflict between mybatisplus and activiti and the dependence of the subsequent preview flow chart function will lead to incomplete display and so on. 

4. Modify the configuration file

989c35d040f0480b8ffbee15c4e5af79.png


server:
  port: 8080

spring:
  datasource:
    username: root
    password: 123456
    #    加上nullCatalogMeansCurrent=true才能自动创建activiti需要的表
    url: jdbc:mysql://localhost:3306/activiti?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=Asia/Shanghai&nullCatalogMeansCurrent=true

  activiti:
    database-schema-update: true
    check-process-definitions: true
    #  注意,如果activiti后面加上了/,就要求启动的时候process文件夹中需要有流程定义文件
    #  是指定activiti流程描述文件的前缀(路径),启动时,activiti就会去寻找此路径下的流程描述文件,并且自动部署
    process-definition-location-prefix: classpath:/activiti/
    #  suffix 是一个String数组,表示描述文件的默认后缀名,默认**.bpmn和**.bpmn20.xml
    #    process-definition-location-suffixes:
    #      - **.bpmn
    #      - **.bpmn20.xml
    #  Activiti7历史数据无法自动插入,开启下面两个配置
    history-level: audit
    db-history-used: true
#  mapper.xml文件所在路径
mybatis-plus:
  mapper-locations: classpath*:mapper/**/*Mapper.xml
#  configuration:
#    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #开启sql日志

I have written the specific description in the comments.


3. Effect display

        After the preparatory work is completed, the coding can be started. There are a lot of demo codes, so the following will only show the effect.

1. First, log in Zhang San (product manager, id is 1) in a simulated manner, and enter the My Requirements interface to make a request.

a5f513d47f4041408d6f62379b651632.png

6aadfc91921d4fbd9bbe77fb7a844891.png

9d4f9ac5da0b45bdb1c4473b60672e9f.png

2. After the addition is completed, the process is not started. Zhang San clicks to initiate the process, and clicks the Submit for Review button, selects the approver and clicks Save.

f9e48bef6e3b46c482b5e89e72e7b1bb.png

9a48f4447e964f85857e1123bc71c446.pngb0a50bded19843a08d675a0e6afcb06b.png

3. At this time, click the View Process button.5dc4f48d8b7c4a7291be3bf470a36bdf.png

4. You can see that the process is now in the team leader's place, that is, Li Si in the database configuration, and then log in to Li Si's account, enter the to-do interface, and view the to-do list. 680e3c3045664243b0e3cbe6ef878b39.png9110ef8dd48b477da0f63dc0160daa62.png 5. Click the back button to return to Zhang San to rewrite the requirements.

fe1a95835ddf45d59d26969af81eacc2.png0a6500ba5a3942be9e3dfed297e0cef0.png

6. Log in to Zhang San's (id: 1) account and resubmit the request. 125ae210306b4fd49ea76a789f54dbce.pngb752efe68075425c95967d53bb61e2aa.png44969aab6bd54f79b26e5026f3d2ba32.png 7. Click Submit for review and continue to select approvers.

0f8ebfd719a74cd5baa9745599e56f05.png800325c9d83b4c23b100d38347ca2e4a.png

8. Log in to Li Si's account and re-approve (id: 2)  38df6137f3b34dbb8fdc775aecf2b475.pnge1e0168c04454092857e458c9bfeb314.png 9. Choose to agree this timea305f976a29c4d76855ad289b71e5047.png195d2f14cfc6468683bd65331f329b96.png

10. Check the flowchart againd6473af806db450188d9fdf1c6f974ed.png

11. Log in to Wang Wu's account (id: 3)a988f3cdb12247dd96bc32cf6d567130.png

6a8ee90536824bda8d0e9c656d06688b.png

12. Click Agree 3cebf0d76a58402fb9b70157ce62878a.png0114d147711d48ada650966df9e84faf.png13. View the flow chart39d42a8467154675a8ac2e900d1774dd.png

14. Log in to Zhao Liu's account for approval (id: 4)9df57d83178c4249adaa91ebff1cc498.png724347a1ad6147aba409b44daa5e2052.png

15. Click through2c11ead80f2c40cdb3dd1642e37b466a.pngdf4566d13ee349bb87d2820c647634da.png

16. Back to Zhang San's demand list again, the process status has ended67ed7ee39843424cb354c138d2171811.png1dd7bf2f4b7a4509906766c04cfa8578.png

The general effect is like this. The following chapters will display and describe the code of each function, and write slowly when you have time.

----------------------------------------------------END----------------------------------------------------------


Guess you like

Origin blog.csdn.net/weixin_56995925/article/details/124530843