forked from ddrilling/AsbCloudServer
Рефакторинг репозитория, сервиса
This commit is contained in:
parent
79929dc6d2
commit
25f35b77f5
@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.Json.Serialization;
|
||||
using AsbCloudApp.Data.WellOperation;
|
||||
|
||||
namespace AsbCloudApp.Data.DetectedOperation;
|
||||
@ -9,84 +8,84 @@ namespace AsbCloudApp.Data.DetectedOperation;
|
||||
/// <summary>
|
||||
/// Автоматически определенная операция
|
||||
/// </summary>
|
||||
public class DetectedOperationDto: IId
|
||||
public class DetectedOperationDto : IId
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
[Required]
|
||||
public int Id { get; set; }
|
||||
/// <inheritdoc/>
|
||||
[Required]
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Id телеметрии
|
||||
/// </summary>
|
||||
[Required]
|
||||
public int IdTelemetry { get; set; }
|
||||
/// <summary>
|
||||
/// Id телеметрии
|
||||
/// </summary>
|
||||
[Required]
|
||||
public int IdTelemetry { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Id названия/описания операции
|
||||
/// </summary>
|
||||
[Required]
|
||||
public int IdCategory { get; set; }
|
||||
/// <summary>
|
||||
/// Id названия/описания операции
|
||||
/// </summary>
|
||||
[Required]
|
||||
public int IdCategory { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Id пользователя панели на момент начала операции
|
||||
/// </summary>
|
||||
public int? IdUserAtStart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Пользователь панели оператора
|
||||
/// </summary>
|
||||
public string? TelemetryUserName { get; set; }
|
||||
/// <summary>
|
||||
/// Id пользователя панели на момент начала операции
|
||||
/// </summary>
|
||||
public int? IdUserAtStart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Id пользователя изменившего операцию
|
||||
/// </summary>
|
||||
public int? IdEditor { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Дата завершения операции в часовом поясе скважины
|
||||
/// </summary>
|
||||
[Required]
|
||||
public DateTimeOffset DateEnd { get; set; }
|
||||
/// <summary>
|
||||
/// Дата завершения операции в часовом поясе скважины
|
||||
/// </summary>
|
||||
[Required]
|
||||
public DateTimeOffset DateEnd { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Дата начала операции в часовом поясе скважины
|
||||
/// </summary>
|
||||
[Required]
|
||||
public DateTimeOffset DateStart { get; set; }
|
||||
/// <summary>
|
||||
/// Дата начала операции в часовом поясе скважины
|
||||
/// </summary>
|
||||
[Required]
|
||||
public DateTimeOffset DateStart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// глубина на завершения операции, м
|
||||
/// </summary>
|
||||
[Required]
|
||||
public double DepthEnd { get; set; }
|
||||
/// <summary>
|
||||
/// глубина на завершения операции, м
|
||||
/// </summary>
|
||||
[Required]
|
||||
public double DepthEnd { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// глубина на начало операции, м
|
||||
/// </summary>
|
||||
[Required]
|
||||
public double DepthStart { get; set; }
|
||||
/// <summary>
|
||||
/// глубина на начало операции, м
|
||||
/// </summary>
|
||||
[Required]
|
||||
public double DepthStart { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Продолжительность операции в минутах
|
||||
/// </summary>
|
||||
[Required]
|
||||
public double DurationMinutes => (DateEnd - DateStart).TotalMinutes;
|
||||
/// <summary>
|
||||
/// Продолжительность операции в минутах
|
||||
/// </summary>
|
||||
[Required]
|
||||
public double DurationMinutes => (DateEnd - DateStart).TotalMinutes;
|
||||
|
||||
/// <summary>
|
||||
/// название/описание операции
|
||||
/// </summary>
|
||||
[Required]
|
||||
public WellOperationCategoryDto OperationCategory { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Включенные подсистемы
|
||||
/// </summary>
|
||||
[Required]
|
||||
public EnabledSubsystems EnabledSubsystems { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Флаг включенной подсистемы
|
||||
/// </summary>
|
||||
[Required]
|
||||
public int EnabledSubsystems { get; set; }
|
||||
/// <summary>
|
||||
/// Значение ключевой параметра операции
|
||||
/// </summary>
|
||||
[Required]
|
||||
public double Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// название/описание операции
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public WellOperationCategoryDto? OperationCategory { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ключевой параметр операции
|
||||
/// </summary>
|
||||
[Required]
|
||||
public double Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Доп. инфо по операции
|
||||
/// </summary>
|
||||
public IDictionary<string, object> ExtraData { get; set; } = new Dictionary<string, object>();
|
||||
/// <summary>
|
||||
/// Доп. инфо по операции
|
||||
/// </summary>
|
||||
public IDictionary<string, object> ExtraData { get; set; } = new Dictionary<string, object>();
|
||||
}
|
102
AsbCloudApp/Data/DetectedOperation/EnabledSubsystems.cs
Normal file
102
AsbCloudApp/Data/DetectedOperation/EnabledSubsystems.cs
Normal file
@ -0,0 +1,102 @@
|
||||
namespace AsbCloudApp.Data.DetectedOperation;
|
||||
|
||||
/// <summary>
|
||||
/// Включённые подсистемы
|
||||
/// </summary>
|
||||
public struct EnabledSubsystems
|
||||
{
|
||||
private int value;
|
||||
|
||||
private EnabledSubsystems(int value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public static implicit operator int(EnabledSubsystems param) =>
|
||||
param.value;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public static implicit operator EnabledSubsystems(int param) =>
|
||||
new(param);
|
||||
|
||||
/// <summary>
|
||||
/// Бурение ротором
|
||||
/// </summary>
|
||||
public bool IsAutoRotor
|
||||
{
|
||||
get => (value & (int)EnabledSubsystemsFlags.AutoRotor) > 0;
|
||||
set => UpdateEnabledSubsystems(value, EnabledSubsystemsFlags.AutoRotor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Бурение слайдом
|
||||
/// </summary>
|
||||
public bool IsAutoSlide
|
||||
{
|
||||
get => (value & (int)EnabledSubsystemsFlags.AutoSlide) > 0;
|
||||
set => UpdateEnabledSubsystems(value, EnabledSubsystemsFlags.AutoSlide);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ПРОРАБОТКА
|
||||
/// </summary>
|
||||
public bool IsAutoConditionig
|
||||
{
|
||||
get => (value & (int)EnabledSubsystemsFlags.AutoConditionig) > 0;
|
||||
set => UpdateEnabledSubsystems(value, EnabledSubsystemsFlags.AutoConditionig);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// СПУСК СПО
|
||||
/// </summary>
|
||||
public bool IsAutoSinking
|
||||
{
|
||||
get => (value & (int)EnabledSubsystemsFlags.AutoSinking) > 0;
|
||||
set => UpdateEnabledSubsystems(value, EnabledSubsystemsFlags.AutoSinking);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ПОДЪЕМ СПО
|
||||
/// </summary>
|
||||
public bool IsAutoLifting
|
||||
{
|
||||
get => (value & (int)EnabledSubsystemsFlags.AutoLifting) > 0;
|
||||
set => UpdateEnabledSubsystems(value, EnabledSubsystemsFlags.AutoLifting);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ПОДЪЕМ С ПРОРАБОТКОЙ
|
||||
/// </summary>
|
||||
public bool IsAutoLiftingWithConditionig
|
||||
{
|
||||
get => (value & (int)EnabledSubsystemsFlags.AutoLiftingWithConditionig) > 0;
|
||||
set => UpdateEnabledSubsystems(value, EnabledSubsystemsFlags.AutoLiftingWithConditionig);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Блокировка
|
||||
/// </summary>
|
||||
public bool IsAutoBlocknig
|
||||
{
|
||||
get => (value & (int)EnabledSubsystemsFlags.AutoBlocknig) > 0;
|
||||
set => UpdateEnabledSubsystems(value, EnabledSubsystemsFlags.AutoBlocknig);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Осцилляция
|
||||
/// </summary>
|
||||
public bool IsAutoOscillation
|
||||
{
|
||||
get => (value & (int)EnabledSubsystemsFlags.AutoOscillation) > 0;
|
||||
set => UpdateEnabledSubsystems(value, EnabledSubsystemsFlags.AutoOscillation);
|
||||
}
|
||||
|
||||
private void UpdateEnabledSubsystems(bool isEnable, EnabledSubsystemsFlags flag)
|
||||
{
|
||||
if (isEnable)
|
||||
value |= (int)flag;
|
||||
else
|
||||
value &= ~(int)flag;
|
||||
}
|
||||
}
|
@ -4,7 +4,8 @@ using AsbCloudApp.Requests;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.WellOperation;
|
||||
|
||||
namespace AsbCloudApp.Repositories;
|
||||
|
||||
@ -14,14 +15,29 @@ namespace AsbCloudApp.Repositories;
|
||||
public interface IDetectedOperationRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// Добавление записей
|
||||
/// Добавление нескольких записей
|
||||
/// </summary>
|
||||
/// <param name="dtos"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns>количество добавленных</returns>
|
||||
Task<int> InsertRangeAsync(IEnumerable<DetectedOperationDto> dtos, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Обновить несколько записей
|
||||
/// </summary>
|
||||
/// <param name="idEditor"></param>
|
||||
/// <param name="dtos"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> InsertRange(int? idEditor, IEnumerable<DetectedOperationDto> dtos, CancellationToken token);
|
||||
Task<int> UpdateRangeAsync(IEnumerable<DetectedOperationDto> dtos, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Удаление нескольких записей
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> DeleteRangeAsync(IEnumerable<int> ids, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Получить автоматически определенные операции по телеметрии
|
||||
/// </summary>
|
||||
@ -31,29 +47,12 @@ public interface IDetectedOperationRepository
|
||||
Task<IEnumerable<DetectedOperationDto>> Get(DetectedOperationByTelemetryRequest request, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Редактирование записей
|
||||
/// </summary>
|
||||
/// <param name="idEditor"></param>
|
||||
/// <param name="dtos"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> UpdateRange(int idEditor, IEnumerable<DetectedOperationDto> dtos, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Удалить операции
|
||||
/// Получить страницу списка операций
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> Delete(DetectedOperationByTelemetryRequest request, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Удаление записей
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> DeleteRange(IEnumerable<int> ids, CancellationToken token);
|
||||
Task<PaginationContainer<DetectedOperationDto>> GetPageAsync(DetectedOperationByTelemetryRequest request, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Получение дат последних определённых операций
|
||||
@ -61,4 +60,12 @@ public interface IDetectedOperationRepository
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<IDictionary<int, DateTimeOffset>> GetLastDetectedDatesAsync(CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Удалить операции
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> DeleteAsync(DetectedOperationByTelemetryRequest request, CancellationToken token);
|
||||
}
|
||||
|
@ -13,6 +13,26 @@ namespace AsbCloudApp.Services
|
||||
/// </summary>
|
||||
public interface IDetectedOperationService
|
||||
{
|
||||
/// <summary>
|
||||
/// Добавление операций
|
||||
/// </summary>
|
||||
/// <param name="idEditor"></param>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="dtos"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> InsertRangeManualAsync(int idEditor, int idWell, IEnumerable<DetectedOperationDto> dtos, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Редактирование операций
|
||||
/// </summary>
|
||||
/// <param name="idEditor"></param>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="dtos"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<int> UpdateRangeManualAsync(int idEditor, int idWell, IEnumerable<DetectedOperationDto> dtos, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Список названий операций.
|
||||
/// Если указан idWell, то возвращается список названий операций найденных на указанной скважине.
|
||||
|
@ -151,8 +151,6 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks
|
||||
|
||||
private static DataSaubStatDto CalcStat(DetectedOperationDto operation, Span<TelemetryDataSaubDto> span)
|
||||
{
|
||||
var hasOscillation = EnabledSubsystemsFlags.AutoOscillation.HasEnabledSubsystems(operation.EnabledSubsystems);
|
||||
|
||||
var aggregatedValues = CalcAggregate(span);
|
||||
var dateStart = span[0].DateTime;
|
||||
var dateEnd = span[^1].DateTime;
|
||||
@ -181,7 +179,7 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks
|
||||
RotorSpeed = aggregatedValues.RotorSpeed,
|
||||
IdCategory = operation.IdCategory,
|
||||
EnabledSubsystems = operation.EnabledSubsystems,
|
||||
HasOscillation = hasOscillation,
|
||||
HasOscillation = operation.EnabledSubsystems.IsAutoOscillation,
|
||||
IdTelemetry = operation.IdTelemetry,
|
||||
Flow = aggregatedValues.Flow
|
||||
};
|
||||
|
@ -42,6 +42,7 @@ using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using AsbCloudApp.Data.DetectedOperation;
|
||||
using AsbCloudInfrastructure.Services.ProcessMapPlan.Export;
|
||||
using AsbCloudInfrastructure.Services.WellOperations.Factories;
|
||||
|
||||
@ -51,6 +52,10 @@ namespace AsbCloudInfrastructure
|
||||
{
|
||||
public static void MapsterSetup()
|
||||
{
|
||||
TypeAdapterConfig.GlobalSettings.Default.Config
|
||||
.ForType<DetectedOperationDto, DetectedOperation>()
|
||||
.Ignore(source => source.OperationCategory);
|
||||
|
||||
TypeAdapterConfig.GlobalSettings.Default.Config
|
||||
.ForType<ScheduleDto, Schedule>()
|
||||
.Ignore(source => source.Driller);
|
||||
|
@ -1,5 +1,4 @@
|
||||
using AsbCloudApp.Data.DetectedOperation;
|
||||
using AsbCloudApp.Exceptions;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudApp.Requests;
|
||||
using AsbCloudApp.Services;
|
||||
@ -12,38 +11,51 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
using AsbCloudApp.Data;
|
||||
|
||||
namespace AsbCloudInfrastructure.Repository;
|
||||
|
||||
public class DetectedOperationRepository : IDetectedOperationRepository
|
||||
public class DetectedOperationRepository : CrudRepositoryBase<DetectedOperationDto, DetectedOperation>, IDetectedOperationRepository
|
||||
{
|
||||
private readonly IAsbCloudDbContext dbContext;
|
||||
private readonly ITelemetryService telemetryService;
|
||||
|
||||
public DetectedOperationRepository(IAsbCloudDbContext dbContext,
|
||||
public DetectedOperationRepository(IAsbCloudDbContext context,
|
||||
ITelemetryService telemetryService)
|
||||
: base(context)
|
||||
{
|
||||
this.dbContext = dbContext;
|
||||
this.telemetryService = telemetryService;
|
||||
}
|
||||
|
||||
public async Task<int> Delete(DetectedOperationByTelemetryRequest request, CancellationToken token)
|
||||
|
||||
public async Task<int> DeleteAsync(DetectedOperationByTelemetryRequest request, CancellationToken token)
|
||||
{
|
||||
var query = BuildQuery(request);
|
||||
dbContext.Set<DetectedOperation>().RemoveRange(query);
|
||||
return await dbContext.SaveChangesAsync(token);
|
||||
}
|
||||
|
||||
public async Task<int> DeleteRange(IEnumerable<int> ids, CancellationToken token)
|
||||
public async Task<PaginationContainer<DetectedOperationDto>> GetPageAsync(DetectedOperationByTelemetryRequest request, CancellationToken token)
|
||||
{
|
||||
var query = dbContext.Set<DetectedOperation>()
|
||||
.Where(e => ids.Contains( e.Id));
|
||||
var skip = request.Skip ?? 0;
|
||||
var take = request.Take ?? 32;
|
||||
|
||||
dbContext.Set<DetectedOperation>()
|
||||
.RemoveRange(query);
|
||||
var query = BuildQuery(request);
|
||||
|
||||
return await dbContext.SaveChangesAsync(token);
|
||||
var entities = await query.Skip(skip)
|
||||
.Take(take)
|
||||
.AsNoTracking()
|
||||
.ToArrayAsync(token);
|
||||
|
||||
var offset = telemetryService.GetTimezone(request.IdTelemetry).Offset;
|
||||
|
||||
var paginationContainer = new PaginationContainer<DetectedOperationDto>
|
||||
{
|
||||
Skip = skip,
|
||||
Take = take,
|
||||
Count = await query.CountAsync(token),
|
||||
Items = entities.Select(o => Convert(o, offset))
|
||||
};
|
||||
|
||||
return paginationContainer;
|
||||
}
|
||||
|
||||
public async Task<IDictionary<int, DateTimeOffset>> GetLastDetectedDatesAsync(CancellationToken token) =>
|
||||
@ -60,82 +72,18 @@ public class DetectedOperationRepository : IDetectedOperationRepository
|
||||
{
|
||||
var query = BuildQuery(request)
|
||||
.Include(o => o.OperationCategory);
|
||||
var entities = await query.ToArrayAsync(token);
|
||||
var entities = await query.AsNoTracking().ToArrayAsync(token);
|
||||
var offset = telemetryService.GetTimezone(request.IdTelemetry).Offset;
|
||||
var dtos = entities.Select(o => Convert(o, offset));
|
||||
|
||||
return dtos;
|
||||
}
|
||||
|
||||
public async Task<int> InsertRange(int? idEditor, IEnumerable<DetectedOperationDto> dtos, CancellationToken token)
|
||||
{
|
||||
if(!dtos.Any())
|
||||
return 0;
|
||||
|
||||
var entities = dtos.Select(Convert);
|
||||
var dbset = dbContext.Set<DetectedOperation>();
|
||||
foreach(var entity in entities)
|
||||
{
|
||||
if (idEditor.HasValue)
|
||||
entity.IdEditor = idEditor.Value;
|
||||
|
||||
entity.Creation = DateTimeOffset.UtcNow;
|
||||
entity.Id = default;
|
||||
dbset.Add(entity);
|
||||
}
|
||||
|
||||
return await dbContext.SaveChangesWithExceptionHandling(token);
|
||||
}
|
||||
|
||||
public async Task<int> UpdateRange(int idEditor, IEnumerable<DetectedOperationDto> dtos, CancellationToken token)
|
||||
{
|
||||
if (!dtos.Any())
|
||||
return 0;
|
||||
|
||||
var ids = dtos
|
||||
.Select(o => o.Id)
|
||||
.Distinct()
|
||||
.ToArray();
|
||||
|
||||
if (ids.Any(id => id == default))
|
||||
throw new ArgumentInvalidException(nameof(dtos), "Все записи должны иметь Id");
|
||||
|
||||
if (ids.Length != dtos.Count())
|
||||
throw new ArgumentInvalidException(nameof(dtos), "Все записи должны иметь уникальные Id");
|
||||
|
||||
var dbSet = dbContext.Set<DetectedOperation>();
|
||||
|
||||
var existingEntitiesCount = await dbSet
|
||||
.Where(o => ids.Contains(o.Id))
|
||||
.CountAsync(token);
|
||||
|
||||
if (ids.Length != existingEntitiesCount)
|
||||
throw new ArgumentInvalidException(nameof(dtos), "Все записи должны существовать в БД");
|
||||
|
||||
var entities = dtos
|
||||
.Select(dto =>
|
||||
{
|
||||
var entity = Convert(dto);
|
||||
entity.IdEditor = idEditor;
|
||||
return entity;
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
var entries = new EntityEntry<DetectedOperation>[entities.Length];
|
||||
for(var i = 0; i < entities.Length; i++)
|
||||
entries[i] = dbSet.Update(entities[i]);
|
||||
|
||||
var result = await dbContext.SaveChangesWithExceptionHandling(token);
|
||||
|
||||
foreach (var entry in entries)
|
||||
entry.State = EntityState.Detached;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private IQueryable<DetectedOperation> BuildQuery(DetectedOperationByTelemetryRequest request)
|
||||
{
|
||||
var query = dbContext.Set<DetectedOperation>()
|
||||
.OrderBy(o => o.DateStart)
|
||||
.ThenBy(o => o.DepthStart)
|
||||
.Where(o => o.IdTelemetry == request.IdTelemetry);
|
||||
|
||||
if (request.IdsCategories.Any())
|
||||
@ -160,32 +108,21 @@ public class DetectedOperationRepository : IDetectedOperationRepository
|
||||
}
|
||||
|
||||
if (request.SortFields?.Any() == true)
|
||||
{
|
||||
query = query.SortBy(request.SortFields);
|
||||
}
|
||||
else
|
||||
query = query
|
||||
.OrderBy(o => o.DateStart)
|
||||
.ThenBy(o => o.DepthStart);
|
||||
|
||||
if (request.Skip.HasValue)
|
||||
query = query.Skip((int)request.Skip);
|
||||
|
||||
if (request.Take.HasValue)
|
||||
query = query.Take((int)request.Take);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
|
||||
private static DetectedOperationDto Convert(DetectedOperation src, TimeSpan offset)
|
||||
{
|
||||
var dto = src.Adapt<DetectedOperationDto>();
|
||||
dto.DateStart = src.DateStart.ToOffset(offset);
|
||||
dto.DateEnd = src.DateEnd.ToOffset(offset);
|
||||
dto.EnabledSubsystems = src.EnabledSubsystems;
|
||||
return dto;
|
||||
}
|
||||
|
||||
private static DetectedOperation Convert(DetectedOperationDto src)
|
||||
protected override DetectedOperation Convert(DetectedOperationDto src)
|
||||
{
|
||||
var entity = src.Adapt<DetectedOperation>();
|
||||
entity.DateStart = src.DateStart.ToUniversalTime();
|
||||
|
@ -162,8 +162,7 @@ public class DetectedOperationExportService
|
||||
private static string GetCategoryName(IEnumerable<WellOperationCategoryDto> wellOperationCategories, DetectedOperationDto current)
|
||||
{
|
||||
var idCategory = current.IdCategory;
|
||||
if (idCategory == WellOperationCategory.IdSlide &&
|
||||
EnabledSubsystemsFlags.AutoOscillation.HasEnabledSubsystems(current.EnabledSubsystems))
|
||||
if (idCategory == WellOperationCategory.IdSlide && current.EnabledSubsystems.IsAutoOscillation)
|
||||
return "Бурение в слайде с осцилляцией";
|
||||
|
||||
var category = wellOperationCategories.FirstOrDefault(o => o.Id == current.IdCategory);
|
||||
|
@ -11,6 +11,7 @@ using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Data.WellOperation;
|
||||
using AsbCloudApp.Exceptions;
|
||||
using AsbCloudInfrastructure.Services.DetectOperations.Detectors;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.DetectOperations;
|
||||
@ -80,6 +81,43 @@ public class DetectedOperationService : IDetectedOperationService
|
||||
return dtos;
|
||||
}
|
||||
|
||||
public async Task<int> InsertRangeManualAsync(int idEditor, int idWell, IEnumerable<DetectedOperationDto> dtos, CancellationToken token)
|
||||
{
|
||||
var idTelemetry = await GetIdTelemetryByWell(idWell, token);
|
||||
|
||||
foreach (var dto in dtos)
|
||||
{
|
||||
dto.IdEditor = idEditor;
|
||||
dto.IdTelemetry = idTelemetry;
|
||||
}
|
||||
|
||||
return await operationRepository.InsertRangeAsync(dtos, token);
|
||||
}
|
||||
|
||||
public async Task<int> UpdateRangeManualAsync(int idEditor, int idWell, IEnumerable<DetectedOperationDto> dtos, CancellationToken token)
|
||||
{
|
||||
var idTelemetry = await GetIdTelemetryByWell(idWell, token);
|
||||
|
||||
foreach (var dto in dtos)
|
||||
{
|
||||
dto.IdEditor = idEditor;
|
||||
dto.IdTelemetry = idTelemetry;
|
||||
}
|
||||
|
||||
return await operationRepository.UpdateRangeAsync(dtos, token);
|
||||
}
|
||||
|
||||
private async Task<int> GetIdTelemetryByWell(int idWell, CancellationToken token)
|
||||
{
|
||||
var well = await wellService.GetOrDefaultAsync(idWell, token) ??
|
||||
throw new ArgumentInvalidException(nameof(idWell), "Well doesn`t exist");
|
||||
|
||||
var idTelemetry = well.IdTelemetry ??
|
||||
throw new ArgumentInvalidException(nameof(idWell), "У скважины отсутствует телеметрия");
|
||||
|
||||
return idTelemetry;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<WellOperationCategoryDto>> GetCategoriesAsync(int? idWell, CancellationToken token)
|
||||
{
|
||||
if(idWell is null)
|
||||
@ -213,7 +251,7 @@ public class DetectedOperationService : IDetectedOperationService
|
||||
return 0;
|
||||
|
||||
var requestByTelemetry = new DetectedOperationByTelemetryRequest(well.IdTelemetry.Value, request);
|
||||
var result = await operationRepository.Delete(requestByTelemetry, token);
|
||||
var result = await operationRepository.DeleteAsync(requestByTelemetry, token);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ public class WorkOperationDetection: Work
|
||||
var detectedOperations = await detectedOperationService.DetectOperationsAsync(telemetryId, beginDate, token);
|
||||
|
||||
if (detectedOperations.Any())
|
||||
await detectedOperationRepository.InsertRange(null, detectedOperations, token);
|
||||
await detectedOperationRepository.InsertRangeAsync(detectedOperations, token);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.DetectedOperation;
|
||||
using AsbCloudApp.Data.DetectedOperation;
|
||||
using AsbCloudApp.Requests;
|
||||
using AsbCloudApp.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
@ -7,6 +6,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.WellOperation;
|
||||
using AsbCloudApp.Exceptions;
|
||||
using AsbCloudApp.Repositories;
|
||||
@ -52,7 +52,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
{
|
||||
var idUser = await AssertUserHasAccessToWellAsync(idWell, token);
|
||||
|
||||
var result = await detectedOperationRepository.InsertRange(idUser, dtos, token);
|
||||
var result = await detectedOperationService.InsertRangeManualAsync(idUser, idWell, dtos, token);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
@ -70,7 +70,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
{
|
||||
var idUser = await AssertUserHasAccessToWellAsync(idWell, token);
|
||||
|
||||
var result = await detectedOperationRepository.UpdateRange(idUser, dtos, token);
|
||||
var result = await detectedOperationService.UpdateRangeManualAsync(idUser, idWell, dtos, token);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
@ -88,7 +88,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
{
|
||||
await AssertUserHasAccessToWellAsync(idWell, token);
|
||||
|
||||
var result = await detectedOperationRepository.DeleteRange(ids, token);
|
||||
var result = await detectedOperationRepository.DeleteRangeAsync(ids, token);
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
@ -117,9 +117,8 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(DetectedOperationDto), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetAsync(int idWell,
|
||||
[FromQuery] DetectedOperationRequest request,
|
||||
[ProducesResponseType(typeof(PaginationContainer<DetectedOperationDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetAsync(int idWell, [FromQuery] DetectedOperationRequest request,
|
||||
CancellationToken token)
|
||||
{
|
||||
await AssertUserHasAccessToWellAsync(idWell, token);
|
||||
@ -131,7 +130,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
|
||||
var requestToService = new DetectedOperationByTelemetryRequest(well.IdTelemetry.Value, request);
|
||||
|
||||
var result = await detectedOperationRepository.Get(requestToService, token);
|
||||
var result = await detectedOperationRepository.GetPageAsync(requestToService, token);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user