admin/src/Oms.Application/Messaging/ParcelCreate/OrderParcelLabelGenerateEventHandler.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

40 lines
1.5 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.DependencyInjection;
using Microsoft.Extensions.Logging;
using Oms.Application.Services.Orders;
namespace Oms.Application.Messaging.ParcelCreate;
/// <summary>
/// 处理创单后系统面单生成事件。
/// </summary>
public sealed class OrderParcelLabelGenerateEventHandler(
IServiceScopeFactory scopeFactory,
IUnitOfWorkManager unitOfWorkManager,
ILogger<OrderParcelLabelGenerateEventHandler> logger)
: IEventHandler<OrderParcelLabelGenerateIntegrationEvent>, ITransientDependency
{
public async Task HandleAsync(
OrderParcelLabelGenerateIntegrationEvent @event,
CancellationToken cancellationToken)
{
using var unitOfWork = unitOfWorkManager.Begin(OmsOutboxUnitOfWork.Transactional());
using var scope = scopeFactory.CreateScope();
var orderService = scope.ServiceProvider.GetRequiredService<OrderService>();
var result = await orderService.GenerateLabelPdfForBatchAsync(@event.OrderId, cancellationToken);
if (!result.Success)
{
// 面单失败不阻断创单主链路;记录后正常 Ack,避免反复重试打满队列
logger.LogWarning(
"Label generate failed OrderId={OrderId} Error={Error}",
@event.OrderId,
result.Error);
}
await unitOfWork.CompleteAsync(cancellationToken);
}
}