diff --git a/src/SJZY.Track.Application/Services/ProvideServices/TrackService.cs b/src/SJZY.Track.Application/Services/ProvideServices/TrackService.cs index 1931a805..d18b811a 100644 --- a/src/SJZY.Track.Application/Services/ProvideServices/TrackService.cs +++ b/src/SJZY.Track.Application/Services/ProvideServices/TrackService.cs @@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Http; using SJZY.Track.Application.Contract.Dtos.ProvideServices; using SJZY.Track.Application.Contract.Events; using SJZY.Track.Application.Contract.Services.ProvideServices; -using SJZY.Track.Application.Helpers; using SJZY.Track.Domain.Aggregates.OrderAggregate; using SJZY.Track.Domain.Aggregates.TrackContentAggregate; using SJZY.Track.Domain.Aggregates.TrackDetailsAggregate; @@ -60,7 +59,7 @@ public partial class TrackService : ApplicationService, ITrackService var orderId = await _orderRepository.GetFirstAsync( x => x.SubSystemId == input.SubSystemId && x.OrderType == input.OrderType && x.OrderNo == input.OrderNo, x => x.Id); - if (orderId == default) + if (orderId == null) { throw new BusinessException(message: $"订单:{input.OrderNo}不存在"); } @@ -74,8 +73,8 @@ public partial class TrackService : ApplicationService, ITrackService var name = userInfo.Data.UserName; - var tracks = new List(); - var existsExternal = false; + List tracks; + bool existsExternal; var esIds = input.EsIds?.Distinct().ToArray(); //优先使用esId if (esIds != null && esIds.Length > 0) @@ -273,7 +272,7 @@ public partial class TrackService : ApplicationService, ITrackService x.OrderNo, x.CustomId }); - if (order == default) + if (order == null) { throw new BusinessException(message: $"订单:{input.OrderNo}不存在"); } @@ -479,7 +478,7 @@ public partial class TrackService : ApplicationService, ITrackService #region 轨迹内容中的配置规则检查 var trackContent = await _trackContentRepository.GetByCodeAsync(subSystemId, trackCode); - if (trackContent == default) + if (trackContent == null) { throw new BusinessException(message: $"轨迹代码:{trackCode}轨迹内容不存在"); } @@ -518,11 +517,11 @@ public partial class TrackService : ApplicationService, ITrackService var tracks = await RetryQueryTrackAsync(orderId, trackCode, trackTime, extra, compareFields); //不存在需要更新的轨迹 if (tracks.Count == 0) - throw new BusinessException(message: $"订单:[{orderNo}],轨迹代码:{trackCode}没有要更新的记录"); + throw new BusinessException(message: $"订单:[{orderNo}],轨迹代码:[{trackCode}]没有要更新的记录"); //更新轨迹,同一时间存在多条轨迹记录,理由:不清晰到底要修改哪一条或是全部修改 if (tracks.Count > 1) - throw new BusinessException(message: $"订单:{orderNo},轨迹代码:{trackCode}存在多条记录,不允许修改"); + throw new BusinessException(message: $"订单:{orderNo},轨迹代码:[{trackCode}]存在多条记录,不允许修改"); } } diff --git a/src/SJZY.Track.Domain/Extensions/CollectionExtensions.cs b/src/SJZY.Track.Domain/Extensions/CollectionExtensions.cs index fc788ba9..220c4ebc 100644 --- a/src/SJZY.Track.Domain/Extensions/CollectionExtensions.cs +++ b/src/SJZY.Track.Domain/Extensions/CollectionExtensions.cs @@ -4,29 +4,28 @@ using SJZY.Expand.ElasticSearch; namespace SJZY.Track.Domain.Extensions; -public class ListWrapperFactory +public static class ListWrapperFactory { public static ListWrapper, QueryContainer>> CreateListWrapper(TInput input) where TIndex : IdBaseIndex { - return new ListWrapper, QueryContainer>>(new (), input); + return new ListWrapper, QueryContainer>>(new List, QueryContainer>>(), input); } } public class ListWrapper : List { - public List List { get; set; } public TInput Input { get; set; } public ListWrapper(List list, TInput input) { - List = list; + AddRange(list);; Input = input; } public void AddIf(Predicate predicate,TItem item) { if(predicate(Input)) - List.Add(item); + Add(item); } } diff --git a/src/SJZY.Track.Repository/Repositories/WarningDetailsEsRepository.cs b/src/SJZY.Track.Repository/Repositories/WarningDetailsEsRepository.cs index d5cd6074..d8511f43 100644 --- a/src/SJZY.Track.Repository/Repositories/WarningDetailsEsRepository.cs +++ b/src/SJZY.Track.Repository/Repositories/WarningDetailsEsRepository.cs @@ -33,8 +33,8 @@ public class WarningDetailsEsRepository : IWarningDetailsEsRepository, ITransien musts.AddIf(_ => orderNos?.Length > 0, c => c.Terms(f => f.Field(d => d.OrderNo.Suffix("keyword")).Terms(orderNos))); musts.AddIf(x => x.OrderType > 0, c => c.Term(f => f.OrderType, input.OrderType)); musts.AddIf(x => x.Status > 0, c => c.Term(f => f.Status, input.Status)); - musts.AddIf(x => x.CustomId > 0, c => c.Term(f => f.CustomId, input.CustomId)); - musts.AddIf(x => !string.IsNullOrWhiteSpace(x.WarningName), c => c.Term(f => f.WarningName, input.WarningName)); + musts.AddIf(x => x.SubSystemId > 0, c => c.Term(f => f.SubSystemId, input.SubSystemId)); + musts.AddIf(x => !string.IsNullOrWhiteSpace(x.WarningName), c => c.Term(f => f.WarningName.Suffix("keyword"), input.WarningName)); musts.AddIf(x => x.CreateTimeStart.HasValue, c => c.DateRange(r => r.Field(f => f.CreateTime).GreaterThanOrEquals(input.CreateTimeStart))); musts.AddIf(x => x.CreateTimeEnd.HasValue, c => c.DateRange(r => r.Field(f => f.CreateTime).LessThanOrEquals(input.CreateTimeEnd))); @@ -534,7 +534,6 @@ public class WarningDetailsEsRepository : IWarningDetailsEsRepository, ITransien musts.AddIf(x => x.OrderType > 0, c => c.Term(f => f.OrderType, input.OrderType)); musts.AddIf(x => x.Status > 0, c => c.Term(f => f.Status, input.Status)); musts.AddIf(x => x.CustomId > 0, c => c.Term(f => f.CustomId, input.CustomId)); - musts.AddIf(x => x.MissingTrackStatusId > 0, c => c.Match(f => f.Field(d => d.MissingTrackStatusIds).Query(input.MissingTrackStatusId.ToString()))); musts.AddIf(x => x.WarningCreateTimeStart.HasValue, c => c.DateRange(r => r.Field(f => f.CreateTime).LessThanOrEquals(input.WarningCreateTimeStart))); musts.AddIf(x => x.WarningCreateTimeEnd.HasValue, c => c.DateRange(r => r.Field(f => f.CreateTime).LessThanOrEquals(input.WarningCreateTimeEnd))); musts.AddIf(x => x.WarningHandleTimeStart.HasValue, c => c.DateRange(r => r.Field(f => f.ProcessedTime).LessThanOrEquals(input.WarningHandleTimeStart))); @@ -542,6 +541,9 @@ public class WarningDetailsEsRepository : IWarningDetailsEsRepository, ITransien // 模糊匹配userId musts.AddIf(x => x.NotifyUserId.HasValue, c => c.Match(f => f.Field(d => d.NotifyUsers).Query(input.NotifyUserId.ToString()))); + // 匹配缺失轨迹状态 + musts.AddIf(x => x.MissingTrackStatusId > 0, c => c.Script(s => s.Script(a => a.Source("doc['missingTrackStatusIds.keyword'].value.contains(params.value)") + .Params(p => p.Add("value", input.MissingTrackStatusId.ToString()))))); var resp = await _client.SearchAsync(x => x .Index(GlobalConst.CompleteWarningDetailsIndex) @@ -696,12 +698,11 @@ public class WarningDetailsEsRepository : IWarningDetailsEsRepository, ITransien await _client.MapAsync(m => m.Index(indexName4).AutoMap()); } - var r = await _client.Indices.BulkAliasAsync(b => + var r = await _client.Indices.BulkAliasAsync(b => b.Add(a => a.Alias(GlobalConst.TransportWarningDetailsIndex).Index(indexName1)) .Add(a => a.Alias(GlobalConst.ReturnWarningDetailsIndex).Index(indexName2)) .Add(a => a.Alias(GlobalConst.CompleteWarningDetailsIndex).Index(indexName3)) .Add(a => a.Alias(GlobalConst.ReturnMessageRecordIndex).Index(indexName4)) ); - } }