53 lines
1.9 KiB
C#
53 lines
1.9 KiB
C#
using Nest;
|
||
using SJZY.Expand.ElasticSearch.Services;
|
||
using SJZY.Track.Domain.Aggregates.ForewarningAggregate;
|
||
|
||
namespace SJZY.Track.Repository.Repositories;
|
||
|
||
public class RuleFactorRepository:ElasticSearchContextAbstract<RuleFactorEntity>, IRuleFactorRepository,
|
||
ITransientDependency
|
||
{
|
||
public RuleFactorRepository(ConnectionFactory connectionFactory) : base(connectionFactory)
|
||
{
|
||
}
|
||
|
||
public async Task CreateAsync(RuleFactorEntity entity)
|
||
{
|
||
await IndexDocumentAsync(entity);
|
||
}
|
||
|
||
public async Task<List<RuleFactorEntity>> GetFactorByIdsAsync(int[] ruleIds)
|
||
{
|
||
var response = await Context.SearchAsync<RuleFactorEntity>(s => s.Query(q => q.Terms(t => t.Field(f => f.RuleId).Terms(ruleIds))));
|
||
int num = response.ApiCall.HttpStatusCode ?? throw new Exception("数据查询失败,原因:" + response.DebugInformation);
|
||
switch (num)
|
||
{
|
||
case 200:
|
||
return response.Documents.ToList();
|
||
case 404:
|
||
return new List<RuleFactorEntity>();
|
||
default:
|
||
throw new Exception($"数据查询失败,http status: {num},原因:{response.DebugInformation}");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取所有数据
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
/// <exception cref="Exception"></exception>
|
||
public async Task<List<RuleFactorEntity>> GetAllList()
|
||
{
|
||
var response = await Context.SearchAsync<RuleFactorEntity>();
|
||
int num = response.ApiCall.HttpStatusCode ?? throw new Exception("数据查询失败,原因:" + response.DebugInformation);
|
||
switch (num)
|
||
{
|
||
case 200:
|
||
return response.Documents.ToList();
|
||
case 404:
|
||
return new List<RuleFactorEntity>();
|
||
default:
|
||
throw new Exception($"数据查询失败,http status: {num},原因:{response.DebugInformation}");
|
||
}
|
||
}
|
||
} |