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

183 lines
6.8 KiB
C#
Raw Permalink 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.Dto.CheckIn;
using QYZH.InteractiveMagazine.Models.Enum;
namespace QYZH.InteractiveMagazine.WebApi.Controllers;
/// <summary>
/// 签到配置管理控制器
/// </summary>
[Route("api/[controller]")]
[ApiController]
[ApiExplorerSettings(GroupName = nameof(ApiVersionEnum.Platform))]
public class CheckInConfigController : BaseController
{
private readonly ICheckInConfigService _checkInConfigService;
private readonly ILogger<CheckInConfigController> _logger;
public CheckInConfigController(ICheckInConfigService checkInConfigService, ILogger<CheckInConfigController> logger)
{
_checkInConfigService = checkInConfigService;
_logger = logger;
}
/// <summary>
/// 创建签到配置
/// </summary>
/// <param name="input">签到配置信息</param>
/// <returns>创建的签到配置信息</returns>
[OperationLog(OperationLogActionType.Create, OperationLogTargetType.CheckInConfig)]
[HttpPost]
public async Task<BaseResponse<CheckInConfigOutput>> CreateAsync([FromBody] CheckInConfigInput input)
{
try
{
var result = await _checkInConfigService.CreateAsync(input);
return Success(result, "创建签到配置成功");
}
catch (BusinessException ex)
{
_logger.LogWarning(ex, "创建签到配置业务异常: {Message}", ex.Message);
return BaseResponse<CheckInConfigOutput>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "创建签到配置系统异常,参数:{Input}", input);
return BaseResponse<CheckInConfigOutput>.Fail("创建签到配置失败,请稍后重试");
}
}
/// <summary>
/// 更新签到配置
/// </summary>
/// <param name="id">签到配置ID</param>
/// <param name="input">签到配置信息</param>
/// <returns>更新后的签到配置信息</returns>
[OperationLog(OperationLogActionType.Update, OperationLogTargetType.CheckInConfig)]
[HttpPut("{id}")]
public async Task<BaseResponse<CheckInConfigOutput>> UpdateAsync(long id, [FromBody] CheckInConfigInput input)
{
try
{
var result = await _checkInConfigService.UpdateAsync(id, input);
return Success(result, "更新签到配置成功");
}
catch (BusinessException ex)
{
_logger.LogWarning(ex, "更新签到配置业务异常: {Message}", ex.Message);
return BaseResponse<CheckInConfigOutput>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "更新签到配置系统异常ID{Id},参数:{Input}", id, input);
return BaseResponse<CheckInConfigOutput>.Fail("更新签到配置失败,请稍后重试");
}
}
/// <summary>
/// 删除签到配置(软删除)
/// </summary>
/// <param name="id">签到配置ID</param>
/// <returns>操作结果</returns>
[OperationLog(OperationLogActionType.Delete, OperationLogTargetType.CheckInConfig)]
[HttpDelete("{id}")]
public async Task<BaseResponse<object>> DeleteAsync(long id)
{
try
{
await _checkInConfigService.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<CheckInConfigOutput>> GetByIdAsync(long id)
{
try
{
var result = await _checkInConfigService.GetByIdAsync(id);
return Success(result);
}
catch (BusinessException ex)
{
_logger.LogWarning(ex, "获取签到配置业务异常: {Message}", ex.Message);
return BaseResponse<CheckInConfigOutput>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "获取签到配置系统异常ID{Id}", id);
return BaseResponse<CheckInConfigOutput>.Fail("获取签到配置信息失败,请稍后重试");
}
}
/// <summary>
/// 分页查询签到配置列表
/// </summary>
/// <param name="input">查询条件</param>
/// <returns>分页结果</returns>
[HttpPost("list")]
public async Task<BaseResponse<PageListModel<CheckInConfigOutput>>> GetListAsync([FromBody] CheckInConfigQueryInput input)
{
try
{
var result = await _checkInConfigService.GetListAsync(input);
return Success(result);
}
catch (BusinessException ex)
{
_logger.LogWarning(ex, "查询签到配置列表业务异常: {Message}", ex.Message);
return BaseResponse<PageListModel<CheckInConfigOutput>>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "查询签到配置列表系统异常,参数:{Input}", input);
return BaseResponse<PageListModel<CheckInConfigOutput>>.Fail("查询签到配置列表失败,请稍后重试");
}
}
/// <summary>
/// 更新签到配置启用/禁用状态
/// </summary>
/// <param name="id">签到配置ID</param>
/// <returns>操作结果</returns>
[OperationLog(OperationLogActionType.StatusChange, OperationLogTargetType.CheckInConfig)]
[HttpPut("{id}/status")]
public async Task<BaseResponse<bool>> UpdateStatusAsync(long id)
{
try
{
var res = await _checkInConfigService.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("更新签到配置状态失败,请稍后重试");
}
}
}