Добавлен новый метод с правильно сериализацией
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,6 +24,15 @@ public interface ISetpointClient : IDisposable
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<SetpointValueDto>> GetCurrent(IEnumerable<Guid> setpointKeys, 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>
|
||||
|
@ -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,6 +24,34 @@ public class SetpointClient : BaseClient, ISetpointClient
|
||||
return result!;
|
||||
}
|
||||
|
||||
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(
|
||||
@ -67,4 +96,6 @@ public class SetpointClient : BaseClient, ISetpointClient
|
||||
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user