feat: db操作支持不修改更新审计日志

This commit is contained in:
橙子
2025-02-05 00:02:04 +08:00
parent e69bbb46b3
commit 5d286ebc9e
4 changed files with 23 additions and 8 deletions

View File

@@ -61,7 +61,12 @@ public class DefaultSqlSugarDbContext : SqlSugarDbContext
if (entityInfo.PropertyName.Equals(nameof(IAuditedObject.LastModificationTime))) 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); entityInfo.SetValue(DateTime.Now);
} }
@@ -70,7 +75,12 @@ public class DefaultSqlSugarDbContext : SqlSugarDbContext
{ {
if (typeof(Guid?) == entityInfo.EntityColumnInfo.PropertyInfo.PropertyType) 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); entityInfo.SetValue(CurrentUser.Id);
} }

View File

@@ -24,6 +24,15 @@ namespace Yi.Framework.Bbs.Domain.Entities.Forum
PlateId = plateId; PlateId = plateId;
} }
public void AddSeeNumber()
{
this.SeeNum += 1;
//设置最小值,不更新
this.LastModificationTime = DateTime.MinValue;
//设置空值,不更新
this.LastModifierId = Guid.Empty;
}
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true)] [SugarColumn(ColumnName = "Id", IsPrimaryKey = true)]
public override Guid Id { get; protected set; } public override Guid Id { get; protected set; }
public string? Title { get; set; } public string? Title { get; set; }

View File

@@ -23,13 +23,9 @@ namespace Yi.Framework.Bbs.Domain.EventHandlers
var entity = await _repository.GetAsync(eventData.DiscussId); var entity = await _repository.GetAsync(eventData.DiscussId);
if (entity is not null) if (entity is not null)
{ {
entity.SeeNum += 1; entity.AddSeeNumber();
await _repository.UpdateAsync(entity); await _repository.UpdateAsync(entity);
} }
} }
} }
} }

View File

@@ -53,7 +53,7 @@ namespace Yi.Framework.ChatHub.Domain.Managers
{ {
if (result.Successful) if (result.Successful)
{ {
yield return result.Choices.FirstOrDefault()?.Message.Content ?? string.Empty; yield return result.Choices.FirstOrDefault()?.Message.Content ?? null;
} }
else else
{ {