feat: 完成审计日志模块引入

This commit is contained in:
陈淳
2024-01-23 15:08:01 +08:00
parent 96ae77e5ab
commit e9b5147743
19 changed files with 183 additions and 101 deletions

View File

@@ -51,22 +51,22 @@ namespace Yi.Framework.SqlSugarCore.Repositories
#region Abp模块 #region Abp模块
public async Task<TEntity?> FindAsync(Expression<Func<TEntity, bool>> predicate, bool includeDetails = true, CancellationToken cancellationToken = default) public virtual async Task<TEntity?> FindAsync(Expression<Func<TEntity, bool>> predicate, bool includeDetails = true, CancellationToken cancellationToken = default)
{ {
return await GetFirstAsync(predicate); return await GetFirstAsync(predicate);
} }
public async Task<TEntity> GetAsync(Expression<Func<TEntity, bool>> predicate, bool includeDetails = true, CancellationToken cancellationToken = default) public virtual async Task<TEntity> GetAsync(Expression<Func<TEntity, bool>> predicate, bool includeDetails = true, CancellationToken cancellationToken = default)
{ {
return await GetFirstAsync(predicate); return await GetFirstAsync(predicate);
} }
public async Task DeleteAsync(Expression<Func<TEntity, bool>> predicate, bool autoSave = false, CancellationToken cancellationToken = default) public virtual async Task DeleteAsync(Expression<Func<TEntity, bool>> predicate, bool autoSave = false, CancellationToken cancellationToken = default)
{ {
await this.DeleteAsync(predicate); await this.DeleteAsync(predicate);
} }
public async Task DeleteDirectAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default) public virtual async Task DeleteDirectAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default)
{ {
await this.DeleteAsync(predicate); await this.DeleteAsync(predicate);
} }
@@ -96,53 +96,53 @@ namespace Yi.Framework.SqlSugarCore.Repositories
throw new NotImplementedException(); throw new NotImplementedException();
} }
public async Task<List<TEntity>> GetListAsync(Expression<Func<TEntity, bool>> predicate, bool includeDetails = false, CancellationToken cancellationToken = default) public virtual async Task<List<TEntity>> GetListAsync(Expression<Func<TEntity, bool>> predicate, bool includeDetails = false, CancellationToken cancellationToken = default)
{ {
return await GetListAsync(predicate); return await GetListAsync(predicate);
} }
public async Task<TEntity> InsertAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default) public virtual async Task<TEntity> InsertAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default)
{ {
return await InsertReturnEntityAsync(entity); return await InsertReturnEntityAsync(entity);
} }
public async Task InsertManyAsync(IEnumerable<TEntity> entities, bool autoSave = false, CancellationToken cancellationToken = default) public virtual async Task InsertManyAsync(IEnumerable<TEntity> entities, bool autoSave = false, CancellationToken cancellationToken = default)
{ {
await InsertRangeAsync(entities.ToList()); await InsertRangeAsync(entities.ToList());
} }
public async Task<TEntity> UpdateAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default) public virtual async Task<TEntity> UpdateAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default)
{ {
await UpdateAsync(entity); await UpdateAsync(entity);
return entity; return entity;
} }
public async Task UpdateManyAsync(IEnumerable<TEntity> entities, bool autoSave = false, CancellationToken cancellationToken = default) public virtual async Task UpdateManyAsync(IEnumerable<TEntity> entities, bool autoSave = false, CancellationToken cancellationToken = default)
{ {
await UpdateRangeAsync(entities.ToList()); await UpdateRangeAsync(entities.ToList());
} }
public async Task DeleteAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default) public virtual async Task DeleteAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default)
{ {
await DeleteAsync(entity); await DeleteAsync(entity);
} }
public async Task DeleteManyAsync(IEnumerable<TEntity> entities, bool autoSave = false, CancellationToken cancellationToken = default) public virtual async Task DeleteManyAsync(IEnumerable<TEntity> entities, bool autoSave = false, CancellationToken cancellationToken = default)
{ {
await DeleteAsync(entities.ToList()); await DeleteAsync(entities.ToList());
} }
public async Task<List<TEntity>> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default) public virtual async Task<List<TEntity>> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default)
{ {
return await GetListAsync(); return await GetListAsync();
} }
public async Task<long> GetCountAsync(CancellationToken cancellationToken = default) public virtual async Task<long> GetCountAsync(CancellationToken cancellationToken = default)
{ {
return await this.CountAsync(); return await this.CountAsync();
} }
public async Task<List<TEntity>> GetPagedListAsync(int skipCount, int maxResultCount, string sorting, bool includeDetails = false, CancellationToken cancellationToken = default) public virtual async Task<List<TEntity>> GetPagedListAsync(int skipCount, int maxResultCount, string sorting, bool includeDetails = false, CancellationToken cancellationToken = default)
{ {
return await GetPageListAsync(_ => true, skipCount, maxResultCount); return await GetPageListAsync(_ => true, skipCount, maxResultCount);
} }
@@ -150,69 +150,69 @@ namespace Yi.Framework.SqlSugarCore.Repositories
#region DB快捷操作 #region DB快捷操作
public async Task<IDeleteable<TEntity>> AsDeleteable() public virtual async Task<IDeleteable<TEntity>> AsDeleteable()
{ {
return (await GetDbSimpleClientAsync()).AsDeleteable(); return (await GetDbSimpleClientAsync()).AsDeleteable();
} }
public async Task<IInsertable<TEntity>> AsInsertable(List<TEntity> insertObjs) public virtual async Task<IInsertable<TEntity>> AsInsertable(List<TEntity> insertObjs)
{ {
return (await GetDbSimpleClientAsync()).AsInsertable(insertObjs); return (await GetDbSimpleClientAsync()).AsInsertable(insertObjs);
} }
public async Task<IInsertable<TEntity>> AsInsertable(TEntity insertObj) public virtual async Task<IInsertable<TEntity>> AsInsertable(TEntity insertObj)
{ {
return (await GetDbSimpleClientAsync()).AsInsertable(insertObj); return (await GetDbSimpleClientAsync()).AsInsertable(insertObj);
} }
public async Task<IInsertable<TEntity>> AsInsertable(TEntity[] insertObjs) public virtual async Task<IInsertable<TEntity>> AsInsertable(TEntity[] insertObjs)
{ {
return (await GetDbSimpleClientAsync()).AsInsertable(insertObjs); return (await GetDbSimpleClientAsync()).AsInsertable(insertObjs);
} }
public async Task<ISugarQueryable<TEntity>> AsQueryable() public virtual async Task<ISugarQueryable<TEntity>> AsQueryable()
{ {
return (await GetDbSimpleClientAsync()).AsQueryable(); return (await GetDbSimpleClientAsync()).AsQueryable();
} }
public async Task<ISqlSugarClient> AsSugarClient() public virtual async Task<ISqlSugarClient> AsSugarClient()
{ {
return (await GetDbSimpleClientAsync()).AsSugarClient(); return (await GetDbSimpleClientAsync()).AsSugarClient();
} }
public async Task<ITenant> AsTenant() public virtual async Task<ITenant> AsTenant()
{ {
return (await GetDbSimpleClientAsync()).AsTenant(); return (await GetDbSimpleClientAsync()).AsTenant();
} }
public async Task<IUpdateable<TEntity>> AsUpdateable(List<TEntity> updateObjs) public virtual async Task<IUpdateable<TEntity>> AsUpdateable(List<TEntity> updateObjs)
{ {
return (await GetDbSimpleClientAsync()).AsUpdateable(updateObjs); return (await GetDbSimpleClientAsync()).AsUpdateable(updateObjs);
} }
public async Task<IUpdateable<TEntity>> AsUpdateable(TEntity updateObj) public virtual async Task<IUpdateable<TEntity>> AsUpdateable(TEntity updateObj)
{ {
return (await GetDbSimpleClientAsync()).AsUpdateable(updateObj); return (await GetDbSimpleClientAsync()).AsUpdateable(updateObj);
} }
public async Task<IUpdateable<TEntity>> AsUpdateable() public virtual async Task<IUpdateable<TEntity>> AsUpdateable()
{ {
return (await GetDbSimpleClientAsync()).AsUpdateable(); return (await GetDbSimpleClientAsync()).AsUpdateable();
} }
public async Task<IUpdateable<TEntity>> AsUpdateable(TEntity[] updateObjs) public virtual async Task<IUpdateable<TEntity>> AsUpdateable(TEntity[] updateObjs)
{ {
return (await GetDbSimpleClientAsync()).AsUpdateable(updateObjs); return (await GetDbSimpleClientAsync()).AsUpdateable(updateObjs);
} }
#endregion #endregion
#region SimpleClient模块 #region SimpleClient模块
public async Task<int> CountAsync(Expression<Func<TEntity, bool>> whereExpression) public virtual async Task<int> CountAsync(Expression<Func<TEntity, bool>> whereExpression)
{ {
return await (await GetDbSimpleClientAsync()).CountAsync(whereExpression); return await (await GetDbSimpleClientAsync()).CountAsync(whereExpression);
} }
public async Task<bool> DeleteAsync(TEntity deleteObj) public virtual async Task<bool> DeleteAsync(TEntity deleteObj)
{ {
if (deleteObj is ISoftDelete) if (deleteObj is ISoftDelete)
{ {
@@ -226,7 +226,7 @@ namespace Yi.Framework.SqlSugarCore.Repositories
} }
public async Task<bool> DeleteAsync(List<TEntity> deleteObjs) public virtual async Task<bool> DeleteAsync(List<TEntity> deleteObjs)
{ {
if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity))) if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity)))
{ {
@@ -239,7 +239,7 @@ namespace Yi.Framework.SqlSugarCore.Repositories
} }
} }
public async Task<bool> DeleteAsync(Expression<Func<TEntity, bool>> whereExpression) public virtual async Task<bool> DeleteAsync(Expression<Func<TEntity, bool>> whereExpression)
{ {
if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity))) if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity)))
{ {
@@ -252,7 +252,7 @@ namespace Yi.Framework.SqlSugarCore.Repositories
} }
public async Task<bool> DeleteByIdAsync(dynamic id) public virtual async Task<bool> DeleteByIdAsync(dynamic id)
{ {
if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity))) if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity)))
{ {
@@ -267,7 +267,7 @@ namespace Yi.Framework.SqlSugarCore.Repositories
} }
} }
public async Task<bool> DeleteByIdsAsync(dynamic[] ids) public virtual async Task<bool> DeleteByIdsAsync(dynamic[] ids)
{ {
if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity))) if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity)))
{ {
@@ -288,101 +288,101 @@ namespace Yi.Framework.SqlSugarCore.Repositories
} }
public async Task<TEntity> GetByIdAsync(dynamic id) public virtual async Task<TEntity> GetByIdAsync(dynamic id)
{ {
return await (await GetDbSimpleClientAsync()).GetByIdAsync(id); return await (await GetDbSimpleClientAsync()).GetByIdAsync(id);
} }
public async Task<TEntity> GetFirstAsync(Expression<Func<TEntity, bool>> whereExpression) public virtual async Task<TEntity> GetFirstAsync(Expression<Func<TEntity, bool>> whereExpression)
{ {
return await (await GetDbSimpleClientAsync()).GetFirstAsync(whereExpression); return await (await GetDbSimpleClientAsync()).GetFirstAsync(whereExpression);
} }
public async Task<List<TEntity>> GetListAsync() public virtual async Task<List<TEntity>> GetListAsync()
{ {
return await (await GetDbSimpleClientAsync()).GetListAsync(); return await (await GetDbSimpleClientAsync()).GetListAsync();
} }
public async Task<List<TEntity>> GetListAsync(Expression<Func<TEntity, bool>> whereExpression) public virtual async Task<List<TEntity>> GetListAsync(Expression<Func<TEntity, bool>> whereExpression)
{ {
return await (await GetDbSimpleClientAsync()).GetListAsync(whereExpression); return await (await GetDbSimpleClientAsync()).GetListAsync(whereExpression);
} }
public async Task<List<TEntity>> GetPageListAsync(Expression<Func<TEntity, bool>> whereExpression, int pageNum, int pageSize) public virtual async Task<List<TEntity>> GetPageListAsync(Expression<Func<TEntity, bool>> whereExpression, int pageNum, int pageSize)
{ {
return await (await GetDbSimpleClientAsync()).GetPageListAsync(whereExpression, new PageModel() { PageIndex = pageNum, PageSize = pageSize }); return await (await GetDbSimpleClientAsync()).GetPageListAsync(whereExpression, new PageModel() { PageIndex = pageNum, PageSize = pageSize });
} }
public async Task<List<TEntity>> GetPageListAsync(Expression<Func<TEntity, bool>> whereExpression, int pageNum, int pageSize, Expression<Func<TEntity, object>>? orderByExpression = null, OrderByType orderByType = OrderByType.Asc) public virtual async Task<List<TEntity>> GetPageListAsync(Expression<Func<TEntity, bool>> whereExpression, int pageNum, int pageSize, Expression<Func<TEntity, object>>? orderByExpression = null, OrderByType orderByType = OrderByType.Asc)
{ {
return await (await GetDbSimpleClientAsync()).GetPageListAsync(whereExpression, new PageModel { PageIndex = pageNum, PageSize = pageSize }, orderByExpression, orderByType); return await (await GetDbSimpleClientAsync()).GetPageListAsync(whereExpression, new PageModel { PageIndex = pageNum, PageSize = pageSize }, orderByExpression, orderByType);
} }
public async Task<TEntity> GetSingleAsync(Expression<Func<TEntity, bool>> whereExpression) public virtual async Task<TEntity> GetSingleAsync(Expression<Func<TEntity, bool>> whereExpression)
{ {
return await (await GetDbSimpleClientAsync()).GetSingleAsync(whereExpression); return await (await GetDbSimpleClientAsync()).GetSingleAsync(whereExpression);
} }
public async Task<bool> InsertAsync(TEntity insertObj) public virtual async Task<bool> InsertAsync(TEntity insertObj)
{ {
return await (await GetDbSimpleClientAsync()).InsertAsync(insertObj); return await (await GetDbSimpleClientAsync()).InsertAsync(insertObj);
} }
public async Task<bool> InsertOrUpdateAsync(TEntity data) public virtual async Task<bool> InsertOrUpdateAsync(TEntity data)
{ {
return await (await GetDbSimpleClientAsync()).InsertOrUpdateAsync(data); return await (await GetDbSimpleClientAsync()).InsertOrUpdateAsync(data);
} }
public async Task<bool> InsertOrUpdateAsync(List<TEntity> datas) public virtual async Task<bool> InsertOrUpdateAsync(List<TEntity> datas)
{ {
return await (await GetDbSimpleClientAsync()).InsertOrUpdateAsync(datas); return await (await GetDbSimpleClientAsync()).InsertOrUpdateAsync(datas);
} }
public async Task<bool> InsertRangeAsync(List<TEntity> insertObjs) public virtual async Task<bool> InsertRangeAsync(List<TEntity> insertObjs)
{ {
return await (await GetDbSimpleClientAsync()).InsertRangeAsync(insertObjs); return await (await GetDbSimpleClientAsync()).InsertRangeAsync(insertObjs);
} }
public async Task<long> InsertReturnBigIdentityAsync(TEntity insertObj) public virtual async Task<long> InsertReturnBigIdentityAsync(TEntity insertObj)
{ {
return await (await GetDbSimpleClientAsync()).InsertReturnBigIdentityAsync(insertObj); return await (await GetDbSimpleClientAsync()).InsertReturnBigIdentityAsync(insertObj);
} }
public async Task<TEntity> InsertReturnEntityAsync(TEntity insertObj) public virtual async Task<TEntity> InsertReturnEntityAsync(TEntity insertObj)
{ {
return await (await GetDbSimpleClientAsync()).InsertReturnEntityAsync(insertObj); return await (await GetDbSimpleClientAsync()).InsertReturnEntityAsync(insertObj);
} }
public async Task<int> InsertReturnIdentityAsync(TEntity insertObj) public virtual async Task<int> InsertReturnIdentityAsync(TEntity insertObj)
{ {
return await (await GetDbSimpleClientAsync()).InsertReturnIdentityAsync(insertObj); return await (await GetDbSimpleClientAsync()).InsertReturnIdentityAsync(insertObj);
} }
public async Task<long> InsertReturnSnowflakeIdAsync(TEntity insertObj) public virtual async Task<long> InsertReturnSnowflakeIdAsync(TEntity insertObj)
{ {
return await (await GetDbSimpleClientAsync()).InsertReturnSnowflakeIdAsync(insertObj); return await (await GetDbSimpleClientAsync()).InsertReturnSnowflakeIdAsync(insertObj);
} }
public async Task<bool> IsAnyAsync(Expression<Func<TEntity, bool>> whereExpression) public virtual async Task<bool> IsAnyAsync(Expression<Func<TEntity, bool>> whereExpression)
{ {
return await (await GetDbSimpleClientAsync()).IsAnyAsync(whereExpression); return await (await GetDbSimpleClientAsync()).IsAnyAsync(whereExpression);
} }
public async Task<bool> UpdateAsync(TEntity updateObj) public virtual async Task<bool> UpdateAsync(TEntity updateObj)
{ {
return await (await GetDbSimpleClientAsync()).UpdateAsync(updateObj); return await (await GetDbSimpleClientAsync()).UpdateAsync(updateObj);
} }
public async Task<bool> UpdateAsync(Expression<Func<TEntity, TEntity>> columns, Expression<Func<TEntity, bool>> whereExpression) public virtual async Task<bool> UpdateAsync(Expression<Func<TEntity, TEntity>> columns, Expression<Func<TEntity, bool>> whereExpression)
{ {
return await (await GetDbSimpleClientAsync()).UpdateAsync(columns, whereExpression); return await (await GetDbSimpleClientAsync()).UpdateAsync(columns, whereExpression);
} }
public async Task<bool> UpdateRangeAsync(List<TEntity> updateObjs) public virtual async Task<bool> UpdateRangeAsync(List<TEntity> updateObjs)
{ {
return await (await GetDbSimpleClientAsync()).UpdateRangeAsync(updateObjs); return await (await GetDbSimpleClientAsync()).UpdateRangeAsync(updateObjs);
} }
@@ -396,22 +396,22 @@ namespace Yi.Framework.SqlSugarCore.Repositories
{ {
} }
public async Task DeleteAsync(TKey id, bool autoSave = false, CancellationToken cancellationToken = default) public virtual async Task DeleteAsync(TKey id, bool autoSave = false, CancellationToken cancellationToken = default)
{ {
await DeleteByIdAsync(id); await DeleteByIdAsync(id);
} }
public async Task DeleteManyAsync(IEnumerable<TKey> ids, bool autoSave = false, CancellationToken cancellationToken = default) public virtual async Task DeleteManyAsync(IEnumerable<TKey> ids, bool autoSave = false, CancellationToken cancellationToken = default)
{ {
await DeleteByIdsAsync(ids.Select(x => (object)x).ToArray()); await DeleteByIdsAsync(ids.Select(x => (object)x).ToArray());
} }
public async Task<TEntity?> FindAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default) public virtual async Task<TEntity?> FindAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default)
{ {
return await GetByIdAsync(id); return await GetByIdAsync(id);
} }
public async Task<TEntity> GetAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default) public virtual async Task<TEntity> GetAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default)
{ {
return await GetByIdAsync(id); return await GetByIdAsync(id);
} }

