From e26c5d98a7d33058216427a310f9aa37ff452ffb Mon Sep 17 00:00:00 2001 From: eugeniy_ivanov Date: Fri, 7 Apr 2023 04:51:30 +0500 Subject: [PATCH] delete manual timescale script (error index) edit generic repository --- .../IGtrRepository.cs} | 4 +- ...dd_table_WITS_GTR_and_manual_hypertable.cs | 8 +-- AsbCloudInfrastructure/DependencyInjection.cs | 5 ++ .../Repository/GtrWitsRepository.cs | 16 ++--- .../Controllers/GTR/GtrWitsController.cs | 62 ++++++++++++++++++- 5 files changed, 80 insertions(+), 15 deletions(-) rename AsbCloudApp/{Services/WITS/IGtrService.cs => Repositories/IGtrRepository.cs} (96%) diff --git a/AsbCloudApp/Services/WITS/IGtrService.cs b/AsbCloudApp/Repositories/IGtrRepository.cs similarity index 96% rename from AsbCloudApp/Services/WITS/IGtrService.cs rename to AsbCloudApp/Repositories/IGtrRepository.cs index 012296b8..c9dc64ce 100644 --- a/AsbCloudApp/Services/WITS/IGtrService.cs +++ b/AsbCloudApp/Repositories/IGtrRepository.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -namespace AsbCloudApp.Services.WITS +namespace AsbCloudApp.Repositories { #nullable enable /// @@ -20,7 +20,7 @@ namespace AsbCloudApp.Services.WITS /// /// Task SaveDataAsync(int idTelemetry, WitsRecordDto dto, CancellationToken token); - + /// /// получить данные для клиента /// diff --git a/AsbCloudDb/Migrations/20230331060526_add_table_WITS_GTR_and_manual_hypertable.cs b/AsbCloudDb/Migrations/20230331060526_add_table_WITS_GTR_and_manual_hypertable.cs index 56a822f5..8376e95c 100644 --- a/AsbCloudDb/Migrations/20230331060526_add_table_WITS_GTR_and_manual_hypertable.cs +++ b/AsbCloudDb/Migrations/20230331060526_add_table_WITS_GTR_and_manual_hypertable.cs @@ -74,10 +74,10 @@ namespace AsbCloudDb.Migrations onDelete: ReferentialAction.Cascade); }, comment: "таблица данных ГТИ с типом значения string"); - migrationBuilder.Sql - ("SELECT create_hypertable('t_wits_string','time','id_telemetry',chunk_time_interval => INTERVAL '5 day'); " + - "SELECT create_hypertable('t_wits_float','time','id_telemetry',chunk_time_interval => INTERVAL '5 day'); " + - "SELECT create_hypertable('t_wits_int','time','id_telemetry',chunk_time_interval => INTERVAL '5 day'); "); + //migrationBuilder.Sql + // ("SELECT create_hypertable('t_wits_string','date','id_telemetry', 2, chunk_time_interval => INTERVAL '5 day'); " + + // "SELECT create_hypertable('t_wits_float','date','id_telemetry', 2, chunk_time_interval => INTERVAL '5 day'); " + + // "SELECT create_hypertable('t_wits_int','date','id_telemetry', 2, chunk_time_interval => INTERVAL '5 day'); "); } protected override void Down(MigrationBuilder migrationBuilder) diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs index f74de38e..e5bd349a 100644 --- a/AsbCloudInfrastructure/DependencyInjection.cs +++ b/AsbCloudInfrastructure/DependencyInjection.cs @@ -1,10 +1,12 @@ using AsbCloudApp.Data; +using AsbCloudApp.Data.GTR; using AsbCloudApp.Data.SAUB; using AsbCloudApp.Data.Subsystems; using AsbCloudApp.Repositories; using AsbCloudApp.Services; using AsbCloudApp.Services.Subsystems; using AsbCloudDb.Model; +using AsbCloudDb.Model.GTR; using AsbCloudDb.Model.Subsystems; using AsbCloudInfrastructure.Background; using AsbCloudInfrastructure.Repository; @@ -136,6 +138,9 @@ namespace AsbCloudInfrastructure services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient,int>>(); + services.AddTransient, float>>(); + services.AddTransient, string>>(); // admin crud services: services.AddTransient, CrudCacheRepositoryBase>(s => diff --git a/AsbCloudInfrastructure/Repository/GtrWitsRepository.cs b/AsbCloudInfrastructure/Repository/GtrWitsRepository.cs index d8f2b8be..0113f3d2 100644 --- a/AsbCloudInfrastructure/Repository/GtrWitsRepository.cs +++ b/AsbCloudInfrastructure/Repository/GtrWitsRepository.cs @@ -1,6 +1,6 @@ using AsbCloudApp.Data.GTR; +using AsbCloudApp.Repositories; using AsbCloudApp.Services; -using AsbCloudApp.Services.WITS; using AsbCloudDb.Model; using AsbCloudDb.Model.GTR; using Microsoft.EntityFrameworkCore; @@ -13,19 +13,19 @@ using System.Threading.Tasks; namespace AsbCloudInfrastructure.Repository { #nullable enable - public class GtrWitsRepository : IGtrRepository - where T : WitsItemBase + public class GtrWitsRepository : IGtrRepository + where TEntity : WitsItemBase { private readonly IAsbCloudDbContext db; private readonly ITelemetryService telemetryService; - private readonly DbSet dbset; + private readonly DbSet dbset; private static Random random = new Random((int)(DateTime.Now.Ticks % 0xFFFFFFFF)); public GtrWitsRepository( IAsbCloudDbContext db, ITelemetryService telemetryService) { - dbset = db.Set(); + dbset = db.Set(); this.db = db; this.telemetryService = telemetryService; } @@ -60,7 +60,7 @@ namespace AsbCloudInfrastructure.Repository // return cacheData; var dateEnd = dateBeginUtc.AddSeconds(intervalSec); - var dbSet = db.Set(); + var dbSet = db.Set(); var query = dbSet .Where(d => d.IdTelemetry == telemetry.Id @@ -120,7 +120,7 @@ namespace AsbCloudInfrastructure.Repository { if (!existingEntities.Any(e => e == entity.DateTime)) { - dbset.Add((T)entity); + dbset.Add((TEntity)entity); } else { @@ -134,7 +134,7 @@ namespace AsbCloudInfrastructure.Repository dt.Second, (dt.Millisecond + random.Next(1, 283)) % 1000, dt.Offset); - dbset.Add((T)entity); + dbset.Add((TEntity)entity); } } await db.SaveChangesAsync(token); diff --git a/AsbCloudWebApi/Controllers/GTR/GtrWitsController.cs b/AsbCloudWebApi/Controllers/GTR/GtrWitsController.cs index 5d6f69cc..f42f6950 100644 --- a/AsbCloudWebApi/Controllers/GTR/GtrWitsController.cs +++ b/AsbCloudWebApi/Controllers/GTR/GtrWitsController.cs @@ -1,5 +1,15 @@ -using Microsoft.AspNetCore.Http; +using AsbCloudApp.Data.GTR; +using AsbCloudApp.Repositories; +using AsbCloudApp.Services; +using AsbCloudDb.Model; +using AsbCloudWebApi.SignalR; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.SignalR; +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; namespace AsbCloudWebApi.Controllers.GTR { @@ -7,5 +17,55 @@ namespace AsbCloudWebApi.Controllers.GTR [ApiController] public class GtrWitsController : ControllerBase { + protected readonly IWellService wellService; + private readonly ITelemetryService telemetryService; + private readonly IGtrRepository gtrRepository; + private readonly IHubContext telemetryHubContext; + + //public string SirnalRMethodGetDataName { get; protected set; } = "ReceiveData"; + + public GtrWitsController( + ITelemetryService telemetryService, + IGtrRepository gtrRepository, + IWellService wellService, + IHubContext telemetryHubContext) + { + this.telemetryService = telemetryService; + this.gtrRepository = gtrRepository; + this.wellService = wellService; + this.telemetryHubContext = telemetryHubContext; + } + + /// + /// Возвращает данные САУБ по скважине. + /// По умолчанию за последние 10 минут. + /// + /// id скважины + /// дата начала выборки. По умолчанию: текущее время - intervalSec + /// интервал времени даты начала выборки, секунды + /// желаемое количество точек. Если в выборке точек будет больше, то выборка будет прорежена. + /// Токен завершения задачи + /// + [HttpGet("{idWell}")] + //[Permission] + public virtual async Task>> GetDataAsync(int idWell, DateTime begin = default, + int intervalSec = 600, int approxPointsCount = 1024, CancellationToken token = default) + { + //int? idCompany = User.GetCompanyId(); + + //if (idCompany is null) + // return Forbid(); + + //bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + // idWell, token).ConfigureAwait(false); + + //if (!isCompanyOwnsWell) + // return Forbid(); + + var content = await gtrRepository.GetAsync(idWell, begin, + intervalSec, approxPointsCount, token).ConfigureAwait(false); + + return Ok(content); + } } }