mirror of https://gitee.com/stylefeng/roses
【8.0】【tenant】移除旧租户相关业务
parent
3811e45d1d
commit
1dd597025a
|
@ -82,11 +82,6 @@ public interface RuleConstants {
|
|||
*/
|
||||
String CHINESE_TRAN_LANGUAGE_CODE = "chinese";
|
||||
|
||||
/**
|
||||
* 租户数据源标识前缀
|
||||
*/
|
||||
String TENANT_DB_PREFIX = "sys_tenant_db_";
|
||||
|
||||
/**
|
||||
* base64图片前缀,用在给<img src=""/>使用
|
||||
*/
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
package cn.stylefeng.roses.kernel.rule.constants;
|
||||
|
||||
/**
|
||||
* 租户数据常量,如果租户业务变了这里也需要修改
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2021/9/24 17:20
|
||||
*/
|
||||
public interface TenantConstants {
|
||||
|
||||
/**
|
||||
* 租户库的前缀
|
||||
*/
|
||||
String TENANT_DB_PREFIX = "sys_tenant_db_";
|
||||
|
||||
/**
|
||||
* master数据源名称
|
||||
*/
|
||||
String MASTER_DATASOURCE_NAME = "master";
|
||||
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
package cn.stylefeng.roses.kernel.rule.tenant;
|
||||
|
||||
/**
|
||||
* 租户编码信息暂存,一般给缓存使用
|
||||
* <p>
|
||||
* 一次性使用,使用完就立即释放
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2022/11/8 0:58
|
||||
*/
|
||||
public class OnceTenantCodeHolder {
|
||||
|
||||
private static final ThreadLocal<String> CONTEXT_HOLDER = new ThreadLocal<>();
|
||||
|
||||
/**
|
||||
* 设置租户编码
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2022/11/8 0:59
|
||||
*/
|
||||
public static void setTenantCode(String aesKey) {
|
||||
CONTEXT_HOLDER.set(aesKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取租户编码
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2022/11/8 0:59
|
||||
*/
|
||||
public static String getTenantCode() {
|
||||
return CONTEXT_HOLDER.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除租户编码
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2022/11/8 0:59
|
||||
*/
|
||||
public static void clearTenantCode() {
|
||||
CONTEXT_HOLDER.remove();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
package cn.stylefeng.roses.kernel.rule.tenant;
|
||||
|
||||
/**
|
||||
* 租户编码信息暂存,一般给缓存使用
|
||||
* <p>
|
||||
* 在一次Http请求中生效,一般用在登录接口,当前Context没有LoginUser时使用
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2022/11/8 0:58
|
||||
*/
|
||||
public class RequestTenantCodeHolder {
|
||||
|
||||
private static final ThreadLocal<String> CONTEXT_HOLDER = new ThreadLocal<>();
|
||||
|
||||
/**
|
||||
* 设置租户编码
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2022/11/8 0:59
|
||||
*/
|
||||
public static void setTenantCode(String aesKey) {
|
||||
CONTEXT_HOLDER.set(aesKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取租户编码
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2022/11/8 0:59
|
||||
*/
|
||||
public static String getTenantCode() {
|
||||
return CONTEXT_HOLDER.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除租户编码
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2022/11/8 0:59
|
||||
*/
|
||||
public static void clearTenantCode() {
|
||||
CONTEXT_HOLDER.remove();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package cn.stylefeng.roses.kernel.rule.tenant;
|
||||
|
||||
/**
|
||||
* 租户前缀获取
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2022/11/7 20:16
|
||||
*/
|
||||
public interface TenantPrefixApi {
|
||||
|
||||
/**
|
||||
* 获取当前用户的租户前缀
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2022/11/7 20:29
|
||||
*/
|
||||
String getTenantPrefix();
|
||||
|
||||
}
|
|
@ -44,15 +44,12 @@ import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
|||
import cn.stylefeng.roses.kernel.auth.api.pojo.payload.DefaultJwtPayload;
|
||||
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
|
||||
import cn.stylefeng.roses.kernel.demo.expander.DemoConfigExpander;
|
||||
import cn.stylefeng.roses.kernel.dsctn.api.constants.DatasourceContainerConstants;
|
||||
import cn.stylefeng.roses.kernel.dsctn.api.context.CurrentDataSourceContext;
|
||||
import cn.stylefeng.roses.kernel.jwt.JwtTokenOperator;
|
||||
import cn.stylefeng.roses.kernel.jwt.api.JwtApi;
|
||||
import cn.stylefeng.roses.kernel.jwt.api.exception.JwtException;
|
||||
import cn.stylefeng.roses.kernel.jwt.api.exception.enums.JwtExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.jwt.api.pojo.config.JwtConfig;
|
||||
import cn.stylefeng.roses.kernel.log.api.LoginLogServiceApi;
|
||||
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
|
||||
import cn.stylefeng.roses.kernel.sys.api.SysUserServiceApi;
|
||||
import cn.stylefeng.roses.kernel.sys.api.pojo.user.UserValidateDTO;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
@ -243,28 +240,16 @@ public class AuthServiceImpl implements AuthServiceApi {
|
|||
// 获取用户的信息
|
||||
String account = defaultJwtPayload.getAccount();
|
||||
|
||||
// 获取用户租户信息
|
||||
String tenantCode = defaultJwtPayload.getTenantCode();
|
||||
|
||||
LoginUser loginUser;
|
||||
try {
|
||||
// 如果有特定租户则进行切换操作
|
||||
if (StrUtil.isNotEmpty(tenantCode) && !DatasourceContainerConstants.MASTER_DATASOURCE_NAME.equals(tenantCode)) {
|
||||
CurrentDataSourceContext.setDataSourceName(RuleConstants.TENANT_DB_PREFIX + tenantCode);
|
||||
}
|
||||
|
||||
// 获取用户信息
|
||||
UserValidateDTO userValidateDTO = sysUserServiceApi.getUserLoginValidateDTO(account);
|
||||
// 获取用户信息
|
||||
UserValidateDTO userValidateDTO = sysUserServiceApi.getUserLoginValidateDTO(account);
|
||||
|
||||
// 创建登录用户
|
||||
loginUser = new LoginUser(userValidateDTO.getUserId(), token);
|
||||
// 创建登录用户
|
||||
loginUser = new LoginUser(userValidateDTO.getUserId(), token);
|
||||
|
||||
// 创建用户会话信息
|
||||
sessionManagerApi.updateSession(token, loginUser);
|
||||
} finally {
|
||||
// 清除租户信息
|
||||
CurrentDataSourceContext.clearDataSourceName();
|
||||
}
|
||||
// 创建用户会话信息
|
||||
sessionManagerApi.updateSession(token, loginUser);
|
||||
|
||||
return loginUser;
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ import cn.stylefeng.roses.kernel.auth.api.pojo.sso.SsoProperties;
|
|||
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
|
||||
import cn.stylefeng.roses.kernel.demo.expander.DemoConfigExpander;
|
||||
import cn.stylefeng.roses.kernel.log.api.LoginLogServiceApi;
|
||||
import cn.stylefeng.roses.kernel.rule.tenant.RequestTenantCodeHolder;
|
||||
import cn.stylefeng.roses.kernel.rule.util.HttpServletUtil;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.exception.ScannerException;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.exception.enums.ScannerExceptionEnum;
|
||||
|
@ -103,9 +102,6 @@ public class LoginService {
|
|||
// 1.2 判断账号是否密码重试次数过多被冻结
|
||||
Integer loginErrorCount = validatePasswordRetryTimes(loginRequest);
|
||||
|
||||
// 1.3 暂存多租户编码(v7.3.2增加,方便缓存调用过程中获取多租户的前缀)
|
||||
RequestTenantCodeHolder.setTenantCode(loginRequest.getTenantCode());
|
||||
|
||||
// 2. 如果开启了验证码校验,则验证当前请求的验证码是否正确
|
||||
validateCaptcha(loginRequest);
|
||||
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
package cn.stylefeng.roses.kernel.auth.callback;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.tenant.RequestTenantCodeHolder;
|
||||
import cn.stylefeng.roses.kernel.rule.threadlocal.RemoveThreadLocalApi;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 清除参数缓存相关的ThreadLocal
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2021/10/29 11:37
|
||||
*/
|
||||
@Component
|
||||
public class TenantCodeRemoveThreadLocalHolder implements RemoveThreadLocalApi {
|
||||
|
||||
@Override
|
||||
public void removeThreadLocalAction() {
|
||||
RequestTenantCodeHolder.clearTenantCode();
|
||||
}
|
||||
|
||||
}
|
|
@ -26,9 +26,6 @@ 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;
|
||||
|
@ -151,20 +148,6 @@ public interface CacheOperatorApi<T> {
|
|||
*/
|
||||
String getCommonKeyPrefix();
|
||||
|
||||
/**
|
||||
* 是否按租户维度去切割缓存(不推荐开启)
|
||||
* <p>
|
||||
* key的组成方式:租户前缀:业务前缀:业务key
|
||||
* <p>
|
||||
* 如果不开启租户切割,则租户前缀一直会为master:
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2022/11/9 19:02
|
||||
*/
|
||||
default Boolean divideByTenant() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最终的计算前缀
|
||||
* <p>
|
||||
|
@ -174,11 +157,7 @@ public interface CacheOperatorApi<T> {
|
|||
* @since 2022/11/9 10:41
|
||||
*/
|
||||
default String getFinalPrefix() {
|
||||
// 获取租户前缀
|
||||
String tenantPrefix = getTenantPrefix();
|
||||
|
||||
// 计算最终前缀
|
||||
return tenantPrefix + CACHE_DELIMITER + getCommonKeyPrefix() + CACHE_DELIMITER;
|
||||
return getCommonKeyPrefix() + CACHE_DELIMITER;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -216,39 +195,4 @@ public interface CacheOperatorApi<T> {
|
|||
return StrUtil.removePrefix(finalKey, getFinalPrefix());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取租户前缀
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2022/11/9 10:35
|
||||
*/
|
||||
default String getTenantPrefix() {
|
||||
|
||||
// 缓存是否按租户维度切分
|
||||
Boolean divideByTenantFlag = divideByTenant();
|
||||
|
||||
// 如果不按租户维度切分,则默认都返回为master
|
||||
if (!divideByTenantFlag) {
|
||||
return TenantConstants.MASTER_DATASOURCE_NAME;
|
||||
}
|
||||
|
||||
// 用户的租户前缀
|
||||
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;
|
||||
}
|
||||
|
||||
return tenantPrefix;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
package cn.stylefeng.roses.kernel.cache.api.tenant;
|
||||
|
||||
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
|
||||
import cn.stylefeng.roses.kernel.rule.tenant.OnceTenantCodeHolder;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
|
||||
/**
|
||||
* 租户缓存动态代理
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2022/11/8 0:45
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class TenantCacheProxy implements InvocationHandler {
|
||||
|
||||
/**
|
||||
* 被代理的缓存操作类
|
||||
*/
|
||||
private CacheOperatorApi<?> targetCacheObject = null;
|
||||
|
||||
/**
|
||||
* 租户编码
|
||||
*/
|
||||
private String tenantCode = null;
|
||||
|
||||
/**
|
||||
* 绑定缓存操作原始类
|
||||
*
|
||||
* @param tenantCode 租户编码
|
||||
* @param target 被代理的缓存类
|
||||
* @author fengshuonan
|
||||
* @since 2022/11/8 1:05
|
||||
*/
|
||||
public <T> CacheOperatorApi<T> bindCacheObject(String tenantCode, CacheOperatorApi<T> target) {
|
||||
this.targetCacheObject = target;
|
||||
this.tenantCode = tenantCode;
|
||||
return (CacheOperatorApi<T>) Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getSuperclass().getInterfaces(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
Object result = null;
|
||||
try {
|
||||
// 设置租户编码
|
||||
OnceTenantCodeHolder.setTenantCode(tenantCode);
|
||||
|
||||
// 执行原有缓存操作类
|
||||
result = method.invoke(targetCacheObject, args);
|
||||
} finally {
|
||||
// 清除租户编码
|
||||
OnceTenantCodeHolder.clearTenantCode();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
package cn.stylefeng.roses.kernel.cache.api.tenant;
|
||||
|
||||
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 租户缓存动态代理
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2022/11/8 0:45
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
public class TenantCacheProxyFactory {
|
||||
|
||||
/**
|
||||
* 存放所有代理的缓存
|
||||
*/
|
||||
private static final Map<String, CacheOperatorApi<?>> proxyCacheMap = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 创建带租户控制的缓存代理
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2022/11/8 1:18
|
||||
*/
|
||||
public static <T> CacheOperatorApi<T> createTenantCacheProxy(String tenantCode, CacheOperatorApi<?> cacheOperatorApi) {
|
||||
|
||||
// 计算缓存的key
|
||||
String key = tenantCode + cacheOperatorApi.getCommonKeyPrefix();
|
||||
|
||||
// 直接获取缓存中的代理
|
||||
if (proxyCacheMap.containsKey(key)) {
|
||||
return (CacheOperatorApi<T>) proxyCacheMap.get(key);
|
||||
}
|
||||
|
||||
TenantCacheProxy tenantCacheProxy = new TenantCacheProxy();
|
||||
CacheOperatorApi<?> resultCacheOperator = tenantCacheProxy.bindCacheObject(tenantCode, cacheOperatorApi);
|
||||
proxyCacheMap.put(key, resultCacheOperator);
|
||||
return (CacheOperatorApi<T>) resultCacheOperator;
|
||||
}
|
||||
|
||||
}
|
|
@ -11,7 +11,6 @@ import cn.stylefeng.roses.kernel.db.api.sqladapter.database.CreateDatabaseSql;
|
|||
import cn.stylefeng.roses.kernel.db.api.sqladapter.database.GetDatabasesSql;
|
||||
import cn.stylefeng.roses.kernel.db.api.sqladapter.table.TableFieldListSql;
|
||||
import cn.stylefeng.roses.kernel.db.api.sqladapter.table.TableListSql;
|
||||
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
@ -48,10 +47,7 @@ public class DatabaseUtil {
|
|||
while (resultSet.next()) {
|
||||
String database = resultSet.getString("database");
|
||||
if (StrUtil.isNotBlank(database)) {
|
||||
if (StrUtil.startWith(database, RuleConstants.TENANT_DB_PREFIX)) {
|
||||
database = database.replaceAll(RuleConstants.TENANT_DB_PREFIX, "");
|
||||
databasesList.add(database);
|
||||
}
|
||||
databasesList.add(database);
|
||||
}
|
||||
}
|
||||
return databasesList;
|
||||
|
|
|
@ -88,11 +88,6 @@ public enum DatasourceContainerExceptionEnum implements AbstractExceptionEnum {
|
|||
*/
|
||||
EDIT_DATASOURCE_NAME_ERROR(RuleConstants.BUSINESS_ERROR_TYPE_CODE + DatasourceContainerConstants.DS_CTN_EXCEPTION_STEP_CODE + "10", "修改数据源失败,不能修改数据源名称,原名称为={}"),
|
||||
|
||||
/**
|
||||
* 租户数据源不能删除
|
||||
*/
|
||||
TENANT_DATASOURCE_CANT_DELETE(RuleConstants.BUSINESS_ERROR_TYPE_CODE + DatasourceContainerConstants.DS_CTN_EXCEPTION_STEP_CODE + "11", "租户数据源不能删除"),
|
||||
|
||||
/**
|
||||
* 数据源信息不存在
|
||||
*/
|
||||
|
|
|
@ -47,7 +47,6 @@ import cn.stylefeng.roses.kernel.group.api.GroupApi;
|
|||
import cn.stylefeng.roses.kernel.group.api.constants.GroupConstants;
|
||||
import cn.stylefeng.roses.kernel.group.api.pojo.SysGroupDTO;
|
||||
import cn.stylefeng.roses.kernel.group.api.pojo.SysGroupRequest;
|
||||
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
|
||||
import cn.stylefeng.roses.kernel.rule.enums.DbTypeEnum;
|
||||
import cn.stylefeng.roses.kernel.rule.enums.StatusEnum;
|
||||
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
||||
|
@ -167,11 +166,6 @@ public class DatabaseInfoServiceImpl extends ServiceImpl<DatabaseInfoMapper, Dat
|
|||
|
||||
DatabaseInfo databaseInfo = this.queryDatabaseInfoById(databaseInfoRequest);
|
||||
|
||||
// 如果是租户数据库不能删除
|
||||
if (databaseInfo.getDbName().startsWith(RuleConstants.TENANT_DB_PREFIX)) {
|
||||
throw new DatasourceContainerException(DatasourceContainerExceptionEnum.TENANT_DATASOURCE_CANT_DELETE);
|
||||
}
|
||||
|
||||
// 不能删除主数据源
|
||||
if (MASTER_DATASOURCE_NAME.equals(databaseInfo.getDbName())) {
|
||||
throw new DatasourceContainerException(DatasourceContainerExceptionEnum.MASTER_DATASOURCE_CANT_DELETE);
|
||||
|
|
|
@ -26,11 +26,8 @@ package cn.stylefeng.roses.kernel.validator.api.validators.unique.service;
|
|||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
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;
|
||||
|
@ -69,7 +66,7 @@ public class TableUniqueValueService {
|
|||
if (!uniqueValidateParam.getExcludeCurrentRecord()
|
||||
&& !uniqueValidateParam.getExcludeLogicDeleteItems()) {
|
||||
String sqlTemplate = "select count(*) from {} where {} = {0}";
|
||||
String finalSql = StrUtil.format(sqlTemplate, calcTenantTableName(uniqueValidateParam.getTableName()), uniqueValidateParam.getColumnName());
|
||||
String finalSql = StrUtil.format(sqlTemplate, uniqueValidateParam.getTableName(), uniqueValidateParam.getColumnName());
|
||||
resultCount = dbOperatorApi.selectCount(finalSql, uniqueValidateParam.getValue());
|
||||
}
|
||||
|
||||
|
@ -78,7 +75,7 @@ public class TableUniqueValueService {
|
|||
&& uniqueValidateParam.getExcludeLogicDeleteItems()) {
|
||||
String sqlTemplate = "select count(*) from {} where {} = {0} and ({} is null or {} <> '{}')";
|
||||
String finalSql = StrUtil.format(sqlTemplate,
|
||||
calcTenantTableName(uniqueValidateParam.getTableName()),
|
||||
uniqueValidateParam.getTableName(),
|
||||
uniqueValidateParam.getColumnName(),
|
||||
uniqueValidateParam.getLogicDeleteFieldName(),
|
||||
uniqueValidateParam.getLogicDeleteFieldName(),
|
||||
|
@ -94,7 +91,7 @@ public class TableUniqueValueService {
|
|||
paramIdValidate(uniqueValidateParam);
|
||||
|
||||
String sqlTemplate = "select count(*) from {} where {} = {0} and {} <> {1}";
|
||||
String finalSql = StrUtil.format(sqlTemplate, calcTenantTableName(uniqueValidateParam.getTableName()), uniqueValidateParam.getColumnName(), uniqueValidateParam.getIdFieldName());
|
||||
String finalSql = StrUtil.format(sqlTemplate, uniqueValidateParam.getTableName(), uniqueValidateParam.getColumnName(), uniqueValidateParam.getIdFieldName());
|
||||
resultCount = dbOperatorApi.selectCount(finalSql, uniqueValidateParam.getValue(), uniqueValidateParam.getId());
|
||||
}
|
||||
|
||||
|
@ -107,7 +104,7 @@ public class TableUniqueValueService {
|
|||
|
||||
String sqlTemplate = "select count(*) from {} where {} = {0} and {} <> {1} and ({} is null or {} <> '{}')";
|
||||
String finalSql = StrUtil.format(sqlTemplate,
|
||||
calcTenantTableName(uniqueValidateParam.getTableName()),
|
||||
uniqueValidateParam.getTableName(),
|
||||
uniqueValidateParam.getColumnName(),
|
||||
uniqueValidateParam.getIdFieldName(),
|
||||
uniqueValidateParam.getLogicDeleteFieldName(),
|
||||
|
@ -151,28 +148,4 @@ public class TableUniqueValueService {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算携带租户code情况下的表名称
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2021/9/24 17:01
|
||||
*/
|
||||
private static String calcTenantTableName(String originTableName) {
|
||||
|
||||
// 获取租户编码
|
||||
LoginUser loginUser = LoginContext.me().getLoginUserNullable();
|
||||
if (loginUser == null) {
|
||||
return originTableName;
|
||||
}
|
||||
|
||||
String tenantCode = loginUser.getTenantCode();
|
||||
|
||||
// 如果是主数据源可以忽略
|
||||
if (StrUtil.isBlank(tenantCode) || TenantConstants.MASTER_DATASOURCE_NAME.equals(tenantCode)) {
|
||||
return originTableName;
|
||||
}
|
||||
|
||||
return TenantConstants.TENANT_DB_PREFIX + tenantCode + "." + originTableName;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -54,13 +54,6 @@ public class HrOrgApprover extends BaseEntity {
|
|||
@ChineseDescription("用户id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 租户id
|
||||
*/
|
||||
@TableField("tenant_id")
|
||||
@ChineseDescription("租户id")
|
||||
private Long tenantId;
|
||||
|
||||
//-------------------------------非实体字段-------------------------------
|
||||
//-------------------------------非实体字段-------------------------------
|
||||
//-------------------------------非实体字段-------------------------------
|
||||
|
|
|
@ -48,11 +48,4 @@ public class PortalUserApp extends BaseEntity {
|
|||
@ChineseDescription("关联的菜单id")
|
||||
private Long menuId;
|
||||
|
||||
/**
|
||||
* 租户id
|
||||
*/
|
||||
@TableField("tenant_id")
|
||||
@ChineseDescription("租户id")
|
||||
private Long tenantId;
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue