修改日志记录方式
This commit is contained in:
parent
669638765b
commit
3e6dbcc07c
|
|
@ -16,7 +16,7 @@ namespace AI.Api.Controllers
|
|||
this._questionLogService = questionLogService;
|
||||
}
|
||||
|
||||
[HttpGet("record")]
|
||||
[HttpPost("record")]
|
||||
public async Task<long> RecordAsync([FromBody] QuestionLogDto questionLogDto)
|
||||
{
|
||||
var entity = questionLogDto.Adapt<QuestionLog>();
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ namespace AI.Api
|
|||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
app.UseCustomCors();
|
||||
}
|
||||
|
||||
//调用中间件:UseAuthentication(认证),必须在所有需要身份认证的中间件前调用,比如 UseAuthorization(授权)。
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
namespace AI.Api.WebCore
|
||||
{
|
||||
/// <summary>
|
||||
/// 跨域配置扩展服务
|
||||
/// </summary>
|
||||
public static class CorsAppBuilderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 允许所有跨域请求 (属于基础服务,若已调用 UseBasicServices 则无需调用)
|
||||
/// </summary>
|
||||
/// <param name="app"></param>
|
||||
/// <returns></returns>
|
||||
public static IApplicationBuilder UseCustomCors(this IApplicationBuilder app)
|
||||
{
|
||||
//// 获取配置文件中的允许跨域的地址
|
||||
//var hosts = AppSetting.AllowedHosts.Split("|", StringSplitOptions.RemoveEmptyEntries);
|
||||
app.UseCors(options =>
|
||||
{
|
||||
options.AllowAnyOrigin() // 允许跨域请求的地址
|
||||
.AllowAnyHeader() // 允许的请求标头
|
||||
.AllowAnyMethod(); // 允许跨域请求的类型 (GET,POST等)
|
||||
|
||||
});
|
||||
|
||||
return app;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
|
@ -7,9 +8,24 @@ using System.Threading.Tasks;
|
|||
namespace AI.Common.Dtos
|
||||
{
|
||||
public class QuestionLogDto
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public string QuestionContent { get; set; }
|
||||
public string? GptAnswer { get; set; }
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 备 注:内容
|
||||
/// 默认值:
|
||||
///</summary>
|
||||
public string Content { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备 注:类型 1:文本 2:图片 3:文件
|
||||
/// 默认值:
|
||||
///</summary>
|
||||
public int Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备 注:发生时间戳
|
||||
/// 默认值:
|
||||
///</summary>
|
||||
public long Timestamp { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ namespace AI.Common.Entities
|
|||
/// 默认值:
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
|
||||
public long Id { get; set; }
|
||||
public UInt64 Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备 注:
|
||||
|
|
@ -27,25 +27,32 @@ namespace AI.Common.Entities
|
|||
public DateTime Create_time { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备 注:
|
||||
/// 备 注:提问人
|
||||
/// 默认值:
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName = "uid")]
|
||||
public long Uid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备 注:问题内容
|
||||
/// 备 注:内容
|
||||
/// 默认值:
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName = "question_content")]
|
||||
public string? QuestionContent { get; set; }
|
||||
[SugarColumn(ColumnName = "content")]
|
||||
public string Content { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备 注:
|
||||
/// 备 注:类型 1:文本 2:图片 3:文件
|
||||
/// 默认值:
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName = "gpt_answer")]
|
||||
public string? GptAnswer { get; set; }
|
||||
[SugarColumn(ColumnName = "type")]
|
||||
public int Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 备 注:发生时间戳
|
||||
/// 默认值:
|
||||
///</summary>
|
||||
[SugarColumn(ColumnName = "timestamp")]
|
||||
public long Timestamp { get; set; }
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,18 +21,9 @@ namespace AI.Common.Services
|
|||
}
|
||||
|
||||
public async Task<long> RecordAsync(QuestionLog questionLog)
|
||||
{
|
||||
if (questionLog.Id <= 0)
|
||||
{
|
||||
// 新增
|
||||
return await _sqlSugarClient.Insertable(questionLog).ExecuteReturnBigIdentityAsync();
|
||||
}
|
||||
|
||||
// 更新
|
||||
await _sqlSugarClient.Updateable(questionLog)
|
||||
.UpdateColumns(x => new { x.QuestionContent, x.GptAnswer }).ExecuteCommandAsync();
|
||||
|
||||
return questionLog.Id;
|
||||
{
|
||||
// 新增
|
||||
return await _sqlSugarClient.Insertable(questionLog).ExecuteReturnBigIdentityAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue