Browse Source

feat: 添加ElasticSearch模块

pull/126/head
wangjun 3 years ago
parent
commit
92c167028b
  1. 14
      aspnet-core/Lion.AbpPro.sln
  2. 14
      aspnet-core/frameworks/src/Lion.AbpPro.ElasticSearch/GlobalUsings.cs
  3. 13
      aspnet-core/frameworks/src/Lion.AbpPro.ElasticSearch/Lion.AbpPro.ElasticSearch.csproj
  4. 10
      aspnet-core/frameworks/src/Lion.AbpPro.ElasticSearch/Lion/AbpPro/ElasticSearch/AbpProElasticSearchModule.cs
  5. 19
      aspnet-core/frameworks/src/Lion.AbpPro.ElasticSearch/Lion/AbpPro/ElasticSearch/AbpProElasticSearchOptions.cs
  6. 114
      aspnet-core/frameworks/src/Lion.AbpPro.ElasticSearch/Lion/AbpPro/ElasticSearch/ElasticSearchRepository.cs
  7. 19
      aspnet-core/frameworks/src/Lion.AbpPro.ElasticSearch/Lion/AbpPro/ElasticSearch/ElasticsearchProvider.cs
  8. 24
      aspnet-core/frameworks/src/Lion.AbpPro.ElasticSearch/Lion/AbpPro/ElasticSearch/Exceptions/AbpProElasticSearchEntityNotFoundException.cs
  9. 24
      aspnet-core/frameworks/src/Lion.AbpPro.ElasticSearch/Lion/AbpPro/ElasticSearch/Exceptions/AbpProElasticSearchException.cs
  10. 45
      aspnet-core/frameworks/src/Lion.AbpPro.ElasticSearch/Lion/AbpPro/ElasticSearch/IBasicElasticSearchRepository.cs
  11. 15
      aspnet-core/frameworks/src/Lion.AbpPro.ElasticSearch/Lion/AbpPro/ElasticSearch/IElasticSearchEntity.cs
  12. 6
      aspnet-core/frameworks/src/Lion.AbpPro.ElasticSearch/Lion/AbpPro/ElasticSearch/IElasticsearchProvider.cs
  13. 32
      aspnet-core/frameworks/test/Lion.AbpPro.ElasticSearch.Tests/Lion.AbpPro.ElasticSearch.Tests.csproj
  14. 13
      aspnet-core/frameworks/test/Lion.AbpPro.ElasticSearch.Tests/Lion/AbpPro/ElasticSearch/AbpProElasticSearchTestBase.cs
  15. 9
      aspnet-core/frameworks/test/Lion.AbpPro.ElasticSearch.Tests/Lion/AbpPro/ElasticSearch/AbpProElasticSearchTestBaseModule.cs
  16. 412
      aspnet-core/frameworks/test/Lion.AbpPro.ElasticSearch.Tests/Lion/AbpPro/ElasticSearch/StudentElasticSearchRepositoryTests.cs
  17. 7
      aspnet-core/frameworks/test/Lion.AbpPro.ElasticSearch.Tests/Lion/AbpPro/ElasticSearch/Students/Gender.cs
  18. 5
      aspnet-core/frameworks/test/Lion.AbpPro.ElasticSearch.Tests/Lion/AbpPro/ElasticSearch/Students/IStudentElasticSearchRepository.cs
  19. 16
      aspnet-core/frameworks/test/Lion.AbpPro.ElasticSearch.Tests/Lion/AbpPro/ElasticSearch/Students/Student.cs
  20. 13
      aspnet-core/frameworks/test/Lion.AbpPro.ElasticSearch.Tests/Lion/AbpPro/ElasticSearch/Students/StudentElasticSearchRepository.cs
  21. 3
      aspnet-core/frameworks/test/Lion.AbpPro.ElasticSearch.Tests/Usings.cs
  22. 7
      aspnet-core/frameworks/test/Lion.AbpPro.ElasticSearch.Tests/appsettings.json
  23. 11
      aspnet-core/services/src/Lion.AbpPro.Application.Contracts/ElasticSearches/Dto/PagingElasticSearchLogInput.cs
  24. 23
      aspnet-core/services/src/Lion.AbpPro.Application.Contracts/ElasticSearches/Dto/PagingElasticSearchLogOutput.cs
  25. 14
      aspnet-core/services/src/Lion.AbpPro.Application.Contracts/ElasticSearches/ILionAbpProLogAppService.cs
  26. 16
      aspnet-core/services/src/Lion.AbpPro.Application.Contracts/Lion.AbpPro.Application.Contracts.csproj
  27. 6
      aspnet-core/services/src/Lion.AbpPro.Application.Contracts/Permissions/AbpProPermissionDefinitionProvider.cs
  28. 2
      aspnet-core/services/src/Lion.AbpPro.Application.Contracts/Permissions/AbpProPermissions.cs
  29. 29
      aspnet-core/services/src/Lion.AbpPro.Application/ElasticSearches/Dto/PagingElasticSearchLogDto.cs
  30. 10
      aspnet-core/services/src/Lion.AbpPro.Application/ElasticSearches/ElasticSearchApplicationAutoMapperProfile.cs
  31. 73
      aspnet-core/services/src/Lion.AbpPro.Application/ElasticSearches/LionAbpProLogAppService.cs
  32. 15
      aspnet-core/services/src/Lion.AbpPro.Application/ElasticSearches/Providers/ElasticsearchBasicService.cs
  33. 23
      aspnet-core/services/src/Lion.AbpPro.Application/ElasticSearches/Providers/ElasticsearchProvider.cs
  34. 7
      aspnet-core/services/src/Lion.AbpPro.Application/ElasticSearches/Providers/IElasticsearchProvider.cs
  35. 4
      aspnet-core/services/src/Lion.AbpPro.Application/GlobalUsings.cs
  36. 4
      aspnet-core/services/src/Lion.AbpPro.Application/Lion.AbpPro.Application.csproj
  37. 20
      aspnet-core/services/src/Lion.AbpPro.HttpApi/Controllers/Systems/LionAbpProLogController.cs
  38. 2
      aspnet-core/services/src/Lion.AbpPro.HttpApi/GlobalUsings.cs

14
aspnet-core/Lion.AbpPro.sln

