From 4ebbe1b67c527d9bb89ff8abe6e4725ee6bbc1a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=B9=8F=E5=86=9B?= <2357729423@qq.com> Date: Tue, 2 Apr 2024 19:41:29 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E6=8E=A8=E9=80=81swap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EventHandlers/TrackPushEventHandler.cs | 7 ++--- .../TrackPush/TrackPushCacheService.cs | 28 ++++++------------- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/SJZY.Track.Application/EventHandlers/TrackPushEventHandler.cs b/src/SJZY.Track.Application/EventHandlers/TrackPushEventHandler.cs index 6b002bc5..c66a7aed 100644 --- a/src/SJZY.Track.Application/EventHandlers/TrackPushEventHandler.cs +++ b/src/SJZY.Track.Application/EventHandlers/TrackPushEventHandler.cs @@ -80,12 +80,11 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe // 推断 本次推送 是否可行 config = await _trackPushCacheService.IsValidPushAsync(order.SubSystemId, order.CustomId, order.LatestPushTrackCode, @event.TrackCode); - allPush = true; } } if (config == null) return; - await DoAddAsync(@event, config, log, allPush); + await DoAddAsync(@event, config, log); break; case OptionType.删除: break; @@ -144,7 +143,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe } private async Task DoAddAsync(TrackPushEvent @event, - TrackPushContentConfigDto config, TrackPushRecordIndex log, bool allPush) + TrackPushContentConfigDto config, TrackPushRecordIndex log) { var track = new { @@ -166,7 +165,7 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe data = new[] { track } }); - if (allPush) + if (config.IsAllPush) { var history = await _trackPushRecordsRepository.GetLatestTrackPushRecordAsync(@event.OrderId); if (history != default) diff --git a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs index 91077d30..88d6b079 100644 --- a/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs +++ b/src/SJZY.Track.Application/Services/TrackPush/TrackPushCacheService.cs @@ -44,28 +44,16 @@ public class TrackPushCacheService : ITrackPushCacheService, ITransientDependenc var cache = await GetPushContentConfigsAsync(subSystemId, customId); if (cache == null || cache.Count < 1) return default; - TrackPushContentConfigDto? matched; - if (latestPushTrackCode == null) - { - matched = cache.First(); - } - else - { - var idx = cache.FindIndex(x => x.TrackCode == latestPushTrackCode); + var idx = cache.FindIndex(x => x.TrackCode == latestPushTrackCode); - if (idx == -1) return default; // 是否预警? + if (idx + 1 >= cache.Count) return default; // 推完了 - // find next - if (idx + 1 < cache.Count && cache[idx + 1].TrackCode == trackCode) - { - matched = cache[idx + 1]; - } - else - { - // find swap - matched = cache.FirstOrDefault(x => x.TrackCode == cache[idx].SwapTrackCode); - } - } + // find next + var matched = cache[idx + 1].TrackCode == trackCode + ? cache[idx + 1] + : + // find swap + cache.FirstOrDefault(x => x.TrackCode == cache[idx + 1].SwapTrackCode); return matched != null && matched.TrackCode == trackCode && matched.IsAutoPush ? matched : default; }