21 changed files with 259 additions and 61 deletions
@ -0,0 +1,26 @@ |
|||||
|
using System; |
||||
|
|
||||
|
|
||||
|
namespace CompanyName.ProjectName.ElasticsearchRepository.Dto |
||||
|
{ |
||||
|
|
||||
|
public class PagingElasticSearchLogOutput |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 日志级别
|
||||
|
/// </summary>
|
||||
|
public string Level { get; set; } |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 日志内容
|
||||
|
/// </summary>
|
||||
|
public string Message { get; set; } |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 创建时间
|
||||
|
/// </summary>
|
||||
|
public DateTime CreationTime { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -1,27 +1,28 @@ |
|||||
<Project Sdk="Microsoft.NET.Sdk"> |
<Project Sdk="Microsoft.NET.Sdk"> |
||||
<Import Project="..\..\..\common.props" /> |
<Import Project="..\..\..\common.props" /> |
||||
|
|
||||
<PropertyGroup> |
<PropertyGroup> |
||||
<TargetFramework>net5.0</TargetFramework> |
<TargetFramework>net5.0</TargetFramework> |
||||
<RootNamespace>CompanyName.ProjectName</RootNamespace> |
<RootNamespace>CompanyName.ProjectName</RootNamespace> |
||||
</PropertyGroup> |
</PropertyGroup> |
||||
|
|
||||
<ItemGroup> |
<ItemGroup> |
||||
<ProjectReference Include="..\..\..\modules\DataDictionaryManagement\src\CompanyName.ProjectName.DataDictionaryManagement.Application\CompanyName.ProjectName.DataDictionaryManagement.Application.csproj" /> |
<ProjectReference Include="..\..\..\modules\DataDictionaryManagement\src\CompanyName.ProjectName.DataDictionaryManagement.Application\CompanyName.ProjectName.DataDictionaryManagement.Application.csproj" /> |
||||
<ProjectReference Include="..\..\..\modules\NotificationManagement\src\CompanyName.ProjectName.NotificationManagement.Application\CompanyName.ProjectName.NotificationManagement.Application.csproj" /> |
<ProjectReference Include="..\..\..\modules\NotificationManagement\src\CompanyName.ProjectName.NotificationManagement.Application\CompanyName.ProjectName.NotificationManagement.Application.csproj" /> |
||||
<ProjectReference Include="..\CompanyName.ProjectName.Domain\CompanyName.ProjectName.Domain.csproj" /> |
<ProjectReference Include="..\CompanyName.ProjectName.Domain\CompanyName.ProjectName.Domain.csproj" /> |
||||
<ProjectReference Include="..\CompanyName.ProjectName.Application.Contracts\CompanyName.ProjectName.Application.Contracts.csproj" /> |
<ProjectReference Include="..\CompanyName.ProjectName.Application.Contracts\CompanyName.ProjectName.Application.Contracts.csproj" /> |
||||
<ProjectReference Include="..\CompanyName.ProjectName.FreeSqlRepository\CompanyName.ProjectName.FreeSqlRepository.csproj" /> |
<ProjectReference Include="..\CompanyName.ProjectName.FreeSqlRepository\CompanyName.ProjectName.FreeSqlRepository.csproj" /> |
||||
</ItemGroup> |
</ItemGroup> |
||||
|
|
||||
<ItemGroup> |
<ItemGroup> |
||||
<PackageReference Include="EasyAbp.Abp.SettingUi.Application" Version="$(EasyAbpSttingVersion)" /> |
<PackageReference Include="EasyAbp.Abp.SettingUi.Application" Version="$(EasyAbpSttingVersion)" /> |
||||
<PackageReference Include="Volo.Abp.Account.Application" Version="$(AbpPackageVersion)" /> |
<PackageReference Include="Volo.Abp.Account.Application" Version="$(AbpPackageVersion)" /> |
||||
<PackageReference Include="Volo.Abp.Identity.Application" Version="$(AbpPackageVersion)" /> |
<PackageReference Include="Volo.Abp.Identity.Application" Version="$(AbpPackageVersion)" /> |
||||
<PackageReference Include="Volo.Abp.PermissionManagement.Application" Version="$(AbpPackageVersion)" /> |
<PackageReference Include="Volo.Abp.PermissionManagement.Application" Version="$(AbpPackageVersion)" /> |
||||
<PackageReference Include="Volo.Abp.TenantManagement.Application" Version="$(AbpPackageVersion)" /> |
<PackageReference Include="Volo.Abp.TenantManagement.Application" Version="$(AbpPackageVersion)" /> |
||||
<PackageReference Include="Volo.Abp.FeatureManagement.Application" Version="$(AbpPackageVersion)" /> |
<PackageReference Include="Volo.Abp.FeatureManagement.Application" Version="$(AbpPackageVersion)" /> |
||||
<PackageReference Include="Volo.Abp.SettingManagement.Application" Version="$(AbpPackageVersion)" /> |
<PackageReference Include="Volo.Abp.SettingManagement.Application" Version="$(AbpPackageVersion)" /> |
||||
</ItemGroup> |
<PackageReference Include="NEST" Version="$(NESTVersion)" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
</Project> |
</Project> |
||||
|
|||||
@ -1,25 +1,76 @@ |
|||||
using System.Threading.Tasks; |
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
using CompanyName.ProjectName.ElasticsearchRepository; |
using CompanyName.ProjectName.ElasticsearchRepository; |
||||
using CompanyName.ProjectName.ElasticsearchRepository.Dto; |
using CompanyName.ProjectName.ElasticsearchRepository.Dto; |
||||
using CompanyName.ProjectName.Extension.Customs.Dtos; |
using CompanyName.ProjectName.Extension.Customs.Dtos; |
||||
using CompanyName.ProjectName.Permissions; |
using CompanyName.ProjectName.Permissions; |
||||
using Microsoft.AspNetCore.Authorization; |
using Microsoft.AspNetCore.Authorization; |
||||
|
using Microsoft.Extensions.Configuration; |
||||
|
using Nest; |
||||
|
|
||||
namespace CompanyName.ProjectName.ElasticSearchs |
namespace CompanyName.ProjectName.ElasticSearchs |
||||
{ |
{ |
||||
[Authorize(Policy = ProjectNamePermissions.SystemManagement.ES)] |
[Authorize(Policy = ProjectNamePermissions.SystemManagement.ES)] |
||||
public class CompanyNameProjectNameLogAppService:ProjectNameAppService,ICompanyNameProjectNameLogAppService |
public class CompanyNameProjectNameLogAppService : ElasticsearchBasicService, |
||||
|
ICompanyNameProjectNameLogAppService |
||||
{ |
{ |
||||
private readonly ICompanyNameProjectNameLogRepository _companyNameProjectNameLogRepository; |
private readonly IConfiguration _configuration; |
||||
|
|
||||
public CompanyNameProjectNameLogAppService(ICompanyNameProjectNameLogRepository companyNameProjectNameLogRepository) |
public CompanyNameProjectNameLogAppService( |
||||
|
IElasticsearchProvider elasticsearchProvider, |
||||
|
IConfiguration configuration) : base(elasticsearchProvider) |
||||
{ |
{ |
||||
_companyNameProjectNameLogRepository = companyNameProjectNameLogRepository; |
_configuration = configuration; |
||||
} |
} |
||||
|
|
||||
public Task<CustomePagedResultDto<PagingElasticSearchLogOutput>> PaingAsync(PagingElasticSearchLogInput input) |
public async Task<CustomePagedResultDto<PagingElasticSearchLogOutput>> PaingAsync( |
||||
|
PagingElasticSearchLogInput input) |
||||
{ |
{ |
||||
return _companyNameProjectNameLogRepository.PaingAsync(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<PagingElasticSearchLogDto>, |
||||
|
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<PagingElasticSearchLogDto>(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, |
||||
|
ObjectMapper |
||||
|
.Map<List<PagingElasticSearchLogDto>, List<PagingElasticSearchLogOutput>>( |
||||
|
result.Documents.ToList())); |
||||
|
} |
||||
|
|
||||
|
return null; |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
@ -0,0 +1,32 @@ |
|||||
|
using System; |
||||
|
using Nest; |
||||
|
|
||||
|
namespace CompanyName.ProjectName.ElasticSearchs |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Dto为什么在Service层
|
||||
|
/// 因为NEST 类库的坑 PropertyName必须用这个
|
||||
|
/// 不想在契约层添加NEST 包引用
|
||||
|
/// </summary>
|
||||
|
[Serializable] |
||||
|
public class PagingElasticSearchLogDto |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 日志级别
|
||||
|
/// </summary>
|
||||
|
public string Level { get; set; } |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 日志内容
|
||||
|
/// </summary>
|
||||
|
public string Message { get; set; } |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 创建时间
|
||||
|
/// </summary>
|
||||
|
[PropertyName("@timestamp")] |
||||
|
public DateTime CreationTime { get; set; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
using Nest; |
||||
|
using Volo.Abp.Domain.Services; |
||||
|
|
||||
|
namespace CompanyName.ProjectName.ElasticsearchRepository |
||||
|
{ |
||||
|
public abstract class ElasticsearchBasicService : ProjectNameAppService |
||||
|
{ |
||||
|
private readonly IElasticsearchProvider _elasticsearchProvider; |
||||
|
|
||||
|
// ReSharper disable once PublicConstructorInAbstractClass
|
||||
|
public ElasticsearchBasicService(IElasticsearchProvider elasticsearchProvider) |
||||
|
{ |
||||
|
_elasticsearchProvider = elasticsearchProvider; |
||||
|
} |
||||
|
|
||||
|
protected IElasticClient Client => _elasticsearchProvider.GetElasticClient(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,29 @@ |
|||||
|
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); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,10 @@ |
|||||
|
using Nest; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
|
namespace CompanyName.ProjectName.ElasticsearchRepository |
||||
|
{ |
||||
|
public interface IElasticsearchProvider : ISingletonDependency |
||||
|
{ |
||||
|
IElasticClient GetElasticClient(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
<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> |
||||
@ -0,0 +1,14 @@ |
|||||
|
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; } |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
using System; |
||||
|
using Volo.Abp.Modularity; |
||||
|
|
||||
|
namespace CompanyName.ProjectName.ElasticsearchRepository.Shared |
||||
|
{ |
||||
|
public class ProjectNameElasticSearchSharedModule : AbpModule |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
@ -1,17 +1,16 @@ |
|||||
<Project Sdk="Microsoft.NET.Sdk"> |
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
<Import Project="..\..\..\common.props" /> |
||||
<PropertyGroup> |
<PropertyGroup> |
||||
<TargetFramework>net5.0</TargetFramework> |
<TargetFramework>net5.0</TargetFramework> |
||||
</PropertyGroup> |
</PropertyGroup> |
||||
|
|
||||
<ItemGroup> |
<ItemGroup> |
||||
<PackageReference Include="Volo.Abp.Core" Version="$(AbpPackageVersion)"/> |
<PackageReference Include="Volo.Abp.Core" Version="$(AbpPackageVersion)" /> |
||||
<PackageReference Include="NEST" Version="$(NESTVersion)"/> |
<PackageReference Include="NEST" Version="$(NESTVersion)" /> |
||||
</ItemGroup> |
</ItemGroup> |
||||
|
|
||||
<ItemGroup> |
<ItemGroup> |
||||
|
<ProjectReference Include="..\CompanyName.ProjectName.Domain\CompanyName.ProjectName.Domain.csproj" /> |
||||
<ProjectReference Include="..\CompanyName.ProjectName.Domain\CompanyName.ProjectName.Domain.csproj"/> |
|
||||
</ItemGroup> |
</ItemGroup> |
||||
|
|
||||
</Project> |
</Project> |
||||
Loading…
Reference in new issue