forked from ddrilling/AsbCloudServer
Merge pull request 'Создать метод который удаляет данные по телеметрии панели (и все связанные с ней) до заданной даты.' (#290) from feature/#34835931-delete-telemetry-part-by-id-and-dates into dev
Reviewed-on: https://test.digitaldrilling.ru:8443/DDrilling/AsbCloudServer/pulls/290 Reviewed-by: Никита Фролов <ng.frolov@digitaldrilling.ru>
This commit is contained in:
commit
ec33345ded
@ -1,4 +1,5 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@ -9,7 +10,7 @@ namespace AsbCloudApp.Repositories
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Репозиторий работы с данными из таблицы t_data_daub_stat
|
/// Репозиторий работы с данными из таблицы t_data_daub_stat
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IDataSaubStatRepository
|
public interface IDataSaubStatRepository : ITelemetryDataEditorService
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение записей по ключу телеметрии
|
/// Получение записей по ключу телеметрии
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
using System;
|
using AsbCloudApp.Data;
|
||||||
using AsbCloudApp.Data.DetectedOperation;
|
using AsbCloudApp.Data.DetectedOperation;
|
||||||
using AsbCloudApp.Requests;
|
using AsbCloudApp.Requests;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using AsbCloudApp.Data;
|
using System.Threading.Tasks;
|
||||||
using AsbCloudApp.Data.WellOperation;
|
|
||||||
|
|
||||||
namespace AsbCloudApp.Repositories;
|
namespace AsbCloudApp.Repositories;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Таблица автоматически определенных операций
|
/// Таблица автоматически определенных операций
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IDetectedOperationRepository
|
public interface IDetectedOperationRepository : ITelemetryDataEditorService
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление нескольких записей
|
/// Добавление нескольких записей
|
||||||
@ -21,7 +21,7 @@ public interface IDetectedOperationRepository
|
|||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns>количество добавленных</returns>
|
/// <returns>количество добавленных</returns>
|
||||||
Task<int> InsertRangeAsync(IEnumerable<DetectedOperationDto> dtos, CancellationToken token);
|
Task<int> InsertRangeAsync(IEnumerable<DetectedOperationDto> dtos, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Обновить несколько записей
|
/// Обновить несколько записей
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -37,7 +37,7 @@ public interface IDetectedOperationRepository
|
|||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<int> DeleteRangeAsync(IEnumerable<int> ids, CancellationToken token);
|
Task<int> DeleteRangeAsync(IEnumerable<int> ids, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить автоматически определенные операции по телеметрии
|
/// Получить автоматически определенные операции по телеметрии
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -60,7 +60,7 @@ public interface IDetectedOperationRepository
|
|||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IDictionary<int, DateTimeOffset>> GetLastDetectedDatesAsync(CancellationToken token);
|
Task<IDictionary<int, DateTimeOffset>> GetLastDetectedDatesAsync(CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удалить операции
|
/// Удалить операции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using AsbCloudApp.Data.SAUB;
|
using AsbCloudApp.Data.SAUB;
|
||||||
using AsbCloudApp.Requests;
|
using AsbCloudApp.Requests;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -9,7 +10,7 @@ namespace AsbCloudApp.Repositories
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// репозиторий по работе с данными drill_test
|
/// репозиторий по работе с данными drill_test
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IDrillTestRepository
|
public interface IDrillTestRepository : ITelemetryDataEditorService
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить данные drill_test в соответствии с параметрами запроса
|
/// Получить данные drill_test в соответствии с параметрами запроса
|
||||||
|
@ -5,13 +5,14 @@ using System.Threading;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AsbCloudApp.Requests;
|
using AsbCloudApp.Requests;
|
||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
|
||||||
namespace AsbCloudApp.Repositories
|
namespace AsbCloudApp.Repositories
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// данные ГТИ
|
/// данные ГТИ
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IGtrRepository
|
public interface IGtrRepository : ITelemetryDataEditorService
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// добавить данные (для панели бурильщика)
|
/// добавить данные (для панели бурильщика)
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using AsbCloudApp.Requests;
|
using AsbCloudApp.Requests;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace AsbCloudApp.Repositories
|
namespace AsbCloudApp.Repositories
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Репозиторий по ограничивающим параметрам с фильтрацией
|
/// Репозиторий по ограничивающим параметрам с фильтрацией
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface ILimitingParameterRepository
|
public interface ILimitingParameterRepository : ITelemetryDataEditorService
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение списка ограничивающих параметров по идентификатору скважины
|
/// Получение списка ограничивающих параметров по идентификатору скважины
|
||||||
|
39
AsbCloudApp/Requests/TelemetryPartDeleteRequest.cs
Normal file
39
AsbCloudApp/Requests/TelemetryPartDeleteRequest.cs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace AsbCloudApp.Requests;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Параметры запроса на удаление куска телеметрии
|
||||||
|
/// </summary>
|
||||||
|
public class TelemetryPartDeleteRequest : IValidatableObject
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// ключ телеметрии
|
||||||
|
/// </summary>
|
||||||
|
public int IdTelemetry { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// greater or equal then Date. Must be set one of GeDate or LeDate
|
||||||
|
/// </summary>
|
||||||
|
public DateTimeOffset? GeDate { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// less or equal then Date. Must be set one of GeDate or LeDate
|
||||||
|
/// </summary>
|
||||||
|
public DateTimeOffset? LeDate { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Валидация входящих данных
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="validationContext"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||||
|
{
|
||||||
|
if (IdTelemetry == 0)
|
||||||
|
yield return new ValidationResult($"IdTelemetry must be defined");
|
||||||
|
if (!GeDate.HasValue && !LeDate.HasValue)
|
||||||
|
yield return new ValidationResult($"GeDate or LeDate must be defined");
|
||||||
|
}
|
||||||
|
}
|
@ -10,7 +10,7 @@ namespace AsbCloudApp.Services
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Сервис сообщений панели оператора
|
/// Сервис сообщений панели оператора
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IMessageService
|
public interface IMessageService : ITelemetryDataEditorService
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить сообщения по параметрам
|
/// Получить сообщения по параметрам
|
||||||
|
19
AsbCloudApp/Services/ITelemetryDataEditorService.cs
Normal file
19
AsbCloudApp/Services/ITelemetryDataEditorService.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using AsbCloudApp.Requests;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AsbCloudApp.Services;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сервис по работе с данными телеметрии
|
||||||
|
/// </summary>
|
||||||
|
public interface ITelemetryDataEditorService
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление части телеметрии по запросу
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<int> DeleteAsync(TelemetryPartDeleteRequest request, CancellationToken token);
|
||||||
|
}
|
@ -11,7 +11,7 @@ namespace AsbCloudApp.Services
|
|||||||
/// сервис данных тех. процесса
|
/// сервис данных тех. процесса
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="TDto"></typeparam>
|
/// <typeparam name="TDto"></typeparam>
|
||||||
public interface ITelemetryDataService<TDto> where TDto : ITelemetryData
|
public interface ITelemetryDataService<TDto> : ITelemetryDataEditorService where TDto : ITelemetryData
|
||||||
{
|
{
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@ -9,7 +10,7 @@ namespace AsbCloudApp.Services
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The wits record repository.
|
/// The wits record repository.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IWitsRecordRepository<TDto>
|
public interface IWitsRecordRepository<TDto> : ITelemetryDataEditorService
|
||||||
where TDto : ITelemetryData
|
where TDto : ITelemetryData
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -493,6 +493,8 @@ namespace AsbCloudInfrastructure
|
|||||||
|
|
||||||
services.AddTransient<IWellboreService, WellboreService>();
|
services.AddTransient<IWellboreService, WellboreService>();
|
||||||
|
|
||||||
|
services.AddTransient<ITelemetryDataEditorService, TelemetryDataEditorService>();
|
||||||
|
|
||||||
services.AddTransient<DetectedOperationExportService>();
|
services.AddTransient<DetectedOperationExportService>();
|
||||||
|
|
||||||
services.AddTransient<IDailyReportService, DailyReportService>();
|
services.AddTransient<IDailyReportService, DailyReportService>();
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using AsbCloudApp.Repositories;
|
using AsbCloudApp.Repositories;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
@ -81,5 +82,32 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
|
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IQueryable<DataSaubStat> BuildQuery(TelemetryPartDeleteRequest request)
|
||||||
|
{
|
||||||
|
var query = db.Set<DataSaubStat>()
|
||||||
|
.Where(o => o.IdTelemetry == request.IdTelemetry);
|
||||||
|
|
||||||
|
if (request.LeDate is not null)
|
||||||
|
{
|
||||||
|
var leDate = request.LeDate.Value.ToUniversalTime();
|
||||||
|
query = query.Where(o => o.DateStart <= leDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.GeDate is not null)
|
||||||
|
{
|
||||||
|
var geDate = request.GeDate.Value.ToUniversalTime();
|
||||||
|
query = query.Where(o => o.DateEnd >= geDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<int> DeleteAsync(TelemetryPartDeleteRequest request, CancellationToken token)
|
||||||
|
{
|
||||||
|
var query = BuildQuery(request);
|
||||||
|
db.Set<DataSaubStat>().RemoveRange(query);
|
||||||
|
return await db.SaveChangesAsync(token);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,8 @@ using AsbCloudApp.Data;
|
|||||||
|
|
||||||
namespace AsbCloudInfrastructure.Repository;
|
namespace AsbCloudInfrastructure.Repository;
|
||||||
|
|
||||||
public class DetectedOperationRepository : CrudRepositoryBase<DetectedOperationDto, DetectedOperation>, IDetectedOperationRepository
|
public class DetectedOperationRepository
|
||||||
|
: CrudRepositoryBase<DetectedOperationDto, DetectedOperation>, IDetectedOperationRepository
|
||||||
{
|
{
|
||||||
private readonly ITelemetryService telemetryService;
|
private readonly ITelemetryService telemetryService;
|
||||||
|
|
||||||
@ -33,6 +34,13 @@ public class DetectedOperationRepository : CrudRepositoryBase<DetectedOperationD
|
|||||||
return await dbContext.SaveChangesAsync(token);
|
return await dbContext.SaveChangesAsync(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<int> DeleteAsync(TelemetryPartDeleteRequest request, CancellationToken token)
|
||||||
|
{
|
||||||
|
var query = BuildQuery(request);
|
||||||
|
dbContext.Set<DetectedOperation>().RemoveRange(query);
|
||||||
|
return await dbContext.SaveChangesAsync(token);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<PaginationContainer<DetectedOperationDto>> GetPageAsync(DetectedOperationByTelemetryRequest request, CancellationToken token)
|
public async Task<PaginationContainer<DetectedOperationDto>> GetPageAsync(DetectedOperationByTelemetryRequest request, CancellationToken token)
|
||||||
{
|
{
|
||||||
var skip = request.Skip ?? 0;
|
var skip = request.Skip ?? 0;
|
||||||
@ -112,7 +120,27 @@ public class DetectedOperationRepository : CrudRepositoryBase<DetectedOperationD
|
|||||||
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IQueryable<DetectedOperation> BuildQuery(TelemetryPartDeleteRequest request)
|
||||||
|
{
|
||||||
|
var query = dbContext.Set<DetectedOperation>()
|
||||||
|
.Where(o => o.IdTelemetry == request.IdTelemetry);
|
||||||
|
|
||||||
|
if (request.LeDate is not null)
|
||||||
|
{
|
||||||
|
var leDate = request.LeDate.Value.ToUniversalTime();
|
||||||
|
query = query.Where(o => o.DateStart <= leDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.GeDate is not null)
|
||||||
|
{
|
||||||
|
var geDate = request.GeDate.Value.ToUniversalTime();
|
||||||
|
query = query.Where(o => o.DateEnd >= geDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
private static DetectedOperationDto Convert(DetectedOperation src, TimeSpan offset)
|
private static DetectedOperationDto Convert(DetectedOperation src, TimeSpan offset)
|
||||||
{
|
{
|
||||||
var dto = src.Adapt<DetectedOperationDto>();
|
var dto = src.Adapt<DetectedOperationDto>();
|
||||||
|
@ -84,5 +84,33 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
dto.TimeStampStart = dto.TimeStampStart.ToRemoteDateTime(dto.Telemetry?.TimeZone?.Hours ?? 0);
|
dto.TimeStampStart = dto.TimeStampStart.ToRemoteDateTime(dto.Telemetry?.TimeZone?.Hours ?? 0);
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: Унифицировать модели данных телеметрии.Чтобы в будущем унифицировать репозитории данных телеметрии.
|
||||||
|
private IQueryable<DrillTest> BuildQuery(TelemetryPartDeleteRequest request)
|
||||||
|
{
|
||||||
|
var query = db.Set<DrillTest>()
|
||||||
|
.Where(o => o.IdTelemetry == request.IdTelemetry);
|
||||||
|
|
||||||
|
if (request.LeDate is not null)
|
||||||
|
{
|
||||||
|
var leDate = request.LeDate.Value.ToUniversalTime();
|
||||||
|
query = query.Where(o => o.TimeStampStart <= leDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.GeDate is not null)
|
||||||
|
{
|
||||||
|
var geDate = request.GeDate.Value.ToUniversalTime();
|
||||||
|
query = query.Where(o => o.TimeStampStart >= geDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<int> DeleteAsync(TelemetryPartDeleteRequest request, CancellationToken token)
|
||||||
|
{
|
||||||
|
var query = BuildQuery(request);
|
||||||
|
db.Set<DrillTest>().RemoveRange(query);
|
||||||
|
return await db.SaveChangesAsync(token);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
|
using AsbCloudApp.Data;
|
||||||
using AsbCloudApp.Data.GTR;
|
using AsbCloudApp.Data.GTR;
|
||||||
|
using AsbCloudApp.Exceptions;
|
||||||
using AsbCloudApp.Repositories;
|
using AsbCloudApp.Repositories;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using AsbCloudDb;
|
using AsbCloudDb;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
using AsbCloudDb.Model.GTR;
|
using AsbCloudDb.Model.GTR;
|
||||||
|
using Mapster;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
@ -12,11 +16,6 @@ using System.Diagnostics;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AsbCloudApp.Exceptions;
|
|
||||||
using AsbCloudApp.Requests;
|
|
||||||
using Mapster;
|
|
||||||
using AsbCloudApp.Data;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure.Repository
|
namespace AsbCloudInfrastructure.Repository
|
||||||
{
|
{
|
||||||
@ -87,7 +86,7 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
public async Task<DatesRangeDto?> GetRangeAsync(int idWell, DateTimeOffset? geDate, DateTimeOffset? leDate, CancellationToken token)
|
public async Task<DatesRangeDto?> GetRangeAsync(int idWell, DateTimeOffset? geDate, DateTimeOffset? leDate, CancellationToken token)
|
||||||
{
|
{
|
||||||
var telemetry = telemetryService.GetOrDefaultTelemetryByIdWell(idWell);
|
var telemetry = telemetryService.GetOrDefaultTelemetryByIdWell(idWell);
|
||||||
|
|
||||||
if (telemetry is null)
|
if (telemetry is null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
@ -109,7 +108,7 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
});
|
});
|
||||||
var range = await groupedQuery.FirstOrDefaultAsync(token);
|
var range = await groupedQuery.FirstOrDefaultAsync(token);
|
||||||
|
|
||||||
if (range is null)
|
if (range is null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var result = new DatesRangeDto
|
var result = new DatesRangeDto
|
||||||
@ -121,16 +120,16 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async Task<IEnumerable<GtrWitsDto>> GetAsync<TEntity, TType>(int idWell, GtrRequest request, CancellationToken token)
|
private async Task<IEnumerable<GtrWitsDto>> GetAsync<TEntity, TType>(int idWell, GtrRequest request, CancellationToken token)
|
||||||
where TEntity : WitsItemBase<TType>
|
where TEntity : WitsItemBase<TType>
|
||||||
where TType : notnull
|
where TType : notnull
|
||||||
{
|
{
|
||||||
var telemetry = telemetryService.GetOrDefaultTelemetryByIdWell(idWell);
|
var telemetry = telemetryService.GetOrDefaultTelemetryByIdWell(idWell);
|
||||||
|
|
||||||
if (telemetry is null)
|
if (telemetry is null)
|
||||||
return Enumerable.Empty<GtrWitsDto>();
|
return Enumerable.Empty<GtrWitsDto>();
|
||||||
|
|
||||||
if (telemetry.TimeZone is null)
|
if (telemetry.TimeZone is null)
|
||||||
throw new ArgumentInvalidException(nameof(idWell),$"Telemetry id: {telemetry.Id} can't find timezone");
|
throw new ArgumentInvalidException(nameof(idWell), $"Telemetry id: {telemetry.Id} can't find timezone");
|
||||||
|
|
||||||
var query = BuildQuery<TEntity, TType>(telemetry.Id, request);
|
var query = BuildQuery<TEntity, TType>(telemetry.Id, request);
|
||||||
|
|
||||||
@ -147,7 +146,7 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
|
|
||||||
var interval = TimeSpan.FromSeconds(10);
|
var interval = TimeSpan.FromSeconds(10);
|
||||||
var timezoneOffset = TimeSpan.FromHours(telemetry.TimeZone.Hours);
|
var timezoneOffset = TimeSpan.FromHours(telemetry.TimeZone.Hours);
|
||||||
|
|
||||||
var dtos = entities
|
var dtos = entities
|
||||||
.GroupBy(e => e.DateTime.Ticks / interval.Ticks)
|
.GroupBy(e => e.DateTime.Ticks / interval.Ticks)
|
||||||
.Select(groupByInterval =>
|
.Select(groupByInterval =>
|
||||||
@ -166,9 +165,9 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
}
|
}
|
||||||
|
|
||||||
private IQueryable<TEntity> BuildQuery<TEntity, TType>(int idTelemetry, GtrRequest request)
|
private IQueryable<TEntity> BuildQuery<TEntity, TType>(int idTelemetry, GtrRequest request)
|
||||||
where TEntity : WitsItemBase<TType>
|
where TEntity : WitsItemBase<TType>
|
||||||
where TType : notnull
|
where TType : notnull
|
||||||
{
|
{
|
||||||
var query = db.Set<TEntity>()
|
var query = db.Set<TEntity>()
|
||||||
.Where(e => e.IdTelemetry == idTelemetry);
|
.Where(e => e.IdTelemetry == idTelemetry);
|
||||||
|
|
||||||
@ -183,9 +182,9 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
var lastDate = query
|
var lastDate = query
|
||||||
.OrderBy(e=>e.DateTime)
|
.OrderBy(e => e.DateTime)
|
||||||
.LastOrDefault()
|
.LastOrDefault()
|
||||||
?.DateTime
|
?.DateTime
|
||||||
?? DateTimeOffset.UtcNow;
|
?? DateTimeOffset.UtcNow;
|
||||||
var dateBegin = lastDate.AddSeconds(-request.IntervalSec);
|
var dateBegin = lastDate.AddSeconds(-request.IntervalSec);
|
||||||
var dateEnd = lastDate;
|
var dateEnd = lastDate;
|
||||||
@ -329,10 +328,10 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
var dateTime = record.Date.ToUtcDateTimeOffset(timezoneHours);
|
var dateTime = record.Date.ToUtcDateTimeOffset(timezoneHours);
|
||||||
foreach (var item in record.Items)
|
foreach (var item in record.Items)
|
||||||
{
|
{
|
||||||
if (cacheTelemetryItems?.TryGetValue((record.Id, item.Key), out var cacheItem) == true)
|
if (cacheTelemetryItems?.TryGetValue((record.Id, item.Key), out var cacheItem) == true)
|
||||||
if (Math.Abs((dateTime - cacheItem.Date).TotalSeconds) < 1)
|
if (Math.Abs((dateTime - cacheItem.Date).TotalSeconds) < 1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (item.Value.Value is string valueString)
|
if (item.Value.Value is string valueString)
|
||||||
{
|
{
|
||||||
var entity = MakeEntity<WitsItemString, string>(record.Id, item.Key, idTelemetry, dateTime, valueString);
|
var entity = MakeEntity<WitsItemString, string>(record.Id, item.Key, idTelemetry, dateTime, valueString);
|
||||||
@ -362,14 +361,15 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
if (ints.Any())
|
if (ints.Any())
|
||||||
await db.Database.ExecInsertOrIgnoreAsync(db.Set<WitsItemInt>(), ints, token);
|
await db.Database.ExecInsertOrIgnoreAsync(db.Set<WitsItemInt>(), ints, token);
|
||||||
}
|
}
|
||||||
catch(Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Trace.TraceError("Exception while saving GTR Wits data", ex);
|
Trace.TraceError("Exception while saving GTR Wits data", ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
cache.AddOrUpdate(idTelemetry,
|
cache.AddOrUpdate(idTelemetry,
|
||||||
(_) => MakeNewCache(dtos),
|
(_) => MakeNewCache(dtos),
|
||||||
(_, oldItemsDictionary) => {
|
(_, oldItemsDictionary) =>
|
||||||
|
{
|
||||||
foreach (var record in dtos)
|
foreach (var record in dtos)
|
||||||
foreach (var item in record.Items)
|
foreach (var item in record.Items)
|
||||||
{
|
{
|
||||||
@ -398,7 +398,8 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
{
|
{
|
||||||
var items = dtos.SelectMany(record =>
|
var items = dtos.SelectMany(record =>
|
||||||
record.Items.Select(
|
record.Items.Select(
|
||||||
item => new WitsItemRecordDto {
|
item => new WitsItemRecordDto
|
||||||
|
{
|
||||||
IdItem = item.Key,
|
IdItem = item.Key,
|
||||||
IdRecord = record.Id,
|
IdRecord = record.Id,
|
||||||
Date = record.Date,
|
Date = record.Date,
|
||||||
@ -409,7 +410,7 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
.GroupBy(item => (item.IdRecord, item.IdItem));
|
.GroupBy(item => (item.IdRecord, item.IdItem));
|
||||||
|
|
||||||
var pairs = groups.Select(group => new KeyValuePair<(int, int), WitsItemRecordDto>(
|
var pairs = groups.Select(group => new KeyValuePair<(int, int), WitsItemRecordDto>(
|
||||||
group.Key,
|
group.Key,
|
||||||
group.OrderByDescending(item => item.Date).First()));
|
group.OrderByDescending(item => item.Date).First()));
|
||||||
|
|
||||||
return new ConcurrentDictionary<(int, int), WitsItemRecordDto>(pairs);
|
return new ConcurrentDictionary<(int, int), WitsItemRecordDto>(pairs);
|
||||||
@ -439,6 +440,47 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
Value = (TValue)dto.Value.Value,
|
Value = (TValue)dto.Value.Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private IQueryable<TEntity> BuildQuery<TEntity, TValue>(TelemetryPartDeleteRequest request)
|
||||||
|
where TEntity : WitsItemBase<TValue>
|
||||||
|
where TValue : notnull
|
||||||
|
{
|
||||||
|
var query = db.Set<TEntity>().Where(i => i.IdTelemetry == request.IdTelemetry);
|
||||||
|
|
||||||
|
if (request.LeDate is not null)
|
||||||
|
{
|
||||||
|
var leDate = request.LeDate.Value.ToUniversalTime();
|
||||||
|
query = query.Where(o => o.DateTime <= leDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.GeDate is not null)
|
||||||
|
{
|
||||||
|
var geDate = request.GeDate.Value.ToUniversalTime();
|
||||||
|
query = query.Where(o => o.DateTime >= geDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<int> DeleteAsync(TelemetryPartDeleteRequest request, CancellationToken token)
|
||||||
|
{
|
||||||
|
var result = 0;
|
||||||
|
result += await DeleteAsync<WitsItemFloat, float>(request, token);
|
||||||
|
result += await DeleteAsync<WitsItemInt, int>(request, token);
|
||||||
|
result += await DeleteAsync<WitsItemString, string>(request, token);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<int> DeleteAsync<TEntity, TType>(TelemetryPartDeleteRequest request, CancellationToken token)
|
||||||
|
where TEntity : WitsItemBase<TType>
|
||||||
|
where TType : notnull
|
||||||
|
{
|
||||||
|
var query = BuildQuery<TEntity, TType>(request);
|
||||||
|
db.Set<TEntity>().RemoveRange(query);
|
||||||
|
return await db.SaveChangesAsync(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private class WitsRequest
|
private class WitsRequest
|
||||||
{
|
{
|
||||||
public int IdTelemetry { get; set; }
|
public int IdTelemetry { get; set; }
|
||||||
|
@ -17,10 +17,17 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
private readonly IAsbCloudDbContext context;
|
private readonly IAsbCloudDbContext context;
|
||||||
|
|
||||||
public LimitingParameterRepository(IAsbCloudDbContext context)
|
public LimitingParameterRepository(IAsbCloudDbContext context)
|
||||||
{
|
{
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<int> DeleteAsync(TelemetryPartDeleteRequest request, CancellationToken token)
|
||||||
|
{
|
||||||
|
var query = BuildQuery(request);
|
||||||
|
context.Set<LimitingParameter>().RemoveRange(query);
|
||||||
|
return await context.SaveChangesAsync(token);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<LimitingParameterDataDto>> GetLimitingParametersAsync(LimitingParameterRequest request, WellDto wellDto, CancellationToken token)
|
public async Task<IEnumerable<LimitingParameterDataDto>> GetLimitingParametersAsync(LimitingParameterRequest request, WellDto wellDto, CancellationToken token)
|
||||||
{
|
{
|
||||||
var timezoneOffset = wellDto.Timezone.Hours;
|
var timezoneOffset = wellDto.Timezone.Hours;
|
||||||
@ -74,6 +81,26 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IQueryable<LimitingParameter> BuildQuery(TelemetryPartDeleteRequest request)
|
||||||
|
{
|
||||||
|
var query = context.Set<LimitingParameter>()
|
||||||
|
.Where(o => o.IdTelemetry == request.IdTelemetry);
|
||||||
|
|
||||||
|
if (request.LeDate is not null)
|
||||||
|
{
|
||||||
|
var leDate = request.LeDate.Value.ToUniversalTime();
|
||||||
|
query = query.Where(o => o.DateStart <= leDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.GeDate is not null)
|
||||||
|
{
|
||||||
|
var geDate = request.GeDate.Value.ToUniversalTime();
|
||||||
|
query = query.Where(o => o.DateEnd >= geDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
using AsbCloudApp.Requests;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
@ -20,7 +21,7 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
private readonly IAsbCloudDbContext db;
|
private readonly IAsbCloudDbContext db;
|
||||||
private readonly ITelemetryService telemetryService;
|
private readonly ITelemetryService telemetryService;
|
||||||
|
|
||||||
private static readonly ConcurrentDictionary<int, TDto> cache = new ();
|
private static readonly ConcurrentDictionary<int, TDto> cache = new();
|
||||||
|
|
||||||
public WitsRecordRepository(IAsbCloudDbContext db, ITelemetryService telemetryService)
|
public WitsRecordRepository(IAsbCloudDbContext db, ITelemetryService telemetryService)
|
||||||
{
|
{
|
||||||
@ -58,6 +59,33 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
return data.Select(d => Convert(d, timezoneHours));
|
return data.Select(d => Convert(d, timezoneHours));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IQueryable<TEntity> BuildQuery(TelemetryPartDeleteRequest request)
|
||||||
|
{
|
||||||
|
var query = db.Set<TEntity>()
|
||||||
|
.Where(o => o.IdTelemetry == request.IdTelemetry);
|
||||||
|
|
||||||
|
if (request.LeDate is not null)
|
||||||
|
{
|
||||||
|
var leDate = request.LeDate.Value.ToUniversalTime();
|
||||||
|
query = query.Where(o => o.DateTime <= leDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.GeDate is not null)
|
||||||
|
{
|
||||||
|
var geDate = request.GeDate.Value.ToUniversalTime();
|
||||||
|
query = query.Where(o => o.DateTime >= geDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<int> DeleteAsync(TelemetryPartDeleteRequest request, CancellationToken token)
|
||||||
|
{
|
||||||
|
var query = BuildQuery(request);
|
||||||
|
dbset.RemoveRange(query);
|
||||||
|
return await db.SaveChangesAsync(token);
|
||||||
|
}
|
||||||
|
|
||||||
public TDto? GetLastOrDefault(int idTelemetry)
|
public TDto? GetLastOrDefault(int idTelemetry)
|
||||||
=> cache.GetValueOrDefault(idTelemetry);
|
=> cache.GetValueOrDefault(idTelemetry);
|
||||||
|
|
||||||
@ -66,7 +94,7 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
if (!dtos.Any())
|
if (!dtos.Any())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
cache.AddOrUpdate(idTelemetry, dtos.Last(), (_,_) => dtos.OrderBy(r => r.DateTime).Last());
|
cache.AddOrUpdate(idTelemetry, dtos.Last(), (_, _) => dtos.OrderBy(r => r.DateTime).Last());
|
||||||
|
|
||||||
var timezoneHours = telemetryService.GetTimezone(idTelemetry).Hours;
|
var timezoneHours = telemetryService.GetTimezone(idTelemetry).Hours;
|
||||||
var entities = dtos
|
var entities = dtos
|
||||||
@ -81,7 +109,7 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
.Select(e => e.DateTime)
|
.Select(e => e.DateTime)
|
||||||
.OrderBy(d => d)
|
.OrderBy(d => d)
|
||||||
.ToArrayAsync(token);
|
.ToArrayAsync(token);
|
||||||
|
|
||||||
foreach (var entity in entities)
|
foreach (var entity in entities)
|
||||||
{
|
{
|
||||||
if (!existingEntities.Any(e => e == entity.DateTime))
|
if (!existingEntities.Any(e => e == entity.DateTime))
|
||||||
@ -101,9 +129,9 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
(dt.Millisecond + random.Next(1, 283)) % 1000,
|
(dt.Millisecond + random.Next(1, 283)) % 1000,
|
||||||
dt.Offset);
|
dt.Offset);
|
||||||
dbset.Add(entity);
|
dbset.Add(entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await db.SaveChangesAsync(token);
|
await db.SaveChangesAsync(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,8 +154,8 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
{
|
{
|
||||||
var entity = dto.Adapt<TEntity>();
|
var entity = dto.Adapt<TEntity>();
|
||||||
entity.Recid = GetRecId(dto);
|
entity.Recid = GetRecId(dto);
|
||||||
entity.IdTelemetry = idTelemetry;
|
entity.IdTelemetry = idTelemetry;
|
||||||
entity.DateTime = dto.DateTime.ToUtcDateTimeOffset(timezoneHours);
|
entity.DateTime = dto.DateTime.ToUtcDateTimeOffset(timezoneHours);
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
|||||||
var allUsers = await memoryCache.GetOrCreateBasicAsync(db.Set<TelemetryUser>(), token);
|
var allUsers = await memoryCache.GetOrCreateBasicAsync(db.Set<TelemetryUser>(), token);
|
||||||
var users = allUsers.Where(u => u.IdTelemetry == telemetry.Id);
|
var users = allUsers.Where(u => u.IdTelemetry == telemetry.Id);
|
||||||
|
|
||||||
var eventsDict = events.ToDictionary(x=>x.IdEvent, x => x);
|
var eventsDict = events.ToDictionary(x => x.IdEvent, x => x);
|
||||||
var usersDict = users.ToDictionary(x => x.IdUser, x => x);
|
var usersDict = users.ToDictionary(x => x.IdUser, x => x);
|
||||||
|
|
||||||
var messagesDtoList = new List<MessageDto>();
|
var messagesDtoList = new List<MessageDto>();
|
||||||
@ -142,7 +142,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
|||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
|
|
||||||
var telemetry = telemetryService.GetOrCreateTelemetryByUid(uid);
|
var telemetry = telemetryService.GetOrCreateTelemetryByUid(uid);
|
||||||
|
|
||||||
foreach (var dto in dtos)
|
foreach (var dto in dtos)
|
||||||
{
|
{
|
||||||
var entity = dto.Adapt<TelemetryMessage>();
|
var entity = dto.Adapt<TelemetryMessage>();
|
||||||
@ -154,6 +154,33 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
|||||||
|
|
||||||
return db.SaveChangesAsync(token);
|
return db.SaveChangesAsync(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IQueryable<TelemetryMessage> BuildQuery(TelemetryPartDeleteRequest request)
|
||||||
|
{
|
||||||
|
var query = db.Set<TelemetryMessage>()
|
||||||
|
.Where(o => o.IdTelemetry == request.IdTelemetry);
|
||||||
|
|
||||||
|
if (request.GeDate is not null)
|
||||||
|
{
|
||||||
|
var geDate = request.GeDate.Value.ToUniversalTime();
|
||||||
|
query = query.Where(o => o.DateTime <= geDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.LeDate is not null)
|
||||||
|
{
|
||||||
|
var leDate = request.LeDate.Value.ToUniversalTime();
|
||||||
|
query = query.Where(o => o.DateTime >= leDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<int> DeleteAsync(TelemetryPartDeleteRequest request, CancellationToken token)
|
||||||
|
{
|
||||||
|
var query = BuildQuery(request);
|
||||||
|
db.Set<TelemetryMessage>().RemoveRange(query);
|
||||||
|
return await db.SaveChangesAsync(token);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using AsbCloudApp.Exceptions;
|
using AsbCloudApp.Exceptions;
|
||||||
using AsbCloudApp.Repositories;
|
using AsbCloudApp.Repositories;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using AsbCloudDb;
|
using AsbCloudDb;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
@ -11,8 +12,6 @@ using System.Diagnostics;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AsbCloudApp.Requests;
|
|
||||||
using Mapster;
|
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services.SAUB
|
namespace AsbCloudInfrastructure.Services.SAUB
|
||||||
{
|
{
|
||||||
@ -160,12 +159,12 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
|||||||
public async Task<IEnumerable<TDto>> GetByTelemetryAsync(int idTelemetry, TelemetryDataRequest request, CancellationToken token)
|
public async Task<IEnumerable<TDto>> GetByTelemetryAsync(int idTelemetry, TelemetryDataRequest request, CancellationToken token)
|
||||||
{
|
{
|
||||||
var timezone = telemetryService.GetTimezone(idTelemetry);
|
var timezone = telemetryService.GetTimezone(idTelemetry);
|
||||||
|
|
||||||
var cache = telemetryDataCache.GetOrDefault(idTelemetry, request);
|
var cache = telemetryDataCache.GetOrDefault(idTelemetry, request);
|
||||||
|
|
||||||
if(cache is not null)
|
if (cache is not null)
|
||||||
return cache;
|
return cache;
|
||||||
|
|
||||||
var query = BuildQuery(idTelemetry, request);
|
var query = BuildQuery(idTelemetry, request);
|
||||||
|
|
||||||
var entities = await query
|
var entities = await query
|
||||||
@ -219,10 +218,30 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
|||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IQueryable<TEntity> BuildQuery(TelemetryPartDeleteRequest request)
|
||||||
|
{
|
||||||
|
var query = db.Set<TEntity>()
|
||||||
|
.Where(o => o.IdTelemetry == request.IdTelemetry);
|
||||||
|
|
||||||
|
if (request.GeDate is not null)
|
||||||
|
{
|
||||||
|
var geDate = request.GeDate.Value.ToUniversalTime();
|
||||||
|
query = query.Where(o => o.DateTime <= geDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (request.LeDate is not null)
|
||||||
|
{
|
||||||
|
var leDate = request.LeDate.Value.ToUniversalTime();
|
||||||
|
query = query.Where(o => o.DateTime >= leDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public async Task<DatesRangeDto?> GetRangeAsync(int idWell, DateTimeOffset geDate, DateTimeOffset? leDate, CancellationToken token)
|
public async Task<DatesRangeDto?> GetRangeAsync(int idWell, DateTimeOffset geDate, DateTimeOffset? leDate, CancellationToken token)
|
||||||
{
|
{
|
||||||
var telemetry = telemetryService.GetOrDefaultTelemetryByIdWell(idWell)
|
var telemetry = telemetryService.GetOrDefaultTelemetryByIdWell(idWell)
|
||||||
?? throw new ArgumentInvalidException(nameof(idWell), $"По скважине id:{idWell} нет телеметрии");
|
?? throw new ArgumentInvalidException(nameof(idWell), $"По скважине id:{idWell} нет телеметрии");
|
||||||
|
|
||||||
if ((DateTimeOffset.UtcNow - geDate) < TimeSpan.FromHours(12))
|
if ((DateTimeOffset.UtcNow - geDate) < TimeSpan.FromHours(12))
|
||||||
@ -231,7 +250,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
|||||||
var cachedRange = telemetryDataCache.GetOrDefaultCachedDataDateRange(telemetry.Id);
|
var cachedRange = telemetryDataCache.GetOrDefaultCachedDataDateRange(telemetry.Id);
|
||||||
if (cachedRange is not null)
|
if (cachedRange is not null)
|
||||||
{
|
{
|
||||||
var datesRange = new DatesRangeDto {From = cachedRange.From, To = cachedRange.To };
|
var datesRange = new DatesRangeDto { From = cachedRange.From, To = cachedRange.To };
|
||||||
if (geDate >= cachedRange.From)
|
if (geDate >= cachedRange.From)
|
||||||
datesRange.From = geDate.ToOffset(cachedRange.From.Offset);
|
datesRange.From = geDate.ToOffset(cachedRange.From.Offset);
|
||||||
|
|
||||||
@ -246,7 +265,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
|||||||
.Where(entity => entity.IdTelemetry == telemetry.Id)
|
.Where(entity => entity.IdTelemetry == telemetry.Id)
|
||||||
.Where(entity => entity.DateTime >= geDate.ToUniversalTime());
|
.Where(entity => entity.DateTime >= geDate.ToUniversalTime());
|
||||||
|
|
||||||
if(leDate.HasValue)
|
if (leDate.HasValue)
|
||||||
query = query.Where(entity => entity.DateTime <= leDate.Value.ToUniversalTime());
|
query = query.Where(entity => entity.DateTime <= leDate.Value.ToUniversalTime());
|
||||||
|
|
||||||
var groupQuery = query
|
var groupQuery = query
|
||||||
@ -282,5 +301,11 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
|||||||
|
|
||||||
protected abstract TEntity Convert(TDto src, double timezoneOffset);
|
protected abstract TEntity Convert(TDto src, double timezoneOffset);
|
||||||
|
|
||||||
|
public async Task<int> DeleteAsync(TelemetryPartDeleteRequest request, CancellationToken token)
|
||||||
|
{
|
||||||
|
var query = BuildQuery(request);
|
||||||
|
db.Set<TEntity>().RemoveRange(query);
|
||||||
|
return await db.SaveChangesAsync(token);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,82 @@
|
|||||||
|
using AsbCloudApp.Data.SAUB;
|
||||||
|
using AsbCloudApp.Data.WITS;
|
||||||
|
using AsbCloudApp.Repositories;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AsbCloudInfrastructure.Services.SAUB
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Сервис по работе с данными телеметрии
|
||||||
|
/// </summary>
|
||||||
|
public class TelemetryDataEditorService : ITelemetryDataEditorService
|
||||||
|
{
|
||||||
|
private readonly ITelemetryDataEditorService[] repositories;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="dataSaubService"></param>
|
||||||
|
/// <param name="dataSpinService"></param>
|
||||||
|
/// <param name="dataSaubStatRepository"></param>
|
||||||
|
/// <param name="messageService"></param>
|
||||||
|
/// <param name="drillTestRepository"></param>
|
||||||
|
/// <param name="limitingParameterRepository"></param>
|
||||||
|
/// <param name="detectedOperationRepository"></param>
|
||||||
|
/// <param name="witsRecord1Repository"></param>
|
||||||
|
/// <param name="witsRecord7Repository"></param>
|
||||||
|
/// <param name="witsRecord8Repository"></param>
|
||||||
|
/// <param name="witsRecord50Repository"></param>
|
||||||
|
/// <param name="witsRecord60Repository"></param>
|
||||||
|
/// <param name="witsRecord61Repository"></param>
|
||||||
|
/// <param name="gtrRepository"></param>
|
||||||
|
public TelemetryDataEditorService(
|
||||||
|
ITelemetryDataSaubService dataSaubService,
|
||||||
|
ITelemetryDataService<TelemetryDataSpinDto> dataSpinService,
|
||||||
|
IDataSaubStatRepository dataSaubStatRepository,
|
||||||
|
IMessageService messageService,
|
||||||
|
IDrillTestRepository drillTestRepository,
|
||||||
|
ILimitingParameterRepository limitingParameterRepository,
|
||||||
|
IDetectedOperationRepository detectedOperationRepository,
|
||||||
|
IWitsRecordRepository<Record1Dto> witsRecord1Repository,
|
||||||
|
IWitsRecordRepository<Record7Dto> witsRecord7Repository,
|
||||||
|
IWitsRecordRepository<Record8Dto> witsRecord8Repository,
|
||||||
|
IWitsRecordRepository<Record50Dto> witsRecord50Repository,
|
||||||
|
IWitsRecordRepository<Record60Dto> witsRecord60Repository,
|
||||||
|
IWitsRecordRepository<Record61Dto> witsRecord61Repository,
|
||||||
|
IGtrRepository gtrRepository
|
||||||
|
)
|
||||||
|
{
|
||||||
|
repositories =
|
||||||
|
[
|
||||||
|
dataSaubService,
|
||||||
|
dataSpinService,
|
||||||
|
dataSaubStatRepository,
|
||||||
|
messageService,
|
||||||
|
drillTestRepository,
|
||||||
|
limitingParameterRepository,
|
||||||
|
detectedOperationRepository,
|
||||||
|
witsRecord1Repository,
|
||||||
|
witsRecord7Repository,
|
||||||
|
witsRecord8Repository,
|
||||||
|
witsRecord50Repository,
|
||||||
|
witsRecord60Repository,
|
||||||
|
witsRecord61Repository,
|
||||||
|
gtrRepository,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<int> DeleteAsync(TelemetryPartDeleteRequest request, CancellationToken token)
|
||||||
|
{
|
||||||
|
var result = 0;
|
||||||
|
foreach (var repository in repositories)
|
||||||
|
{
|
||||||
|
result += await repository.DeleteAsync(request, token);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,10 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -16,12 +19,15 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
public class AdminTelemetryController : CrudController<TelemetryDto, ICrudRepository<TelemetryDto>>
|
public class AdminTelemetryController : CrudController<TelemetryDto, ICrudRepository<TelemetryDto>>
|
||||||
{
|
{
|
||||||
private readonly ITelemetryService telemetryService;
|
private readonly ITelemetryService telemetryService;
|
||||||
|
private readonly ITelemetryDataEditorService telemetryEditorService;
|
||||||
|
|
||||||
public AdminTelemetryController(ICrudRepository<TelemetryDto> service,
|
public AdminTelemetryController(ICrudRepository<TelemetryDto> service,
|
||||||
ITelemetryService telemetryService)
|
ITelemetryService telemetryService,
|
||||||
|
ITelemetryDataEditorService telemetryEditorService)
|
||||||
: base(service)
|
: base(service)
|
||||||
{
|
{
|
||||||
this.telemetryService = telemetryService;
|
this.telemetryService = telemetryService;
|
||||||
|
this.telemetryEditorService = telemetryEditorService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -36,5 +42,22 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
return Ok(count);
|
return Ok(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление куска телеметрии по запросу
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request">запрос</param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpDelete("/part")]
|
||||||
|
[Permission]
|
||||||
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
||||||
|
public async Task<IActionResult> DeleteAsync([FromQuery] TelemetryPartDeleteRequest request,CancellationToken token)
|
||||||
|
{
|
||||||
|
var result = await telemetryEditorService.DeleteAsync(request, token);
|
||||||
|
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user