mirror of
				https://github.com/continew-org/continew-admin.git
				synced 2025-10-26 18:58:37 +08:00 
			
		
		
		
	feat(plugin/tenant): 新增多租户插件模块 (#175)
This commit is contained in:
		| @@ -167,5 +167,18 @@ | ||||
|             <groupId>top.continew.starter</groupId> | ||||
|             <artifactId>continew-starter-extension-crud-mp</artifactId> | ||||
|         </dependency> | ||||
|  | ||||
|         <!-- 多租户组件--> | ||||
|         <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> | ||||
| @@ -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; | ||||
|  | ||||
| } | ||||
| @@ -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() { | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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() { | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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()); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -180,4 +180,11 @@ public class UserContextHolder { | ||||
|         StpUtil.checkLogin(); | ||||
|         return getContext().isAdmin(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * 获取租户ID | ||||
|      */ | ||||
|     public static Long getTenantId() { | ||||
|         return ExceptionUtils.exToNull(() -> getContext().getTenantId()); | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 小熊
					小熊