49 lines
1.6 KiB
C#
49 lines
1.6 KiB
C#
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 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)
|
|
{
|
|
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 rows = 0;
|
|
var pageindex = 0;
|
|
|
|
do
|
|
{
|
|
rows = await _orderRepository.PushWarnOrdersAsync(pageSize, pageindex);
|
|
pageindex++;
|
|
total += rows;
|
|
await Task.Delay(waitTime);
|
|
} while (rows == pageSize);
|
|
|
|
await RedisHelper.Client.DelAsync(GlobalConst.TrackPushTrackWaringLockKey);
|
|
_logger.LogInformation(message: "本次预警扫描了:{total}个订单", total);
|
|
}
|
|
}
|