mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-18 09:35:29 +08:00
多租户配置排除表: 增加以注解方式排除
This commit is contained in:
parent
5ccb511064
commit
0234e63923
@ -0,0 +1,16 @@
|
||||
package org.dromara.common.tenant.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 忽略租户限制注解
|
||||
* 用于标记实体类不需要进行租户数据隔离
|
||||
* 限制: 仅允许标注在实体类上(被 mybatis-plus @TableName 标记的类)
|
||||
* @author 金鹏
|
||||
*/
|
||||
@Target({ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
@Inherited
|
||||
public @interface IgnoreTenant {
|
||||
}
|
||||
@ -83,4 +83,5 @@ public class TenantConfig {
|
||||
return new TenantSaTokenDao();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package org.dromara.common.tenant.handle;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -8,6 +10,7 @@ import net.sf.jsqlparser.expression.Expression;
|
||||
import net.sf.jsqlparser.expression.NullValue;
|
||||
import net.sf.jsqlparser.expression.StringValue;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.tenant.annotation.IgnoreTenant;
|
||||
import org.dromara.common.tenant.helper.TenantHelper;
|
||||
import org.dromara.common.tenant.properties.TenantProperties;
|
||||
|
||||
@ -48,9 +51,32 @@ public class PlusTenantLineHandler implements TenantLineHandler {
|
||||
"gen_table_column"
|
||||
);
|
||||
tables.addAll(excludes);
|
||||
return StringUtils.equalsAnyIgnoreCase(tableName, tables.toArray(new String[0]));
|
||||
// 检查表是否通过注解标记为忽略租户
|
||||
boolean ignoreByAnnotation = isIgnoreTenantByAnnotation(tableName);
|
||||
return StringUtils.equalsAnyIgnoreCase(tableName, tables.toArray(new String[0]))|| ignoreByAnnotation;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过实体类注解判断是否忽略租户限制
|
||||
* @param tableName 表名
|
||||
* @return 是否忽略租户限制
|
||||
*/
|
||||
private boolean isIgnoreTenantByAnnotation(String tableName) {
|
||||
try {
|
||||
// 获取所有已注册的实体类
|
||||
List<TableInfo> tableInfos = TableInfoHelper.getTableInfos();
|
||||
for (TableInfo tableInfo : tableInfos) {
|
||||
// 比较表名是否匹配
|
||||
if (tableName.equalsIgnoreCase(tableInfo.getTableName())) {
|
||||
Class<?> entityType = tableInfo.getEntityType();
|
||||
// 检查实体类是否有 @IgnoreTenant 注解
|
||||
return entityType.isAnnotationPresent(IgnoreTenant.class);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("检查表{}是否忽略租户时发生异常", tableName, e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user