test #4
@ -3,7 +3,17 @@ namespace TrackCenter.Application.Dtos.TrackPull;
|
|||||||
public class TrackPullPayload
|
public class TrackPullPayload
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 订单号
|
/// 订单号(按拉取优先级配置的单号类型解析后的主单号)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string OrderNo { get; set; } = null!;
|
public string OrderNo { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 尾程单号 / 跟踪号
|
||||||
|
/// </summary>
|
||||||
|
public string? TrackNo { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 其他单号
|
||||||
|
/// </summary>
|
||||||
|
public string? OtherNo { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -62,6 +62,8 @@ public class ProvideQueries : SqlSugarRootlessRepository<TrackCenterDbContext>,
|
|||||||
OrderNo = d.OrderNoType == TrackOrderNoType.客户单号 ? a.OrderNo :
|
OrderNo = d.OrderNoType == TrackOrderNoType.客户单号 ? a.OrderNo :
|
||||||
d.OrderNoType == TrackOrderNoType.跟踪单号 ? a.TrackNo :
|
d.OrderNoType == TrackOrderNoType.跟踪单号 ? a.TrackNo :
|
||||||
d.OrderNoType == TrackOrderNoType.其他单号 ? a.ThirdPartyOrderNumber : a.OrderNo,
|
d.OrderNoType == TrackOrderNoType.其他单号 ? a.ThirdPartyOrderNumber : a.OrderNo,
|
||||||
|
TrackNo = a.TrackNo,
|
||||||
|
OtherNo = a.ThirdPartyOrderNumber,
|
||||||
OrderType = a.OrderType,
|
OrderType = a.OrderType,
|
||||||
AppKey = a.AppKey,
|
AppKey = a.AppKey,
|
||||||
ServiceProviderCode = b.ServiceProviderCode,
|
ServiceProviderCode = b.ServiceProviderCode,
|
||||||
@ -165,6 +167,8 @@ public class ProvideQueries : SqlSugarRootlessRepository<TrackCenterDbContext>,
|
|||||||
OrderNo = config.OrderNoType == TrackOrderNoType.客户单号 ? a.OrderNo :
|
OrderNo = config.OrderNoType == TrackOrderNoType.客户单号 ? a.OrderNo :
|
||||||
config.OrderNoType == TrackOrderNoType.跟踪单号 ? a.TrackNo :
|
config.OrderNoType == TrackOrderNoType.跟踪单号 ? a.TrackNo :
|
||||||
config.OrderNoType == TrackOrderNoType.其他单号 ? a.ThirdPartyOrderNumber : a.OrderNo,
|
config.OrderNoType == TrackOrderNoType.其他单号 ? a.ThirdPartyOrderNumber : a.OrderNo,
|
||||||
|
TrackNo = a.TrackNo,
|
||||||
|
OtherNo = a.ThirdPartyOrderNumber,
|
||||||
OrderType = a.OrderType,
|
OrderType = a.OrderType,
|
||||||
AppKey = a.AppKey,
|
AppKey = a.AppKey,
|
||||||
ServiceProviderCode = b.ServiceProviderCode
|
ServiceProviderCode = b.ServiceProviderCode
|
||||||
|
|||||||
@ -23,7 +23,9 @@ public partial class OrderService
|
|||||||
x.AppKey == AppKey && x.OrderType == TrackOrderType.小包 && x.OrderNo == input.OrderNo);
|
x.AppKey == AppKey && x.OrderType == TrackOrderType.小包 && x.OrderNo == input.OrderNo);
|
||||||
if (order != null)
|
if (order != null)
|
||||||
{
|
{
|
||||||
|
var existing = order;
|
||||||
order = await BuiltOrder(input);
|
order = await BuiltOrder(input);
|
||||||
|
ApplyUpsertOntoExisting(order, existing, resetTrackInfoWhenTrackNoChanged: true);
|
||||||
|
|
||||||
await _orderRepository.UpdateOrderAsync(order);
|
await _orderRepository.UpdateOrderAsync(order);
|
||||||
|
|
||||||
@ -71,7 +73,9 @@ public partial class OrderService
|
|||||||
x.AppKey == AppKey && x.OrderType == TrackOrderType.大包 && x.OrderNo == input.BagNo);
|
x.AppKey == AppKey && x.OrderType == TrackOrderType.大包 && x.OrderNo == input.BagNo);
|
||||||
if (order != null)
|
if (order != null)
|
||||||
{
|
{
|
||||||
|
var existing = order;
|
||||||
order = await BuiltOrder(input);
|
order = await BuiltOrder(input);
|
||||||
|
ApplyUpsertOntoExisting(order, existing, resetTrackInfoWhenTrackNoChanged: false);
|
||||||
|
|
||||||
await _orderRepository.UpdateOrderAsync(order);
|
await _orderRepository.UpdateOrderAsync(order);
|
||||||
|
|
||||||
@ -119,7 +123,9 @@ public partial class OrderService
|
|||||||
x.AppKey == AppKey && x.OrderType == TrackOrderType.主单 && x.OrderNo == input.MasterNo);
|
x.AppKey == AppKey && x.OrderType == TrackOrderType.主单 && x.OrderNo == input.MasterNo);
|
||||||
if (order != null)
|
if (order != null)
|
||||||
{
|
{
|
||||||
|
var existing = order;
|
||||||
order = await BuiltOrder(input);
|
order = await BuiltOrder(input);
|
||||||
|
ApplyUpsertOntoExisting(order, existing, resetTrackInfoWhenTrackNoChanged: false);
|
||||||
|
|
||||||
await _orderRepository.UpdateOrderAsync(order);
|
await _orderRepository.UpdateOrderAsync(order);
|
||||||
|
|
||||||
@ -260,6 +266,41 @@ public partial class OrderService
|
|||||||
return order;
|
return order;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 合并到已有订单:保留 Id;跟踪号未变则保留轨迹摘要,变更则清空便于重拉。
|
||||||
|
/// </summary>
|
||||||
|
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)
|
private static OrderPullStatusEntity CreateOrderPullStatus(TrackPullConfigEntity config, OrderEntity order)
|
||||||
{
|
{
|
||||||
var status = new OrderPullStatusEntity
|
var status = new OrderPullStatusEntity
|
||||||
|
|||||||
@ -68,7 +68,9 @@ public class TrackPullService : ApplicationServiceBase
|
|||||||
{
|
{
|
||||||
var data = new List<object>(group.Select(x => new TrackPullPayload
|
var data = new List<object>(group.Select(x => new TrackPullPayload
|
||||||
{
|
{
|
||||||
OrderNo = x.OrderNo
|
OrderNo = x.OrderNo,
|
||||||
|
TrackNo = x.TrackNo,
|
||||||
|
OtherNo = x.OtherNo,
|
||||||
}));
|
}));
|
||||||
var serviceProviderCode = group.Key.ServiceProviderCode;
|
var serviceProviderCode = group.Key.ServiceProviderCode;
|
||||||
var attach = Base64Helper.SerializeObject(new TrackRefreshAttach(group.Key.ServiceProviderCode,
|
var attach = Base64Helper.SerializeObject(new TrackRefreshAttach(group.Key.ServiceProviderCode,
|
||||||
|
|||||||
@ -106,7 +106,9 @@ public class TrackPullTask(
|
|||||||
{
|
{
|
||||||
var data = new List<object>(group.Select(x => new TrackPullPayload
|
var data = new List<object>(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,
|
var attach = Base64Helper.SerializeObject(new TrackRefreshAttach(config.ServiceProviderCode,
|
||||||
config.AppKey, group.Key));
|
config.AppKey, group.Key));
|
||||||
|
|||||||
@ -2,8 +2,21 @@ namespace TrackCenter.Domain.Dtos.Order;
|
|||||||
|
|
||||||
public class OrderWithServiceProviderVO
|
public class OrderWithServiceProviderVO
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 按拉取优先级配置解析后的主单号(可能是客户单号/跟踪号/其他单号)
|
||||||
|
/// </summary>
|
||||||
public string OrderNo { get; set; } = null!;
|
public string OrderNo { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 尾程单号 / 跟踪号
|
||||||
|
/// </summary>
|
||||||
|
public string? TrackNo { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 其他单号
|
||||||
|
/// </summary>
|
||||||
|
public string? OtherNo { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 订单类型
|
/// 订单类型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -254,11 +254,34 @@ public class OrderRepository : BasicRepository<OrderEntity>, IOrderRepository, I
|
|||||||
{
|
{
|
||||||
using var tran = TransactionHelper.GetReadCommitted();
|
using var tran = TransactionHelper.GetReadCommitted();
|
||||||
|
|
||||||
// 更新订单主表
|
// 注意:UpdateAsync(entity, cols) 的 cols 是 IgnoreColumns;
|
||||||
await UpdateAsync(order, x => new
|
// 指定要更新的列必须用 UpdateColumnAsync。
|
||||||
|
await UpdateColumnAsync(order, x => new
|
||||||
{
|
{
|
||||||
x.Customer,
|
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,
|
||||||
});
|
});
|
||||||
|
|
||||||
// 更新订单拉取状态
|
// 更新订单拉取状态
|
||||||
@ -280,11 +303,33 @@ public class OrderRepository : BasicRepository<OrderEntity>, IOrderRepository, I
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// 更新订单主表
|
// 更新订单主表(与 UpdateOrderAsync 字段对齐)
|
||||||
await UpdateRangeAsync(orders, x => new
|
await UpdateRangeAsync(orders, x => new
|
||||||
{
|
{
|
||||||
x.Customer,
|
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();
|
var orderIds = orders.Select(x => x.Id).ToHashSet();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user