@ -252,6 +252,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lion.AbpPro.EntityFramework
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lion.AbpPro.EntityFrameworkCore.Tests", "frameworks\test\Lion.AbpPro.EntityFrameworkCore.Mysql.Tests\Lion.AbpPro.EntityFrameworkCore.Tests.csproj", "{AEFB2D25-29F4-4CE2-820D-A74EFB6A56B2}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lion.AbpPro.EntityFrameworkCore.Tests", "frameworks\test\Lion.AbpPro.EntityFrameworkCore.Mysql.Tests\Lion.AbpPro.EntityFrameworkCore.Tests.csproj", "{AEFB2D25-29F4-4CE2-820D-A74EFB6A56B2}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lion.AbpPro.ElasticSearch", "frameworks\src\Lion.AbpPro.ElasticSearch\Lion.AbpPro.ElasticSearch.csproj", "{CCC3BE80-5D36-4833-B629-9F4230396EC3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lion.AbpPro.ElasticSearch.Tests", "frameworks\test\Lion.AbpPro.ElasticSearch.Tests\Lion.AbpPro.ElasticSearch.Tests.csproj", "{2B2110E1-4C29-41AF-ADB5-C1B5F3C3C1D0}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -618,6 +622,14 @@ Global
{AEFB2D25-29F4-4CE2-820D-A74EFB6A56B2}.Debug|Any CPU.Build.0 = Debug|Any CPU {AEFB2D25-29F4-4CE2-820D-A74EFB6A56B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AEFB2D25-29F4-4CE2-820D-A74EFB6A56B2}.Release|Any CPU.ActiveCfg = Release|Any CPU {AEFB2D25-29F4-4CE2-820D-A74EFB6A56B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AEFB2D25-29F4-4CE2-820D-A74EFB6A56B2}.Release|Any CPU.Build.0 = Release|Any CPU {AEFB2D25-29F4-4CE2-820D-A74EFB6A56B2}.Release|Any CPU.Build.0 = Release|Any CPU
{CCC3BE80-5D36-4833-B629-9F4230396EC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CCC3BE80-5D36-4833-B629-9F4230396EC3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CCC3BE80-5D36-4833-B629-9F4230396EC3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CCC3BE80-5D36-4833-B629-9F4230396EC3}.Release|Any CPU.Build.0 = Release|Any CPU
{2B2110E1-4C29-41AF-ADB5-C1B5F3C3C1D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2B2110E1-4C29-41AF-ADB5-C1B5F3C3C1D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B2110E1-4C29-41AF-ADB5-C1B5F3C3C1D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B2110E1-4C29-41AF-ADB5-C1B5F3C3C1D0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -738,6 +750,8 @@ Global
{496667FC-2D9A-4CEF-9CC3-A372E9B9C002} = {7BE85EBC-99AD-4CDE-957E-4BDD087FC4E3} {496667FC-2D9A-4CEF-9CC3-A372E9B9C002} = {7BE85EBC-99AD-4CDE-957E-4BDD087FC4E3}
{2CDD9AF8-AEE1-43EA-B014-DAFE4D3D7DD1} = {7BE85EBC-99AD-4CDE-957E-4BDD087FC4E3} {2CDD9AF8-AEE1-43EA-B014-DAFE4D3D7DD1} = {7BE85EBC-99AD-4CDE-957E-4BDD087FC4E3}
{AEFB2D25-29F4-4CE2-820D-A74EFB6A56B2} = {EFC415F8-872F-4C7E-8645-31A51481BCFC} {AEFB2D25-29F4-4CE2-820D-A74EFB6A56B2} = {EFC415F8-872F-4C7E-8645-31A51481BCFC}
{CCC3BE80-5D36-4833-B629-9F4230396EC3} = {7BE85EBC-99AD-4CDE-957E-4BDD087FC4E3}
{2B2110E1-4C29-41AF-ADB5-C1B5F3C3C1D0} = {EFC415F8-872F-4C7E-8645-31A51481BCFC}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {28315BFD-90E7-4E14-A2EA-F3D23AF4126F} SolutionGuid = {28315BFD-90E7-4E14-A2EA-F3D23AF4126F}

14
aspnet-core/frameworks/src/Lion.AbpPro.ElasticSearch/GlobalUsings.cs

@ -0,0 +1,14 @@
// Global using directives
global using System.Collections.Concurrent;
global using System.Runtime.Serialization;
global using Elasticsearch.Net;
global using Microsoft.Extensions.Logging;
global using Microsoft.Extensions.Options;
global using Nest;
global using Volo.Abp.Autofac;
global using Volo.Abp.DependencyInjection;
global using Volo.Abp.Modularity;
global using Microsoft.Extensions.DependencyInjection;
global using Volo.Abp;
global using LogLevel = Microsoft.Extensions.Logging.LogLevel;

13
aspnet-core/frameworks/src/Lion.AbpPro.ElasticSearch/Lion.AbpPro.ElasticSearch.csproj

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NEST" />
<PackageReference Include="Volo.Abp.Autofac" />
</ItemGroup>
</Project>

10
aspnet-core/frameworks/src/Lion.AbpPro.ElasticSearch/Lion/AbpPro/ElasticSearch/AbpProElasticSearchModule.cs

@ -0,0 +1,10 @@
namespace Lion.AbpPro.ElasticSearch;
[DependsOn(typeof(AbpAutofacModule))]
public class AbpProElasticSearchModule : AbpModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.Configure<AbpProElasticSearchOptions>(context.Services.GetConfiguration().GetSection("ElasticSearch"));
}
}

19
aspnet-core/frameworks/src/Lion.AbpPro.ElasticSearch/Lion/AbpPro/ElasticSearch/AbpProElasticSearchOptions.cs

@ -0,0 +1,19 @@
namespace Lion.AbpPro.ElasticSearch;
public class AbpProElasticSearchOptions
{
/// <summary>
/// es地址
/// </summary>
public string Host { get; set; }
/// <summary>
/// 用户名
/// </summary>
public string UserName { get; set; }
/// <summary>
/// 密码
/// </summary>
public string Password { get; set; }
}

114
aspnet-core/frameworks/src/Lion.AbpPro.ElasticSearch/Lion/AbpPro/ElasticSearch/ElasticSearchRepository.cs

