Skip to content

Commit 819be06

Browse files
committed
refactor(tenant): 优化租户管理表字段设计
1 parent f350ee1 commit 819be06

File tree

9 files changed

+76
-56
lines changed

9 files changed

+76
-56
lines changed

continew-common/src/main/java/top/continew/admin/common/model/dto/TenantDTO.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ public class TenantDTO implements Serializable {
4646
/**
4747
* 管理员用户名
4848
*/
49-
private String username;
49+
private String adminUsername;
5050

5151
/**
5252
* 管理员密码
5353
*/
54-
private String password;
54+
private String adminPassword;
5555

5656
/**
5757
* 套餐 ID

continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/model/entity/TenantDO.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class TenantDO extends BaseDO {
4949
private String code;
5050

5151
/**
52-
* 绑定域名
52+
* 域名
5353
*/
5454
private String domain;
5555

@@ -69,10 +69,15 @@ public class TenantDO extends BaseDO {
6969
private DisEnableStatusEnum status;
7070

7171
/**
72-
* 租户管理员
72+
* 管理员用户
7373
*/
7474
private Long adminUser;
7575

76+
/**
77+
* 管理员用户名
78+
*/
79+
private String adminUsername;
80+
7681
/**
7782
* 套餐 ID
7883
*/

continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/model/req/TenantReq.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ public class TenantReq implements Serializable {
5454
private String name;
5555

5656
/**
57-
* 绑定域名
57+
* 域名
5858
*/
59-
@Schema(description = "绑定域名", example = "https://T0sL6RWv0vFh.continew.top/")
60-
@Length(max = 255, message = "绑定域名长度不能超过 {max} 个字符")
61-
@Pattern(regexp = RegexConstants.HTTP_HOST, message = "绑定域名格式不正确")
59+
@Schema(description = "域名", example = "https://T0sL6RWv0vFh.continew.top/")
60+
@Length(max = 255, message = "域名长度不能超过 {max} 个字符")
61+
@Pattern(regexp = RegexConstants.HTTP_HOST, message = "域名格式不正确")
6262
private String domain;
6363

6464
/**
@@ -89,19 +89,19 @@ public class TenantReq implements Serializable {
8989
private Long packageId;
9090

9191
/**
92-
* 用户名
92+
* 管理员用户名
9393
*/
94-
@Schema(description = "用户名", example = "zhangsan")
95-
@NotBlank(message = "用户名不能为空", groups = CrudValidationGroup.Create.class)
96-
@Pattern(regexp = RegexConstants.USERNAME, message = "用户名长度为 4-64 个字符,支持大小写字母、数字、下划线,以字母开头")
97-
private String username;
94+
@Schema(description = "管理员用户名", example = "zhangsan")
95+
@NotBlank(message = "管理员用户名不能为空", groups = CrudValidationGroup.Create.class)
96+
@Pattern(regexp = RegexConstants.USERNAME, message = "管理员用户名长度为 4-64 个字符,支持大小写字母、数字、下划线,以字母开头")
97+
private String adminUsername;
9898

9999
/**
100-
* 密码(加密)
100+
* 管理员密码(加密)
101101
*/
102-
@Schema(description = "密码(加密)", example = "E7c72TH+LDxKTwavjM99W1MdI9Lljh79aPKiv3XB9MXcplhm7qJ1BJCj28yaflbdVbfc366klMtjLIWQGqb0qw==")
103-
@NotBlank(message = "密码不能为空", groups = CrudValidationGroup.Create.class)
104-
private String password;
102+
@Schema(description = "管理员密码(加密)", example = "E7c72TH+LDxKTwavjM99W1MdI9Lljh79aPKiv3XB9MXcplhm7qJ1BJCj28yaflbdVbfc366klMtjLIWQGqb0qw==")
103+
@NotBlank(message = "管理员密码不能为空", groups = CrudValidationGroup.Create.class)
104+
private String adminPassword;
105105

106106
/**
107107
* 编码

continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/model/resp/TenantResp.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ public class TenantResp extends BaseDetailResp {
6161
private String code;
6262

6363
/**
64-
* 绑定域名
64+
* 域名
6565
*/
66-
@Schema(description = "绑定域名", example = "https://T0sL6RWv0vFh.continew.top/")
67-
@ExcelProperty(value = "绑定域名", order = 4)
66+
@Schema(description = "域名", example = "T0sL6RWv0vFh.continew.top")
67+
@ExcelProperty(value = "域名", order = 4)
6868
private String domain;
6969

7070
/**
@@ -88,11 +88,23 @@ public class TenantResp extends BaseDetailResp {
8888
@ExcelProperty(value = "状态", converter = ExcelBaseEnumConverter.class, order = 8)
8989
private DisEnableStatusEnum status;
9090

91+
/**
92+
* 管理员用户
93+
*/
94+
@Schema(description = "管理员用户", example = "2")
95+
private Long adminUser;
96+
97+
/**
98+
* 管理员用户名
99+
*/
100+
@Schema(description = "管理员用户名", example = "admin")
101+
@ExcelProperty(value = "管理员用户名", order = 9)
102+
private String adminUsername;
103+
91104
/**
92105
* 套餐 ID
93106
*/
94107
@Schema(description = "套餐 ID", example = "1")
95-
@ExcelProperty(value = "套餐 ID", order = 9)
96108
@AssembleMethod(props = @Mapping(src = "name", ref = "packageName"), targetType = PackageService.class, method = @ContainerMethod(bindMethod = "get", resultType = PackageResp.class))
97109
private Long packageId;
98110

continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/service/TenantService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
public interface TenantService extends BaseService<TenantResp, TenantDetailResp, TenantQuery, TenantReq>, IService<TenantDO> {
3737

3838
/**
39-
* 根据绑定域名查询
39+
* 根据域名查询
4040
*
41-
* @param domain 绑定域名
41+
* @param domain 域名
4242
* @return ID
4343
*/
4444
Long getIdByDomain(String domain);

continew-plugin/continew-plugin-tenant/src/main/java/top/continew/admin/tenant/service/impl/TenantServiceImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,16 +197,16 @@ private void checkNameRepeat(String name, Long id) {
197197
}
198198

199199
/**
200-
* 检查绑定域名是否重复
200+
* 检查域名是否重复
201201
*
202-
* @param domain 绑定域名
202+
* @param domain 域名
203203
* @param id ID
204204
*/
205205
private void checkDomainRepeat(String domain, Long id) {
206206
CheckUtils.throwIf(baseMapper.lambdaQuery()
207207
.eq(TenantDO::getDomain, domain)
208208
.ne(id != null, TenantDO::getId, id)
209-
.exists(), "绑定域名为 [{}] 的租户已存在", domain);
209+
.exists(), "域名为 [{}] 的租户已存在", domain);
210210
}
211211

212212
/**

continew-server/src/main/resources/db/changelog/mysql/plugin/plugin_tenant.sql

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@
44
-- comment 初始化租户插件数据表
55
-- 初始化表结构
66
CREATE TABLE IF NOT EXISTS `tenant` (
7-
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
8-
`name` varchar(30) NOT NULL COMMENT '名称',
9-
`code` varchar(30) NOT NULL COMMENT '编码',
10-
`domain` varchar(255) DEFAULT NULL COMMENT '绑定域名',
11-
`expire_time` datetime DEFAULT NULL COMMENT '过期时间',
12-
`description` varchar(200) DEFAULT NULL COMMENT '描述',
13-
`status` tinyint(1) UNSIGNED NOT NULL DEFAULT 1 COMMENT '状态(1:启用;2:禁用)',
14-
`admin_user` bigint(20) DEFAULT NULL COMMENT '租户管理员',
15-
`package_id` bigint(20) NOT NULL COMMENT '套餐ID',
16-
`create_user` bigint(20) NOT NULL COMMENT '创建人',
17-
`create_time` datetime NOT NULL COMMENT '创建时间',
18-
`update_user` bigint(20) DEFAULT NULL COMMENT '修改人',
19-
`update_time` datetime DEFAULT NULL COMMENT '修改时间',
7+
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
8+
`name` varchar(30) NOT NULL COMMENT '名称',
9+
`code` varchar(30) NOT NULL COMMENT '编码',
10+
`domain` varchar(255) DEFAULT NULL COMMENT '域名',
11+
`expire_time` datetime DEFAULT NULL COMMENT '过期时间',
12+
`description` varchar(200) DEFAULT NULL COMMENT '描述',
13+
`status` tinyint(1) UNSIGNED NOT NULL DEFAULT 1 COMMENT '状态(1:启用;2:禁用)',
14+
`admin_user` bigint(20) DEFAULT NULL COMMENT '管理员用户',
15+
`admin_username` varchar(64) DEFAULT NULL COMMENT '管理员用户名',
16+
`package_id` bigint(20) NOT NULL COMMENT '套餐ID',
17+
`create_user` bigint(20) NOT NULL COMMENT '创建人',
18+
`create_time` datetime NOT NULL COMMENT '创建时间',
19+
`update_user` bigint(20) DEFAULT NULL COMMENT '修改人',
20+
`update_time` datetime DEFAULT NULL COMMENT '修改时间',
2021
PRIMARY KEY (`id`),
2122
UNIQUE INDEX `uk_code`(`code`),
2223
INDEX `idx_admin_user`(`admin_user`),

continew-server/src/main/resources/db/changelog/postgresql/plugin/plugin_tenant.sql

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@
44
-- comment 初始化租户插件数据表
55
-- 初始化表结构
66
CREATE TABLE IF NOT EXISTS "tenant" (
7-
"id" int8 NOT NULL,
8-
"name" varchar(30) NOT NULL,
9-
"code" varchar(30) NOT NULL,
10-
"domain" varchar(255) DEFAULT NULL,
11-
"expire_time" timestamp DEFAULT NULL,
12-
"description" varchar(200) DEFAULT NULL,
13-
"status" int2 NOT NULL DEFAULT 1,
14-
"admin_user" int8 DEFAULT NULL,
15-
"package_id" int8 NOT NULL,
16-
"create_user" int8 NOT NULL,
17-
"create_time" timestamp NOT NULL,
18-
"update_user" int8 DEFAULT NULL,
19-
"update_time" timestamp DEFAULT NULL,
7+
"id" int8 NOT NULL,
8+
"name" varchar(30) NOT NULL,
9+
"code" varchar(30) NOT NULL,
10+
"domain" varchar(255) DEFAULT NULL,
11+
"expire_time" timestamp DEFAULT NULL,
12+
"description" varchar(200) DEFAULT NULL,
13+
"status" int2 NOT NULL DEFAULT 1,
14+
"admin_user" int8 DEFAULT NULL,
15+
"admin_username" varchar(64) DEFAULT NULL,
16+
"package_id" int8 NOT NULL,
17+
"create_user" int8 NOT NULL,
18+
"create_time" timestamp NOT NULL,
19+
"update_user" int8 DEFAULT NULL,
20+
"update_time" timestamp DEFAULT NULL,
2021
PRIMARY KEY ("id")
2122
);
2223
CREATE UNIQUE INDEX "uk_tenant_code" ON "tenant" ("code");
@@ -27,12 +28,13 @@ CREATE INDEX "idx_tenant_update_user" ON "tenant" ("update_user");
2728
COMMENT ON COLUMN "tenant"."id" IS 'ID';
2829
COMMENT ON COLUMN "tenant"."name" IS '名称';
2930
COMMENT ON COLUMN "tenant"."code" IS '编码';
30-
COMMENT ON COLUMN "tenant"."domain" IS '绑定域名';
31+
COMMENT ON COLUMN "tenant"."domain" IS '域名';
3132
COMMENT ON COLUMN "tenant"."expire_time" IS '过期时间';
3233
COMMENT ON COLUMN "tenant"."description" IS '描述';
3334
COMMENT ON COLUMN "tenant"."status" IS '状态(1:启用;2:禁用)';
3435
COMMENT ON COLUMN "tenant"."package_id" IS '套餐ID';
35-
COMMENT ON COLUMN "tenant"."admin_user" IS '租户管理员';
36+
COMMENT ON COLUMN "tenant"."admin_user" IS '管理员用户';
37+
COMMENT ON COLUMN "tenant"."admin_username" IS '管理员用户名';
3638
COMMENT ON COLUMN "tenant"."create_user" IS '创建人';
3739
COMMENT ON COLUMN "tenant"."create_time" IS '创建时间';
3840
COMMENT ON COLUMN "tenant"."update_user" IS '修改人';

continew-system/src/main/java/top/continew/admin/system/api/TenantDataApiForSystemImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,10 @@ private Long initRoleData(TenantDTO tenant) {
183183
*/
184184
private Long initUserData(TenantDTO tenant, Long deptId) {
185185
// 解密密码
186-
String password = SecureUtils.decryptPasswordByRsaPrivateKey(tenant.getPassword(), "密码解密失败", true);
186+
String password = SecureUtils.decryptPasswordByRsaPrivateKey(tenant.getAdminPassword(), "密码解密失败", true);
187187
// 初始化用户
188188
UserDO user = new UserDO();
189-
user.setUsername(tenant.getUsername());
189+
user.setUsername(tenant.getAdminUsername());
190190
user.setNickname(RoleCodeEnum.TENANT_ADMIN.getDescription());
191191
user.setPassword(password);
192192
user.setGender(GenderEnum.UNKNOWN);

0 commit comments

Comments
 (0)