From 84e2764ebec087a9b0d9e5020a4f3b0680f42c51 Mon Sep 17 00:00:00 2001 From: xiaolipro <2357729423@qq.com> Date: Tue, 30 Jul 2024 15:13:55 +0800 Subject: [PATCH] temp --- ...TrackChangeAfterUpdateOrderEventHandler.cs | 58 +++++++++---------- .../ForewarningNotifyService.cs | 6 +- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/SJZY.Track.Application/CAP/EventHandlers/TrackChangeAfterUpdateOrderEventHandler.cs b/src/SJZY.Track.Application/CAP/EventHandlers/TrackChangeAfterUpdateOrderEventHandler.cs index 3e96a3b5..056d1748 100644 --- a/src/SJZY.Track.Application/CAP/EventHandlers/TrackChangeAfterUpdateOrderEventHandler.cs +++ b/src/SJZY.Track.Application/CAP/EventHandlers/TrackChangeAfterUpdateOrderEventHandler.cs @@ -24,7 +24,7 @@ public class TrackChangeAfterUpdateOrderEventHandler : ITransientDependency, ICa [CapSubscribe(GlobalConst.TrackChangeAfterUpdateOrderSubscribe)] public async Task ConsumerAsync(TrackChangeAfterUpdateOrderEvent @event) { - var orders = await _orderRepository.GetListAsync(x => @event.OrderIds.Contains(x.Id), x => MapOrderSummary(x)); + var orders = await GetOrdersAsync(@event.OrderIds); if (orders.Count == 0) return; @@ -68,7 +68,34 @@ public class TrackChangeAfterUpdateOrderEventHandler : ITransientDependency, ICa }); // 预警计算 - await _forewarningNotifyService.WarningCalculateAsync( BuiltWarningDto(orders, @event)); + await _forewarningNotifyService.WarningCalculateAsync(BuiltWarningDto(orders, @event)); + } + + private async Task> GetOrdersAsync(int[] orderIds) + { + return await _orderRepository.GetListAsync(order => orderIds.Contains(order.Id), order => new OrderEntity + { + Id = order.Id, + + // 轨迹 + IsCompleted = order.IsCompleted, + LatestTrackContent = order.LatestTrackContent, + LatestTrackEnContent = order.LatestTrackEnContent, + LatestTrackPlace = order.LatestTrackPlace, + LatestTrackTime = order.LatestTrackTime, + LatestTrackTimeZone = order.LatestTrackTimeZone, + + // 因素 + CargoType = order.CargoType, + CreateTime = order.CreateTime, + ArrivalCountry = order.ArrivalCountry, + ArrivalProvince = order.ArrivalProvince, + ArrivalCity = order.ArrivalCity, + ArrivalPostCode = order.ArrivalPostCode, + IsTransit = order.IsTransit, + LeavePort = order.LeavePort, + ProductCode = order.ProductCode + }); } private WarningDto BuiltWarningDto(List orders, TrackChangeAfterUpdateOrderEvent @event) @@ -95,31 +122,4 @@ public class TrackChangeAfterUpdateOrderEventHandler : ITransientDependency, ICa }).ToList() }; } - - private OrderEntity MapOrderSummary(OrderEntity order) - { - return new OrderEntity - { - Id = order.Id, - - // 轨迹 - IsCompleted = order.IsCompleted, - LatestTrackContent = order.LatestTrackContent, - LatestTrackEnContent = order.LatestTrackEnContent, - LatestTrackPlace = order.LatestTrackPlace, - LatestTrackTime = order.LatestTrackTime, - LatestTrackTimeZone = order.LatestTrackTimeZone, - - // 因素 - CargoType = order.CargoType, - CreateTime = order.CreateTime, - ArrivalCountry = order.ArrivalCountry, - ArrivalProvince = order.ArrivalProvince, - ArrivalCity = order.ArrivalCity, - ArrivalPostCode = order.ArrivalPostCode, - IsTransit = order.IsTransit, - LeavePort = order.LeavePort, - ProductCode = order.ProductCode - }; - } } \ No newline at end of file diff --git a/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningNotifyService.cs b/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningNotifyService.cs index 75f44fec..003d6cf6 100644 --- a/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningNotifyService.cs +++ b/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningNotifyService.cs @@ -51,10 +51,10 @@ public class ForewarningNotifyService : IForewarningNotifyService, ITransientDep order ); - foreach (var rule in endingRules) + foreach (var member in endingRules.Select(rule => + new WarningNotifyCacheEntry(rule.Id, order.Id).ToString()) + ) { - var entry = new WarningNotifyCacheEntry(rule.Id, order.Id); - var member = entry.ToString(); // todo: pipeline optimize? var score = await RedisHelper.Client.ZScoreAsync(GlobalConst.ForewarningNotifyKey, member); // tips: score is null 说明发生ending时,没有匹配到规则,所以没有add到set,不需要删除