108 lines
3.7 KiB
C#
108 lines
3.7 KiB
C#
using DotNetCore.CAP;
|
|
using SJZY.Track.Application.Contract.Events;
|
|
using SJZY.Track.Application.Contract.Services;
|
|
using SJZY.Track.Domain.Aggregates.OrderAggregate;
|
|
using SJZY.Track.Domain.Consts;
|
|
using SJZY.Track.Domain.Dtos.Forewarning;
|
|
using Volo.Abp.DependencyInjection;
|
|
|
|
namespace SJZY.Track.Application.CAP.EventHandlers;
|
|
|
|
public class TrackChangeAfterUpdateOrderEventHandler : ITransientDependency, ICapSubscribe
|
|
{
|
|
private readonly IOrderRepository _orderRepository;
|
|
private readonly IForewarningNotifyService _forewarningNotifyService;
|
|
|
|
public TrackChangeAfterUpdateOrderEventHandler(IOrderRepository orderRepository,
|
|
IForewarningNotifyService forewarningNotifyService)
|
|
{
|
|
_orderRepository = orderRepository;
|
|
_forewarningNotifyService = forewarningNotifyService;
|
|
}
|
|
|
|
[CapSubscribe(GlobalConst.TrackChangeAfterUpdateOrderSubscribe)]
|
|
public async Task ConsumerAsync(TrackChangeAfterUpdateOrderEvent @event)
|
|
{
|
|
var orders = await _orderRepository.GetListAsync(x => @event.OrderIds.Contains(x.Id),
|
|
x => new OrderEntity
|
|
{
|
|
Id = x.Id,
|
|
IsCompleted = x.IsCompleted,
|
|
LatestTrackContent = x.LatestTrackContent,
|
|
LatestTrackEnContent = x.LatestTrackEnContent,
|
|
LatestTrackPlace = x.LatestTrackPlace,
|
|
LatestTrackTime = x.LatestTrackTime,
|
|
LatestTrackTimeZone = x.LatestTrackTimeZone,
|
|
});
|
|
|
|
if (orders.Count == 0) return;
|
|
|
|
var updateOrders = new List<OrderEntity>();
|
|
foreach (var order in orders)
|
|
{
|
|
if (order.LatestTrackContent != @event.TrackContent)
|
|
{
|
|
if (order.LatestTrackTime != null &&
|
|
@event.TrackTime.Subtract(TimeSpan.FromHours(@event.TrackTimeZone)) <
|
|
order.LatestTrackTime.Value.Subtract(TimeSpan.FromHours(order.LatestTrackTimeZone ?? 0)))
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
|
|
if (!order.IsCompleted)
|
|
{
|
|
order.IsCompleted = @event.IsCompleted;
|
|
}
|
|
|
|
order.LatestTrackContent = @event.TrackContent;
|
|
order.LatestTrackEnContent = @event.TrackEnContent;
|
|
order.LatestTrackPlace = @event.TrackPlace;
|
|
order.LatestTrackTime = @event.TrackTime;
|
|
order.LatestTrackTimeZone = @event.TrackTimeZone;
|
|
updateOrders.Add(order);
|
|
}
|
|
|
|
await _orderRepository.UpdateRangeAsync(updateOrders, x => new
|
|
{
|
|
x.IsCompleted, x.LatestTrackContent, x.LatestTrackEnContent, x.LatestTrackPlace, x.LatestTrackTime,
|
|
x.LatestTrackTimeZone
|
|
});
|
|
}
|
|
|
|
private ForewarningOrderModel OrderToForewarningOrderModel(OrderEntity order)
|
|
{
|
|
return new ForewarningOrderModel
|
|
{
|
|
Id = order.Id,
|
|
Track = DetermineTrackBasedOnOrderDetails(order),
|
|
SystemId = order.SubSystemId,
|
|
CustomerId = order.CustomId,
|
|
CargoType = order.CargoType,
|
|
Month = order.CreateTime.Month,
|
|
Area = DetermineAreaBasedOnOrderDetails(order),
|
|
IsTransit = order.IsTransfer,
|
|
DeparturePort = order.LeavePort,
|
|
ProductCode = order.ProductCode
|
|
};
|
|
}
|
|
|
|
// Placeholder methods for deriving or converting values. You'll need to implement these based on your specific logic.
|
|
private int DetermineTrackBasedOnOrderDetails(OrderEntity order)
|
|
{
|
|
// Implement logic to determine Track
|
|
return default;
|
|
}
|
|
|
|
private int? DetermineMonthBasedOnOrderDetails(OrderEntity order)
|
|
{
|
|
// Implement logic to determine Month
|
|
return default;
|
|
}
|
|
|
|
private int? DetermineAreaBasedOnOrderDetails(OrderEntity order)
|
|
{
|
|
// Implement logic to determine Area
|
|
return default;
|
|
}
|
|
} |