diff --git a/src/SJZY.Track.Application/CAP/EventHandlers/PushWarningEventHandler.cs b/src/SJZY.Track.Application/CAP/EventHandlers/PushWarningEventHandler.cs index 103351c3..f4c68504 100644 --- a/src/SJZY.Track.Application/CAP/EventHandlers/PushWarningEventHandler.cs +++ b/src/SJZY.Track.Application/CAP/EventHandlers/PushWarningEventHandler.cs @@ -1,5 +1,6 @@ using DotNetCore.CAP; using Microsoft.Extensions.Logging; +using SJZY.Expand.ABP.Core; using SJZY.Track.Application.Contract.Events; using SJZY.Track.Domain.Aggregates.OrderAggregate; using SJZY.Track.Domain.Consts; @@ -22,6 +23,14 @@ public class PushWarningEventHandler : ITransientDependency, ICapSubscribe [CapSubscribe(GlobalConst.TrackPushWarning)] public async Task Handle(PushWarningEvent @event) { + var hasProcess = await RedisHelper.Client.ExistsAsync(GlobalConst.TrackPushTrackWaringLockKey); + if (hasProcess) + { + return; + } + + await RedisHelper.Client.SetAsync(GlobalConst.TrackPushTrackWaringLockKey, 1, TimeSpan.FromHours(3)); + int total = 0, pageSize = @event.PageSize, waitTime = 1000; var dateTimes = Enumerable.Range(1, 12).Select(val => DateTime.Now.AddHours(-val)).ToList(); @@ -38,6 +47,7 @@ public class PushWarningEventHandler : ITransientDependency, ICapSubscribe } while (rows != pageSize); } + await RedisHelper.Client.DelAsync(GlobalConst.TrackPushTrackWaringLockKey); _logger.LogInformation(message: "本次预警扫描了:{total}个订单", total); } } \ No newline at end of file diff --git a/src/SJZY.Track.Domain/Consts/GlobalConst.Redis.cs b/src/SJZY.Track.Domain/Consts/GlobalConst.Redis.cs index 06972eff..4dec0225 100644 --- a/src/SJZY.Track.Domain/Consts/GlobalConst.Redis.cs +++ b/src/SJZY.Track.Domain/Consts/GlobalConst.Redis.cs @@ -21,44 +21,49 @@ public partial class GlobalConst /// 轨迹拉取配置信息redis key前缀 /// public const string TrackPullContentKeyPrefix = "TrackPullContent"; - + /// /// 预警通知redis key /// public const string ForewarningNotifyKey = "ForewarningNotify"; - + /// /// 预警通知剩余次数redis key /// public const string ForewarningNotifyCntKey = "ForewarningNotifyCnt"; - + /// /// kpi区域redis key前缀 /// public const string KpiAreaKeyPrefix = "KpiArea"; - + /// /// 城市时区redis key前缀 /// public const string CityTimezoneKeyPrefix = "CityTimezone"; - + /// /// 港口时区redis key前缀 /// public const string PortTimezoneKeyPrefix = "PortTimezone"; - + /// /// 发布订阅通知频道Key /// public const string PublishNotifyChannelKey = "PublishNotifyChannel"; - + /// /// 轨迹区域reids key /// public const string TrackAreaKeyPrefix = "TrackArea"; - + /// /// 轨迹预警数据redis key前缀 /// public const string TrackWarningKeyPrefix = "TrackWarning"; + + /// + /// 12小时推送预警轨迹锁 + /// + public const string TrackPushTrackWaringLockKey = "TrackPushTrackWaringLock"; } \ No newline at end of file diff --git a/src/SJZY.Track.Repository/Repositories/OrderRepository.cs b/src/SJZY.Track.Repository/Repositories/OrderRepository.cs index 5460ce3c..fbdcdc51 100644 --- a/src/SJZY.Track.Repository/Repositories/OrderRepository.cs +++ b/src/SJZY.Track.Repository/Repositories/OrderRepository.cs @@ -94,13 +94,12 @@ AND `a`.`IsDeleted` = 0 AND `b`.`IsDeleted` = 0 limit @pageSize", new { pageSize .Select((b, a) => new { Order = b }) .ToPageListAsync(pageindex, pageSize); - var latestPushTimeIds = new LinkedList(); - var questionZeroIds = new LinkedList(); + var latestPushTimeIds = new List(); + var questionZeroIds = new List(); foreach (var item in ordersToUpdate) { var order = item.Order; - var questionType = !order.LatestPushTime.HasValue - || order.LatestPushTime < DateTime.Now.AddHours(-12) + var questionType = !order.LatestPushTime.HasValue || order.LatestPushTime < DateTime.Now.AddHours(-12) ? 2 : 0; if (order.QuestionType == questionType) continue;