|
@ -49,7 +49,7 @@ public class MybatisPlusConfig { |
|
|
if (request != null) { |
|
|
if (request != null) { |
|
|
// 从请求头拿ID
|
|
|
// 从请求头拿ID
|
|
|
tenantId = request.getHeader("tenantId"); |
|
|
tenantId = request.getHeader("tenantId"); |
|
|
if(tenantId != null){ |
|
|
|
|
|
|
|
|
if(tenantId != null && !tenantId.trim().isEmpty()){ |
|
|
return new LongValue(tenantId); |
|
|
return new LongValue(tenantId); |
|
|
} |
|
|
} |
|
|
// 从域名拿ID
|
|
|
// 从域名拿ID
|
|
@ -57,7 +57,7 @@ public class MybatisPlusConfig { |
|
|
if (StrUtil.isNotBlank(Domain)) { |
|
|
if (StrUtil.isNotBlank(Domain)) { |
|
|
String key = "Domain:" + Domain; |
|
|
String key = "Domain:" + Domain; |
|
|
tenantId = redisUtil.get(key); |
|
|
tenantId = redisUtil.get(key); |
|
|
if(tenantId != null){ |
|
|
|
|
|
|
|
|
if(tenantId != null && !tenantId.trim().isEmpty()){ |
|
|
System.out.println("从域名拿TID = " + tenantId); |
|
|
System.out.println("从域名拿TID = " + tenantId); |
|
|
return new LongValue(tenantId); |
|
|
return new LongValue(tenantId); |
|
|
} |
|
|
} |
|
@ -65,8 +65,17 @@ public class MybatisPlusConfig { |
|
|
} |
|
|
} |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
// 忽略异常,使用默认逻辑
|
|
|
// 忽略异常,使用默认逻辑
|
|
|
|
|
|
System.err.println("获取租户ID异常: " + e.getMessage()); |
|
|
} |
|
|
} |
|
|
return getLoginUserTenantId(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 最后尝试从登录用户获取
|
|
|
|
|
|
Expression loginUserTenantId = getLoginUserTenantId(); |
|
|
|
|
|
if (loginUserTenantId instanceof LongValue) { |
|
|
|
|
|
return loginUserTenantId; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 如果都获取不到,返回null而不是undefined
|
|
|
|
|
|
return new NullValue(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
@ -119,11 +128,14 @@ public class MybatisPlusConfig { |
|
|
if (authentication != null) { |
|
|
if (authentication != null) { |
|
|
Object object = authentication.getPrincipal(); |
|
|
Object object = authentication.getPrincipal(); |
|
|
if (object instanceof User) { |
|
|
if (object instanceof User) { |
|
|
return new LongValue(((User) object).getTenantId()); |
|
|
|
|
|
|
|
|
Integer tenantId = ((User) object).getTenantId(); |
|
|
|
|
|
if (tenantId != null) { |
|
|
|
|
|
return new LongValue(tenantId); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
System.out.println(e.getMessage()); |
|
|
|
|
|
|
|
|
System.err.println("获取登录用户租户ID异常: " + e.getMessage()); |
|
|
} |
|
|
} |
|
|
return new NullValue(); |
|
|
return new NullValue(); |
|
|
} |
|
|
} |
|
|