接口修改
This commit is contained in:
@ -1,7 +1,10 @@
|
||||
using QYZH.InteractiveMagazine.Models.Entity;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using QYZH.InteractiveMagazine.Infrastructure.Context;
|
||||
using QYZH.InteractiveMagazine.Models.Entity;
|
||||
using SqlSugar;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Security.Claims;
|
||||
using Yitter.IdGenerator;
|
||||
|
||||
|
||||
@ -106,7 +109,7 @@ namespace QYZH.InteractiveMagazine.Repository.Core
|
||||
|
||||
return db;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加创建人 创建时间 更新人 更新时间 默认值
|
||||
/// </summary>
|
||||
@ -117,14 +120,20 @@ namespace QYZH.InteractiveMagazine.Repository.Core
|
||||
db.Aop.DataExecuting = (oldValue, entityInfo) =>
|
||||
{
|
||||
var entityValue = entityInfo.EntityColumnInfo.PropertyInfo.GetValue(entityInfo.EntityValue)?.ToString();
|
||||
var currnetUserName = "";
|
||||
|
||||
//var currnetUserName = "";
|
||||
//var currentNameIdentifier = ServiceContext.GetRequiredService<IHttpContextAccessor>().HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value ?? "";
|
||||
//var currentUserId = string.IsNullOrWhiteSpace(currentNameIdentifier) ? 0 : long.Parse(currentNameIdentifier);
|
||||
|
||||
var currentClaimName = ServiceContext.GetRequiredService<IHttpContextAccessor>().HttpContext?.User?.FindFirst(ClaimTypes.Name)?.Value;
|
||||
|
||||
/*** inset生效 ***/
|
||||
if (entityInfo.OperationType == DataFilterType.InsertByObject)
|
||||
{
|
||||
if (entityInfo.PropertyName == "CreatedAt" && (string.IsNullOrWhiteSpace(entityValue) || entityValue == DateTime.MinValue.ToString()))
|
||||
entityInfo.SetValue(DateTime.Now);//修改CreateTime字段
|
||||
else if (entityInfo.PropertyName == "CreatedBy" && (string.IsNullOrWhiteSpace(entityValue)))
|
||||
entityInfo.SetValue(currnetUserName);//修改创建人字段
|
||||
entityInfo.SetValue(currentClaimName);//修改创建人字段
|
||||
else if (entityInfo.PropertyName == "IsDeleted" && string.IsNullOrWhiteSpace(entityValue))
|
||||
entityInfo.SetValue("0");//修改CreateTime字段
|
||||
}
|
||||
@ -135,7 +144,7 @@ namespace QYZH.InteractiveMagazine.Repository.Core
|
||||
if (entityInfo.PropertyName == "UpdatedAt" && (string.IsNullOrWhiteSpace(entityValue) || entityValue == DateTime.MinValue.ToString()))
|
||||
entityInfo.SetValue(DateTime.Now);//修改UpdatedTime字段
|
||||
else if (entityInfo.PropertyName == "UpdatedBy" && (string.IsNullOrWhiteSpace(entityValue) || entityValue == "0"))
|
||||
entityInfo.SetValue(currnetUserName);//修改更新人字段
|
||||
entityInfo.SetValue(currentClaimName);//修改更新人字段
|
||||
}
|
||||
};
|
||||
return db;
|
||||
|
||||
Reference in New Issue
Block a user