feat(admin): add admin role type management
1. 新增后台角色类型枚举AdminRoleTypeEnum 2. 为AdminRole实体添加角色类型字段并设置默认值 3. 新增/更新管理员角色相关DTO的角色类型属性 4. 完善权限服务中的角色增删改查逻辑,增加系统角色保护校验 5. 修复任务消费中角色类型存储为枚举字符串的问题,改为存储枚举值 6. 新增初始化角色类型的SQL脚本
This commit is contained in:
@ -1,3 +1,5 @@
|
|||||||
|
using QYZH.InteractiveMagazine.Models.Enum;
|
||||||
|
|
||||||
namespace QYZH.InteractiveMagazine.Models.Dto;
|
namespace QYZH.InteractiveMagazine.Models.Dto;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -148,6 +150,11 @@ public class AdminRoleInput
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string Code { get; set; } = string.Empty;
|
public string Code { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 角色类型
|
||||||
|
/// </summary>
|
||||||
|
public AdminRoleTypeEnum Type { get; set; } = AdminRoleTypeEnum.Normal;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 备注
|
/// 备注
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -184,6 +191,11 @@ public class AdminRoleOutput
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string Code { get; set; } = string.Empty;
|
public string Code { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 角色类型
|
||||||
|
/// </summary>
|
||||||
|
public AdminRoleTypeEnum Type { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 备注
|
/// 备注
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -224,6 +236,11 @@ public class AdminRoleSimpleOutput
|
|||||||
/// 角色编码
|
/// 角色编码
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Code { get; set; } = string.Empty;
|
public string Code { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 角色类型
|
||||||
|
/// </summary>
|
||||||
|
public AdminRoleTypeEnum Type { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -241,6 +258,11 @@ public class AdminRoleQueryInput : PageQueryModel
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string? Code { get; set; }
|
public string? Code { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 角色类型
|
||||||
|
/// </summary>
|
||||||
|
public AdminRoleTypeEnum? Type { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 状态
|
/// 状态
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
|
using QYZH.InteractiveMagazine.Models.Enum;
|
||||||
|
|
||||||
namespace QYZH.InteractiveMagazine.Models.Entity;
|
namespace QYZH.InteractiveMagazine.Models.Entity;
|
||||||
|
|
||||||
@ -22,6 +23,13 @@ public partial class AdminRole : SqlSugarBaseEntity
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string Code { get; set; } = string.Empty;
|
public string Code { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Desc:角色类型,0=普通角色,1=系统角色
|
||||||
|
/// Default:0
|
||||||
|
/// Nullable:False
|
||||||
|
/// </summary>
|
||||||
|
public AdminRoleTypeEnum Type { get; set; } = AdminRoleTypeEnum.Normal;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Desc:备注
|
/// Desc:备注
|
||||||
/// Default:
|
/// Default:
|
||||||
|
|||||||
21
QYZH.InteractiveMagazine.Models/Enum/AdminRoleTypeEnum.cs
Normal file
21
QYZH.InteractiveMagazine.Models/Enum/AdminRoleTypeEnum.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace QYZH.InteractiveMagazine.Models.Enum;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 后台角色类型枚举
|
||||||
|
/// </summary>
|
||||||
|
public enum AdminRoleTypeEnum
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 普通角色
|
||||||
|
/// </summary>
|
||||||
|
[Description("普通角色")]
|
||||||
|
Normal = 0,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 系统角色
|
||||||
|
/// </summary>
|
||||||
|
[Description("系统角色")]
|
||||||
|
System = 1
|
||||||
|
}
|
||||||
@ -128,6 +128,7 @@ public class AdminPermissionService(
|
|||||||
{
|
{
|
||||||
Name = input.Name.Trim(),
|
Name = input.Name.Trim(),
|
||||||
Code = input.Code.Trim(),
|
Code = input.Code.Trim(),
|
||||||
|
Type = input.Type,
|
||||||
Remark = input.Remark?.Trim(),
|
Remark = input.Remark?.Trim(),
|
||||||
Status = input.Status,
|
Status = input.Status,
|
||||||
CreatedBy = "System",
|
CreatedBy = "System",
|
||||||
@ -157,9 +158,11 @@ public class AdminPermissionService(
|
|||||||
BusinessException.ThrowIf(role == null, "角色不存在", ResultCode.NOT_FOUND);
|
BusinessException.ThrowIf(role == null, "角色不存在", ResultCode.NOT_FOUND);
|
||||||
|
|
||||||
await ValidateRoleInputAsync(input, id);
|
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.Code = input.Code.Trim();
|
||||||
|
role.Type = input.Type;
|
||||||
role.Remark = input.Remark?.Trim();
|
role.Remark = input.Remark?.Trim();
|
||||||
role.Status = input.Status;
|
role.Status = input.Status;
|
||||||
role.UpdatedBy = "System";
|
role.UpdatedBy = "System";
|
||||||
@ -182,6 +185,7 @@ public class AdminPermissionService(
|
|||||||
public async Task DeleteRoleAsync(long id)
|
public async Task DeleteRoleAsync(long id)
|
||||||
{
|
{
|
||||||
var role = await adminRoleRepository.GetByIdAsync(id);
|
var role = await adminRoleRepository.GetByIdAsync(id);
|
||||||
|
BusinessException.ThrowIf(role?.Type == AdminRoleTypeEnum.System, "系统角色不允许删除", ResultCode.FORBIDDEN);
|
||||||
BusinessException.ThrowIf(role == null, "角色不存在", ResultCode.NOT_FOUND);
|
BusinessException.ThrowIf(role == null, "角色不存在", ResultCode.NOT_FOUND);
|
||||||
|
|
||||||
var usedByUser = await adminUserRoleRepository.Queryable().AnyAsync(x => x.RoleId == id && !x.IsDeleted);
|
var usedByUser = await adminUserRoleRepository.Queryable().AnyAsync(x => x.RoleId == id && !x.IsDeleted);
|
||||||
@ -221,6 +225,7 @@ public class AdminPermissionService(
|
|||||||
.Where(x => !x.IsDeleted)
|
.Where(x => !x.IsDeleted)
|
||||||
.WhereIF(!string.IsNullOrWhiteSpace(input.Name), x => x.Name.Contains(input.Name!))
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Name), x => x.Name.Contains(input.Name!))
|
||||||
.WhereIF(!string.IsNullOrWhiteSpace(input.Code), x => x.Code.Contains(input.Code!))
|
.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)
|
.WhereIF(input.Status.HasValue, x => x.Status == input.Status!.Value)
|
||||||
.OrderByDescending(x => x.CreatedAt)
|
.OrderByDescending(x => x.CreatedAt)
|
||||||
.ToPageListAsync(input.PageIndex, input.PageSize, totalNumber);
|
.ToPageListAsync(input.PageIndex, input.PageSize, totalNumber);
|
||||||
@ -283,7 +288,8 @@ public class AdminPermissionService(
|
|||||||
{
|
{
|
||||||
Id = role.Id,
|
Id = role.Id,
|
||||||
Name = role.Name,
|
Name = role.Name,
|
||||||
Code = role.Code
|
Code = role.Code,
|
||||||
|
Type = role.Type
|
||||||
})
|
})
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
}
|
}
|
||||||
@ -490,6 +496,7 @@ public class AdminPermissionService(
|
|||||||
Id = role.Id,
|
Id = role.Id,
|
||||||
Name = role.Name,
|
Name = role.Name,
|
||||||
Code = role.Code,
|
Code = role.Code,
|
||||||
|
Type = role.Type,
|
||||||
Remark = role.Remark,
|
Remark = role.Remark,
|
||||||
Status = role.Status,
|
Status = role.Status,
|
||||||
MenuIds = menuIds,
|
MenuIds = menuIds,
|
||||||
|
|||||||
@ -963,7 +963,7 @@ public class JournalTaskReceiveConsumer(
|
|||||||
LastTag = 0,
|
LastTag = 0,
|
||||||
DotPageNum = page?.PageNum ?? 0,
|
DotPageNum = page?.PageNum ?? 0,
|
||||||
PageResultUrl = string.Empty,
|
PageResultUrl = string.Empty,
|
||||||
Type = task.Type.ToString(),
|
Type = ((int)task.Type).ToString(),
|
||||||
DotPageNo = page?.PageNo ?? string.Empty,
|
DotPageNo = page?.PageNo ?? string.Empty,
|
||||||
PageAnswerDotUrl = string.Empty,
|
PageAnswerDotUrl = string.Empty,
|
||||||
BreakCount = GetBreakCount(scoreUnit),
|
BreakCount = GetBreakCount(scoreUnit),
|
||||||
|
|||||||
Reference in New Issue
Block a user