@ -0,0 +1,114 @@
using Lion.AbpPro.ElasticSearch.Exceptions;
namespace Lion.AbpPro.ElasticSearch;
public abstract class ElasticSearchRepository<TEntity> : IBasicElasticSearchRepository<TEntity>
where TEntity : class, IElasticSearchEntity
{
protected abstract string IndexName { get; }
private readonly IElasticsearchProvider _elasticsearchProvider;
protected ElasticSearchRepository(IElasticsearchProvider elasticsearchProvider)
{
_elasticsearchProvider = elasticsearchProvider;
}
protected IElasticClient Client => _elasticsearchProvider.GetClient();
/// <summary>
/// 根据id查询实体
/// </summary>
public virtual async Task<TEntity> FindAsync(Guid id, CancellationToken cancellationToken = default)
{
var result = await Client.GetAsync<TEntity>(id, e => e.Index(IndexName), cancellationToken);
if (!result.IsValid)
{
return null;
}
return result.Source;
}
/// <summary>
/// 根据id查询实体
/// </summary>
/// <exception cref="AbpProElasticSearchEntityNotFoundException"></exception>
/// <returns>如果没有查询到,会抛异常</returns>
public virtual async Task<TEntity> GetAsync(Guid id, CancellationToken cancellationToken = default)
{
var result = await Client.GetAsync<TEntity>(id, e => e.Index(IndexName), cancellationToken);
if (!result.IsValid)
{
throw new AbpProElasticSearchEntityNotFoundException(innerException: result.OriginalException);
}
return result.Source;
}
/// <summary>
/// 新增数据时,如果文档的唯一id在索引里已存在,那么会更新掉原数据
/// </summary>
/// <exception cref="AbpProElasticSearchException"></exception>
public virtual async Task InsertAsync(TEntity entity, CancellationToken cancellationToken = default)
{
var result = await Client.IndexAsync(entity, x => x.Index(IndexName), cancellationToken);
if (!result.IsValid)
{
throw new AbpProElasticSearchException(innerException: result.OriginalException);
}
}
/// <summary>
/// 批量新增数据时,如果文档的唯一id在索引里已存在,那么会更新掉原数据
/// </summary>
/// <exception cref="AbpProElasticSearchException"></exception>
public async Task InsertManyAsync(IEnumerable<TEntity> entities, CancellationToken cancellationToken = default)
{
// var result = await Client.BulkAsync(b => b.Index(IndexName).IndexMany(entities), cancellationToken);
var result = await Client.IndexManyAsync(entities, IndexName, cancellationToken);
if (!result.IsValid)
{
throw new AbpProElasticSearchException(innerException: result.OriginalException);
}
}
/// <summary>
/// 根据Id删除实体
/// </summary>
/// <exception cref="AbpProElasticSearchException"></exception>
public virtual async Task DeleteAsync(Guid id, CancellationToken cancellationToken = default)
{
var result = await Client.DeleteAsync<TEntity>(id, x => x.Index(IndexName), cancellationToken);
if (!result.IsValid)
{
throw new AbpProElasticSearchException(innerException: result.OriginalException);
}
}
/// <summary>
/// 根据Id更新实体
/// </summary>
/// <exception cref="AbpProElasticSearchException"></exception>
public virtual async Task UpdateAsync(TEntity TEntity)
{
var result = await Client.UpdateAsync<TEntity>(TEntity.Id, x => x.Index(IndexName).Doc(TEntity));
if (!result.IsValid)
{
throw new UserFriendlyException(result.OriginalException.Message);
}
}
public async Task<Tuple<long, IList<TEntity>>> PageAsync(List<Func<QueryContainerDescriptor<TEntity>, QueryContainer>> predicates, int pageIndex = 1, int pageSize = 10)
{
predicates ??= new List<Func<QueryContainerDescriptor<TEntity>, QueryContainer>>();
var query = await Client.SearchAsync<TEntity>(x => x.Index(IndexName)
.Query(q => q.Bool(qb => qb.Filter(predicates)))
.From((pageIndex - 1) * pageSize)
.Size(pageSize)
.Sort(s => s.Descending(v => v.CreationTime)));
return new Tuple<long, IList<TEntity>>(query.Total, query.Documents.ToList());
}
}

19
aspnet-core/frameworks/src/Lion.AbpPro.ElasticSearch/Lion/AbpPro/ElasticSearch/ElasticsearchProvider.cs

@ -0,0 +1,19 @@
namespace Lion.AbpPro.ElasticSearch;
public class ElasticsearchProvider : IElasticsearchProvider, ISingletonDependency
{
private readonly AbpProElasticSearchOptions _options;
public ElasticsearchProvider(IOptions<AbpProElasticSearchOptions> options)
{
_options = options.Value;
}
public virtual IElasticClient GetClient()
{
var connectionPool = new SingleNodeConnectionPool(new Uri(_options.Host));
var settings = new ConnectionSettings(connectionPool);
settings.BasicAuthentication(_options.UserName, _options.Password);
return new ElasticClient(settings);
}
}

24
aspnet-core/frameworks/src/Lion.AbpPro.ElasticSearch/Lion/AbpPro/ElasticSearch/Exceptions/AbpProElasticSearchEntityNotFoundException.cs

@ -0,0 +1,24 @@
namespace Lion.AbpPro.ElasticSearch.Exceptions;
public class AbpProElasticSearchEntityNotFoundException : BusinessException
{
public AbpProElasticSearchEntityNotFoundException(
string code = null,
string message = null,
string details = null,
Exception innerException = null,
LogLevel logLevel = LogLevel.Error)
: base(
code,
message,
details,
innerException,
logLevel
)
{
}
public AbpProElasticSearchEntityNotFoundException(SerializationInfo serializationInfo, StreamingContext context) : base(serializationInfo, context)
{
}
}

24
aspnet-core/frameworks/src/Lion.AbpPro.ElasticSearch/Lion/AbpPro/ElasticSearch/Exceptions/AbpProElasticSearchException.cs

@ -0,0 +1,24 @@
namespace Lion.AbpPro.ElasticSearch.Exceptions;
public class AbpProElasticSearchException : BusinessException
{
public AbpProElasticSearchException(
string code = null,
string message = null,
string details = null,
Exception innerException = null,
LogLevel logLevel = LogLevel.Error)
: base(
code,
message,
details,
innerException,
logLevel
)
{
}
public AbpProElasticSearchException(SerializationInfo serializationInfo, StreamingContext context) : base(serializationInfo, context)
{
}
}

