Commit 4f70810c354ae1da257ccaf65673ca61d7c4f594

Authored by YunaiV
1 parent ef7089c1

1. 处理多个环境的配置

README.md
@@ -35,12 +35,12 @@ @@ -35,12 +35,12 @@
35 | | 部门管理 | 配置系统组织机构(公司、部门、小组),树结构展现支持数据权限 | 35 | | 部门管理 | 配置系统组织机构(公司、部门、小组),树结构展现支持数据权限 |
36 | | 岗位管理 | 配置系统用户所属担任职务 | 36 | | 岗位管理 | 配置系统用户所属担任职务 |
37 | | 字典管理 | 对系统中经常使用的一些较为固定的数据进行维护 | 37 | | 字典管理 | 对系统中经常使用的一些较为固定的数据进行维护 |
38 -| | 通知公告 | 系统通知公告信息发布维护 | 38 +| 🚀 | 短信管理 | 短信渠道、短息模板、短信日志,对接阿里云、云片等主流短信平台 |
39 | 🚀 | 操作日志 | 系统正常操作日志记录和查询,集成 Swagger 生成日志内容 | 39 | 🚀 | 操作日志 | 系统正常操作日志记录和查询,集成 Swagger 生成日志内容 |
40 | | 登录日志 | 系统登录日志记录查询包含登录异常 | 40 | | 登录日志 | 系统登录日志记录查询包含登录异常 |
  41 +| | 通知公告 | 系统通知公告信息发布维护 |
