diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/activiti/service/process/ProcessService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/activiti/service/process/ProcessService.java new file mode 100644 index 000000000..4ef499658 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/activiti/service/process/ProcessService.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.adminserver.modules.activiti.service.process; + +import org.springframework.web.multipart.MultipartFile; + +/** + * 流程基础管理 + * + * @author ZJQ + * @date 2021/9/5 21:00 + */ +public interface ProcessService { + + /** + * 上传流程文件,进行流程部署 + * @param multipartFile 上传文件 + */ + void deployProcess(MultipartFile multipartFile); +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/activiti/service/process/impl/ProcessServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/activiti/service/process/impl/ProcessServiceImpl.java new file mode 100644 index 000000000..aa4e134f7 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/activiti/service/process/impl/ProcessServiceImpl.java @@ -0,0 +1,85 @@ +package cn.iocoder.yudao.adminserver.modules.activiti.service.process.impl; + +import cn.iocoder.yudao.adminserver.modules.activiti.service.process.ProcessService; +import lombok.extern.slf4j.Slf4j; +import org.activiti.engine.RepositoryService; +import org.activiti.engine.repository.Deployment; +import org.activiti.engine.repository.ProcessDefinition; +import org.apache.commons.io.FilenameUtils; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.zip.ZipInputStream; +import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.FILE_UPLOAD_FAILED; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; + +/** + * 流程基础管理 + * + * @author ZJQ + * @date 2021/9/5 21:04 + */ +@Service +@Slf4j +public class ProcessServiceImpl implements ProcessService { + + private static final String BPMN20_XML = "bpmn20.xml"; + + @Resource + private RepositoryService repositoryService; + + /** + * 上传流程文件,进行流程部署 + * @param multipartFile 上传文件 + */ + @Override + public void deployProcess(MultipartFile multipartFile) { + String fileName = multipartFile.getOriginalFilename(); + try (InputStream inputStream = multipartFile.getInputStream()){ + Deployment deployment = getDeplymentByType(inputStream,fileName); + //获取部署成功的流程模型 + List processDefinitions = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).list(); + processDefinitions.forEach((processDefinition)->{ + //设置线上部署流程模型名字 + String proDefId= processDefinition.getId(); + repositoryService.setProcessDefinitionCategory(proDefId,fileName); + log.info("流程文件部署成功,流程ID="+proDefId); + }); + } catch (IOException e) { + log.error("流程部署出现异常"+e); + } + } + + + /** + * 根据上传文件类型对应实现不同方式的流程部署 + * @param inputStream 文件输入流 + * @param fileName 文件名 + * @return 文件部署流程 + */ + public Deployment getDeplymentByType(InputStream inputStream,String fileName){ + Deployment deployment; + String type = FilenameUtils.getExtension(fileName); + switch (type){ + case "bpmn": + String baseName = FilenameUtils.getBaseName(fileName); + deployment = repositoryService.createDeployment().addInputStream(baseName+"."+BPMN20_XML,inputStream).deploy(); + break; + case "png": + deployment = repositoryService.createDeployment().addInputStream(fileName,inputStream).deploy(); + break; + case "zip": + case "bar": + ZipInputStream zipInputStream = new ZipInputStream(inputStream); + deployment = repositoryService.createDeployment().addZipInputStream(zipInputStream).deploy(); + break; + default: + throw exception(FILE_UPLOAD_FAILED); + } + return deployment; + } +} diff --git a/yudao-admin-server/src/main/resources/application-local.yaml b/yudao-admin-server/src/main/resources/application-local.yaml index 53ab06560..ef485e083 100644 --- a/yudao-admin-server/src/main/resources/application-local.yaml +++ b/yudao-admin-server/src/main/resources/application-local.yaml @@ -43,17 +43,30 @@ spring: primary: master datasource: master: - name: ruoyi-vue-pro + name: ruoyi_vue_pro url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT driver-class-name: com.mysql.jdbc.Driver username: root - password: 123456 + password: root slave: # 模拟从库,可根据自己需要修改 - name: ruoyi-vue-pro + name: ruoyi_vue_pro url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT driver-class-name: com.mysql.jdbc.Driver username: root - password: 123456 + password: root + + + activiti: + #1.false:默认值,activiti启动时,对比数据库表中保存的版本,如果不匹配。将抛出异常 + #2.true:启动时会对数据库中所有表进行更新操作,如果表存在,不做处理,反之,自动创建表 + #3.create_drop:启动时自动创建表,关闭时自动删除表 + #4.drop_create:启动时,删除旧表,再创建新表 + database-schema-update: true + #activiti7默认不生成历史信息表,需手动设置开启 + db-history-used: true + check-process-definitions: true + history-level: full + # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 redis: diff --git a/yudao-dependencies/pom.xml b/yudao-dependencies/pom.xml index 42adcdf8a..e2989e6e2 100644 --- a/yudao-dependencies/pom.xml +++ b/yudao-dependencies/pom.xml @@ -396,6 +396,15 @@ ${aliyun-java-sdk-dysmsapi.version} + + + + + cn.iocoder.boot + yudao-spring-boot-starter-activiti + ${revision} + + diff --git a/yudao-framework/pom.xml b/yudao-framework/pom.xml index 635dc7cf6..e9ff025f5 100644 --- a/yudao-framework/pom.xml +++ b/yudao-framework/pom.xml @@ -28,6 +28,7 @@ yudao-spring-boot-starter-biz-operatelog yudao-spring-boot-starter-biz-dict yudao-spring-boot-starter-biz-sms + yudao-spring-boot-starter-activiti yudao-framework diff --git a/yudao-framework/yudao-spring-boot-starter-activiti/pom.xml b/yudao-framework/yudao-spring-boot-starter-activiti/pom.xml new file mode 100644 index 000000000..f3acec5e2 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-activiti/pom.xml @@ -0,0 +1,58 @@ + + + + cn.iocoder.boot + yudao-framework + ${revision} + + 4.0.0 + yudao-spring-boot-starter-activiti + jar + + ${artifactId} + Activiti 拓展 + https://github.com/YunaiV/ruoyi-vue-pro + + + + 7.1.0.M6 + + + + + cn.iocoder.boot + yudao-common + + + + + org.activiti.dependencies + activiti-dependencies + ${activiti.version} + pom + + + + org.activiti + activiti-spring-boot-starter + ${activiti.version} + + + de.odysseus.juel + juel-api + + + de.odysseus.juel + juel-spi + + + org.mybatis + mybatis + + + + + + diff --git a/yudao-framework/yudao-spring-boot-starter-activiti/src/main/java/cn/iocoder/yudao/framework/activiti/package-info.java b/yudao-framework/yudao-spring-boot-starter-activiti/src/main/java/cn/iocoder/yudao/framework/activiti/package-info.java new file mode 100644 index 000000000..c49d90f93 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-activiti/src/main/java/cn/iocoder/yudao/framework/activiti/package-info.java @@ -0,0 +1 @@ +package cn.iocoder.yudao.framework.activiti;