Добавлен новый метод с правильно сериализацией
All checks were successful
Unit tests / test (push) Successful in 50s
All checks were successful
Unit tests / test (push) Successful in 50s
This commit is contained in:
parent
3d6eb1a28c
commit
e50bd64be1
@ -24,12 +24,21 @@ public interface ISetpointClient : IDisposable
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<SetpointValueDto>> GetCurrent(IEnumerable<Guid> setpointKeys, CancellationToken token);
|
Task<IEnumerable<SetpointValueDto>> GetCurrent(IEnumerable<Guid> setpointKeys, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить диапазон дат, для которых есть данные в репозитории
|
/// Получить актуальные значения уставок
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="token"></param>
|
/// <param name="setpointConfigs"></param>
|
||||||
/// <returns></returns>
|
/// <param name="token"></param>
|
||||||
Task<DatesRangeDto> GetDatesRangeAsync(CancellationToken token);
|
/// <returns></returns>
|
||||||
|
Task<Dictionary<Guid, object?>> GetCurrentDictionary(Dictionary<Guid, Type> setpointConfigs, CancellationToken token);
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получить диапазон дат, для которых есть данные в репозитории
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<DatesRangeDto> GetDatesRangeAsync(CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить значения уставок за определенный момент времени
|
/// Получить значения уставок за определенный момент времени
|
||||||
|
@ -3,6 +3,7 @@ using DD.Persistence.Client.Clients.Base;
|
|||||||
using DD.Persistence.Client.Clients.Interfaces;
|
using DD.Persistence.Client.Clients.Interfaces;
|
||||||
using DD.Persistence.Client.Clients.Interfaces.Refit;
|
using DD.Persistence.Client.Clients.Interfaces.Refit;
|
||||||
using DD.Persistence.Models;
|
using DD.Persistence.Models;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace DD.Persistence.Client.Clients;
|
namespace DD.Persistence.Client.Clients;
|
||||||
|
|
||||||
@ -23,7 +24,35 @@ public class SetpointClient : BaseClient, ISetpointClient
|
|||||||
return result!;
|
return result!;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<SetpointValueDto>> GetHistory(IEnumerable<Guid> setpointKeys, DateTimeOffset historyMoment, CancellationToken token)
|
public async Task<Dictionary<Guid, object?>> GetCurrentDictionary(Dictionary<Guid, Type> setpointConfigs, CancellationToken token)
|
||||||
|
{
|
||||||
|
var data = await GetCurrent(setpointConfigs.Keys, token);
|
||||||
|
var dict = DeserializeResultToDict(setpointConfigs, data);
|
||||||
|
|
||||||
|
return dict;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Dictionary<Guid, object?> DeserializeResultToDict(Dictionary<Guid, Type> setpointConfigs, IEnumerable<SetpointValueDto> data)
|
||||||
|
{
|
||||||
|
var dict = new Dictionary<Guid, object?>();
|
||||||
|
|
||||||
|
foreach (var valueDto in data)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (valueDto.Value is not null &&
|
||||||
|
valueDto.Value is JsonElement element &&
|
||||||
|
setpointConfigs.TryGetValue(valueDto.Key, out var type) &&
|
||||||
|
type is not null)
|
||||||
|
|
||||||
|
dict[valueDto.Key] = element.Deserialize(type!) ?? valueDto.Value;
|
||||||
|
else
|
||||||
|
dict[valueDto.Key] = valueDto.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return dict;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<SetpointValueDto>> GetHistory(IEnumerable<Guid> setpointKeys, DateTimeOffset historyMoment, CancellationToken token)
|
||||||
{
|
{
|
||||||
var result = await ExecuteGetResponse(
|
var result = await ExecuteGetResponse(
|
||||||
async () => await refitSetpointClient.GetHistory(setpointKeys, historyMoment, token), token);
|
async () => await refitSetpointClient.GetHistory(setpointKeys, historyMoment, token), token);
|
||||||
@ -67,4 +96,6 @@ public class SetpointClient : BaseClient, ISetpointClient
|
|||||||
|
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user