Skip to content

Commit af1079d

Browse files
committed
refactor(tenant): 优化租户相关代码
1 parent ed6dd65 commit af1079d

111 files changed

Lines changed: 2695 additions & 2273 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 54 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ContiNew Admin 中后台管理框架
1+
# ContiNew Admin 多租户中后台管理框架
22

33
<a href="https://github.com/continew-org/continew-admin" title="Release" target="_blank">
44
<img src="https://img.shields.io/badge/SNAPSHOT-v4.0.0-%23ff3f59.svg" alt="Release" />
@@ -44,9 +44,9 @@
4444

4545
**AI 编程纪元已经开启,基于 ContiNew 项目开发,让 AI 助手“学习”更优雅的代码规范,“写出”更优质的代码。**
4646

47-
ContiNew Admin(Continue New Admin)持续迭代优化的前后端分离中后台管理系统框架。开箱即用,重视每一处代码规范,重视每一种解决方案细节,持续提供舒适的前、后端开发体验。
47+
ContiNew Admin(Continue New Admin):持续迭代优化的,前后端分离,多租户中后台管理系统框架。开箱即用,重视每一处代码规范,重视每一种解决方案细节,持续提供舒适的前、后端开发体验。
4848

49-
当前采用的技术栈:Spring Boot3(Java17)、Vue3 & Arco Design & TS & Vite、Sa-Token、MyBatis Plus、Redisson、JetCache、JustAuth、Crane4j、EasyExcel、Liquibase、Hutool 等。
49+
当前采用的技术栈:Spring Boot3(Java17)、Vue3 & Arco Design & TS & Vite、Sa-Token、MyBatis Plus、FastExcel、Redisson、JetCache、JustAuth、Crane4j、Hutool、Liquibase 等。
5050

5151
## 项目源码
5252

@@ -143,10 +143,13 @@ public class DeptController extends BaseController<DeptService, DeptResp, DeptDe
143143
- 客户端配置:多端(PC端、小程序端等)认证管理,可设置不同的 token 有效期
144144
- 在线用户:管理当前登录用户,可一键踢除下线
145145
- 日志管理:管理系统登录日志、操作日志,支持查看日志详情,包含请求头、响应头等报文信息
146-
- 短信日志:管理系统短信发送日志,支持删除、导出
146+
- 短信日志:管理系统短信发送日志,支持删除、导出
147+
- 应用管理:管理第三方系统应用 AK、SK,包含新增、修改、删除、查看密钥、重置密钥等功能,支持设置密钥有效期
148+
- 租户管理:管理租户信息,包含新增、修改、删除、分配角色等功能
149+
- 租户套餐:管理租户套餐信息,包含新增、修改、删除、查看等功能
150+
- 租户数据源:管理数据源信息,包含新增、修改、删除、查看、测试等功能
147151
- 任务管理:管理系统定时任务,包含新增、修改、删除、执行功能,支持 Cron(可配置式生成 Cron 表达式) 和固定频率
148152
- 任务日志:管理定时任务执行日志,包含停止、重试指定批次,查询集群各节点的详细输出日志等功能
149-
- 应用管理:管理第三方系统应用 AK、SK,包含新增、修改、删除、查看密钥、重置密钥等功能,支持设置密钥有效期
150153
- 代码生成:提供根据数据库表自动生成相应的前后端 CRUD 代码的功能,支持同步最新表结构及代码生成预览
151154

