62 lines
1.9 KiB
C#
62 lines
1.9 KiB
C#
using Fake.EventBus.Distributed;
|
||
using Fake.UnitOfWork;
|
||
using Microsoft.Extensions.Logging;
|
||
using Oms.Application.Services.Orders.Issues;
|
||
|
||
namespace Oms.Application.Messaging.OrderSideEffects;
|
||
|
||
/// <summary>
|
||
/// 订单旁路副作用事件:事务内写 Outbox,Commit 后投递 RabbitMQ。
|
||
/// </summary>
|
||
public sealed class OrderSideEffectEventPublisher(
|
||
IDistributedEventBus eventBus,
|
||
IUnitOfWorkManager unitOfWorkManager,
|
||
ILogger<OrderSideEffectEventPublisher> logger) : IOrderSideEffectEventPublisher
|
||
{
|
||
public async Task PublishLifecycleTrackAppendAsync(
|
||
int orderId,
|
||
string orderNo,
|
||
string trackCode,
|
||
string? authorization = null,
|
||
CancellationToken cancellationToken = default)
|
||
{
|
||
if (orderId <= 0 || string.IsNullOrWhiteSpace(orderNo) || string.IsNullOrWhiteSpace(trackCode))
|
||
{
|
||
return;
|
||
}
|
||
|
||
var @event = new OrderLifecycleTrackAppendIntegrationEvent
|
||
{
|
||
OrderId = orderId,
|
||
OrderNo = orderNo.Trim(),
|
||
TrackCode = trackCode.Trim(),
|
||
Authorization = string.IsNullOrWhiteSpace(authorization) ? null : authorization.Trim()
|
||
};
|
||
|
||
await OmsIntegrationEventPublisher.PublishAsync(
|
||
eventBus, unitOfWorkManager, logger, @event, cancellationToken);
|
||
}
|
||
|
||
public async Task PublishAutoTriggerFireAsync(
|
||
int orderId,
|
||
AutoTriggerTiming timing,
|
||
int operatorUserId,
|
||
CancellationToken cancellationToken = default)
|
||
{
|
||
if (orderId <= 0)
|
||
{
|
||
return;
|
||
}
|
||
|
||
var @event = new OrderAutoTriggerFireIntegrationEvent
|
||
{
|
||
OrderId = orderId,
|
||
Timing = timing.ToString(),
|
||
OperatorUserId = operatorUserId
|
||
};
|
||
|
||
await OmsIntegrationEventPublisher.PublishAsync(
|
||
eventBus, unitOfWorkManager, logger, @event, cancellationToken);
|
||
}
|
||
}
|