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

206 lines
7.5 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>
/// AIPrompt配置管理控制器
/// </summary>
[Route("api/[controller]")]
[ApiController]
[ApiExplorerSettings(GroupName = nameof(ApiVersionEnum.Platform))]
public class AiBasePromptController : BaseController
{
private readonly IAiBasePromptService _aiBasePromptService;
private readonly ILogger<AiBasePromptController> _logger;
public AiBasePromptController(IAiBasePromptService aiBasePromptService, ILogger<AiBasePromptController> logger)
{
_aiBasePromptService = aiBasePromptService;
_logger = logger;
}
/// <summary>
/// 创建Prompt配置
/// </summary>
/// <param name="input">Prompt配置信息</param>
/// <returns>创建的Prompt配置信息</returns>
[OperationLog(OperationLogActionType.Create, OperationLogTargetType.AiBasePrompt)]
[HttpPost]
public async Task<BaseResponse<AiBasePromptOutput>> CreateAsync([FromBody] AiBasePromptInput input)
{
try
{
var result = await _aiBasePromptService.CreateAsync(input);
return Success(result, "创建Prompt配置成功");
}
catch (BusinessException ex)
{
_logger.LogWarning(ex, "创建Prompt配置业务异常: {Message}", ex.Message);
return BaseResponse<AiBasePromptOutput>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "创建Prompt配置系统异常参数{Input}", input);
return BaseResponse<AiBasePromptOutput>.Fail("创建Prompt配置失败请稍后重试");
}
}
/// <summary>
/// 更新Prompt配置
/// </summary>
/// <param name="id">Prompt配置ID</param>
/// <param name="input">Prompt配置信息</param>
/// <returns>更新后的Prompt配置信息</returns>
[OperationLog(OperationLogActionType.Update, OperationLogTargetType.AiBasePrompt)]
[HttpPut("{id}")]
public async Task<BaseResponse<AiBasePromptOutput>> UpdateAsync(long id, [FromBody] AiBasePromptInput input)
{
try
{
var result = await _aiBasePromptService.UpdateAsync(id, input);
return Success(result, "更新Prompt配置成功");
}
catch (BusinessException ex)
{
_logger.LogWarning(ex, "更新Prompt配置业务异常: {Message}", ex.Message);
return BaseResponse<AiBasePromptOutput>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "更新Prompt配置系统异常ID{Id},参数:{Input}", id, input);
return BaseResponse<AiBasePromptOutput>.Fail("更新Prompt配置失败请稍后重试");
}
}
/// <summary>
/// 删除Prompt配置
/// </summary>
/// <param name="id">Prompt配置ID</param>
/// <returns>操作结果</returns>
[OperationLog(OperationLogActionType.Delete, OperationLogTargetType.AiBasePrompt)]
[HttpDelete("{id}")]
public async Task<BaseResponse<object>> DeleteAsync(long id)
{
try
{
await _aiBasePromptService.DeleteAsync(id);
return Success(new object(), "删除Prompt配置成功");
}
catch (BusinessException ex)
{
_logger.LogWarning(ex, "删除Prompt配置业务异常: {Message}", ex.Message);
return BaseResponse<object>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "删除Prompt配置系统异常ID{Id}", id);
return BaseResponse<object>.Fail("删除Prompt配置失败请稍后重试");
}
}
/// <summary>
/// 根据ID获取Prompt配置
/// </summary>
/// <param name="id">Prompt配置ID</param>
/// <returns>Prompt配置信息</returns>
[HttpGet("{id}")]
public async Task<BaseResponse<AiBasePromptOutput>> GetByIdAsync(long id)
{
try
{
var result = await _aiBasePromptService.GetByIdAsync(id);
return Success(result);
}
catch (BusinessException ex)
{
_logger.LogWarning(ex, "获取Prompt配置业务异常: {Message}", ex.Message);
return BaseResponse<AiBasePromptOutput>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "获取Prompt配置系统异常ID{Id}", id);
return BaseResponse<AiBasePromptOutput>.Fail("获取Prompt配置信息失败请稍后重试");
}
}
/// <summary>
/// 分页查询Prompt配置列表
/// </summary>
/// <param name="input">查询条件</param>
/// <returns>分页结果</returns>
[HttpPost("list")]
public async Task<BaseResponse<PageListModel<AiBasePromptOutput>>> GetListAsync([FromBody] AiBasePromptQueryInput input)
{
try
{
var result = await _aiBasePromptService.GetListAsync(input);
return Success(result);
}
catch (BusinessException ex)
{
_logger.LogWarning(ex, "查询Prompt配置列表业务异常: {Message}", ex.Message);
return BaseResponse<PageListModel<AiBasePromptOutput>>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "查询Prompt配置列表系统异常参数{Input}", input);
return BaseResponse<PageListModel<AiBasePromptOutput>>.Fail("查询Prompt配置列表失败请稍后重试");
}
}
/// <summary>
/// 获取全部Prompt配置无分页
/// </summary>
/// <returns>全部Prompt配置列表</returns>
[HttpGet("all")]
public async Task<BaseResponse<List<AiBasePromptOutput>>> GetAllAsync()
{
try
{
var result = await _aiBasePromptService.GetAllAsync();
return Success(result);
}
catch (BusinessException ex)
{
_logger.LogWarning(ex, "查询全部Prompt配置业务异常: {Message}", ex.Message);
return BaseResponse<List<AiBasePromptOutput>>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "查询全部Prompt配置系统异常");
return BaseResponse<List<AiBasePromptOutput>>.Fail("查询Prompt配置列表失败请稍后重试");
}
}
/// <summary>
/// 切换Prompt启用/禁用状态
/// </summary>
/// <param name="id">Prompt配置ID</param>
/// <returns>操作结果</returns>
[OperationLog(OperationLogActionType.StatusChange, OperationLogTargetType.AiBasePrompt)]
[HttpPut("{id}/toggle-status")]
public async Task<BaseResponse<object>> ToggleStatusAsync(long id)
{
try
{
await _aiBasePromptService.ToggleStatusAsync(id);
return Success(new object(), "切换Prompt状态成功");
}
catch (BusinessException ex)
{
_logger.LogWarning(ex, "切换Prompt状态业务异常: {Message}", ex.Message);
return BaseResponse<object>.Fail(ex.Message);
}
catch (Exception ex)
{
_logger.LogError(ex, "切换Prompt状态系统异常ID{Id}", id);
return BaseResponse<object>.Fail("切换Prompt状态失败请稍后重试");
}
}
}