152155
## 系统截图
@@ -313,8 +316,8 @@ continew-admin
313316
│ │ │ │ │ ├─ service(系统认证相关业务接口及实现类)
314317
│ │ │ │ │ ├─ model(系统认证相关模型)
315318
│ │ │ │ │ │ ├─ query(系统认证相关查询条件)
316-
│ │ │ │ │ │ ├─ req(系统认证相关请求对象(Request))
317-
│ │ │ │ │ │ └─ resp(系统认证相关响应对象(Response))
319+
│ │ │ │ │ │ ├─ req(系统认证相关请求参数(Request))
320+
│ │ │ │ │ │ └─ resp(系统认证相关响应参数(Response))
318321
│ │ │ │ │ ├─ enums(系统认证相关枚举)
319322
│ │ │ │ │ ├─ handler(系统认证相关处理器)
320323
│ │ │ │ │ └─ config(系统认证相关配置)
@@ -323,10 +326,10 @@ continew-admin
323326
│ │ │ │ ├─ service(系统管理相关业务接口及实现类)
324327
│ │ │ │ ├─ mapper(系统管理相关 Mapper)
325328
│ │ │ │ ├─ model(系统管理相关模型)
326-
│ │ │ │ │ ├─ entity(系统管理相关实体对象)
329+
│ │ │ │ │ ├─ entity(系统管理相关实体)
327330
│ │ │ │ │ ├─ query(系统管理相关查询条件)
328-
│ │ │ │ │ ├─ req(系统管理相关请求对象(Request))
329-
│ │ │ │ │ └─ resp(系统管理相关响应对象(Response))
331+
│ │ │ │ │ ├─ req(系统管理相关请求参数(Request))
332+
│ │ │ │ │ └─ resp(系统管理相关响应参数(Response))
330333
│ │ │ │ ├─ enums(系统管理相关枚举)
331334
│ │ │ │ ├─ util(系统管理相关工具类)
332335
│ │ │ │ ├─ validation(系统管理相关参数校验工具类)
@@ -335,7 +338,39 @@ continew-admin
335338
│ │ │ └─ mapper(系统管理相关 Mapper XML 文件目录)
336339
│ │ └─ test(测试相关代码目录)
337340
│ └─ pom.xml
338-
├─ continew-plugin(插件模块,存放代码生成、任务调度等扩展模块,后续会进行插件化改造)
341+
├─ continew-plugin(插件模块,存放能力开放、租户等扩展模块,后续会进行插件化改造)
342+
│ ├─ continew-plugin-open(能力开放插件模块)
343+
│ │ ├─ src
344+
│ │ │ ├─ main/java/top/continew/admin/open
345+
│ │ │ │ ├─ controller(能力开放相关 API)
346+
│ │ │ │ ├─ service(能力开放相关业务接口及实现类)
347+
│ │ │ │ ├─ mapper(能力开放相关 Mapper)
348+
│ │ │ │ ├─ model(能力开放相关模型)
349+
│ │ │ │ │ ├─ entity(能力开放相关实体)
350+
│ │ │ │ │ ├─ query(能力开放相关查询条件)
351+
│ │ │ │ │ ├─ req(能力开放相关请求参数(Request))
352+
│ │ │ │ │ └─ resp(能力开放相关响应参数(Response))
353+
│ │ │ │ ├─ util(能力开放相关工具类)
354+
│ │ │ │ └─ config(能力开放相关配置)
355+
│ │ │ └─ test(测试相关代码目录)
356+
│ │ └─ pom.xml
357+
│ ├─ continew-plugin-tenant(租户插件模块)
358+
│ │ ├─ src
359+
│ │ │ ├─ main/java/top/continew/admin/tenant
360+
│ │ │ │ ├─ controller(租户相关 API)
361+
│ │ │ │ ├─ service(租户相关业务接口及实现类)
362+
│ │ │ │ ├─ mapper(租户相关 Mapper)
363+
│ │ │ │ ├─ model(租户相关模型)
364+
│ │ │ │ │ ├─ enums(租户相关枚举)
365+
│ │ │ │ │ ├─ entity(租户相关实体)
366+
│ │ │ │ │ ├─ query(租户相关查询条件)
367+
│ │ │ │ │ ├─ req(租户相关请求参数(Request))
368+
│ │ │ │ │ └─ resp(租户相关响应参数(Response))
369+
│ │ │ │ ├─ util(租户相关工具类)
370+
│ │ │ │ ├─ constant(租户相关常量类)
371+
│ │ │ │ └─ config(租户相关配置)
372+
│ │ │ └─ test(测试相关代码目录)
373+
│ │ └─ pom.xml
339374
│ ├─ continew-plugin-schedule(任务调度插件模块)
340375
│ │ ├─ src
341376
│ │ │ ├─ main/java/top/continew/admin/schedule
@@ -344,29 +379,14 @@ continew-admin
344379
│ │ │ │ ├─ api(任务调度中心相关 API)
345380
│ │ │ │ ├─ model(任务调度相关模型)
346381
│ │ │ │ │ ├─ query(任务调度相关查询条件)
347-
│ │ │ │ │ ├─ req(任务调度相关请求对象(Request))
348-
│ │ │ │ │ └─ resp(任务调度相关响应对象(Response))
349-
│ │ │ │ ├─ constant(任务调度相关常量)
382+
│ │ │ │ │ ├─ req(任务调度相关请求参数(Request))
383+
│ │ │ │ │ └─ resp(任务调度相关响应参数(Response))
384+
│ │ │ │ ├─ constant(任务调度相关常量类)
350385
│ │ │ │ ├─ enums(任务调度相关枚举)
351386
│ │ │ │ ├─ exception(任务调度相关异常)
352387
│ │ │ │ └─ config(任务调度相关配置)
353388
│ │ │ └─ test(测试相关代码目录)
354389
│ │ └─ pom.xml
355-
│ ├─ continew-plugin-open(能力开放插件模块)
356-
│ │ ├─ src
357-
│ │ │ ├─ main/java/top/continew/admin/open
358-
│ │ │ │ ├─ controller(能力开放相关 API)
359-
│ │ │ │ ├─ service(能力开放相关业务接口及实现类)
360-
│ │ │ │ ├─ mapper(能力开放相关 Mapper)
361-
│ │ │ │ ├─ model(能力开放相关模型)
362-
│ │ │ │ │ ├─ entity(能力开放相关实体对象)
363-
│ │ │ │ │ ├─ query(能力开放相关查询条件)
364-
│ │ │ │ │ ├─ req(能力开放相关请求对象(Request))
365-
│ │ │ │ │ └─ resp(能力开放相关响应对象(Response))
366-
│ │ │ │ ├─ util(能力开放相关工具类)
367-
│ │ │ │ └─ config(能力开放相关配置)
368-
│ │ │ └─ test(测试相关代码目录)
369-
│ │ └─ pom.xml
370390
│ ├─ continew-plugin-generator(代码生成器插件模块)
371391
│ │ ├─ src
372392
│ │ │ ├─ main
@@ -375,10 +395,10 @@ continew-admin
375395
│ │ │ │ │ ├─ service(代码生成器相关业务接口及实现类)
376396
│ │ │ │ │ ├─ mapper(代码生成器相关 Mapper)
377397
│ │ │ │ │ ├─ model(代码生成器相关模型)
378-
│ │ │ │ │ │ ├─ entity(代码生成器相关实体对象)
398+
│ │ │ │ │ │ ├─ entity(代码生成器相关实体)
379399
│ │ │ │ │ │ ├─ query(代码生成器相关查询条件)
380-
│ │ │ │ │ │ ├─ req(代码生成器相关请求对象(Request))
381-
│ │ │ │ │ │ └─ resp(代码生成器相关响应对象(Response))
400+
│ │ │ │ │ │ ├─ req(代码生成器相关请求参数(Request))
401+
│ │ │ │ │ │ └─ resp(代码生成器相关响应参数(Response))
382402
│ │ │ │ │ ├─ enums(代码生成器相关枚举)
383403
│ │ │ │ │ └─ config(代码生成器相关配置)
384404
│ │ │ │ └─ resources
@@ -400,9 +420,9 @@ continew-admin
400420
│ │ │ │ └─ service(业务接口及实现基类)
401421
│ │ │ ├─ service(公共服务接口)
402422
│ │ │ ├─ model(公共模型)
403-
│ │ │ │ └─ req(公共请求对象(Request))
423+
│ │ │ │ └─ req(公共请求参数(Request))
404424
│ │ │ ├─ context(公共上下文)
405-
│ │ │ ├─ constant(公共常量)
425+
│ │ │ ├─ constant(公共常量类)
406426
│ │ │ ├─ enums(公共枚举)
407427
│ │ │ ├─ util(公共工具类)
408428
│ │ │ └─ config(公共配置)

