refactor: 调整期刊实体字段与用户期刊输出映射
1. 移除Journal实体冗余的Title字段,统一使用Name字段 2. 更新UserDto和UsersService中的期刊标题映射逻辑 3. 新增JournalPageTask的四项能力评分字段 4. 新增AI提示词管理的完整服务、控制器与相关DTO 5. 新增用户作答记录实体JournalPageTaskUserAnswer
This commit is contained in:
45
QYZH.InteractiveMagazine.IService/IAiBasePromptService.cs
Normal file
45
QYZH.InteractiveMagazine.IService/IAiBasePromptService.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using QYZH.InteractiveMagazine.Models.Dto;
|
||||
using QYZH.InteractiveMagazine.Models.Entity;
|
||||
|
||||
namespace QYZH.InteractiveMagazine.IService;
|
||||
|
||||
/// <summary>
|
||||
/// AIPrompt配置服务接口
|
||||
/// </summary>
|
||||
public interface IAiBasePromptService : IBaseService<AiBasePrompt>
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建Prompt配置
|
||||
/// </summary>
|
||||
/// <param name="input">Prompt配置输入</param>
|
||||
/// <returns>创建的Prompt配置信息</returns>
|
||||
Task<AiBasePromptOutput> CreateAsync(AiBasePromptInput input);
|
||||
|
||||
/// <summary>
|
||||
/// 更新Prompt配置
|
||||
/// </summary>
|
||||
/// <param name="id">Prompt配置ID</param>
|
||||
/// <param name="input">Prompt配置输入</param>
|
||||
/// <returns>更新后的Prompt配置信息</returns>
|
||||
Task<AiBasePromptOutput> UpdateAsync(long id, AiBasePromptInput input);
|
||||
|
||||
/// <summary>
|
||||
/// 删除Prompt配置(软删除)
|
||||
/// </summary>
|
||||
/// <param name="id">Prompt配置ID</param>
|
||||
Task DeleteAsync(long id);
|
||||
|
||||
/// <summary>
|
||||
/// 根据ID获取Prompt配置
|
||||
/// </summary>
|
||||
/// <param name="id">Prompt配置ID</param>
|
||||
/// <returns>Prompt配置信息</returns>
|
||||
Task<AiBasePromptOutput> GetByIdAsync(long id);
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询Prompt配置列表
|
||||
/// </summary>
|
||||
/// <param name="input">查询条件</param>
|
||||
/// <returns>分页结果</returns>
|
||||
Task<PageListModel<AiBasePromptOutput>> GetListAsync(AiBasePromptQueryInput input);
|
||||
}
|
||||
116
QYZH.InteractiveMagazine.Models/Dto/Ai/AiBasePromptDto.cs
Normal file
116
QYZH.InteractiveMagazine.Models/Dto/Ai/AiBasePromptDto.cs
Normal file
@ -0,0 +1,116 @@
|
||||
using QYZH.InteractiveMagazine.Models.Dto;
|
||||
|
||||
namespace QYZH.InteractiveMagazine.Models.Dto;
|
||||
|
||||
/// <summary>
|
||||
/// AIPrompt配置创建/更新输入
|
||||
/// </summary>
|
||||
public class AiBasePromptInput
|
||||
{
|
||||
/// <summary>
|
||||
/// 配置标识(如:DEFAULT, READING, COMPREHENSION)
|
||||
/// </summary>
|
||||
public string PromptKey { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 配置名称(如:默认Prompt、阅读理解专用)
|
||||
/// </summary>
|
||||
public string PromptName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Prompt模板内容
|
||||
/// </summary>
|
||||
public string PromptTemplate { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 配置说明
|
||||
/// </summary>
|
||||
public string? Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 优先级(数值越小优先级越高)
|
||||
/// </summary>
|
||||
public int Priority { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否为默认模板
|
||||
/// </summary>
|
||||
public bool IsDefault { get; set; } = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AIPrompt配置输出
|
||||
/// </summary>
|
||||
public class AiBasePromptOutput
|
||||
{
|
||||
/// <summary>
|
||||
/// 主键ID
|
||||
/// </summary>
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 配置标识
|
||||
/// </summary>
|
||||
public string PromptKey { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 配置名称
|
||||
/// </summary>
|
||||
public string PromptName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Prompt模板内容
|
||||
/// </summary>
|
||||
public string PromptTemplate { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 配置说明
|
||||
/// </summary>
|
||||
public string? Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 优先级
|
||||
/// </summary>
|
||||
public int Priority { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否为默认模板
|
||||
/// </summary>
|
||||
public bool IsDefault { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建人
|
||||
/// </summary>
|
||||
public string? CreatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间
|
||||
/// </summary>
|
||||
public DateTime CreatedAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 更新人
|
||||
/// </summary>
|
||||
public string? UpdatedBy { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 更新时间
|
||||
/// </summary>
|
||||
public DateTime? UpdatedAt { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AIPrompt配置分页查询输入
|
||||
/// </summary>
|
||||
public class AiBasePromptQueryInput : PageQueryModel
|
||||
{
|
||||
/// <summary>
|
||||
/// 配置标识(精确匹配)
|
||||
/// </summary>
|
||||
public string? PromptKey { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 配置名称(模糊查询)
|
||||
/// </summary>
|
||||
public string? PromptName { get; set; }
|
||||
}
|
||||
@ -86,7 +86,7 @@ public class UserJournalItemOutput
|
||||
/// <summary>
|
||||
/// 期刊标题
|
||||
/// </summary>
|
||||
public string JournalTitle { get; set; } = string.Empty;
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 期刊封面
|
||||
|
||||
@ -92,8 +92,6 @@ namespace QYZH.InteractiveMagazine.Models.Entity
|
||||
public string PdfPreviewUrl { get; set; }
|
||||
|
||||
|
||||
public string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Desc:下载书籍页码点阵码PDF文件名称
|
||||
/// Default:
|
||||
|
||||
@ -152,5 +152,33 @@ namespace QYZH.InteractiveMagazine.Models.Entity
|
||||
/// </summary>
|
||||
public string CustomPrompt {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:理解力评分
|
||||
/// Default:0
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public float Comprehension {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:判断力评分
|
||||
/// Default:0
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public float Judgment {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:表达力评分
|
||||
/// Default:0
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public float Expression {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:说服力评分
|
||||
/// Default:0
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public float Persuasiveness {get;set;}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,216 @@
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace QYZH.InteractiveMagazine.Models.Entity
|
||||
{
|
||||
///<summary>
|
||||
///杂志任务用户作答记录;
|
||||
///</summary>
|
||||
[SugarTable("JournalPageTaskUserAnswer")]
|
||||
public partial class JournalPageTaskUserAnswer : SqlSugarBaseEntity
|
||||
{
|
||||
public JournalPageTaskUserAnswer(){
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:书id
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public long JournalId {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:书页id
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public long JournalPageId {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:任务id
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public long JournalPageTaskId {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:任务分组id
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public long JournalPageTaskGroupId {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:用户id
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public long UserId {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:作答结果
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string Result {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:积分
|
||||
/// Default:0
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public float Points {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:成长值
|
||||
/// Default:0
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public float GrowthPoints {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:题目作答图片地址
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string QuestionAnswerUrl {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:答案图片地址
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string AnswerUrl {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:页面作答图片地址
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string PageAnswerUrl {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:乐观锁
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public int Revision {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:作答状态
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public int AnswerStatus {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:作答开始时间
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public DateTime AnswerStartTime {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:作答结束时间
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public DateTime AnswerEndTime {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:作答耗时(秒)
|
||||
/// Default:0
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public int AnswerSeconds {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:图像识别结果
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public int ImageRecognition {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:书页序号
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public int JournalPageNum {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:修改次数
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public int Modify {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:最后标签id
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public long LastTag {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:点读书页序号
|
||||
/// Default:
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public int DotPageNum {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:页面结果图片地址
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string PageResultUrl {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:题型
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string Type {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:点读书页编号
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string DotPageNo {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:页面作答点读图片地址
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string PageAnswerDotUrl {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:中断次数
|
||||
/// Default:0
|
||||
/// Nullable:False
|
||||
/// </summary>
|
||||
public int BreakCount {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:中断时间记录
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string BreakTimes {get;set;}
|
||||
|
||||
/// <summary>
|
||||
/// Desc:作业状态
|
||||
/// Default:
|
||||
/// Nullable:True
|
||||
/// </summary>
|
||||
public string AssignmentStatus {get;set;}
|
||||
|
||||
}
|
||||
}
|
||||
254
QYZH.InteractiveMagazine.Service/AiBasePromptService.cs
Normal file
254
QYZH.InteractiveMagazine.Service/AiBasePromptService.cs
Normal file
@ -0,0 +1,254 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using QYZH.InteractiveMagazine.IService;
|
||||
using QYZH.InteractiveMagazine.Models.Common;
|
||||
using QYZH.InteractiveMagazine.Models.Dto;
|
||||
using QYZH.InteractiveMagazine.Models.Entity;
|
||||
using QYZH.InteractiveMagazine.Repository;
|
||||
using SqlSugar;
|
||||
|
||||
namespace QYZH.InteractiveMagazine.Service;
|
||||
|
||||
/// <summary>
|
||||
/// AIPrompt配置服务实现
|
||||
/// </summary>
|
||||
public class AiBasePromptService(
|
||||
BaseRepository<AiBasePrompt> promptRepository,
|
||||
ILogger<AiBasePromptService> logger) : BaseRepository<AiBasePrompt>, IAiBasePromptService
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 创建Prompt配置
|
||||
/// </summary>
|
||||
public async Task<AiBasePromptOutput> CreateAsync(AiBasePromptInput input)
|
||||
{
|
||||
logger.LogInformation("正在创建Prompt配置,PromptKey: {PromptKey}", input.PromptKey);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input.PromptKey))
|
||||
{
|
||||
throw new BusinessException("配置标识不能为空", 400);
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input.PromptName))
|
||||
{
|
||||
throw new BusinessException("配置名称不能为空", 400);
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input.PromptTemplate))
|
||||
{
|
||||
throw new BusinessException("Prompt模板内容不能为空", 400);
|
||||
}
|
||||
|
||||
// 检查PromptKey是否已存在
|
||||
var exists = await promptRepository.IsAnyAsync(p => p.PromptKey == input.PromptKey.Trim());
|
||||
if (exists)
|
||||
{
|
||||
throw new BusinessException($"配置标识 '{input.PromptKey.Trim()}' 已存在", 400);
|
||||
}
|
||||
|
||||
var entity = new AiBasePrompt
|
||||
{
|
||||
PromptKey = input.PromptKey.Trim(),
|
||||
PromptName = input.PromptName.Trim(),
|
||||
PromptTemplate = input.PromptTemplate,
|
||||
Description = input.Description,
|
||||
Priority = input.Priority,
|
||||
IsDefault = input.IsDefault,
|
||||
CreatedBy = "System",
|
||||
UpdatedBy = "System",
|
||||
CreatedAt = DateTime.Now,
|
||||
UpdatedAt = DateTime.Now,
|
||||
IsDeleted = false
|
||||
};
|
||||
|
||||
var result = await promptRepository.InsertAsync(entity);
|
||||
if (!result)
|
||||
{
|
||||
logger.LogError("Prompt配置创建失败,PromptKey: {PromptKey}", input.PromptKey);
|
||||
throw new BusinessException("创建Prompt配置失败", 500);
|
||||
}
|
||||
|
||||
logger.LogInformation("Prompt配置创建成功,PromptKey: {PromptKey}, ID: {Id}", input.PromptKey, entity.Id);
|
||||
|
||||
return new AiBasePromptOutput
|
||||
{
|
||||
Id = entity.Id,
|
||||
PromptKey = entity.PromptKey,
|
||||
PromptName = entity.PromptName,
|
||||
PromptTemplate = entity.PromptTemplate,
|
||||
Description = entity.Description,
|
||||
Priority = entity.Priority,
|
||||
IsDefault = entity.IsDefault,
|
||||
CreatedBy = entity.CreatedBy,
|
||||
CreatedAt = entity.CreatedAt,
|
||||
UpdatedBy = entity.UpdatedBy,
|
||||
UpdatedAt = entity.UpdatedAt
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新Prompt配置
|
||||
/// </summary>
|
||||
public async Task<AiBasePromptOutput> UpdateAsync(long id, AiBasePromptInput input)
|
||||
{
|
||||
logger.LogInformation("正在更新Prompt配置,ID: {Id}", id);
|
||||
|
||||
var entity = await promptRepository.GetByIdAsync(id);
|
||||
if (entity == null)
|
||||
{
|
||||
logger.LogWarning("未找到要更新的Prompt配置,ID: {Id}", id);
|
||||
throw new BusinessException("Prompt配置不存在", 404);
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input.PromptKey))
|
||||
{
|
||||
throw new BusinessException("配置标识不能为空", 400);
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input.PromptName))
|
||||
{
|
||||
throw new BusinessException("配置名称不能为空", 400);
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(input.PromptTemplate))
|
||||
{
|
||||
throw new BusinessException("Prompt模板内容不能为空", 400);
|
||||
}
|
||||
|
||||
// 检查PromptKey是否被其他记录占用
|
||||
var exists = await promptRepository.IsAnyAsync(p => p.PromptKey == input.PromptKey.Trim() && p.Id != id);
|
||||
if (exists)
|
||||
{
|
||||
throw new BusinessException($"配置标识 '{input.PromptKey.Trim()}' 已被其他配置使用", 400);
|
||||
}
|
||||
|
||||
entity.PromptKey = input.PromptKey.Trim();
|
||||
entity.PromptName = input.PromptName.Trim();
|
||||
entity.PromptTemplate = input.PromptTemplate;
|
||||
entity.Description = input.Description;
|
||||
entity.Priority = input.Priority;
|
||||
entity.IsDefault = input.IsDefault;
|
||||
entity.UpdatedBy = "System";
|
||||
entity.UpdatedAt = DateTime.Now;
|
||||
|
||||
var result = await promptRepository.UpdateAsync(entity);
|
||||
if (!result)
|
||||
{
|
||||
logger.LogError("Prompt配置更新失败,ID: {Id}", id);
|
||||
throw new BusinessException("更新Prompt配置失败", 500);
|
||||
}
|
||||
|
||||
logger.LogInformation("Prompt配置更新成功,ID: {Id}", id);
|
||||
|
||||
return new AiBasePromptOutput
|
||||
{
|
||||
Id = entity.Id,
|
||||
PromptKey = entity.PromptKey,
|
||||
PromptName = entity.PromptName,
|
||||
PromptTemplate = entity.PromptTemplate,
|
||||
Description = entity.Description,
|
||||
Priority = entity.Priority,
|
||||
IsDefault = entity.IsDefault,
|
||||
CreatedBy = entity.CreatedBy,
|
||||
CreatedAt = entity.CreatedAt,
|
||||
UpdatedBy = entity.UpdatedBy,
|
||||
UpdatedAt = entity.UpdatedAt
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除Prompt配置(软删除)
|
||||
/// </summary>
|
||||
public async Task DeleteAsync(long id)
|
||||
{
|
||||
logger.LogInformation("正在删除Prompt配置,ID: {Id}", id);
|
||||
|
||||
var entity = await promptRepository.GetByIdAsync(id);
|
||||
if (entity == null)
|
||||
{
|
||||
logger.LogWarning("未找到要删除的Prompt配置,ID: {Id}", id);
|
||||
throw new BusinessException("Prompt配置不存在", 404);
|
||||
}
|
||||
|
||||
var result = await promptRepository.DeleteByIdAsync(id);
|
||||
if (!result)
|
||||
{
|
||||
logger.LogError("Prompt配置删除失败,ID: {Id}", id);
|
||||
throw new BusinessException("删除Prompt配置失败", 500);
|
||||
}
|
||||
|
||||
logger.LogInformation("Prompt配置删除成功,ID: {Id}", id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据ID获取Prompt配置
|
||||
/// </summary>
|
||||
public async Task<AiBasePromptOutput> GetByIdAsync(long id)
|
||||
{
|
||||
logger.LogInformation("正在获取Prompt配置信息,ID: {Id}", id);
|
||||
|
||||
var entity = await promptRepository.GetByIdAsync(id);
|
||||
if (entity == null)
|
||||
{
|
||||
logger.LogWarning("未找到Prompt配置,ID: {Id}", id);
|
||||
throw new BusinessException("Prompt配置不存在", 404);
|
||||
}
|
||||
|
||||
return new AiBasePromptOutput
|
||||
{
|
||||
Id = entity.Id,
|
||||
PromptKey = entity.PromptKey,
|
||||
PromptName = entity.PromptName,
|
||||
PromptTemplate = entity.PromptTemplate,
|
||||
Description = entity.Description,
|
||||
Priority = entity.Priority,
|
||||
IsDefault = entity.IsDefault,
|
||||
CreatedBy = entity.CreatedBy,
|
||||
CreatedAt = entity.CreatedAt,
|
||||
UpdatedBy = entity.UpdatedBy,
|
||||
UpdatedAt = entity.UpdatedAt
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分页查询Prompt配置列表
|
||||
/// </summary>
|
||||
public async Task<PageListModel<AiBasePromptOutput>> GetListAsync(AiBasePromptQueryInput input)
|
||||
{
|
||||
logger.LogInformation("正在查询Prompt配置列表,页码: {PageIndex}, 每页条数: {PageSize}", input.PageIndex, input.PageSize);
|
||||
|
||||
if (input.PageIndex <= 0)
|
||||
{
|
||||
throw new BusinessException("页码必须大于0", 400);
|
||||
}
|
||||
|
||||
if (input.PageSize <= 0 || input.PageSize > 100)
|
||||
{
|
||||
throw new BusinessException("每页条数必须在1-100之间", 400);
|
||||
}
|
||||
|
||||
RefAsync<int> totalNumber = 0;
|
||||
var pageResult = await promptRepository.Queryable()
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(input.PromptKey), p => p.PromptKey == input.PromptKey)
|
||||
.WhereIF(!string.IsNullOrWhiteSpace(input.PromptName), p => p.PromptName.Contains(input.PromptName))
|
||||
.OrderBy(p => p.Priority)
|
||||
.OrderByDescending(p => p.CreatedAt)
|
||||
.ToPageListAsync(input.PageIndex, input.PageSize, totalNumber);
|
||||
|
||||
var result = pageResult.Select(p => new AiBasePromptOutput
|
||||
{
|
||||
Id = p.Id,
|
||||
PromptKey = p.PromptKey,
|
||||
PromptName = p.PromptName,
|
||||
PromptTemplate = p.PromptTemplate,
|
||||
Description = p.Description,
|
||||
Priority = p.Priority,
|
||||
IsDefault = p.IsDefault,
|
||||
CreatedBy = p.CreatedBy,
|
||||
CreatedAt = p.CreatedAt,
|
||||
UpdatedBy = p.UpdatedBy,
|
||||
UpdatedAt = p.UpdatedAt
|
||||
}).ToList();
|
||||
|
||||
return new PageListModel<AiBasePromptOutput>(result, input.PageIndex, input.PageSize, totalNumber);
|
||||
}
|
||||
}
|
||||
@ -105,7 +105,6 @@ public class JournalService(BaseRepository<JournalPage> JournalPageRepository,
|
||||
Journal.Width = input.Width;
|
||||
Journal.Height = input.Height;
|
||||
Journal.Name = input.Name;
|
||||
Journal.Title = input.Title;
|
||||
|
||||
var res = await UseTranAsync(async () =>
|
||||
{
|
||||
|
||||
@ -157,7 +157,7 @@ public class UsersService(
|
||||
{
|
||||
if (journalDict.TryGetValue(item.JournalId, out var journal))
|
||||
{
|
||||
item.JournalTitle = journal.Title;
|
||||
item.Name = journal.Name;
|
||||
item.CoverImageUrl = journal.Cover;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,151 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
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>
|
||||
[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>
|
||||
[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>
|
||||
[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配置列表失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user