commit
61799385c9
@ -1,27 +0,0 @@
|
|||||||
package com.ruoyi.common.annotation;
|
|
||||||
|
|
||||||
import java.lang.annotation.Documented;
|
|
||||||
import java.lang.annotation.ElementType;
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.annotation.Target;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据权限过滤注解
|
|
||||||
*
|
|
||||||
* @author ruoyi
|
|
||||||
*/
|
|
||||||
@Target(ElementType.METHOD)
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
@Documented
|
|
||||||
public @interface DataScope {
|
|
||||||
/**
|
|
||||||
* 部门表的别名
|
|
||||||
*/
|
|
||||||
public String deptAlias() default "";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户表的别名
|
|
||||||
*/
|
|
||||||
public String userAlias() default "";
|
|
||||||
}
|
|
||||||
@ -1,64 +0,0 @@
|
|||||||
package com.ruoyi.framework.aspectj;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
|
||||||
import org.aspectj.lang.annotation.Around;
|
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
|
||||||
import org.aspectj.lang.annotation.Pointcut;
|
|
||||||
import org.aspectj.lang.reflect.MethodSignature;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.core.annotation.AnnotationUtils;
|
|
||||||
import org.springframework.core.annotation.Order;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import com.ruoyi.common.annotation.DataSource;
|
|
||||||
import com.ruoyi.common.utils.StringUtils;
|
|
||||||
import com.ruoyi.framework.datasource.DynamicDataSourceContextHolder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 多数据源处理
|
|
||||||
*
|
|
||||||
* @author ruoyi
|
|
||||||
*/
|
|
||||||
@Aspect
|
|
||||||
@Order(1)
|
|
||||||
@Component
|
|
||||||
public class DataSourceAspect {
|
|
||||||
protected Logger logger = LoggerFactory.getLogger(getClass());
|
|
||||||
|
|
||||||
@Pointcut("@annotation(com.ruoyi.common.annotation.DataSource)"
|
|
||||||
+ "|| @within(com.ruoyi.common.annotation.DataSource)")
|
|
||||||
public void dsPointCut() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Around("dsPointCut()")
|
|
||||||
public Object around(ProceedingJoinPoint point) throws Throwable {
|
|
||||||
DataSource dataSource = getDataSource(point);
|
|
||||||
|
|
||||||
if (StringUtils.isNotNull(dataSource)) {
|
|
||||||
DynamicDataSourceContextHolder.setDataSourceType(dataSource.value().name());
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
return point.proceed();
|
|
||||||
} finally {
|
|
||||||
// 销毁数据源 在执行方法之后
|
|
||||||
DynamicDataSourceContextHolder.clearDataSourceType();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取需要切换的数据源
|
|
||||||
*/
|
|
||||||
public DataSource getDataSource(ProceedingJoinPoint point) {
|
|
||||||
MethodSignature signature = (MethodSignature) point.getSignature();
|
|
||||||
DataSource dataSource = AnnotationUtils.findAnnotation(signature.getMethod(), DataSource.class);
|
|
||||||
if (Objects.nonNull(dataSource)) {
|
|
||||||
return dataSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
return AnnotationUtils.findAnnotation(signature.getDeclaringType(), DataSource.class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
package com.ruoyi.common.enums;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 数据源
|
|
||||||
*
|
|
||||||
* @author ruoyi
|
|
||||||
*/
|
|
||||||
public enum DataSourceType
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* 主库
|
|
||||||
*/
|
|
||||||
MASTER,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 从库
|
|
||||||
*/
|
|
||||||
SLAVE
|
|
||||||
}
|
|
||||||
@ -1,24 +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,116 +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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,37 +0,0 @@
|
|||||||
# 数据源配置
|
|
||||||
spring:
|
|
||||||
datasource:
|
|
||||||
type: com.alibaba.druid.pool.DruidDataSource
|
|
||||||
driverClassName: com.mysql.cj.jdbc.Driver
|
|
||||||
druid:
|
|
||||||
# 主库数据源
|
|
||||||
master:
|
|
||||||
url: jdbc:mysql://localhost:3306/ry-vue?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
|
||||||
username: root
|
|
||||||
password: password
|
|
||||||
# 从库数据源
|
|
||||||
slave:
|
|
||||||
# 从数据源开关/默认关闭
|
|
||||||
enabled: false
|
|
||||||
url:
|
|
||||||
username:
|
|
||||||
password:
|
|
||||||
# 初始连接数
|
|
||||||
initialSize: 5
|
|
||||||
# 最小连接池数量
|
|
||||||
minIdle: 10
|
|
||||||
# 最大连接池数量
|
|
||||||
maxActive: 20
|
|
||||||
# 配置获取连接等待超时的时间
|
|
||||||
maxWait: 60000
|
|
||||||
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
|
|
||||||
timeBetweenEvictionRunsMillis: 60000
|
|
||||||
# 配置一个连接在池中最小生存的时间,单位是毫秒
|
|
||||||
minEvictableIdleTimeMillis: 300000
|
|
||||||
# 配置一个连接在池中最大生存的时间,单位是毫秒
|
|
||||||
maxEvictableIdleTimeMillis: 900000
|
|
||||||
# 配置检测连接是否有效
|
|
||||||
validationQuery: SELECT 1 FROM DUAL
|
|
||||||
testWhileIdle: true
|
|
||||||
testOnBorrow: false
|
|
||||||
testOnReturn: false
|
|
||||||
@ -0,0 +1,38 @@
|
|||||||
|
package cn.iocoder.dashboard.framework.datasource.core.filter;
|
||||||
|
|
||||||
|
import com.alibaba.druid.util.Utils;
|
||||||
|
import org.springframework.web.filter.OncePerRequestFilter;
|
||||||
|
|
||||||
|
import javax.servlet.FilterChain;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Druid 底部广告过滤器
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
public class DruidAdRemoveFilter extends OncePerRequestFilter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* common.js 的路径
|
||||||
|
*/
|
||||||
|
private static final String COMMON_JS_ILE_PATH = "support/http/resources/js/common.js";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
|
||||||
|
throws ServletException, IOException {
|
||||||
|
chain.doFilter(request, response);
|
||||||
|
// 重置缓冲区,响应头不会被重置
|
||||||
|
response.resetBuffer();
|
||||||
|
// 获取 common.js
|
||||||
|
String text = Utils.readFromResource(COMMON_JS_ILE_PATH);
|
||||||
|
// 正则替换 banner, 除去底部的广告信息
|
||||||
|
text = text.replaceAll("<a.*?banner\"></a><br/>", "");
|
||||||
|
text = text.replaceAll("powered.*?shrek.wang</a>", "");
|
||||||
|
response.getWriter().write(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,24 +1,12 @@
|
|||||||
package cn.iocoder.dashboard.modules.tool.dal.mysql.codegen;
|
package cn.iocoder.dashboard.modules.tool.dal.mysql.codegen;
|
||||||
|
|
||||||
import cn.iocoder.dashboard.BaseDbUnitTest;
|
import cn.iocoder.dashboard.BaseDbUnitTest;
|
||||||
import cn.iocoder.dashboard.modules.tool.dal.dataobject.codegen.ToolSchemaTableDO;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
|
|
||||||
class ToolInformationSchemaTableMapperTest extends BaseDbUnitTest {
|
class ToolInformationSchemaTableMapperTest extends BaseDbUnitTest {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ToolSchemaTableMapper toolInformationSchemaTableMapper;
|
private ToolSchemaTableMapper toolInformationSchemaTableMapper;
|
||||||
|
|
||||||
@Test
|
|
||||||
public void tstSelectListByTableSchema() {
|
|
||||||
List<ToolSchemaTableDO> tables = toolInformationSchemaTableMapper
|
|
||||||
.selectListByTableSchema("ruoyi-vue-pro");
|
|
||||||
assertTrue(tables.size() > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue