11 changed files with 0 additions and 234 deletions
@ -1,15 +0,0 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
<Import Project="..\..\..\common.props" /> |
|||
<PropertyGroup> |
|||
<TargetFramework>net5.0</TargetFramework> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Volo.Abp.Core" Version="$(AbpPackageVersion)" /> |
|||
|
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\..\frameworks\Extensions\src\CompanyName.ProjectName.Extension\CompanyName.ProjectName.Extension.csproj" /> |
|||
</ItemGroup> |
|||
</Project> |
|||
@ -1,14 +0,0 @@ |
|||
using System; |
|||
using CompanyName.ProjectName.Extension.Customs.Dtos; |
|||
|
|||
namespace CompanyName.ProjectName.ElasticsearchRepository.Dto |
|||
{ |
|||
public class PagingElasticSearchLogInput : PagingBase |
|||
{ |
|||
public string Filter { get; set; } |
|||
|
|||
public DateTime? StartCreationTime { get; set; } |
|||
|
|||
public DateTime? EndCreationTime { get; set; } |
|||
} |
|||
} |
|||
@ -1,27 +0,0 @@ |
|||
using System; |
|||
using Newtonsoft.Json; |
|||
|
|||
namespace CompanyName.ProjectName.ElasticsearchRepository.Dto |
|||
{ |
|||
[Serializable] |
|||
public class PagingElasticSearchLogOutput |
|||
{ |
|||
/// <summary>
|
|||
/// 日志级别
|
|||
/// </summary>
|
|||
public string Level { get; set; } |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 日志内容
|
|||
/// </summary>
|
|||
public string Message { get; set; } |
|||
|
|||
|
|||
/// <summary>
|
|||
/// 创建时间
|
|||
/// </summary>
|
|||
[JsonProperty("@timestamp")] |
|||
public DateTime CreationTime { get; set; } |
|||
} |
|||
} |
|||
@ -1,17 +0,0 @@ |
|||
using System.Threading.Tasks; |
|||
using CompanyName.ProjectName.ElasticsearchRepository.Dto; |
|||
using CompanyName.ProjectName.Extension.Customs.Dtos; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace CompanyName.ProjectName.ElasticsearchRepository |
|||
{ |
|||
public interface ICompanyNameProjectNameLogRepository : ITransientDependency |
|||
{ |
|||
/// <summary>
|
|||
/// 分页查询es日志
|
|||
/// </summary>
|
|||
/// <param name="input"></param>
|
|||
/// <returns></returns>
|
|||
Task<CustomePagedResultDto<PagingElasticSearchLogOutput>> PaingAsync(PagingElasticSearchLogInput input); |
|||
} |
|||
} |
|||
@ -1,9 +0,0 @@ |
|||
using System; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace CompanyName.ProjectName.ElasticsearchRepository.Shared |
|||
{ |
|||
public class ProjectNameElasticSearchSharedModule : AbpModule |
|||
{ |
|||
} |
|||
} |
|||
@ -1,16 +0,0 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
<Import Project="..\..\..\common.props" /> |
|||
<PropertyGroup> |
|||
<TargetFramework>net5.0</TargetFramework> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Volo.Abp.Core" Version="$(AbpPackageVersion)" /> |
|||
<PackageReference Include="NEST" Version="$(NESTVersion)" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\CompanyName.ProjectName.Domain\CompanyName.ProjectName.Domain.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -1,69 +0,0 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using CompanyName.ProjectName.ElasticsearchRepository.Dto; |
|||
using CompanyName.ProjectName.Extension.Customs.Dtos; |
|||
using Microsoft.Extensions.Configuration; |
|||
using Nest; |
|||
|
|||
namespace CompanyName.ProjectName.ElasticsearchRepository |
|||
{ |
|||
public class CompanyNameProjectNameLogRepository : ElasticsearchBasicRepository, |
|||
ICompanyNameProjectNameLogRepository |
|||
{ |
|||
private readonly IConfiguration _configuration; |
|||
|
|||
public CompanyNameProjectNameLogRepository( |
|||
IElasticsearchProvider elasticsearchProvider, |
|||
IConfiguration configuration) : base(elasticsearchProvider) |
|||
{ |
|||
_configuration = configuration; |
|||
} |
|||
|
|||
public async Task<CustomePagedResultDto<PagingElasticSearchLogOutput>> PaingAsync( |
|||
PagingElasticSearchLogInput input) |
|||
{ |
|||
var IndexName = |
|||
_configuration.GetValue<string>("ElasticSearch:SearchIndexFormat"); |
|||
// 默认查询当天
|
|||
input.StartCreationTime = input.StartCreationTime?.AddMilliseconds(-1) ?? |
|||
DateTime.Now.Date.AddMilliseconds(-1); |
|||
input.EndCreationTime = |
|||
input.EndCreationTime?.AddDays(1).AddMilliseconds(-1) ?? |
|||
DateTime.Now.Date.AddDays(1).AddMilliseconds(-1); |
|||
var mustFilters = |
|||
new List<Func<QueryContainerDescriptor<PagingElasticSearchLogOutput>, |
|||
QueryContainer>> |
|||
{ |
|||
t => t.DateRange(f => |
|||
f.Field(fd => fd.CreationTime).TimeZone("Asia/Shanghai") |
|||
.GreaterThanOrEquals(input.StartCreationTime.Value)), |
|||
t => t.DateRange( |
|||
f => f.Field(fd => fd.CreationTime).TimeZone("Asia/Shanghai") |
|||
.LessThanOrEquals(input.EndCreationTime.Value)) |
|||
}; |
|||
|
|||
if (!string.IsNullOrWhiteSpace(input.Filter)) |
|||
{ |
|||
mustFilters.Add(t => |
|||
t.MatchPhrase(f => f.Field(fd => fd.Message).Query(input.Filter.Trim()))); |
|||
} |
|||
|
|||
var result = await Client.SearchAsync<PagingElasticSearchLogOutput>(e => e |
|||
.Index(IndexName) |
|||
.From(input.SkipCount) |
|||
.Size(input.PageSize) |
|||
.Sort(s => s.Descending(sd => sd.CreationTime)) |
|||
.Query(q => q.Bool(qb => qb.Filter(mustFilters)))); |
|||
|
|||
if (result.HitsMetadata != null) |
|||
{ |
|||
return new CustomePagedResultDto<PagingElasticSearchLogOutput>( |
|||
result.HitsMetadata.Total.Value, result.Documents.ToList()); |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
} |
|||
} |
|||
@ -1,18 +0,0 @@ |
|||
using Nest; |
|||
using Volo.Abp.Domain.Services; |
|||
|
|||
namespace CompanyName.ProjectName.ElasticsearchRepository |
|||
{ |
|||
public abstract class ElasticsearchBasicRepository : DomainService |
|||
{ |
|||
private readonly IElasticsearchProvider _elasticsearchProvider; |
|||
|
|||
// ReSharper disable once PublicConstructorInAbstractClass
|
|||
public ElasticsearchBasicRepository(IElasticsearchProvider elasticsearchProvider) |
|||
{ |
|||
_elasticsearchProvider = elasticsearchProvider; |
|||
} |
|||
|
|||
protected IElasticClient Client => _elasticsearchProvider.GetElasticClient(); |
|||
} |
|||
} |
|||
@ -1,29 +0,0 @@ |
|||
using System; |
|||
using Elasticsearch.Net; |
|||
using Microsoft.Extensions.Configuration; |
|||
using Nest; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace CompanyName.ProjectName.ElasticsearchRepository |
|||
{ |
|||
public class ElasticsearchProvider : IElasticsearchProvider, ISingletonDependency |
|||
{ |
|||
private readonly IConfiguration _configuration; |
|||
|
|||
public ElasticsearchProvider(IConfiguration configuration) |
|||
{ |
|||
_configuration = configuration; |
|||
} |
|||
|
|||
public IElasticClient GetElasticClient() |
|||
{ |
|||
var pool = new SingleNodeConnectionPool(new Uri(_configuration.GetValue<string>("ElasticSearch:Url"))); |
|||
var connectionSettings = |
|||
new ConnectionSettings(pool); |
|||
connectionSettings.EnableHttpCompression(); |
|||
connectionSettings.BasicAuthentication(_configuration.GetValue<string>("ElasticSearch:UserName"), |
|||
_configuration.GetValue<string>("ElasticSearch:Password")); |
|||
return new ElasticClient(connectionSettings); |
|||
} |
|||
} |
|||
} |
|||
@ -1,10 +0,0 @@ |
|||
using Nest; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace CompanyName.ProjectName.ElasticsearchRepository |
|||
{ |
|||
public interface IElasticsearchProvider : ISingletonDependency |
|||
{ |
|||
IElasticClient GetElasticClient(); |
|||
} |
|||
} |
|||
@ -1,10 +0,0 @@ |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace CompanyName.ProjectName.ElasticsearchRepository |
|||
{ |
|||
|
|||
public class ProjectNameElasticSearchModule : AbpModule |
|||
{ |
|||
|
|||
} |
|||
} |
|||
Loading…
Reference in new issue