Files
QYZH.InteractiveMagazine/QYZH.InteractiveMagazine.WebApi/Controllers/MedalController.cs
glz 766be485d0 feat: 新增操作日志功能并优化定时任务配置
1.  新增OperationLogAttribute与OperationLogActionFilter,实现自动化操作日志记录
2.  新增OperationLogRecordInput输入模型,重构IOperationLogService日志接口
3.  为所有业务控制器接口添加操作日志注解
4.  调整期刊AI批改任务的执行周期与方法适配异步调用
5.  优化Hangfire定时任务注册逻辑,支持异步任务
6.  补充完善操作日志类型与目标类型枚举
2026-07-09 18:01:37 +08:00

220 lines
7.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>
[Route("api/[controller]")]
[ApiController]
[ApiExplorerSettings(GroupName = nameof(ApiVersionEnum.Platform))]
public class MedalController : BaseController
{
private readonly IMedalService _medalService;
private readonly ILogger<MedalController> _logger;
public MedalController(IMedalService medalService, ILogger<MedalController> logger)
{
_medalService = medalService;
_logger = logger;
}
/// <summary>
/// 创建勋章
/// </summary>
/// <param name="input">勋章信息</param>
/// <returns>创建的勋章信息</returns>
[OperationLog(OperationLogActionType.Create, OperationLogTargetType.Medal)]
[HttpPost]
public async Task<BaseResponse<MedalOutput>> CreateAsync([FromBody] MedalInput input)
{
try
{
var result = await _medalService.CreateAsync(input);
return Success(result, "创建勋章成功");
}
catch (BusinessException ex)
{
_logger.LogWarning(ex, "创建勋章业务异常: {Message}", ex.Message);
return BaseResponse<MedalOutput>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "创建勋章系统异常,参数:{Input}", input);
return BaseResponse<MedalOutput>.Fail("创建勋章失败,请稍后重试");
}
}
/// <summary>
/// 更新勋章
/// </summary>
/// <param name="id">勋章ID</param>
/// <param name="input">勋章信息</param>
/// <returns>更新后的勋章信息</returns>
[OperationLog(OperationLogActionType.Update, OperationLogTargetType.Medal)]
[HttpPut("{id}")]
public async Task<BaseResponse<MedalOutput>> UpdateAsync(long id, [FromBody] MedalInput input)
{
try
{
var result = await _medalService.UpdateAsync(id, input);
return Success(result, "更新勋章成功");
}
catch (BusinessException ex)
{
_logger.LogWarning(ex, "更新勋章业务异常: {Message}", ex.Message);
return BaseResponse<MedalOutput>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "更新勋章系统异常ID{Id},参数:{Input}", id, input);
return BaseResponse<MedalOutput>.Fail("更新勋章失败,请稍后重试");
}
}
/// <summary>
/// 删除勋章
/// </summary>
/// <param name="id">勋章ID</param>
/// <returns>操作结果</returns>
[OperationLog(OperationLogActionType.Delete, OperationLogTargetType.Medal)]
[HttpDelete("{id}")]
public async Task<BaseResponse<object>> DeleteAsync(long id)
{
try
{
await _medalService.DeleteAsync(id);
return Success(new object(), "删除勋章成功");
}
catch (BusinessException ex)
{
_logger.LogWarning(ex, "删除勋章业务异常: {Message}", ex.Message);
return BaseResponse<object>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "删除勋章系统异常ID{Id}", id);
return BaseResponse<object>.Fail("删除勋章失败,请稍后重试");
}
}
/// <summary>
/// 根据ID获取勋章
/// </summary>
/// <param name="id">勋章ID</param>
/// <returns>勋章信息</returns>
[HttpGet("{id}")]
public async Task<BaseResponse<MedalOutput>> GetByIdAsync(long id)
{
try
{
var result = await _medalService.GetByIdAsync(id);
return Success(result);
}
catch (BusinessException ex)
{
_logger.LogWarning(ex, "获取勋章业务异常: {Message}", ex.Message);
return BaseResponse<MedalOutput>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "获取勋章系统异常ID{Id}", id);
return BaseResponse<MedalOutput>.Fail("获取勋章信息失败,请稍后重试");
}
}
/// <summary>
/// 分页查询勋章列表
/// </summary>
/// <param name="input">查询条件</param>
/// <returns>分页结果</returns>
[HttpPost("list")]
public async Task<BaseResponse<PageListModel<MedalOutput>>> GetListAsync([FromBody] MedalQueryInput input)
{
try
{
var result = await _medalService.GetListAsync(input);
return Success(result);
}
catch (BusinessException ex)
{
_logger.LogWarning(ex, "查询勋章列表业务异常: {Message}", ex.Message);
return BaseResponse<PageListModel<MedalOutput>>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "查询勋章列表系统异常,参数:{Input}", input);
return BaseResponse<PageListModel<MedalOutput>>.Fail("查询勋章列表失败,请稍后重试");
}
}
/// <summary>
/// 更新勋章启用/禁用状态
/// </summary>
/// <param name="id">勋章ID</param>
/// <param name="status">状态: 0=禁用, 1=启用</param>
/// <returns>操作结果</returns>
[OperationLog(OperationLogActionType.StatusChange, OperationLogTargetType.Medal)]
[HttpPut("{id}/status")]
public async Task<BaseResponse<bool>> UpdateStatusAsync(long id)
{
try
{
var res = await _medalService.UpdateStatusAsync(id);
return Success(res, "更新勋章状态成功");
}
catch (BusinessException ex)
{
_logger.LogWarning(ex, "更新勋章状态业务异常: {Message}", ex.Message);
return BaseResponse<bool>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "更新勋章状态系统异常ID{Id}", id);
return BaseResponse<bool>.Fail("更新勋章状态失败,请稍后重试");
}
}
/// <summary>
/// 获取规则配置中可用的目标表列表
/// </summary>
[HttpGet("rule-config/tables")]
public async Task<BaseResponse<List<MedalRuleTableOptionOutput>>> GetAvailableTables()
{
try
{
var result = await _medalService.GetAvailableTablesAsync();
return Success(result);
}
catch (Exception ex)
{
_logger.LogError(ex, "获取可用目标表列表系统异常");
return BaseResponse<List<MedalRuleTableOptionOutput>>.Fail("获取可用目标表列表失败,请稍后重试");
}
}
/// <summary>
/// 获取指定表的可用字段列表
/// </summary>
/// <param name="tableName">表名</param>
[HttpGet("rule-config/tables/{tableName}/fields")]
public async Task<BaseResponse<List<MedalRuleFieldOptionOutput>>> GetTableFields(string tableName)
{
try
{
var result = await _medalService.GetTableFieldsAsync(tableName);
return Success(result);
}
catch (Exception ex)
{
_logger.LogError(ex, "获取可用字段列表系统异常,表名:{TableName}", tableName);
return BaseResponse<List<MedalRuleFieldOptionOutput>>.Fail("获取可用字段列表失败,请稍后重试");
}
}
}