1. 新增OperationLogAttribute与OperationLogActionFilter,实现自动化操作日志记录 2. 新增OperationLogRecordInput输入模型,重构IOperationLogService日志接口 3. 为所有业务控制器接口添加操作日志注解 4. 调整期刊AI批改任务的执行周期与方法适配异步调用 5. 优化Hangfire定时任务注册逻辑,支持异步任务 6. 补充完善操作日志类型与目标类型枚举
149 lines
5.1 KiB
C#
149 lines
5.1 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using QYZH.InteractiveMagazine.Infrastructure.Middleware;
|
|
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>
|
|
[OperationLog(OperationLogActionType.Create, OperationLogTargetType.AdminMenu)]
|
|
[HttpPost("menus")]
|
|
public async Task<BaseResponse<AdminMenuOutput>> CreateMenuAsync([FromBody] AdminMenuInput input)
|
|
{
|
|
var result = await adminPermissionService.CreateMenuAsync(input);
|
|
return Success(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新菜单
|
|
/// </summary>
|
|
[OperationLog(OperationLogActionType.Update, OperationLogTargetType.AdminMenu)]
|
|
[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>
|
|
[OperationLog(OperationLogActionType.Delete, OperationLogTargetType.AdminMenu)]
|
|
[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>
|
|
[OperationLog(OperationLogActionType.Create, OperationLogTargetType.AdminRole)]
|
|
[HttpPost("roles")]
|
|
public async Task<BaseResponse<AdminRoleOutput>> CreateRoleAsync([FromBody] AdminRoleInput input)
|
|
{
|
|
var result = await adminPermissionService.CreateRoleAsync(input);
|
|
return Success(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新角色
|
|
/// </summary>
|
|
[OperationLog(OperationLogActionType.Update, OperationLogTargetType.AdminRole)]
|
|
[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>
|
|
[OperationLog(OperationLogActionType.Delete, OperationLogTargetType.AdminRole)]
|
|
[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>
|
|
[OperationLog(OperationLogActionType.Assign, OperationLogTargetType.AdminRole, TargetIdRouteKey = "roleId")]
|
|
[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>
|
|
[OperationLog(OperationLogActionType.Assign, OperationLogTargetType.AdminUser, TargetIdRouteKey = "adminUserId")]
|
|
[HttpPut("users/{adminUserId}/roles")]
|
|
public async Task<BaseResponse<object>> AssignAdminUserRolesAsync(long adminUserId, [FromBody] AssignAdminUserRolesInput input)
|
|
{
|
|
await adminPermissionService.AssignAdminUserRolesAsync(adminUserId, input);
|
|
return Success(new object());
|
|
}
|
|
}
|