39 lines
1.5 KiB
C#
39 lines
1.5 KiB
C#
using DotNetCore.CAP;
|
|
using SJZY.Track.Application.Contract.Events;
|
|
using SJZY.Track.Domain.Aggregates.OrderAggregate;
|
|
using Volo.Abp.DependencyInjection;
|
|
|
|
namespace SJZY.Track.Application.EventHandlers;
|
|
|
|
public class UpdateOrderTrackEventHandler : ITransientDependency, ICapSubscribe
|
|
{
|
|
private readonly IOrderRepository _orderRepository;
|
|
|
|
public UpdateOrderTrackEventHandler(IOrderRepository orderRepository)
|
|
{
|
|
_orderRepository = orderRepository;
|
|
}
|
|
|
|
[CapSubscribe(GlobalConst.UpdateOrderTrackSubscribe)]
|
|
public async Task ConsumerAsync(UpdateOrderTrackEvent @event)
|
|
{
|
|
var order = await _orderRepository.GetFirstAsync(x => x.Id == @event.OrderId);
|
|
if (order == default) return;
|
|
|
|
if (order.IsCompleted) return;
|
|
order.LatestTrackContent = @event.TrackContent;
|
|
order.LatestTrackEnContent = @event.TrackEnContent;
|
|
order.LatestTrackPlace = @event.TrackPlace;
|
|
order.LatestTrackTime = @event.TrackTime;
|
|
order.LatestTrackTimeZone = @event.TrackTimeZone;
|
|
if (@event.IsCompleted) order.IsCompleted = true;
|
|
else if (order.LatestTrackTime != null &&
|
|
order.LatestTrackTime.Value.Subtract(TimeSpan.FromHours(order.LatestTrackTimeZone ?? 0)) >
|
|
@event.TrackTime.Subtract(TimeSpan.FromHours(@event.TrackTimeZone))) return;
|
|
|
|
await _orderRepository.UpdateColumnAsync(order, x => new
|
|
{
|
|
x.IsCompleted, x.LatestTrackContent, x.LatestTrackEnContent, x.LatestTrackPlace, x.LatestTrackTime
|
|
});
|
|
}
|
|
} |