feat: 定时任务推送预警(》12小时没有推送的 改为事件提交
This commit is contained in:
parent
7cba774373
commit
b30846a811
@ -0,0 +1,6 @@
|
|||||||
|
namespace SJZY.Track.Application.Contract.Events;
|
||||||
|
|
||||||
|
public class PushWarningEvent
|
||||||
|
{
|
||||||
|
public int PageSize { get; set; }
|
||||||
|
}
|
||||||
@ -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<PushWarningEventHandler> _logger;
|
||||||
|
private readonly IOrderRepository _orderRepository;
|
||||||
|
|
||||||
|
public PushWarningEventHandler(IOrderRepository orderRepository,
|
||||||
|
ILogger<PushWarningEventHandler> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,6 +1,5 @@
|
|||||||
using DotNetCore.CAP;
|
using DotNetCore.CAP;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using SJZY.Track.Application.CAP.EventHandlers;
|
|
||||||
using SJZY.Track.Application.Contract.Dtos.ProvideServices;
|
using SJZY.Track.Application.Contract.Dtos.ProvideServices;
|
||||||
using SJZY.Track.Application.Contract.Events;
|
using SJZY.Track.Application.Contract.Events;
|
||||||
using SJZY.Track.Domain.Aggregates.OrderAggregate;
|
using SJZY.Track.Domain.Aggregates.OrderAggregate;
|
||||||
@ -18,10 +17,10 @@ namespace SJZY.Track.Application.Services.ProvideServices;
|
|||||||
[Route("/ProviderService")]
|
[Route("/ProviderService")]
|
||||||
public class TrackPushService : ApplicationService
|
public class TrackPushService : ApplicationService
|
||||||
{
|
{
|
||||||
private readonly IOrderRepository _orderRepository;
|
|
||||||
private readonly ICapPublisher _capPublisher;
|
private readonly ICapPublisher _capPublisher;
|
||||||
private readonly ITrackPushRecordsRepository _trackPushRecordsRepository;
|
private readonly IOrderRepository _orderRepository;
|
||||||
private readonly IHttpClientProxy<IRequestCurrentUserService> _requestCurrentUserService;
|
private readonly IHttpClientProxy<IRequestCurrentUserService> _requestCurrentUserService;
|
||||||
|
private readonly ITrackPushRecordsRepository _trackPushRecordsRepository;
|
||||||
|
|
||||||
public TrackPushService(IOrderRepository orderRepository
|
public TrackPushService(IOrderRepository orderRepository
|
||||||
, ICapPublisher capPublisher
|
, ICapPublisher capPublisher
|
||||||
@ -92,23 +91,12 @@ public class TrackPushService : ApplicationService
|
|||||||
[HttpPost("Track/PushWarnForTask")]
|
[HttpPost("Track/PushWarnForTask")]
|
||||||
public async Task<string> PushWarnForTaskAsync()
|
public async Task<string> PushWarnForTaskAsync()
|
||||||
{
|
{
|
||||||
int total = 0, pageSize = 1000,waitTime = 1000;
|
await _capPublisher.PublishAsync(GlobalConst.TrackPushWarning, new PushWarningEvent
|
||||||
var dateTimes = Enumerable.Range(1, 12).Select(val => DateTime.Now.AddHours(-val)).ToList();
|
|
||||||
|
|
||||||
foreach (var dateTime in dateTimes)
|
|
||||||
{
|
{
|
||||||
var rows = 0;
|
PageSize = 1000
|
||||||
var pageindex = 1;
|
});
|
||||||
do
|
|
||||||
{
|
return "推送预警任务已启动";
|
||||||
rows = await _orderRepository.PushWarnOrdersAsync(pageSize,pageindex,dateTime);
|
|
||||||
total+=rows;
|
|
||||||
pageindex++;
|
|
||||||
await Task.Delay(waitTime);
|
|
||||||
}while (rows!= pageSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $"本次预警扫描了:{total}个订单";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -56,4 +56,9 @@ public partial class GlobalConst
|
|||||||
/// 关联订单后补轨迹
|
/// 关联订单后补轨迹
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public const string OrderLinkAfterFillTrack = "SJZY.Track.OrderLinkAfterFillTrack";
|
public const string OrderLinkAfterFillTrack = "SJZY.Track.OrderLinkAfterFillTrack";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 推送预警任务
|
||||||
|
/// </summary>
|
||||||
|
public const string TrackPushWarning = "SJZY.Track.TrackPushWarning";
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user