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

193 lines
7.2 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.Enum;
namespace QYZH.InteractiveMagazine.WebApi.Controllers;
/// <summary>
/// 社区消息管理控制器
/// </summary>
[Route("api/[controller]")]
[ApiController]
[ApiExplorerSettings(GroupName = nameof(ApiVersionEnum.Platform))]
public class CommunityMessageController : BaseController
{
private readonly ICommunityMessageService _communityMessageService;
private readonly ILogger<CommunityMessageController> _logger;
public CommunityMessageController(ICommunityMessageService communityMessageService, ILogger<CommunityMessageController> logger)
{
_communityMessageService = communityMessageService;
_logger = logger;
}
/// <summary>
/// 分页查询社区消息列表
/// </summary>
[HttpPost("list")]
public async Task<BaseResponse<PageListModel<AdminMessageDetailOutput>>> GetListAsync([FromBody] AdminMessageQueryInput input)
{
try
{
var result = await _communityMessageService.GetListAsync(input);
return Success(result);
}
catch (BusinessException ex)
{
_logger.LogWarning(ex, "查询社区消息列表业务异常: {Message}", ex.Message);
return BaseResponse<PageListModel<AdminMessageDetailOutput>>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "查询社区消息列表系统异常,参数:{Input}", input);
return BaseResponse<PageListModel<AdminMessageDetailOutput>>.Fail("查询社区消息列表失败,请稍后重试");
}
}
/// <summary>
/// 查看消息详情
/// </summary>
[HttpGet("{id}")]
public async Task<BaseResponse<AdminMessageDetailOutput>> GetDetailAsync(long id)
{
try
{
var result = await _communityMessageService.GetDetailAsync(id);
return Success(result);
}
catch (BusinessException ex)
{
_logger.LogWarning(ex, "获取社区消息详情业务异常: {Message}", ex.Message);
return BaseResponse<AdminMessageDetailOutput>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "获取社区消息详情系统异常ID{Id}", id);
return BaseResponse<AdminMessageDetailOutput>.Fail("获取消息详情失败,请稍后重试");
}
}
/// <summary>
/// 删除消息
/// </summary>
[OperationLog(OperationLogActionType.Delete, OperationLogTargetType.CommunityMessage)]
[HttpDelete("{id}")]
public async Task<BaseResponse<object>> DeleteAsync(long id)
{
try
{
await _communityMessageService.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>
/// 冻结/解冻消息
/// </summary>
[OperationLog(OperationLogActionType.StatusChange, OperationLogTargetType.CommunityMessage)]
[HttpPut("{id}/freeze")]
public async Task<BaseResponse<object>> FreezeAsync(long id, [FromBody] AdminFreezeInput input)
{
try
{
await _communityMessageService.FreezeAsync(id, input.Status);
return Success(new object(), input.Status == (int)MessageStatusEnum.Frozen ? "冻结消息成功" : "解冻消息成功");
}
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>
/// 设置/取消精选
/// </summary>
[OperationLog(OperationLogActionType.StatusChange, OperationLogTargetType.CommunityMessage)]
[HttpPut("{id}/featured")]
public async Task<BaseResponse<object>> SetFeaturedAsync(long id, [FromBody] AdminSetFeaturedInput input)
{
try
{
await _communityMessageService.SetFeaturedAsync(id, input.IsFeatured);
return Success(new object(), input.IsFeatured == 1 ? "设置精选成功" : "取消精选成功");
}
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>
/// 设置排序权重
/// </summary>
[OperationLog(OperationLogActionType.Update, OperationLogTargetType.CommunityMessage)]
[HttpPut("{id}/sort")]
public async Task<BaseResponse<object>> SetSortOrderAsync(long id, [FromBody] AdminSetSortOrderInput input)
{
try
{
await _communityMessageService.SetSortOrderAsync(id, input.SortOrder);
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>
/// 批量发布消息
/// </summary>
[OperationLog(OperationLogActionType.StatusChange, OperationLogTargetType.CommunityMessage, TargetIdRouteKey = null)]
[HttpPost("batch-publish")]
public async Task<BaseResponse<object>> BatchPublishAsync([FromBody] AdminBatchPublishInput input)
{
try
{
await _communityMessageService.BatchPublishAsync(input.Ids);
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, "批量发布社区消息系统异常IDs{Ids}", input.Ids);
return BaseResponse<object>.Fail("批量发布消息失败,请稍后重试");
}
}
}