track/src/SJZY.Track.Repository/Repositories/RuleFactorRepository.cs
2024-07-24 08:54:56 +08:00

53 lines
1.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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}");
}
}
}