using Fake.DependencyInjection; using Fake.EventBus; using Fake.UnitOfWork; using Oms.Application.Messaging; using Microsoft.Extensions.Logging; using Oms.Application.Services.Orders; using Oms.Domain.OrdersAggregate.Repositories; namespace Oms.Application.Messaging.ParcelCreate; /// /// 处理创单后 9610 汇总申报订单写入事件。 /// public sealed class OrderParcelCustoms9610UpsertEventHandler( IOrderRepository orderRepository, Customs9610OrderWriter customs9610OrderWriter, IUnitOfWorkManager unitOfWorkManager, ILogger logger) : IEventHandler, ITransientDependency { public async Task HandleAsync( OrderParcelCustoms9610UpsertIntegrationEvent @event, CancellationToken cancellationToken) { using var unitOfWork = unitOfWorkManager.Begin(OmsOutboxUnitOfWork.Transactional()); var order = await orderRepository.FirstOrDefaultAsync(x => x.Id == @event.OrderId, cancellationToken); if (order == null) { logger.LogWarning("9610 upsert skipped, order missing OrderId={OrderId}", @event.OrderId); return; } try { await customs9610OrderWriter.UpsertFromOrderAsync(order, @event.PlatformCode, cancellationToken); } catch (Exception ex) { // 与原同步路径一致:9610 失败不抛到总线重试风暴 logger.LogWarning(ex, "9610 upsert failed OrderId={OrderId}", @event.OrderId); } await unitOfWork.CompleteAsync(cancellationToken); } }