45
aspnet-core/frameworks/src/Lion.AbpPro.ElasticSearch/Lion/AbpPro/ElasticSearch/IBasicElasticSearchRepository.cs

@ -0,0 +1,45 @@
using Lion.AbpPro.ElasticSearch.Exceptions;
namespace Lion.AbpPro.ElasticSearch;
public interface IBasicElasticSearchRepository<TEntity> where TEntity : class, IElasticSearchEntity
{
/// <summary>
/// 根据id查询实体
/// </summary>
Task<TEntity> FindAsync(Guid id, CancellationToken cancellationToken = default);
/// <summary>
/// 根据id查询实体
/// </summary>
/// <exception cref="AbpProElasticSearchEntityNotFoundException"></exception>
/// <returns>如果没有查询到,会抛异常</returns>
Task<TEntity> GetAsync(Guid id, CancellationToken cancellationToken = default);
/// <summary>
/// 新增数据时,如果文档的唯一id在索引里已存在,那么会更新掉原数据
/// </summary>
/// <exception cref="AbpProElasticSearchException"></exception>
Task InsertAsync(TEntity entity, CancellationToken cancellationToken = default);
/// <summary>
/// 批量新增数据时,如果文档的唯一id在索引里已存在,那么会更新掉原数据
/// </summary>
/// <exception cref="AbpProElasticSearchException"></exception>
Task InsertManyAsync(IEnumerable<TEntity> entities, CancellationToken cancellationToken = default);
/// <summary>
/// 根据Id删除实体
/// </summary>
/// <exception cref="AbpProElasticSearchException"></exception>
Task UpdateAsync(TEntity TEntity);
/// <summary>
/// 根据Id更新实体
/// </summary>
/// <exception cref="AbpProElasticSearchException"></exception>
Task DeleteAsync(Guid id, CancellationToken cancellationToken = default);
Task<Tuple<long, IList<TEntity>>> PageAsync(List<Func<QueryContainerDescriptor<TEntity>, QueryContainer>> predicates, int pageIndex = 1, int pageSize = 10);
}

15
aspnet-core/frameworks/src/Lion.AbpPro.ElasticSearch/Lion/AbpPro/ElasticSearch/IElasticSearchEntity.cs

@ -0,0 +1,15 @@
namespace Lion.AbpPro.ElasticSearch;
public interface IElasticSearchEntity
{
/// <summary>
/// 主键Id
/// </summary>
Guid Id { get; set; }
/// <summary>
/// 创建时间
/// </summary>
DateTime CreationTime { get; set; }
}

6
aspnet-core/frameworks/src/Lion.AbpPro.ElasticSearch/Lion/AbpPro/ElasticSearch/IElasticsearchProvider.cs

@ -0,0 +1,6 @@
namespace Lion.AbpPro.ElasticSearch;
public interface IElasticsearchProvider
{
IElasticClient GetClient();
}

32
aspnet-core/frameworks/test/Lion.AbpPro.ElasticSearch.Tests/Lion.AbpPro.ElasticSearch.Tests.csproj

@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="NSubstitute" />
<PackageReference Include="Shouldly" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.extensibility.execution" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="coverlet.collector" />
<PackageReference Include="JunitXml.TestLogger" />
<PackageReference Include="Volo.Abp.TestBase" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Lion.AbpPro.ElasticSearch\Lion.AbpPro.ElasticSearch.csproj" />
</ItemGroup>
<ItemGroup>
<Content Include="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>

13
aspnet-core/frameworks/test/Lion.AbpPro.ElasticSearch.Tests/Lion/AbpPro/ElasticSearch/AbpProElasticSearchTestBase.cs

@ -0,0 +1,13 @@
using Volo.Abp.Testing;
namespace Lion.AbpPro.ElasticSearch
{
public abstract class AbpProElasticSearchTestBase : AbpIntegratedTest<AbpProElasticSearchTestBaseModule>
{
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
{
options.UseAutofac();
}
}
}

9
aspnet-core/frameworks/test/Lion.AbpPro.ElasticSearch.Tests/Lion/AbpPro/ElasticSearch/AbpProElasticSearchTestBaseModule.cs

@ -0,0 +1,9 @@
namespace Lion.AbpPro.ElasticSearch
{
[DependsOn(typeof(AbpProElasticSearchModule))]
[DependsOn(typeof(AbpTestBaseModule))]
public class AbpProElasticSearchTestBaseModule : AbpModule
{
}
}

412
aspnet-core/frameworks/test/Lion.AbpPro.ElasticSearch.Tests/Lion/AbpPro/ElasticSearch/StudentElasticSearchRepositoryTests.cs

