feat(admin): add admin role type management

1. 新增后台角色类型枚举AdminRoleTypeEnum
2. 为AdminRole实体添加角色类型字段并设置默认值
3. 新增/更新管理员角色相关DTO的角色类型属性
4. 完善权限服务中的角色增删改查逻辑,增加系统角色保护校验
5. 修复任务消费中角色类型存储为枚举字符串的问题,改为存储枚举值
6. 新增初始化角色类型的SQL脚本
This commit is contained in:
glz
2026-07-08 09:55:17 +08:00
parent a64d1b459a
commit a8b19cbacc
5 changed files with 61 additions and 3 deletions

View File

@ -128,6 +128,7 @@ public class AdminPermissionService(
{
Name = input.Name.Trim(),
Code = input.Code.Trim(),
Type = input.Type,
Remark = input.Remark?.Trim(),
Status = input.Status,
CreatedBy = "System",
@ -157,9 +158,11 @@ public class AdminPermissionService(
BusinessException.ThrowIf(role == null, "角色不存在", ResultCode.NOT_FOUND);
await ValidateRoleInputAsync(input, id);
BusinessException.ThrowIf(role!.Type == AdminRoleTypeEnum.System && input.Type != AdminRoleTypeEnum.System, "系统角色不能修改为普通角色", ResultCode.FORBIDDEN);
role!.Name = input.Name.Trim();
role.Name = input.Name.Trim();
role.Code = input.Code.Trim();
role.Type = input.Type;
role.Remark = input.Remark?.Trim();
role.Status = input.Status;
role.UpdatedBy = "System";
@ -182,6 +185,7 @@ public class AdminPermissionService(
public async Task DeleteRoleAsync(long id)
{
var role = await adminRoleRepository.GetByIdAsync(id);
BusinessException.ThrowIf(role?.Type == AdminRoleTypeEnum.System, "系统角色不允许删除", ResultCode.FORBIDDEN);
BusinessException.ThrowIf(role == null, "角色不存在", ResultCode.NOT_FOUND);
var usedByUser = await adminUserRoleRepository.Queryable().AnyAsync(x => x.RoleId == id && !x.IsDeleted);
@ -221,6 +225,7 @@ public class AdminPermissionService(
.Where(x => !x.IsDeleted)
.WhereIF(!string.IsNullOrWhiteSpace(input.Name), x => x.Name.Contains(input.Name!))
.WhereIF(!string.IsNullOrWhiteSpace(input.Code), x => x.Code.Contains(input.Code!))
.WhereIF(input.Type.HasValue, x => x.Type == input.Type!.Value)
.WhereIF(input.Status.HasValue, x => x.Status == input.Status!.Value)
.OrderByDescending(x => x.CreatedAt)
.ToPageListAsync(input.PageIndex, input.PageSize, totalNumber);
@ -283,7 +288,8 @@ public class AdminPermissionService(
{
Id = role.Id,
Name = role.Name,
Code = role.Code
Code = role.Code,
Type = role.Type
})
.ToListAsync();
}
@ -490,6 +496,7 @@ public class AdminPermissionService(
Id = role.Id,
Name = role.Name,
Code = role.Code,
Type = role.Type,
Remark = role.Remark,
Status = role.Status,
MenuIds = menuIds,