View File

@@ -36,8 +36,6 @@ namespace Yi.Framework.SqlSugarCore
service.AddTransient(typeof(ISqlSugarRepository<>), typeof(SqlSugarRepository<>)); service.AddTransient(typeof(ISqlSugarRepository<>), typeof(SqlSugarRepository<>));
service.AddTransient(typeof(ISqlSugarRepository<,>), typeof(SqlSugarRepository<,>)); service.AddTransient(typeof(ISqlSugarRepository<,>), typeof(SqlSugarRepository<,>));
service.AddTransient<IAuditingStore, SqlSugarLogAuditingStore>();
service.AddTransient(typeof(ISugarDbContextProvider<>), typeof(UnitOfWorkSqlsugarDbContextProvider<>)); service.AddTransient(typeof(ISugarDbContextProvider<>), typeof(UnitOfWorkSqlsugarDbContextProvider<>));

View File

@@ -6,4 +6,8 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Volo.Abp.Ddd.Domain.Shared" Version="8.0.0" />
</ItemGroup>
</Project> </Project>

View File

@@ -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
{ {
} }

View File

@@ -1,4 +1,5 @@
using System; using System;
using SqlSugar;
using Volo.Abp.Auditing; using Volo.Abp.Auditing;
using Volo.Abp.Data; using Volo.Abp.Data;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
@@ -8,24 +9,29 @@ using Yi.Framework.AuditLogging.Domain.Shared.Consts;
namespace Yi.Framework.AuditLogging.Domain.Entities; namespace Yi.Framework.AuditLogging.Domain.Entities;
[DisableAuditing] [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 class AuditLogActionEntity : Entity<Guid>, IMultiTenant
{ {
public virtual Guid? TenantId { get; protected set; } public virtual Guid? TenantId { get; protected set; }
public virtual Guid AuditLogId { 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()
{ {
} }

View File

@@ -1,4 +1,5 @@
using Volo.Abp.Auditing; using SqlSugar;
using Volo.Abp.Auditing;
using Volo.Abp.Data; using Volo.Abp.Data;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
@@ -7,6 +8,9 @@ using Yi.Framework.AuditLogging.Domain.Shared.Consts;
namespace Yi.Framework.AuditLogging.Domain.Entities namespace Yi.Framework.AuditLogging.Domain.Entities
{ {
[DisableAuditing] [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 class AuditLogAggregateRoot: AggregateRoot<Guid>, IMultiTenant
{ {
public AuditLogAggregateRoot() public AuditLogAggregateRoot()
@@ -68,49 +72,60 @@ namespace Yi.Framework.AuditLogging.Domain.Entities
Comments = comments.Truncate(AuditLogConsts.MaxCommentsLength); 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 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 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 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 int? HttpStatusCode { get; set; }
public virtual Guid? TenantId { get; protected 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; }
} }
} }

View File

@@ -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.Domain.Entities;
using Volo.Abp.Guids; using Volo.Abp.Guids;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
@@ -6,23 +8,30 @@ using Yi.Framework.AuditLogging.Domain.Shared.Consts;
namespace Yi.Framework.AuditLogging.Domain.Entities 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 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 AuditLogId { get; protected set; }
public virtual Guid? TenantId { 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 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 string? EntityTypeFullName { get; protected set; }
[Navigate(NavigateType.OneToMany, nameof(EntityPropertyChangeEntity.EntityChangeId))]
public virtual ICollection<EntityPropertyChangeEntity> PropertyChanges { get; protected set; } public virtual List<EntityPropertyChangeEntity> PropertyChanges { get; protected set; }
public EntityChangeEntity( public EntityChangeEntity(

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using SqlSugar;
using Volo.Abp.Auditing; using Volo.Abp.Auditing;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
using Volo.Abp.Guids; using Volo.Abp.Guids;
@@ -11,6 +12,9 @@ using Yi.Framework.AuditLogging.Domain.Shared.Consts;
namespace Yi.Framework.AuditLogging.Domain.Entities namespace Yi.Framework.AuditLogging.Domain.Entities
{ {
[SugarTable("YiEntityPropertyChange")]
[SugarIndex($"index_{nameof(EntityChangeId)}", nameof(EntityChangeId), OrderByType.Asc)]
public class EntityPropertyChangeEntity:Entity<Guid>, IMultiTenant public class EntityPropertyChangeEntity:Entity<Guid>, IMultiTenant
{ {
public EntityPropertyChangeEntity() public EntityPropertyChangeEntity()
@@ -33,15 +37,18 @@ namespace Yi.Framework.AuditLogging.Domain.Entities
PropertyName = entityChangeInfo.PropertyName.TruncateFromBeginning(EntityPropertyChangeConsts.MaxPropertyNameLength); PropertyName = entityChangeInfo.PropertyName.TruncateFromBeginning(EntityPropertyChangeConsts.MaxPropertyNameLength);
PropertyTypeFullName = entityChangeInfo.PropertyTypeFullName.TruncateFromBeginning(EntityPropertyChangeConsts.MaxPropertyTypeFullNameLength); 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? 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; }
} }
} }

View File

@@ -1,8 +1,17 @@
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Auditing;
using Volo.Abp.Domain;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Yi.Framework.AuditLogging.Domain.Shared;
namespace Yi.Framework.AuditLogging.Domain namespace Yi.Framework.AuditLogging.Domain
{ {
[DependsOn(typeof(YiFrameworkAuditLoggingDomainSharedModule),
typeof(AbpDddDomainModule),
typeof(AbpAuditingModule)
)]
public class YiFrameworkAuditLoggingDomainModule:AbpModule public class YiFrameworkAuditLoggingDomainModule:AbpModule
{ {
public override void ConfigureServices(ServiceConfigurationContext context) public override void ConfigureServices(ServiceConfigurationContext context)

View File

@@ -16,6 +16,21 @@ public class SqlSugarCoreAuditLogRepository : SqlSugarRepository<AuditLogAggrega
public SqlSugarCoreAuditLogRepository(ISugarDbContextProvider<ISqlSugarDbContext> sugarDbContextProvider) : base(sugarDbContextProvider) 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( public virtual async Task<List<AuditLogAggregateRoot>> GetListAsync(
string sorting = null, string sorting = null,
int maxResultCount = 50, int maxResultCount = 50,
@@ -138,11 +153,11 @@ public class SqlSugarCoreAuditLogRepository : SqlSugarRepository<AuditLogAggrega
var result = await _DbQueryable var result = await _DbQueryable
.Where(a => a.ExecutionTime < endDate.AddDays(1) && a.ExecutionTime > startDate) .Where(a => a.ExecutionTime < endDate.AddDays(1) && a.ExecutionTime > startDate)
.OrderBy(t => t.ExecutionTime) .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) }) .Select(g => new { Day = SqlFunc.AggregateMin(g.ExecutionTime), avgExecutionTime = SqlFunc.AggregateAvg(g.ExecutionDuration) })
.ToListAsync(); .ToListAsync();
return result.ToDictionary(element => element.Day.ClearTime(), element => (double)element.avgExecutionTime); return result.ToDictionary(element => element.Day.Value.ClearTime(), element => (double)element.avgExecutionTime);
} }

View File

@@ -1,12 +1,16 @@
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Yi.Framework.AuditLogging.Domain;
using Yi.Framework.AuditLogging.Domain.Repositories; using Yi.Framework.AuditLogging.Domain.Repositories;
using Yi.Framework.AuditLogging.SqlSugarCore.Repositories; using Yi.Framework.AuditLogging.SqlSugarCore.Repositories;
using Yi.Framework.SqlSugarCore; using Yi.Framework.SqlSugarCore;
namespace Yi.AuditLogging.SqlSugarCore namespace Yi.AuditLogging.SqlSugarCore
{ {
[DependsOn(typeof(YiFrameworkSqlSugarCoreModule))] [DependsOn(
typeof(YiFrameworkAuditLoggingDomainModule),
typeof(YiFrameworkSqlSugarCoreModule))]
public class YiFrameworkAuditLoggingSqlSugarCoreModule : AbpModule public class YiFrameworkAuditLoggingSqlSugarCoreModule : AbpModule
{ {
public override void ConfigureServices(ServiceConfigurationContext context) public override void ConfigureServices(ServiceConfigurationContext context)

View File

@@ -9,7 +9,7 @@ using Yi.Framework.SqlSugarCore.Abstractions;
namespace Yi.Framework.TenantManagement.Domain namespace Yi.Framework.TenantManagement.Domain
{ {
[SugarTable("Tenant")] [SugarTable("YiTenant")]
[MasterTenant] [MasterTenant]
public class TenantAggregateRoot : FullAuditedAggregateRoot<Guid>, IHasEntityVersion public class TenantAggregateRoot : FullAuditedAggregateRoot<Guid>, IHasEntityVersion
{ {

View File

@@ -6,6 +6,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\module\audit-logging\Yi.Framework.AuditLogging.Domain.Shared\Yi.Framework.AuditLogging.Domain.Shared.csproj" />
<ProjectReference Include="..\..\module\bbs\Yi.Framework.Bbs.Domain.Shared\Yi.Framework.Bbs.Domain.Shared.csproj" /> <ProjectReference Include="..\..\module\bbs\Yi.Framework.Bbs.Domain.Shared\Yi.Framework.Bbs.Domain.Shared.csproj" />
<ProjectReference Include="..\..\module\rbac\Yi.Framework.Rbac.Domain.Shared\Yi.Framework.Rbac.Domain.Shared.csproj" /> <ProjectReference Include="..\..\module\rbac\Yi.Framework.Rbac.Domain.Shared\Yi.Framework.Rbac.Domain.Shared.csproj" />
</ItemGroup> </ItemGroup>

View File

@@ -1,5 +1,6 @@
using Volo.Abp.Domain; using Volo.Abp.Domain;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Yi.Framework.AuditLogging.Domain.Shared;
using Yi.Framework.Bbs.Domain.Shared; using Yi.Framework.Bbs.Domain.Shared;
using Yi.Framework.Rbac.Domain.Shared; using Yi.Framework.Rbac.Domain.Shared;
@@ -8,7 +9,8 @@ namespace Yi.Abp.Domain.Shared
[DependsOn( [DependsOn(
typeof(YiFrameworkRbacDomainSharedModule), typeof(YiFrameworkRbacDomainSharedModule),
typeof(YiFrameworkBbsDomainSharedModule), typeof(YiFrameworkBbsDomainSharedModule),
typeof(YiFrameworkAuditLoggingDomainSharedModule),
typeof(AbpDddDomainSharedModule))] typeof(AbpDddDomainSharedModule))]
public class YiAbpDomainSharedModule : AbpModule public class YiAbpDomainSharedModule : AbpModule
{ {

View File

@@ -9,6 +9,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\framework\Yi.Framework.Mapster\Yi.Framework.Mapster.csproj" /> <ProjectReference Include="..\..\framework\Yi.Framework.Mapster\Yi.Framework.Mapster.csproj" />
<ProjectReference Include="..\..\framework\Yi.Framework.SqlSugarCore.Abstractions\Yi.Framework.SqlSugarCore.Abstractions.csproj" /> <ProjectReference Include="..\..\framework\Yi.Framework.SqlSugarCore.Abstractions\Yi.Framework.SqlSugarCore.Abstractions.csproj" />
<ProjectReference Include="..\..\module\audit-logging\Yi.Framework.AuditLogging.Domain\Yi.Framework.AuditLogging.Domain.csproj" />
<ProjectReference Include="..\..\module\bbs\Yi.Framework.Bbs.Domain\Yi.Framework.Bbs.Domain.csproj" /> <ProjectReference Include="..\..\module\bbs\Yi.Framework.Bbs.Domain\Yi.Framework.Bbs.Domain.csproj" />
<ProjectReference Include="..\..\module\rbac\Yi.Framework.Rbac.Domain\Yi.Framework.Rbac.Domain.csproj" /> <ProjectReference Include="..\..\module\rbac\Yi.Framework.Rbac.Domain\Yi.Framework.Rbac.Domain.csproj" />
<ProjectReference Include="..\..\module\tenant-management\Yi.Framework.TenantManagement.Domain\Yi.Framework.TenantManagement.Domain.csproj" /> <ProjectReference Include="..\..\module\tenant-management\Yi.Framework.TenantManagement.Domain\Yi.Framework.TenantManagement.Domain.csproj" />

View File

@@ -2,6 +2,7 @@
using Volo.Abp.Domain; using Volo.Abp.Domain;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Yi.Abp.Domain.Shared; using Yi.Abp.Domain.Shared;
using Yi.Framework.AuditLogging.Domain;
using Yi.Framework.Bbs.Domain; using Yi.Framework.Bbs.Domain;
using Yi.Framework.Mapster; using Yi.Framework.Mapster;
using Yi.Framework.Rbac.Domain; using Yi.Framework.Rbac.Domain;
@@ -15,6 +16,7 @@ namespace Yi.Abp.Domain
typeof(YiFrameworkTenantManagementDomainModule), typeof(YiFrameworkTenantManagementDomainModule),
typeof(YiFrameworkRbacDomainModule), typeof(YiFrameworkRbacDomainModule),
typeof(YiFrameworkBbsDomainModule), typeof(YiFrameworkBbsDomainModule),
typeof(YiFrameworkAuditLoggingDomainModule),
typeof(YiFrameworkMapsterModule), typeof(YiFrameworkMapsterModule),
typeof(AbpDddDomainModule), typeof(AbpDddDomainModule),

View File

@@ -4,6 +4,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\framework\Yi.Framework.Mapster\Yi.Framework.Mapster.csproj" /> <ProjectReference Include="..\..\framework\Yi.Framework.Mapster\Yi.Framework.Mapster.csproj" />
<ProjectReference Include="..\..\framework\Yi.Framework.SqlSugarCore\Yi.Framework.SqlSugarCore.csproj" /> <ProjectReference Include="..\..\framework\Yi.Framework.SqlSugarCore\Yi.Framework.SqlSugarCore.csproj" />
<ProjectReference Include="..\..\module\audit-logging\Yi.Framework.AuditLogging.SqlSugarCore\Yi.Framework.AuditLogging.SqlSugarCore.csproj" />
<ProjectReference Include="..\..\module\bbs\Yi.Framework.Bbs.SqlSugarCore\Yi.Framework.Bbs.SqlSugarCore.csproj" /> <ProjectReference Include="..\..\module\bbs\Yi.Framework.Bbs.SqlSugarCore\Yi.Framework.Bbs.SqlSugarCore.csproj" />
<ProjectReference Include="..\..\module\rbac\Yi.Framework.Rbac.SqlSugarCore\Yi.Framework.Rbac.SqlSugarCore.csproj" /> <ProjectReference Include="..\..\module\rbac\Yi.Framework.Rbac.SqlSugarCore\Yi.Framework.Rbac.SqlSugarCore.csproj" />
<ProjectReference Include="..\..\module\tenant-management\Yi.Framework.TenantManagement.SqlSugarCore\Yi.Framework.TenantManagement.SqlSugarCore.csproj" /> <ProjectReference Include="..\..\module\tenant-management\Yi.Framework.TenantManagement.SqlSugarCore\Yi.Framework.TenantManagement.SqlSugarCore.csproj" />

View File

@@ -2,6 +2,7 @@
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Yi.Abp.Domain; using Yi.Abp.Domain;
using Yi.Abp.SqlSugarCore; using Yi.Abp.SqlSugarCore;
using Yi.AuditLogging.SqlSugarCore;
using Yi.Framework.Bbs.SqlSugarCore; using Yi.Framework.Bbs.SqlSugarCore;
using Yi.Framework.Mapster; using Yi.Framework.Mapster;
using Yi.Framework.Rbac.SqlSugarCore; using Yi.Framework.Rbac.SqlSugarCore;
@@ -17,6 +18,7 @@ namespace Yi.Abp.SqlsugarCore
typeof(YiFrameworkRbacSqlSugarCoreModule), typeof(YiFrameworkRbacSqlSugarCoreModule),
typeof(YiFrameworkBbsSqlSugarCoreModule), typeof(YiFrameworkBbsSqlSugarCoreModule),
typeof(YiFrameworkAuditLoggingSqlSugarCoreModule),
typeof(YiFrameworkTenantManagementSqlSugarCoreModule), typeof(YiFrameworkTenantManagementSqlSugarCoreModule),
typeof(YiFrameworkMapsterModule), typeof(YiFrameworkMapsterModule),
typeof(YiFrameworkSqlSugarCoreModule) typeof(YiFrameworkSqlSugarCoreModule)

View File

@@ -57,7 +57,9 @@ namespace Yi.Abp.Web
//请求日志 //请求日志
Configure<AbpAuditingOptions>(optios => Configure<AbpAuditingOptions>(optios =>
{ {
optios.IsEnabled = true; //默认关闭,开启会有大量的审计日志
optios.IsEnabled = false;
//审计日志过滤器
optios.AlwaysLogSelectors.Add(x => Task.FromResult(true)); optios.AlwaysLogSelectors.Add(x => Task.FromResult(true));
}); });