欢迎访问优讯网!
您当前的位置:首页 > 爱编程

Springboot集成activity过程图解

时间:2020-04-30 08:38:06  来源:优讯网  作者:小卡司  浏览次数:
这篇文章主要介绍了Springboot集成activity过程图解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
 

1.第一步添加bpmn文件得插件,不然没法查看和编辑bpmn文件,添加插件的方法各自百度即可,很简单

2.安装好bpmn插件后开始新建bpmn文件,也就是画流程图

一般是在代码中进行指定流程审批人的,我这里只做入门案例

3.添加pom依赖

这里包含了在线设计流程图的相关依赖,在下一篇会写出来,项目中一般都是在前端在线设计;所以直接放上去也没事

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
https://maven.apache.org/xsd/maven-4.0.0.xsd"
>
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.0.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>
  <groupId>com</groupId>
  <artifactId>springboot_activiti</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>springboot_activiti</name>
  <description>Demo project for Spring Boot</description>
 
 
 
  <properties>
    <springboot.version>2.2.0.RELEASE</springboot.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <activiti.version>6.0.0</activiti.version>
  </properties>
 
  <dependencies>
 
 
    <dependency>
      <groupId>org.activiti</groupId>
      <artifactId>activiti-engine</artifactId>
      <version>${activiti.version}</version>
    </dependency>
 
    <dependency>
      <groupId>org.activiti</groupId>
      <artifactId>activiti-spring</artifactId>
      <version>${activiti.version}</version>
      <exclusions>
        <exclusion>
          <groupId>org.codehaus.jackson</groupId>
          <artifactId>jackson-core-asl</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-log4j12</artifactId>
        </exclusion>
        <exclusion>
          <artifactId>spring-context</artifactId>
          <groupId>org.springframework</groupId>
        </exclusion>
        <exclusion>
          <artifactId>spring-jdbc</artifactId>
          <groupId>org.springframework</groupId>
        </exclusion>
        <exclusion>
          <artifactId>spring-tx</artifactId>
          <groupId>org.springframework</groupId>
        </exclusion>
        <exclusion>
          <artifactId>spring-orm</artifactId>
          <groupId>org.springframework</groupId>
        </exclusion>
        <exclusion>
          <artifactId>spring-beans</artifactId>
          <groupId>org.springframework</groupId>
        </exclusion>
        <exclusion>
          <artifactId>mybatis</artifactId>
          <groupId>org.mybatis</groupId>
        </exclusion>
        <exclusion>
          <artifactId>activation</artifactId>
          <groupId>javax.activation</groupId>
        </exclusion>
      </exclusions>
 
    </dependency>
 
    <dependency>
      <groupId>org.activiti</groupId>
      <artifactId>activiti-spring-boot-starter-basic</artifactId>
      <version>${activiti.version}</version>
    </dependency>
 
    <!-- Activiti 流程图 -->
    <dependency>
      <groupId>org.activiti</groupId>
      <artifactId>activiti-common-rest</artifactId>
      <version>${activiti.version}</version>
    </dependency>
    <!-- Activiti 在线设计 -->
    <dependency>
      <groupId>org.activiti</groupId>
      <artifactId>activiti-modeler</artifactId>
      <version>5.22.0</version>
      <exclusions>
        <exclusion>
          <artifactId>spring-beans</artifactId>
          <groupId>org.springframework</groupId>
        </exclusion>
        <exclusion>
          <artifactId>spring-context</artifactId>
          <groupId>org.springframework</groupId>
        </exclusion>
        <exclusion>
          <artifactId>spring-core</artifactId>
          <groupId>org.springframework</groupId>
        </exclusion>
        <exclusion>
          <artifactId>spring-tx</artifactId>
          <groupId>org.springframework</groupId>
        </exclusion>
        <exclusion>
          <artifactId>spring-web</artifactId>
          <groupId>org.springframework</groupId>
        </exclusion>
        <exclusion>
          <artifactId>spring-security-config</artifactId>
          <groupId>org.springframework.security</groupId>
        </exclusion>
        <exclusion>
          <artifactId>spring-security-core</artifactId>
          <groupId>org.springframework.security</groupId>
        </exclusion>
        <exclusion>
          <artifactId>spring-security-crypto</artifactId>
          <groupId>org.springframework.security</groupId>
        </exclusion>
        <exclusion>
          <artifactId>spring-security-web</artifactId>
          <groupId>org.springframework.security</groupId>
        </exclusion>
        <exclusion>
          <artifactId>spring-webmvc</artifactId>
          <groupId>org.springframework</groupId>
        </exclusion>
        <exclusion>
          <artifactId>activation</artifactId>
          <groupId>javax.activation</groupId>
        </exclusion>
        <exclusion>
          <artifactId>commons-io</artifactId>
          <groupId>commons-io</groupId>
        </exclusion>
      </exclusions>
    </dependency>
 
 
 
 
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-autoconfigure</artifactId>
      <version>${springboot.version}</version>
    </dependency>
 
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
 
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
 
 
    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <version>2.3</version>
    </dependency>
 
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-core</artifactId>
      <version>2.10.0</version>
    </dependency>
 
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <scope>runtime</scope>
    </dependency>
 
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-api</artifactId>
      <version>RELEASE</version>
      <scope>compile</scope>
    </dependency>
 
 
  </dependencies>
 
  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
 
      <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <configuration>
          <port>8081</port>
          <path>/activity</path>
          <systemProperties>
            <com.sun.management.jmxremote.port>4000</com.sun.management.
jmxremote.port
>
          </systemProperties>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

4.yml文件

这里采用的数据库还是mysql

这里有个需要注意的地方,springboot2.2中的driver-class-name值变了,不是以前的那个了,不然会报错

