All checks were successful
Build and Deploy / deploy (push) Successful in 1m1s
新增获取下游文件接口;事件发布统一走事务性 UoW,避免批量预报等按钮报 Outbox 错误。 Co-authored-by: Cursor <cursoragent@cursor.com>
46 lines
1.6 KiB
C#
46 lines
1.6 KiB
C#
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;
|
||
|
||
/// <summary>
|
||
/// 处理创单后 9610 汇总申报订单写入事件。
|
||
/// </summary>
|
||
public sealed class OrderParcelCustoms9610UpsertEventHandler(
|
||
IOrderRepository orderRepository,
|
||
Customs9610OrderWriter customs9610OrderWriter,
|
||
IUnitOfWorkManager unitOfWorkManager,
|
||
ILogger<OrderParcelCustoms9610UpsertEventHandler> logger)
|
||
: IEventHandler<OrderParcelCustoms9610UpsertIntegrationEvent>, 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);
|
||
}
|
||
}
|