feat: 完成审计日志模块引入
This commit is contained in:
@@ -6,4 +6,8 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Volo.Abp.Ddd.Domain.Shared" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
namespace Yi.Framework.AuditLogging.Domain.Shared
|
||||
using Volo.Abp.Domain;
|
||||
using Volo.Abp.Modularity;
|
||||
|
||||
namespace Yi.Framework.AuditLogging.Domain.Shared
|
||||
{
|
||||
public class YiFrameworkAuditLoggingDomainSharedModule
|
||||
[DependsOn(typeof(AbpDddDomainSharedModule))]
|
||||
public class YiFrameworkAuditLoggingDomainSharedModule:AbpModule
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using SqlSugar;
|
||||
using Volo.Abp.Auditing;
|
||||
using Volo.Abp.Data;
|
||||
using Volo.Abp.Domain.Entities;
|
||||
@@ -8,24 +9,29 @@ using Yi.Framework.AuditLogging.Domain.Shared.Consts;
|
||||
namespace Yi.Framework.AuditLogging.Domain.Entities;
|
||||
|
||||
[DisableAuditing]
|
||||
[SugarTable("YiAuditLogAction")]
|
||||
[SugarIndex($"index_{nameof(AuditLogId)}", nameof(AuditLogId), OrderByType.Asc)]
|
||||
[SugarIndex($"index_{nameof(TenantId)}_{nameof(ExecutionTime)}", nameof(TenantId), OrderByType.Asc, nameof(ServiceName), OrderByType.Asc, nameof(MethodName), OrderByType.Asc, nameof(ExecutionTime), OrderByType.Asc)]
|
||||
public class AuditLogActionEntity : Entity<Guid>, IMultiTenant
|
||||
{
|
||||
public virtual Guid? TenantId { get; protected set; }
|
||||
|
||||
public virtual Guid AuditLogId { get; protected set; }
|
||||
|
||||
public virtual string ServiceName { get; protected set; }
|
||||
public virtual string? ServiceName { get; protected set; }
|
||||
|
||||
public virtual string MethodName { get; protected set; }
|
||||
public virtual string? MethodName { get; protected set; }
|
||||
|
||||
public virtual string Parameters { get; protected set; }
|
||||
public virtual string? Parameters { get; protected set; }
|
||||
|
||||
public virtual DateTime ExecutionTime { get; protected set; }
|
||||
public virtual DateTime? ExecutionTime { get; protected set; }
|
||||
|
||||
public virtual int ExecutionDuration { get; protected set; }
|
||||
public virtual int? ExecutionDuration { get; protected set; }
|
||||
|
||||
|
||||
protected AuditLogActionEntity()
|
||||
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true)]
|
||||
public override Guid Id { get; protected set; }
|
||||
public AuditLogActionEntity()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Volo.Abp.Auditing;
|
||||
using SqlSugar;
|
||||
using Volo.Abp.Auditing;
|
||||
using Volo.Abp.Data;
|
||||
using Volo.Abp.Domain.Entities;
|
||||
using Volo.Abp.MultiTenancy;
|
||||
@@ -7,6 +8,9 @@ using Yi.Framework.AuditLogging.Domain.Shared.Consts;
|
||||
namespace Yi.Framework.AuditLogging.Domain.Entities
|
||||
{
|
||||
[DisableAuditing]
|
||||
[SugarTable("YiAuditLog")]
|
||||
[SugarIndex($"index_{nameof(ExecutionTime)}", nameof(TenantId), OrderByType.Asc,nameof(ExecutionTime), OrderByType.Asc)]
|
||||
[SugarIndex($"index_{nameof(ExecutionTime)}_{nameof(UserId)}",nameof(TenantId), OrderByType.Asc, nameof(UserId), OrderByType.Asc, nameof(ExecutionTime), OrderByType.Asc)]
|
||||
public class AuditLogAggregateRoot: AggregateRoot<Guid>, IMultiTenant
|
||||
{
|
||||
public AuditLogAggregateRoot()
|
||||
@@ -68,49 +72,60 @@ namespace Yi.Framework.AuditLogging.Domain.Entities
|
||||
Comments = comments.Truncate(AuditLogConsts.MaxCommentsLength);
|
||||
}
|
||||
|
||||
public virtual string ApplicationName { get; set; }
|
||||
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true)]
|
||||
public override Guid Id { get; protected set; }
|
||||
|
||||
public virtual string? ApplicationName { get; set; }
|
||||
|
||||
public virtual Guid? UserId { get; protected set; }
|
||||
|
||||
public virtual string UserName { get; protected set; }
|
||||
public virtual string? UserName { get; protected set; }
|
||||
|
||||
public virtual string TenantName { get; protected set; }
|
||||
public virtual string? TenantName { get; protected set; }
|
||||
|
||||
public virtual Guid? ImpersonatorUserId { get; protected set; }
|
||||
|
||||
public virtual string ImpersonatorUserName { get; protected set; }
|
||||
public virtual string? ImpersonatorUserName { get; protected set; }
|
||||
|
||||
public virtual Guid? ImpersonatorTenantId { get; protected set; }
|
||||
|
||||
public virtual string ImpersonatorTenantName { get; protected set; }
|
||||
public virtual string? ImpersonatorTenantName { get; protected set; }
|
||||
|
||||
public virtual DateTime ExecutionTime { get; protected set; }
|
||||
public virtual DateTime? ExecutionTime { get; protected set; }
|
||||
|
||||
public virtual int ExecutionDuration { get; protected set; }
|
||||
public virtual int? ExecutionDuration { get; protected set; }
|
||||
|
||||
public virtual string ClientIpAddress { get; protected set; }
|
||||
public virtual string? ClientIpAddress { get; protected set; }
|
||||
|
||||
public virtual string ClientName { get; protected set; }
|
||||
public virtual string? ClientName { get; protected set; }
|
||||
|
||||
public virtual string ClientId { get; set; }
|
||||
public virtual string? ClientId { get; set; }
|
||||
|
||||
public virtual string CorrelationId { get; set; }
|
||||
public virtual string? CorrelationId { get; set; }
|
||||
|
||||
public virtual string BrowserInfo { get; protected set; }
|
||||
public virtual string? BrowserInfo { get; protected set; }
|
||||
|
||||
public virtual string HttpMethod { get; protected set; }
|
||||
public virtual string? HttpMethod { get; protected set; }
|
||||
|
||||
public virtual string Url { get; protected set; }
|
||||
public virtual string? Url { get; protected set; }
|
||||
|
||||
public virtual string Exceptions { get; protected set; }
|
||||
public virtual string? Exceptions { get; protected set; }
|
||||
|
||||
public virtual string Comments { get; protected set; }
|
||||
public virtual string? Comments { get; protected set; }
|
||||
|
||||
public virtual int? HttpStatusCode { get; set; }
|
||||
|
||||
public virtual Guid? TenantId { get; protected set; }
|
||||
public virtual List<EntityChangeEntity> EntityChanges { get; protected set; }
|
||||
|
||||
public virtual List<AuditLogActionEntity> Actions { get; protected set; }
|
||||
//导航属性
|
||||
[Navigate(NavigateType.OneToMany, nameof(EntityChangeEntity.AuditLogId))]
|
||||
public virtual List<EntityChangeEntity> EntityChanges { get; protected set; }
|
||||
|
||||
//导航属性
|
||||
[Navigate(NavigateType.OneToMany, nameof(AuditLogActionEntity.AuditLogId))]
|
||||
public virtual List<AuditLogActionEntity> Actions { get; protected set; }
|
||||
|
||||
[SugarColumn(IsIgnore = true)]
|
||||
public override ExtraPropertyDictionary ExtraProperties { get; protected set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Volo.Abp.Auditing;
|
||||
using System.Reflection;
|
||||
using SqlSugar;
|
||||
using Volo.Abp.Auditing;
|
||||
using Volo.Abp.Domain.Entities;
|
||||
using Volo.Abp.Guids;
|
||||
using Volo.Abp.MultiTenancy;
|
||||
@@ -6,23 +8,30 @@ using Yi.Framework.AuditLogging.Domain.Shared.Consts;
|
||||
|
||||
namespace Yi.Framework.AuditLogging.Domain.Entities
|
||||
{
|
||||
[SugarTable("YiEntityChange")]
|
||||
[SugarIndex($"index_{nameof(AuditLogId)}", nameof(AuditLogId), OrderByType.Asc)]
|
||||
[SugarIndex($"index_{nameof(TenantId)}_{nameof(EntityId)}", nameof(TenantId), OrderByType.Asc, nameof(EntityTypeFullName), OrderByType.Asc, nameof(EntityId), OrderByType.Asc)]
|
||||
public class EntityChangeEntity : Entity<Guid>, IMultiTenant
|
||||
{
|
||||
public EntityChangeEntity() { }
|
||||
|
||||
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true)]
|
||||
public override Guid Id { get; protected set; }
|
||||
public virtual Guid AuditLogId { get; protected set; }
|
||||
|
||||
public virtual Guid? TenantId { get; protected set; }
|
||||
|
||||
public virtual DateTime ChangeTime { get; protected set; }
|
||||
public virtual DateTime? ChangeTime { get; protected set; }
|
||||
|
||||
public virtual EntityChangeType ChangeType { get; protected set; }
|
||||
public virtual EntityChangeType? ChangeType { get; protected set; }
|
||||
|
||||
public virtual Guid? EntityTenantId { get; protected set; }
|
||||
|
||||
public virtual string EntityId { get; protected set; }
|
||||
public virtual string? EntityId { get; protected set; }
|
||||
|
||||
public virtual string EntityTypeFullName { get; protected set; }
|
||||
|
||||
public virtual ICollection<EntityPropertyChangeEntity> PropertyChanges { get; protected set; }
|
||||
public virtual string? EntityTypeFullName { get; protected set; }
|
||||
[Navigate(NavigateType.OneToMany, nameof(EntityPropertyChangeEntity.EntityChangeId))]
|
||||
public virtual List<EntityPropertyChangeEntity> PropertyChanges { get; protected set; }
|
||||
|
||||
|
||||
public EntityChangeEntity(
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SqlSugar;
|
||||
using Volo.Abp.Auditing;
|
||||
using Volo.Abp.Domain.Entities;
|
||||
using Volo.Abp.Guids;
|
||||
@@ -11,6 +12,9 @@ using Yi.Framework.AuditLogging.Domain.Shared.Consts;
|
||||
|
||||
namespace Yi.Framework.AuditLogging.Domain.Entities
|
||||
{
|
||||
[SugarTable("YiEntityPropertyChange")]
|
||||
|
||||
[SugarIndex($"index_{nameof(EntityChangeId)}", nameof(EntityChangeId), OrderByType.Asc)]
|
||||
public class EntityPropertyChangeEntity:Entity<Guid>, IMultiTenant
|
||||
{
|
||||
public EntityPropertyChangeEntity()
|
||||
@@ -33,15 +37,18 @@ namespace Yi.Framework.AuditLogging.Domain.Entities
|
||||
PropertyName = entityChangeInfo.PropertyName.TruncateFromBeginning(EntityPropertyChangeConsts.MaxPropertyNameLength);
|
||||
PropertyTypeFullName = entityChangeInfo.PropertyTypeFullName.TruncateFromBeginning(EntityPropertyChangeConsts.MaxPropertyTypeFullNameLength);
|
||||
}
|
||||
|
||||
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true)]
|
||||
public override Guid Id { get; protected set; }
|
||||
public virtual Guid? TenantId { get; protected set; }
|
||||
public virtual Guid EntityChangeId { get; protected set; }
|
||||
public virtual Guid? EntityChangeId { get; protected set; }
|
||||
|
||||
public virtual string NewValue { get; protected set; }
|
||||
public virtual string? NewValue { get; protected set; }
|
||||
|
||||
public virtual string OriginalValue { get; protected set; }
|
||||
public virtual string? OriginalValue { get; protected set; }
|
||||
|
||||
public virtual string PropertyName { get; protected set; }
|
||||
public virtual string? PropertyName { get; protected set; }
|
||||
|
||||
public virtual string PropertyTypeFullName { get; protected set; }
|
||||
public virtual string? PropertyTypeFullName { get; protected set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Volo.Abp.Auditing;
|
||||
using Volo.Abp.Domain;
|
||||
using Volo.Abp.Modularity;
|
||||
using Yi.Framework.AuditLogging.Domain.Shared;
|
||||
|
||||
namespace Yi.Framework.AuditLogging.Domain
|
||||
{
|
||||
[DependsOn(typeof(YiFrameworkAuditLoggingDomainSharedModule),
|
||||
|
||||
|
||||
typeof(AbpDddDomainModule),
|
||||
typeof(AbpAuditingModule)
|
||||
)]
|
||||
public class YiFrameworkAuditLoggingDomainModule:AbpModule
|
||||
{
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
|
||||
@@ -16,6 +16,21 @@ public class SqlSugarCoreAuditLogRepository : SqlSugarRepository<AuditLogAggrega
|
||||
public SqlSugarCoreAuditLogRepository(ISugarDbContextProvider<ISqlSugarDbContext> sugarDbContextProvider) : base(sugarDbContextProvider)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写插入,支持导航属性
|
||||
/// </summary>
|
||||
/// <param name="insertObj"></param>
|
||||
/// <returns></returns>
|
||||
public override async Task<bool> InsertAsync(AuditLogAggregateRoot insertObj)
|
||||
{
|
||||
|
||||
return await _Db.InsertNav<AuditLogAggregateRoot>(insertObj)
|
||||
.Include(z1 => z1.Actions)
|
||||
//.Include(z1 => z1.EntityChanges).ThenInclude(z2 => z2.PropertyChanges)
|
||||
.ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
public virtual async Task<List<AuditLogAggregateRoot>> GetListAsync(
|
||||
string sorting = null,
|
||||
int maxResultCount = 50,
|
||||
@@ -138,11 +153,11 @@ public class SqlSugarCoreAuditLogRepository : SqlSugarRepository<AuditLogAggrega
|
||||
var result = await _DbQueryable
|
||||
.Where(a => a.ExecutionTime < endDate.AddDays(1) && a.ExecutionTime > startDate)
|
||||
.OrderBy(t => t.ExecutionTime)
|
||||
.GroupBy(t => new { t.ExecutionTime.Date })
|
||||
.GroupBy(t => new { t.ExecutionTime.Value.Date })
|
||||
.Select(g => new { Day = SqlFunc.AggregateMin(g.ExecutionTime), avgExecutionTime = SqlFunc.AggregateAvg(g.ExecutionDuration) })
|
||||
.ToListAsync();
|
||||
|
||||
return result.ToDictionary(element => element.Day.ClearTime(), element => (double)element.avgExecutionTime);
|
||||
return result.ToDictionary(element => element.Day.Value.ClearTime(), element => (double)element.avgExecutionTime);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Volo.Abp.Modularity;
|
||||
using Yi.Framework.AuditLogging.Domain;
|
||||
using Yi.Framework.AuditLogging.Domain.Repositories;
|
||||
using Yi.Framework.AuditLogging.SqlSugarCore.Repositories;
|
||||
using Yi.Framework.SqlSugarCore;
|
||||
|
||||
namespace Yi.AuditLogging.SqlSugarCore
|
||||
{
|
||||
[DependsOn(typeof(YiFrameworkSqlSugarCoreModule))]
|
||||
[DependsOn(
|
||||
typeof(YiFrameworkAuditLoggingDomainModule),
|
||||
|
||||
typeof(YiFrameworkSqlSugarCoreModule))]
|
||||
public class YiFrameworkAuditLoggingSqlSugarCoreModule : AbpModule
|
||||
{
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
|
||||
@@ -9,7 +9,7 @@ using Yi.Framework.SqlSugarCore.Abstractions;
|
||||
|
||||
namespace Yi.Framework.TenantManagement.Domain
|
||||
{
|
||||
[SugarTable("Tenant")]
|
||||
[SugarTable("YiTenant")]
|
||||
[MasterTenant]
|
||||
public class TenantAggregateRoot : FullAuditedAggregateRoot<Guid>, IHasEntityVersion
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user