feat: 新增大包轨迹同步下发 apiCode
All checks were successful
Build and Deploy / deploy (push) Successful in 58s
All checks were successful
Build and Deploy / deploy (push) Successful in 58s
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
8226542ffd
commit
3bde909238
@ -1,5 +1,7 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Oms.Application.Integrations.Itfx;
|
||||
using Oms.Domain.ChannelsAggregate.Entities;
|
||||
using Oms.Domain.ChannelsAggregate.Repositories;
|
||||
using Oms.Domain.OrdersAggregate.Consts;
|
||||
using Oms.Domain.OrdersAggregate.Entities;
|
||||
@ -45,6 +47,8 @@ internal sealed class PickupBigBagTrackSyncer(
|
||||
IPickupOrderLineRepository pickupOrderLineRepository,
|
||||
ISalesProductRepository salesProductRepository,
|
||||
IServiceChannelRepository serviceChannelRepository,
|
||||
IServiceChannelGroupRepository serviceChannelGroupRepository,
|
||||
IItfxMetadataClient itfxMetadataClient,
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
ILogger<PickupBigBagTrackSyncer> logger) : IPickupBigBagTrackSyncer
|
||||
{
|
||||
@ -83,7 +87,7 @@ internal sealed class PickupBigBagTrackSyncer(
|
||||
|
||||
try
|
||||
{
|
||||
var (channel, product) = await ResolveChannelProductAsync(pickup.CarrierService, cancellationToken);
|
||||
var (channel, product, apiCode) = await ResolveChannelProductAsync(pickup.CarrierService, cancellationToken);
|
||||
var country = ResolveCountry(pickup);
|
||||
|
||||
// 1) UpsertBigBag:client 取 product(销售产品编码)
|
||||
@ -96,6 +100,7 @@ internal sealed class PickupBigBagTrackSyncer(
|
||||
Channel = channel,
|
||||
Product = product,
|
||||
Country = country,
|
||||
ApiCode = apiCode,
|
||||
Authorization = authorization
|
||||
},
|
||||
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,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var salesProductCode = carrierService?.Trim();
|
||||
if (string.IsNullOrWhiteSpace(salesProductCode))
|
||||
{
|
||||
return (null, null);
|
||||
return (null, null, null);
|
||||
}
|
||||
|
||||
var product = await salesProductRepository.GetByProductCodeAsync(salesProductCode, cancellationToken);
|
||||
if (product == null)
|
||||
{
|
||||
return (null, salesProductCode);
|
||||
return (null, salesProductCode, null);
|
||||
}
|
||||
|
||||
var providers = await salesProductRepository.GetAllocationProvidersAsync(product.Id, cancellationToken);
|
||||
@ -239,14 +244,42 @@ internal sealed class PickupBigBagTrackSyncer(
|
||||
.FirstOrDefault();
|
||||
if (channelId <= 0)
|
||||
{
|
||||
return (null, product.ProductCode);
|
||||
return (null, product.ProductCode, null);
|
||||
}
|
||||
|
||||
var channel = await serviceChannelRepository.FirstOrDefaultAsync(x => x.Id == channelId, cancellationToken);
|
||||
var channelCode = channel?.ChannelCode?.Trim();
|
||||
var apiCode = channel == null
|
||||
? null
|
||||
: await ResolveApiCodeFromServiceChannelAsync(channel, cancellationToken);
|
||||
return (
|
||||
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)
|
||||
|
||||
@ -260,7 +260,8 @@ internal sealed class SmallBagTrackOrderClient(
|
||||
OtherNo = request.OtherNo?.Trim() ?? string.Empty,
|
||||
Channel = request.Channel?.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 authorization = ResolveAuthorization(request.Authorization);
|
||||
|
||||
@ -17,6 +17,8 @@ internal sealed class SmallBagTrackUpsertBigBagApiRequest
|
||||
|
||||
public string Country { get; set; } = string.Empty;
|
||||
|
||||
public string ApiCode { get; set; } = string.Empty;
|
||||
|
||||
public static string BuildEndpointUrl(string baseUrl) =>
|
||||
$"{baseUrl.Trim().TrimEnd('/')}/ProviderService/Order/UpsertBigBag";
|
||||
}
|
||||
|
||||
@ -17,5 +17,10 @@ public class SmallBagTrackUpsertBigBagRequest
|
||||
|
||||
public string? Country { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// API 服务商 code(轨迹拉取配置 ServiceProviderCode)。
|
||||
/// </summary>
|
||||
public string? ApiCode { get; set; }
|
||||
|
||||
public string? Authorization { get; set; }
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user