‎continew-common/pom.xml‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,15 @@
168168
<artifactId>continew-starter-extension-crud-mp</artifactId>
169169
</dependency>
170170

171-
<!-- 多租户组件-->
171+
<!-- ContiNew Starter 扩展模块 - 租户 -->
172172
<dependency>
173173
<groupId>top.continew.starter</groupId>
174174
<artifactId>continew-starter-extension-tenant-mp</artifactId>
175175
</dependency>
176-
177176
<!-- Dynamic Datasource(基于 Spring Boot 的快速集成多数据源的启动器) -->
178177
<dependency>
179178
<groupId>com.baomidou</groupId>
180179
<artifactId>dynamic-datasource-spring-boot3-starter</artifactId>
181180
</dependency>
182-
183181
</dependencies>
184182
</project>

continew-common/src/main/java/top/continew/admin/common/config/properties/CaptchaProperties.java renamed to continew-common/src/main/java/top/continew/admin/common/config/CaptchaProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package top.continew.admin.common.config.properties;
17+
package top.continew.admin.common.config;
1818

1919
import lombok.Data;
2020
import org.springframework.beans.factory.annotation.Value;

continew-common/src/main/java/top/continew/admin/common/config/properties/RsaProperties.java renamed to continew-common/src/main/java/top/continew/admin/common/config/RsaProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package top.continew.admin.common.config.properties;
17+
package top.continew.admin.common.config;
1818

1919
import cn.hutool.extra.spring.SpringUtil;
2020

continew-common/src/main/java/top/continew/admin/common/config/properties/TenantProperties.java renamed to continew-common/src/main/java/top/continew/admin/common/config/TenantProperties.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,26 @@
1414
* limitations under the License.
1515
*/
1616

17-
package top.continew.admin.common.config.properties;
17+
package top.continew.admin.common.config;
1818

1919
import lombok.Data;
20-
import org.springframework.boot.context.properties.ConfigurationProperties;
2120
import org.springframework.stereotype.Component;
22-
import top.continew.starter.core.constant.PropertiesConstants;
2321

