diff --git a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/Repositories/SqlSugarRepository.cs b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/Repositories/SqlSugarRepository.cs index b1987eb3..c94cc338 100644 --- a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/Repositories/SqlSugarRepository.cs +++ b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/Repositories/SqlSugarRepository.cs @@ -51,22 +51,22 @@ namespace Yi.Framework.SqlSugarCore.Repositories #region Abp模块 - public async Task FindAsync(Expression> predicate, bool includeDetails = true, CancellationToken cancellationToken = default) + public virtual async Task FindAsync(Expression> predicate, bool includeDetails = true, CancellationToken cancellationToken = default) { return await GetFirstAsync(predicate); } - public async Task GetAsync(Expression> predicate, bool includeDetails = true, CancellationToken cancellationToken = default) + public virtual async Task GetAsync(Expression> predicate, bool includeDetails = true, CancellationToken cancellationToken = default) { return await GetFirstAsync(predicate); } - public async Task DeleteAsync(Expression> predicate, bool autoSave = false, CancellationToken cancellationToken = default) + public virtual async Task DeleteAsync(Expression> predicate, bool autoSave = false, CancellationToken cancellationToken = default) { await this.DeleteAsync(predicate); } - public async Task DeleteDirectAsync(Expression> predicate, CancellationToken cancellationToken = default) + public virtual async Task DeleteDirectAsync(Expression> predicate, CancellationToken cancellationToken = default) { await this.DeleteAsync(predicate); } @@ -96,53 +96,53 @@ namespace Yi.Framework.SqlSugarCore.Repositories throw new NotImplementedException(); } - public async Task> GetListAsync(Expression> predicate, bool includeDetails = false, CancellationToken cancellationToken = default) + public virtual async Task> GetListAsync(Expression> predicate, bool includeDetails = false, CancellationToken cancellationToken = default) { return await GetListAsync(predicate); } - public async Task InsertAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default) + public virtual async Task InsertAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default) { return await InsertReturnEntityAsync(entity); } - public async Task InsertManyAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default) + public virtual async Task InsertManyAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default) { await InsertRangeAsync(entities.ToList()); } - public async Task UpdateAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default) + public virtual async Task UpdateAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default) { await UpdateAsync(entity); return entity; } - public async Task UpdateManyAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default) + public virtual async Task UpdateManyAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default) { 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); } - public async Task DeleteManyAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default) + public virtual async Task DeleteManyAsync(IEnumerable entities, bool autoSave = false, CancellationToken cancellationToken = default) { await DeleteAsync(entities.ToList()); } - public async Task> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default) + public virtual async Task> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default) { return await GetListAsync(); } - public async Task GetCountAsync(CancellationToken cancellationToken = default) + public virtual async Task GetCountAsync(CancellationToken cancellationToken = default) { return await this.CountAsync(); } - public async Task> GetPagedListAsync(int skipCount, int maxResultCount, string sorting, bool includeDetails = false, CancellationToken cancellationToken = default) + public virtual async Task> GetPagedListAsync(int skipCount, int maxResultCount, string sorting, bool includeDetails = false, CancellationToken cancellationToken = default) { return await GetPageListAsync(_ => true, skipCount, maxResultCount); } @@ -150,69 +150,69 @@ namespace Yi.Framework.SqlSugarCore.Repositories #region 内置DB快捷操作 - public async Task> AsDeleteable() + public virtual async Task> AsDeleteable() { return (await GetDbSimpleClientAsync()).AsDeleteable(); } - public async Task> AsInsertable(List insertObjs) + public virtual async Task> AsInsertable(List insertObjs) { return (await GetDbSimpleClientAsync()).AsInsertable(insertObjs); } - public async Task> AsInsertable(TEntity insertObj) + public virtual async Task> AsInsertable(TEntity insertObj) { return (await GetDbSimpleClientAsync()).AsInsertable(insertObj); } - public async Task> AsInsertable(TEntity[] insertObjs) + public virtual async Task> AsInsertable(TEntity[] insertObjs) { return (await GetDbSimpleClientAsync()).AsInsertable(insertObjs); } - public async Task> AsQueryable() + public virtual async Task> AsQueryable() { return (await GetDbSimpleClientAsync()).AsQueryable(); } - public async Task AsSugarClient() + public virtual async Task AsSugarClient() { return (await GetDbSimpleClientAsync()).AsSugarClient(); } - public async Task AsTenant() + public virtual async Task AsTenant() { return (await GetDbSimpleClientAsync()).AsTenant(); } - public async Task> AsUpdateable(List updateObjs) + public virtual async Task> AsUpdateable(List updateObjs) { return (await GetDbSimpleClientAsync()).AsUpdateable(updateObjs); } - public async Task> AsUpdateable(TEntity updateObj) + public virtual async Task> AsUpdateable(TEntity updateObj) { return (await GetDbSimpleClientAsync()).AsUpdateable(updateObj); } - public async Task> AsUpdateable() + public virtual async Task> AsUpdateable() { return (await GetDbSimpleClientAsync()).AsUpdateable(); } - public async Task> AsUpdateable(TEntity[] updateObjs) + public virtual async Task> AsUpdateable(TEntity[] updateObjs) { return (await GetDbSimpleClientAsync()).AsUpdateable(updateObjs); } #endregion #region SimpleClient模块 - public async Task CountAsync(Expression> whereExpression) + public virtual async Task CountAsync(Expression> whereExpression) { return await (await GetDbSimpleClientAsync()).CountAsync(whereExpression); } - public async Task DeleteAsync(TEntity deleteObj) + public virtual async Task DeleteAsync(TEntity deleteObj) { if (deleteObj is ISoftDelete) { @@ -226,7 +226,7 @@ namespace Yi.Framework.SqlSugarCore.Repositories } - public async Task DeleteAsync(List deleteObjs) + public virtual async Task DeleteAsync(List deleteObjs) { if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity))) { @@ -239,7 +239,7 @@ namespace Yi.Framework.SqlSugarCore.Repositories } } - public async Task DeleteAsync(Expression> whereExpression) + public virtual async Task DeleteAsync(Expression> whereExpression) { if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity))) { @@ -252,7 +252,7 @@ namespace Yi.Framework.SqlSugarCore.Repositories } - public async Task DeleteByIdAsync(dynamic id) + public virtual async Task DeleteByIdAsync(dynamic id) { if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity))) { @@ -267,7 +267,7 @@ namespace Yi.Framework.SqlSugarCore.Repositories } } - public async Task DeleteByIdsAsync(dynamic[] ids) + public virtual async Task DeleteByIdsAsync(dynamic[] ids) { if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity))) { @@ -288,101 +288,101 @@ namespace Yi.Framework.SqlSugarCore.Repositories } - public async Task GetByIdAsync(dynamic id) + public virtual async Task GetByIdAsync(dynamic id) { return await (await GetDbSimpleClientAsync()).GetByIdAsync(id); } - public async Task GetFirstAsync(Expression> whereExpression) + public virtual async Task GetFirstAsync(Expression> whereExpression) { return await (await GetDbSimpleClientAsync()).GetFirstAsync(whereExpression); } - public async Task> GetListAsync() + public virtual async Task> GetListAsync() { return await (await GetDbSimpleClientAsync()).GetListAsync(); } - public async Task> GetListAsync(Expression> whereExpression) + public virtual async Task> GetListAsync(Expression> whereExpression) { return await (await GetDbSimpleClientAsync()).GetListAsync(whereExpression); } - public async Task> GetPageListAsync(Expression> whereExpression, int pageNum, int pageSize) + public virtual async Task> GetPageListAsync(Expression> whereExpression, int pageNum, int pageSize) { return await (await GetDbSimpleClientAsync()).GetPageListAsync(whereExpression, new PageModel() { PageIndex = pageNum, PageSize = pageSize }); } - public async Task> GetPageListAsync(Expression> whereExpression, int pageNum, int pageSize, Expression>? orderByExpression = null, OrderByType orderByType = OrderByType.Asc) + public virtual async Task> GetPageListAsync(Expression> whereExpression, int pageNum, int pageSize, Expression>? orderByExpression = null, OrderByType orderByType = OrderByType.Asc) { return await (await GetDbSimpleClientAsync()).GetPageListAsync(whereExpression, new PageModel { PageIndex = pageNum, PageSize = pageSize }, orderByExpression, orderByType); } - public async Task GetSingleAsync(Expression> whereExpression) + public virtual async Task GetSingleAsync(Expression> whereExpression) { return await (await GetDbSimpleClientAsync()).GetSingleAsync(whereExpression); } - public async Task InsertAsync(TEntity insertObj) + public virtual async Task InsertAsync(TEntity insertObj) { return await (await GetDbSimpleClientAsync()).InsertAsync(insertObj); } - public async Task InsertOrUpdateAsync(TEntity data) + public virtual async Task InsertOrUpdateAsync(TEntity data) { return await (await GetDbSimpleClientAsync()).InsertOrUpdateAsync(data); } - public async Task InsertOrUpdateAsync(List datas) + public virtual async Task InsertOrUpdateAsync(List datas) { return await (await GetDbSimpleClientAsync()).InsertOrUpdateAsync(datas); } - public async Task InsertRangeAsync(List insertObjs) + public virtual async Task InsertRangeAsync(List insertObjs) { return await (await GetDbSimpleClientAsync()).InsertRangeAsync(insertObjs); } - public async Task InsertReturnBigIdentityAsync(TEntity insertObj) + public virtual async Task InsertReturnBigIdentityAsync(TEntity insertObj) { return await (await GetDbSimpleClientAsync()).InsertReturnBigIdentityAsync(insertObj); } - public async Task InsertReturnEntityAsync(TEntity insertObj) + public virtual async Task InsertReturnEntityAsync(TEntity insertObj) { return await (await GetDbSimpleClientAsync()).InsertReturnEntityAsync(insertObj); } - public async Task InsertReturnIdentityAsync(TEntity insertObj) + public virtual async Task InsertReturnIdentityAsync(TEntity insertObj) { return await (await GetDbSimpleClientAsync()).InsertReturnIdentityAsync(insertObj); } - public async Task InsertReturnSnowflakeIdAsync(TEntity insertObj) + public virtual async Task InsertReturnSnowflakeIdAsync(TEntity insertObj) { return await (await GetDbSimpleClientAsync()).InsertReturnSnowflakeIdAsync(insertObj); } - public async Task IsAnyAsync(Expression> whereExpression) + public virtual async Task IsAnyAsync(Expression> whereExpression) { return await (await GetDbSimpleClientAsync()).IsAnyAsync(whereExpression); } - public async Task UpdateAsync(TEntity updateObj) + public virtual async Task UpdateAsync(TEntity updateObj) { return await (await GetDbSimpleClientAsync()).UpdateAsync(updateObj); } - public async Task UpdateAsync(Expression> columns, Expression> whereExpression) + public virtual async Task UpdateAsync(Expression> columns, Expression> whereExpression) { return await (await GetDbSimpleClientAsync()).UpdateAsync(columns, whereExpression); } - public async Task UpdateRangeAsync(List updateObjs) + public virtual async Task UpdateRangeAsync(List 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); } - public async Task DeleteManyAsync(IEnumerable ids, bool autoSave = false, CancellationToken cancellationToken = default) + public virtual async Task DeleteManyAsync(IEnumerable ids, bool autoSave = false, CancellationToken cancellationToken = default) { await DeleteByIdsAsync(ids.Select(x => (object)x).ToArray()); } - public async Task FindAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default) + public virtual async Task FindAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default) { return await GetByIdAsync(id); } - public async Task GetAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default) + public virtual async Task GetAsync(TKey id, bool includeDetails = true, CancellationToken cancellationToken = default) { return await GetByIdAsync(id); } diff --git a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/YiFrameworkSqlSugarCoreModule.cs b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/YiFrameworkSqlSugarCoreModule.cs index d4b1e02b..c54e512e 100644 --- a/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/YiFrameworkSqlSugarCoreModule.cs +++ b/Yi.Abp.Net8/framework/Yi.Framework.SqlSugarCore/YiFrameworkSqlSugarCoreModule.cs @@ -36,8 +36,6 @@ namespace Yi.Framework.SqlSugarCore service.AddTransient(typeof(ISqlSugarRepository<>), typeof(SqlSugarRepository<>)); service.AddTransient(typeof(ISqlSugarRepository<,>), typeof(SqlSugarRepository<,>)); - service.AddTransient(); - service.AddTransient(typeof(ISugarDbContextProvider<>), typeof(UnitOfWorkSqlsugarDbContextProvider<>)); diff --git a/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.Domain.Shared/Yi.Framework.AuditLogging.Domain.Shared.csproj b/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.Domain.Shared/Yi.Framework.AuditLogging.Domain.Shared.csproj index fa71b7ae..1c82bea3 100644 --- a/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.Domain.Shared/Yi.Framework.AuditLogging.Domain.Shared.csproj +++ b/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.Domain.Shared/Yi.Framework.AuditLogging.Domain.Shared.csproj @@ -6,4 +6,8 @@ enable + + + + diff --git a/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.Domain.Shared/YiFrameworkAuditLoggingDomainSharedModule.cs b/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.Domain.Shared/YiFrameworkAuditLoggingDomainSharedModule.cs index 8f04b3ae..fa38c2b4 100644 --- a/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.Domain.Shared/YiFrameworkAuditLoggingDomainSharedModule.cs +++ b/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.Domain.Shared/YiFrameworkAuditLoggingDomainSharedModule.cs @@ -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 { } diff --git a/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.Domain/Entities/AuditLogActionEntity.cs b/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.Domain/Entities/AuditLogActionEntity.cs index b4e049fe..8c959ec3 100644 --- a/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.Domain/Entities/AuditLogActionEntity.cs +++ b/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.Domain/Entities/AuditLogActionEntity.cs @@ -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, 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() { } diff --git a/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.Domain/Entities/AuditLogAggregateRoot.cs b/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.Domain/Entities/AuditLogAggregateRoot.cs index dcdbe84d..e0188184 100644 --- a/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.Domain/Entities/AuditLogAggregateRoot.cs +++ b/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.Domain/Entities/AuditLogAggregateRoot.cs @@ -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, 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 EntityChanges { get; protected set; } - public virtual List Actions { get; protected set; } + //导航属性 + [Navigate(NavigateType.OneToMany, nameof(EntityChangeEntity.AuditLogId))] + public virtual List EntityChanges { get; protected set; } + + //导航属性 + [Navigate(NavigateType.OneToMany, nameof(AuditLogActionEntity.AuditLogId))] + public virtual List Actions { get; protected set; } + + [SugarColumn(IsIgnore = true)] + public override ExtraPropertyDictionary ExtraProperties { get; protected set; } } } diff --git a/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.Domain/Entities/EntityChangeEntity.cs b/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.Domain/Entities/EntityChangeEntity.cs index d119ccf7..ca8ff72e 100644 --- a/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.Domain/Entities/EntityChangeEntity.cs +++ b/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.Domain/Entities/EntityChangeEntity.cs @@ -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, 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 PropertyChanges { get; protected set; } + public virtual string? EntityTypeFullName { get; protected set; } + [Navigate(NavigateType.OneToMany, nameof(EntityPropertyChangeEntity.EntityChangeId))] + public virtual List PropertyChanges { get; protected set; } public EntityChangeEntity( diff --git a/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.Domain/Entities/EntityPropertyChangeEntity.cs b/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.Domain/Entities/EntityPropertyChangeEntity.cs index 7140c701..62dbc686 100644 --- a/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.Domain/Entities/EntityPropertyChangeEntity.cs +++ b/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.Domain/Entities/EntityPropertyChangeEntity.cs @@ -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, 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; } } } diff --git a/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.Domain/YiFrameworkAuditLoggingDomainModule.cs b/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.Domain/YiFrameworkAuditLoggingDomainModule.cs index 96fb03e9..f826a3db 100644 --- a/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.Domain/YiFrameworkAuditLoggingDomainModule.cs +++ b/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.Domain/YiFrameworkAuditLoggingDomainModule.cs @@ -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) diff --git a/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.SqlSugarCore/Repositories/SqlSugarCoreAuditLogRepository.cs b/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.SqlSugarCore/Repositories/SqlSugarCoreAuditLogRepository.cs index 0e79c73c..87de9d85 100644 --- a/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.SqlSugarCore/Repositories/SqlSugarCoreAuditLogRepository.cs +++ b/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.SqlSugarCore/Repositories/SqlSugarCoreAuditLogRepository.cs @@ -16,6 +16,21 @@ public class SqlSugarCoreAuditLogRepository : SqlSugarRepository sugarDbContextProvider) : base(sugarDbContextProvider) { } + + /// + /// 重写插入,支持导航属性 + /// + /// + /// + public override async Task InsertAsync(AuditLogAggregateRoot insertObj) + { + + return await _Db.InsertNav(insertObj) + .Include(z1 => z1.Actions) + //.Include(z1 => z1.EntityChanges).ThenInclude(z2 => z2.PropertyChanges) + .ExecuteCommandAsync(); + } + public virtual async Task> GetListAsync( string sorting = null, int maxResultCount = 50, @@ -138,11 +153,11 @@ public class SqlSugarCoreAuditLogRepository : SqlSugarRepository 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); } diff --git a/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.SqlSugarCore/YiFrameworkAuditLoggingSqlSugarCoreModule.cs b/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.SqlSugarCore/YiFrameworkAuditLoggingSqlSugarCoreModule.cs index f16d83d9..37d61ee1 100644 --- a/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.SqlSugarCore/YiFrameworkAuditLoggingSqlSugarCoreModule.cs +++ b/Yi.Abp.Net8/module/audit-logging/Yi.Framework.AuditLogging.SqlSugarCore/YiFrameworkAuditLoggingSqlSugarCoreModule.cs @@ -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) diff --git a/Yi.Abp.Net8/module/tenant-management/Yi.Framework.TenantManagement.Domain/TenantAggregateRoot.cs b/Yi.Abp.Net8/module/tenant-management/Yi.Framework.TenantManagement.Domain/TenantAggregateRoot.cs index 7dbf4739..55bfbc00 100644 --- a/Yi.Abp.Net8/module/tenant-management/Yi.Framework.TenantManagement.Domain/TenantAggregateRoot.cs +++ b/Yi.Abp.Net8/module/tenant-management/Yi.Framework.TenantManagement.Domain/TenantAggregateRoot.cs @@ -9,7 +9,7 @@ using Yi.Framework.SqlSugarCore.Abstractions; namespace Yi.Framework.TenantManagement.Domain { - [SugarTable("Tenant")] + [SugarTable("YiTenant")] [MasterTenant] public class TenantAggregateRoot : FullAuditedAggregateRoot, IHasEntityVersion { diff --git a/Yi.Abp.Net8/src/Yi.Abp.Domain.Shared/Yi.Abp.Domain.Shared.csproj b/Yi.Abp.Net8/src/Yi.Abp.Domain.Shared/Yi.Abp.Domain.Shared.csproj index ba4ea44b..5cf21b41 100644 --- a/Yi.Abp.Net8/src/Yi.Abp.Domain.Shared/Yi.Abp.Domain.Shared.csproj +++ b/Yi.Abp.Net8/src/Yi.Abp.Domain.Shared/Yi.Abp.Domain.Shared.csproj @@ -6,6 +6,7 @@ + diff --git a/Yi.Abp.Net8/src/Yi.Abp.Domain.Shared/YiAbpDomainSharedModule.cs b/Yi.Abp.Net8/src/Yi.Abp.Domain.Shared/YiAbpDomainSharedModule.cs index 78b2724d..f1f59ac7 100644 --- a/Yi.Abp.Net8/src/Yi.Abp.Domain.Shared/YiAbpDomainSharedModule.cs +++ b/Yi.Abp.Net8/src/Yi.Abp.Domain.Shared/YiAbpDomainSharedModule.cs @@ -1,5 +1,6 @@ using Volo.Abp.Domain; using Volo.Abp.Modularity; +using Yi.Framework.AuditLogging.Domain.Shared; using Yi.Framework.Bbs.Domain.Shared; using Yi.Framework.Rbac.Domain.Shared; @@ -8,7 +9,8 @@ namespace Yi.Abp.Domain.Shared [DependsOn( typeof(YiFrameworkRbacDomainSharedModule), typeof(YiFrameworkBbsDomainSharedModule), - + typeof(YiFrameworkAuditLoggingDomainSharedModule), + typeof(AbpDddDomainSharedModule))] public class YiAbpDomainSharedModule : AbpModule { diff --git a/Yi.Abp.Net8/src/Yi.Abp.Domain/Yi.Abp.Domain.csproj b/Yi.Abp.Net8/src/Yi.Abp.Domain/Yi.Abp.Domain.csproj index 612ac2fd..40a50937 100644 --- a/Yi.Abp.Net8/src/Yi.Abp.Domain/Yi.Abp.Domain.csproj +++ b/Yi.Abp.Net8/src/Yi.Abp.Domain/Yi.Abp.Domain.csproj @@ -9,6 +9,7 @@ + diff --git a/Yi.Abp.Net8/src/Yi.Abp.Domain/YiAbpDomainModule.cs b/Yi.Abp.Net8/src/Yi.Abp.Domain/YiAbpDomainModule.cs index 52443beb..680910eb 100644 --- a/Yi.Abp.Net8/src/Yi.Abp.Domain/YiAbpDomainModule.cs +++ b/Yi.Abp.Net8/src/Yi.Abp.Domain/YiAbpDomainModule.cs @@ -2,6 +2,7 @@ using Volo.Abp.Domain; using Volo.Abp.Modularity; using Yi.Abp.Domain.Shared; +using Yi.Framework.AuditLogging.Domain; using Yi.Framework.Bbs.Domain; using Yi.Framework.Mapster; using Yi.Framework.Rbac.Domain; @@ -15,6 +16,7 @@ namespace Yi.Abp.Domain typeof(YiFrameworkTenantManagementDomainModule), typeof(YiFrameworkRbacDomainModule), typeof(YiFrameworkBbsDomainModule), + typeof(YiFrameworkAuditLoggingDomainModule), typeof(YiFrameworkMapsterModule), typeof(AbpDddDomainModule), diff --git a/Yi.Abp.Net8/src/Yi.Abp.SqlSugarCore/Yi.Abp.SqlSugarCore.csproj b/Yi.Abp.Net8/src/Yi.Abp.SqlSugarCore/Yi.Abp.SqlSugarCore.csproj index 0b231f03..c948284e 100644 --- a/Yi.Abp.Net8/src/Yi.Abp.SqlSugarCore/Yi.Abp.SqlSugarCore.csproj +++ b/Yi.Abp.Net8/src/Yi.Abp.SqlSugarCore/Yi.Abp.SqlSugarCore.csproj @@ -4,6 +4,7 @@ + diff --git a/Yi.Abp.Net8/src/Yi.Abp.SqlSugarCore/YiAbpSqlSugarCoreModule.cs b/Yi.Abp.Net8/src/Yi.Abp.SqlSugarCore/YiAbpSqlSugarCoreModule.cs index 6bf5b9b1..cc27417b 100644 --- a/Yi.Abp.Net8/src/Yi.Abp.SqlSugarCore/YiAbpSqlSugarCoreModule.cs +++ b/Yi.Abp.Net8/src/Yi.Abp.SqlSugarCore/YiAbpSqlSugarCoreModule.cs @@ -2,6 +2,7 @@ using Volo.Abp.Modularity; using Yi.Abp.Domain; using Yi.Abp.SqlSugarCore; +using Yi.AuditLogging.SqlSugarCore; using Yi.Framework.Bbs.SqlSugarCore; using Yi.Framework.Mapster; using Yi.Framework.Rbac.SqlSugarCore; @@ -17,6 +18,7 @@ namespace Yi.Abp.SqlsugarCore typeof(YiFrameworkRbacSqlSugarCoreModule), typeof(YiFrameworkBbsSqlSugarCoreModule), + typeof(YiFrameworkAuditLoggingSqlSugarCoreModule), typeof(YiFrameworkTenantManagementSqlSugarCoreModule), typeof(YiFrameworkMapsterModule), typeof(YiFrameworkSqlSugarCoreModule) diff --git a/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs b/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs index d42c1422..6915dab4 100644 --- a/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs +++ b/Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs @@ -57,7 +57,9 @@ namespace Yi.Abp.Web //请求日志 Configure(optios => { - optios.IsEnabled = true; + //默认关闭,开启会有大量的审计日志 + optios.IsEnabled = false; + //审计日志过滤器 optios.AlwaysLogSelectors.Add(x => Task.FromResult(true)); });