1.04 #6

Merged
zzh merged 4 commits from test into master 2026-10-10 19:35:37 +08:00
6 changed files with 60 additions and 12 deletions
Showing only changes of commit 32156dcfe0 - Show all commits

View File

@ -67,16 +67,11 @@ internal sealed class SmallBagTrackUpsertRequestBuilder(
}; };
} }
internal static string ResolveTrackNo(Order order) /// <summary>
{ /// 仅取运单跟踪号;无值则空串,不回落运单号/客户单号等。
var trackNo = order.TrackNo?.Trim(); /// </summary>
if (!string.IsNullOrWhiteSpace(trackNo)) internal static string ResolveTrackNo(Order order) =>
{ order.TrackNo?.Trim() ?? string.Empty;
return trackNo;
}
return order.ServiceNo?.Trim() ?? string.Empty;
}
internal static string? PickSupplierCodeFromProviders( internal static string? PickSupplierCodeFromProviders(
IEnumerable<SalesProductAllocationProviderSnapshotDto> providers, IEnumerable<SalesProductAllocationProviderSnapshotDto> providers,

View File

@ -6,6 +6,7 @@ using Oms.Application.Dtos.Orders;
using Oms.Application.Integrations.Itfx; using Oms.Application.Integrations.Itfx;
using Oms.Application.Integrations.SmallBagTrack; using Oms.Application.Integrations.SmallBagTrack;
using Oms.Application.Messaging; using Oms.Application.Messaging;
using Oms.Application.Messaging.ParcelCreate;
using Oms.Application.Shared; using Oms.Application.Shared;
using Oms.Application.Storage; using Oms.Application.Storage;
using Oms.Domain.ChannelsAggregate.Repositories; using Oms.Domain.ChannelsAggregate.Repositories;
@ -23,6 +24,7 @@ public sealed class OrderBatchActionExecutor(
IObjectStorage fileStorage, IObjectStorage fileStorage,
ISmallBagTrackOrderClient smallBagTrackOrderClient, ISmallBagTrackOrderClient smallBagTrackOrderClient,
ISmallBagTrackUpsertRequestBuilder smallBagTrackUpsertRequestBuilder, ISmallBagTrackUpsertRequestBuilder smallBagTrackUpsertRequestBuilder,
IOrderParcelCreateEventPublisher parcelCreateEventPublisher,
OrderDownstreamCredentialResolver downstreamCredentialResolver, OrderDownstreamCredentialResolver downstreamCredentialResolver,
IItfxForwardClient itfxForwardClient, IItfxForwardClient itfxForwardClient,
OrderFileManager orderFileManager, OrderFileManager orderFileManager,
@ -231,9 +233,31 @@ public sealed class OrderBatchActionExecutor(
if (ItfxCreateOrderOneDataParser.TryParse(forward.ResponseBody, out var data) if (ItfxCreateOrderOneDataParser.TryParse(forward.ResponseBody, out var data)
&& data != null) && data != null)
{ {
var previousTrackNo = order.TrackNo;
if (ItfxCreateOrderOneDataParser.ApplyToOrder(order, data)) if (ItfxCreateOrderOneDataParser.ApplyToOrder(order, data))
{ {
await orderRepository.UpdateAsync(order, cancellationToken); await orderRepository.UpdateAsync(order, cancellationToken);
var nextTrackNo = order.TrackNo?.Trim() ?? string.Empty;
var prevTrackNo = previousTrackNo?.Trim() ?? string.Empty;
if (!string.IsNullOrWhiteSpace(nextTrackNo)
&& !string.Equals(nextTrackNo, prevTrackNo, StringComparison.Ordinal))
{
var trackRequest = await smallBagTrackUpsertRequestBuilder.BuildAsync(
order,
cancellationToken: cancellationToken);
trackRequest.AppendInitialTrackOnSuccess = true;
if (!string.IsNullOrWhiteSpace(authorization))
{
trackRequest.Authorization = authorization.Trim();
}
await parcelCreateEventPublisher.PublishTrackUpsertAsync(
order,
trackRequest,
customerId: order.CustomerId,
cancellationToken);
}
} }
if (!string.IsNullOrWhiteSpace(data.LabelUrl)) if (!string.IsNullOrWhiteSpace(data.LabelUrl))

View File

@ -57,9 +57,11 @@ public partial class OrderService
&& ItfxCreateOrderOneDataParser.TryParse(forward.ResponseBody, out var data) && ItfxCreateOrderOneDataParser.TryParse(forward.ResponseBody, out var data)
&& data != null) && data != null)
{ {
var previousTrackNo = order.TrackNo;
if (ItfxCreateOrderOneDataParser.ApplyToOrder(order, data)) if (ItfxCreateOrderOneDataParser.ApplyToOrder(order, data))
{ {
await OrderRepository.UpdateAsync(order); await OrderRepository.UpdateAsync(order);
await EnqueueSmallBagTrackUpsertWhenTrackNoChangedAsync(order, previousTrackNo);
} }
if (!string.IsNullOrWhiteSpace(data.LabelUrl)) if (!string.IsNullOrWhiteSpace(data.LabelUrl))
@ -118,9 +120,11 @@ public partial class OrderService
&& ItfxGetFileDataParser.TryParse(forward.ResponseBody, out var data) && ItfxGetFileDataParser.TryParse(forward.ResponseBody, out var data)
&& data != null) && data != null)
{ {
var previousTrackNo = order.TrackNo;
if (ItfxGetFileDataParser.ApplyToOrder(order, data)) if (ItfxGetFileDataParser.ApplyToOrder(order, data))
{ {
await OrderRepository.UpdateAsync(order); await OrderRepository.UpdateAsync(order);
await EnqueueSmallBagTrackUpsertWhenTrackNoChangedAsync(order, previousTrackNo);
} }
if (!string.IsNullOrWhiteSpace(data.Url)) if (!string.IsNullOrWhiteSpace(data.Url))

View File

@ -48,6 +48,7 @@ public partial class OrderService
order.ClientNo = newClientNo; order.ClientNo = newClientNo;
} }
var previousTrackNo = order.TrackNo;
if (input.TrackNo != null) if (input.TrackNo != null)
{ {
order.TrackNo = string.IsNullOrWhiteSpace(input.TrackNo) ? null : input.TrackNo.Trim(); order.TrackNo = string.IsNullOrWhiteSpace(input.TrackNo) ? null : input.TrackNo.Trim();
@ -155,6 +156,11 @@ public partial class OrderService
afterSnap, afterSnap,
remark); remark);
if (input.TrackNo != null)
{
await EnqueueSmallBagTrackUpsertWhenTrackNoChangedAsync(order, previousTrackNo);
}
return (await MapOrderOutputsAsync([order])).First(); return (await MapOrderOutputsAsync([order])).First();
} }

View File

@ -3201,6 +3201,25 @@ public partial class OrderService
await ParcelCreateEventPublisher.PublishTrackUpsertAsync(order, request, customer?.Id); await ParcelCreateEventPublisher.PublishTrackUpsertAsync(order, request, customer?.Id);
} }
/// <summary>
/// 跟踪号相对旧值有变更且新值非空时,再创建/更新一次轨迹订单。
/// </summary>
private async Task EnqueueSmallBagTrackUpsertWhenTrackNoChangedAsync(
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))
{
return;
}
await EnqueueSmallBagTrackUpsertAsync(order, customer: null, receiver: null, appendInitialTrack);
}
private async Task EnqueueLifecycleTrackAppendAsync(Order order, string trackCode) private async Task EnqueueLifecycleTrackAppendAsync(Order order, string trackCode)
{ {
if (string.IsNullOrWhiteSpace(order.ServiceNo)) if (string.IsNullOrWhiteSpace(order.ServiceNo))

View File

@ -20,7 +20,7 @@ public class SmallBagTrackUpsertRequestBuilderTests
} }
[Fact] [Fact]
public void ResolveTrackNo_FallsBackToServiceNoWhenTrackNoEmpty() public void ResolveTrackNo_EmptyWhenTrackNoMissing()
{ {
var order = new Order var order = new Order
{ {
@ -28,7 +28,7 @@ public class SmallBagTrackUpsertRequestBuilderTests
TrackNo = null TrackNo = null
}; };
Assert.Equal("IDE2607221859123456", SmallBagTrackUpsertRequestBuilder.ResolveTrackNo(order)); Assert.Equal(string.Empty, SmallBagTrackUpsertRequestBuilder.ResolveTrackNo(order));
} }
[Fact] [Fact]