2422
import java.util.List;
2523

2624
/**
27-
* @description: 多租户配置
28-
* @author: 小熊
29-
* @create: 2024-11-29 12:05
25+
* 租户配置属性
26+
*
27+
* @author 小熊
28+
* @author Charles7c
29+
* @since 2024/11/29 12:05
3030
*/
31-
@Component
32-
@ConfigurationProperties(prefix = PropertiesConstants.TENANT)
3331
@Data
34-
public class TenantProperties {
35-
36-
private boolean enabled;
32+
@Component
33+
public class TenantProperties extends top.continew.starter.extension.tenant.autoconfigure.TenantProperties {
3734

35+
/**
36+
* 忽略菜单 ID(租户不能使用的菜单)
37+
*/
3838
private List<Long> ignoreMenus;
39-
4039
}

‎continew-common/src/main/java/top/continew/admin/common/constant/CacheConstants.java‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,6 @@ public class CacheConstants {
7171
*/
7272
public static final String DATA_IMPORT_KEY = "SYSTEM" + DELIMITER + "DATA_IMPORT" + DELIMITER;
7373

74-
/**
75-
* 数据连接键前缀
76-
*/
77-
public static final String DB_CONNECT_KEY_PREFIX = "DB_CONNECT" + DELIMITER;
78-
79-
/**
80-
* 租户信息前缀
81-
*/
82-
public static final String TENANT_KEY = "TENANT" + DELIMITER;
83-
8474
private CacheConstants() {
8575
}
8676
}

‎continew-common/src/main/java/top/continew/admin/common/constant/SysConstants.java‎

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,29 +85,14 @@ public class SysConstants {
8585
public static final String LOGOUT_URI = "/auth/logout";
8686

8787
/**
88-
* 描述类字段后缀
88+
* 租户默认数据源
8989
*/
90-
public static final String DESCRIPTION_FIELD_SUFFIX = "String";
91-
92-
/**
93-
* 租户数据库前缀
94-
*/
95-
public static final String TENANT_DB_PREFIX = "tenant_";
96-
97-
/**
98-
* 默认租户
99-
*/
100-
public static final String DEFAULT_TENANT = "0";
101-
102-
/**
103-
* 默认数据源
104-
*/
105-
public static final String DEFAULT_DATASOURCE = "master";
90+
public static final String DEFAULT_TENANT_DATASOURCE = "master";
10691

10792
/**
10893
* 租户管理员角色编码
10994
*/
110-
public static final String TENANT_ADMIN_CODE = "tenant_admin";
95+
public static final String TENANT_ADMIN_ROLE_CODE = "tenant_admin";
11196

11297
private SysConstants() {
11398
}

‎continew-common/src/main/java/top/continew/admin/common/context/UserContext.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public class UserContext implements Serializable {
8080
*/
8181
private Set<RoleContext> roles;
8282

83-
/*
83+
/**
8484
* 客户端类型
8585
*/
8686
private String clientType;
@@ -134,5 +134,4 @@ public boolean isPasswordExpired() {
134134
}
135135
return this.pwdResetTime.plusDays(this.passwordExpirationDays).isBefore(LocalDateTime.now());
136136
}
137-
138137
}

‎continew-common/src/main/java/top/continew/admin/common/context/UserContextHolder.java‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,15 @@ public static Long getUserId() {
143143
return ExceptionUtils.exToNull(() -> getContext().getId());
144144
}
145145

146+
/**
147+
* 获取租户 ID
148+
*
149+
* @return 租户 ID
150+
*/
151+
public static Long getTenantId() {
152+
return ExceptionUtils.exToNull(() -> getContext().getTenantId());
153+
}
154+
146155
/**
147156
* 获取用户名
148157
*
@@ -180,11 +189,4 @@ public static boolean isAdmin() {
180189
StpUtil.checkLogin();
181190
return getContext().isAdmin();
182191
}
183-
184-
/**
185-
* 获取租户ID
186-
*/
187-
public static Long getTenantId() {
188-
return ExceptionUtils.exToNull(() -> getContext().getTenantId());
189-
}
190192
}

‎continew-common/src/main/java/top/continew/admin/common/util/SecureUtils.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import cn.hutool.crypto.SecureUtil;
2121
import cn.hutool.crypto.asymmetric.KeyType;
2222
import cn.hutool.extra.spring.SpringUtil;
23-
import top.continew.admin.common.config.properties.RsaProperties;
23+
import top.continew.admin.common.config.RsaProperties;
2424
import top.continew.starter.core.exception.BusinessException;
2525
import top.continew.starter.core.util.validation.ValidationUtils;
2626
import top.continew.starter.security.crypto.autoconfigure.CryptoProperties;

0 commit comments

Comments
 (0)