- GetNavHistoryAsync现在会自动检查是否有历史数据 - 无历史数据时自动调用BackfillNavHistoryInternalAsync - 拆分内部回填方法,避免重复验证权限
58 lines
1.7 KiB
C#
Executable File
58 lines
1.7 KiB
C#
Executable File
using Microsoft.Extensions.Logging;
|
||
|
||
namespace AssetManager.Infrastructure.Services;
|
||
|
||
/// <summary>
|
||
/// Mock 汇率服务(占位实现,后续接入真实汇率源)
|
||
/// </summary>
|
||
public class MockExchangeRateService : IExchangeRateService
|
||
{
|
||
private readonly ILogger<MockExchangeRateService> _logger;
|
||
|
||
// 固定的 Mock 汇率(以 2026 年初为基准)
|
||
private readonly Dictionary<string, decimal> _mockRates = new()
|
||
{
|
||
{ "CNY-USD", 0.14m },
|
||
{ "USD-CNY", 7.10m },
|
||
{ "CNY-HKD", 1.09m },
|
||
{ "HKD-CNY", 0.92m },
|
||
{ "USD-HKD", 7.75m },
|
||
{ "HKD-USD", 0.13m },
|
||
{ "CNY-CNY", 1.00m },
|
||
{ "USD-USD", 1.00m },
|
||
{ "HKD-HKD", 1.00m }
|
||
};
|
||
|
||
public MockExchangeRateService(ILogger<MockExchangeRateService> logger)
|
||
{
|
||
_logger = logger;
|
||
}
|
||
|
||
public Task<decimal> GetExchangeRateAsync(string fromCurrency, string toCurrency)
|
||
{
|
||
_logger.LogInformation("Mock 获取汇率: {FromCurrency} -> {ToCurrency}", fromCurrency, toCurrency);
|
||
|
||
string key = $"{fromCurrency}-{toCurrency}";
|
||
if (_mockRates.TryGetValue(key, out decimal rate))
|
||
{
|
||
return Task.FromResult(rate);
|
||
}
|
||
|
||
// 默认返回 1(同币种或不支持的币种)
|
||
return Task.FromResult(1.00m);
|
||
}
|
||
|
||
public Task<decimal> ConvertAmountAsync(decimal amount, string fromCurrency, string toCurrency)
|
||
{
|
||
_logger.LogInformation("Mock 转换金额: {Amount} {FromCurrency} -> {ToCurrency}", amount, fromCurrency, toCurrency);
|
||
|
||
if (fromCurrency == toCurrency)
|
||
{
|
||
return Task.FromResult(amount);
|
||
}
|
||
|
||
return GetExchangeRateAsync(fromCurrency, toCurrency)
|
||
.ContinueWith(t => amount * t.Result);
|
||
}
|
||
}
|