41 42
42 计划新增功能: 43 计划新增功能:
43 -* 短信  
44 * 邮件 44 * 邮件
45 * 钉钉、飞书等通知 45 * 钉钉、飞书等通知
46 46
@@ -87,14 +87,15 @@ @@ -87,14 +87,15 @@
87 87
88 ## 技术栈 88 ## 技术栈
89 89
90 -**后端** 90 +### 后端
91 91
92 | 框架 | 说明 | 版本 | 学习指南 | 92 | 框架 | 说明 | 版本 | 学习指南 |
93 | --- | --- | --- | --- | 93 | --- | --- | --- | --- |
94 | [Spring Boot](https://spring.io/projects/spring-boot) | 应用开发框架 | 2.4.2 | [文档](https://github.com/YunaiV/SpringBoot-Labs) | 94 | [Spring Boot](https://spring.io/projects/spring-boot) | 应用开发框架 | 2.4.2 | [文档](https://github.com/YunaiV/SpringBoot-Labs) |
95 | [MySQL](https://www.mysql.com/cn/) | 数据库服务器 | 5.7 | | 95 | [MySQL](https://www.mysql.com/cn/) | 数据库服务器 | 5.7 | |
96 | [Druid](https://github.com/alibaba/druid) | JDBC 连接池、监控组件 | 1.2.4 | [文档](http://www.iocoder.cn/Spring-Boot/datasource-pool/?yudao) | 96 | [Druid](https://github.com/alibaba/druid) | JDBC 连接池、监控组件 | 1.2.4 | [文档](http://www.iocoder.cn/Spring-Boot/datasource-pool/?yudao) |
97 -| [MyBatis-Plus](https://mp.baomidou.com/) | MyBatis 增强工具包 | 3.4.1 | [文档](http://www.iocoder.cn/Spring-Boot/MyBatis/?yudao) | 97 +| [MyBatis Plus](https://mp.baomidou.com/) | MyBatis 增强工具包 | 3.4.1 | [文档](http://www.iocoder.cn/Spring-Boot/MyBatis/?yudao) |
  98 +| [Dynamic Datasource](https://dynamic-datasource.com/) | 动态数据源 | 3.3.2 | [文档](hhttp://www.iocoder.cn/Spring-Boot/datasource-pool/?yudao) |
98 | [Redis](https://redis.io/) | key-value 数据库 | 5.0 | | 99 | [Redis](https://redis.io/) | key-value 数据库 | 5.0 | |
99 | [Redisson](https://github.com/redisson/redisson) | Redis 客户端 | 3.1.46 | [文档](http://www.iocoder.cn/Spring-Boot/Redis/?yudao) | 100 | [Redisson](https://github.com/redisson/redisson) | Redis 客户端 | 3.1.46 | [文档](http://www.iocoder.cn/Spring-Boot/Redis/?yudao) |
100 | [Spring MVC](https://github.com/spring-projects/spring-framework/tree/master/spring-webmvc) | MVC 框架 | 5.4.2 | [文档](http://www.iocoder.cn/SpringMVC/MVC/?yudao) | 101 | [Spring MVC](https://github.com/spring-projects/spring-framework/tree/master/spring-webmvc) | MVC 框架 | 5.4.2 | [文档](http://www.iocoder.cn/SpringMVC/MVC/?yudao) |
@@ -111,7 +112,7 @@ @@ -111,7 +112,7 @@
111 | [JUnit](https://junit.org/junit5/) | Java 单元测试框架 | 5.7.0 | - | 112 | [JUnit](https://junit.org/junit5/) | Java 单元测试框架 | 5.7.0 | - |
112 | [Mockito](https://github.com/mockito/mockito) | Java Mock 框架 | 3.6.28 | - | 113 | [Mockito](https://github.com/mockito/mockito) | Java Mock 框架 | 3.6.28 | - |
113 114
114 -**前端** 115 +### 前端
115 116
116 | 框架 | 说明 | 版本 | 117 | 框架 | 说明 | 版本 |
117 | --- | --- | --- | 118 | --- | --- | --- |
ruoyi-common/src/main/java/com/ruoyi/common/annotation/DataScope.java deleted
1 -package com.ruoyi.common.annotation;  
2 -  
3 -import java.lang.annotation.Documented;  
4 -import java.lang.annotation.ElementType;  
5 -import java.lang.annotation.Retention;  
6 -import java.lang.annotation.RetentionPolicy;  
7 -import java.lang.annotation.Target;  
8 -  
9 -/**  
10 - * 数据权限过滤注解  
11 - *  
12 - * @author ruoyi  
13 - */  
14 -@Target(ElementType.METHOD)  
15 -@Retention(RetentionPolicy.RUNTIME)  
16 -@Documented  
17 -public @interface DataScope {  
18 - /**  
19 - * 部门表的别名  
20 - */  
21 - public String deptAlias() default "";  
22 -  
23 - /**  
24 - * 用户表的别名  
25 - */  
26 - public String userAlias() default "";  
27 -}  
ruoyi-common/src/main/java/com/ruoyi/common/annotation/DataScopeAspect.java deleted
1 -package com.ruoyi.framework.aspectj;  
2 -  
3 -import java.lang.reflect.Method;  
4 -  
5 -import org.aspectj.lang.JoinPoint;  
6 -import org.aspectj.lang.Signature;  
7 -import org.aspectj.lang.annotation.Aspect;  
8 -import org.aspectj.lang.annotation.Before;  
9 -import org.aspectj.lang.annotation.Pointcut;  
10 -import org.aspectj.lang.reflect.MethodSignature;  
11 -import org.springframework.stereotype.Component;  
12 -import com.ruoyi.common.annotation.DataScope;  
13 -import com.ruoyi.common.core.domain.BaseEntity;  
14 -import com.ruoyi.common.core.domain.entity.SysRole;  
15 -import com.ruoyi.common.core.domain.entity.SysUser;  
16 -import com.ruoyi.common.core.domain.model.LoginUser;  
17 -import com.ruoyi.common.utils.ServletUtils;  
18 -import com.ruoyi.common.utils.StringUtils;  
19 -import com.ruoyi.common.utils.spring.SpringUtils;  
20 -import com.ruoyi.framework.web.service.TokenService;  
21 -  
22 -/**  
23 - * 数据过滤处理  
24 - *  
25 - * @author ruoyi  
26 - */  
27 -@Aspect  
28 -@Component  
29 -public class DataScopeAspect {  
30 - /**  
31 - * 全部数据权限  
32 - */  
33 - public static final String DATA_SCOPE_ALL = "1";  
34 -  
35 - /**  
36 - * 自定数据权限  
37 - */  
38 - public static final String DATA_SCOPE_CUSTOM = "2";  
39 -  
40 - /**  
41 - * 部门数据权限  
42 - */  
43 - public static final String DATA_SCOPE_DEPT = "3";  
44 -  
45 - /**  
46 - * 部门及以下数据权限  
47 - */  
48 - public static final String DATA_SCOPE_DEPT_AND_CHILD = "4";  
49 -  
50 - /**  
51 - * 仅本人数据权限  
52 - */  
53 - public static final String DATA_SCOPE_SELF = "5";  
54 -  
55 - /**  
56 - * 数据权限过滤关键字  
57 - */  
58 - public static final String DATA_SCOPE = "dataScope";  
59 -  
60 - // 配置织入点  
61 - @Pointcut("@annotation(com.ruoyi.common.annotation.DataScope)")  
62 - public void dataScopePointCut() {  
63 - }  
64 -  
65 - @Before("dataScopePointCut()")  
66 - public void doBefore(JoinPoint point) throws Throwable {  
67 - handleDataScope(point);  
68 - }  
69 -  
70 - protected void handleDataScope(final JoinPoint joinPoint) {  
71 - // 获得注解  
72 - DataScope controllerDataScope = getAnnotationLog(joinPoint);  
73 - if (controllerDataScope == null) {  
74 - return;  
75 - }  
76 - // 获取当前的用户  
77 - LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());  
78 - if (StringUtils.isNotNull(loginUser)) {  
79 - SysUser currentUser = loginUser.getUser();  
80 - // 如果是超级管理员,则不过滤数据  
81 - if (StringUtils.isNotNull(currentUser) && !currentUser.isAdmin()) {  
82 - dataScopeFilter(joinPoint, currentUser, controllerDataScope.deptAlias(),  
83 - controllerDataScope.userAlias());  
84 - }  
85 - }  
86 - }  
87 -  
88 - /**  
89 - * 数据范围过滤  
90 - *  
91 - * @param joinPoint 切点  
92 - * @param user 用户  
93 - * @param userAlias 别名  
94 - */  
95 - public static void dataScopeFilter(JoinPoint joinPoint, SysUser user, String deptAlias, String userAlias) {  
96 - StringBuilder sqlString = new StringBuilder();  
97 -  
98 - for (SysRole role : user.getRoles()) {  
99 - String dataScope = role.getDataScope();  
100 - if (DATA_SCOPE_ALL.equals(dataScope)) {  
101 - sqlString = new StringBuilder();  
102 - break;  
103 - } else if (DATA_SCOPE_CUSTOM.equals(dataScope)) {  
104 - sqlString.append(StringUtils.format(  
105 - " OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) ", deptAlias,  
106 - role.getRoleId()));  
107 - } else if (DATA_SCOPE_DEPT.equals(dataScope)) {  
108 - sqlString.append(StringUtils.format(" OR {}.dept_id = {} ", deptAlias, user.getDeptId()));  
109 - } else if (DATA_SCOPE_DEPT_AND_CHILD.equals(dataScope)) {  
110 - sqlString.append(StringUtils.format(  
111 - " OR {}.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = {} or find_in_set( {} , ancestors ) )",  
112 - deptAlias, user.getDeptId(), user.getDeptId()));  
113 - } else if (DATA_SCOPE_SELF.equals(dataScope)) {  
114 - if (StringUtils.isNotBlank(userAlias)) {  
115 - sqlString.append(StringUtils.format(" OR {}.user_id = {} ", userAlias, user.getUserId()));  
116 - } else {  
117 - // 数据权限为仅本人且没有userAlias别名不查询任何数据  
118 - sqlString.append(" OR 1=0 ");  
119 - }  
120 - }  
121 - }  
122 -  
123 - if (StringUtils.isNotBlank(sqlString.toString())) {  
124 - Object params = joinPoint.getArgs()[0];  
125 - if (StringUtils.isNotNull(params) && params instanceof BaseEntity) {  
126 - BaseEntity baseEntity = (BaseEntity) params;  
127 - baseEntity.getParams().put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")");  
128 - }  
129 - }  
130 - }  
131 -  
132 - /**  
133 - * 是否存在注解,如果存在就获取  
134 - */  
135 - private DataScope getAnnotationLog(JoinPoint joinPoint) {  
136 - Signature signature = joinPoint.getSignature();  
137 - MethodSignature methodSignature = (MethodSignature) signature;  
138 - Method method = methodSignature.getMethod();  
139 -  
140 - if (method != null) {  
141 - return method.getAnnotation(DataScope.class);  
142 - }  
143 - return null;  
144 - }  
145 -}  
src/main/java/cn/iocoder/dashboard/framework/datasource/core/enums/DataSourceEnum.java 0 → 100644
  1 +package cn.iocoder.dashboard.framework.datasource.core.enums;
  2 +
  3 +/**
  4 + * 对应于多数据源中不同数据源配置
  5 + *
  6 + * 通过在方法上,使用 {@link com.baomidou.dynamic.datasource.annotation.DS} 注解,设置使用的数据源。
  7 + * 注意,默认是 {@link #MASTER} 数据源
  8 + *
  9 + * 对应官方文档为 http://dynamic-datasource.com/guide/customize/Annotation.html
  10 + */
  11 +public interface DataSourceEnum {
  12 +
  13 + /**
  14 + * 主库,推荐使用 {@link com.baomidou.dynamic.datasource.annotation.Master} 注解
  15 + */
  16 + String MASTER = "master";
  17 + /**
  18 + * 从库,推荐使用 {@link com.baomidou.dynamic.datasource.annotation.Slave} 注解
  19 + */
  20 + String SLAVE = "slave";
  21 +
  22 +}
src/main/java/cn/iocoder/dashboard/framework/datasource/core/enums/DatasourceMark.java deleted
1 -package cn.iocoder.dashboard.framework.datasource.core.enums;  
2 -  
3 -/**  
4 - * 对应于多数据源中不同数据源配置  
5 - *  
6 - * 在方法上使用注解{@code @DS(DatasourceMark.slave)}可以指定slave数据源,默认是master数据源  
7 - */  
8 -public interface DatasourceMark {  
9 -  
10 - String MASTER = "master";  
11 -  
12 - String SLAVE = "slave";  
13 -  
14 -}  
src/main/java/cn/iocoder/dashboard/modules/tool/dal/mysql/codegen/ToolSchemaTableMapper.java
@@ -18,11 +18,7 @@ public interface ToolSchemaTableMapper extends BaseMapperX<ToolSchemaTableDO> { @@ -18,11 +18,7 @@ public interface ToolSchemaTableMapper extends BaseMapperX<ToolSchemaTableDO> {
18 .likeIfPresent("table_comment", tableComment)); 18 .likeIfPresent("table_comment", tableComment));
19 } 19 }
20 20
21 - default List<ToolSchemaTableDO> selectListByTableSchema(String tableSchema) {  
22 - return selectList(new QueryWrapper<ToolSchemaTableDO>().eq("table_schema", tableSchema));  
23 - }  
24 -  
25 - default ToolSchemaTableDO selectByTableName1(String tableSchema, String tableName) { 21 + default ToolSchemaTableDO selectByTableSchemaAndTableName(String tableSchema, String tableName) {
26 return selectOne(new QueryWrapper<ToolSchemaTableDO>().eq("table_schema",tableSchema) 22 return selectOne(new QueryWrapper<ToolSchemaTableDO>().eq("table_schema",tableSchema)
27 .eq("table_name", tableName)); 23 .eq("table_name", tableName));
28 } 24 }
src/main/java/cn/iocoder/dashboard/modules/tool/service/codegen/impl/ToolCodegenServiceImpl.java
@@ -101,10 +101,10 @@ public class ToolCodegenServiceImpl implements ToolCodegenService { @@ -101,10 +101,10 @@ public class ToolCodegenServiceImpl implements ToolCodegenService {
101 101
102 @Override 102 @Override
103 public Long createCodegen(String tableName) { 103 public Long createCodegen(String tableName) {
104 - //获取当前schema 104 + // 获取当前schema
105 String tableSchema = codegenProperties.getDbSchemas().iterator().next(); 105 String tableSchema = codegenProperties.getDbSchemas().iterator().next();
106 // 从数据库中,获得数据库表结构 106 // 从数据库中,获得数据库表结构
107 - ToolSchemaTableDO schemaTable = schemaTableMapper.selectByTableName1(tableSchema, tableName); 107 + ToolSchemaTableDO schemaTable = schemaTableMapper.selectByTableSchemaAndTableName(tableSchema, tableName);
108 List<ToolSchemaColumnDO> schemaColumns = schemaColumnMapper.selectListByTableName(tableSchema, tableName); 108 List<ToolSchemaColumnDO> schemaColumns = schemaColumnMapper.selectListByTableName(tableSchema, tableName);
109 // 导入 109 // 导入
110 return this.createCodegen0(ToolCodegenImportTypeEnum.DB, schemaTable, schemaColumns); 110 return this.createCodegen0(ToolCodegenImportTypeEnum.DB, schemaTable, schemaColumns);
src/main/resources/application-dev.yaml
@@ -4,39 +4,42 @@ server: @@ -4,39 +4,42 @@ server:
4 --- #################### 数据库相关配置 #################### 4 --- #################### 数据库相关配置 ####################
5 5
6 spring: 6 spring:
7 - # 数据源配置项 TODO 监控配置  
8 - # 排除默认的自动配置,使用dynamic-datasource-spring-boot-starter配置多数据源,整合druid 7 + # 数据源配置项
9 autoconfigure: 8 autoconfigure:
10 - exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure 9 + exclude:
  10 + - com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure # 排除 Druid 的自动配置,使用 dynamic-datasource-spring-boot-starter 配置多数据源
11 datasource: 11 datasource:
12 - druid: 12 + druid: # Druid 【监控】相关的全局配置
13 web-stat-filter: 13 web-stat-filter:
14 enabled: true 14 enabled: true
15 stat-view-servlet: 15 stat-view-servlet:
16 enabled: true 16 enabled: true
17 - # 设置白名单,不填则允许所有访问  
18 - allow: 17 + allow: # 设置白名单,不填则允许所有访问
19 url-pattern: /druid/* 18 url-pattern: /druid/*
20 - # 控制台管理用户名和密码  
21 - login-username: 19 + login-username: # 控制台管理用户名和密码
22 login-password: 20 login-password:
23 filter: 21 filter:
24 stat: 22 stat:
25 enabled: true 23 enabled: true
26 - # 慢 SQL 记录  
27 - log-slow-sql: true 24 + log-slow-sql: true # 慢 SQL 记录
28 slow-sql-millis: 100 25 slow-sql-millis: 100
29 merge-sql: true 26 merge-sql: true
30 wall: 27 wall:
31 config: 28 config:
32 multi-statement-allow: true 29 multi-statement-allow: true
33 - dynamic:  
34 - # druid全局配置 https://dynamic-datasource.com/en/guide/integration/Druid.html#configurate-parameters  
35 -# druid: #The following are the supported global parameters  
36 -# initial-size:  
37 -# max-active:  
38 -# min-idle:  
39 -# max-wait: 30 + dynamic: # 多数据源配置
  31 + druid: # Druid 【连接池】相关的全局配置
  32 + initial-size: 5 # 初始连接数
  33 + min-idle: 10 # 最小连接池数量
  34 + max-active: 20 # 最大连接池数量
  35 + max-wait: 600000 # 配置获取连接等待超时的时间,单位:毫秒
  36 + time-between-eviction-runs-millis: 60000 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位:毫秒
  37 + min-evictable-idle-time-millis: 300000 # 配置一个连接在池中最小生存的时间,单位:毫秒
  38 + max-evictable-idle-time-millis: 900000 # 配置一个连接在池中最大生存的时间,单位:毫秒
  39 + validation-query: SELECT 1 FROM DUAL # 配置检测连接是否有效
  40 + test-while-idle: true
  41 + test-on-borrow: false
  42 + test-on-return: false
40 primary: master 43 primary: master
41 datasource: 44 datasource:
42 master: 45 master:
@@ -45,19 +48,12 @@ spring: @@ -45,19 +48,12 @@ spring:
45 driver-class-name: com.mysql.jdbc.Driver 48 driver-class-name: com.mysql.jdbc.Driver
46 username: root 49 username: root
47 password: 3WLiVUBEwTbvAfsh 50 password: 3WLiVUBEwTbvAfsh
48 - # druid 局部配置  
49 -# druid: # The following are independent parameters that can be reset for each db  
50 -# validation-query: select 1 FROM DUAL #such as oracle need this  
51 -# slave:  
52 -# name: ruoyi-vue-pro-slave  
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  
55 -# username: root  
56 -# password: 123456  
57 -  
58 -  
59 -  
60 - 51 + slave: # 模拟从库,可根据自己需要修改 # 模拟从库,可根据自己需要修改
  52 + name: ruoyi-vue-pro
  53 + url: jdbc:mysql://400-infra.server.iocoder.cn:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT
  54 + driver-class-name: com.mysql.jdbc.Driver
  55 + username: root
  56 + password: 3WLiVUBEwTbvAfsh
61 57
62 # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 58 # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
63 redis: 59 redis:
@@ -103,9 +99,9 @@ apollo: @@ -103,9 +99,9 @@ apollo:
103 eagerLoad: 99 eagerLoad:
104 enabled: true # 设置 Apollo 在日志初始化前生效,可以实现日志的动态级别配置 100 enabled: true # 设置 Apollo 在日志初始化前生效,可以实现日志的动态级别配置
105 jdbc: # 自定义的 JDBC 配置项,用于数据库的地址 101 jdbc: # 自定义的 JDBC 配置项,用于数据库的地址
106 - url: ${spring.datasource.url}  
107 - username: ${spring.datasource.username}  
108 - password: ${spring.datasource.password} 102 + url: ${spring.datasource.dynamic.datasource.master.url}
  103 + username: ${spring.datasource.dynamic.datasource.master.username}
  104 + password: ${spring.datasource.dynamic.datasource.master.password}
109 105
110 --- #################### 服务保障相关配置 #################### 106 --- #################### 服务保障相关配置 ####################
111 107
@@ -181,7 +177,7 @@ yudao: @@ -181,7 +177,7 @@ yudao:
181 base-path: http://127.0.0.1:${server.port}${yudao.web.api-prefix}/system/file/get/ 177 base-path: http://127.0.0.1:${server.port}${yudao.web.api-prefix}/system/file/get/
182 codegen: 178 codegen:
183 base-package: ${yudao.info.base-package} 179 base-package: ${yudao.info.base-package}
184 - db-schemas: ${spring.datasource.name} 180 + db-schemas: ${spring.datasource.dynamic.datasource.master.name}
185 xss: 181 xss:
186 enable: false 182 enable: false
187 exclude-urls: # 如下两个 url,仅仅是为了演示,去掉配置也没关系 183 exclude-urls: # 如下两个 url,仅仅是为了演示,去掉配置也没关系
src/main/resources/application-local.yaml
@@ -4,7 +4,7 @@ server: @@ -4,7 +4,7 @@ server:
4 --- #################### 数据库相关配置 #################### 4 --- #################### 数据库相关配置 ####################
5 5
6 spring: 6 spring:
7 - # 数据源配置项 TODO 监控配置 7 + # 数据源配置项
8 autoconfigure: 8 autoconfigure:
9 exclude: 9 exclude:
10 - com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure # 排除 Druid 的自动配置,使用 dynamic-datasource-spring-boot-starter 配置多数据源 10 - com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure # 排除 Druid 的自动配置,使用 dynamic-datasource-spring-boot-starter 配置多数据源
@@ -48,8 +48,8 @@ spring: @@ -48,8 +48,8 @@ spring:
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: 123456
51 - slave:  
52 - name: ruoyi-vue-slave 51 + slave: # 模拟从库,可根据自己需要修改
  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
@@ -177,18 +177,10 @@ yudao: @@ -177,18 +177,10 @@ yudao:
177 base-path: http://127.0.0.1:${server.port}${yudao.web.api-prefix}/system/file/get/ 177 base-path: http://127.0.0.1:${server.port}${yudao.web.api-prefix}/system/file/get/
178 codegen: 178 codegen:
179 base-package: ${yudao.info.base-package} 179 base-package: ${yudao.info.base-package}
180 - db-schemas: ${spring.datasource.name} 180 + db-schemas: ${spring.datasource.dynamic.datasource.master.name}
181 xss: 181 xss:
182 enable: false 182 enable: false
183 exclude-urls: # 如下两个 url,仅仅是为了演示,去掉配置也没关系 183 exclude-urls: # 如下两个 url,仅仅是为了演示,去掉配置也没关系
184 - ${spring.boot.admin.context-path}/** # 不处理 Spring Boot Admin 的请求 184 - ${spring.boot.admin.context-path}/** # 不处理 Spring Boot Admin 的请求
185 - ${management.endpoints.web.base-path}/** # 不处理 Actuator 的请求 185 - ${management.endpoints.web.base-path}/** # 不处理 Actuator 的请求
186 demo: false # 关闭演示模式 186 demo: false # 关闭演示模式
187 -  
188 -  
189 -  
190 -  
191 -  
192 -  
193 -  
194 -  
src/main/resources/application.yaml
@@ -12,7 +12,6 @@ spring: @@ -12,7 +12,6 @@ spring:
12 max-file-size: 16MB # 单个文件大小 12 max-file-size: 16MB # 单个文件大小
13 max-request-size: 32MB # 设置总上传的文件大小 13 max-request-size: 32MB # 设置总上传的文件大小
14 14
15 - # Jackson 配置项  
16 jackson: 15 jackson:
17 serialization: 16 serialization:
18 write-dates-as-timestamps: true # 设置 Date 的格式,使用时间戳 17 write-dates-as-timestamps: true # 设置 Date 的格式,使用时间戳
@@ -32,3 +31,6 @@ mybatis-plus: @@ -32,3 +31,6 @@ mybatis-plus:
32 logic-not-delete-value: 0 # 逻辑未删除值(默认为 0) 31 logic-not-delete-value: 0 # 逻辑未删除值(默认为 0)
33 mapper-locations: classpath*:mapper/*.xml 32 mapper-locations: classpath*:mapper/*.xml
34 type-aliases-package: ${yudao.info.base-package}.modules.*.dal.dataobject 33 type-aliases-package: ${yudao.info.base-package}.modules.*.dal.dataobject
  34 +
  35 +--- #################### 芋道相关配置 ####################
  36 +
src/test-integration/java/cn/iocoder/dashboard/BaseDbAndRedisIntegrationTest.java
@@ -4,6 +4,8 @@ import cn.iocoder.dashboard.framework.datasource.config.DataSourceConfiguration; @@ -4,6 +4,8 @@ import cn.iocoder.dashboard.framework.datasource.config.DataSourceConfiguration;
4 import cn.iocoder.dashboard.framework.mybatis.config.MybatisConfiguration; 4 import cn.iocoder.dashboard.framework.mybatis.config.MybatisConfiguration;
5 import cn.iocoder.dashboard.framework.redis.config.RedisConfig; 5 import cn.iocoder.dashboard.framework.redis.config.RedisConfig;
6 import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure; 6 import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
  7 +import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceAutoConfiguration;
  8 +import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.druid.DruidDynamicDataSourceConfiguration;
7 import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration; 9 import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
8 import org.redisson.spring.starter.RedissonAutoConfiguration; 10 import org.redisson.spring.starter.RedissonAutoConfiguration;
9 import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; 11 import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
@@ -26,6 +28,9 @@ public class BaseDbAndRedisIntegrationTest { @@ -26,6 +28,9 @@ public class BaseDbAndRedisIntegrationTest {
26 // MyBatis 配置类 28 // MyBatis 配置类
27 MybatisConfiguration.class, // 自己的 MyBatis 配置类 29 MybatisConfiguration.class, // 自己的 MyBatis 配置类
28 MybatisPlusAutoConfiguration.class, // MyBatis 的自动配置类 30 MybatisPlusAutoConfiguration.class, // MyBatis 的自动配置类
  31 + // Dynamic Datasource 配置后类
  32 + DynamicDataSourceAutoConfiguration.class, //
  33 + DruidDynamicDataSourceConfiguration.class, //
29 // Redis 配置类 34 // Redis 配置类
30 RedisAutoConfiguration.class, // Spring Redis 自动配置类 35 RedisAutoConfiguration.class, // Spring Redis 自动配置类
31 RedisConfig.class, // 自己的 Redis 配置类 36 RedisConfig.class, // 自己的 Redis 配置类
src/test-integration/java/cn/iocoder/dashboard/modules/tool/dal/mysql/codegen/ToolInformationSchemaTableMapperTest.java
1 package cn.iocoder.dashboard.modules.tool.dal.mysql.codegen; 1 package cn.iocoder.dashboard.modules.tool.dal.mysql.codegen;
2 2
3 import cn.iocoder.dashboard.BaseDbUnitTest; 3 import cn.iocoder.dashboard.BaseDbUnitTest;
4 -import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolSchemaTableDO;  
5 -import org.junit.jupiter.api.Test;  
6 4
7 import javax.annotation.Resource; 5 import javax.annotation.Resource;
8 -import java.util.List;  
9 -  
10 -import static org.junit.jupiter.api.Assertions.assertTrue;  
11 6
12 class ToolInformationSchemaTableMapperTest extends BaseDbUnitTest { 7 class ToolInformationSchemaTableMapperTest extends BaseDbUnitTest {
13 8
14 @Resource 9 @Resource
15 private ToolSchemaTableMapper toolInformationSchemaTableMapper; 10 private ToolSchemaTableMapper toolInformationSchemaTableMapper;
16 11
17 - @Test  
18 - public void tstSelectListByTableSchema() {  
19 - List<ToolSchemaTableDO> tables = toolInformationSchemaTableMapper  
20 - .selectListByTableSchema("ruoyi-vue-pro");  
21 - assertTrue(tables.size() > 0);  
22 - }  
23 -  
24 } 12 }
src/test-integration/resources/application-integration-test.yaml
@@ -7,12 +7,37 @@ spring: @@ -7,12 +7,37 @@ spring:
7 7
8 spring: 8 spring:
9 # 数据源配置项 9 # 数据源配置项
  10 + autoconfigure:
  11 + exclude:
  12 + - com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure # 排除 Druid 的自动配置,使用 dynamic-datasource-spring-boot-starter 配置多数据源
10 datasource: 13 datasource:
11 - name: ruoyi-vue-pro  
12 - url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.name}?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT  
13 - driver-class-name: com.mysql.jdbc.Driver  
14 - username: root  
15 - password: 123456 14 + dynamic: # 多数据源配置
  15 + druid: # Druid 【连接池】相关的全局配置
  16 + initial-size: 5 # 初始连接数
  17 + min-idle: 10 # 最小连接池数量
  18 + max-active: 20 # 最大连接池数量
  19 + max-wait: 600000 # 配置获取连接等待超时的时间,单位:毫秒
  20 + time-between-eviction-runs-millis: 60000 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位:毫秒
  21 + min-evictable-idle-time-millis: 300000 # 配置一个连接在池中最小生存的时间,单位:毫秒
  22 + max-evictable-idle-time-millis: 900000 # 配置一个连接在池中最大生存的时间,单位:毫秒
  23 + validation-query: SELECT 1 FROM DUAL # 配置检测连接是否有效
  24 + test-while-idle: true
  25 + test-on-borrow: false
  26 + test-on-return: false
  27 + primary: master
  28 + datasource:
  29 + master:
  30 + name: ruoyi-vue-pro
  31 + url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.master.name}?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT
  32 + driver-class-name: com.mysql.jdbc.Driver
  33 + username: root
  34 + password: 123456
  35 + slave: # 模拟从库,可根据自己需要修改
  36 + name: ruoyi-vue-pro
  37 + url: jdbc:mysql://127.0.0.1:3306/${spring.datasource.dynamic.datasource.slave.name}?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT
  38 + driver-class-name: com.mysql.jdbc.Driver
  39 + username: root
  40 + password: 123456
16 41
17 # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 42 # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
18 redis: 43 redis:
@@ -70,7 +95,7 @@ yudao: @@ -70,7 +95,7 @@ yudao:
70 base-path: http://127.0.0.1:${server.port}/${yudao.web.api-prefix}/file/get/ 95 base-path: http://127.0.0.1:${server.port}/${yudao.web.api-prefix}/file/get/
71 codegen: 96 codegen:
72 base-package: ${yudao.info.base-package}.modules 97 base-package: ${yudao.info.base-package}.modules
73 - db-schemas: ${spring.datasource.name} 98 + db-schemas: ${spring.datasource.dynamic.datasource.master.name}
74 xss: 99 xss:
75 enable: false 100 enable: false
76 exclude-urls: # 如下两个 url,仅仅是为了演示,去掉配置也没关系 101 exclude-urls: # 如下两个 url,仅仅是为了演示,去掉配置也没关系