@ -0,0 +1,412 @@
using Lion.AbpPro.ElasticSearch.Exceptions;
using Lion.AbpPro.ElasticSearch.Students;
using Nest;
using Shouldly;
namespace Lion.AbpPro.ElasticSearch
{
public sealed class StudentElasticSearchRepositoryTests : AbpProElasticSearchTestBase
{
private readonly IStudentElasticSearchRepository _studentElasticSearchRepository;
public StudentElasticSearchRepositoryTests()
{
_studentElasticSearchRepository = GetRequiredService<IStudentElasticSearchRepository>();
}
[Fact]
public async Task FindAsync_Should_Find_Student()
{
// Arrange
var student = new Student
{
Id = Guid.NewGuid(),
Name = "John Doe",
Age = 10,
CreationTime = DateTime.Now,
Price = 100.3,
Gender = Gender.Man
};
await _studentElasticSearchRepository.InsertAsync(student);
// Act
var result = await _studentElasticSearchRepository.FindAsync(student.Id);
// Assert
result.ShouldNotBeNull();
}
[Fact]
public async Task GetAsync_Should_Exception()
{
await Should.ThrowAsync<AbpProElasticSearchEntityNotFoundException>(async () => { await _studentElasticSearchRepository.GetAsync(Guid.NewGuid()); });
}
[Fact]
public async Task InsertAsync_Should_Insert_Student()
{
// Arrange
var student = new Student
{
Id = Guid.NewGuid(),
Name = "John Doe",
Age = 10,
CreationTime = DateTime.Now,
Price = 100.3,
Gender = Gender.Man
};
// Act
await _studentElasticSearchRepository.InsertAsync(student);
// Assert
var result = await _studentElasticSearchRepository.FindAsync(student.Id);
result.ShouldNotBeNull();
}
[Fact]
public async Task InsertAsync_Should_RepeatInsert_Student()
{
// Arrange
var student = new Student
{
Id = Guid.NewGuid(),
Name = "John Doe",
Age = 10,
CreationTime = DateTime.Now,
Price = 100.3,
Gender = Gender.Man
};
// Act
await _studentElasticSearchRepository.InsertAsync(student);
// Assert
var result = await _studentElasticSearchRepository.FindAsync(student.Id);
result.ShouldNotBeNull();
// Act
student.Name = "abp";
student.Age = 20;
student.Gender = Gender.WoMan;
await _studentElasticSearchRepository.InsertAsync(student);
// Assert
var result1 = await _studentElasticSearchRepository.FindAsync(student.Id);
result1.ShouldNotBeNull();
result1.Name.ShouldBe(student.Name);
result1.Age.ShouldBe(student.Age);
result1.Gender.ShouldBe(student.Gender);
result1.Price.ShouldBe(student.Price);
}
[Fact]
public async Task InsertManyAsync_Should_Insert_Student()
{
// Arrange
var students = new List<Student>
{
new Student
{
Id = Guid.NewGuid(),
Name = "John Doe",
Age = 10,
CreationTime = DateTime.Now,
Price = 100.3,
Gender = Gender.Man
},
new Student
{
Id = Guid.NewGuid(),
Name = "John Wang",
Age = 10,
CreationTime = DateTime.Now,
Price = 100.3,
Gender = Gender.WoMan
}
};
// Act
await _studentElasticSearchRepository.InsertManyAsync(students);
// Assert
foreach (var student in students)
{
var result = await _studentElasticSearchRepository.FindAsync(student.Id);
result.ShouldNotBeNull();
}
}
[Fact]
public async Task DeleteAsync_Should_Delete_Student()
{
// Arrange
var student = new Student
{
Id = Guid.NewGuid(),
Name = "John Doe",
Age = 10,
CreationTime = DateTime.Now,
Price = 100.3,
Gender = Gender.Man
};
await _studentElasticSearchRepository.InsertAsync(student);
// Act
await _studentElasticSearchRepository.DeleteAsync(student.Id);
// Assert
var result = await _studentElasticSearchRepository.FindAsync(student.Id);
result.ShouldBeNull();
}
[Fact]
public async Task UpdateAsync_Should_Update_Student()
{
// Arrange
var student = new Student
{
Id = Guid.NewGuid(),
Name = "John Doe",
Age = 10,
CreationTime = DateTime.Now,
Price = 100.3,
Gender = Gender.Man
};
await _studentElasticSearchRepository.InsertAsync(student);
// Act
student.Name = "update";
student.Age = 20;
await _studentElasticSearchRepository.UpdateAsync(student);
// Assert
var exiStudent = await _studentElasticSearchRepository.FindAsync(student.Id);
exiStudent.ShouldNotBeNull();
exiStudent.Name.ShouldBe(student.Name);
exiStudent.Age.ShouldBe(student.Age);
}
[Fact(DisplayName = "DataRange时间范围查询")]
public async Task PageAsync_Should_Return_Students()
{
// Arrange
var students = new List<Student>
{
new Student
{
Id = Guid.NewGuid(),
Name = "韩立",
Age = 10,
CreationTime = DateTime.Now,
Price = 100.1,
Gender = Gender.Man
},
new Student
{
Id = Guid.NewGuid(),
Name = "南宫婉",
Age = 18,
CreationTime = DateTime.Now.AddDays(-1),
Price = 100.2,
Gender = Gender.WoMan
},
new Student
{
Id = Guid.NewGuid(),
Name = "Test001",
Age = 19,
CreationTime = DateTime.Now,
Price = 100,
Gender = Gender.WoMan
},
new Student
{
Id = Guid.NewGuid(),
Name = "Test",
Age = 10,
CreationTime = DateTime.Now.AddDays(-10),
Price = 100,
Gender = Gender.WoMan
}
};
// Act
await _studentElasticSearchRepository.InsertManyAsync(students);
var TimeZone = "Asia/Shanghai";
var mustFilters = new List<Func<QueryContainerDescriptor<Student>, QueryContainer>>();
// // 查询日期
// mustFilters.Add(e =>
// e.DateRange(f =>
// f.Field(fd => fd.CreationTime)
// .TimeZone(TimeZone)
// // 小于等于LessThanOrEquals
// // 大于等于GreaterThanOrEquals
// .GreaterThanOrEquals(DateTime.Now.AddDays(-1))));
//
// 查询日期区间 3天之前到现在
mustFilters.Add(a => a
.Bool(b => b
.Must(
m => m.DateRange(r => r.Field(f => f.CreationTime).TimeZone(TimeZone).GreaterThanOrEquals(DateTime.Now.AddDays(-3))),
m => m.DateRange(r => r.Field(f => f.CreationTime).TimeZone(TimeZone).LessThanOrEquals(DateTime.Now))
)
)
);
var query = new QueryContainerDescriptor<Student>();
// https://zhuanlan.zhihu.com/p/592767668
// Act
var result = await _studentElasticSearchRepository.PageAsync(mustFilters);
// Assert
Assert.NotNull(result);
Assert.True(result.Item1 >= 0);
Assert.NotNull(result.Item2);
}
[Fact(DisplayName = "Term精准查询")]
public async Task PageAsync_Term_Should_OK()
{
// Arrange
var students = new List<Student>
{
new Student
{
Id = Guid.NewGuid(),
Name = "韩立",
Age = 10,
CreationTime = DateTime.Now,
Price = 100.1,
Gender = Gender.Man
},
};
await _studentElasticSearchRepository.InsertManyAsync(students);
// Act
var mustFilters = new List<Func<QueryContainerDescriptor<Student>, QueryContainer>>();
// 因为text类型会自动生成keyword类型,所以此时这样可以查询出来
mustFilters.Add(e => e.Term(f => f.Field(b => b.Name.Suffix("keyword")).Value("韩立")));
// Act
var result = await _studentElasticSearchRepository.PageAsync(mustFilters);
// Assert
Assert.NotNull(result);
Assert.True(result.Item1 >= 0);
Assert.NotNull(result.Item2);
// Act
var mustFilters1 = new List<Func<QueryContainerDescriptor<Student>, QueryContainer>>();
// 如果name是中文是无法查询到的,text类型会自动分词
mustFilters1.Add(e => e.Term(f => f.Field(b => b.Name).Value("韩立")));
// Act
var result1 = await _studentElasticSearchRepository.PageAsync(mustFilters1);
Assert.True(result1.Item1 == 0);
Assert.True(result1.Item2.Count == 0);
}
[Fact(DisplayName = "Wildcard模糊查询")]
public async Task PageAsync_Wildcard_Should_OK()
{
// Arrange
var students = new List<Student>
{
new Student
{
Id = Guid.NewGuid(),
Name = "Mock",
Age = 10,
CreationTime = DateTime.Now,
Price = 100.1,
Gender = Gender.Man
},
};
await _studentElasticSearchRepository.InsertManyAsync(students);
// Act
var mustFilters = new List<Func<QueryContainerDescriptor<Student>, QueryContainer>>();
// * 代表匹配多个字符
// ?代表匹配单个字符
mustFilters.Add(e => e.Wildcard(f => f.Field(b => b.Name).Value("Moc?")));
// Act
var result = await _studentElasticSearchRepository.PageAsync(mustFilters);
// Assert
Assert.NotNull(result);
Assert.True(result.Item1 >= 0);
Assert.NotNull(result.Item2);
}
[Fact(DisplayName = "Match查询")]
public async Task PageAsync_Match_Should_OK()
{
// Arrange
var students = new List<Student>
{
new Student
{
Id = Guid.NewGuid(),
//Name = "杀人防火历飞雨,万人敬仰韩天尊",
Name = "Student1",
Age = 10,
CreationTime = DateTime.Now,
Price = 100.1,
Gender = Gender.Man
},
};
await _studentElasticSearchRepository.InsertManyAsync(students);
// Act
var mustFilters = new List<Func<QueryContainerDescriptor<Student>, QueryContainer>>();
// Student1 不会进行分词, 所以参数是Student 或者 1 都会查询不到数据
mustFilters.Add(e => e.Match(f => f.Field(b => b.Name).Query("Student")));
// Act
var result = await _studentElasticSearchRepository.PageAsync(mustFilters);
// Assert
Assert.True(result.Item1 == 0);
Assert.True(result.Item2.Count == 0);
}
[Fact(DisplayName = "数值区间查询")]
public async Task PageAsync_Range_Should_OK()
{
// Arrange
var students = new List<Student>
{
new Student
{
Id = Guid.NewGuid(),
Name = "My Name Is Match",
Age = 10,
CreationTime = DateTime.Now,
Price = 100.1,
Gender = Gender.Man
},
};
await _studentElasticSearchRepository.InsertManyAsync(students);
// Act
var mustFilters = new List<Func<QueryContainerDescriptor<Student>, QueryContainer>>();
// 查询数值区间
mustFilters.Add(a => a
.Bool(b => b
.Must(
m => m.Range(r => r.Field(f => f.Age).GreaterThanOrEquals(0)),
m => m.Range(r => r.Field(f => f.Age).LessThanOrEquals(20))
)
)
);
// Act
var result = await _studentElasticSearchRepository.PageAsync(mustFilters);
// Assert
Assert.NotNull(result);
Assert.True(result.Item1 >= 0);
Assert.NotNull(result.Item2);
}
}
}

