From 3e6dbcc07cbc90e181283d12c412e6b0b5407fda Mon Sep 17 00:00:00 2001 From: youngq Date: Fri, 29 Nov 2024 17:46:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=A5=E5=BF=97=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AI.Api/Controllers/QuestLogController.cs | 2 +- AI.Api/Program.cs | 1 + AI.Api/WebCore/CorsAppBuilderExtensions.cs | 28 ++++++++++++++++++++++ AI.Common/Dtos/QuestionLogDto.cs | 26 ++++++++++++++++---- AI.Common/Entities/QuestionLog.cs | 23 +++++++++++------- AI.Common/Services/QuestionLogService.cs | 15 +++--------- 6 files changed, 69 insertions(+), 26 deletions(-) create mode 100644 AI.Api/WebCore/CorsAppBuilderExtensions.cs diff --git a/AI.Api/Controllers/QuestLogController.cs b/AI.Api/Controllers/QuestLogController.cs index 09de724..10c3a72 100644 --- a/AI.Api/Controllers/QuestLogController.cs +++ b/AI.Api/Controllers/QuestLogController.cs @@ -16,7 +16,7 @@ namespace AI.Api.Controllers this._questionLogService = questionLogService; } - [HttpGet("record")] + [HttpPost("record")] public async Task RecordAsync([FromBody] QuestionLogDto questionLogDto) { var entity = questionLogDto.Adapt(); diff --git a/AI.Api/Program.cs b/AI.Api/Program.cs index e0f6f27..f313175 100644 --- a/AI.Api/Program.cs +++ b/AI.Api/Program.cs @@ -56,6 +56,7 @@ namespace AI.Api { app.UseSwagger(); app.UseSwaggerUI(); + app.UseCustomCors(); } //调用中间件:UseAuthentication(认证),必须在所有需要身份认证的中间件前调用,比如 UseAuthorization(授权)。 diff --git a/AI.Api/WebCore/CorsAppBuilderExtensions.cs b/AI.Api/WebCore/CorsAppBuilderExtensions.cs new file mode 100644 index 0000000..87bafa6 --- /dev/null +++ b/AI.Api/WebCore/CorsAppBuilderExtensions.cs @@ -0,0 +1,28 @@ +锘縩amespace AI.Api.WebCore +{ + /// + /// 璺ㄥ煙閰嶇疆鎵╁睍鏈嶅姟 + /// + public static class CorsAppBuilderExtensions + { + /// + /// 鍏佽鎵鏈夎法鍩熻姹 (灞炰簬鍩虹鏈嶅姟锛岃嫢宸茶皟鐢 UseBasicServices 鍒欐棤闇璋冪敤) + /// + /// + /// + 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; + } + } +} diff --git a/AI.Common/Dtos/QuestionLogDto.cs b/AI.Common/Dtos/QuestionLogDto.cs index 802e288..5fe3948 100644 --- a/AI.Common/Dtos/QuestionLogDto.cs +++ b/AI.Common/Dtos/QuestionLogDto.cs @@ -1,4 +1,5 @@ -锘縰sing System; +锘縰sing 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; } + { + + /// + /// 澶 娉:鍐呭 + /// 榛樿鍊: + /// + public string Content { get; set; } + + /// + /// 澶 娉:绫诲瀷 1:鏂囨湰 2:鍥剧墖 3:鏂囦欢 + /// 榛樿鍊: + /// + public int Type { get; set; } + + /// + /// 澶 娉:鍙戠敓鏃堕棿鎴 + /// 榛樿鍊: + /// + public long Timestamp { get; set; } } } diff --git a/AI.Common/Entities/QuestionLog.cs b/AI.Common/Entities/QuestionLog.cs index 37d22d5..1e50467 100644 --- a/AI.Common/Entities/QuestionLog.cs +++ b/AI.Common/Entities/QuestionLog.cs @@ -17,7 +17,7 @@ namespace AI.Common.Entities /// 榛樿鍊: /// [SugarColumn(ColumnName = "id", IsPrimaryKey = true, IsIdentity = true)] - public long Id { get; set; } + public UInt64 Id { get; set; } /// /// 澶 娉: @@ -27,25 +27,32 @@ namespace AI.Common.Entities public DateTime Create_time { get; set; } /// - /// 澶 娉: + /// 澶 娉:鎻愰棶浜 /// 榛樿鍊: /// [SugarColumn(ColumnName = "uid")] public long Uid { get; set; } /// - /// 澶 娉:闂鍐呭 + /// 澶 娉:鍐呭 /// 榛樿鍊: /// - [SugarColumn(ColumnName = "question_content")] - public string? QuestionContent { get; set; } + [SugarColumn(ColumnName = "content")] + public string Content { get; set; } /// - /// 澶 娉: + /// 澶 娉:绫诲瀷 1:鏂囨湰 2:鍥剧墖 3:鏂囦欢 /// 榛樿鍊: /// - [SugarColumn(ColumnName = "gpt_answer")] - public string? GptAnswer { get; set; } + [SugarColumn(ColumnName = "type")] + public int Type { get; set; } + + /// + /// 澶 娉:鍙戠敓鏃堕棿鎴 + /// 榛樿鍊: + /// + [SugarColumn(ColumnName = "timestamp")] + public long Timestamp { get; set; } } diff --git a/AI.Common/Services/QuestionLogService.cs b/AI.Common/Services/QuestionLogService.cs index 07804be..900cc4c 100644 --- a/AI.Common/Services/QuestionLogService.cs +++ b/AI.Common/Services/QuestionLogService.cs @@ -21,18 +21,9 @@ namespace AI.Common.Services } public async Task 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(); } } }