Правка по результатам ревью

This commit is contained in:
Olga Nemt 2024-07-23 17:26:23 +05:00
parent 8c8d868b9f
commit 1f2f3206b1
18 changed files with 123 additions and 203 deletions

View File

@ -1,5 +1,5 @@
using AsbCloudApp.Data;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using System;
using System.Collections.Generic;
using System.Threading;
@ -10,7 +10,7 @@ namespace AsbCloudApp.Repositories
/// <summary>
/// Репозиторий работы с данными из таблицы t_data_daub_stat
/// </summary>
public interface IDataSaubStatRepository
public interface IDataSaubStatRepository : ITelemetryDataEditorService
{
/// <summary>
/// Получение записей по ключу телеметрии
@ -37,13 +37,5 @@ namespace AsbCloudApp.Repositories
/// <param name="token"></param>
/// <returns></returns>
Task<int> InsertRangeAsync(IEnumerable<DataSaubStatDto> dataSaubStats, CancellationToken token);
/// <summary>
/// Удаление записей по запросу на удаление куска телеметрии
/// </summary>
/// <param name="request"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<int> DeleteAsync(TelemetryPartDeleteRequest request, CancellationToken token);
}
}

View File

@ -1,18 +1,18 @@
using System;
using AsbCloudApp.Data;
using AsbCloudApp.Data.DetectedOperation;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Threading;
using AsbCloudApp.Data;
using AsbCloudApp.Data.WellOperation;
using System.Threading.Tasks;
namespace AsbCloudApp.Repositories;
/// <summary>
/// Таблица автоматически определенных операций
/// </summary>
public interface IDetectedOperationRepository
public interface IDetectedOperationRepository : ITelemetryDataEditorService
{
/// <summary>
/// Добавление нескольких записей
@ -21,7 +21,7 @@ public interface IDetectedOperationRepository
/// <param name="token"></param>
/// <returns>количество добавленных</returns>
Task<int> InsertRangeAsync(IEnumerable<DetectedOperationDto> dtos, CancellationToken token);
/// <summary>
/// Обновить несколько записей
/// </summary>
@ -37,7 +37,7 @@ public interface IDetectedOperationRepository
/// <param name="token"></param>
/// <returns></returns>
Task<int> DeleteRangeAsync(IEnumerable<int> ids, CancellationToken token);
/// <summary>
/// Получить автоматически определенные операции по телеметрии
/// </summary>
@ -60,7 +60,7 @@ public interface IDetectedOperationRepository
/// <param name="token"></param>
/// <returns></returns>
Task<IDictionary<int, DateTimeOffset>> GetLastDetectedDatesAsync(CancellationToken token);
/// <summary>
/// Удалить операции
/// </summary>
@ -68,12 +68,4 @@ public interface IDetectedOperationRepository
/// <param name="token"></param>
/// <returns></returns>
Task<int> DeleteAsync(DetectedOperationByTelemetryRequest request, CancellationToken token);
/// <summary>
/// Удалить операции по запросу на удаление куска телеметрии
/// </summary>
/// <param name="request">запрос</param>
/// <param name="token"></param>
/// <returns></returns>
Task<int> DeleteAsync(TelemetryPartDeleteRequest request, CancellationToken token);
}

View File

@ -1,5 +1,6 @@
using AsbCloudApp.Data.SAUB;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
@ -9,7 +10,7 @@ namespace AsbCloudApp.Repositories
/// <summary>
/// репозиторий по работе с данными drill_test
/// </summary>
public interface IDrillTestRepository
public interface IDrillTestRepository : ITelemetryDataEditorService
{
/// <summary>
/// Получить данные drill_test в соответствии с параметрами запроса
@ -37,13 +38,5 @@ namespace AsbCloudApp.Repositories
/// <param name="token"></param>
/// <returns></returns>
Task<int> SaveDataAsync(int idTelemetry, IEnumerable<DrillTestBaseDto> dtos, CancellationToken token);
/// <summary>
/// Удаление записей drill_test по запросу на удаление куска телеметрии
/// </summary>
/// <param name="request"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<int> DeleteAsync(TelemetryPartDeleteRequest request, CancellationToken token);
}
}

View File