7
aspnet-core/frameworks/test/Lion.AbpPro.ElasticSearch.Tests/Lion/AbpPro/ElasticSearch/Students/Gender.cs

@ -0,0 +1,7 @@
namespace Lion.AbpPro.ElasticSearch.Students;
public enum Gender
{
Man = 10,
WoMan = 20
}

5
aspnet-core/frameworks/test/Lion.AbpPro.ElasticSearch.Tests/Lion/AbpPro/ElasticSearch/Students/IStudentElasticSearchRepository.cs

@ -0,0 +1,5 @@
namespace Lion.AbpPro.ElasticSearch.Students;
public interface IStudentElasticSearchRepository : IBasicElasticSearchRepository<Student>
{
}

16
aspnet-core/frameworks/test/Lion.AbpPro.ElasticSearch.Tests/Lion/AbpPro/ElasticSearch/Students/Student.cs

@ -0,0 +1,16 @@
namespace Lion.AbpPro.ElasticSearch.Students;
public class Student : IElasticSearchEntity
{
public Guid Id { get; set; }
public DateTime CreationTime { get; set; }
public double Price { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public Gender Gender { get; set; }
}

13
aspnet-core/frameworks/test/Lion.AbpPro.ElasticSearch.Tests/Lion/AbpPro/ElasticSearch/Students/StudentElasticSearchRepository.cs

@ -0,0 +1,13 @@
using Volo.Abp.DependencyInjection;
namespace Lion.AbpPro.ElasticSearch.Students;
public class StudentElasticSearchRepository : ElasticSearchRepository<Student>, IStudentElasticSearchRepository, ITransientDependency
{
public StudentElasticSearchRepository(IElasticsearchProvider elasticsearchProvider) : base(elasticsearchProvider)
{
}
// index 只能是小写
protected override string IndexName => "Students20230701".ToLower();
}

3
aspnet-core/frameworks/test/Lion.AbpPro.ElasticSearch.Tests/Usings.cs

@ -0,0 +1,3 @@
global using Xunit;
global using Volo.Abp;
global using Volo.Abp.Modularity;

7
aspnet-core/frameworks/test/Lion.AbpPro.ElasticSearch.Tests/appsettings.json

@ -0,0 +1,7 @@
{
"ElasticSearch": {
"Host": "http://localhost:9200",
"UserName": "admin",
"Password": "changeme"
}
}

11
aspnet-core/services/src/Lion.AbpPro.Application.Contracts/ElasticSearches/Dto/PagingElasticSearchLogInput.cs

@ -1,11 +0,0 @@
namespace Lion.AbpPro.ElasticSearches.Dto
{
public class PagingElasticSearchLogInput : PagingBase
{
public string Filter { get; set; }
public DateTime? StartCreationTime { get; set; }
public DateTime? EndCreationTime { get; set; }
}
}

23
aspnet-core/services/src/Lion.AbpPro.Application.Contracts/ElasticSearches/Dto/PagingElasticSearchLogOutput.cs

@ -1,23 +0,0 @@
namespace Lion.AbpPro.ElasticSearches.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; }
}
}

