feat: 新增大包轨迹同步下发 apiCode
All checks were successful
Build and Deploy / deploy (push) Successful in 58s

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
zzh 2026-09-28 16:58:00 +08:00
parent 8226542ffd
commit 3bde909238
4 changed files with 48 additions and 7 deletions

View File

@ -1,5 +1,7 @@
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Oms.Application.Integrations.Itfx;
using Oms.Domain.ChannelsAggregate.Entities;
using Oms.Domain.ChannelsAggregate.Repositories; using Oms.Domain.ChannelsAggregate.Repositories;
using Oms.Domain.OrdersAggregate.Consts; using Oms.Domain.OrdersAggregate.Consts;
using Oms.Domain.OrdersAggregate.Entities; using Oms.Domain.OrdersAggregate.Entities;
@ -45,6 +47,8 @@ internal sealed class PickupBigBagTrackSyncer(
IPickupOrderLineRepository pickupOrderLineRepository, IPickupOrderLineRepository pickupOrderLineRepository,
ISalesProductRepository salesProductRepository, ISalesProductRepository salesProductRepository,
IServiceChannelRepository serviceChannelRepository, IServiceChannelRepository serviceChannelRepository,
IServiceChannelGroupRepository serviceChannelGroupRepository,
IItfxMetadataClient itfxMetadataClient,
IHttpContextAccessor httpContextAccessor, IHttpContextAccessor httpContextAccessor,
ILogger<PickupBigBagTrackSyncer> logger) : IPickupBigBagTrackSyncer ILogger<PickupBigBagTrackSyncer> logger) : IPickupBigBagTrackSyncer
{ {
@ -83,7 +87,7 @@ internal sealed class PickupBigBagTrackSyncer(
try try
{ {
var (channel, product) = await ResolveChannelProductAsync(pickup.CarrierService, cancellationToken); var (channel, product, apiCode) = await ResolveChannelProductAsync(pickup.CarrierService, cancellationToken);
var country = ResolveCountry(pickup); var country = ResolveCountry(pickup);
// 1) UpsertBigBag:client 取 product(销售产品编码) // 1) UpsertBigBag:client 取 product(销售产品编码)
@ -96,6 +100,7 @@ internal sealed class PickupBigBagTrackSyncer(
Channel = channel, Channel = channel,
Product = product, Product = product,
Country = country, Country = country,
ApiCode = apiCode,
Authorization = authorization Authorization = authorization
}, },
cancellationToken); cancellationToken);
@ -215,20 +220,20 @@ internal sealed class PickupBigBagTrackSyncer(
} }
} }
private async Task<(string? Channel, string? Product)> ResolveChannelProductAsync( private async Task<(string? Channel, string? Product, string? ApiCode)> ResolveChannelProductAsync(
string? carrierService, string? carrierService,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
var salesProductCode = carrierService?.Trim(); var salesProductCode = carrierService?.Trim();
if (string.IsNullOrWhiteSpace(salesProductCode)) if (string.IsNullOrWhiteSpace(salesProductCode))
{ {
return (null, null); return (null, null, null);
} }
var product = await salesProductRepository.GetByProductCodeAsync(salesProductCode, cancellationToken); var product = await salesProductRepository.GetByProductCodeAsync(salesProductCode, cancellationToken);
if (product == null) if (product == null)
{ {
return (null, salesProductCode); return (null, salesProductCode, null);
} }
var providers = await salesProductRepository.GetAllocationProvidersAsync(product.Id, cancellationToken); var providers = await salesProductRepository.GetAllocationProvidersAsync(product.Id, cancellationToken);
@ -239,14 +244,42 @@ internal sealed class PickupBigBagTrackSyncer(
.FirstOrDefault(); .FirstOrDefault();
if (channelId <= 0) if (channelId <= 0)
{ {
return (null, product.ProductCode); return (null, product.ProductCode, null);
} }
var channel = await serviceChannelRepository.FirstOrDefaultAsync(x => x.Id == channelId, cancellationToken); var channel = await serviceChannelRepository.FirstOrDefaultAsync(x => x.Id == channelId, cancellationToken);
var channelCode = channel?.ChannelCode?.Trim(); var channelCode = channel?.ChannelCode?.Trim();
var apiCode = channel == null
? null
: await ResolveApiCodeFromServiceChannelAsync(channel, cancellationToken);
return ( return (
string.IsNullOrWhiteSpace(channelCode) ? null : channelCode, string.IsNullOrWhiteSpace(channelCode) ? null : channelCode,
product.ProductCode); product.ProductCode,
apiCode);
}
private async Task<string?> ResolveApiCodeFromServiceChannelAsync(
ServiceChannel channel,
CancellationToken cancellationToken)
{
if (!channel.GroupId.HasValue || channel.GroupId.Value <= 0)
{
return null;
}
var group = await serviceChannelGroupRepository.FirstOrDefaultAsync(
x => x.Id == channel.GroupId.Value,
cancellationToken);
if (group == null || group.ApiServiceProviderId <= 0)
{
return null;
}
var serviceProvider = await itfxMetadataClient.GetServiceProviderAsync(
group.ApiServiceProviderId,
cancellationToken);
var code = serviceProvider?.Code?.Trim();
return string.IsNullOrWhiteSpace(code) ? null : code;
} }
private static string ResolveCountry(PickupOrder pickup) private static string ResolveCountry(PickupOrder pickup)

View File

@ -260,7 +260,8 @@ internal sealed class SmallBagTrackOrderClient(
OtherNo = request.OtherNo?.Trim() ?? string.Empty, OtherNo = request.OtherNo?.Trim() ?? string.Empty,
Channel = request.Channel?.Trim() ?? string.Empty, Channel = request.Channel?.Trim() ?? string.Empty,
Product = request.Product?.Trim() ?? string.Empty, Product = request.Product?.Trim() ?? string.Empty,
Country = request.Country?.Trim() ?? string.Empty Country = request.Country?.Trim() ?? string.Empty,
ApiCode = request.ApiCode?.Trim() ?? string.Empty
}; };
var url = SmallBagTrackUpsertBigBagApiRequest.BuildEndpointUrl(settings.BaseUrl); var url = SmallBagTrackUpsertBigBagApiRequest.BuildEndpointUrl(settings.BaseUrl);
var authorization = ResolveAuthorization(request.Authorization); var authorization = ResolveAuthorization(request.Authorization);

View File

@ -17,6 +17,8 @@ internal sealed class SmallBagTrackUpsertBigBagApiRequest
public string Country { get; set; } = string.Empty; public string Country { get; set; } = string.Empty;
public string ApiCode { get; set; } = string.Empty;
public static string BuildEndpointUrl(string baseUrl) => public static string BuildEndpointUrl(string baseUrl) =>
$"{baseUrl.Trim().TrimEnd('/')}/ProviderService/Order/UpsertBigBag"; $"{baseUrl.Trim().TrimEnd('/')}/ProviderService/Order/UpsertBigBag";
} }

View File

@ -17,5 +17,10 @@ public class SmallBagTrackUpsertBigBagRequest
public string? Country { get; set; } public string? Country { get; set; }
/// <summary>
/// API 服务商 code(轨迹拉取配置 ServiceProviderCode)。
/// </summary>
public string? ApiCode { get; set; }
public string? Authorization { get; set; } public string? Authorization { get; set; }
} }