Springboot集成activity过程图解1.第⼀步添加bpmn⽂件得插件,不然没法查看和编辑bpmn⽂件,添加插件的⽅法各⾃百度即可,很简单
2.安装好bpmn插件后开始新建bpmn⽂件,也就是画流程图
⼀般是在代码中进⾏指定流程审批⼈的,我这⾥只做⼊门案例
这⾥包含了在线设计流程图的相关依赖,在下⼀篇会写出来,项⽬中⼀般都是在前端在线设计;所以直接放上去也没事<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="/POM/4.0.0" xmlns:xsi="/2001/XMLSchema-instance"
xsi:schemaLocation="/POM/4.0.0 /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>
&porting.outputEncoding>UTF-8</porting.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&dehaus.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&batis</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>
<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.</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>at.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>
这⾥采⽤的数据库还是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: sql.cj.jdbc.Driver
activiti:
# ⾃动部署验证设置:true-开启(默认)、false-关闭
check-process-definitions: false
#⾃动部署⽂件路径后缀
# process-definition-location-prefix: classpath:/processes/
# process-definition-location-suffixes:
# - **.bpmn
# - **.l
server:
port: 8082
5.配置已经好了,下⾯开始写代码了,只是初步写了⼀些新建流程,正常提交流程,直接结束流程,以及查询待办的案例,细节还需要各⾃⾃⼰去调试学习controller
package com.ller;
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(){
ateDeployment();
}
/**
* 启动流程
* @return
*/
@RequestMapping("/startActivityDemo")
public Boolean startActivityDemo(){
return activityConsumerService.startActivityDemo("test01");
}
/
**
* 获取待办
* @return
*/
@RequestMapping("/getTaskList")
public boolean getTaskList(){
TaskList();
}
/**
* 提交
* @param taskId
* @return
springboot切换log4j2*/
@RequestMapping("/complete")
public boolean complete(String taskId){
return activityConsumerServiceplete(taskId);
}
/**
* 根据流程id直接结束流程
* @paramru
* @return
*/
@RequestMapping("/deleteProcessInstance")
public boolean deleteProcessInstance(String runId){
return activityConsumerService.deleteProcessInstance(runId);
}
}
service
package com.springboot_activiti.service;
public interface ActivityConsumerService {
boolean createDeployment();
boolean startActivityDemo(String key);
boolean getTaskList();
boolean complete(String taskId);
boolean deleteProcessInstance(String runId);
}
实现类
package com.springboot_activiti.service;
import ine.RepositoryService;
import ine.RuntimeService;
import ine.TaskService;
import pository.DeploymentBuilder;
import ine.runtime.ProcessInstance;
import ine.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 ateDeployment();
builder.addClasspathResource("test01.bpmn");
builder.deploy();
return true;
}
/
**
* 查询待办
* @return
*/
public boolean getTaskList(){
//获取待办的⼀些信息,这⾥可以传⼊需要查询的⽤户,
//我这⾥查询的所有待办
List<Task> tasks = ateTaskQuery().list();
for (Task t:tasks) {
System.out.CreateTime());
System.out.Id());
System.out.Name());
System.out.ProcessInstanceId());
System.out.TaskDefinitionKey());
System.out.ParentTaskId());
}
return true;
}
/**
* 根据流程key开启⼀个流程
* @param key
* @return
*/
@Override
public boolean startActivityDemo(String key) {
ProcessInstance test01 = runtimeService.startProcessInstanceByKey(key);
String id = Id();
System.out.println("流程id="+id);
/* */
/* String assignee = "abc";*/
return true;
}
/**
* 根据任务id提交任务
* @param taskId
* @return
*/
@Override
public boolean complete(String taskId){
taskServiceplete(taskId);
return true;
}
/**
* 根据流程id直接结束流程
* @param runId
* @return
*/
@Override
public boolean deleteProcessInstance(String runId){
runtimeService.deleteProcessInstance(runId,"结束");
return true;
}
}
启动类,这⾥存在⼀个在线视图设计的验证处理,
package com.springboot_activiti;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import t.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传⼊即可)
请求案例
查询待办
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论