@ -5,13 +5,14 @@ using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Requests;
using AsbCloudApp.Data;
using AsbCloudApp.Services;
namespace AsbCloudApp.Repositories
{
/// <summary>
/// данные ГТИ
/// </summary>
public interface IGtrRepository
public interface IGtrRepository : ITelemetryDataEditorService
{
/// <summary>
/// добавить данные (для панели бурильщика)
@ -71,14 +72,5 @@ namespace AsbCloudApp.Repositories
/// <param name="token"></param>
/// <returns></returns>
Task<DatesRangeDto?> GetRangeAsync(int idWell, DateTimeOffset? geDate, DateTimeOffset? leDate, CancellationToken token);
/// <summary>
/// удаление данных ГТИ по запросу на удаление куска телеметрии
/// </summary>
/// <param name="request">запрос</param>
/// <param name="token"></param>
/// <returns></returns>
Task<int> DeleteAsync<TType>(TelemetryPartDeleteRequest request, CancellationToken token)
where TType : notnull;
}
}

View File

@ -1,16 +1,16 @@
using AsbCloudApp.Data;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Threading;
using System;
using System.Threading.Tasks;
namespace AsbCloudApp.Repositories
{
/// <summary>
/// Репозиторий по ограничивающим параметрам с фильтрацией
/// </summary>
public interface ILimitingParameterRepository
public interface ILimitingParameterRepository : ITelemetryDataEditorService
{
/// <summary>
/// Получение списка ограничивающих параметров по идентификатору скважины
@ -30,15 +30,5 @@ 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="request"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<int> DeleteAsync(TelemetryPartDeleteRequest request, CancellationToken token);
}
}

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace AsbCloudApp.Requests;
@ -6,7 +7,7 @@ namespace AsbCloudApp.Requests;
/// <summary>
/// Параметры запроса на удаление куска телеметрии
/// </summary>
public class TelemetryPartDeleteRequest
public class TelemetryPartDeleteRequest : IValidatableObject
{
/// <summary>
/// ключ телеметрии
@ -22,4 +23,17 @@ public class TelemetryPartDeleteRequest
/// less or equal then Date
/// </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");
}
}

View File

@ -10,7 +10,7 @@ namespace AsbCloudApp.Services
/// <summary>
/// Сервис сообщений панели оператора
/// </summary>
public interface IMessageService
public interface IMessageService : ITelemetryDataEditorService
{
/// <summary>
/// Получить сообщения по параметрам
@ -29,13 +29,5 @@ namespace AsbCloudApp.Services
/// <returns></returns>
Task InsertAsync(string uid, IEnumerable<TelemetryMessageDto> dtos,
CancellationToken token);
/// <summary>
/// Удаление сообщений по запросу на удаление куска телеметрии
/// </summary>
/// <param name="request">запрос</param>
/// <param name="token"></param>
/// <returns></returns>
Task<int> DeleteAsync(TelemetryPartDeleteRequest request, CancellationToken token);
}
}

View File

@ -15,5 +15,5 @@ public interface ITelemetryDataEditorService
/// <param name="request"></param>
/// <param name="token"></param>
/// <returns></returns>
Task DeleteAsync(TelemetryPartDeleteRequest request, CancellationToken token);
Task<int> DeleteAsync(TelemetryPartDeleteRequest request, CancellationToken token);
}

View File

@ -11,7 +11,7 @@ namespace AsbCloudApp.Services
/// сервис данных тех. процесса
/// </summary>
/// <typeparam name="TDto"></typeparam>
public interface ITelemetryDataService<TDto> where TDto : ITelemetryData
public interface ITelemetryDataService<TDto> : ITelemetryDataEditorService where TDto : ITelemetryData
{
/// <summary>
@ -70,14 +70,5 @@ namespace AsbCloudApp.Services
/// <param name="token"></param>
/// <returns></returns>
Task<int> UpdateDataAsync(string uid, IEnumerable<TDto> dtos, CancellationToken token);
/// <summary>
/// удалить данные по запросу
/// </summary>
/// <param name="request">запрос</param>
/// <param name="token"></param>
/// <returns></returns>
Task<int> DeleteAsync(TelemetryPartDeleteRequest request, CancellationToken token);
}
}

View File

@ -10,7 +10,7 @@ namespace AsbCloudApp.Services
/// <summary>
/// The wits record repository.
/// </summary>
public interface IWitsRecordRepository<TDto>
public interface IWitsRecordRepository<TDto> : ITelemetryDataEditorService
where TDto : ITelemetryData
{
/// <summary>
@ -46,13 +46,5 @@ namespace AsbCloudApp.Services
/// <param name="token">The token.</param>
/// <returns>A Task.</returns>
Task<(DateTime begin, DateTime end, int count)?> GetStatAsync(int idTelemetry, CancellationToken token);
/// <summary>
/// Удалить записи по запросу на удаление куска телеметрии
/// </summary>
/// <param name="request"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<int> DeleteAsync(TelemetryPartDeleteRequest request, CancellationToken token);
}
}

