From 6c516e983ea3874869d7c2081ed50f6fc3f9a7e1 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Wed, 17 Jul 2024 15:49:53 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=87=D0=B0=D1=81=D1=82=D0=B8=20=D1=82=D0=B5=D0=BB?= =?UTF-8?q?=D0=B5=D0=BC=D0=B5=D1=82=D1=80=D0=B8=D0=B8=20=D0=BF=D0=BE=20?= =?UTF-8?q?=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82=D1=80=D0=B0=D0=BC:?= =?UTF-8?q?=20=D0=BA=D0=BB=D1=8E=D1=87=20=D1=82=D0=B5=D0=BB=D0=B5=D0=BC?= =?UTF-8?q?=D0=B5=D1=82=D1=80=D0=B8=D0=B8=20=D0=B8=20=D0=B8=D0=BD=D1=82?= =?UTF-8?q?=D0=B5=D1=80=D0=B2=D0=B0=D0=BB=20=D0=B4=D0=B0=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ILimitingParameterRepository.cs | 13 ++++++++++++ AsbCloudApp/Services/ITelemetryService.cs | 10 ++++++++++ .../Repository/LimitingParameterRepository.cs | 17 +++++++++++++++- .../Services/SAUB/TelemetryService.cs | 14 ++++++++++++- .../Controllers/AdminTelemetryController.cs | 20 +++++++++++++++++++ 5 files changed, 72 insertions(+), 2 deletions(-) diff --git a/AsbCloudApp/Repositories/ILimitingParameterRepository.cs b/AsbCloudApp/Repositories/ILimitingParameterRepository.cs index 63706248..02395d34 100644 --- a/AsbCloudApp/Repositories/ILimitingParameterRepository.cs +++ b/AsbCloudApp/Repositories/ILimitingParameterRepository.cs @@ -3,6 +3,7 @@ using AsbCloudApp.Requests; using System.Collections.Generic; using System.Threading.Tasks; using System.Threading; +using System; namespace AsbCloudApp.Repositories { @@ -29,5 +30,17 @@ namespace AsbCloudApp.Repositories /// /// Task> GetLimitingParametersAsync(LimitingParameterRequest request, int idTelemetry, double timezoneHours, CancellationToken token); + + /// + /// Удаление ограничивающих параметров по ключу телеметрии и интервалу дат + /// + /// + /// + /// + /// + /// + Task DeleteAsync(int telemetryId, DateTimeOffset? gDate, DateTimeOffset? lDate, CancellationToken token); + + } } diff --git a/AsbCloudApp/Services/ITelemetryService.cs b/AsbCloudApp/Services/ITelemetryService.cs index 49b28388..54b56226 100644 --- a/AsbCloudApp/Services/ITelemetryService.cs +++ b/AsbCloudApp/Services/ITelemetryService.cs @@ -78,5 +78,15 @@ namespace AsbCloudApp.Services /// /// Task GetTelemetriesInfoByLastData(DateTimeOffset from, CancellationToken token); + + /// + /// Удаление части телеметрии + /// + /// ключ телеметрии + /// начало временного диапазона + /// конец временного диапазона + /// + /// + Task DeleteAsync(int telemetryId, DateTimeOffset? gDate, DateTimeOffset? lDate, CancellationToken token); } } \ No newline at end of file diff --git a/AsbCloudInfrastructure/Repository/LimitingParameterRepository.cs b/AsbCloudInfrastructure/Repository/LimitingParameterRepository.cs index 0ee3e574..c6e76d07 100644 --- a/AsbCloudInfrastructure/Repository/LimitingParameterRepository.cs +++ b/AsbCloudInfrastructure/Repository/LimitingParameterRepository.cs @@ -17,10 +17,25 @@ namespace AsbCloudInfrastructure.Repository private readonly IAsbCloudDbContext context; public LimitingParameterRepository(IAsbCloudDbContext context) - { + { this.context = context; } + public async Task DeleteAsync(int telemetryId, DateTimeOffset? gDate, DateTimeOffset? lDate, CancellationToken token) + { + var query = context.Set() + .Where(o => o.IdTelemetry == telemetryId); + + if (gDate.HasValue) + query = query.Where(o => o.DateStart > gDate.Value.ToUniversalTime()); + + if (lDate.HasValue) + query = query.Where(o => o.DateStart < lDate.Value.ToUniversalTime()); + + context.Set().RemoveRange(query); + return await context.SaveChangesAsync(token); + } + public async Task> GetLimitingParametersAsync(LimitingParameterRequest request, WellDto wellDto, CancellationToken token) { var timezoneOffset = wellDto.Timezone.Hours; diff --git a/AsbCloudInfrastructure/Services/SAUB/TelemetryService.cs b/AsbCloudInfrastructure/Services/SAUB/TelemetryService.cs index 4200595e..4032dd87 100644 --- a/AsbCloudInfrastructure/Services/SAUB/TelemetryService.cs +++ b/AsbCloudInfrastructure/Services/SAUB/TelemetryService.cs @@ -24,6 +24,8 @@ namespace AsbCloudInfrastructure.Services.SAUB //TODO: методы использующие ITelemetryDataCache, скорее всего, тут не нужны private readonly ITelemetryDataCache dataSaubCache; private readonly ITimezoneService timezoneService; + private readonly ITelemetryDataSaubService dataSaubService; + private readonly ILimitingParameterRepository limitingParameterRepository; public ITimezoneService TimeZoneService => timezoneService; @@ -31,12 +33,17 @@ namespace AsbCloudInfrastructure.Services.SAUB IAsbCloudDbContext db, IMemoryCache memoryCache, ITelemetryDataCache dataSaubCache, - ITimezoneService timezoneService) + ITimezoneService timezoneService, + ITelemetryDataSaubService dataSaubService, + ILimitingParameterRepository limitingParameterRepository) { this.db = db; this.memoryCache = memoryCache; this.dataSaubCache = dataSaubCache; this.timezoneService = timezoneService; + + this.dataSaubService = dataSaubService; + this.limitingParameterRepository = limitingParameterRepository; } private IEnumerable GetTelemetryCache() @@ -352,5 +359,10 @@ namespace AsbCloudInfrastructure.Services.SAUB return affected; } + + public async Task DeleteAsync(int telemetryId, DateTimeOffset? gDate, DateTimeOffset? lDate, CancellationToken token) + { + return await limitingParameterRepository.DeleteAsync(telemetryId, gDate, lDate, token); + } } } diff --git a/AsbCloudWebApi/Controllers/AdminTelemetryController.cs b/AsbCloudWebApi/Controllers/AdminTelemetryController.cs index 1275e2cd..a0f7348a 100644 --- a/AsbCloudWebApi/Controllers/AdminTelemetryController.cs +++ b/AsbCloudWebApi/Controllers/AdminTelemetryController.cs @@ -2,6 +2,7 @@ using AsbCloudApp.Data; using AsbCloudApp.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using System; using System.Threading; using System.Threading.Tasks; @@ -36,5 +37,24 @@ namespace AsbCloudWebApi.Controllers .ConfigureAwait(false); return Ok(count); } + + /// + /// Удаление куска телеметрии + /// + /// ключ телеметрии + /// начало интервала удаления + /// конец интервала удаления + /// + /// + [HttpDelete("{telemetryId}")] + [Permission] + public async Task DeleteAsync(int telemetryId, + DateTimeOffset? gDate, + DateTimeOffset? lDate, + CancellationToken token) + { + await telemetryService.DeleteAsync(telemetryId, gDate, lDate, token); + return Ok(); + } } }