From 12a8a52ec007e4971babc8b9e99bcb050372e4e9 Mon Sep 17 00:00:00 2001 From: cKey <35512826+colinin@users.noreply.github.com> Date: Fri, 15 Apr 2022 13:19:02 +0800 Subject: [PATCH] =?UTF-8?q?feat(auditing):=20=E6=8F=90=E4=BE=9B=E6=9C=89?= =?UTF-8?q?=E5=85=B3=E7=94=A8=E6=88=B7=E7=9A=84=E5=AE=A1=E8=AE=A1=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ElasticsearchAuditLogManager.cs | 2 +- .../ElasticsearchEntityChangeStore.cs | 371 ++++++++++++++++++ .../AuditLogs/EntityChangeGetByPagedDto.cs | 15 + .../EntityChangeGetWithUsernameDto.cs | 7 + .../AuditLogs/EntityChangeWithUsernameDto.cs | 7 + .../AuditLogs/IEntityChangesAppService.cs | 17 + .../Abp/Auditing/AbpAuditingMapperProfile.cs | 1 + .../AuditLogs/EntityChangesAppService.cs | 62 +++ .../AuditLogs/EntityChangesController.cs | 50 +++ .../Elasticsearch/AbpElasticsearchOptions.cs | 3 + 10 files changed, 534 insertions(+), 1 deletion(-) create mode 100644 aspnet-core/modules/auditing/LINGYUN.Abp.AuditLogging.Elasticsearch/LINGYUN/Abp/AuditLogging/Elasticsearch/ElasticsearchEntityChangeStore.cs create mode 100644 aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.Application.Contracts/LINGYUN/Abp/Auditing/AuditLogs/EntityChangeGetByPagedDto.cs create mode 100644 aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.Application.Contracts/LINGYUN/Abp/Auditing/AuditLogs/EntityChangeGetWithUsernameDto.cs create mode 100644 aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.Application.Contracts/LINGYUN/Abp/Auditing/AuditLogs/EntityChangeWithUsernameDto.cs create mode 100644 aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.Application.Contracts/LINGYUN/Abp/Auditing/AuditLogs/IEntityChangesAppService.cs create mode 100644 aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.Application/LINGYUN/Abp/Auditing/AuditLogs/EntityChangesAppService.cs create mode 100644 aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.HttpApi/LINGYUN/Abp/Auditing/AuditLogs/EntityChangesController.cs diff --git a/aspnet-core/modules/auditing/LINGYUN.Abp.AuditLogging.Elasticsearch/LINGYUN/Abp/AuditLogging/Elasticsearch/ElasticsearchAuditLogManager.cs b/aspnet-core/modules/auditing/LINGYUN.Abp.AuditLogging.Elasticsearch/LINGYUN/Abp/AuditLogging/Elasticsearch/ElasticsearchAuditLogManager.cs index 89e163a61..f5e30aca0 100644 --- a/aspnet-core/modules/auditing/LINGYUN.Abp.AuditLogging.Elasticsearch/LINGYUN/Abp/AuditLogging/Elasticsearch/ElasticsearchAuditLogManager.cs +++ b/aspnet-core/modules/auditing/LINGYUN.Abp.AuditLogging.Elasticsearch/LINGYUN/Abp/AuditLogging/Elasticsearch/ElasticsearchAuditLogManager.cs @@ -254,7 +254,7 @@ namespace LINGYUN.Abp.AuditLogging.Elasticsearch } if (!url.IsNullOrWhiteSpace()) { - querys.Add((log) => log.Match((q) => q.Field(GetField(nameof(AuditLog.Url))).Query(url))); + querys.Add((log) => log.Wildcard((q) => q.Field(GetField(nameof(AuditLog.Url))).Value($"*{url}*"))); } if (userId.HasValue) { diff --git a/aspnet-core/modules/auditing/LINGYUN.Abp.AuditLogging.Elasticsearch/LINGYUN/Abp/AuditLogging/Elasticsearch/ElasticsearchEntityChangeStore.cs b/aspnet-core/modules/auditing/LINGYUN.Abp.AuditLogging.Elasticsearch/LINGYUN/Abp/AuditLogging/Elasticsearch/ElasticsearchEntityChangeStore.cs new file mode 100644 index 000000000..3a11a24fc --- /dev/null +++ b/aspnet-core/modules/auditing/LINGYUN.Abp.AuditLogging.Elasticsearch/LINGYUN/Abp/AuditLogging/Elasticsearch/ElasticsearchEntityChangeStore.cs @@ -0,0 +1,371 @@ +using LINGYUN.Abp.Elasticsearch; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; +using Microsoft.Extensions.Options; +using Nest; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Volo.Abp.Auditing; +using Volo.Abp.DependencyInjection; + +namespace LINGYUN.Abp.AuditLogging.Elasticsearch; + +[Dependency(ReplaceServices = true)] +public class ElasticsearchEntityChangeStore : IEntityChangeStore, ITransientDependency +{ + private readonly AbpElasticsearchOptions _elasticsearchOptions; + private readonly IIndexNameNormalizer _indexNameNormalizer; + private readonly IElasticsearchClientFactory _clientFactory; + + public ILogger Logger { protected get; set; } + + public ElasticsearchEntityChangeStore( + IIndexNameNormalizer indexNameNormalizer, + IElasticsearchClientFactory clientFactory, + IOptions elasticsearchOptions) + { + _clientFactory = clientFactory; + _indexNameNormalizer = indexNameNormalizer; + _elasticsearchOptions = elasticsearchOptions.Value; + + Logger = NullLogger.Instance; + } + + public async virtual Task GetAsync( + Guid entityChangeId, + CancellationToken cancellationToken = default) + { + var client = _clientFactory.Create(); + + var resposne = await client.SearchAsync( + dsl => dsl.Index(CreateIndex()) + .Query(query => + query.Bool(bo => + bo.Must(m => + m.Nested(n => + n.InnerHits() + .Path("EntityChanges") + .Query(nq => + nq.Term(nqt => + nqt.Field(GetField(nameof(EntityChange.Id))).Value(entityChangeId))))))) + .Source(x => x.Excludes(f => f.Field("*"))) + .Sort(entity => entity.Field("EntityChanges.ChangeTime", SortOrder.Descending)) + .Size(1), + ct: cancellationToken); + + if (resposne.Shards.Successful > 0) + { + var hits = resposne.Hits.FirstOrDefault(); + if (hits.InnerHits.Count > 0) + { + return hits.InnerHits.First().Value.Documents().FirstOrDefault(); + } + } + + return null; + } + + public async virtual Task GetCountAsync( + Guid? auditLogId = null, + DateTime? startTime = null, + DateTime? endTime = null, + EntityChangeType? changeType = null, + string entityId = null, + string entityTypeFullName = null, + CancellationToken cancellationToken = default) + { + await Task.CompletedTask; + return 0; + //var client = _clientFactory.Create(); + + //var querys = BuildQueryDescriptor( + // auditLogId, + // startTime, + // endTime, + // changeType, + // entityId, + // entityTypeFullName); + + //Func, QueryContainer> selector = q => q.MatchAll(); + //if (querys.Count > 0) + //{ + // selector = q => q.Bool(b => b.Must(querys.ToArray())); + //} + + //var response = await client.CountAsync(dsl => + // dsl.Index(CreateIndex()) + // .Query(q => + // q.Bool(b => + // b.Must(m => + // m.Nested(n => + // n.InnerHits(hit => hit.Source(s => s.ExcludeAll())) + // .Path("EntityChanges") + // .Query(selector) + // ) + // ) + // ) + // ), + // ct: cancellationToken); + + //return response.Count; + } + + public async virtual Task> GetListAsync( + string sorting = null, + int maxResultCount = 50, + int skipCount = 0, + Guid? auditLogId = null, + DateTime? startTime = null, + DateTime? endTime = null, + EntityChangeType? changeType = null, + string entityId = null, + string entityTypeFullName = null, + bool includeDetails = false, + CancellationToken cancellationToken = default) + { + // TODO: 需要解决Nested格式数据返回方式 + + //var client = _clientFactory.Create(); + + //var sortOrder = !sorting.IsNullOrWhiteSpace() && sorting.EndsWith("asc", StringComparison.InvariantCultureIgnoreCase) + // ? SortOrder.Ascending : SortOrder.Descending; + //sorting = !sorting.IsNullOrWhiteSpace() + // ? sorting.Split()[0] + // : nameof(EntityChange.ChangeTime); + + //var querys = BuildQueryDescriptor( + // auditLogId, + // startTime, + // endTime, + // changeType, + // entityId, + // entityTypeFullName); + + //SourceFilterDescriptor SourceFilter(SourceFilterDescriptor selector) + //{ + // selector.Includes(GetEntityChangeSources()); + // if (!includeDetails) + // { + // selector.Excludes(field => + // field.Field("EntityChanges.PropertyChanges") + // .Field("EntityChanges.ExtraProperties")); + // } + + // return selector; + //} + + //Func, QueryContainer> selector = q => q.MatchAll(); + //if (querys.Count > 0) + //{ + // selector = q => q.Bool(b => b.Must(querys.ToArray())); + //} + + //var response = await client.SearchAsync(dsl => + // dsl.Index(CreateIndex()) + // .Query(q => + // q.Bool(b => + // b.Must(m => + // m.Nested(n => + // n.InnerHits(hit => hit.Source(SourceFilter)) + // .Path("EntityChanges") + // .Query(selector) + // ) + // ) + // ) + // ) + // .Source(x => x.Excludes(f => f.Field("*"))) + // .Sort(entity => entity.Field(GetField(sorting), sortOrder)) + // .From(skipCount) + // .Size(maxResultCount), + // cancellationToken); + + //if (response.Shards.Successful > 0) + //{ + // var hits = response.Hits.FirstOrDefault(); + // if (hits.InnerHits.Count > 0) + // { + // return hits.InnerHits.First().Value.Documents().ToList(); + // } + //} + await Task.CompletedTask; + return new List(); + } + + public async virtual Task GetWithUsernameAsync( + Guid entityChangeId, + CancellationToken cancellationToken = default) + { + var client = _clientFactory.Create(); + + var response = await client.SearchAsync( + dsl => dsl.Index(CreateIndex()) + .Query(query => + query.Bool(bo => + bo.Must(m => + m.Nested(n => + n.InnerHits() + .Path("EntityChanges") + .Query(nq => + nq.Bool(nb => + nb.Must(nm => + nm.Term(nt => + nt.Field(GetField(nameof(EntityChange.Id))).Value(entityChangeId))))))))) + .Source(selector => selector.Includes(field => + field.Field(f => f.UserName))) + .Size(1), + ct: cancellationToken); + + var auditLog = response.Documents.FirstOrDefault(); + EntityChange entityChange = null; + + if (response.Shards.Successful > 0) + { + var hits = response.Hits.FirstOrDefault(); + if (hits.InnerHits.Count > 0) + { + entityChange = hits.InnerHits.First().Value.Documents().FirstOrDefault(); + } + } + + return new EntityChangeWithUsername() + { + EntityChange = entityChange, + UserName = auditLog?.UserName + }; + } + + public async virtual Task> GetWithUsernameAsync( + string entityId, + string entityTypeFullName, + CancellationToken cancellationToken = default) + { + var client = _clientFactory.Create(); + + var response = await client.SearchAsync( + dsl => dsl.Index(CreateIndex()) + .Query(query => + query.Bool(bo => + bo.Must(m => + m.Nested(n => + n.InnerHits() + .Path("EntityChanges") + .Query(nq => + nq.Bool(nb => + nb.Must(nm => + nm.Term(nt => + nt.Field(GetField(nameof(EntityChange.EntityId))).Value(entityId)), + nm => + nm.Term(nt => + nt.Field(GetField(nameof(EntityChange.EntityTypeFullName))).Value(entityTypeFullName)) + ) + ) + ) + ) + ) + ) + ) + .Source(selector => selector.Includes(field => + field.Field(f => f.UserName))) + .Sort(entity => entity.Field(f => f.ExecutionTime, SortOrder.Descending)), + ct: cancellationToken); + + if (response.Hits.Count > 0) + { + return response.Hits. + Select(hit => new EntityChangeWithUsername + { + UserName = hit.Source.UserName, + EntityChange = hit.InnerHits.Any() ? + hit.InnerHits.First().Value.Documents().FirstOrDefault() + : null + }) + .ToList(); + } + + return new List(); + } + + protected virtual List, QueryContainer>> BuildQueryDescriptor( + Guid? auditLogId = null, + DateTime? startTime = null, + DateTime? endTime = null, + EntityChangeType? changeType = null, + string entityId = null, + string entityTypeFullName = null) + { + var querys = new List, QueryContainer>>(); + + if (auditLogId.HasValue) + { + querys.Add(entity => entity.Term(q => q.Field(GetField(nameof(EntityChange.AuditLogId))).Value(auditLogId))); + } + if (startTime.HasValue) + { + querys.Add(entity => entity.DateRange(q => q.Field(GetField(nameof(EntityChange.ChangeTime))).GreaterThanOrEquals(startTime))); + } + if (endTime.HasValue) + { + querys.Add(entity => entity.DateRange(q => q.Field(GetField(nameof(EntityChange.ChangeTime))).LessThanOrEquals(endTime))); + } + if (changeType.HasValue) + { + querys.Add(entity => entity.Term(q => q.Field(GetField(nameof(EntityChange.ChangeType))).Value(changeType))); + } + if (!entityId.IsNullOrWhiteSpace()) + { + querys.Add(entity => entity.Term(q => q.Field(GetField(nameof(EntityChange.EntityId))).Value(entityId))); + } + if (!entityTypeFullName.IsNullOrWhiteSpace()) + { + querys.Add(entity => entity.Wildcard(q => q.Field(GetField(nameof(EntityChange.EntityTypeFullName))).Value($"*{entityTypeFullName}*"))); + } + + return querys; + } + + protected virtual string CreateIndex() + { + return _indexNameNormalizer.NormalizeIndex("audit-log"); + } + + protected Func, IPromise> GetEntityChangeSources() + { + return field => field + .Field("EntityChanges.Id") + .Field("EntityChanges.AuditLogId") + .Field("EntityChanges.TenantId") + .Field("EntityChanges.ChangeTime") + .Field("EntityChanges.ChangeType") + .Field("EntityChanges.EntityTenantId") + .Field("EntityChanges.EntityId") + .Field("EntityChanges.EntityTypeFullName") + .Field("EntityChanges.PropertyChanges") + .Field("EntityChanges.ExtraProperties"); + } + + private readonly static IDictionary _fieldMaps = new Dictionary(StringComparer.InvariantCultureIgnoreCase) + { + { "Id", "EntityChanges.Id.keyword" }, + { "AuditLogId", "EntityChanges.AuditLogId.keyword" }, + { "TenantId", "EntityChanges.TenantId.keyword" }, + { "EntityTenantId", "EntityChanges.EntityTenantId.keyword" }, + { "EntityId", "EntityChanges.EntityId.keyword" }, + { "EntityTypeFullName", "EntityChanges.EntityTypeFullName.keyword" }, + { "PropertyChanges", "EntityChanges.PropertyChanges" }, + { "ExtraProperties", "EntityChanges.ExtraProperties" }, + { "ChangeType", "EntityChanges.ChangeType" }, + { "ChangeTime", "EntityChanges.ChangeTime" }, + }; + protected virtual string GetField(string field) + { + if (_fieldMaps.TryGetValue(field, out var mapField)) + { + return _elasticsearchOptions.FieldCamelCase ? mapField.ToCamelCase() : mapField.ToPascalCase(); + } + + return _elasticsearchOptions.FieldCamelCase ? field.ToCamelCase() : field.ToPascalCase(); + } +} diff --git a/aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.Application.Contracts/LINGYUN/Abp/Auditing/AuditLogs/EntityChangeGetByPagedDto.cs b/aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.Application.Contracts/LINGYUN/Abp/Auditing/AuditLogs/EntityChangeGetByPagedDto.cs new file mode 100644 index 000000000..85a1a651f --- /dev/null +++ b/aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.Application.Contracts/LINGYUN/Abp/Auditing/AuditLogs/EntityChangeGetByPagedDto.cs @@ -0,0 +1,15 @@ +using System; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Auditing; + +namespace LINGYUN.Abp.Auditing.AuditLogs; + +public class EntityChangeGetByPagedDto : PagedAndSortedResultRequestDto +{ + public Guid? AuditLogId { get; set; } + public DateTime? StartTime { get; set; } + public DateTime? EndTime { get; set; } + public EntityChangeType? ChangeType { get; set; } + public string EntityId { get; set; } + public string EntityTypeFullName { get; set; } +} diff --git a/aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.Application.Contracts/LINGYUN/Abp/Auditing/AuditLogs/EntityChangeGetWithUsernameDto.cs b/aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.Application.Contracts/LINGYUN/Abp/Auditing/AuditLogs/EntityChangeGetWithUsernameDto.cs new file mode 100644 index 000000000..9c962119e --- /dev/null +++ b/aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.Application.Contracts/LINGYUN/Abp/Auditing/AuditLogs/EntityChangeGetWithUsernameDto.cs @@ -0,0 +1,7 @@ +namespace LINGYUN.Abp.Auditing.AuditLogs; + +public class EntityChangeGetWithUsernameDto +{ + public string EntityId { get; set; } + public string EntityTypeFullName { get; set; } +} diff --git a/aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.Application.Contracts/LINGYUN/Abp/Auditing/AuditLogs/EntityChangeWithUsernameDto.cs b/aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.Application.Contracts/LINGYUN/Abp/Auditing/AuditLogs/EntityChangeWithUsernameDto.cs new file mode 100644 index 000000000..5da2e0c32 --- /dev/null +++ b/aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.Application.Contracts/LINGYUN/Abp/Auditing/AuditLogs/EntityChangeWithUsernameDto.cs @@ -0,0 +1,7 @@ +namespace LINGYUN.Abp.Auditing.AuditLogs; +public class EntityChangeWithUsernameDto +{ + public EntityChangeDto EntityChange { get; set; } + + public string UserName { get; set; } +} diff --git a/aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.Application.Contracts/LINGYUN/Abp/Auditing/AuditLogs/IEntityChangesAppService.cs b/aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.Application.Contracts/LINGYUN/Abp/Auditing/AuditLogs/IEntityChangesAppService.cs new file mode 100644 index 000000000..9bb561963 --- /dev/null +++ b/aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.Application.Contracts/LINGYUN/Abp/Auditing/AuditLogs/IEntityChangesAppService.cs @@ -0,0 +1,17 @@ +using System; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Application.Services; + +namespace LINGYUN.Abp.Auditing.AuditLogs; + +public interface IEntityChangesAppService : IApplicationService +{ + Task GetAsync(Guid id); + + Task GetWithUsernameAsync(Guid id); + + Task> GetListAsync(EntityChangeGetByPagedDto input); + + Task> GetWithUsernameAsync(EntityChangeGetWithUsernameDto input); +} diff --git a/aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.Application/LINGYUN/Abp/Auditing/AbpAuditingMapperProfile.cs b/aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.Application/LINGYUN/Abp/Auditing/AbpAuditingMapperProfile.cs index 8ebb2145f..d328041ef 100644 --- a/aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.Application/LINGYUN/Abp/Auditing/AbpAuditingMapperProfile.cs +++ b/aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.Application/LINGYUN/Abp/Auditing/AbpAuditingMapperProfile.cs @@ -14,6 +14,7 @@ namespace LINGYUN.Abp.Auditing CreateMap() .MapExtraProperties(); CreateMap(); + CreateMap(); CreateMap() .MapExtraProperties(); CreateMap() diff --git a/aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.Application/LINGYUN/Abp/Auditing/AuditLogs/EntityChangesAppService.cs b/aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.Application/LINGYUN/Abp/Auditing/AuditLogs/EntityChangesAppService.cs new file mode 100644 index 000000000..169e4b037 --- /dev/null +++ b/aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.Application/LINGYUN/Abp/Auditing/AuditLogs/EntityChangesAppService.cs @@ -0,0 +1,62 @@ +using LINGYUN.Abp.Auditing.Features; +using LINGYUN.Abp.Auditing.Permissions; +using LINGYUN.Abp.AuditLogging; +using Microsoft.AspNetCore.Authorization; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Volo.Abp.Application.Dtos; +using Volo.Abp.Features; + +namespace LINGYUN.Abp.Auditing.AuditLogs; + +[Authorize(AuditingPermissionNames.AuditLog.Default)] +[RequiresFeature(AuditingFeatureNames.Logging.AuditLog)] +public class EntityChangesAppService : AuditingApplicationServiceBase, IEntityChangesAppService +{ + protected IEntityChangeStore EntityChangeStore { get; } + + public EntityChangesAppService( + IEntityChangeStore entityChangeStore) + { + EntityChangeStore = entityChangeStore; + } + + public async virtual Task GetAsync(Guid id) + { + var entityChange = await EntityChangeStore.GetAsync(id); + + return ObjectMapper.Map(entityChange); + } + + public async virtual Task> GetListAsync(EntityChangeGetByPagedDto input) + { + var totalCount = await EntityChangeStore.GetCountAsync( + input.AuditLogId, input.StartTime, input.EndTime, + input.ChangeType, input.EntityId, input.EntityTypeFullName); + + var entityChanges = await EntityChangeStore.GetListAsync( + input.Sorting, input.MaxResultCount, input.SkipCount, + input.AuditLogId, input.StartTime, input.EndTime, + input.ChangeType, input.EntityId, input.EntityTypeFullName); + + return new PagedResultDto(totalCount, + ObjectMapper.Map, List>(entityChanges)); + } + + public async virtual Task GetWithUsernameAsync(Guid id) + { + var entityChangeWithUsername = await EntityChangeStore.GetWithUsernameAsync(id); + + return ObjectMapper.Map(entityChangeWithUsername); + } + + public async virtual Task> GetWithUsernameAsync(EntityChangeGetWithUsernameDto input) + { + var entityChangeWithUsernames = await EntityChangeStore.GetWithUsernameAsync( + input.EntityId, input.EntityTypeFullName); + + return new ListResultDto( + ObjectMapper.Map, List>(entityChangeWithUsernames)); + } +} diff --git a/aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.HttpApi/LINGYUN/Abp/Auditing/AuditLogs/EntityChangesController.cs b/aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.HttpApi/LINGYUN/Abp/Auditing/AuditLogs/EntityChangesController.cs new file mode 100644 index 000000000..8d4369e97 --- /dev/null +++ b/aspnet-core/modules/auditing/LINGYUN.Abp.Auditing.HttpApi/LINGYUN/Abp/Auditing/AuditLogs/EntityChangesController.cs @@ -0,0 +1,50 @@ +using Microsoft.AspNetCore.Mvc; +using System; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.Abp.Application.Dtos; +using Volo.Abp.AspNetCore.Mvc; + +namespace LINGYUN.Abp.Auditing.AuditLogs; + +[RemoteService(Name = AuditingRemoteServiceConsts.RemoteServiceName)] +[Area("auditing")] +[ControllerName("entity-changes")] +[Route("api/auditing/entity-changes")] +public class EntityChangesController : AbpControllerBase, IEntityChangesAppService +{ + protected IEntityChangesAppService EntityChangeAppService { get; } + + public EntityChangesController( + IEntityChangesAppService entityChangeAppService) + { + EntityChangeAppService = entityChangeAppService; + } + + [HttpGet] + [Route("{id}")] + public Task GetAsync(Guid id) + { + return EntityChangeAppService.GetAsync(id); + } + + [HttpGet] + public Task> GetListAsync(EntityChangeGetByPagedDto input) + { + return EntityChangeAppService.GetListAsync(input); + } + + [HttpGet] + [Route("with-username/{id}")] + public Task GetWithUsernameAsync(Guid id) + { + return EntityChangeAppService.GetWithUsernameAsync(id); + } + + [HttpGet] + [Route("with-username")] + public Task> GetWithUsernameAsync(EntityChangeGetWithUsernameDto input) + { + return EntityChangeAppService.GetWithUsernameAsync(input); + } +} diff --git a/aspnet-core/modules/elasticsearch/LINGYUN.Abp.Elasticsearch/LINGYUN/Abp/Elasticsearch/AbpElasticsearchOptions.cs b/aspnet-core/modules/elasticsearch/LINGYUN.Abp.Elasticsearch/LINGYUN/Abp/Elasticsearch/AbpElasticsearchOptions.cs index 4bd224ea7..1af0f1a63 100644 --- a/aspnet-core/modules/elasticsearch/LINGYUN.Abp.Elasticsearch/LINGYUN/Abp/Elasticsearch/AbpElasticsearchOptions.cs +++ b/aspnet-core/modules/elasticsearch/LINGYUN.Abp.Elasticsearch/LINGYUN/Abp/Elasticsearch/AbpElasticsearchOptions.cs @@ -15,6 +15,7 @@ namespace LINGYUN.Abp.Elasticsearch /// 默认:false /// public bool FieldCamelCase { get; set; } + public bool DisableDirectStreaming { get; set; } public string NodeUris { get; set; } public int ConnectionLimit { get; set; } public string UserName { get; set; } @@ -61,6 +62,8 @@ namespace LINGYUN.Abp.Elasticsearch configuration.BasicAuthentication(UserName, Password); } + configuration.DisableDirectStreaming(DisableDirectStreaming); + return configuration; } }