fix: 编辑订单跟踪号改为同步 Upsert,不再发 Outbox 事件
All checks were successful
Build and Deploy / deploy (push) Successful in 1m28s
All checks were successful
Build and Deploy / deploy (push) Successful in 1m28s
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
45361e9eb5
commit
264c3a5dcb
@ -1,7 +1,5 @@
|
||||
using System.Data;
|
||||
using System.Globalization;
|
||||
using Fake.Application;
|
||||
using Fake.UnitOfWork;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using Oms.Application.Dtos.Channels;
|
||||
@ -26,10 +24,9 @@ public partial class OrderService
|
||||
|
||||
/// <summary>
|
||||
/// 编辑订单详情(基本信息、发件人、收件人)。
|
||||
/// 跟踪号变更时会写轨迹 Upsert Outbox,须事务性 UoW。
|
||||
/// 跟踪号变更时同步调用轨迹 Upsert(不走 Outbox)。
|
||||
/// </summary>
|
||||
[HttpPost("/order/update")]
|
||||
[UnitOfWork(IsTransactional = true, IsolationLevel = IsolationLevel.ReadCommitted)]
|
||||
public async Task<OrderOutput> UpdateOrderDetailAsync(OrderUpdateInput input)
|
||||
{
|
||||
var order = await GetOrderOrThrowAsync(input.Id);
|
||||
@ -162,7 +159,7 @@ public partial class OrderService
|
||||
|
||||
if (input.TrackNo != null)
|
||||
{
|
||||
await EnqueueSmallBagTrackUpsertWhenTrackNoChangedAsync(order, previousTrackNo);
|
||||
await SyncSmallBagTrackUpsertWhenTrackNoChangedAsync(order, previousTrackNo);
|
||||
}
|
||||
|
||||
return (await MapOrderOutputsAsync([order])).First();
|
||||
|
||||
@ -3234,6 +3234,30 @@ public partial class OrderService
|
||||
await EnqueueSmallBagTrackUpsertAsync(order, customer: null, receiver: null, appendInitialTrack);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 跟踪号变更时同步 Upsert 轨迹(编辑订单详情用,避免依赖 Outbox/事务 UoW)。
|
||||
/// 失败仅记日志,不阻断订单保存。
|
||||
/// </summary>
|
||||
private async Task SyncSmallBagTrackUpsertWhenTrackNoChangedAsync(
|
||||
Order order,
|
||||
string? previousTrackNo,
|
||||
bool appendInitialTrack = true)
|
||||
{
|
||||
var next = order.TrackNo?.Trim() ?? string.Empty;
|
||||
var prev = previousTrackNo?.Trim() ?? string.Empty;
|
||||
if (string.IsNullOrWhiteSpace(next)
|
||||
|| string.Equals(next, prev, StringComparison.Ordinal)
|
||||
|| string.IsNullOrWhiteSpace(order.ServiceNo))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var request = await BuildSmallBagTrackUpsertRequestAsync(order);
|
||||
request.AppendInitialTrackOnSuccess = appendInitialTrack;
|
||||
ApplyTrackAuthorization(request);
|
||||
await SmallBagTrackOrderClient.UpsertAsync(request);
|
||||
}
|
||||
|
||||
private async Task EnqueueLifecycleTrackAppendAsync(Order order, string trackCode)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(order.ServiceNo))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user