feat(多租户):多租户数据隔离功能实现
This commit is contained in:
+1
-1
@@ -39,7 +39,7 @@ public class TenantProperties {
|
||||
);
|
||||
|
||||
/**
|
||||
* 忽略租户的SQL
|
||||
* 不可忽略租户的SQL
|
||||
*/
|
||||
private List<String> noIgnoreSqls = Arrays.asList(
|
||||
"com.central.user.mapper.SysRoleMapper.findAll",
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package com.central.db.interceptor;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
|
||||
import com.central.common.context.LoginUserContextHolder;
|
||||
import com.central.common.context.TenantContextHolder;
|
||||
import com.central.common.model.LoginAppUser;
|
||||
import net.sf.jsqlparser.expression.Expression;
|
||||
import net.sf.jsqlparser.expression.NullValue;
|
||||
import net.sf.jsqlparser.expression.StringValue;
|
||||
|
||||
/**
|
||||
* 超级管理员可以管理租户数据权限开放
|
||||
* @date 2025-05-15
|
||||
* @author lsl
|
||||
*/
|
||||
public class CustomTenantLineHandler implements TenantLineHandler {
|
||||
@Override
|
||||
public Expression getTenantId() {
|
||||
// 判断当前用户是否为超级管理员
|
||||
if (isSuperAdmin()) {
|
||||
// 超级管理员返回Null,不加租户条件
|
||||
return new NullValue();
|
||||
}
|
||||
// 普通用户返回租户ID
|
||||
return new StringValue(TenantContextHolder.getTenant());
|
||||
}
|
||||
|
||||
private boolean isSuperAdmin() {
|
||||
// 你可以通过ThreadLocal、SecurityContext、LoginUserContextHolder等获取当前用户角色
|
||||
// 例如:
|
||||
LoginAppUser user = LoginUserContextHolder.getUser();
|
||||
return user != null && user.getUsername().equals("admin");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user