feat(plugin/tenant): 新增多租户插件模块 (#175)

This commit is contained in:
小熊
2025-07-10 20:38:59 +08:00
committed by GitHub
parent 72493f8161
commit ed6dd65a51
70 changed files with 3539 additions and 65 deletions

View File

@@ -0,0 +1,40 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.continew.admin.common.config.properties;
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
*/
@Component
@ConfigurationProperties(prefix = PropertiesConstants.TENANT)
@Data
public class TenantProperties {
private boolean enabled;
private List<Long> ignoreMenus;
}

View File

@@ -71,6 +71,16 @@ 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

@@ -84,6 +84,31 @@ 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 TENANT_ADMIN_CODE = "tenant_admin";
private SysConstants() {
}
}

View File

@@ -80,7 +80,7 @@ public class UserContext implements Serializable {
*/
private Set<RoleContext> roles;
/**
/*
* 客户端类型
*/
private String clientType;
@@ -90,6 +90,11 @@ public class UserContext implements Serializable {
*/
private String clientId;
/**
* 租户 ID
*/
private Long tenantId;
public UserContext(Set<String> permissions, Set<RoleContext> roles, Integer passwordExpirationDays) {
this.permissions = permissions;
this.setRoles(roles);
@@ -129,4 +134,5 @@ public class UserContext implements Serializable {
}
return this.pwdResetTime.plusDays(this.passwordExpirationDays).isBefore(LocalDateTime.now());
}
}

View File

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