From 76c8a8336819cf721eb06ff5404eebe70fef4526 Mon Sep 17 00:00:00 2001 From: zzh <1368735060@qq.com> Date: Sat, 10 Oct 2026 19:20:10 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20UpsertSmallBag=20=E5=AD=98=E5=9C=A8?= =?UTF-8?q?=E6=97=B6=E6=9B=B4=E6=96=B0=20TrackNo=20=E7=AD=89=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- .../ProvideServices/OrderService.V2.cs | 41 +++++++++++++++ .../Repositories/OrderRepository.cs | 50 +++++++++++++++++-- 2 files changed, 88 insertions(+), 3 deletions(-) diff --git a/src/TrackCenter.Application/Services/ProvideServices/OrderService.V2.cs b/src/TrackCenter.Application/Services/ProvideServices/OrderService.V2.cs index cbcfc734..af38574f 100644 --- a/src/TrackCenter.Application/Services/ProvideServices/OrderService.V2.cs +++ b/src/TrackCenter.Application/Services/ProvideServices/OrderService.V2.cs @@ -23,7 +23,9 @@ public partial class OrderService x.AppKey == AppKey && x.OrderType == TrackOrderType.小包 && x.OrderNo == input.OrderNo); if (order != null) { + var existing = order; order = await BuiltOrder(input); + ApplyUpsertOntoExisting(order, existing, resetTrackInfoWhenTrackNoChanged: true); await _orderRepository.UpdateOrderAsync(order); @@ -71,7 +73,9 @@ public partial class OrderService x.AppKey == AppKey && x.OrderType == TrackOrderType.大包 && x.OrderNo == input.BagNo); if (order != null) { + var existing = order; order = await BuiltOrder(input); + ApplyUpsertOntoExisting(order, existing, resetTrackInfoWhenTrackNoChanged: false); await _orderRepository.UpdateOrderAsync(order); @@ -119,7 +123,9 @@ public partial class OrderService x.AppKey == AppKey && x.OrderType == TrackOrderType.主单 && x.OrderNo == input.MasterNo); if (order != null) { + var existing = order; order = await BuiltOrder(input); + ApplyUpsertOntoExisting(order, existing, resetTrackInfoWhenTrackNoChanged: false); await _orderRepository.UpdateOrderAsync(order); @@ -260,6 +266,41 @@ public partial class OrderService return order; } + /// + /// 合并到已有订单:保留 Id;跟踪号未变则保留轨迹摘要,变更则清空便于重拉。 + /// + private static void ApplyUpsertOntoExisting( + OrderEntity built, + OrderEntity existing, + bool resetTrackInfoWhenTrackNoChanged) + { + built.Id = existing.Id; + + var previousTrackNo = existing.TrackNo?.Trim() ?? string.Empty; + var nextTrackNo = built.TrackNo?.Trim() ?? string.Empty; + var trackNoChanged = !string.Equals(previousTrackNo, nextTrackNo, StringComparison.Ordinal); + + if (resetTrackInfoWhenTrackNoChanged && trackNoChanged) + { + built.ResetTrackInfo(); + return; + } + + built.IsCompleted = existing.IsCompleted; + built.LatestPushTrackCode = existing.LatestPushTrackCode; + built.LatestPushTime = existing.LatestPushTime; + built.LatestPushError = existing.LatestPushError; + built.LatestTrackStatus = existing.LatestTrackStatus; + built.LatestTrackContent = existing.LatestTrackContent; + built.LatestTrackEnContent = existing.LatestTrackEnContent; + built.LatestTrackTime = existing.LatestTrackTime; + built.LatestTrackTimeZone = existing.LatestTrackTimeZone; + built.LatestTrackPlace = existing.LatestTrackPlace; + built.EstimatedDeliveryDate = existing.EstimatedDeliveryDate; + built.DestinationTimeZone = existing.DestinationTimeZone; + built.QuestionType = existing.QuestionType; + } + private static OrderPullStatusEntity CreateOrderPullStatus(TrackPullConfigEntity config, OrderEntity order) { var status = new OrderPullStatusEntity diff --git a/src/TrackCenter.Repository/Repositories/OrderRepository.cs b/src/TrackCenter.Repository/Repositories/OrderRepository.cs index 672c2402..39dc7578 100644 --- a/src/TrackCenter.Repository/Repositories/OrderRepository.cs +++ b/src/TrackCenter.Repository/Repositories/OrderRepository.cs @@ -254,11 +254,33 @@ public class OrderRepository : BasicRepository, IOrderRepository, I { using var tran = TransactionHelper.GetReadCommitted(); - // 更新订单主表 + // 更新订单主表(Upsert 业务字段;勿只更 Customer/AppKey) await UpdateAsync(order, x => new { x.Customer, x.AppKey, + x.TrackNo, + x.ThirdPartyOrderNumber, + x.Channel, + x.ProductCode, + x.ServiceProviderCode, + x.ArrivalCountry, + x.ArrivalProvince, + x.ArrivalPostCode, + x.ArrivalCity, + x.ArrivalEmail, + x.LeaveCountry, + x.LeaveCity, + x.IsTransit, + x.IsCompleted, + x.LatestTrackStatus, + x.LatestTrackContent, + x.LatestTrackEnContent, + x.LatestTrackTime, + x.LatestTrackTimeZone, + x.LatestTrackPlace, + x.EstimatedDeliveryDate, + x.DestinationTimeZone, }); // 更新订单拉取状态 @@ -280,11 +302,33 @@ public class OrderRepository : BasicRepository, IOrderRepository, I try { - // 更新订单主表 + // 更新订单主表(与 UpdateOrderAsync 字段对齐) await UpdateRangeAsync(orders, x => new { x.Customer, - x.AppKey + x.AppKey, + x.TrackNo, + x.ThirdPartyOrderNumber, + x.Channel, + x.ProductCode, + x.ServiceProviderCode, + x.ArrivalCountry, + x.ArrivalProvince, + x.ArrivalPostCode, + x.ArrivalCity, + x.ArrivalEmail, + x.LeaveCountry, + x.LeaveCity, + x.IsTransit, + x.IsCompleted, + x.LatestTrackStatus, + x.LatestTrackContent, + x.LatestTrackEnContent, + x.LatestTrackTime, + x.LatestTrackTimeZone, + x.LatestTrackPlace, + x.EstimatedDeliveryDate, + x.DestinationTimeZone, }); var orderIds = orders.Select(x => x.Id).ToHashSet(); From be959893920510b45f44226428cb3e509f236d72 Mon Sep 17 00:00:00 2001 From: zzh <1368735060@qq.com> Date: Sat, 10 Oct 2026 19:31:01 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20UpdateOrderAsync=20=E6=94=B9?= =?UTF-8?q?=E7=94=A8=20UpdateColumnAsync=EF=BC=8C=E7=9C=9F=E6=AD=A3?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=20TrackNo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- src/TrackCenter.Repository/Repositories/OrderRepository.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/TrackCenter.Repository/Repositories/OrderRepository.cs b/src/TrackCenter.Repository/Repositories/OrderRepository.cs index 39dc7578..3f62cdd7 100644 --- a/src/TrackCenter.Repository/Repositories/OrderRepository.cs +++ b/src/TrackCenter.Repository/Repositories/OrderRepository.cs @@ -254,8 +254,9 @@ public class OrderRepository : BasicRepository, IOrderRepository, I { using var tran = TransactionHelper.GetReadCommitted(); - // 更新订单主表(Upsert 业务字段;勿只更 Customer/AppKey) - await UpdateAsync(order, x => new + // 注意:UpdateAsync(entity, cols) 的 cols 是 IgnoreColumns; + // 指定要更新的列必须用 UpdateColumnAsync。 + await UpdateColumnAsync(order, x => new { x.Customer, x.AppKey, From 67f3ba76c79c21fde86618e9484afe1487e68a89 Mon Sep 17 00:00:00 2001 From: zzh <1368735060@qq.com> Date: Mon, 12 Oct 2026 16:36:40 +0800 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=E6=89=B9=E9=87=8F=E6=8B=89?= =?UTF-8?q?=E5=8F=96=E8=BD=A8=E8=BF=B9=20payload=20=E5=A2=9E=E5=8A=A0=20tr?= =?UTF-8?q?ackNo=E3=80=81otherNo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- .../Dtos/TrackPull/TrackPullPayload.cs | 12 +++++++++++- .../Queries/ProvideQueries.cs | 4 ++++ .../Services/ProvideServices/TrackPullService.cs | 4 +++- .../Services/TimerTaskss/TrackPullTask.cs | 4 +++- .../Dtos/Order/OrderWithServiceProviderVO.cs | 13 +++++++++++++ 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/TrackCenter.Application/Dtos/TrackPull/TrackPullPayload.cs b/src/TrackCenter.Application/Dtos/TrackPull/TrackPullPayload.cs index c48bdded..75612ffa 100644 --- a/src/TrackCenter.Application/Dtos/TrackPull/TrackPullPayload.cs +++ b/src/TrackCenter.Application/Dtos/TrackPull/TrackPullPayload.cs @@ -3,7 +3,17 @@ namespace TrackCenter.Application.Dtos.TrackPull; public class TrackPullPayload { /// - /// 订单号 + /// 订单号(按拉取优先级配置的单号类型解析后的主单号) /// public string OrderNo { get; set; } = null!; + + /// + /// 尾程单号 / 跟踪号 + /// + public string? TrackNo { get; set; } + + /// + /// 其他单号 + /// + public string? OtherNo { get; set; } } diff --git a/src/TrackCenter.Application/Queries/ProvideQueries.cs b/src/TrackCenter.Application/Queries/ProvideQueries.cs index 1e5226fc..57da1285 100644 --- a/src/TrackCenter.Application/Queries/ProvideQueries.cs +++ b/src/TrackCenter.Application/Queries/ProvideQueries.cs @@ -62,6 +62,8 @@ public class ProvideQueries : SqlSugarRootlessRepository, OrderNo = d.OrderNoType == TrackOrderNoType.客户单号 ? a.OrderNo : d.OrderNoType == TrackOrderNoType.跟踪单号 ? a.TrackNo : d.OrderNoType == TrackOrderNoType.其他单号 ? a.ThirdPartyOrderNumber : a.OrderNo, + TrackNo = a.TrackNo, + OtherNo = a.ThirdPartyOrderNumber, OrderType = a.OrderType, AppKey = a.AppKey, ServiceProviderCode = b.ServiceProviderCode, @@ -165,6 +167,8 @@ public class ProvideQueries : SqlSugarRootlessRepository, OrderNo = config.OrderNoType == TrackOrderNoType.客户单号 ? a.OrderNo : config.OrderNoType == TrackOrderNoType.跟踪单号 ? a.TrackNo : config.OrderNoType == TrackOrderNoType.其他单号 ? a.ThirdPartyOrderNumber : a.OrderNo, + TrackNo = a.TrackNo, + OtherNo = a.ThirdPartyOrderNumber, OrderType = a.OrderType, AppKey = a.AppKey, ServiceProviderCode = b.ServiceProviderCode diff --git a/src/TrackCenter.Application/Services/ProvideServices/TrackPullService.cs b/src/TrackCenter.Application/Services/ProvideServices/TrackPullService.cs index 22fd0039..a4248da4 100644 --- a/src/TrackCenter.Application/Services/ProvideServices/TrackPullService.cs +++ b/src/TrackCenter.Application/Services/ProvideServices/TrackPullService.cs @@ -68,7 +68,9 @@ public class TrackPullService : ApplicationServiceBase { var data = new List(group.Select(x => new TrackPullPayload { - OrderNo = x.OrderNo + OrderNo = x.OrderNo, + TrackNo = x.TrackNo, + OtherNo = x.OtherNo, })); var serviceProviderCode = group.Key.ServiceProviderCode; var attach = Base64Helper.SerializeObject(new TrackRefreshAttach(group.Key.ServiceProviderCode, diff --git a/src/TrackCenter.Application/Services/TimerTaskss/TrackPullTask.cs b/src/TrackCenter.Application/Services/TimerTaskss/TrackPullTask.cs index 6c41fdb1..e8c7818b 100644 --- a/src/TrackCenter.Application/Services/TimerTaskss/TrackPullTask.cs +++ b/src/TrackCenter.Application/Services/TimerTaskss/TrackPullTask.cs @@ -106,7 +106,9 @@ public class TrackPullTask( { var data = new List(group.Select(x => new TrackPullPayload { - OrderNo = x.OrderNo + OrderNo = x.OrderNo, + TrackNo = x.TrackNo, + OtherNo = x.OtherNo, })); var attach = Base64Helper.SerializeObject(new TrackRefreshAttach(config.ServiceProviderCode, config.AppKey, group.Key)); diff --git a/src/TrackCenter.Domain/Dtos/Order/OrderWithServiceProviderVO.cs b/src/TrackCenter.Domain/Dtos/Order/OrderWithServiceProviderVO.cs index 13fe51f8..9fd09ccd 100644 --- a/src/TrackCenter.Domain/Dtos/Order/OrderWithServiceProviderVO.cs +++ b/src/TrackCenter.Domain/Dtos/Order/OrderWithServiceProviderVO.cs @@ -2,8 +2,21 @@ namespace TrackCenter.Domain.Dtos.Order; public class OrderWithServiceProviderVO { + /// + /// 按拉取优先级配置解析后的主单号(可能是客户单号/跟踪号/其他单号) + /// public string OrderNo { get; set; } = null!; + /// + /// 尾程单号 / 跟踪号 + /// + public string? TrackNo { get; set; } + + /// + /// 其他单号 + /// + public string? OtherNo { get; set; } + /// /// 订单类型 ///