14
aspnet-core/services/src/Lion.AbpPro.Application.Contracts/ElasticSearches/ILionAbpProLogAppService.cs

@ -1,14 +0,0 @@
using Lion.AbpPro.ElasticSearches.Dto;
namespace Lion.AbpPro.ElasticSearches
{
public interface ILionAbpProLogAppService : IApplicationService
{
/// <summary>
/// 分页查询es日志
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
Task<CustomPagedResultDto<PagingElasticSearchLogOutput>> PaingAsync(PagingElasticSearchLogInput input);
}
}

16
aspnet-core/services/src/Lion.AbpPro.Application.Contracts/Lion.AbpPro.Application.Contracts.csproj

@ -1,23 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net7.0</TargetFramework> <TargetFramework>net7.0</TargetFramework>
<RootNamespace>Lion.AbpPro</RootNamespace> <RootNamespace>Lion.AbpPro</RootNamespace>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\..\modules\BasicManagement\src\Lion.AbpPro.BasicManagement.Application.Contracts\Lion.AbpPro.BasicManagement.Application.Contracts.csproj"/> <ProjectReference Include="..\..\..\modules\BasicManagement\src\Lion.AbpPro.BasicManagement.Application.Contracts\Lion.AbpPro.BasicManagement.Application.Contracts.csproj" />
<ProjectReference Include="..\..\..\modules\DataDictionaryManagement\src\Lion.AbpPro.DataDictionaryManagement.Application.Contracts\Lion.AbpPro.DataDictionaryManagement.Application.Contracts.csproj"/> <ProjectReference Include="..\..\..\modules\DataDictionaryManagement\src\Lion.AbpPro.DataDictionaryManagement.Application.Contracts\Lion.AbpPro.DataDictionaryManagement.Application.Contracts.csproj" />
<ProjectReference Include="..\..\..\modules\NotificationManagement\src\Lion.AbpPro.NotificationManagement.Application.Contracts\Lion.AbpPro.NotificationManagement.Application.Contracts.csproj"/> <ProjectReference Include="..\..\..\modules\NotificationManagement\src\Lion.AbpPro.NotificationManagement.Application.Contracts\Lion.AbpPro.NotificationManagement.Application.Contracts.csproj" />
<ProjectReference Include="..\..\..\modules\LanguageManagement\src\Lion.AbpPro.LanguageManagement.Application.Contracts\Lion.AbpPro.LanguageManagement.Application.Contracts.csproj"/> <ProjectReference Include="..\..\..\modules\LanguageManagement\src\Lion.AbpPro.LanguageManagement.Application.Contracts\Lion.AbpPro.LanguageManagement.Application.Contracts.csproj" />
<ProjectReference Include="..\Lion.AbpPro.Domain.Shared\Lion.AbpPro.Domain.Shared.csproj"/> <ProjectReference Include="..\Lion.AbpPro.Domain.Shared\Lion.AbpPro.Domain.Shared.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Volo.Abp.ObjectExtending" />
<PackageReference Include="Volo.Abp.ObjectExtending"/>
</ItemGroup> </ItemGroup>

6
aspnet-core/services/src/Lion.AbpPro.Application.Contracts/Permissions/AbpProPermissionDefinitionProvider.cs

@ -4,12 +4,6 @@ namespace Lion.AbpPro.Permissions
{ {
public override void Define(IPermissionDefinitionContext context) public override void Define(IPermissionDefinitionContext context)
{ {
var abpIdentityGroup = context.GetGroup(IdentityPermissions.GroupName);
var esManagement = abpIdentityGroup.AddPermission(AbpProPermissions.SystemManagement.ES, L("Permission:ESManagement"));
} }
private static LocalizableString L(string name) private static LocalizableString L(string name)

2
aspnet-core/services/src/Lion.AbpPro.Application.Contracts/Permissions/AbpProPermissions.cs

@ -8,8 +8,6 @@ namespace Lion.AbpPro.Permissions
public static class SystemManagement public static class SystemManagement
{ {
public const string Default = "AbpIdentity"; public const string Default = "AbpIdentity";
public const string ES = Default + ".ES";
} }
} }

29
aspnet-core/services/src/Lion.AbpPro.Application/ElasticSearches/Dto/PagingElasticSearchLogDto.cs

@ -1,29 +0,0 @@
namespace Lion.AbpPro.ElasticSearches.Dto
{
/// <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; }
}
}

10
aspnet-core/services/src/Lion.AbpPro.Application/ElasticSearches/ElasticSearchApplicationAutoMapperProfile.cs

@ -1,10 +0,0 @@
namespace Lion.AbpPro.ElasticSearches
{
public class ElasticSearchApplicationAutoMapperProfile : Profile
{
public ElasticSearchApplicationAutoMapperProfile()
{
CreateMap<PagingElasticSearchLogDto, PagingElasticSearchLogOutput>();
}
}
}

73
aspnet-core/services/src/Lion.AbpPro.Application/ElasticSearches/LionAbpProLogAppService.cs

