feat: 完善aop插入审计日志

This commit is contained in:
陈淳
2023-08-08 10:35:09 +08:00
parent d62baa0e51
commit 3a61df42ea
2 changed files with 12 additions and 4 deletions

View File

@@ -108,9 +108,13 @@ namespace Yi.Framework.Infrastructure.Sqlsugar
case DataFilterType.UpdateByObject: case DataFilterType.UpdateByObject:
if (entityInfo.PropertyName.Equals(nameof(IAuditedObject.LastModificationTime))) if (entityInfo.PropertyName.Equals(nameof(IAuditedObject.LastModificationTime)))
{
//为空或者为默认最小值
if (oldValue is null || DateTime.MinValue.Equals((DateTime)oldValue))
{ {
entityInfo.SetValue(DateTime.Now); entityInfo.SetValue(DateTime.Now);
} }
}
if (entityInfo.PropertyName.Equals(nameof(IAuditedObject.LastModifierId))) if (entityInfo.PropertyName.Equals(nameof(IAuditedObject.LastModifierId)))
{ {
if (_currentUser != null) if (_currentUser != null)
@@ -121,9 +125,13 @@ namespace Yi.Framework.Infrastructure.Sqlsugar
break; break;
case DataFilterType.InsertByObject: case DataFilterType.InsertByObject:
if (entityInfo.PropertyName.Equals(nameof(IAuditedObject.CreationTime))) if (entityInfo.PropertyName.Equals(nameof(IAuditedObject.CreationTime)))
{
//为空或者为默认最小值
if (oldValue is null || DateTime.MinValue.Equals((DateTime)oldValue))
{ {
entityInfo.SetValue(DateTime.Now); entityInfo.SetValue(DateTime.Now);
} }
}
if (entityInfo.PropertyName.Equals(nameof(IAuditedObject.CreatorId))) if (entityInfo.PropertyName.Equals(nameof(IAuditedObject.CreatorId)))
{ {
if (_currentUser != null) if (_currentUser != null)

View File

@@ -36,7 +36,7 @@ public class Startup : AppStartup
services.AddSchedule(options => services.AddSchedule(options =>
{ {
// 注册作业,并配置作业触发器 // 注册作业,并配置作业触发器
options.AddJob<TestJob>(Triggers.Period(10000)); //options.AddJob<TestJob>(Triggers.Period(10000));
options.AddJob<SystemDataJob>(Triggers.Cron("0 0 0,12 ? * ?",CronStringFormat.WithSeconds)); // 表示每天凌晨与12点 options.AddJob<SystemDataJob>(Triggers.Cron("0 0 0,12 ? * ?",CronStringFormat.WithSeconds)); // 表示每天凌晨与12点
}); });
services.AddFileLogging("log/application-{0:yyyy}-{0:MM}-{0:dd}.log", options => services.AddFileLogging("log/application-{0:yyyy}-{0:MM}-{0:dd}.log", options =>