refactor: 移除角色状态字段
This commit is contained in:
parent
dbe93df8bc
commit
e89ba7d5cd
@ -19,7 +19,6 @@ package top.continew.admin.system.model.entity;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import top.continew.admin.common.enums.DataScopeEnum;
|
import top.continew.admin.common.enums.DataScopeEnum;
|
||||||
import top.continew.admin.common.enums.DisEnableStatusEnum;
|
|
||||||
import top.continew.starter.extension.crud.model.entity.BaseDO;
|
import top.continew.starter.extension.crud.model.entity.BaseDO;
|
||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
@ -62,11 +61,6 @@ public class RoleDO extends BaseDO {
|
|||||||
*/
|
*/
|
||||||
private Integer sort;
|
private Integer sort;
|
||||||
|
|
||||||
/**
|
|
||||||
* 状态
|
|
||||||
*/
|
|
||||||
private DisEnableStatusEnum status;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否为系统内置数据
|
* 是否为系统内置数据
|
||||||
*/
|
*/
|
||||||
|
@ -43,10 +43,4 @@ public class RoleQuery implements Serializable {
|
|||||||
@Schema(description = "关键词", example = "测试人员")
|
@Schema(description = "关键词", example = "测试人员")
|
||||||
@Query(columns = {"name", "code", "description"}, type = QueryType.LIKE)
|
@Query(columns = {"name", "code", "description"}, type = QueryType.LIKE)
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
/**
|
|
||||||
* 状态
|
|
||||||
*/
|
|
||||||
@Schema(description = "状态(1:启用;2:禁用)", example = "1")
|
|
||||||
private Integer status;
|
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@ import lombok.Data;
|
|||||||
import org.hibernate.validator.constraints.Length;
|
import org.hibernate.validator.constraints.Length;
|
||||||
import top.continew.admin.common.constant.RegexConstants;
|
import top.continew.admin.common.constant.RegexConstants;
|
||||||
import top.continew.admin.common.enums.DataScopeEnum;
|
import top.continew.admin.common.enums.DataScopeEnum;
|
||||||
import top.continew.admin.common.enums.DisEnableStatusEnum;
|
|
||||||
import top.continew.starter.extension.crud.model.req.BaseReq;
|
import top.continew.starter.extension.crud.model.req.BaseReq;
|
||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
@ -92,10 +91,4 @@ public class RoleReq extends BaseReq {
|
|||||||
*/
|
*/
|
||||||
@Schema(description = "权限范围:部门 ID 列表", example = "5")
|
@Schema(description = "权限范围:部门 ID 列表", example = "5")
|
||||||
private List<Long> deptIds = new ArrayList<>();
|
private List<Long> deptIds = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
|
||||||
* 状态
|
|
||||||
*/
|
|
||||||
@Schema(description = "状态(1:启用;2:禁用)", type = "Integer", allowableValues = {"1", "2"}, example = "1")
|
|
||||||
private DisEnableStatusEnum status;
|
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import top.continew.admin.common.constant.ContainerConstants;
|
import top.continew.admin.common.constant.ContainerConstants;
|
||||||
import top.continew.admin.common.enums.DataScopeEnum;
|
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.converter.ExcelBaseEnumConverter;
|
||||||
import top.continew.starter.extension.crud.model.resp.BaseDetailResp;
|
import top.continew.starter.extension.crud.model.resp.BaseDetailResp;
|
||||||
|
|
||||||
@ -75,13 +74,6 @@ public class RoleDetailResp extends BaseDetailResp {
|
|||||||
@ExcelProperty(value = "排序")
|
@ExcelProperty(value = "排序")
|
||||||
private Integer sort;
|
private Integer sort;
|
||||||
|
|
||||||
/**
|
|
||||||
* 状态
|
|
||||||
*/
|
|
||||||
@Schema(description = "状态(1:启用;2:禁用)", example = "1")
|
|
||||||
@ExcelProperty(value = "状态", converter = ExcelBaseEnumConverter.class)
|
|
||||||
private DisEnableStatusEnum status;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否为系统内置数据
|
* 是否为系统内置数据
|
||||||
*/
|
*/
|
||||||
|
@ -19,7 +19,6 @@ package top.continew.admin.system.model.resp;
|
|||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import top.continew.admin.common.enums.DataScopeEnum;
|
import top.continew.admin.common.enums.DataScopeEnum;
|
||||||
import top.continew.admin.common.enums.DisEnableStatusEnum;
|
|
||||||
import top.continew.starter.extension.crud.model.resp.BaseDetailResp;
|
import top.continew.starter.extension.crud.model.resp.BaseDetailResp;
|
||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
@ -62,12 +61,6 @@ public class RoleResp extends BaseDetailResp {
|
|||||||
@Schema(description = "排序", example = "1")
|
@Schema(description = "排序", example = "1")
|
||||||
private Integer sort;
|
private Integer sort;
|
||||||
|
|
||||||
/**
|
|
||||||
* 状态
|
|
||||||
*/
|
|
||||||
@Schema(description = "状态(1:启用;2:禁用)", type = "Integer", allowableValues = {"1", "2"}, example = "1")
|
|
||||||
private DisEnableStatusEnum status;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否为系统内置数据
|
* 是否为系统内置数据
|
||||||
*/
|
*/
|
||||||
|
@ -50,19 +50,11 @@ public interface UserRoleService {
|
|||||||
*/
|
*/
|
||||||
List<Long> listRoleIdByUserId(Long userId);
|
List<Long> listRoleIdByUserId(Long userId);
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据角色 ID 列表查询
|
|
||||||
*
|
|
||||||
* @param roleIds 角色 ID 列表
|
|
||||||
* @return 总记录数
|
|
||||||
*/
|
|
||||||
Long countByRoleIds(List<Long> roleIds);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据角色 ID 判断是否已被用户关联
|
* 根据角色 ID 判断是否已被用户关联
|
||||||
*
|
*
|
||||||
* @param roleId 角色 ID
|
* @param roleIds 角色 ID 列表
|
||||||
* @return 是否已关联
|
* @return true:已关联;false:未关联
|
||||||
*/
|
*/
|
||||||
boolean isRoleIdExists(Long roleId);
|
boolean isRoleIdExists(List<Long> roleIds);
|
||||||
}
|
}
|
@ -27,7 +27,6 @@ import top.continew.admin.auth.service.OnlineUserService;
|
|||||||
import top.continew.admin.common.constant.CacheConstants;
|
import top.continew.admin.common.constant.CacheConstants;
|
||||||
import top.continew.admin.common.constant.SysConstants;
|
import top.continew.admin.common.constant.SysConstants;
|
||||||
import top.continew.admin.common.enums.DataScopeEnum;
|
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.dto.RoleDTO;
|
||||||
import top.continew.admin.common.model.resp.LabelValueResp;
|
import top.continew.admin.common.model.resp.LabelValueResp;
|
||||||
import top.continew.admin.system.mapper.RoleMapper;
|
import top.continew.admin.system.mapper.RoleMapper;
|
||||||
@ -84,12 +83,8 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, RoleDO, RoleRes
|
|||||||
CheckUtils.throwIf(this.isNameExists(name, id), "修改失败,[{}] 已存在", name);
|
CheckUtils.throwIf(this.isNameExists(name, id), "修改失败,[{}] 已存在", name);
|
||||||
RoleDO oldRole = super.getById(id);
|
RoleDO oldRole = super.getById(id);
|
||||||
CheckUtils.throwIfNotEqual(req.getCode(), oldRole.getCode(), "角色编码不允许修改", oldRole.getName());
|
CheckUtils.throwIfNotEqual(req.getCode(), oldRole.getCode(), "角色编码不允许修改", oldRole.getName());
|
||||||
CheckUtils.throwIf(DisEnableStatusEnum.DISABLE.equals(req.getStatus()) && userRoleService
|
|
||||||
.isRoleIdExists(id), "所选角色存在用户关联,请解除关联后重试");
|
|
||||||
DataScopeEnum oldDataScope = oldRole.getDataScope();
|
DataScopeEnum oldDataScope = oldRole.getDataScope();
|
||||||
if (Boolean.TRUE.equals(oldRole.getIsSystem())) {
|
if (Boolean.TRUE.equals(oldRole.getIsSystem())) {
|
||||||
CheckUtils.throwIfEqual(DisEnableStatusEnum.DISABLE, req.getStatus(), "[{}] 是系统内置角色,不允许禁用", oldRole
|
|
||||||
.getName());
|
|
||||||
CheckUtils.throwIfNotEqual(req.getDataScope(), oldDataScope, "[{}] 是系统内置角色,不允许修改角色数据权限", oldRole.getName());
|
CheckUtils.throwIfNotEqual(req.getDataScope(), oldDataScope, "[{}] 是系统内置角色,不允许修改角色数据权限", oldRole.getName());
|
||||||
}
|
}
|
||||||
// 更新信息
|
// 更新信息
|
||||||
@ -116,7 +111,7 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, RoleDO, RoleRes
|
|||||||
Optional<RoleDO> isSystemData = list.stream().filter(RoleDO::getIsSystem).findFirst();
|
Optional<RoleDO> isSystemData = list.stream().filter(RoleDO::getIsSystem).findFirst();
|
||||||
CheckUtils.throwIf(isSystemData::isPresent, "所选角色 [{}] 是系统内置角色,不允许删除", isSystemData.orElseGet(RoleDO::new)
|
CheckUtils.throwIf(isSystemData::isPresent, "所选角色 [{}] 是系统内置角色,不允许删除", isSystemData.orElseGet(RoleDO::new)
|
||||||
.getName());
|
.getName());
|
||||||
CheckUtils.throwIf(userRoleService.countByRoleIds(ids) > 0, "所选角色存在用户关联,请解除关联后重试");
|
CheckUtils.throwIf(userRoleService.isRoleIdExists(ids), "所选角色存在用户关联,请解除关联后重试");
|
||||||
// 删除角色和菜单关联
|
// 删除角色和菜单关联
|
||||||
roleMenuService.deleteByRoleIds(ids);
|
roleMenuService.deleteByRoleIds(ids);
|
||||||
// 删除角色和部门关联
|
// 删除角色和部门关联
|
||||||
@ -143,9 +138,7 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, RoleDO, RoleRes
|
|||||||
if (CollUtil.isEmpty(list)) {
|
if (CollUtil.isEmpty(list)) {
|
||||||
return new ArrayList<>(0);
|
return new ArrayList<>(0);
|
||||||
}
|
}
|
||||||
return list.stream()
|
return list.stream().map(r -> new LabelValueResp<>(r.getName(), r.getId())).toList();
|
||||||
.map(r -> new LabelValueResp<>(r.getName(), r.getId(), DisEnableStatusEnum.DISABLE.equals(r.getStatus())))
|
|
||||||
.toList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -75,12 +75,7 @@ public class UserRoleServiceImpl implements UserRoleService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long countByRoleIds(List<Long> roleIds) {
|
public boolean isRoleIdExists(List<Long> roleIds) {
|
||||||
return userRoleMapper.lambdaQuery().in(UserRoleDO::getRoleId, roleIds).count();
|
return userRoleMapper.lambdaQuery().in(UserRoleDO::getRoleId, roleIds).exists();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isRoleIdExists(Long roleId) {
|
|
||||||
return userRoleMapper.lambdaQuery().eq(UserRoleDO::getRoleId, roleId).exists();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
WHERE t5.id = #{userId}
|
WHERE t5.id = #{userId}
|
||||||
AND t1.status = 1
|
AND t1.status = 1
|
||||||
AND t1.permission IS NOT NULL
|
AND t1.permission IS NOT NULL
|
||||||
AND t3.status = 1
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectListByRoleCode" resultType="top.continew.admin.system.model.entity.MenuDO">
|
<select id="selectListByRoleCode" resultType="top.continew.admin.system.model.entity.MenuDO">
|
||||||
@ -21,6 +20,5 @@
|
|||||||
LEFT JOIN sys_role AS t3 ON t3.id = t2.role_id
|
LEFT JOIN sys_role AS t3 ON t3.id = t2.role_id
|
||||||
WHERE t3.code = #{roleCode}
|
WHERE t3.code = #{roleCode}
|
||||||
AND t1.status = 1
|
AND t1.status = 1
|
||||||
AND t3.status = 1
|
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
@ -93,10 +93,10 @@ VALUES
|
|||||||
|
|
||||||
-- 初始化默认角色
|
-- 初始化默认角色
|
||||||
INSERT INTO `sys_role`
|
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
|
VALUES
|
||||||
(1, '系统管理员', 'admin', 1, '系统初始角色', 1, 1, b'1', 1, NOW(), NULL, NULL),
|
(1, '系统管理员', 'admin', 1, '系统初始角色', 1, b'1', 1, NOW(), NULL, NULL),
|
||||||
(547888897925840928, '测试人员', 'test', 5, NULL, 2, 1, b'0', 1, NOW(), NULL, NULL);
|
(547888897925840928, '测试人员', 'test', 5, NULL, 2, b'0', 1, NOW(), NULL, NULL);
|
||||||
|
|
||||||
-- 初始化默认用户:admin/admin123;test/123456
|
-- 初始化默认用户:admin/admin123;test/123456
|
||||||
INSERT INTO `sys_user`
|
INSERT INTO `sys_user`
|
||||||
|
@ -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:自定义数据权限)',
|
`data_scope` tinyint(1) NOT NULL DEFAULT 4 COMMENT '数据权限(1:全部数据权限;2:本部门及以下数据权限;3:本部门数据权限;4:仅本人数据权限;5:自定义数据权限)',
|
||||||
`description` varchar(200) DEFAULT NULL COMMENT '描述',
|
`description` varchar(200) DEFAULT NULL COMMENT '描述',
|
||||||
`sort` int NOT NULL DEFAULT 999 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 '是否为系统内置数据',
|
`is_system` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否为系统内置数据',
|
||||||
`create_user` bigint(20) NOT NULL COMMENT '创建人',
|
`create_user` bigint(20) NOT NULL COMMENT '创建人',
|
||||||
`create_time` datetime NOT NULL COMMENT '创建时间',
|
`create_time` datetime NOT NULL COMMENT '创建时间',
|
||||||
|
@ -93,10 +93,10 @@ VALUES
|
|||||||
|
|
||||||
-- 初始化默认角色
|
-- 初始化默认角色
|
||||||
INSERT INTO "sys_role"
|
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
|
VALUES
|
||||||
(1, '系统管理员', 'admin', 1, '系统初始角色', 1, 1, true, 1, NOW(), NULL, NULL),
|
(1, '系统管理员', 'admin', 1, '系统初始角色', 1, true, 1, NOW(), NULL, NULL),
|
||||||
(547888897925840928, '测试人员', 'test', 5, NULL, 2, 1, false, 1, NOW(), NULL, NULL);
|
(547888897925840928, '测试人员', 'test', 5, NULL, 2, false, 1, NOW(), NULL, NULL);
|
||||||
|
|
||||||
-- 初始化默认用户:admin/admin123;test/123456
|
-- 初始化默认用户:admin/admin123;test/123456
|
||||||
INSERT INTO "sys_user"
|
INSERT INTO "sys_user"
|
||||||
|
@ -89,7 +89,6 @@ CREATE TABLE IF NOT EXISTS "sys_role" (
|
|||||||
"data_scope" int2 NOT NULL DEFAULT 4,
|
"data_scope" int2 NOT NULL DEFAULT 4,
|
||||||
"description" varchar(200) DEFAULT NULL,
|
"description" varchar(200) DEFAULT NULL,
|
||||||
"sort" int4 NOT NULL DEFAULT 999,
|
"sort" int4 NOT NULL DEFAULT 999,
|
||||||
"status" int2 NOT NULL DEFAULT 1,
|
|
||||||
"is_system" bool NOT NULL DEFAULT false,
|
"is_system" bool NOT NULL DEFAULT false,
|
||||||
"create_user" int8 NOT NULL,
|
"create_user" int8 NOT NULL,
|
||||||
"create_time" timestamp 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"."data_scope" IS '数据权限(1:全部数据权限;2:本部门及以下数据权限;3:本部门数据权限;4:仅本人数据权限;5:自定义数据权限)';
|
||||||
COMMENT ON COLUMN "sys_role"."description" IS '描述';
|
COMMENT ON COLUMN "sys_role"."description" IS '描述';
|
||||||
COMMENT ON COLUMN "sys_role"."sort" 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"."is_system" IS '是否为系统内置数据';
|
||||||
COMMENT ON COLUMN "sys_role"."create_user" IS '创建人';
|
COMMENT ON COLUMN "sys_role"."create_user" IS '创建人';
|
||||||
COMMENT ON COLUMN "sys_role"."create_time" IS '创建时间';
|
COMMENT ON COLUMN "sys_role"."create_time" IS '创建时间';
|
||||||
|
Loading…
Reference in New Issue
Block a user