@ -1,73 +0,0 @@
namespace Lion.AbpPro.ElasticSearches
{
[Authorize]
public class LionAbpProLogAppService : ElasticsearchBasicService, ILionAbpProLogAppService
{
private readonly IConfiguration _configuration;
// 时区
private const string TimeZone = "Asia/Shanghai";
public LionAbpProLogAppService(
IElasticsearchProvider elasticsearchProvider,
IConfiguration configuration) : base(elasticsearchProvider)
{
_configuration = configuration;
}
[Authorize(Policy = AbpProPermissions.SystemManagement.ES)]
public async Task<CustomPagedResultDto<PagingElasticSearchLogOutput>> PaingAsync(PagingElasticSearchLogInput input)
{
var IndexName = _configuration.GetValue<string>("ElasticSearch:SearchIndexFormat");
// 默认查询当天
input.StartCreationTime = input.StartCreationTime?.AddMilliseconds(-1) ?? Clock.Now.Date.AddMilliseconds(-1);
input.EndCreationTime = input.EndCreationTime?.AddDays(1).AddMilliseconds(-1) ?? Clock.Now.Date.AddDays(1).AddMilliseconds(-1);
var mustFilters = new List<Func<QueryContainerDescriptor<PagingElasticSearchLogDto>, QueryContainer>>();
if (input.StartCreationTime.HasValue)
{
input.StartCreationTime = input.StartCreationTime.ToCurrentDateMaxDateTime();
mustFilters.Add(e => e.DateRange(f => f.Field(fd => fd.CreationTime).TimeZone(TimeZone).GreaterThanOrEquals(input.StartCreationTime)));
}
if (input.EndCreationTime.HasValue)
{
input.EndCreationTime = input.EndCreationTime.ToNextSecondDateTime();
mustFilters.Add(e => e.DateRange(f => f.Field(fd => fd.CreationTime).TimeZone(TimeZone).LessThanOrEquals(input.EndCreationTime)));
}
if (!string.IsNullOrWhiteSpace(input.Filter))
{
mustFilters.Add
(
t => t.Match(f => f.Field(fd => fd.Message).Query(input.Filter.Trim()).Fuzziness(Fuzziness.Auto))
);
}
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 CustomPagedResultDto<PagingElasticSearchLogOutput>
(
result.HitsMetadata.Total.Value,
ObjectMapper
.Map<List<PagingElasticSearchLogDto>, List<PagingElasticSearchLogOutput>>
(
result.Documents.ToList()
)
);
}
return null;
}
}
}

15
aspnet-core/services/src/Lion.AbpPro.Application/ElasticSearches/Providers/ElasticsearchBasicService.cs

@ -1,15 +0,0 @@
namespace Lion.AbpPro.ElasticSearches.Providers
{
public abstract class ElasticsearchBasicService : AbpProAppService
{
private readonly IElasticsearchProvider _elasticsearchProvider;
// ReSharper disable once PublicConstructorInAbstractClass
public ElasticsearchBasicService(IElasticsearchProvider elasticsearchProvider)
{
_elasticsearchProvider = elasticsearchProvider;
}
protected IElasticClient Client => _elasticsearchProvider.GetElasticClient();
}
}

23
aspnet-core/services/src/Lion.AbpPro.Application/ElasticSearches/Providers/ElasticsearchProvider.cs

@ -1,23 +0,0 @@
namespace Lion.AbpPro.ElasticSearches.Providers
{
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);
}
}
}

7
aspnet-core/services/src/Lion.AbpPro.Application/ElasticSearches/Providers/IElasticsearchProvider.cs

@ -1,7 +0,0 @@
namespace Lion.AbpPro.ElasticSearches.Providers
{
public interface IElasticsearchProvider : ISingletonDependency
{
IElasticClient GetElasticClient();
}
}

4
aspnet-core/services/src/Lion.AbpPro.Application/GlobalUsings.cs

@ -4,11 +4,8 @@ global using System;
global using System.Collections.Generic; global using System.Collections.Generic;
global using System.Linq; global using System.Linq;
global using System.Threading.Tasks; global using System.Threading.Tasks;
global using Elasticsearch.Net;
global using Lion.AbpPro.BasicManagement; global using Lion.AbpPro.BasicManagement;
global using Lion.AbpPro.DataDictionaryManagement; global using Lion.AbpPro.DataDictionaryManagement;
global using Lion.AbpPro.ElasticSearches.Dto;
global using Lion.AbpPro.ElasticSearches.Providers;
global using Lion.AbpPro.Core; global using Lion.AbpPro.Core;
global using Lion.AbpPro.FreeSqlRepository; global using Lion.AbpPro.FreeSqlRepository;
global using Lion.AbpPro.NotificationManagement; global using Lion.AbpPro.NotificationManagement;
@ -16,7 +13,6 @@ global using Lion.AbpPro.Permissions;
global using Microsoft.AspNetCore.Authorization; global using Microsoft.AspNetCore.Authorization;
global using Microsoft.Extensions.Configuration; global using Microsoft.Extensions.Configuration;
global using Microsoft.Extensions.Localization; global using Microsoft.Extensions.Localization;
global using Nest;
global using Volo.Abp.Application.Services; global using Volo.Abp.Application.Services;
global using Volo.Abp.AutoMapper; global using Volo.Abp.AutoMapper;
global using Volo.Abp.DependencyInjection; global using Volo.Abp.DependencyInjection;

4
aspnet-core/services/src/Lion.AbpPro.Application/Lion.AbpPro.Application.csproj

@ -16,8 +16,4 @@
<ProjectReference Include="..\Lion.AbpPro.FreeSqlRepository\Lion.AbpPro.FreeSqlRepository.csproj" /> <ProjectReference Include="..\Lion.AbpPro.FreeSqlRepository\Lion.AbpPro.FreeSqlRepository.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<PackageReference Include="NEST" />
</ItemGroup>
</Project> </Project>

20
aspnet-core/services/src/Lion.AbpPro.HttpApi/Controllers/Systems/LionAbpProLogController.cs

@ -1,20 +0,0 @@
namespace Lion.AbpPro.Controllers.Systems
{
[Route("EsLog")]
public class LionAbpProLogController: AbpProController,ILionAbpProLogAppService
{
private readonly ILionAbpProLogAppService _companyNameAbpProLogAppService;
public LionAbpProLogController(ILionAbpProLogAppService companyNameAbpProLogAppService)
{
_companyNameAbpProLogAppService = companyNameAbpProLogAppService;
}
[HttpPost("page")]
[SwaggerOperation(summary: "分页获取Es日志", Tags = new[] { "EsLog" })]
public Task<CustomPagedResultDto<PagingElasticSearchLogOutput>> PaingAsync(PagingElasticSearchLogInput input)
{
return _companyNameAbpProLogAppService.PaingAsync(input);
}
}
}

2
aspnet-core/services/src/Lion.AbpPro.HttpApi/GlobalUsings.cs

@ -1,8 +1,6 @@
// Global using directives // Global using directives
global using Lion.AbpPro.DataDictionaryManagement; global using Lion.AbpPro.DataDictionaryManagement;
global using Lion.AbpPro.ElasticSearches;
global using Lion.AbpPro.ElasticSearches.Dto;
global using Lion.AbpPro.Core; global using Lion.AbpPro.Core;
global using Lion.AbpPro.NotificationManagement; global using Lion.AbpPro.NotificationManagement;
global using Localization.Resources.AbpUi; global using Localization.Resources.AbpUi;

Loading…
Cancel
Save