mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-19 09:55:16 +08:00
多数据源替换成dynamic-datasource
This commit is contained in:
parent
d98faaffee
commit
3a217c9ea2
9
pom.xml
9
pom.xml
@ -25,6 +25,7 @@
|
|||||||
<velocity.version>1.7</velocity.version>
|
<velocity.version>1.7</velocity.version>
|
||||||
<jwt.version>0.9.1</jwt.version>
|
<jwt.version>0.9.1</jwt.version>
|
||||||
<mybatis-plus.version>3.4.3</mybatis-plus.version>
|
<mybatis-plus.version>3.4.3</mybatis-plus.version>
|
||||||
|
<datasource.version>3.3.6</datasource.version>
|
||||||
<hutool.version>5.6.5</hutool.version>
|
<hutool.version>5.6.5</hutool.version>
|
||||||
<feign.version>2.2.6.RELEASE</feign.version>
|
<feign.version>2.2.6.RELEASE</feign.version>
|
||||||
<feign-okhttp.version>11.0</feign-okhttp.version>
|
<feign-okhttp.version>11.0</feign-okhttp.version>
|
||||||
@ -79,6 +80,13 @@
|
|||||||
<version>${jwt.version}</version>
|
<version>${jwt.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- dynamic-datasource 多数据源-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
|
||||||
|
<version>${datasource.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.baomidou</groupId>
|
<groupId>com.baomidou</groupId>
|
||||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
@ -89,6 +97,7 @@
|
|||||||
<artifactId>mybatis-plus-extension</artifactId>
|
<artifactId>mybatis-plus-extension</artifactId>
|
||||||
<version>${mybatis-plus.version}</version>
|
<version>${mybatis-plus.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.hutool</groupId>
|
<groupId>cn.hutool</groupId>
|
||||||
<artifactId>hutool-all</artifactId>
|
<artifactId>hutool-all</artifactId>
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package com.ruoyi;
|
package com.ruoyi;
|
||||||
|
|
||||||
|
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||||
@ -10,7 +11,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
|||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
|
@SpringBootApplication
|
||||||
public class RuoYiApplication
|
public class RuoYiApplication
|
||||||
{
|
{
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
|
|||||||
@ -1,70 +1,73 @@
|
|||||||
# 数据源配置
|
# 数据源配置
|
||||||
spring:
|
spring:
|
||||||
|
autoconfigure:
|
||||||
|
exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
|
||||||
datasource:
|
datasource:
|
||||||
type: com.alibaba.druid.pool.DruidDataSource
|
type: com.alibaba.druid.pool.DruidDataSource
|
||||||
driverClassName: com.mysql.cj.jdbc.Driver
|
driverClassName: com.mysql.cj.jdbc.Driver
|
||||||
druid:
|
dynamic:
|
||||||
# 主库数据源
|
druid:
|
||||||
master:
|
# 初始连接数
|
||||||
url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true
|
initialSize: 5
|
||||||
username: root
|
# 最小连接池数量
|
||||||
password: root
|
minIdle: 10
|
||||||
# 从库数据源
|
# 最大连接池数量
|
||||||
slave:
|
maxActive: 20
|
||||||
# 从数据源开关/默认关闭
|
# 配置获取连接等待超时的时间
|
||||||
enabled: false
|
maxWait: 60000
|
||||||
url:
|
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
|
||||||
username:
|
timeBetweenEvictionRunsMillis: 60000
|
||||||
password:
|
# 配置一个连接在池中最小生存的时间,单位是毫秒
|
||||||
# 初始连接数
|
minEvictableIdleTimeMillis: 300000
|
||||||
initialSize: 5
|
# 配置一个连接在池中最大生存的时间,单位是毫秒
|
||||||
# 最小连接池数量
|
maxEvictableIdleTimeMillis: 900000
|
||||||
minIdle: 10
|
# 配置检测连接是否有效
|
||||||
# 最大连接池数量
|
validationQuery: SELECT 1 FROM DUAL
|
||||||
maxActive: 20
|
testWhileIdle: true
|
||||||
# 配置获取连接等待超时的时间
|
testOnBorrow: false
|
||||||
maxWait: 60000
|
testOnReturn: false
|
||||||
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
|
filters: stat # 注意这个值和druid原生不一致,默认启动了stat
|
||||||
timeBetweenEvictionRunsMillis: 60000
|
webStatFilter:
|
||||||
# 配置一个连接在池中最小生存的时间,单位是毫秒
|
|
||||||
minEvictableIdleTimeMillis: 300000
|
|
||||||
# 配置一个连接在池中最大生存的时间,单位是毫秒
|
|
||||||
maxEvictableIdleTimeMillis: 900000
|
|
||||||
# 配置检测连接是否有效
|
|
||||||
validationQuery: SELECT 1 FROM DUAL
|
|
||||||
testWhileIdle: true
|
|
||||||
testOnBorrow: false
|
|
||||||
testOnReturn: false
|
|
||||||
webStatFilter:
|
|
||||||
enabled: true
|
|
||||||
statViewServlet:
|
|
||||||
enabled: true
|
|
||||||
# 设置白名单,不填则允许所有访问
|
|
||||||
allow:
|
|
||||||
url-pattern: /druid/*
|
|
||||||
# 控制台管理用户名和密码
|
|
||||||
login-username: ruoyi
|
|
||||||
login-password: 123456
|
|
||||||
filter:
|
|
||||||
stat:
|
|
||||||
enabled: true
|
enabled: true
|
||||||
# 慢SQL记录
|
statViewServlet:
|
||||||
log-slow-sql: true
|
enabled: true
|
||||||
slow-sql-millis: 1000
|
# 设置白名单,不填则允许所有访问
|
||||||
merge-sql: true
|
allow:
|
||||||
wall:
|
url-pattern: /druid/*
|
||||||
config:
|
# 控制台管理用户名和密码
|
||||||
multi-statement-allow: true
|
login-username: ruoyi
|
||||||
|
login-password: 123456
|
||||||
|
filter:
|
||||||
|
stat:
|
||||||
|
enabled: true
|
||||||
|
# 慢SQL记录
|
||||||
|
log-slow-sql: true
|
||||||
|
slow-sql-millis: 1000
|
||||||
|
merge-sql: true
|
||||||
|
wall:
|
||||||
|
config:
|
||||||
|
multi-statement-allow: true
|
||||||
|
datasource:
|
||||||
|
# 主库数据源
|
||||||
|
master:
|
||||||
|
url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true
|
||||||
|
username: root
|
||||||
|
password: root123456
|
||||||
|
# 从库数据源
|
||||||
|
slave:
|
||||||
|
url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true
|
||||||
|
username: root
|
||||||
|
password: root123456
|
||||||
# redis 配置
|
# redis 配置
|
||||||
redis:
|
redis:
|
||||||
# 地址
|
# 地址
|
||||||
host: localhost
|
host: 127.0.0.1
|
||||||
# 端口,默认为6379
|
# 端口,默认为6379
|
||||||
port: 6379
|
port: 6379
|
||||||
# 数据库索引
|
# 数据库索引
|
||||||
database: 0
|
database: 0
|
||||||
# 密码
|
# 密码
|
||||||
password:
|
password: root123456
|
||||||
# 连接超时时间
|
# 连接超时时间
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
# 是否开启ssl
|
# 是否开启ssl
|
||||||
|
|||||||
@ -3,68 +3,70 @@ spring:
|
|||||||
datasource:
|
datasource:
|
||||||
type: com.alibaba.druid.pool.DruidDataSource
|
type: com.alibaba.druid.pool.DruidDataSource
|
||||||
driverClassName: com.mysql.cj.jdbc.Driver
|
driverClassName: com.mysql.cj.jdbc.Driver
|
||||||
druid:
|
dynamic:
|
||||||
# 主库数据源
|
druid:
|
||||||
master:
|
# 主库数据源
|
||||||
url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true
|
master:
|
||||||
username: root
|
url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true
|
||||||
password: root
|
username: root
|
||||||
# 从库数据源
|
password: root123456
|
||||||
slave:
|
# 从库数据源
|
||||||
# 从数据源开关/默认关闭
|
slave:
|
||||||
enabled: false
|
# 从数据源开关/默认关闭
|
||||||
url:
|
enabled: false
|
||||||
username:
|
url:
|
||||||
password:
|
username:
|
||||||
# 初始连接数
|
password:
|
||||||
initialSize: 5
|
# 初始连接数
|
||||||
# 最小连接池数量
|
initialSize: 5
|
||||||
minIdle: 10
|
# 最小连接池数量
|
||||||
# 最大连接池数量
|
minIdle: 10
|
||||||
maxActive: 20
|
# 最大连接池数量
|
||||||
# 配置获取连接等待超时的时间
|
maxActive: 20
|
||||||
maxWait: 60000
|
# 配置获取连接等待超时的时间
|
||||||
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
|
maxWait: 60000
|
||||||
timeBetweenEvictionRunsMillis: 60000
|
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
|
||||||
# 配置一个连接在池中最小生存的时间,单位是毫秒
|
timeBetweenEvictionRunsMillis: 60000
|
||||||
minEvictableIdleTimeMillis: 300000
|
# 配置一个连接在池中最小生存的时间,单位是毫秒
|
||||||
# 配置一个连接在池中最大生存的时间,单位是毫秒
|
minEvictableIdleTimeMillis: 300000
|
||||||
maxEvictableIdleTimeMillis: 900000
|
# 配置一个连接在池中最大生存的时间,单位是毫秒
|
||||||
# 配置检测连接是否有效
|
maxEvictableIdleTimeMillis: 900000
|
||||||
validationQuery: SELECT 1 FROM DUAL
|
# 配置检测连接是否有效
|
||||||
testWhileIdle: true
|
validationQuery: SELECT 1 FROM DUAL
|
||||||
testOnBorrow: false
|
testWhileIdle: true
|
||||||
testOnReturn: false
|
testOnBorrow: false
|
||||||
webStatFilter:
|
testOnReturn: false
|
||||||
enabled: true
|
webStatFilter:
|
||||||
statViewServlet:
|
|
||||||
enabled: true
|
|
||||||
# 设置白名单,不填则允许所有访问
|
|
||||||
allow:
|
|
||||||
url-pattern: /druid/*
|
|
||||||
# 控制台管理用户名和密码
|
|
||||||
login-username: ruoyi
|
|
||||||
login-password: 123456
|
|
||||||
filter:
|
|
||||||
stat:
|
|
||||||
enabled: true
|
enabled: true
|
||||||
# 慢SQL记录
|
statViewServlet:
|
||||||
log-slow-sql: true
|
enabled: true
|
||||||
slow-sql-millis: 1000
|
# 设置白名单,不填则允许所有访问
|
||||||
merge-sql: true
|
allow:
|
||||||
wall:
|
url-pattern: /druid/*
|
||||||
config:
|
# 控制台管理用户名和密码
|
||||||
multi-statement-allow: true
|
login-username: ruoyi
|
||||||
|
login-password: 123456
|
||||||
|
filter:
|
||||||
|
stat:
|
||||||
|
enabled: true
|
||||||
|
# 慢SQL记录
|
||||||
|
log-slow-sql: true
|
||||||
|
slow-sql-millis: 1000
|
||||||
|
merge-sql: true
|
||||||
|
wall:
|
||||||
|
config:
|
||||||
|
multi-statement-allow: true
|
||||||
|
|
||||||
# redis 配置
|
# redis 配置
|
||||||
redis:
|
redis:
|
||||||
# 地址
|
# 地址
|
||||||
host: 192.168.0.222
|
host: 127.0.0.1
|
||||||
# 端口,默认为6379
|
# 端口,默认为6379
|
||||||
port: 6379
|
port: 6379
|
||||||
# 数据库索引
|
# 数据库索引
|
||||||
database: 0
|
database: 0
|
||||||
# 密码
|
# 密码
|
||||||
password:
|
password: root123456
|
||||||
# 连接超时时间
|
# 连接超时时间
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
# 是否开启ssl
|
# 是否开启ssl
|
||||||
|
|||||||
@ -1,28 +1,28 @@
|
|||||||
package com.ruoyi.common.annotation;
|
//package com.ruoyi.common.annotation;
|
||||||
|
//
|
||||||
import java.lang.annotation.Documented;
|
//import java.lang.annotation.Documented;
|
||||||
import java.lang.annotation.ElementType;
|
//import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Inherited;
|
//import java.lang.annotation.Inherited;
|
||||||
import java.lang.annotation.Retention;
|
//import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
//import java.lang.annotation.RetentionPolicy;
|
||||||
import java.lang.annotation.Target;
|
//import java.lang.annotation.Target;
|
||||||
import com.ruoyi.common.enums.DataSourceType;
|
//import com.ruoyi.common.enums.DataSourceType;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* 自定义多数据源切换注解
|
// * 自定义多数据源切换注解
|
||||||
*
|
// *
|
||||||
* 优先级:先方法,后类,如果方法覆盖了类上的数据源类型,以方法的为准,否则以类上的为准
|
// * 优先级:先方法,后类,如果方法覆盖了类上的数据源类型,以方法的为准,否则以类上的为准
|
||||||
*
|
// *
|
||||||
* @author ruoyi
|
// * @author ruoyi
|
||||||
*/
|
// */
|
||||||
@Target({ ElementType.METHOD, ElementType.TYPE })
|
//@Target({ ElementType.METHOD, ElementType.TYPE })
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
//@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Documented
|
//@Documented
|
||||||
@Inherited
|
//@Inherited
|
||||||
public @interface DataSource
|
//public @interface DataSource
|
||||||
{
|
//{
|
||||||
/**
|
// /**
|
||||||
* 切换数据源名称
|
// * 切换数据源名称
|
||||||
*/
|
// */
|
||||||
public DataSourceType value() default DataSourceType.MASTER;
|
// public DataSourceType value() default DataSourceType.MASTER;
|
||||||
}
|
//}
|
||||||
|
|||||||
@ -1,73 +1,73 @@
|
|||||||
package com.ruoyi.framework.aspectj;
|
//package com.ruoyi.framework.aspectj;
|
||||||
|
//
|
||||||
import cn.hutool.core.lang.Validator;
|
//import cn.hutool.core.lang.Validator;
|
||||||
import com.ruoyi.common.annotation.DataSource;
|
//import com.ruoyi.common.annotation.DataSource;
|
||||||
import com.ruoyi.framework.datasource.DynamicDataSourceContextHolder;
|
//import com.ruoyi.framework.datasource.DynamicDataSourceContextHolder;
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
//import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
import org.aspectj.lang.annotation.Around;
|
//import org.aspectj.lang.annotation.Around;
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
//import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.aspectj.lang.annotation.Pointcut;
|
//import org.aspectj.lang.annotation.Pointcut;
|
||||||
import org.aspectj.lang.reflect.MethodSignature;
|
//import org.aspectj.lang.reflect.MethodSignature;
|
||||||
import org.slf4j.Logger;
|
//import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
//import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.core.annotation.AnnotationUtils;
|
//import org.springframework.core.annotation.AnnotationUtils;
|
||||||
import org.springframework.core.annotation.Order;
|
//import org.springframework.core.annotation.Order;
|
||||||
import org.springframework.stereotype.Component;
|
//import org.springframework.stereotype.Component;
|
||||||
|
//
|
||||||
import java.util.Objects;
|
//import java.util.Objects;
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* 多数据源处理
|
// * 多数据源处理
|
||||||
*
|
// *
|
||||||
* @author ruoyi
|
// * @author ruoyi
|
||||||
*/
|
// */
|
||||||
@Aspect
|
//@Aspect
|
||||||
@Order(1)
|
//@Order(1)
|
||||||
@Component
|
//@Component
|
||||||
public class DataSourceAspect
|
//public class DataSourceAspect
|
||||||
{
|
//{
|
||||||
protected Logger logger = LoggerFactory.getLogger(getClass());
|
// protected Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
|
//
|
||||||
@Pointcut("@annotation(com.ruoyi.common.annotation.DataSource)"
|
// @Pointcut("@annotation(com.ruoyi.common.annotation.DataSource)"
|
||||||
+ "|| @within(com.ruoyi.common.annotation.DataSource)")
|
// + "|| @within(com.ruoyi.common.annotation.DataSource)")
|
||||||
public void dsPointCut()
|
// public void dsPointCut()
|
||||||
{
|
// {
|
||||||
|
//
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Around("dsPointCut()")
|
// @Around("dsPointCut()")
|
||||||
public Object around(ProceedingJoinPoint point) throws Throwable
|
// public Object around(ProceedingJoinPoint point) throws Throwable
|
||||||
{
|
// {
|
||||||
DataSource dataSource = getDataSource(point);
|
// DataSource dataSource = getDataSource(point);
|
||||||
|
//
|
||||||
if (Validator.isNotNull(dataSource))
|
// if (Validator.isNotNull(dataSource))
|
||||||
{
|
// {
|
||||||
DynamicDataSourceContextHolder.setDataSourceType(dataSource.value().name());
|
// DynamicDataSourceContextHolder.setDataSourceType(dataSource.value().name());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
return point.proceed();
|
// return point.proceed();
|
||||||
}
|
// }
|
||||||
finally
|
// finally
|
||||||
{
|
// {
|
||||||
// 销毁数据源 在执行方法之后
|
// // 销毁数据源 在执行方法之后
|
||||||
DynamicDataSourceContextHolder.clearDataSourceType();
|
// DynamicDataSourceContextHolder.clearDataSourceType();
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 获取需要切换的数据源
|
// * 获取需要切换的数据源
|
||||||
*/
|
// */
|
||||||
public DataSource getDataSource(ProceedingJoinPoint point)
|
// public DataSource getDataSource(ProceedingJoinPoint point)
|
||||||
{
|
// {
|
||||||
MethodSignature signature = (MethodSignature) point.getSignature();
|
// MethodSignature signature = (MethodSignature) point.getSignature();
|
||||||
DataSource dataSource = AnnotationUtils.findAnnotation(signature.getMethod(), DataSource.class);
|
// DataSource dataSource = AnnotationUtils.findAnnotation(signature.getMethod(), DataSource.class);
|
||||||
if (Objects.nonNull(dataSource))
|
// if (Objects.nonNull(dataSource))
|
||||||
{
|
// {
|
||||||
return dataSource;
|
// return dataSource;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return AnnotationUtils.findAnnotation(signature.getDeclaringType(), DataSource.class);
|
// return AnnotationUtils.findAnnotation(signature.getDeclaringType(), DataSource.class);
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|||||||
@ -1,126 +0,0 @@
|
|||||||
package com.ruoyi.framework.config;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import javax.servlet.Filter;
|
|
||||||
import javax.servlet.FilterChain;
|
|
||||||
import javax.servlet.ServletException;
|
|
||||||
import javax.servlet.ServletRequest;
|
|
||||||
import javax.servlet.ServletResponse;
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
||||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.context.annotation.Primary;
|
|
||||||
import com.alibaba.druid.pool.DruidDataSource;
|
|
||||||
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
|
|
||||||
import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties;
|
|
||||||
import com.alibaba.druid.util.Utils;
|
|
||||||
import com.ruoyi.common.enums.DataSourceType;
|
|
||||||
import com.ruoyi.common.utils.spring.SpringUtils;
|
|
||||||
import com.ruoyi.framework.config.properties.DruidProperties;
|
|
||||||
import com.ruoyi.framework.datasource.DynamicDataSource;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* druid 配置多数据源
|
|
||||||
*
|
|
||||||
* @author ruoyi
|
|
||||||
*/
|
|
||||||
@Configuration
|
|
||||||
public class DruidConfig
|
|
||||||
{
|
|
||||||
@Bean
|
|
||||||
@ConfigurationProperties("spring.datasource.druid.master")
|
|
||||||
public DataSource masterDataSource(DruidProperties druidProperties)
|
|
||||||
{
|
|
||||||
DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
|
|
||||||
return druidProperties.dataSource(dataSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean
|
|
||||||
@ConfigurationProperties("spring.datasource.druid.slave")
|
|
||||||
@ConditionalOnProperty(prefix = "spring.datasource.druid.slave", name = "enabled", havingValue = "true")
|
|
||||||
public DataSource slaveDataSource(DruidProperties druidProperties)
|
|
||||||
{
|
|
||||||
DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
|
|
||||||
return druidProperties.dataSource(dataSource);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Bean(name = "dynamicDataSource")
|
|
||||||
@Primary
|
|
||||||
public DynamicDataSource dataSource(DataSource masterDataSource)
|
|
||||||
{
|
|
||||||
Map<Object, Object> targetDataSources = new HashMap<>();
|
|
||||||
targetDataSources.put(DataSourceType.MASTER.name(), masterDataSource);
|
|
||||||
setDataSource(targetDataSources, DataSourceType.SLAVE.name(), "slaveDataSource");
|
|
||||||
return new DynamicDataSource(masterDataSource, targetDataSources);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置数据源
|
|
||||||
*
|
|
||||||
* @param targetDataSources 备选数据源集合
|
|
||||||
* @param sourceName 数据源名称
|
|
||||||
* @param beanName bean名称
|
|
||||||
*/
|
|
||||||
public void setDataSource(Map<Object, Object> targetDataSources, String sourceName, String beanName)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
DataSource dataSource = SpringUtils.getBean(beanName);
|
|
||||||
targetDataSources.put(sourceName, dataSource);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 去除监控页面底部的广告
|
|
||||||
*/
|
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
|
||||||
@Bean
|
|
||||||
@ConditionalOnProperty(name = "spring.datasource.druid.statViewServlet.enabled", havingValue = "true")
|
|
||||||
public FilterRegistrationBean removeDruidFilterRegistrationBean(DruidStatProperties properties)
|
|
||||||
{
|
|
||||||
// 获取web监控页面的参数
|
|
||||||
DruidStatProperties.StatViewServlet config = properties.getStatViewServlet();
|
|
||||||
// 提取common.js的配置路径
|
|
||||||
String pattern = config.getUrlPattern() != null ? config.getUrlPattern() : "/druid/*";
|
|
||||||
String commonJsPattern = pattern.replaceAll("\\*", "js/common.js");
|
|
||||||
final String filePath = "support/http/resources/js/common.js";
|
|
||||||
// 创建filter进行过滤
|
|
||||||
Filter filter = new Filter()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void init(javax.servlet.FilterConfig filterConfig) throws ServletException
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
|
||||||
throws IOException, ServletException
|
|
||||||
{
|
|
||||||
chain.doFilter(request, response);
|
|
||||||
// 重置缓冲区,响应头不会被重置
|
|
||||||
// response.resetBuffer();
|
|
||||||
// 获取common.js
|
|
||||||
String text = Utils.readFromResource(filePath);
|
|
||||||
// 正则替换banner, 除去底部的广告信息
|
|
||||||
text = text.replaceAll("<a.*?banner\"></a><br/>", "");
|
|
||||||
text = text.replaceAll("powered.*?shrek.wang</a>", "");
|
|
||||||
response.getWriter().write(text);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void destroy()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
|
||||||
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
|
|
||||||
registrationBean.setFilter(filter);
|
|
||||||
registrationBean.addUrlPatterns(commonJsPattern);
|
|
||||||
return registrationBean;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,67 @@
|
|||||||
|
package com.ruoyi.framework.config;
|
||||||
|
|
||||||
|
import com.baomidou.dynamic.datasource.plugin.MasterSlaveAutoRoutingPlugin;
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在纯的读写分离环境,写操作全部是master,读操作全部是slave
|
||||||
|
* @author ding
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class DynamicDataSourceConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public MasterSlaveAutoRoutingPlugin masterSlaveAutoRoutingPlugin(){
|
||||||
|
return new MasterSlaveAutoRoutingPlugin();
|
||||||
|
}
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * 去除监控页面底部的广告
|
||||||
|
// */
|
||||||
|
// @SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
|
// @Bean
|
||||||
|
// @ConditionalOnProperty(name = "spring.datasource.dynamic.druid.statViewServlet.enabled", havingValue = "true")
|
||||||
|
// public FilterRegistrationBean removeDruidFilterRegistrationBean(DruidStatProperties properties)
|
||||||
|
// {
|
||||||
|
// // 获取web监控页面的参数
|
||||||
|
// DruidStatProperties.StatViewServlet config = properties.getStatViewServlet();
|
||||||
|
// // 提取common.js的配置路径
|
||||||
|
// String pattern = config.getUrlPattern() != null ? config.getUrlPattern() : "/druid/*";
|
||||||
|
// String commonJsPattern = pattern.replaceAll("\\*", "js/common.js");
|
||||||
|
// final String filePath = "support/http/resources/js/common.js";
|
||||||
|
// // 创建filter进行过滤
|
||||||
|
// Filter filter = new Filter()
|
||||||
|
// {
|
||||||
|
// @Override
|
||||||
|
// public void init(javax.servlet.FilterConfig filterConfig) throws ServletException
|
||||||
|
// {
|
||||||
|
// }
|
||||||
|
// @Override
|
||||||
|
// public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
||||||
|
// throws IOException, ServletException
|
||||||
|
// {
|
||||||
|
// chain.doFilter(request, response);
|
||||||
|
// // 重置缓冲区,响应头不会被重置
|
||||||
|
//// response.resetBuffer();
|
||||||
|
// // 获取common.js
|
||||||
|
// String text = Utils.readFromResource(filePath);
|
||||||
|
// // 正则替换banner, 除去底部的广告信息
|
||||||
|
// text = text.replaceAll("<a.*?banner\"></a><br/>", "");
|
||||||
|
// text = text.replaceAll("powered.*?shrek.wang</a>", "");
|
||||||
|
// response.getWriter().write(text);
|
||||||
|
// }
|
||||||
|
// @Override
|
||||||
|
// public void destroy()
|
||||||
|
// {
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
// FilterRegistrationBean registrationBean = new FilterRegistrationBean();
|
||||||
|
// registrationBean.setFilter(filter);
|
||||||
|
// registrationBean.addUrlPatterns(commonJsPattern);
|
||||||
|
// return registrationBean;
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
@ -12,7 +12,7 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConfigurationProperties(prefix = "spring.datasource.druid")
|
@ConfigurationProperties(prefix = "spring.datasource.dynamic.druid")
|
||||||
public class DruidProperties {
|
public class DruidProperties {
|
||||||
|
|
||||||
/** 初始连接数 */
|
/** 初始连接数 */
|
||||||
|
|||||||
@ -1,26 +0,0 @@
|
|||||||
package com.ruoyi.framework.datasource;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 动态数据源
|
|
||||||
*
|
|
||||||
* @author ruoyi
|
|
||||||
*/
|
|
||||||
public class DynamicDataSource extends AbstractRoutingDataSource
|
|
||||||
{
|
|
||||||
public DynamicDataSource(DataSource defaultTargetDataSource, Map<Object, Object> targetDataSources)
|
|
||||||
{
|
|
||||||
super.setDefaultTargetDataSource(defaultTargetDataSource);
|
|
||||||
super.setTargetDataSources(targetDataSources);
|
|
||||||
super.afterPropertiesSet();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Object determineCurrentLookupKey()
|
|
||||||
{
|
|
||||||
return DynamicDataSourceContextHolder.getDataSourceType();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,45 +0,0 @@
|
|||||||
package com.ruoyi.framework.datasource;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据源切换处理
|
|
||||||
*
|
|
||||||
* @author ruoyi
|
|
||||||
*/
|
|
||||||
public class DynamicDataSourceContextHolder
|
|
||||||
{
|
|
||||||
public static final Logger log = LoggerFactory.getLogger(DynamicDataSourceContextHolder.class);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 使用ThreadLocal维护变量,ThreadLocal为每个使用该变量的线程提供独立的变量副本,
|
|
||||||
* 所以每一个线程都可以独立地改变自己的副本,而不会影响其它线程所对应的副本。
|
|
||||||
*/
|
|
||||||
private static final ThreadLocal<String> CONTEXT_HOLDER = new ThreadLocal<>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置数据源的变量
|
|
||||||
*/
|
|
||||||
public static void setDataSourceType(String dsType)
|
|
||||||
{
|
|
||||||
log.info("切换到{}数据源", dsType);
|
|
||||||
CONTEXT_HOLDER.set(dsType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获得数据源的变量
|
|
||||||
*/
|
|
||||||
public static String getDataSourceType()
|
|
||||||
{
|
|
||||||
return CONTEXT_HOLDER.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 清空数据源变量
|
|
||||||
*/
|
|
||||||
public static void clearDataSourceType()
|
|
||||||
{
|
|
||||||
CONTEXT_HOLDER.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -23,6 +23,12 @@
|
|||||||
<artifactId>ruoyi-common</artifactId>
|
<artifactId>ruoyi-common</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- dynamic-datasource 多数据源-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@ -5,7 +5,7 @@ import cn.hutool.core.lang.Validator;
|
|||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.ruoyi.common.annotation.DataSource;
|
//import com.ruoyi.common.annotation.DataSource;
|
||||||
import com.ruoyi.common.constant.Constants;
|
import com.ruoyi.common.constant.Constants;
|
||||||
import com.ruoyi.common.constant.UserConstants;
|
import com.ruoyi.common.constant.UserConstants;
|
||||||
import com.ruoyi.common.core.page.TableDataInfo;
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
@ -67,7 +67,7 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
|
|||||||
* @return 参数配置信息
|
* @return 参数配置信息
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@DataSource(DataSourceType.MASTER)
|
// @DataSource(DataSourceType.MASTER)
|
||||||
public SysConfig selectConfigById(Long configId) {
|
public SysConfig selectConfigById(Long configId) {
|
||||||
return baseMapper.selectById(configId);
|
return baseMapper.selectById(configId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,9 @@ package com.ruoyi.system.service.impl;
|
|||||||
|
|
||||||
import cn.hutool.core.lang.Validator;
|
import cn.hutool.core.lang.Validator;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
|
||||||
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||||
|
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
@ -16,9 +19,11 @@ import com.ruoyi.system.mapper.SysDeptMapper;
|
|||||||
import com.ruoyi.system.mapper.SysRoleMapper;
|
import com.ruoyi.system.mapper.SysRoleMapper;
|
||||||
import com.ruoyi.system.mapper.SysUserMapper;
|
import com.ruoyi.system.mapper.SysUserMapper;
|
||||||
import com.ruoyi.system.service.ISysDeptService;
|
import com.ruoyi.system.service.ISysDeptService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -31,6 +36,7 @@ import java.util.stream.Collectors;
|
|||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
|
@Slf4j
|
||||||
public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> implements ISysDeptService {
|
public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> implements ISysDeptService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -39,6 +45,10 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|||||||
@Autowired
|
@Autowired
|
||||||
private SysUserMapper userMapper;
|
private SysUserMapper userMapper;
|
||||||
|
|
||||||
|
//测试当前数据源
|
||||||
|
@Autowired
|
||||||
|
private DataSource dataSource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询部门管理数据
|
* 查询部门管理数据
|
||||||
*
|
*
|
||||||
@ -48,6 +58,10 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|||||||
@Override
|
@Override
|
||||||
@DataScope(deptAlias = "d")
|
@DataScope(deptAlias = "d")
|
||||||
public List<SysDept> selectDeptList(SysDept dept) {
|
public List<SysDept> selectDeptList(SysDept dept) {
|
||||||
|
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource;
|
||||||
|
DataSource datasource=ds.determineDataSource();
|
||||||
|
String dataName = DynamicDataSourceContextHolder.peek();
|
||||||
|
log.info("--查询部门管理数据---当前数据源名称:"+dataName);
|
||||||
return baseMapper.selectDeptList(dept);
|
return baseMapper.selectDeptList(dept);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +123,12 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|||||||
* @return 部门信息
|
* @return 部门信息
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@DS("slave")
|
||||||
public SysDept selectDeptById(Long deptId) {
|
public SysDept selectDeptById(Long deptId) {
|
||||||
|
DynamicRoutingDataSource ds = (DynamicRoutingDataSource) dataSource;
|
||||||
|
DataSource datasource=ds.determineDataSource();
|
||||||
|
String dataName = DynamicDataSourceContextHolder.peek();
|
||||||
|
log.info("mp内置方法--根据部门ID查询信息---当前数据源名称:"+dataName);
|
||||||
return getById(deptId);
|
return getById(deptId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,6 +198,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@DS("slave")
|
||||||
public int insertDept(SysDept dept) {
|
public int insertDept(SysDept dept) {
|
||||||
SysDept info = getById(dept.getParentId());
|
SysDept info = getById(dept.getParentId());
|
||||||
// 如果父节点不为正常状态,则不允许新增子节点
|
// 如果父节点不为正常状态,则不允许新增子节点
|
||||||
@ -186,6 +206,8 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|||||||
throw new CustomException("部门停用,不允许新增");
|
throw new CustomException("部门停用,不允许新增");
|
||||||
}
|
}
|
||||||
dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
|
dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
|
||||||
|
String dataName = DynamicDataSourceContextHolder.peek();
|
||||||
|
log.info("mp内置方法--新增保存部门信息---当前数据源名称:"+dataName);
|
||||||
return baseMapper.insert(dept);
|
return baseMapper.insert(dept);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,6 +218,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@DS("slave")
|
||||||
public int updateDept(SysDept dept) {
|
public int updateDept(SysDept dept) {
|
||||||
SysDept newParentDept = getById(dept.getParentId());
|
SysDept newParentDept = getById(dept.getParentId());
|
||||||
SysDept oldDept = getById(dept.getDeptId());
|
SysDept oldDept = getById(dept.getDeptId());
|
||||||
@ -205,6 +228,8 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
|
|||||||
dept.setAncestors(newAncestors);
|
dept.setAncestors(newAncestors);
|
||||||
updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors);
|
updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors);
|
||||||
}
|
}
|
||||||
|
String dataName = DynamicDataSourceContextHolder.peek();
|
||||||
|
log.info("mp内置方法--修改保存部门信息---当前数据源名称:"+dataName);
|
||||||
int result = baseMapper.updateById(dept);
|
int result = baseMapper.updateById(dept);
|
||||||
if (UserConstants.DEPT_NORMAL.equals(dept.getStatus())) {
|
if (UserConstants.DEPT_NORMAL.equals(dept.getStatus())) {
|
||||||
// 如果该部门是启用状态,则启用该部门的所有上级部门
|
// 如果该部门是启用状态,则启用该部门的所有上级部门
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
package com.ruoyi.system.service.impl;
|
package com.ruoyi.system.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.lang.Validator;
|
import cn.hutool.core.lang.Validator;
|
||||||
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||||
|
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
@ -34,6 +36,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
|
@DS("slave")
|
||||||
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {
|
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -53,7 +56,10 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@DataScope(deptAlias = "d", userAlias = "u", isUser = true)
|
@DataScope(deptAlias = "d", userAlias = "u", isUser = true)
|
||||||
|
@DS("master")
|
||||||
public TableDataInfo<SysUser> selectPageUserList(SysUser user) {
|
public TableDataInfo<SysUser> selectPageUserList(SysUser user) {
|
||||||
|
String dataName = DynamicDataSourceContextHolder.peek();
|
||||||
|
log.info("自定义方法--获取用户列表---当前数据源名称:"+dataName);
|
||||||
return PageUtils.buildDataInfo(baseMapper.selectPageUserList(PageUtils.buildPage(), user));
|
return PageUtils.buildDataInfo(baseMapper.selectPageUserList(PageUtils.buildPage(), user));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user