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