fix(多租户):多租户数据接口和数据表结构,noIgnoreSqls逻辑添加
This commit is contained in:
+8
-1
@@ -4,7 +4,6 @@ import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@@ -38,4 +37,12 @@ public class TenantProperties {
|
||||
"com.central.user.mapper.SysRoleMapper.findAll",
|
||||
"com.central.user.mapper.SysUserRoleMapper.findRolesByUserIds"
|
||||
);
|
||||
|
||||
/**
|
||||
* 忽略租户的SQL
|
||||
*/
|
||||
private List<String> noIgnoreSqls = Arrays.asList(
|
||||
"com.central.user.mapper.SysRoleMapper.findAll",
|
||||
"com.central.user.mapper.SysUserRoleMapper.findRolesByUserIds"
|
||||
);
|
||||
}
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ public class MybatisPlusAutoConfigure {
|
||||
//是否开启多租户隔离
|
||||
if (enableTenant) {
|
||||
CustomTenantInterceptor tenantInterceptor = new CustomTenantInterceptor(
|
||||
tenantLineHandler, tenantProperties.getIgnoreSqls());
|
||||
tenantLineHandler, tenantProperties.getIgnoreSqls(),tenantProperties.getNoIgnoreSqls());
|
||||
mpInterceptor.addInnerInterceptor(tenantInterceptor);
|
||||
}
|
||||
if(dataScopeProperties.getEnabled()){
|
||||
|
||||
+11
-2
@@ -23,10 +23,12 @@ import java.util.List;
|
||||
*/
|
||||
public class CustomTenantInterceptor extends TenantLineInnerInterceptor {
|
||||
private List<String> ignoreSqls;
|
||||
private List<String> noIgnoreSqls;
|
||||
|
||||
public CustomTenantInterceptor(TenantLineHandler tenantLineHandler, List<String> ignoreSqls) {
|
||||
public CustomTenantInterceptor(TenantLineHandler tenantLineHandler, List<String> ignoreSqls, List<String> noIgnoreSqls) {
|
||||
super(tenantLineHandler);
|
||||
this.ignoreSqls = ignoreSqls;
|
||||
this.noIgnoreSqls = noIgnoreSqls;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -35,10 +37,17 @@ public class CustomTenantInterceptor extends TenantLineInnerInterceptor {
|
||||
if (isIgnoreMappedStatement(ms.getId())) {
|
||||
return;
|
||||
}
|
||||
super.beforeQuery(executor, ms, parameter, rowBounds, resultHandler, boundSql);
|
||||
if (isNoIgnoreMappedStatement(ms.getId())) {
|
||||
super.beforeQuery(executor, ms, parameter, rowBounds, resultHandler, boundSql);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean isIgnoreMappedStatement(String msId) {
|
||||
return ignoreSqls.stream().anyMatch((e) -> e.equalsIgnoreCase(msId));
|
||||
}
|
||||
|
||||
private boolean isNoIgnoreMappedStatement(String msId) {
|
||||
return noIgnoreSqls.stream().anyMatch((e) -> e.equalsIgnoreCase(msId));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user