From b30846a8113e7a2b5b4a39d98d177b5a1670eb51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=9F=E5=96=9C=E6=97=BA?= Date: Mon, 5 Aug 2024 16:19:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=8E=A8=E9=80=81=E9=A2=84=E8=AD=A6=EF=BC=88=E3=80=8B12?= =?UTF-8?q?=E5=B0=8F=E6=97=B6=E6=B2=A1=E6=9C=89=E6=8E=A8=E9=80=81=E7=9A=84?= =?UTF-8?q?=20=E6=94=B9=E4=B8=BA=E4=BA=8B=E4=BB=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Events/PushWarningEvent.cs | 6 +++ .../EventHandlers/PushWarningEventHandler.cs | 43 +++++++++++++++++++ .../ProvideServices/TrackPushService.cs | 26 +++-------- .../Consts/GlobalConst.MQ.cs | 5 +++ 4 files changed, 61 insertions(+), 19 deletions(-) create mode 100644 src/SJZY.Track.Application.Contract/Events/PushWarningEvent.cs create mode 100644 src/SJZY.Track.Application/CAP/EventHandlers/PushWarningEventHandler.cs diff --git a/src/SJZY.Track.Application.Contract/Events/PushWarningEvent.cs b/src/SJZY.Track.Application.Contract/Events/PushWarningEvent.cs new file mode 100644 index 00000000..c8fbdb20 --- /dev/null +++ b/src/SJZY.Track.Application.Contract/Events/PushWarningEvent.cs @@ -0,0 +1,6 @@ +namespace SJZY.Track.Application.Contract.Events; + +public class PushWarningEvent +{ + public int PageSize { get; set; } +} \ No newline at end of file diff --git a/src/SJZY.Track.Application/CAP/EventHandlers/PushWarningEventHandler.cs b/src/SJZY.Track.Application/CAP/EventHandlers/PushWarningEventHandler.cs new file mode 100644 index 00000000..8197ec1c --- /dev/null +++ b/src/SJZY.Track.Application/CAP/EventHandlers/PushWarningEventHandler.cs @@ -0,0 +1,43 @@ +using DotNetCore.CAP; +using Microsoft.Extensions.Logging; +using SJZY.Track.Application.Contract.Events; +using SJZY.Track.Domain.Aggregates.OrderAggregate; +using SJZY.Track.Domain.Consts; +using Volo.Abp.DependencyInjection; + +namespace SJZY.Track.Application.CAP.EventHandlers; + +public class PushWarningEventHandler:ITransientDependency, ICapSubscribe +{ + private readonly ILogger _logger; + private readonly IOrderRepository _orderRepository; + + public PushWarningEventHandler(IOrderRepository orderRepository, + ILogger logger) + { + _orderRepository = orderRepository; + _logger = logger; + } + + [CapSubscribe(GlobalConst.TrackPushWarning)] + public async Task Handle(PushWarningEvent @event) + { + int total =0, pageSize = @event.PageSize,waitTime = 1000; + var dateTimes = Enumerable.Range(1, 12).Select(val => DateTime.Now.AddHours(-val)).ToList(); + + foreach (var dateTime in dateTimes) + { + var rows = 0; + var pageindex = 1; + do + { + rows = await _orderRepository.PushWarnOrdersAsync(pageSize,pageindex,dateTime); + pageindex++; + total+=rows; + await Task.Delay(waitTime); + }while (rows!= pageSize); + } + + _logger.LogInformation(message: "本次预警扫描了:{total}个订单",total); + } +} \ No newline at end of file diff --git a/src/SJZY.Track.Application/Services/ProvideServices/TrackPushService.cs b/src/SJZY.Track.Application/Services/ProvideServices/TrackPushService.cs index fe78e2dd..6b21c0fb 100644 --- a/src/SJZY.Track.Application/Services/ProvideServices/TrackPushService.cs +++ b/src/SJZY.Track.Application/Services/ProvideServices/TrackPushService.cs @@ -1,6 +1,5 @@ using DotNetCore.CAP; using Microsoft.AspNetCore.Authorization; -using SJZY.Track.Application.CAP.EventHandlers; using SJZY.Track.Application.Contract.Dtos.ProvideServices; using SJZY.Track.Application.Contract.Events; using SJZY.Track.Domain.Aggregates.OrderAggregate; @@ -18,10 +17,10 @@ namespace SJZY.Track.Application.Services.ProvideServices; [Route("/ProviderService")] public class TrackPushService : ApplicationService { - private readonly IOrderRepository _orderRepository; private readonly ICapPublisher _capPublisher; - private readonly ITrackPushRecordsRepository _trackPushRecordsRepository; + private readonly IOrderRepository _orderRepository; private readonly IHttpClientProxy _requestCurrentUserService; + private readonly ITrackPushRecordsRepository _trackPushRecordsRepository; public TrackPushService(IOrderRepository orderRepository , ICapPublisher capPublisher @@ -92,23 +91,12 @@ public class TrackPushService : ApplicationService [HttpPost("Track/PushWarnForTask")] public async Task PushWarnForTaskAsync() { - int total = 0, pageSize = 1000,waitTime = 1000; - var dateTimes = Enumerable.Range(1, 12).Select(val => DateTime.Now.AddHours(-val)).ToList(); - - foreach (var dateTime in dateTimes) + await _capPublisher.PublishAsync(GlobalConst.TrackPushWarning, new PushWarningEvent { - var rows = 0; - var pageindex = 1; - do - { - rows = await _orderRepository.PushWarnOrdersAsync(pageSize,pageindex,dateTime); - total+=rows; - pageindex++; - await Task.Delay(waitTime); - }while (rows!= pageSize); - } - - return $"本次预警扫描了:{total}个订单"; + PageSize = 1000 + }); + + return "推送预警任务已启动"; } /// diff --git a/src/SJZY.Track.Domain/Consts/GlobalConst.MQ.cs b/src/SJZY.Track.Domain/Consts/GlobalConst.MQ.cs index 378f0b89..515afe91 100644 --- a/src/SJZY.Track.Domain/Consts/GlobalConst.MQ.cs +++ b/src/SJZY.Track.Domain/Consts/GlobalConst.MQ.cs @@ -56,4 +56,9 @@ public partial class GlobalConst /// 关联订单后补轨迹 /// public const string OrderLinkAfterFillTrack = "SJZY.Track.OrderLinkAfterFillTrack"; + + /// + /// 推送预警任务 + /// + public const string TrackPushWarning = "SJZY.Track.TrackPushWarning"; } \ No newline at end of file