From 5d286ebc9ece3a2f3f041667562cb9a672b2ec9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com> Date: Wed, 5 Feb 2025 00:02:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20db=E6=93=8D=E4=BD=9C=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E4=B8=8D=E4=BF=AE=E6=94=B9=E6=9B=B4=E6=96=B0=E5=AE=A1=E8=AE=A1?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DefaultSqlSugarDbContext.cs | 14 ++++++++++++-- .../Entities/Forum/DiscussAggregateRoot.cs | 9 +++++++++ .../EventHandlers/SeeDiscussEventHandler.cs | 6 +----- .../Managers/AiManager.cs | 2 +- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/DefaultSqlSugarDbContext.cs b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/DefaultSqlSugarDbContext.cs index 3245b95f..85f71a55 100644 --- a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/DefaultSqlSugarDbContext.cs +++ b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/DefaultSqlSugarDbContext.cs @@ -61,7 +61,12 @@ public class DefaultSqlSugarDbContext : SqlSugarDbContext if (entityInfo.PropertyName.Equals(nameof(IAuditedObject.LastModificationTime))) { - if (!DateTime.MinValue.Equals(oldValue)) + //最后更新时间,已经是最小值,忽略 + if (DateTime.MinValue.Equals(oldValue)) + { + entityInfo.SetValue(null); + } + else { entityInfo.SetValue(DateTime.Now); } @@ -70,7 +75,12 @@ public class DefaultSqlSugarDbContext : SqlSugarDbContext { if (typeof(Guid?) == entityInfo.EntityColumnInfo.PropertyInfo.PropertyType) { - if (CurrentUser.Id != null) + //最后更新者,已经是空guid,忽略 + if (Guid.Empty.Equals(oldValue)) + { + entityInfo.SetValue(null); + } + else if (CurrentUser.Id != null) { entityInfo.SetValue(CurrentUser.Id); } diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Entities/Forum/DiscussAggregateRoot.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Entities/Forum/DiscussAggregateRoot.cs index be562f33..24ef78b8 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Entities/Forum/DiscussAggregateRoot.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/Entities/Forum/DiscussAggregateRoot.cs @@ -24,6 +24,15 @@ namespace Yi.Framework.Bbs.Domain.Entities.Forum PlateId = plateId; } + public void AddSeeNumber() + { + this.SeeNum += 1; + //设置最小值,不更新 + this.LastModificationTime = DateTime.MinValue; + //设置空值,不更新 + this.LastModifierId = Guid.Empty; + } + [SugarColumn(ColumnName = "Id", IsPrimaryKey = true)] public override Guid Id { get; protected set; } public string? Title { get; set; } diff --git a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/SeeDiscussEventHandler.cs b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/SeeDiscussEventHandler.cs index b9411b40..f82b15dd 100644 --- a/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/SeeDiscussEventHandler.cs +++ b/Yi.Abp.Net8/module/bbs/Yi.Framework.Bbs.Domain/EventHandlers/SeeDiscussEventHandler.cs @@ -23,13 +23,9 @@ namespace Yi.Framework.Bbs.Domain.EventHandlers var entity = await _repository.GetAsync(eventData.DiscussId); if (entity is not null) { - entity.SeeNum += 1; + entity.AddSeeNumber(); await _repository.UpdateAsync(entity); } } - - - - } } diff --git a/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain/Managers/AiManager.cs b/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain/Managers/AiManager.cs index a8571f2b..7c64ea9b 100644 --- a/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain/Managers/AiManager.cs +++ b/Yi.Abp.Net8/module/chat-hub/Yi.Framework.ChatHub.Domain/Managers/AiManager.cs @@ -53,7 +53,7 @@ namespace Yi.Framework.ChatHub.Domain.Managers { if (result.Successful) { - yield return result.Choices.FirstOrDefault()?.Message.Content ?? string.Empty; + yield return result.Choices.FirstOrDefault()?.Message.Content ?? null; } else {