View File

@ -88,16 +88,16 @@ namespace AsbCloudInfrastructure.Repository
var query = db.Set<DataSaubStat>()
.Where(o => o.IdTelemetry == request.IdTelemetry);
if (request.GeDate is not null)
{
var geDate = request.GeDate.Value.ToUniversalTime();
query = query.Where(o => o.DateStart <= geDate);
}
if (request.LeDate is not null)
{
var leDate = request.LeDate.Value.ToUniversalTime();
query = query.Where(o => o.DateEnd >= leDate);
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;

View File

@ -15,7 +15,8 @@ using AsbCloudApp.Data;
namespace AsbCloudInfrastructure.Repository;
public class DetectedOperationRepository : CrudRepositoryBase<DetectedOperationDto, DetectedOperation>, IDetectedOperationRepository
public class DetectedOperationRepository
: CrudRepositoryBase<DetectedOperationDto, DetectedOperation>, IDetectedOperationRepository
{
private readonly ITelemetryService telemetryService;
@ -125,16 +126,16 @@ public class DetectedOperationRepository : CrudRepositoryBase<DetectedOperationD
var query = dbContext.Set<DetectedOperation>()
.Where(o => o.IdTelemetry == request.IdTelemetry);
if (request.GeDate is not null)
{
var geDate = request.GeDate.Value.ToUniversalTime();
query = query.Where(o => o.DateStart <= geDate);
}
if (request.LeDate is not null)
{
var leDate = request.LeDate.Value.ToUniversalTime();
query = query.Where(o => o.DateEnd >= leDate);
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;

View File

@ -85,21 +85,22 @@ namespace AsbCloudInfrastructure.Repository
return dto;
}
//TODO: Óíèôèöèðîâàòü ìîäåëè äàííûõ òåëåìåòðèè.×òîáû â áóäóùåì óíèôèöèðîâàòü ðåïîçèòîðèè äàííûõ òåëåìåòðèè.
private IQueryable<DrillTest> BuildQuery(TelemetryPartDeleteRequest request)
{
var query = db.Set<DrillTest>()
.Where(o => o.IdTelemetry == request.IdTelemetry);
if (request.GeDate is not null)
{
var geDate = request.GeDate.Value.ToUniversalTime();
query = query.Where(o => o.TimeStampStart <= geDate);
}
if (request.LeDate is not null)
{
var leDate = request.LeDate.Value.ToUniversalTime();
query = query.Where(o => o.TimeStampStart >= leDate);
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;

View File

@ -446,32 +446,29 @@ namespace AsbCloudInfrastructure.Repository
{
var query = db.Set<TEntity>().Where(i => i.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);
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<TType>(TelemetryPartDeleteRequest request, CancellationToken token)
where TType : notnull
public async Task<int> DeleteAsync(TelemetryPartDeleteRequest request, CancellationToken token)
{
if (typeof(TType) == typeof(float))
return await DeleteAsync<WitsItemFloat, float>(request, token);
if (typeof(TType) == typeof(int))
return await DeleteAsync<WitsItemInt, int>(request, token);
if (typeof(TType) == typeof(string))
return await DeleteAsync<WitsItemString, string>(request, 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 await Task.FromResult<int>(0);
return result;
}
private async Task<int> DeleteAsync<TEntity, TType>(TelemetryPartDeleteRequest request, CancellationToken token)

View File

@ -87,16 +87,16 @@ namespace AsbCloudInfrastructure.Repository
var query = context.Set<LimitingParameter>()
.Where(o => o.IdTelemetry == request.IdTelemetry);
if (request.GeDate is not null)
{
var geDate = request.GeDate.Value.ToUniversalTime();
query = query.Where(o => o.DateStart <= geDate);
}
if (request.LeDate is not null)
{
var leDate = request.LeDate.Value.ToUniversalTime();
query = query.Where(o => o.DateEnd >= leDate);
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;

View File

@ -64,16 +64,16 @@ namespace AsbCloudInfrastructure.Repository
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);
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;

View File

@ -13,20 +13,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
/// </summary>
public class TelemetryDataEditorService : ITelemetryDataEditorService
{
private readonly ITelemetryDataSaubService dataSaubService;
private readonly ITelemetryDataService<TelemetryDataSpinDto> dataSpinService;
private readonly IDataSaubStatRepository dataSaubStatRepository;
private readonly IMessageService messageService;
private readonly IDrillTestRepository drillTestRepository;
private readonly ILimitingParameterRepository limitingParameterRepository;
private readonly IDetectedOperationRepository detectedOperationRepository;
private readonly IWitsRecordRepository<Record1Dto> witsRecord1Repository;
private readonly IWitsRecordRepository<Record7Dto> witsRecord7Repository;
private readonly IWitsRecordRepository<Record8Dto> witsRecord8Repository;
private readonly IWitsRecordRepository<Record50Dto> witsRecord50Repository;
private readonly IWitsRecordRepository<Record60Dto> witsRecord60Repository;
private readonly IWitsRecordRepository<Record61Dto> witsRecord61Repository;
private readonly IGtrRepository gtrRepository;
private readonly ITelemetryDataEditorService[] repositories;
/// <summary>
///
@ -62,40 +49,34 @@ namespace AsbCloudInfrastructure.Services.SAUB
IGtrRepository gtrRepository
)
{
this.dataSaubService = dataSaubService;
this.dataSpinService = dataSpinService;
this.dataSaubStatRepository = dataSaubStatRepository;
this.messageService = messageService;
this.drillTestRepository = drillTestRepository;
this.limitingParameterRepository = limitingParameterRepository;
this.detectedOperationRepository = detectedOperationRepository;
this.witsRecord1Repository = witsRecord1Repository;
this.witsRecord7Repository = witsRecord7Repository;
this.witsRecord8Repository = witsRecord8Repository;
this.witsRecord50Repository = witsRecord50Repository;
this.witsRecord60Repository = witsRecord60Repository;
this.witsRecord61Repository = witsRecord61Repository;
this.gtrRepository = gtrRepository;
repositories =
[
dataSaubService,
dataSpinService,
dataSaubStatRepository,
messageService,
drillTestRepository,
limitingParameterRepository,
detectedOperationRepository,
witsRecord1Repository,
witsRecord7Repository,
witsRecord8Repository,
witsRecord50Repository,
witsRecord60Repository,
witsRecord61Repository,
gtrRepository,
];
}
public async Task DeleteAsync(TelemetryPartDeleteRequest request, CancellationToken token)
public async Task<int> DeleteAsync(TelemetryPartDeleteRequest request, CancellationToken token)
{
await dataSaubService.DeleteAsync(request, token);
await dataSpinService.DeleteAsync(request, token);
await dataSaubStatRepository.DeleteAsync(request, token);
await messageService.DeleteAsync(request, token);
await drillTestRepository.DeleteAsync(request, token);
await limitingParameterRepository.DeleteAsync(request, token);
await detectedOperationRepository.DeleteAsync(request, token);
await witsRecord1Repository.DeleteAsync(request, token);
await witsRecord7Repository.DeleteAsync(request, token);
await witsRecord8Repository.DeleteAsync(request, token);
await witsRecord50Repository.DeleteAsync(request, token);
await witsRecord60Repository.DeleteAsync(request, token);
await witsRecord61Repository.DeleteAsync(request, token);
await gtrRepository.DeleteAsync<float>(request, token);
await gtrRepository.DeleteAsync<int>(request, token);
await gtrRepository.DeleteAsync<string>(request, token);
int result = 0;
foreach (var repository in repositories)
{
result += await repository.DeleteAsync(request, token);
}
return result;
}
}
}

View File

@ -2,6 +2,7 @@ using AsbCloudApp.Data;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading;
@ -43,29 +44,20 @@ namespace AsbCloudWebApi.Controllers
}
/// <summary>
/// Удаление куска телеметрии
/// Удаление куска телеметрии по запросу
/// </summary>
/// <param name="telemetryId">ключ телеметрии</param>
/// <param name="gDate">начало интервала удаления</param>
/// <param name="lDate">конец интервала удаления</param>
/// <param name="request">запрос</param>
/// <param name="token"></param>
/// <returns></returns>
[HttpDelete("/part/{telemetryId}")]
[HttpDelete("/part")]
[Permission]
public async Task<IActionResult> DeleteAsync(int telemetryId,
DateTimeOffset? gDate,
DateTimeOffset? lDate,
CancellationToken token)
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
public async Task<IActionResult> DeleteAsync([FromQuery] TelemetryPartDeleteRequest request,CancellationToken token)
{
var request = new TelemetryPartDeleteRequest()
{
IdTelemetry = telemetryId,
GeDate = gDate,
LeDate = lDate
};
if(gDate.HasValue || lDate.HasValue)
await telemetryEditorService.DeleteAsync(request, token);
return Ok();
var result = await telemetryEditorService.DeleteAsync(request, token);
return Ok(result);
}
}
}