From e50bd64be186886aaed515f7888a49803923a234 Mon Sep 17 00:00:00 2001 From: Alex Shibalkin Date: Thu, 16 Jan 2025 15:57:53 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BD=D0=BE=D0=B2=D1=8B=D0=B9=20=D0=BC=D0=B5=D1=82?= =?UTF-8?q?=D0=BE=D0=B4=20=D1=81=20=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D0=BE=20=D1=81=D0=B5=D1=80=D0=B8=D0=B0=D0=BB=D0=B8?= =?UTF-8?q?=D0=B7=D0=B0=D1=86=D0=B8=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Clients/Interfaces/ISetpointClient.cs | 21 ++++++++---- .../Clients/SetpointClient.cs | 33 ++++++++++++++++++- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/DD.Persistence.Client/Clients/Interfaces/ISetpointClient.cs b/DD.Persistence.Client/Clients/Interfaces/ISetpointClient.cs index 86462ea..36ede35 100644 --- a/DD.Persistence.Client/Clients/Interfaces/ISetpointClient.cs +++ b/DD.Persistence.Client/Clients/Interfaces/ISetpointClient.cs @@ -24,12 +24,21 @@ public interface ISetpointClient : IDisposable /// Task> GetCurrent(IEnumerable setpointKeys, CancellationToken token); - /// - /// Получить диапазон дат, для которых есть данные в репозитории - /// - /// - /// - Task GetDatesRangeAsync(CancellationToken token); + /// + /// Получить актуальные значения уставок + /// + /// + /// + /// + Task> GetCurrentDictionary(Dictionary setpointConfigs, CancellationToken token); + + + /// + /// Получить диапазон дат, для которых есть данные в репозитории + /// + /// + /// + Task GetDatesRangeAsync(CancellationToken token); /// /// Получить значения уставок за определенный момент времени diff --git a/DD.Persistence.Client/Clients/SetpointClient.cs b/DD.Persistence.Client/Clients/SetpointClient.cs index 808f0b9..b9c472a 100644 --- a/DD.Persistence.Client/Clients/SetpointClient.cs +++ b/DD.Persistence.Client/Clients/SetpointClient.cs @@ -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> GetHistory(IEnumerable setpointKeys, DateTimeOffset historyMoment, CancellationToken token) + public async Task> GetCurrentDictionary(Dictionary setpointConfigs, CancellationToken token) + { + var data = await GetCurrent(setpointConfigs.Keys, token); + var dict = DeserializeResultToDict(setpointConfigs, data); + + return dict; + } + + private static Dictionary DeserializeResultToDict(Dictionary setpointConfigs, IEnumerable data) + { + var dict = new Dictionary(); + + 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> GetHistory(IEnumerable 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); } + + }