修改日志记录方式
This commit is contained in:
parent
669638765b
commit
3e6dbcc07c
|
|
@ -16,7 +16,7 @@ namespace AI.Api.Controllers
|
||||||
this._questionLogService = questionLogService;
|
this._questionLogService = questionLogService;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("record")]
|
[HttpPost("record")]
|
||||||
public async Task<long> RecordAsync([FromBody] QuestionLogDto questionLogDto)
|
public async Task<long> RecordAsync([FromBody] QuestionLogDto questionLogDto)
|
||||||
{
|
{
|
||||||
var entity = questionLogDto.Adapt<QuestionLog>();
|
var entity = questionLogDto.Adapt<QuestionLog>();
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ namespace AI.Api
|
||||||
{
|
{
|
||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
app.UseSwaggerUI();
|
app.UseSwaggerUI();
|
||||||
|
app.UseCustomCors();
|
||||||
}
|
}
|
||||||
|
|
||||||
//调用中间件:UseAuthentication(认证),必须在所有需要身份认证的中间件前调用,比如 UseAuthorization(授权)。
|
//调用中间件: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.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
@ -8,8 +9,23 @@ namespace AI.Common.Dtos
|
||||||
{
|
{
|
||||||
public class QuestionLogDto
|
public class QuestionLogDto
|
||||||
{
|
{
|
||||||
public long Id { get; set; }
|
|
||||||
public string QuestionContent { get; set; }
|
/// <summary>
|
||||||
public string? GptAnswer { get; set; }
|
/// 备 注:内容
|
||||||
|
/// 默认值:
|
||||||
|
///</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>
|
///</summary>
|
||||||
[SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
|
[SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)]
|
||||||
public long Id { get; set; }
|
public UInt64 Id { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 备 注:
|
/// 备 注:
|
||||||
|
|
@ -27,25 +27,32 @@ namespace AI.Common.Entities
|
||||||
public DateTime Create_time { get; set; }
|
public DateTime Create_time { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 备 注:
|
/// 备 注:提问人
|
||||||
/// 默认值:
|
/// 默认值:
|
||||||
///</summary>
|
///</summary>
|
||||||
[SugarColumn(ColumnName = "uid")]
|
[SugarColumn(ColumnName = "uid")]
|
||||||
public long Uid { get; set; }
|
public long Uid { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 备 注:问题内容
|
/// 备 注:内容
|
||||||
/// 默认值:
|
/// 默认值:
|
||||||
///</summary>
|
///</summary>
|
||||||
[SugarColumn(ColumnName = "question_content")]
|
[SugarColumn(ColumnName = "content")]
|
||||||
public string? QuestionContent { get; set; }
|
public string Content { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 备 注:
|
/// 备 注:类型 1:文本 2:图片 3:文件
|
||||||
/// 默认值:
|
/// 默认值:
|
||||||
///</summary>
|
///</summary>
|
||||||
[SugarColumn(ColumnName = "gpt_answer")]
|
[SugarColumn(ColumnName = "type")]
|
||||||
public string? GptAnswer { get; set; }
|
public int Type { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 备 注:发生时间戳
|
||||||
|
/// 默认值:
|
||||||
|
///</summary>
|
||||||
|
[SugarColumn(ColumnName = "timestamp")]
|
||||||
|
public long Timestamp { get; set; }
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,17 +22,8 @@ namespace AI.Common.Services
|
||||||
|
|
||||||
public async Task<long> RecordAsync(QuestionLog questionLog)
|
public async Task<long> RecordAsync(QuestionLog questionLog)
|
||||||
{
|
{
|
||||||
if (questionLog.Id <= 0)
|
// 新增
|
||||||
{
|
return await _sqlSugarClient.Insertable(questionLog).ExecuteReturnBigIdentityAsync();
|
||||||
// 新增
|
|
||||||
return await _sqlSugarClient.Insertable(questionLog).ExecuteReturnBigIdentityAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新
|
|
||||||
await _sqlSugarClient.Updateable(questionLog)
|
|
||||||
.UpdateColumns(x => new { x.QuestionContent, x.GptAnswer }).ExecuteCommandAsync();
|
|
||||||
|
|
||||||
return questionLog.Id;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue