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();
+ }
}
}