Добавлен новый метод с правильно сериализацией
All checks were successful
Unit tests / test (push) Successful in 50s

This commit is contained in:
Alex Shibalkin 2025-01-16 15:57:53 +05:00
parent 3d6eb1a28c
commit e50bd64be1
2 changed files with 47 additions and 7 deletions

View File

@ -24,12 +24,21 @@ public interface ISetpointClient : IDisposable
/// <returns></returns>
Task<IEnumerable<SetpointValueDto>> GetCurrent(IEnumerable<Guid> setpointKeys, CancellationToken token);
/// <summary>
/// Получить диапазон дат, для которых есть данные в репозитории
/// </summary>
/// <param name="token"></param>
/// <returns></returns>
Task<DatesRangeDto> GetDatesRangeAsync(CancellationToken token);
/// <summary>
/// Получить актуальные значения уставок
/// </summary>
/// <param name="setpointConfigs"></param>
/// <param name="token"></param>
/// <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>
/// Получить значения уставок за определенный момент времени

View File

@ -3,6 +3,7 @@ using DD.Persistence.Client.Clients.Base;
using DD.Persistence.Client.Clients.Interfaces;
using DD.Persistence.Client.Clients.Interfaces.Refit;
using DD.Persistence.Models;
using System.Text.Json;
namespace DD.Persistence.Client.Clients;
@ -23,7 +24,35 @@ public class SetpointClient : BaseClient, ISetpointClient
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(
async () => await refitSetpointClient.GetHistory(setpointKeys, historyMoment, token), token);
@ -67,4 +96,6 @@ public class SetpointClient : BaseClient, ISetpointClient
GC.SuppressFinalize(this);
}
}