2026-07-06 14:21:21 +08:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2026-07-09 18:01:37 +08:00
|
|
|
using QYZH.InteractiveMagazine.Infrastructure.Middleware;
|
2026-07-06 14:21:21 +08:00
|
|
|
using QYZH.InteractiveMagazine.IService;
|
|
|
|
|
using QYZH.InteractiveMagazine.Models.Common;
|
|
|
|
|
using QYZH.InteractiveMagazine.Models.Dto;
|
|
|
|
|
using QYZH.InteractiveMagazine.Models.Enum;
|
|
|
|
|
|
|
|
|
|
namespace QYZH.InteractiveMagazine.WebApi.Controllers;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 后台权限管理
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
[ApiExplorerSettings(GroupName = nameof(ApiVersionEnum.Platform))]
|
|
|
|
|
public class PermissionController(IAdminPermissionService adminPermissionService) : BaseController
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 创建菜单
|
|
|
|
|
/// </summary>
|
2026-07-09 18:01:37 +08:00
|
|
|
[OperationLog(OperationLogActionType.Create, OperationLogTargetType.AdminMenu)]
|
2026-07-06 14:21:21 +08:00
|
|
|
[HttpPost("menus")]
|
|
|
|
|
public async Task<BaseResponse<AdminMenuOutput>> CreateMenuAsync([FromBody] AdminMenuInput input)
|
|
|
|
|
{
|
|
|
|
|
var result = await adminPermissionService.CreateMenuAsync(input);
|
|
|
|
|
return Success(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新菜单
|
|
|
|
|
/// </summary>
|
2026-07-09 18:01:37 +08:00
|
|
|
[OperationLog(OperationLogActionType.Update, OperationLogTargetType.AdminMenu)]
|
2026-07-06 14:21:21 +08:00
|
|
|
[HttpPut("menus/{id}")]
|
|
|
|
|
public async Task<BaseResponse<AdminMenuOutput>> UpdateMenuAsync(long id, [FromBody] AdminMenuInput input)
|
|
|
|
|
{
|
|
|
|
|
var result = await adminPermissionService.UpdateMenuAsync(id, input);
|
|
|
|
|
return Success(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除菜单
|
|
|
|
|
/// </summary>
|
2026-07-09 18:01:37 +08:00
|
|
|
[OperationLog(OperationLogActionType.Delete, OperationLogTargetType.AdminMenu)]
|
2026-07-06 14:21:21 +08:00
|
|
|
[HttpDelete("menus/{id}")]
|
|
|
|
|
public async Task<BaseResponse<object>> DeleteMenuAsync(long id)
|
|
|
|
|
{
|
|
|
|
|
await adminPermissionService.DeleteMenuAsync(id);
|
|
|
|
|
return Success(new object());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取菜单树
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpPost("menus/tree")]
|
|
|
|
|
public async Task<BaseResponse<List<AdminMenuOutput>>> GetMenuTreeAsync([FromBody] AdminMenuQueryInput input)
|
|
|
|
|
{
|
|
|
|
|
var result = await adminPermissionService.GetMenuTreeAsync(input);
|
|
|
|
|
return Success(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取当前管理员菜单树
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet("menus/current")]
|
|
|
|
|
public async Task<BaseResponse<List<AdminMenuOutput>>> GetCurrentMenuTreeAsync()
|
|
|
|
|
{
|
|
|
|
|
var userId = GetCurrentUserId();
|
|
|
|
|
BusinessException.ThrowIf(userId == null, "未获取到用户信息", ResultCode.DENY);
|
|
|
|
|
|
|
|
|
|
var result = await adminPermissionService.GetAdminUserMenuTreeAsync(userId!.Value);
|
|
|
|
|
return Success(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 创建角色
|
|
|
|
|
/// </summary>
|
2026-07-09 18:01:37 +08:00
|
|
|
[OperationLog(OperationLogActionType.Create, OperationLogTargetType.AdminRole)]
|
2026-07-06 14:21:21 +08:00
|
|
|
[HttpPost("roles")]
|
|
|
|
|
public async Task<BaseResponse<AdminRoleOutput>> CreateRoleAsync([FromBody] AdminRoleInput input)
|
|
|
|
|
{
|
|
|
|
|
var result = await adminPermissionService.CreateRoleAsync(input);
|
|
|
|
|
return Success(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新角色
|
|
|
|
|
/// </summary>
|
2026-07-09 18:01:37 +08:00
|
|
|
[OperationLog(OperationLogActionType.Update, OperationLogTargetType.AdminRole)]
|
2026-07-06 14:21:21 +08:00
|
|
|
[HttpPut("roles/{id}")]
|
|
|
|
|
public async Task<BaseResponse<AdminRoleOutput>> UpdateRoleAsync(long id, [FromBody] AdminRoleInput input)
|
|
|
|
|
{
|
|
|
|
|
var result = await adminPermissionService.UpdateRoleAsync(id, input);
|
|
|
|
|
return Success(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除角色
|
|
|
|
|
/// </summary>
|
2026-07-09 18:01:37 +08:00
|
|
|
[OperationLog(OperationLogActionType.Delete, OperationLogTargetType.AdminRole)]
|
2026-07-06 14:21:21 +08:00
|
|
|
[HttpDelete("roles/{id}")]
|
|
|
|
|
public async Task<BaseResponse<object>> DeleteRoleAsync(long id)
|
|
|
|
|
{
|
|
|
|
|
await adminPermissionService.DeleteRoleAsync(id);
|
|
|
|
|
return Success(new object());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取角色详情
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet("roles/{id}")]
|
|
|
|
|
public async Task<BaseResponse<AdminRoleOutput>> GetRoleByIdAsync(long id)
|
|
|
|
|
{
|
|
|
|
|
var result = await adminPermissionService.GetRoleByIdAsync(id);
|
|
|
|
|
return Success(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取角色分页列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpPost("roles/list")]
|
|
|
|
|
public async Task<BaseResponse<PageListModel<AdminRoleOutput>>> GetRoleListAsync([FromBody] AdminRoleQueryInput input)
|
|
|
|
|
{
|
|
|
|
|
var result = await adminPermissionService.GetRoleListAsync(input);
|
|
|
|
|
return Success(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 分配角色菜单
|
|
|
|
|
/// </summary>
|
2026-07-09 18:01:37 +08:00
|
|
|
[OperationLog(OperationLogActionType.Assign, OperationLogTargetType.AdminRole, TargetIdRouteKey = "roleId")]
|
2026-07-06 14:21:21 +08:00
|
|
|
[HttpPut("roles/{roleId}/menus")]
|
|
|
|
|
public async Task<BaseResponse<object>> AssignRoleMenusAsync(long roleId, [FromBody] AssignRoleMenusInput input)
|
|
|
|
|
{
|
|
|
|
|
await adminPermissionService.AssignRoleMenusAsync(roleId, input);
|
|
|
|
|
return Success(new object());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 分配管理员角色
|
|
|
|
|
/// </summary>
|
2026-07-09 18:01:37 +08:00
|
|
|
[OperationLog(OperationLogActionType.Assign, OperationLogTargetType.AdminUser, TargetIdRouteKey = "adminUserId")]
|
2026-07-06 14:21:21 +08:00
|
|
|
[HttpPut("users/{adminUserId}/roles")]
|
|
|
|
|
public async Task<BaseResponse<object>> AssignAdminUserRolesAsync(long adminUserId, [FromBody] AssignAdminUserRolesInput input)
|
|
|
|
|
{
|
|
|
|
|
await adminPermissionService.AssignAdminUserRolesAsync(adminUserId, input);
|
|
|
|
|
return Success(new object());
|
|
|
|
|
}
|
|
|
|
|
}
|