forked from ddrilling/AsbCloudServer
Удаление части телеметрии по параметрам: ключ телеметрии и интервал дат
This commit is contained in:
parent
e29b2be423
commit
6c516e983e
@ -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
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<LimitingParameterDataDto>> GetLimitingParametersAsync(LimitingParameterRequest request, int idTelemetry, double timezoneHours, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Удаление ограничивающих параметров по ключу телеметрии и интервалу дат
|
||||
/// </summary>
|
||||
/// <param name="telemetryId"></param>
|
||||
/// <param name="gDate"></param>
|
||||
/// <param name="lDate"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> DeleteAsync(int telemetryId, DateTimeOffset? gDate, DateTimeOffset? lDate, CancellationToken token);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -78,5 +78,15 @@ namespace AsbCloudApp.Services
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<Stream> GetTelemetriesInfoByLastData(DateTimeOffset from, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Удаление части телеметрии
|
||||
/// </summary>
|
||||
/// <param name="telemetryId">ключ телеметрии</param>
|
||||
/// <param name="gDate">начало временного диапазона</param>
|
||||
/// <param name="lDate">конец временного диапазона</param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> DeleteAsync(int telemetryId, DateTimeOffset? gDate, DateTimeOffset? lDate, CancellationToken token);
|
||||
}
|
||||
}
|
@ -21,6 +21,21 @@ namespace AsbCloudInfrastructure.Repository
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public async Task<int> DeleteAsync(int telemetryId, DateTimeOffset? gDate, DateTimeOffset? lDate, CancellationToken token)
|
||||
{
|
||||
var query = context.Set<LimitingParameter>()
|
||||
.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<LimitingParameter>().RemoveRange(query);
|
||||
return await context.SaveChangesAsync(token);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<LimitingParameterDataDto>> GetLimitingParametersAsync(LimitingParameterRequest request, WellDto wellDto, CancellationToken token)
|
||||
{
|
||||
var timezoneOffset = wellDto.Timezone.Hours;
|
||||
|
@ -24,6 +24,8 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
//TODO: методы использующие ITelemetryDataCache, скорее всего, тут не нужны
|
||||
private readonly ITelemetryDataCache<TelemetryDataSaubDto> 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<TelemetryDataSaubDto> 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<Telemetry> GetTelemetryCache()
|
||||
@ -352,5 +359,10 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
|
||||
return affected;
|
||||
}
|
||||
|
||||
public async Task<int> DeleteAsync(int telemetryId, DateTimeOffset? gDate, DateTimeOffset? lDate, CancellationToken token)
|
||||
{
|
||||
return await limitingParameterRepository.DeleteAsync(telemetryId, gDate, lDate, token);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление куска телеметрии
|
||||
/// </summary>
|
||||
/// <param name="telemetryId">ключ телеметрии</param>
|
||||
/// <param name="gDate">начало интервала удаления</param>
|
||||
/// <param name="lDate">конец интервала удаления</param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
[HttpDelete("{telemetryId}")]
|
||||
[Permission]
|
||||
public async Task<IActionResult> DeleteAsync(int telemetryId,
|
||||
DateTimeOffset? gDate,
|
||||
DateTimeOffset? lDate,
|
||||
CancellationToken token)
|
||||
{
|
||||
await telemetryService.DeleteAsync(telemetryId, gDate, lDate, token);
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user