From c3735eec93741d1038429b92e1e13417eebf6b29 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Wed, 7 Jun 2023 13:48:40 +0500 Subject: [PATCH] =?UTF-8?q?GtrWitsController.PostDataAsync=20=D1=82=D0=B5?= =?UTF-8?q?=D0=BF=D0=B5=D1=80=D1=8C=20=D0=BC=D0=BE=D0=B6=D0=B5=D1=82=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B0=D1=82=D1=8C=20=D0=B8=20?= =?UTF-8?q?=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D1=8F=D1=82=D1=8C=20=D0=BD?= =?UTF-8?q?=D0=B5=D1=81=D0=BA=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=BF=D0=B8=D1=81=D0=B5=D0=B9=20=D0=B7=D0=B0=20=D0=BE=D0=B4?= =?UTF-8?q?=D0=B8=D0=BD=20=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Repositories/IGtrRepository.cs | 4 +-- .../Repository/GtrWitsRepository.cs | 36 ++++++++++--------- .../Controllers/SAUB/GtrWitsController.cs | 10 +++--- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/AsbCloudApp/Repositories/IGtrRepository.cs b/AsbCloudApp/Repositories/IGtrRepository.cs index a8c16354..7aad6629 100644 --- a/AsbCloudApp/Repositories/IGtrRepository.cs +++ b/AsbCloudApp/Repositories/IGtrRepository.cs @@ -15,10 +15,10 @@ namespace AsbCloudApp.Repositories /// добавить данные (для панели бурильщика) /// /// - /// + /// /// /// - Task SaveDataAsync(int idTelemetry, WitsRecordDto dto, CancellationToken token); + Task SaveDataAsync(int idTelemetry, IEnumerable dtos, CancellationToken token); /// /// получить данные для клиента diff --git a/AsbCloudInfrastructure/Repository/GtrWitsRepository.cs b/AsbCloudInfrastructure/Repository/GtrWitsRepository.cs index 8e2b77b5..a0af9bf7 100644 --- a/AsbCloudInfrastructure/Repository/GtrWitsRepository.cs +++ b/AsbCloudInfrastructure/Repository/GtrWitsRepository.cs @@ -183,26 +183,30 @@ namespace AsbCloudInfrastructure.Repository return query; } - public async Task SaveDataAsync(int idTelemetry, WitsRecordDto dto, CancellationToken token) + public async Task SaveDataAsync(int idTelemetry, IEnumerable dtos, CancellationToken token) { var timezoneHours = telemetryService.GetTimezone(idTelemetry).Hours; - foreach (var item in dto.Items) + + foreach (var dto in dtos) { - var dateTime = dto.Date.ToUtcDateTimeOffset(timezoneHours); - if (item.Value.Value is string valueString) + foreach (var item in dto.Items) { - var entity = MakeEntity(dto.Id, item.Key, idTelemetry, dateTime, valueString); - db.WitsItemString.Add(entity); - } - if (item.Value.Value is float valueFloat) - { - var entity = MakeEntity(dto.Id, item.Key, idTelemetry, dateTime, valueFloat); - db.WitsItemFloat.Add(entity); - } - if (item.Value.Value is int valueInt) - { - var entity = MakeEntity(dto.Id, item.Key, idTelemetry, dateTime, valueInt); - db.WitsItemInt.Add(entity); + var dateTime = dto.Date.ToUtcDateTimeOffset(timezoneHours); + if (item.Value.Value is string valueString) + { + var entity = MakeEntity(dto.Id, item.Key, idTelemetry, dateTime, valueString); + db.WitsItemString.Add(entity); + } + if (item.Value.Value is float valueFloat) + { + var entity = MakeEntity(dto.Id, item.Key, idTelemetry, dateTime, valueFloat); + db.WitsItemFloat.Add(entity); + } + if (item.Value.Value is int valueInt) + { + var entity = MakeEntity(dto.Id, item.Key, idTelemetry, dateTime, valueInt); + db.WitsItemInt.Add(entity); + } } } await db.SaveChangesAsync(token); diff --git a/AsbCloudWebApi/Controllers/SAUB/GtrWitsController.cs b/AsbCloudWebApi/Controllers/SAUB/GtrWitsController.cs index 981ff1e7..547b53c0 100644 --- a/AsbCloudWebApi/Controllers/SAUB/GtrWitsController.cs +++ b/AsbCloudWebApi/Controllers/SAUB/GtrWitsController.cs @@ -100,21 +100,21 @@ namespace AsbCloudWebApi.Controllers.SAUB /// Сохраняет в БД. /// /// уникальный идентификатор телеметрии - /// WITS запись + /// WITS запись /// /// [HttpPost("{uid}")] public async Task PostDataAsync( string uid, - [FromBody] WitsRecordDto dto, + [FromBody] IEnumerable dtos, CancellationToken token = default) { var idTelemetry = telemetryService.GetOrCreateTelemetryIdByUid(uid); - await gtrRepository.SaveDataAsync(idTelemetry, dto, token).ConfigureAwait(false); + await gtrRepository.SaveDataAsync(idTelemetry, dtos, token).ConfigureAwait(false); var idWell = telemetryService.GetIdWellByTelemetryUid(uid); - if (idWell is not null && dto is not null) + if (idWell is not null && dtos is not null) _ = Task.Run(() => telemetryHubContext.Clients.Group($"well_{idWell}_gtr") - .SendAsync(SignalRMethodGetDataName, dto), CancellationToken.None); + .SendAsync(SignalRMethodGetDataName, dtos), CancellationToken.None); return Ok(); } }