Skip to content

Commit

Permalink
refactor: 移除角色状态字段
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Apr 27, 2024
1 parent dbe93df commit e89ba7d
Show file tree
Hide file tree
Showing 13 changed files with 13 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,11 +61,6 @@ public class RoleDO extends BaseDO {
*/
private Integer sort;

/**
* 状态
*/
private DisEnableStatusEnum status;

/**
* 是否为系统内置数据
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -92,10 +91,4 @@ public class RoleReq extends BaseReq {
*/
@Schema(description = "权限范围:部门 ID 列表", example = "5")
private List<Long> deptIds = new ArrayList<>();

/**
* 状态
*/
@Schema(description = "状态(1:启用;2:禁用)", type = "Integer", allowableValues = {"1", "2"}, example = "1")
private DisEnableStatusEnum status;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

/**
* 是否为系统内置数据
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

/**
* 是否为系统内置数据
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,11 @@ public interface UserRoleService {
*/
List<Long> listRoleIdByUserId(Long userId);

/**
* 根据角色 ID 列表查询
*
* @param roleIds 角色 ID 列表
* @return 总记录数
*/
Long countByRoleIds(List<Long> roleIds);

/**
* 根据角色 ID 判断是否已被用户关联
*
* @param roleId 角色 ID
* @return 是否已关联
* @param roleIds 角色 ID 列表
* @return true:已关联;false:未关联
*/
boolean isRoleIdExists(Long roleId);
boolean isRoleIdExists(List<Long> roleIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
// 更新信息
Expand All @@ -116,7 +111,7 @@ protected void beforeDelete(List<Long> ids) {
Optional<RoleDO> 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);
// 删除角色和部门关联
Expand All @@ -143,9 +138,7 @@ public List<LabelValueResp<Long>> buildDict(List<RoleResp> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,7 @@ public List<Long> listRoleIdByUserId(Long userId) {
}

@Override
public Long countByRoleIds(List<Long> 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<Long> roleIds) {
return userRoleMapper.lambdaQuery().in(UserRoleDO::getRoleId, roleIds).exists();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
WHERE t5.id = #{userId}
AND t1.status = 1
AND t1.permission IS NOT NULL
AND t3.status = 1
</select>

<select id="selectListByRoleCode" resultType="top.continew.admin.system.model.entity.MenuDO">
Expand All @@ -21,6 +20,5 @@
LEFT JOIN sys_role AS t3 ON t3.id = t2.role_id
WHERE t3.code = #{roleCode}
AND t1.status = 1
AND t3.status = 1
</select>
</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 '创建时间',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 '创建时间';
Expand Down

0 comments on commit e89ba7d

Please sign in to comment.