From e89ba7d5cd793e20c3562c7bd1e4655ed1e5a2a3 Mon Sep 17 00:00:00 2001 From: Charles7c Date: Sat, 27 Apr 2024 17:32:54 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E7=8A=B6=E6=80=81=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../continew/admin/system/model/entity/RoleDO.java | 6 ------ .../admin/system/model/query/RoleQuery.java | 6 ------ .../continew/admin/system/model/req/RoleReq.java | 7 ------- .../admin/system/model/resp/RoleDetailResp.java | 8 -------- .../continew/admin/system/model/resp/RoleResp.java | 7 ------- .../admin/system/service/UserRoleService.java | 14 +++----------- .../admin/system/service/impl/RoleServiceImpl.java | 11 ++--------- .../system/service/impl/UserRoleServiceImpl.java | 9 ++------- .../src/main/resources/mapper/MenuMapper.xml | 2 -- .../db/changelog/mysql/continew-admin_data.sql | 6 +++--- .../db/changelog/mysql/continew-admin_table.sql | 1 - .../changelog/postgresql/continew-admin_data.sql | 6 +++--- .../changelog/postgresql/continew-admin_table.sql | 2 -- 13 files changed, 13 insertions(+), 72 deletions(-) diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/model/entity/RoleDO.java b/continew-admin-system/src/main/java/top/continew/admin/system/model/entity/RoleDO.java index 57460b87..a8681901 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/system/model/entity/RoleDO.java +++ b/continew-admin-system/src/main/java/top/continew/admin/system/model/entity/RoleDO.java @@ -19,7 +19,6 @@ import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import top.continew.admin.common.enums.DataScopeEnum; -import top.continew.admin.common.enums.DisEnableStatusEnum; import top.continew.starter.extension.crud.model.entity.BaseDO; import java.io.Serial; @@ -62,11 +61,6 @@ public class RoleDO extends BaseDO { */ private Integer sort; - /** - * 状态 - */ - private DisEnableStatusEnum status; - /** * 是否为系统内置数据 */ diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/model/query/RoleQuery.java b/continew-admin-system/src/main/java/top/continew/admin/system/model/query/RoleQuery.java index b80786fc..3fbea7db 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/system/model/query/RoleQuery.java +++ b/continew-admin-system/src/main/java/top/continew/admin/system/model/query/RoleQuery.java @@ -43,10 +43,4 @@ public class RoleQuery implements Serializable { @Schema(description = "关键词", example = "测试人员") @Query(columns = {"name", "code", "description"}, type = QueryType.LIKE) private String name; - - /** - * 状态 - */ - @Schema(description = "状态(1:启用;2:禁用)", example = "1") - private Integer status; } diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/model/req/RoleReq.java b/continew-admin-system/src/main/java/top/continew/admin/system/model/req/RoleReq.java index 6fce13f5..41c39515 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/system/model/req/RoleReq.java +++ b/continew-admin-system/src/main/java/top/continew/admin/system/model/req/RoleReq.java @@ -24,7 +24,6 @@ import org.hibernate.validator.constraints.Length; import top.continew.admin.common.constant.RegexConstants; import top.continew.admin.common.enums.DataScopeEnum; -import top.continew.admin.common.enums.DisEnableStatusEnum; import top.continew.starter.extension.crud.model.req.BaseReq; import java.io.Serial; @@ -92,10 +91,4 @@ public class RoleReq extends BaseReq { */ @Schema(description = "权限范围:部门 ID 列表", example = "5") private List deptIds = new ArrayList<>(); - - /** - * 状态 - */ - @Schema(description = "状态(1:启用;2:禁用)", type = "Integer", allowableValues = {"1", "2"}, example = "1") - private DisEnableStatusEnum status; } diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/model/resp/RoleDetailResp.java b/continew-admin-system/src/main/java/top/continew/admin/system/model/resp/RoleDetailResp.java index 5fc157ff..ef109ed9 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/system/model/resp/RoleDetailResp.java +++ b/continew-admin-system/src/main/java/top/continew/admin/system/model/resp/RoleDetailResp.java @@ -24,7 +24,6 @@ import lombok.Data; import top.continew.admin.common.constant.ContainerConstants; import top.continew.admin.common.enums.DataScopeEnum; -import top.continew.admin.common.enums.DisEnableStatusEnum; import top.continew.starter.extension.crud.converter.ExcelBaseEnumConverter; import top.continew.starter.extension.crud.model.resp.BaseDetailResp; @@ -75,13 +74,6 @@ public class RoleDetailResp extends BaseDetailResp { @ExcelProperty(value = "排序") private Integer sort; - /** - * 状态 - */ - @Schema(description = "状态(1:启用;2:禁用)", example = "1") - @ExcelProperty(value = "状态", converter = ExcelBaseEnumConverter.class) - private DisEnableStatusEnum status; - /** * 是否为系统内置数据 */ diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/model/resp/RoleResp.java b/continew-admin-system/src/main/java/top/continew/admin/system/model/resp/RoleResp.java index 0574b605..d437edd2 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/system/model/resp/RoleResp.java +++ b/continew-admin-system/src/main/java/top/continew/admin/system/model/resp/RoleResp.java @@ -19,7 +19,6 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import top.continew.admin.common.enums.DataScopeEnum; -import top.continew.admin.common.enums.DisEnableStatusEnum; import top.continew.starter.extension.crud.model.resp.BaseDetailResp; import java.io.Serial; @@ -62,12 +61,6 @@ public class RoleResp extends BaseDetailResp { @Schema(description = "排序", example = "1") private Integer sort; - /** - * 状态 - */ - @Schema(description = "状态(1:启用;2:禁用)", type = "Integer", allowableValues = {"1", "2"}, example = "1") - private DisEnableStatusEnum status; - /** * 是否为系统内置数据 */ diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/service/UserRoleService.java b/continew-admin-system/src/main/java/top/continew/admin/system/service/UserRoleService.java index bc0f4648..b0d4a0fa 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/system/service/UserRoleService.java +++ b/continew-admin-system/src/main/java/top/continew/admin/system/service/UserRoleService.java @@ -50,19 +50,11 @@ public interface UserRoleService { */ List listRoleIdByUserId(Long userId); - /** - * 根据角色 ID 列表查询 - * - * @param roleIds 角色 ID 列表 - * @return 总记录数 - */ - Long countByRoleIds(List roleIds); - /** * 根据角色 ID 判断是否已被用户关联 * - * @param roleId 角色 ID - * @return 是否已关联 + * @param roleIds 角色 ID 列表 + * @return true:已关联;false:未关联 */ - boolean isRoleIdExists(Long roleId); + boolean isRoleIdExists(List roleIds); } \ No newline at end of file diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/RoleServiceImpl.java b/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/RoleServiceImpl.java index 5c764072..4ea69954 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/RoleServiceImpl.java +++ b/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/RoleServiceImpl.java @@ -27,7 +27,6 @@ import top.continew.admin.common.constant.CacheConstants; import top.continew.admin.common.constant.SysConstants; import top.continew.admin.common.enums.DataScopeEnum; -import top.continew.admin.common.enums.DisEnableStatusEnum; import top.continew.admin.common.model.dto.RoleDTO; import top.continew.admin.common.model.resp.LabelValueResp; import top.continew.admin.system.mapper.RoleMapper; @@ -84,12 +83,8 @@ public void update(RoleReq req, Long id) { CheckUtils.throwIf(this.isNameExists(name, id), "修改失败,[{}] 已存在", name); RoleDO oldRole = super.getById(id); CheckUtils.throwIfNotEqual(req.getCode(), oldRole.getCode(), "角色编码不允许修改", oldRole.getName()); - CheckUtils.throwIf(DisEnableStatusEnum.DISABLE.equals(req.getStatus()) && userRoleService - .isRoleIdExists(id), "所选角色存在用户关联,请解除关联后重试"); DataScopeEnum oldDataScope = oldRole.getDataScope(); if (Boolean.TRUE.equals(oldRole.getIsSystem())) { - CheckUtils.throwIfEqual(DisEnableStatusEnum.DISABLE, req.getStatus(), "[{}] 是系统内置角色,不允许禁用", oldRole - .getName()); CheckUtils.throwIfNotEqual(req.getDataScope(), oldDataScope, "[{}] 是系统内置角色,不允许修改角色数据权限", oldRole.getName()); } // 更新信息 @@ -116,7 +111,7 @@ protected void beforeDelete(List ids) { Optional isSystemData = list.stream().filter(RoleDO::getIsSystem).findFirst(); CheckUtils.throwIf(isSystemData::isPresent, "所选角色 [{}] 是系统内置角色,不允许删除", isSystemData.orElseGet(RoleDO::new) .getName()); - CheckUtils.throwIf(userRoleService.countByRoleIds(ids) > 0, "所选角色存在用户关联,请解除关联后重试"); + CheckUtils.throwIf(userRoleService.isRoleIdExists(ids), "所选角色存在用户关联,请解除关联后重试"); // 删除角色和菜单关联 roleMenuService.deleteByRoleIds(ids); // 删除角色和部门关联 @@ -143,9 +138,7 @@ public List> buildDict(List list) { if (CollUtil.isEmpty(list)) { return new ArrayList<>(0); } - return list.stream() - .map(r -> new LabelValueResp<>(r.getName(), r.getId(), DisEnableStatusEnum.DISABLE.equals(r.getStatus()))) - .toList(); + return list.stream().map(r -> new LabelValueResp<>(r.getName(), r.getId())).toList(); } @Override diff --git a/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/UserRoleServiceImpl.java b/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/UserRoleServiceImpl.java index fa6a0612..6efd9a1c 100644 --- a/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/UserRoleServiceImpl.java +++ b/continew-admin-system/src/main/java/top/continew/admin/system/service/impl/UserRoleServiceImpl.java @@ -75,12 +75,7 @@ public List listRoleIdByUserId(Long userId) { } @Override - public Long countByRoleIds(List roleIds) { - return userRoleMapper.lambdaQuery().in(UserRoleDO::getRoleId, roleIds).count(); - } - - @Override - public boolean isRoleIdExists(Long roleId) { - return userRoleMapper.lambdaQuery().eq(UserRoleDO::getRoleId, roleId).exists(); + public boolean isRoleIdExists(List roleIds) { + return userRoleMapper.lambdaQuery().in(UserRoleDO::getRoleId, roleIds).exists(); } } diff --git a/continew-admin-system/src/main/resources/mapper/MenuMapper.xml b/continew-admin-system/src/main/resources/mapper/MenuMapper.xml index 2fc647d6..50d60cf6 100644 --- a/continew-admin-system/src/main/resources/mapper/MenuMapper.xml +++ b/continew-admin-system/src/main/resources/mapper/MenuMapper.xml @@ -11,7 +11,6 @@ WHERE t5.id = #{userId} AND t1.status = 1 AND t1.permission IS NOT NULL - AND t3.status = 1 \ No newline at end of file diff --git a/continew-admin-webapi/src/main/resources/db/changelog/mysql/continew-admin_data.sql b/continew-admin-webapi/src/main/resources/db/changelog/mysql/continew-admin_data.sql index 4de1546a..e60eaa66 100644 --- a/continew-admin-webapi/src/main/resources/db/changelog/mysql/continew-admin_data.sql +++ b/continew-admin-webapi/src/main/resources/db/changelog/mysql/continew-admin_data.sql @@ -93,10 +93,10 @@ VALUES -- 初始化默认角色 INSERT INTO `sys_role` -(`id`, `name`, `code`, `data_scope`, `description`, `sort`, `status`, `is_system`, `create_user`, `create_time`, `update_user`, `update_time`) +(`id`, `name`, `code`, `data_scope`, `description`, `sort`, `is_system`, `create_user`, `create_time`, `update_user`, `update_time`) VALUES -(1, '系统管理员', 'admin', 1, '系统初始角色', 1, 1, b'1', 1, NOW(), NULL, NULL), -(547888897925840928, '测试人员', 'test', 5, NULL, 2, 1, b'0', 1, NOW(), NULL, NULL); +(1, '系统管理员', 'admin', 1, '系统初始角色', 1, b'1', 1, NOW(), NULL, NULL), +(547888897925840928, '测试人员', 'test', 5, NULL, 2, b'0', 1, NOW(), NULL, NULL); -- 初始化默认用户:admin/admin123;test/123456 INSERT INTO `sys_user` diff --git a/continew-admin-webapi/src/main/resources/db/changelog/mysql/continew-admin_table.sql b/continew-admin-webapi/src/main/resources/db/changelog/mysql/continew-admin_table.sql index c01dddec..0172d2a8 100644 --- a/continew-admin-webapi/src/main/resources/db/changelog/mysql/continew-admin_table.sql +++ b/continew-admin-webapi/src/main/resources/db/changelog/mysql/continew-admin_table.sql @@ -56,7 +56,6 @@ CREATE TABLE IF NOT EXISTS `sys_role` ( `data_scope` tinyint(1) NOT NULL DEFAULT 4 COMMENT '数据权限(1:全部数据权限;2:本部门及以下数据权限;3:本部门数据权限;4:仅本人数据权限;5:自定义数据权限)', `description` varchar(200) DEFAULT NULL COMMENT '描述', `sort` int NOT NULL DEFAULT 999 COMMENT '排序', - `status` tinyint(1) UNSIGNED NOT NULL DEFAULT 1 COMMENT '状态(1:启用;2:禁用)', `is_system` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否为系统内置数据', `create_user` bigint(20) NOT NULL COMMENT '创建人', `create_time` datetime NOT NULL COMMENT '创建时间', diff --git a/continew-admin-webapi/src/main/resources/db/changelog/postgresql/continew-admin_data.sql b/continew-admin-webapi/src/main/resources/db/changelog/postgresql/continew-admin_data.sql index f3a852f6..3828af7b 100644 --- a/continew-admin-webapi/src/main/resources/db/changelog/postgresql/continew-admin_data.sql +++ b/continew-admin-webapi/src/main/resources/db/changelog/postgresql/continew-admin_data.sql @@ -93,10 +93,10 @@ VALUES -- 初始化默认角色 INSERT INTO "sys_role" -("id", "name", "code", "data_scope", "description", "sort", "status", "is_system", "create_user", "create_time", "update_user", "update_time") +("id", "name", "code", "data_scope", "description", "sort", "is_system", "create_user", "create_time", "update_user", "update_time") VALUES -(1, '系统管理员', 'admin', 1, '系统初始角色', 1, 1, true, 1, NOW(), NULL, NULL), -(547888897925840928, '测试人员', 'test', 5, NULL, 2, 1, false, 1, NOW(), NULL, NULL); +(1, '系统管理员', 'admin', 1, '系统初始角色', 1, true, 1, NOW(), NULL, NULL), +(547888897925840928, '测试人员', 'test', 5, NULL, 2, false, 1, NOW(), NULL, NULL); -- 初始化默认用户:admin/admin123;test/123456 INSERT INTO "sys_user" diff --git a/continew-admin-webapi/src/main/resources/db/changelog/postgresql/continew-admin_table.sql b/continew-admin-webapi/src/main/resources/db/changelog/postgresql/continew-admin_table.sql index c456d161..4d6bad3d 100644 --- a/continew-admin-webapi/src/main/resources/db/changelog/postgresql/continew-admin_table.sql +++ b/continew-admin-webapi/src/main/resources/db/changelog/postgresql/continew-admin_table.sql @@ -89,7 +89,6 @@ CREATE TABLE IF NOT EXISTS "sys_role" ( "data_scope" int2 NOT NULL DEFAULT 4, "description" varchar(200) DEFAULT NULL, "sort" int4 NOT NULL DEFAULT 999, - "status" int2 NOT NULL DEFAULT 1, "is_system" bool NOT NULL DEFAULT false, "create_user" int8 NOT NULL, "create_time" timestamp NOT NULL, @@ -107,7 +106,6 @@ COMMENT ON COLUMN "sys_role"."code" IS '编码'; COMMENT ON COLUMN "sys_role"."data_scope" IS '数据权限(1:全部数据权限;2:本部门及以下数据权限;3:本部门数据权限;4:仅本人数据权限;5:自定义数据权限)'; COMMENT ON COLUMN "sys_role"."description" IS '描述'; COMMENT ON COLUMN "sys_role"."sort" IS '排序'; -COMMENT ON COLUMN "sys_role"."status" IS '状态(1:启用;2:禁用)'; COMMENT ON COLUMN "sys_role"."is_system" IS '是否为系统内置数据'; COMMENT ON COLUMN "sys_role"."create_user" IS '创建人'; COMMENT ON COLUMN "sys_role"."create_time" IS '创建时间';