Fix method name
This commit is contained in:
parent
a44f450df6
commit
50543ae697
@ -152,9 +152,35 @@ public class RhSolutionsFunctions
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var article = skus.First().Id;
|
|
||||||
IDatabaseClient databaseClient = RhSolutionsAddIn.ServiceProvider.GetService<IDatabaseClient>();
|
IDatabaseClient databaseClient = RhSolutionsAddIn.ServiceProvider.GetService<IDatabaseClient>();
|
||||||
ICurrencyClient currencyClient = RhSolutionsAddIn.ServiceProvider.GetRequiredService<ICurrencyClient>();
|
ICurrencyClient currencyClient = RhSolutionsAddIn.ServiceProvider.GetRequiredService<ICurrencyClient>();
|
||||||
|
IMemoryCache memoryCache = RhSolutionsAddIn.ServiceProvider.GetRequiredService<IMemoryCache>();
|
||||||
|
var article = skus.First().Id;
|
||||||
|
DateTime date = dateField == 0 ? DateTime.Today : DateTime.FromOADate(dateField);
|
||||||
|
|
||||||
|
if (!memoryCache.TryGetValue(date, out decimal exchangeRate))
|
||||||
|
{
|
||||||
|
var result = ExcelAsyncUtil.Run(nameof(КУРСЕВРО), dateField, delegate
|
||||||
|
{
|
||||||
|
var requestResult = currencyClient.GetExchangeRate(date)
|
||||||
|
.GetAwaiter()
|
||||||
|
.GetResult();
|
||||||
|
|
||||||
|
return requestResult ?? -1m;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result is not decimal)
|
||||||
|
{
|
||||||
|
return "Загрузка...";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
exchangeRate = (decimal)result;
|
||||||
|
var cacheEntryOptions = new MemoryCacheEntryOptions()
|
||||||
|
.SetSlidingExpiration(TimeSpan.FromHours(1));
|
||||||
|
memoryCache.Set(date, exchangeRate, cacheEntryOptions);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (ExcelAsyncUtil.Run(nameof(РЕХАУЦЕНАРУБ), line, delegate
|
if (ExcelAsyncUtil.Run(nameof(РЕХАУЦЕНАРУБ), line, delegate
|
||||||
{
|
{
|
||||||
@ -163,11 +189,6 @@ public class RhSolutionsFunctions
|
|||||||
.GetResult()
|
.GetResult()
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
|
|
||||||
DateTime date = dateField == 0 ? DateTime.Today : DateTime.FromOADate(dateField);
|
|
||||||
var exchangeRate = currencyClient.GetCurrencyCourse(date)
|
|
||||||
.GetAwaiter()
|
|
||||||
.GetResult();
|
|
||||||
|
|
||||||
return product == null ? -1m :
|
return product == null ? -1m :
|
||||||
product.Price * exchangeRate * 1.2m;
|
product.Price * exchangeRate * 1.2m;
|
||||||
}) is not decimal requestResult)
|
}) is not decimal requestResult)
|
||||||
@ -199,7 +220,7 @@ public class RhSolutionsFunctions
|
|||||||
{
|
{
|
||||||
var result = ExcelAsyncUtil.Run(nameof(КУРСЕВРО), dateField, delegate
|
var result = ExcelAsyncUtil.Run(nameof(КУРСЕВРО), dateField, delegate
|
||||||
{
|
{
|
||||||
var requestResult = currencyClient.GetCurrencyCourse(date)
|
var requestResult = currencyClient.GetExchangeRate(date)
|
||||||
.GetAwaiter()
|
.GetAwaiter()
|
||||||
.GetResult();
|
.GetResult();
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ public class CurrencyClient : ICurrencyClient
|
|||||||
_httpClient = httpClient;
|
_httpClient = httpClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<decimal?> GetCurrencyCourse(DateTime date)
|
public async Task<decimal?> GetExchangeRate(DateTime date)
|
||||||
{
|
{
|
||||||
string request = $"{_requestAddress}{date.Date:dd/MM/yyyy}";
|
string request = $"{_requestAddress}{date.Date:dd/MM/yyyy}";
|
||||||
HttpResponseMessage response = await _httpClient.GetAsync(request);
|
HttpResponseMessage response = await _httpClient.GetAsync(request);
|
||||||
|
@ -5,5 +5,5 @@ namespace RhSolutions.Services;
|
|||||||
|
|
||||||
public interface ICurrencyClient
|
public interface ICurrencyClient
|
||||||
{
|
{
|
||||||
public Task<decimal?> GetCurrencyCourse(DateTime date);
|
public Task<decimal?> GetExchangeRate(DateTime date);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user