|
|
@@ -1,5 +1,6 @@
|
|
|
package com.fs.framework.datasource;
|
|
|
|
|
|
+import com.fs.common.config.RedisTenantContext;
|
|
|
import com.fs.tenant.domain.TenantInfo;
|
|
|
import com.fs.tenant.service.TenantInfoService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -48,7 +49,9 @@ public class TenantDataSourceUtil {
|
|
|
try {
|
|
|
// 切换到租户数据源
|
|
|
tenantDataSourceManager.switchTenant(tenantInfo);
|
|
|
- log.debug("[TenantDS] 已切换到租户数据源: tenantId={}, tenantCode={}",
|
|
|
+ // 切换Redis租户上下文
|
|
|
+ RedisTenantContext.setTenantId(tenantInfo.getId());
|
|
|
+ log.debug("[TenantDS] 已切换到租户数据源和Redis: tenantId={}, tenantCode={}",
|
|
|
tenantInfo.getId(), tenantInfo.getTenantCode());
|
|
|
|
|
|
// 执行操作
|
|
|
@@ -57,7 +60,9 @@ public class TenantDataSourceUtil {
|
|
|
} finally {
|
|
|
// 清理数据源上下文
|
|
|
tenantDataSourceManager.clear();
|
|
|
- log.debug("[TenantDS] 已清理租户数据源上下文");
|
|
|
+ // 清理Redis租户上下文
|
|
|
+ RedisTenantContext.clear();
|
|
|
+ log.debug("[TenantDS] 已清理租户数据源和Redis上下文");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -89,7 +94,9 @@ public class TenantDataSourceUtil {
|
|
|
try {
|
|
|
// 切换到租户数据源
|
|
|
tenantDataSourceManager.switchTenant(tenantInfo);
|
|
|
- log.debug("[TenantDS] 已切换到租户数据源: tenantId={}, tenantCode={}",
|
|
|
+ // 切换Redis租户上下文
|
|
|
+ RedisTenantContext.setTenantId(tenantInfo.getId());
|
|
|
+ log.debug("[TenantDS] 已切换到租户数据源和Redis: tenantId={}, tenantCode={}",
|
|
|
tenantInfo.getId(), tenantInfo.getTenantCode());
|
|
|
|
|
|
// 执行操作并返回结果
|
|
|
@@ -98,7 +105,9 @@ public class TenantDataSourceUtil {
|
|
|
} finally {
|
|
|
// 清理数据源上下文
|
|
|
tenantDataSourceManager.clear();
|
|
|
- log.debug("[TenantDS] 已清理租户数据源上下文");
|
|
|
+ // 清理Redis租户上下文
|
|
|
+ RedisTenantContext.clear();
|
|
|
+ log.debug("[TenantDS] 已清理租户数据源和Redis上下文");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -126,7 +135,9 @@ public class TenantDataSourceUtil {
|
|
|
try {
|
|
|
// 切换到租户数据源
|
|
|
tenantDataSourceManager.switchTenant(tenantInfo);
|
|
|
- log.debug("[TenantDS] 已切换到租户数据源: tenantId={}, tenantCode={}",
|
|
|
+ // 切换Redis租户上下文
|
|
|
+ RedisTenantContext.setTenantId(tenantInfo.getId());
|
|
|
+ log.debug("[TenantDS] 已切换到租户数据源和Redis: tenantId={}, tenantCode={}",
|
|
|
tenantInfo.getId(), tenantInfo.getTenantCode());
|
|
|
|
|
|
// 执行操作
|
|
|
@@ -135,7 +146,9 @@ public class TenantDataSourceUtil {
|
|
|
} finally {
|
|
|
// 清理数据源上下文
|
|
|
tenantDataSourceManager.clear();
|
|
|
- log.debug("[TenantDS] 已清理租户数据源上下文");
|
|
|
+ // 清理Redis租户上下文
|
|
|
+ RedisTenantContext.clear();
|
|
|
+ log.debug("[TenantDS] 已清理租户数据源和Redis上下文");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -167,7 +180,9 @@ public class TenantDataSourceUtil {
|
|
|
try {
|
|
|
// 切换到租户数据源
|
|
|
tenantDataSourceManager.switchTenant(tenantInfo);
|
|
|
- log.debug("[TenantDS] 已切换到租户数据源: tenantId={}, tenantCode={}",
|
|
|
+ // 切换Redis租户上下文
|
|
|
+ RedisTenantContext.setTenantId(tenantInfo.getId());
|
|
|
+ log.debug("[TenantDS] 已切换到租户数据源和Redis: tenantId={}, tenantCode={}",
|
|
|
tenantInfo.getId(), tenantInfo.getTenantCode());
|
|
|
|
|
|
// 执行操作并返回结果
|
|
|
@@ -176,7 +191,9 @@ public class TenantDataSourceUtil {
|
|
|
} finally {
|
|
|
// 清理数据源上下文
|
|
|
tenantDataSourceManager.clear();
|
|
|
- log.debug("[TenantDS] 已清理租户数据源上下文");
|
|
|
+ // 清理Redis租户上下文
|
|
|
+ RedisTenantContext.clear();
|
|
|
+ log.debug("[TenantDS] 已清理租户数据源和Redis上下文");
|
|
|
}
|
|
|
}
|
|
|
|