mirror of https://gitee.com/stylefeng/roses
【7.3.2】【cache】缓存前缀加上对租户的判断处理
parent
5f4050658a
commit
cd0e0b3416
|
@ -1,4 +1,4 @@
|
|||
package cn.stylefeng.roses.kernel.validator.api.validators.unique.constants;
|
||||
package cn.stylefeng.roses.kernel.rule.constants;
|
||||
|
||||
/**
|
||||
* 租户数据常量,如果租户业务变了这里也需要修改
|
|
@ -0,0 +1,19 @@
|
|||
package cn.stylefeng.roses.kernel.rule.tenant;
|
||||
|
||||
/**
|
||||
* 租户前缀获取
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/11/7 20:16
|
||||
*/
|
||||
public interface TenantPrefixApi {
|
||||
|
||||
/**
|
||||
* 获取当前用户的租户前缀
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/11/7 20:29
|
||||
*/
|
||||
String getTenantPrefix();
|
||||
|
||||
}
|
|
@ -24,7 +24,11 @@
|
|||
*/
|
||||
package cn.stylefeng.roses.kernel.cache.api;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.stylefeng.roses.kernel.rule.constants.TenantConstants;
|
||||
import cn.stylefeng.roses.kernel.rule.tenant.TenantPrefixApi;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
@ -147,10 +151,27 @@ public interface CacheOperatorApi<T> {
|
|||
* @date 2021/7/30 21:18
|
||||
*/
|
||||
default String calcKey(String keyParam) {
|
||||
|
||||
// 用户的租户前缀
|
||||
String tenantPrefix = "";
|
||||
try {
|
||||
TenantPrefixApi tenantPrefixApi = SpringUtil.getBean(TenantPrefixApi.class);
|
||||
if (tenantPrefixApi != null) {
|
||||
tenantPrefix = tenantPrefixApi.getTenantPrefix();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 如果找不到这个bean,则没有加载多租户插件
|
||||
}
|
||||
|
||||
// 如果租户前缀为空,则设置为主租户的编码
|
||||
if (ObjectUtil.isEmpty(tenantPrefix)) {
|
||||
tenantPrefix = TenantConstants.MASTER_DATASOURCE_NAME;
|
||||
}
|
||||
|
||||
if (StrUtil.isBlank(keyParam)) {
|
||||
return getCommonKeyPrefix();
|
||||
return tenantPrefix + ":" + getCommonKeyPrefix();
|
||||
} else {
|
||||
return getCommonKeyPrefix() + keyParam.toUpperCase();
|
||||
return tenantPrefix + ":" + getCommonKeyPrefix() + keyParam.toUpperCase();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,10 +30,10 @@ import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
|||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
||||
import cn.stylefeng.roses.kernel.db.api.DbOperatorApi;
|
||||
import cn.stylefeng.roses.kernel.db.api.context.DbOperatorContext;
|
||||
import cn.stylefeng.roses.kernel.rule.constants.TenantConstants;
|
||||
import cn.stylefeng.roses.kernel.validator.api.exception.ParamValidateException;
|
||||
import cn.stylefeng.roses.kernel.validator.api.exception.enums.ValidatorExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.validator.api.pojo.UniqueValidateParam;
|
||||
import cn.stylefeng.roses.kernel.validator.api.validators.unique.constants.TenantConstants;
|
||||
|
||||
/**
|
||||
* 判断表中字段是否是唯一值的业务封装
|
||||
|
|
Loading…
Reference in New Issue