mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-09 20:57:21 +08:00
refactor: 移除角色状态字段
This commit is contained in:
@@ -19,7 +19,6 @@ package top.continew.admin.system.model.entity;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 是否为系统内置数据
|
||||
*/
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -24,7 +24,6 @@ import lombok.Data;
|
||||
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<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 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;
|
||||
|
||||
/**
|
||||
* 是否为系统内置数据
|
||||
*/
|
||||
|
@@ -19,7 +19,6 @@ package top.continew.admin.system.model.resp;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 是否为系统内置数据
|
||||
*/
|
||||
|
@@ -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);
|
||||
}
|
@@ -27,7 +27,6 @@ import top.continew.admin.auth.service.OnlineUserService;
|
||||
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 class RoleServiceImpl extends BaseServiceImpl<RoleMapper, RoleDO, RoleRes
|
||||
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 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, RoleDO, RoleRes
|
||||
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);
|
||||
// 删除角色和部门关联
|
||||
@@ -143,9 +138,7 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, RoleDO, RoleRes
|
||||
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
|
||||
|
@@ -75,12 +75,7 @@ public class UserRoleServiceImpl implements UserRoleService {
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
@@ -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">
|
||||
@@ -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>
|
Reference in New Issue
Block a user