optimise domains

master
Young 6 months ago
parent 1149871948
commit a2ce9d08ad

@ -0,0 +1,19 @@
namespace Infrastructure.Domains;
[SugarTable]
public abstract class EntityBase<T> : IEntityBase<T> where T : class, IEquatable<T>
{
public bool IsDeleted { get; set; }
public T Id { get; set; }
public DateTime CreatedDate { get; set; }
public string? Name { get; set; }
public DateTime? UpdatedDate { get; set; }
public T CreatorId { get; set; }
public T? UpdaterId { get; set; }
}

@ -0,0 +1,8 @@
namespace Infrastructure.Domains;
public interface IDateAbility
{
DateTime CreatedDate { get; set; }
DateTime? UpdatedDate { get; set; }
}

@ -0,0 +1,9 @@
namespace Infrastructure.Domains;
/// <summary>
/// 实体类软删除接口用于filter
/// </summary>
public interface IDeletable
{
bool IsDeleted { get; set; }
}

@ -0,0 +1,14 @@
namespace Infrastructure.Domains;
public interface IEntityBase<T> : IPrimaryKey<T>, IDateAbility,IOperateAbility<T>, IDeletable where T : IEquatable<T>
{
public string? Name { get; set; }
}
public interface IOperateAbility<T> where T : IEquatable<T>
{
T CreatorId { get; set; }
T? UpdaterId { get; set; }
}

@ -0,0 +1,6 @@
namespace Infrastructure.Domains;
public interface IPrimaryKey<T> where T : IEquatable<T>
{
[SugarColumn(IsPrimaryKey = true)] public T Id { get; set; }
}

@ -1,6 +1,7 @@
using System.Security.Claims; using System.Security.Claims;
using Asp.Versioning; using Asp.Versioning;
using Asp.Versioning.ApiExplorer; using Asp.Versioning.ApiExplorer;
using Infrastructure.Domains;
using Infrastructure.Filters; using Infrastructure.Filters;
using Infrastructure.HttpUserContext; using Infrastructure.HttpUserContext;
using Infrastructure.Options; using Infrastructure.Options;
@ -318,7 +319,7 @@ public static class ServiceCollectionExtensions
IConfiguration configuration, IConfiguration configuration,
IWebHostEnvironment hostEnvironment, IWebHostEnvironment hostEnvironment,
List<ConnectionConfig>? connectionConfigs = null, List<ConnectionConfig>? connectionConfigs = null,
Action<object, DataFilterModel>? onDataChanging = null, Action<object, DataFilterModel>? onDataExecuting = null,
Action<DiffLogModel>? onDiffLogEvent = null Action<DiffLogModel>? onDiffLogEvent = null
) )
{ {
@ -397,7 +398,24 @@ public static class ServiceCollectionExtensions
}; };
} }
client.Aop.DataExecuting = onDataChanging; onDataExecuting ??= (o, entityInfo) =>
{
if (entityInfo is
{
OperationType: DataFilterType.InsertByObject, PropertyName: nameof(IDateAbility.CreatedDate)
})
{
entityInfo.SetValue(DateTime.Now);
}
if (entityInfo is
{ OperationType: DataFilterType.UpdateByObject, PropertyName: nameof(IDateAbility.UpdatedDate) })
{
entityInfo.SetValue(DateTime.Now);
}
};
client.Aop.DataExecuting = onDataExecuting;
client.Aop.OnDiffLogEvent = onDiffLogEvent; client.Aop.OnDiffLogEvent = onDiffLogEvent;
}); });
services.AddSingleton<ISqlSugarClient>(sugarScope); services.AddSingleton<ISqlSugarClient>(sugarScope);

@ -1,40 +0,0 @@
namespace Infrastructure;
/// <summary>
/// 实体类软删除接口用于filter
/// </summary>
public interface IDeletable
{
bool IsDeleted { get; set; }
}
public interface IPrimaryKey<T> where T : IEquatable<T>
{
public T Id { get; set; }
}
public interface IEntityBase<T> : IPrimaryKey<T>, IDeletable where T : IEquatable<T>
{
public DateTime CreatedDate { get; set; }
public DateTime? UpdatedDate { get; set; }
public string? Name { get; set; }
public T CreatorId { get; set; }
}
public abstract class EntityBase<T> : IEntityBase<T> where T : class, IEquatable<T>
{
public bool IsDeleted { get; set; }
public T Id { get; set; }
public DateTime CreatedDate { get; set; }
public string? Name { get; set; }
public DateTime? UpdatedDate { get; set; }
public T CreatorId { get; set; }
}
Loading…
Cancel
Save