using Nest; using SJZY.Expand.ElasticSearch.Services; using SJZY.Track.Domain.Aggregates.ForewarningAggregate; namespace SJZY.Track.Repository.Repositories; public class RuleFactorRepository:ElasticSearchContextAbstract, IRuleFactorRepository, ITransientDependency { public RuleFactorRepository(ConnectionFactory connectionFactory) : base(connectionFactory) { } public async Task CreateAsync(RuleFactorEntity entity) { await IndexDocumentAsync(entity); } public async Task> GetFactorByIdsAsync(int[] ruleIds) { var response = await Context.SearchAsync(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(); default: throw new Exception($"数据查询失败,http status: {num},原因:{response.DebugInformation}"); } } /// /// 获取所有数据 /// /// /// public async Task> GetAllList() { var response = await Context.SearchAsync(); int num = response.ApiCall.HttpStatusCode ?? throw new Exception("数据查询失败,原因:" + response.DebugInformation); switch (num) { case 200: return response.Documents.ToList(); case 404: return new List(); default: throw new Exception($"数据查询失败,http status: {num},原因:{response.DebugInformation}"); } } }