refactor(tenant): 优化租户相关代码

This commit is contained in:
2025-07-15 20:09:54 +08:00
parent ed6dd65a51
commit af1079da6d
111 changed files with 2741 additions and 2319 deletions

View File

@@ -168,17 +168,15 @@
<artifactId>continew-starter-extension-crud-mp</artifactId>
</dependency>
<!-- 多租户组件-->
<!-- ContiNew Starter 扩展模块 - 租户 -->
<dependency>
<groupId>top.continew.starter</groupId>
<artifactId>continew-starter-extension-tenant-mp</artifactId>
</dependency>
<!-- Dynamic Datasource基于 Spring Boot 的快速集成多数据源的启动器) -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot3-starter</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.admin.common.config.properties;
package top.continew.admin.common.config;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package top.continew.admin.common.config.properties;
package top.continew.admin.common.config;
import cn.hutool.extra.spring.SpringUtil;

View File

@@ -14,27 +14,26 @@
* limitations under the License.
*/
package top.continew.admin.common.config.properties;
package top.continew.admin.common.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import top.continew.starter.core.constant.PropertiesConstants;
import java.util.List;
/**
* @description: 租户配置
* @author: 小熊
* @create: 2024-11-29 12:05
* 租户配置属性
*
* @author 小熊
* @author Charles7c
* @since 2024/11/29 12:05
*/
@Component
@ConfigurationProperties(prefix = PropertiesConstants.TENANT)
@Data
public class TenantProperties {
private boolean enabled;
@Component
public class TenantProperties extends top.continew.starter.extension.tenant.autoconfigure.TenantProperties {
/**
* 忽略菜单 ID租户不能使用的菜单
*/
private List<Long> ignoreMenus;
}

View File

@@ -71,16 +71,6 @@ public class CacheConstants {
*/
public static final String DATA_IMPORT_KEY = "SYSTEM" + DELIMITER + "DATA_IMPORT" + DELIMITER;
/**
* 数据连接键前缀
*/
public static final String DB_CONNECT_KEY_PREFIX = "DB_CONNECT" + DELIMITER;
/**
* 租户信息前缀
*/
public static final String TENANT_KEY = "TENANT" + DELIMITER;
private CacheConstants() {
}
}

View File

@@ -85,29 +85,14 @@ public class SysConstants {
public static final String LOGOUT_URI = "/auth/logout";
/**
* 描述类字段后缀
* 租户默认数据源
*/
public static final String DESCRIPTION_FIELD_SUFFIX = "String";
/**
* 租户数据库前缀
*/
public static final String TENANT_DB_PREFIX = "tenant_";
/**
* 默认租户
*/
public static final String DEFAULT_TENANT = "0";
/**
* 默认数据源
*/
public static final String DEFAULT_DATASOURCE = "master";
public static final String DEFAULT_TENANT_DATASOURCE = "master";
/**
* 租户管理员角色编码
*/
public static final String TENANT_ADMIN_CODE = "tenant_admin";
public static final String TENANT_ADMIN_ROLE_CODE = "tenant_admin";
private SysConstants() {
}

View File

@@ -80,7 +80,7 @@ public class UserContext implements Serializable {
*/
private Set<RoleContext> roles;
/*
/**
* 客户端类型
*/
private String clientType;
@@ -134,5 +134,4 @@ public class UserContext implements Serializable {
}
return this.pwdResetTime.plusDays(this.passwordExpirationDays).isBefore(LocalDateTime.now());
}
}

View File

@@ -143,6 +143,15 @@ public class UserContextHolder {
return ExceptionUtils.exToNull(() -> getContext().getId());
}
/**
* 获取租户 ID
*
* @return 租户 ID
*/
public static Long getTenantId() {
return ExceptionUtils.exToNull(() -> getContext().getTenantId());
}
/**
* 获取用户名
*
@@ -180,11 +189,4 @@ public class UserContextHolder {
StpUtil.checkLogin();
return getContext().isAdmin();
}
/**
* 获取租户ID
*/
public static Long getTenantId() {
return ExceptionUtils.exToNull(() -> getContext().getTenantId());
}
}

View File

@@ -20,7 +20,7 @@ import cn.hutool.core.codec.Base64;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.extra.spring.SpringUtil;
import top.continew.admin.common.config.properties.RsaProperties;
import top.continew.admin.common.config.RsaProperties;
import top.continew.starter.core.exception.BusinessException;
import top.continew.starter.core.util.validation.ValidationUtils;
import top.continew.starter.security.crypto.autoconfigure.CryptoProperties;