All checks were successful
Build and Deploy / deploy (push) Successful in 1m52s
将 itfx 网关优先读其他配置 api_center(含 AppKey/AppSecret 回退),面单预览经服务端代理拉取 COS。 Co-authored-by: Cursor <cursoragent@cursor.com>
58 lines
2.4 KiB
C#
58 lines
2.4 KiB
C#
using Fake.DependencyInjection;
|
||
using Microsoft.Extensions.Options;
|
||
using Oms.Domain.SystemAggregate.Consts;
|
||
using Oms.Domain.SystemAggregate.Repositories;
|
||
|
||
namespace Oms.Application.Integrations.Itfx;
|
||
|
||
/// <summary>
|
||
/// itfx / API 中心运行时配置(优先「其他配置」api_center,回退 appsettings Oms:Itfx)。
|
||
/// </summary>
|
||
public interface IItfxGatewayConfigProvider
|
||
{
|
||
Task<ItfxGatewayOptions> GetAsync(CancellationToken cancellationToken = default);
|
||
}
|
||
|
||
internal sealed class ItfxGatewayConfigProvider(
|
||
ISystemOtherConfigRepository repository,
|
||
IOptions<ItfxGatewayOptions> options) : IItfxGatewayConfigProvider, IScopedDependency
|
||
{
|
||
public async Task<ItfxGatewayOptions> GetAsync(CancellationToken cancellationToken = default)
|
||
{
|
||
var fallback = options.Value;
|
||
var entity = await repository.GetByConfigCodeAsync(SystemOtherConfigCodes.ApiCenter, cancellationToken);
|
||
if (entity == null || !entity.Enabled)
|
||
{
|
||
return Clone(fallback);
|
||
}
|
||
|
||
return new ItfxGatewayOptions
|
||
{
|
||
BaseUrl = Coalesce(entity.BaseUrl, fallback.BaseUrl),
|
||
AppKey = Coalesce(entity.AppKey, fallback.AppKey),
|
||
AppSecret = Coalesce(entity.AppSecret, fallback.AppSecret),
|
||
TimeoutSeconds = entity.TimeoutSeconds > 0 ? entity.TimeoutSeconds : fallback.TimeoutSeconds,
|
||
Customs9610StandardCode = fallback.Customs9610StandardCode,
|
||
Customs9610ManifestStandardCode = fallback.Customs9610ManifestStandardCode,
|
||
Customs9610DeclarationFormStandardCode = fallback.Customs9610DeclarationFormStandardCode,
|
||
Customs9610SupplierCode = fallback.Customs9610SupplierCode
|
||
};
|
||
}
|
||
|
||
private static ItfxGatewayOptions Clone(ItfxGatewayOptions src) =>
|
||
new()
|
||
{
|
||
BaseUrl = src.BaseUrl,
|
||
AppKey = src.AppKey,
|
||
AppSecret = src.AppSecret,
|
||
TimeoutSeconds = src.TimeoutSeconds,
|
||
Customs9610StandardCode = src.Customs9610StandardCode,
|
||
Customs9610ManifestStandardCode = src.Customs9610ManifestStandardCode,
|
||
Customs9610DeclarationFormStandardCode = src.Customs9610DeclarationFormStandardCode,
|
||
Customs9610SupplierCode = src.Customs9610SupplierCode
|
||
};
|
||
|
||
private static string Coalesce(string? primary, string fallback) =>
|
||
string.IsNullOrWhiteSpace(primary) ? fallback : primary.Trim();
|
||
}
|