refactor:重构审计日志模块,完善用户数据权限
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
using Volo.Abp.Auditing;
|
||||
using Volo.Abp.Data;
|
||||
using Volo.Abp.Domain.Entities;
|
||||
using Volo.Abp.MultiTenancy;
|
||||
using Yi.Framework.AuditLogging.Domain.Shared.Consts;
|
||||
|
||||
namespace Yi.Framework.AuditLogging.Domain.Entities
|
||||
{
|
||||
[DisableAuditing]
|
||||
public class AuditLogAggregateRoot: AggregateRoot<Guid>, IMultiTenant
|
||||
{
|
||||
public AuditLogAggregateRoot()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public AuditLogAggregateRoot(
|
||||
Guid id,
|
||||
string applicationName,
|
||||
Guid? tenantId,
|
||||
string tenantName,
|
||||
Guid? userId,
|
||||
string userName,
|
||||
DateTime executionTime,
|
||||
int executionDuration,
|
||||
string clientIpAddress,
|
||||
string clientName,
|
||||
string clientId,
|
||||
string correlationId,
|
||||
string browserInfo,
|
||||
string httpMethod,
|
||||
string url,
|
||||
int? httpStatusCode,
|
||||
Guid? impersonatorUserId,
|
||||
string impersonatorUserName,
|
||||
Guid? impersonatorTenantId,
|
||||
string impersonatorTenantName,
|
||||
ExtraPropertyDictionary extraPropertyDictionary,
|
||||
List<EntityChangeEntity> entityChanges,
|
||||
List<AuditLogActionEntity> actions,
|
||||
string exceptions,
|
||||
string comments)
|
||||
: base(id)
|
||||
{
|
||||
ApplicationName = applicationName.Truncate(AuditLogConsts.MaxApplicationNameLength);
|
||||
TenantId = tenantId;
|
||||
TenantName = tenantName.Truncate(AuditLogConsts.MaxTenantNameLength);
|
||||
UserId = userId;
|
||||
UserName = userName.Truncate(AuditLogConsts.MaxUserNameLength);
|
||||
ExecutionTime = executionTime;
|
||||
ExecutionDuration = executionDuration;
|
||||
ClientIpAddress = clientIpAddress.Truncate(AuditLogConsts.MaxClientIpAddressLength);
|
||||
ClientName = clientName.Truncate(AuditLogConsts.MaxClientNameLength);
|
||||
ClientId = clientId.Truncate(AuditLogConsts.MaxClientIdLength);
|
||||
CorrelationId = correlationId.Truncate(AuditLogConsts.MaxCorrelationIdLength);
|
||||
BrowserInfo = browserInfo.Truncate(AuditLogConsts.MaxBrowserInfoLength);
|
||||
HttpMethod = httpMethod.Truncate(AuditLogConsts.MaxHttpMethodLength);
|
||||
Url = url.Truncate(AuditLogConsts.MaxUrlLength);
|
||||
HttpStatusCode = httpStatusCode;
|
||||
ImpersonatorUserId = impersonatorUserId;
|
||||
ImpersonatorUserName = impersonatorUserName.Truncate(AuditLogConsts.MaxUserNameLength);
|
||||
ImpersonatorTenantId = impersonatorTenantId;
|
||||
ImpersonatorTenantName = impersonatorTenantName.Truncate(AuditLogConsts.MaxTenantNameLength);
|
||||
ExtraProperties = extraPropertyDictionary;
|
||||
EntityChanges = entityChanges;
|
||||
Actions = actions;
|
||||
Exceptions = exceptions;
|
||||
Comments = comments.Truncate(AuditLogConsts.MaxCommentsLength);
|
||||
}
|
||||
|
||||
public virtual string ApplicationName { get; set; }
|
||||
|
||||
public virtual Guid? UserId { get; protected set; }
|
||||
|
||||
public virtual string UserName { 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 Guid? ImpersonatorTenantId { get; protected set; }
|
||||
|
||||
public virtual string ImpersonatorTenantName { get; protected set; }
|
||||
|
||||
public virtual DateTime ExecutionTime { get; protected set; }
|
||||
|
||||
public virtual int ExecutionDuration { get; protected set; }
|
||||
|
||||
public virtual string ClientIpAddress { get; protected set; }
|
||||
|
||||
public virtual string ClientName { get; protected set; }
|
||||
|
||||
public virtual string ClientId { get; set; }
|
||||
|
||||
public virtual string CorrelationId { get; set; }
|
||||
|
||||
public virtual string BrowserInfo { get; protected set; }
|
||||
|
||||
public virtual string HttpMethod { get; protected set; }
|
||||
|
||||
public virtual string Url { get; protected set; }
|
||||
|
||||
public virtual string Exceptions { 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; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using Volo.Abp.Auditing;
|
||||
using Volo.Abp.Data;
|
||||
using Volo.Abp.Domain.Entities;
|
||||
using Volo.Abp.MultiTenancy;
|
||||
using Yi.Framework.AuditLogging.Domain.Shared.Consts;
|
||||
|
||||
namespace Yi.Framework.AuditLogging.Domain.Entities;
|
||||
|
||||
[DisableAuditing]
|
||||
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 MethodName { get; protected set; }
|
||||
|
||||
public virtual string Parameters { get; protected set; }
|
||||
|
||||
public virtual DateTime ExecutionTime { get; protected set; }
|
||||
|
||||
public virtual int ExecutionDuration { get; protected set; }
|
||||
|
||||
|
||||
protected AuditLogActionEntity()
|
||||
{
|
||||
}
|
||||
|
||||
public AuditLogActionEntity(Guid id, Guid auditLogId, AuditLogActionInfo actionInfo, Guid? tenantId = null)
|
||||
{
|
||||
|
||||
Id = id;
|
||||
TenantId = tenantId;
|
||||
AuditLogId = auditLogId;
|
||||
ExecutionTime = actionInfo.ExecutionTime;
|
||||
ExecutionDuration = actionInfo.ExecutionDuration;
|
||||
|
||||
ServiceName = actionInfo.ServiceName.TruncateFromBeginning(AuditLogActionConsts.MaxServiceNameLength);
|
||||
MethodName = actionInfo.MethodName.TruncateFromBeginning(AuditLogActionConsts.MaxMethodNameLength);
|
||||
Parameters = actionInfo.Parameters.Length > AuditLogActionConsts.MaxParametersLength ? "" : actionInfo.Parameters;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using Volo.Abp.Auditing;
|
||||
using Volo.Abp.Domain.Entities;
|
||||
using Volo.Abp.Guids;
|
||||
using Volo.Abp.MultiTenancy;
|
||||
using Yi.Framework.AuditLogging.Domain.Shared.Consts;
|
||||
|
||||
namespace Yi.Framework.AuditLogging.Domain.Entities
|
||||
{
|
||||
public class EntityChangeEntity : Entity<Guid>, IMultiTenant
|
||||
{
|
||||
public virtual Guid AuditLogId { get; protected set; }
|
||||
|
||||
public virtual Guid? TenantId { get; protected set; }
|
||||
|
||||
public virtual DateTime ChangeTime { 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 EntityTypeFullName { get; protected set; }
|
||||
|
||||
public virtual ICollection<EntityPropertyChangeEntity> PropertyChanges { get; protected set; }
|
||||
|
||||
|
||||
public EntityChangeEntity(
|
||||
IGuidGenerator guidGenerator,
|
||||
Guid auditLogId,
|
||||
EntityChangeInfo entityChangeInfo,
|
||||
Guid? tenantId = null)
|
||||
{
|
||||
Id = guidGenerator.Create();
|
||||
AuditLogId = auditLogId;
|
||||
TenantId = tenantId;
|
||||
ChangeTime = entityChangeInfo.ChangeTime;
|
||||
ChangeType = entityChangeInfo.ChangeType;
|
||||
EntityTenantId = entityChangeInfo.EntityTenantId;
|
||||
EntityId = entityChangeInfo.EntityId.Truncate(EntityChangeConsts.MaxEntityTypeFullNameLength);
|
||||
EntityTypeFullName = entityChangeInfo.EntityTypeFullName.TruncateFromBeginning(EntityChangeConsts.MaxEntityTypeFullNameLength);
|
||||
|
||||
PropertyChanges = entityChangeInfo
|
||||
.PropertyChanges?
|
||||
.Select(p => new EntityPropertyChangeEntity(guidGenerator, Id, p, tenantId))
|
||||
.ToList()
|
||||
?? new List<EntityPropertyChangeEntity>();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.Auditing;
|
||||
using Volo.Abp.Domain.Entities;
|
||||
using Volo.Abp.Guids;
|
||||
using Volo.Abp.MultiTenancy;
|
||||
using Yi.Framework.AuditLogging.Domain.Shared.Consts;
|
||||
|
||||
namespace Yi.Framework.AuditLogging.Domain.Entities
|
||||
{
|
||||
public class EntityPropertyChangeEntity:Entity<Guid>, IMultiTenant
|
||||
{
|
||||
public EntityPropertyChangeEntity()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public EntityPropertyChangeEntity(
|
||||
IGuidGenerator guidGenerator,
|
||||
Guid entityChangeId,
|
||||
EntityPropertyChangeInfo entityChangeInfo,
|
||||
Guid? tenantId = null)
|
||||
{
|
||||
Id = guidGenerator.Create();
|
||||
TenantId = tenantId;
|
||||
EntityChangeId = entityChangeId;
|
||||
NewValue = entityChangeInfo.NewValue.Truncate(EntityPropertyChangeConsts.MaxNewValueLength);
|
||||
OriginalValue = entityChangeInfo.OriginalValue.Truncate(EntityPropertyChangeConsts.MaxOriginalValueLength);
|
||||
PropertyName = entityChangeInfo.PropertyName.TruncateFromBeginning(EntityPropertyChangeConsts.MaxPropertyNameLength);
|
||||
PropertyTypeFullName = entityChangeInfo.PropertyTypeFullName.TruncateFromBeginning(EntityPropertyChangeConsts.MaxPropertyTypeFullNameLength);
|
||||
}
|
||||
public virtual Guid? TenantId { get; protected set; }
|
||||
public virtual Guid EntityChangeId { get; protected set; }
|
||||
|
||||
public virtual string NewValue { get; protected set; }
|
||||
|
||||
public virtual string OriginalValue { get; protected set; }
|
||||
|
||||
public virtual string PropertyName { get; protected set; }
|
||||
|
||||
public virtual string PropertyTypeFullName { get; protected set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user