spring:
datasource:
url: jdbc:mysql://localhost:3307/t2?useUnicode=true&characterEncoding=utf-8&useSSL=false&autoReconnect=true&serverTimezone=UTC
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
activiti:
# 自动部署验证设置:true-开启(默认)、false-关闭
check-process-definitions: false
#自动部署文件路径后缀
# process-definition-location-prefix: classpath:/processes/
# process-definition-location-suffixes:
# - **.bpmn
# - **.bpmn20.xml
server:
port: 8082

5.配置已经好了,下面开始写代码了,只是初步写了一些新建流程,正常提交流程,直接结束流程,以及查询待办的案例,细节还需要各自自己去调试学习

controller

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package com.springboot_activiti.controller;
 
import com.springboot_activiti.service.ActivityConsumerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
@RestController
@RequestMapping("/activiti")
public class ActivitiController {
 
  @Autowired
  private ActivityConsumerService activityConsumerService;
 
  /**
   * 注册流程
   * @return
   */
  @RequestMapping("/createDeployment")
  public Boolean createDeployment(){
    return activityConsumerService.createDeployment();
  }
 
  /**
   * 启动流程
   * @return
   */
  @RequestMapping("/startActivityDemo")
  public Boolean startActivityDemo(){
    return activityConsumerService.startActivityDemo("test01");
  }
 
  /**
   * 获取待办
   * @return
   */
  @RequestMapping("/getTaskList")
  public boolean getTaskList(){
    return activityConsumerService.getTaskList();
  }
 
  /**
   * 提交
   * @param taskId
   * @return
   */
  @RequestMapping("/complete")
  public boolean complete(String taskId){
    return activityConsumerService.complete(taskId);
  }
  /**
   * 根据流程id直接结束流程
   * @paramru
   * @return
   */
  @RequestMapping("/deleteProcessInstance")
  public boolean deleteProcessInstance(String runId){
    return activityConsumerService.deleteProcessInstance(runId);
  }
}

 

service

1
2
3
4
5
6
7
8
package com.springboot_activiti.service;
public interface ActivityConsumerService {
  boolean createDeployment();
  boolean startActivityDemo(String key);
  boolean getTaskList();
  boolean complete(String taskId);
  boolean deleteProcessInstance(String runId);
}

 

实现类

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package com.springboot_activiti.service;
 
 
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.DeploymentBuilder;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
@Service("activityService")
public class ActivityConsumerServiceImpl implements ActivityConsumerService {
 
 
  @Autowired
  private RuntimeService runtimeService;
  @Autowired
  private TaskService taskService;
 
  @Autowired
  private RepositoryService repositoryService;
 
  /**
   * 注册一个流程
   * @return
   */
  @Override
  public boolean createDeployment() {
    DeploymentBuilder builder=repositoryService.createDeployment();
    builder.addClasspathResource("test01.bpmn");
    builder.deploy();
    return true;
  }
 
  /**
   * 查询待办
   * @return
   */
  public boolean getTaskList(){
    //获取待办的一些信息,这里可以传入需要查询的用户,
    //我这里查询的所有待办
    List<Task> tasks = taskService.createTaskQuery().list();
    for (Task t:tasks) {
      System.out.println(t.getCreateTime());
      System.out.println(t.getId());
      System.out.println(t.getName());
      System.out.println(t.getProcessInstanceId());
      System.out.println(t.getTaskDefinitionKey());
      System.out.println(t.getParentTaskId());
    }
    return true;
  }
 
 
  /**
   * 根据流程key开启一个流程
   * @param key
   * @return
   */
  @Override
  public boolean startActivityDemo(String key) {
    ProcessInstance test01 = runtimeService.startProcessInstanceByKey(key);
    String id = test01.getId();
    System.out.println("流程id="+id);
    /* */
  /*  String assignee = "abc";*/
    return true;
  }
 
  /**
   * 根据任务id提交任务
   * @param taskId
   * @return
   */
  @Override
  public boolean complete(String taskId){
    taskService.complete(taskId);
    return true;
  }
 
  /**
   * 根据流程id直接结束流程
   * @param runId
   * @return
   */
  @Override
  public boolean deleteProcessInstance(String runId){
    runtimeService.deleteProcessInstance(runId,"结束");
    return true;
  }
}

 

启动类,这里存在一个在线视图设计的验证处理,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package com.springboot_activiti;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@ComponentScan("com")
@SpringBootApplication
@EnableAutoConfiguration(exclude = {
org.activiti.spring.boot.SecurityAutoConfiguration.class
    })
public class SpringbootActivitiApplication {
  public static void main(String[] args) {
    SpringApplication.run(SpringbootActivitiApplication.class, args);
  }
}

所有的代码已经写好了

备注说明:

项目启动会新建28张表,各自代表的含义自行百度把

因为我的数据都是直接在流程图bpmn文件里面写好的,实际中肯定是在代码里面指定的

首先访问注册流程

启动流程(会返回一个流程id)

查看待办就可以获取相关的信息了

正常提交任务,会审批到下一节点(查看待办可以得到任务id)

直接结束流程(非正常结束,启动流程的id传入即可)

请求案例

查询待办

启动流程

以上就是本文的全部内容,希望对大家的学习有所帮助

来顶一下
返回首页
返回首页

原文链接:https://www.jb51.net/article/185756.htm


推荐资讯
如何下载旧版centos iso镜像 如何下载迷你mini版的centos镜像
如何下载旧版centos i
计算机的正确使用姿势 电脑痴如何正确的使用电脑
计算机的正确使用姿势
好用的后台管理的前端框架模版H-ui H-ui框架模版分享
好用的后台管理的前端
微信电脑多开方法 无需辅助电脑版微信双开方法分享
微信电脑多开方法 无
相关文章
栏目更新
栏目热门