20 changed files with 131 additions and 163 deletions
@ -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; } |
||||
|
} |
||||
|
} |
||||
@ -1,17 +0,0 @@ |
|||||
<Project Sdk="Microsoft.NET.Sdk"> |
|
||||
|
|
||||
<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,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,10 +0,0 @@ |
|||||
using Volo.Abp.Modularity; |
|
||||
|
|
||||
namespace CompanyName.ProjectName.ElasticsearchRepository |
|
||||
{ |
|
||||
|
|
||||
public class ProjectNameElasticSearchModule : AbpModule |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue