Commit 00e15a5c2c312335463760cbd03423e1ed81efd7
1 parent
1a17e5ec
1、集成Activiti7版本,yudao-dependencies模块新增activiti依赖包;
2、流程文件上传部署API后端逻辑实现;
Showing
7 changed files
with
189 additions
and
4 deletions
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/activiti/service/process/ProcessService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.adminserver.modules.activiti.service.process; | ||
| 2 | + | ||
| 3 | +import org.springframework.web.multipart.MultipartFile; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 流程基础管理 | ||
| 7 | + * | ||
| 8 | + * @author ZJQ | ||
| 9 | + * @date 2021/9/5 21:00 | ||
| 10 | + */ | ||
| 11 | +public interface ProcessService { | ||
| 12 | + | ||
| 13 | + /** | ||
| 14 | + * 上传流程文件,进行流程部署 | ||
| 15 | + * @param multipartFile 上传文件 | ||
| 16 | + */ | ||
| 17 | + void deployProcess(MultipartFile multipartFile); | ||
| 18 | +} |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/activiti/service/process/impl/ProcessServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.adminserver.modules.activiti.service.process.impl; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.adminserver.modules.activiti.service.process.ProcessService; | ||
| 4 | +import lombok.extern.slf4j.Slf4j; | ||
| 5 | +import org.activiti.engine.RepositoryService; | ||
| 6 | +import org.activiti.engine.repository.Deployment; | ||
| 7 | +import org.activiti.engine.repository.ProcessDefinition; | ||
| 8 | +import org.apache.commons.io.FilenameUtils; | ||
| 9 | +import org.springframework.stereotype.Service; | ||
| 10 | +import org.springframework.web.multipart.MultipartFile; | ||
| 11 | + | ||
| 12 | +import javax.annotation.Resource; | ||
| 13 | +import java.io.IOException; | ||
| 14 | +import java.io.InputStream; | ||
| 15 | +import java.util.List; | ||
| 16 | +import java.util.zip.ZipInputStream; | ||
| 17 | +import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.FILE_UPLOAD_FAILED; | ||
| 18 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | ||
| 19 | + | ||
| 20 | +/** | ||
| 21 | + * 流程基础管理 | ||
| 22 | + * | ||
| 23 | + * @author ZJQ | ||
| 24 | + * @date 2021/9/5 21:04 | ||
| 25 | + */ | ||
| 26 | +@Service | ||
| 27 | +@Slf4j | ||
| 28 | +public class ProcessServiceImpl implements ProcessService { | ||
| 29 | + | ||
| 30 | + private static final String BPMN20_XML = "bpmn20.xml"; | ||
| 31 | + | ||
| 32 | + @Resource | ||
| 33 | + private RepositoryService repositoryService; | ||
| 34 | + | ||
| 35 | + /** | ||
| 36 | + * 上传流程文件,进行流程部署 | ||
| 37 | + * @param multipartFile 上传文件 | ||
| 38 | + */ | ||
| 39 | + @Override | ||
| 40 | + public void deployProcess(MultipartFile multipartFile) { | ||
| 41 | + String fileName = multipartFile.getOriginalFilename(); | ||
| 42 | + try (InputStream inputStream = multipartFile.getInputStream()){ | ||
| 43 | + Deployment deployment = getDeplymentByType(inputStream,fileName); | ||
| 44 | + //获取部署成功的流程模型 | ||
| 45 | + List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).list(); | ||
| 46 | + processDefinitions.forEach((processDefinition)->{ | ||
| 47 | + //设置线上部署流程模型名字 | ||
| 48 | + String proDefId= processDefinition.getId(); | ||
| 49 | + repositoryService.setProcessDefinitionCategory(proDefId,fileName); | ||
| 50 | + log.info("流程文件部署成功,流程ID="+proDefId); | ||
| 51 | + }); | ||
| 52 | + } catch (IOException e) { | ||
| 53 | + log.error("流程部署出现异常"+e); | ||
| 54 | + } | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + | ||
| 58 | + /** | ||
| 59 | + * 根据上传文件类型对应实现不同方式的流程部署 | ||
| 60 | + * @param inputStream 文件输入流 | ||
| 61 | + * @param fileName 文件名 | ||
| 62 | + * @return 文件部署流程 | ||
| 63 | + */ | ||
| 64 | + public Deployment getDeplymentByType(InputStream inputStream,String fileName){ | ||
| 65 | + Deployment deployment; | ||
| 66 | + String type = FilenameUtils.getExtension(fileName); | ||
| 67 | + switch (type){ | ||
| 68 | + case "bpmn": | ||
| 69 | + String baseName = FilenameUtils.getBaseName(fileName); | ||
| 70 | + deployment = repositoryService.createDeployment().addInputStream(baseName+"."+BPMN20_XML,inputStream).deploy(); | ||
| 71 | + break; | ||
| 72 | + case "png": | ||
| 73 | + deployment = repositoryService.createDeployment().addInputStream(fileName,inputStream).deploy(); | ||
| 74 | + break; | ||
| 75 | + case "zip": | ||
| 76 | + case "bar": | ||
| 77 | + ZipInputStream zipInputStream = new ZipInputStream(inputStream); | ||
| 78 | + deployment = repositoryService.createDeployment().addZipInputStream(zipInputStream).deploy(); | ||
| 79 | + break; | ||
| 80 | + default: | ||
| 81 | + throw exception(FILE_UPLOAD_FAILED); | ||
| 82 | + } | ||
| 83 | + return deployment; | ||
| 84 | + } | ||
| 85 | +} |
yudao-admin-server/src/main/resources/application-local.yaml
| @@ -43,17 +43,30 @@ spring: | @@ -43,17 +43,30 @@ spring: | ||
| 43 | primary: master | 43 | primary: master |
| 44 | datasource: | 44 | datasource: |
| 45 | master: | 45 | master: |
| 46 | - name: ruoyi-vue-pro | 46 | + name: ruoyi_vue_pro |
| 47 | url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT | 47 | url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT |
| 48 | driver-class-name: com.mysql.jdbc.Driver | 48 | driver-class-name: com.mysql.jdbc.Driver |
| 49 | username: root | 49 | username: root |
| 50 | - password: 123456 | 50 | + password: root |
| 51 | slave: # 模拟从库,可根据自己需要修改 | 51 | slave: # 模拟从库,可根据自己需要修改 |
| 52 | - name: ruoyi-vue-pro | 52 | + name: ruoyi_vue_pro |
| 53 | url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT | 53 | url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT |
| 54 | driver-class-name: com.mysql.jdbc.Driver | 54 | driver-class-name: com.mysql.jdbc.Driver |
| 55 | username: root | 55 | username: root |
| 56 | - password: 123456 | 56 | + password: root |
| 57 | + | ||
| 58 | + | ||
| 59 | + activiti: | ||
| 60 | + #1.false:默认值,activiti启动时,对比数据库表中保存的版本,如果不匹配。将抛出异常 | ||
| 61 | + #2.true:启动时会对数据库中所有表进行更新操作,如果表存在,不做处理,反之,自动创建表 | ||
| 62 | + #3.create_drop:启动时自动创建表,关闭时自动删除表 | ||
| 63 | + #4.drop_create:启动时,删除旧表,再创建新表 | ||
| 64 | + database-schema-update: true | ||
| 65 | + #activiti7默认不生成历史信息表,需手动设置开启 | ||
| 66 | + db-history-used: true | ||
| 67 | + check-process-definitions: true | ||
| 68 | + history-level: full | ||
| 69 | + | ||
| 57 | 70 | ||
| 58 | # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 | 71 | # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 |
| 59 | redis: | 72 | redis: |
yudao-dependencies/pom.xml
| @@ -396,6 +396,15 @@ | @@ -396,6 +396,15 @@ | ||
| 396 | <version>${aliyun-java-sdk-dysmsapi.version}</version> | 396 | <version>${aliyun-java-sdk-dysmsapi.version}</version> |
| 397 | </dependency> | 397 | </dependency> |
| 398 | <!-- SMS SDK end --> | 398 | <!-- SMS SDK end --> |
| 399 | + | ||
| 400 | + | ||
| 401 | + <!-- activiti begin --> | ||
| 402 | + <dependency> | ||
| 403 | + <groupId>cn.iocoder.boot</groupId> | ||
| 404 | + <artifactId>yudao-spring-boot-starter-activiti</artifactId> | ||
| 405 | + <version>${revision}</version> | ||
| 406 | + </dependency> | ||
| 407 | + <!-- activiti end --> | ||
| 399 | </dependencies> | 408 | </dependencies> |
| 400 | </dependencyManagement> | 409 | </dependencyManagement> |
| 401 | 410 |
yudao-framework/pom.xml
| @@ -28,6 +28,7 @@ | @@ -28,6 +28,7 @@ | ||
| 28 | <module>yudao-spring-boot-starter-biz-operatelog</module> | 28 | <module>yudao-spring-boot-starter-biz-operatelog</module> |
| 29 | <module>yudao-spring-boot-starter-biz-dict</module> | 29 | <module>yudao-spring-boot-starter-biz-dict</module> |
| 30 | <module>yudao-spring-boot-starter-biz-sms</module> | 30 | <module>yudao-spring-boot-starter-biz-sms</module> |
| 31 | + <module>yudao-spring-boot-starter-activiti</module> | ||
| 31 | </modules> | 32 | </modules> |
| 32 | 33 | ||
| 33 | <artifactId>yudao-framework</artifactId> | 34 | <artifactId>yudao-framework</artifactId> |
yudao-framework/yudao-spring-boot-starter-activiti/pom.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| 3 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| 4 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 5 | + <parent> | ||
| 6 | + <groupId>cn.iocoder.boot</groupId> | ||
| 7 | + <artifactId>yudao-framework</artifactId> | ||
| 8 | + <version>${revision}</version> | ||
| 9 | + </parent> | ||
| 10 | + <modelVersion>4.0.0</modelVersion> | ||
| 11 | + <artifactId>yudao-spring-boot-starter-activiti</artifactId> | ||
| 12 | + <packaging>jar</packaging> | ||
| 13 | + | ||
| 14 | + <name>${artifactId}</name> | ||
| 15 | + <description>Activiti 拓展</description> | ||
| 16 | + <url>https://github.com/YunaiV/ruoyi-vue-pro</url> | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + <properties> | ||
| 20 | + <activiti.version>7.1.0.M6</activiti.version> | ||
| 21 | + </properties> | ||
| 22 | + | ||
| 23 | + <dependencies> | ||
| 24 | + <dependency> | ||
| 25 | + <groupId>cn.iocoder.boot</groupId> | ||
| 26 | + <artifactId>yudao-common</artifactId> | ||
| 27 | + </dependency> | ||
| 28 | + | ||
| 29 | + | ||
| 30 | + <dependency> | ||
| 31 | + <groupId>org.activiti.dependencies</groupId> | ||
| 32 | + <artifactId>activiti-dependencies</artifactId> | ||
| 33 | + <version>${activiti.version}</version> | ||
| 34 | + <type>pom</type> | ||
| 35 | + </dependency> | ||
| 36 | + | ||
| 37 | + <dependency> | ||
| 38 | + <groupId>org.activiti</groupId> | ||
| 39 | + <artifactId>activiti-spring-boot-starter</artifactId> | ||
| 40 | + <version>${activiti.version}</version> | ||
| 41 | + <exclusions> | ||
| 42 | + <exclusion> | ||
| 43 | + <groupId>de.odysseus.juel</groupId> | ||
| 44 | + <artifactId>juel-api</artifactId> | ||
| 45 | + </exclusion> | ||
| 46 | + <exclusion> | ||
| 47 | + <groupId>de.odysseus.juel</groupId> | ||
| 48 | + <artifactId>juel-spi</artifactId> | ||
| 49 | + </exclusion> | ||
| 50 | + <exclusion> | ||
| 51 | + <groupId>org.mybatis</groupId> | ||
| 52 | + <artifactId>mybatis</artifactId> | ||
| 53 | + </exclusion> | ||
| 54 | + </exclusions> | ||
| 55 | + </dependency> | ||
| 56 | + </dependencies> | ||
| 57 | + | ||
| 58 | +</project> |
yudao-framework/yudao-spring-boot-starter-activiti/src/main/java/cn/iocoder/yudao/framework/activiti/package-info.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.activiti; |