admin/src/Oms.Application/Messaging/ParcelCreate/OrderParcelCustoms9610UpsertEventHandler.cs
zzh 6c3a094126
All checks were successful
Build and Deploy / deploy (push) Successful in 1m1s
feat: 下游 getFile 转存 COS,并修复集成事件 Outbox 事务
新增获取下游文件接口;事件发布统一走事务性 UoW,避免批量预报等按钮报 Outbox 错误。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-10 18:45:40 +08:00

46 lines
1.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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);
}
}