From 27ee40816f9b9d21f9ed858f9d1515459e3d73d8 Mon Sep 17 00:00:00 2001 From: eugeniy_ivanov Date: Tue, 11 Apr 2023 12:06:05 +0500 Subject: [PATCH] refact save method --- .../Repository/GtrWitsRepository.cs | 82 +++++++++---------- .../Controllers/GTR/GtrWitsController.cs | 20 ++++- 2 files changed, 59 insertions(+), 43 deletions(-) diff --git a/AsbCloudInfrastructure/Repository/GtrWitsRepository.cs b/AsbCloudInfrastructure/Repository/GtrWitsRepository.cs index 936f2462..95799a8f 100644 --- a/AsbCloudInfrastructure/Repository/GtrWitsRepository.cs +++ b/AsbCloudInfrastructure/Repository/GtrWitsRepository.cs @@ -158,17 +158,17 @@ namespace AsbCloudInfrastructure.Repository { var jsonValue = item.Value; var type = jsonValue.Value.GetType().Name; - if (type == "string") + if (type == "String") { var entity = GetEntityStr(dto, jsonValue, item.Key, timezoneHours); db.WitsItemString.Add(entity); } - else if (type == "int") + else if (type == "Int32") { var entity = GetEntityInt(dto, jsonValue, item.Key, timezoneHours); db.WitsItemInt.Add(entity); } - else if (type == "float") + else if (type == "Single") { var entity = GetEntityFloat(dto, jsonValue, item.Key, timezoneHours); db.WitsItemFloat.Add(entity); @@ -182,21 +182,21 @@ namespace AsbCloudInfrastructure.Repository DateTimeOffset dateEnd, bool filterByDateEnd, int approxPointsCount , CancellationToken token) { - if (filterByDateEnd) - query = query.Where(d => d.DateTime <= dateEnd); + //if (filterByDateEnd) + // query = query.Where(d => d.DateTime <= dateEnd); - var fullDataCount = await query.CountAsync(token) - .ConfigureAwait(false); + //var fullDataCount = await query.CountAsync(token) + // .ConfigureAwait(false); - if (fullDataCount == 0) - return Enumerable.Empty(); + //if (fullDataCount == 0) + // return Enumerable.Empty(); - if (fullDataCount > 1.75 * approxPointsCount) - { - var m = (int)Math.Round(1d * fullDataCount / approxPointsCount); - if (m > 1) - query = query.Where((d) => (((d.DateTime.DayOfYear * 24 + d.DateTime.Hour) * 60 + d.DateTime.Minute) * 60 + d.DateTime.Second) % m == 0); - } + //if (fullDataCount > 1.75 * approxPointsCount) + //{ + // var m = (int)Math.Round(1d * fullDataCount / approxPointsCount); + // if (m > 1) + // query = query.Where((d) => (((d.DateTime.DayOfYear * 24 + d.DateTime.Hour) * 60 + d.DateTime.Minute) * 60 + d.DateTime.Second) % m == 0); + //} var entities = await query .OrderBy(d => d.DateTime) @@ -210,21 +210,21 @@ namespace AsbCloudInfrastructure.Repository DateTimeOffset dateEnd, bool filterByDateEnd, int approxPointsCount , CancellationToken token) { - if (filterByDateEnd) - query = query.Where(d => d.DateTime <= dateEnd); + //if (filterByDateEnd) + // query = query.Where(d => d.DateTime <= dateEnd); - var fullDataCount = await query.CountAsync(token) - .ConfigureAwait(false); + //var fullDataCount = await query.CountAsync(token) + // .ConfigureAwait(false); - if (fullDataCount == 0) - return Enumerable.Empty(); + //if (fullDataCount == 0) + // return Enumerable.Empty(); - if (fullDataCount > 1.75 * approxPointsCount) - { - var m = (int)Math.Round(1d * fullDataCount / approxPointsCount); - if (m > 1) - query = query.Where((d) => (((d.DateTime.DayOfYear * 24 + d.DateTime.Hour) * 60 + d.DateTime.Minute) * 60 + d.DateTime.Second) % m == 0); - } + //if (fullDataCount > 1.75 * approxPointsCount) + //{ + // var m = (int)Math.Round(1d * fullDataCount / approxPointsCount); + // if (m > 1) + // query = query.Where((d) => (((d.DateTime.DayOfYear * 24 + d.DateTime.Hour) * 60 + d.DateTime.Minute) * 60 + d.DateTime.Second) % m == 0); + //} var entities = await query .OrderBy(d => d.DateTime) @@ -238,21 +238,21 @@ namespace AsbCloudInfrastructure.Repository DateTimeOffset dateEnd, bool filterByDateEnd, int approxPointsCount , CancellationToken token) { - if (filterByDateEnd) - query = query.Where(d => d.DateTime <= dateEnd); + //if (filterByDateEnd) + // query = query.Where(d => d.DateTime <= dateEnd); - var fullDataCount = await query.CountAsync(token) - .ConfigureAwait(false); + //var fullDataCount = await query.CountAsync(token) + // .ConfigureAwait(false); - if (fullDataCount == 0) - return Enumerable.Empty(); + //if (fullDataCount == 0) + // return Enumerable.Empty(); - if (fullDataCount > 1.75 * approxPointsCount) - { - var m = (int)Math.Round(1d * fullDataCount / approxPointsCount); - if (m > 1) - query = query.Where((d) => (((d.DateTime.DayOfYear * 24 + d.DateTime.Hour) * 60 + d.DateTime.Minute) * 60 + d.DateTime.Second) % m == 0); - } + //if (fullDataCount > 1.75 * approxPointsCount) + //{ + // var m = (int)Math.Round(1d * fullDataCount / approxPointsCount); + // if (m > 1) + // query = query.Where((d) => (((d.DateTime.DayOfYear * 24 + d.DateTime.Hour) * 60 + d.DateTime.Minute) * 60 + d.DateTime.Second) % m == 0); + //} var entities = await query .OrderBy(d => d.DateTime) @@ -270,7 +270,7 @@ namespace AsbCloudInfrastructure.Repository DateTime = record.Date.ToUtcDateTimeOffset(timezoneHours), IdRecord = record.Id, IdItem = idItems, - Value = JsonSerializer.Deserialize(value.ToString())!, + Value = value.Value.ToString()!, }; return entity; } @@ -296,7 +296,7 @@ namespace AsbCloudInfrastructure.Repository DateTime = record.Date.ToUtcDateTimeOffset(timezoneHours), IdRecord = record.Id, IdItem = idItems, - Value = JsonSerializer.Deserialize(value.ToString())!, + Value = (float)value.Value, }; return entity; } diff --git a/AsbCloudWebApi/Controllers/GTR/GtrWitsController.cs b/AsbCloudWebApi/Controllers/GTR/GtrWitsController.cs index 023543b3..01af471e 100644 --- a/AsbCloudWebApi/Controllers/GTR/GtrWitsController.cs +++ b/AsbCloudWebApi/Controllers/GTR/GtrWitsController.cs @@ -38,8 +38,7 @@ namespace AsbCloudWebApi.Controllers.GTR } /// - /// Возвращает данные САУБ по скважине. - /// По умолчанию за последние 10 минут. + /// /// /// id скважины /// дата начала выборки.По умолчанию: текущее время - intervalSec @@ -68,5 +67,22 @@ namespace AsbCloudWebApi.Controllers.GTR return Ok(content); } + + [HttpPost("{uid}")] + public async Task PostDataAsync( + string uid, + [FromBody] WitsRecordDto dto, + [FromServices] IGtrRepository gtrRepository, + CancellationToken token = default) + { + var idTelemetry = telemetryService.GetOrCreateTelemetryIdByUid(uid); + await gtrRepository.SaveDataAsync(idTelemetry, dto, token).ConfigureAwait(false); + //var idWell = telemetryService.GetIdWellByTelemetryUid(uid); + //if (idWell != null && dtos.Any()) + // _ = Task.Run(() => telemetryHubContext.Clients.Group($"well_{idWell}_wits") + // .SendAsync(SirnalRMethodGetDataName, dtos), CancellationToken.None); + + return Ok(); + } } }