|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package org.dromara.common.tenant.handle;
|
|
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.dromara.common.core.constant.GlobalConstants;
|
|
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
|
|
import org.dromara.common.redis.handler.KeyPrefixHandler;
|
|
|
|
@ -10,6 +11,7 @@ import org.dromara.common.tenant.helper.TenantHelper;
|
|
|
|
|
*
|
|
|
|
|
* @author Lion Li
|
|
|
|
|
*/
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class TenantKeyPrefixHandler extends KeyPrefixHandler {
|
|
|
|
|
|
|
|
|
|
public TenantKeyPrefixHandler(String keyPrefix) {
|
|
|
|
@ -28,6 +30,9 @@ public class TenantKeyPrefixHandler extends KeyPrefixHandler {
|
|
|
|
|
return super.map(name);
|
|
|
|
|
}
|
|
|
|
|
String tenantId = TenantHelper.getTenantId();
|
|
|
|
|
if (StringUtils.isBlank(tenantId)) {
|
|
|
|
|
log.error("无法获取有效的租户id -> Null");
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.startsWith(name, tenantId)) {
|
|
|
|
|
// 如果存在则直接返回
|
|
|
|
|
return super.map(name);
|
|
|
|
@ -48,6 +53,9 @@ public class TenantKeyPrefixHandler extends KeyPrefixHandler {
|
|
|
|
|
return super.unmap(name);
|
|
|
|
|
}
|
|
|
|
|
String tenantId = TenantHelper.getTenantId();
|
|
|
|
|
if (StringUtils.isBlank(tenantId)) {
|
|
|
|
|
log.error("无法获取有效的租户id -> Null");
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.startsWith(unmap, tenantId)) {
|
|
|
|
|
// 如果存在则删除
|
|
|
|
|
return unmap.substring((tenantId + ":").length());
|
|
|
|
|