forked from ddrilling/AsbCloudServer
Добавил функционал получения ствола скважины
This commit is contained in:
parent
2b064fe463
commit
04c2266591
64
AsbCloudApp/Data/WellboreDto.cs
Normal file
64
AsbCloudApp/Data/WellboreDto.cs
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace AsbCloudApp.Data;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ствол скважины
|
||||||
|
/// </summary>
|
||||||
|
public class WellboreDto
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Идентификатор
|
||||||
|
/// </summary>
|
||||||
|
public int? Id { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Название
|
||||||
|
/// </summary>
|
||||||
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Идентификатор скважины
|
||||||
|
/// </summary>
|
||||||
|
public int IdWell { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Состояние скважины
|
||||||
|
/// </summary>
|
||||||
|
public int IdWellState { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Идентификатор телеметрии
|
||||||
|
/// </summary>
|
||||||
|
public int? IdWellTelemetry { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Временная зона скважины
|
||||||
|
/// </summary>
|
||||||
|
public SimpleTimezoneDto? WellTimezone { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Название скважины
|
||||||
|
/// </summary>
|
||||||
|
public string WellName { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Начальная глубина ствола
|
||||||
|
/// </summary>
|
||||||
|
public double? DepthFrom { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конечная глубина скважины
|
||||||
|
/// </summary>
|
||||||
|
public double? DepthTo { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Дата начала первой операции
|
||||||
|
/// </summary>
|
||||||
|
public DateTimeOffset? DateFrom { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Дата завершения последней операции
|
||||||
|
/// </summary>
|
||||||
|
public DateTimeOffset? DateTo { get; set; }
|
||||||
|
}
|
@ -74,6 +74,24 @@ namespace AsbCloudApp.Repositories
|
|||||||
WellOperationRequest request,
|
WellOperationRequest request,
|
||||||
CancellationToken token);
|
CancellationToken token);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение ствола скважины
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell"></param>
|
||||||
|
/// <param name="idWellSectionType"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<WellboreDto?> GetWellboreAsync(int idWell, int? idWellSectionType, CancellationToken cancellationToken);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение стволов скважин
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<PaginationContainer<WellboreDto>> GetWellboresAsync(WellboreRequest request,
|
||||||
|
CancellationToken cancellationToken);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавить несколько операций за один раз
|
/// Добавить несколько операций за один раз
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
14
AsbCloudApp/Requests/WellboreRequest.cs
Normal file
14
AsbCloudApp/Requests/WellboreRequest.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace AsbCloudApp.Requests;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Параметры запроса для ствола скважины
|
||||||
|
/// </summary>
|
||||||
|
public class WellboreRequest : RequestBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Пары идентификаторов скважины и секции
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<(int idWell, int? idWellSectionType)> Ids { get; set; } = null!;
|
||||||
|
}
|
@ -255,6 +255,79 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
return dtos;
|
return dtos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<WellboreDto?> GetWellboreAsync(int idWell, int? idWellSectionType,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var well = await db.Wells.Include(w => w.WellOperations)
|
||||||
|
.FirstOrDefaultAsync(w => w.Id == idWell, cancellationToken);
|
||||||
|
|
||||||
|
if (well is null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var factOperations = well.WellOperations.AsQueryable();
|
||||||
|
|
||||||
|
var section = await db.WellSectionTypes
|
||||||
|
.FirstOrDefaultAsync(w => w.Id == idWellSectionType, cancellationToken);
|
||||||
|
|
||||||
|
if (section is not null)
|
||||||
|
factOperations = factOperations.Where(w => w.IdWellSectionType == section.Id);
|
||||||
|
|
||||||
|
factOperations = factOperations.OrderBy(f => f.DateStart);
|
||||||
|
|
||||||
|
var firstOperation = factOperations.FirstOrDefault();
|
||||||
|
var lastOperation = factOperations.LastOrDefault();
|
||||||
|
|
||||||
|
return new WellboreDto
|
||||||
|
{
|
||||||
|
Id = section?.Id,
|
||||||
|
Name = section?.Caption,
|
||||||
|
IdWell = well.Id,
|
||||||
|
WellName = well.Caption,
|
||||||
|
IdWellState = well.IdState,
|
||||||
|
IdWellTelemetry = well.IdTelemetry,
|
||||||
|
WellTimezone = well.Timezone.Adapt<SimpleTimezoneDto>(),
|
||||||
|
DepthFrom = firstOperation?.DepthStart,
|
||||||
|
DepthTo = lastOperation?.DepthEnd,
|
||||||
|
DateFrom = firstOperation?.DateStart,
|
||||||
|
DateTo = lastOperation?.DateStart.AddHours(lastOperation.DurationHours),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<PaginationContainer<WellboreDto>> GetWellboresAsync(WellboreRequest request,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var wellbores = new List<WellboreDto>();
|
||||||
|
|
||||||
|
var skip = request.Skip ?? 0;
|
||||||
|
var take = request.Take ?? 10;
|
||||||
|
|
||||||
|
foreach (var id in request.Ids)
|
||||||
|
{
|
||||||
|
var wellbore = await GetWellboreAsync(id.idWell,
|
||||||
|
id.idWellSectionType,
|
||||||
|
cancellationToken);
|
||||||
|
|
||||||
|
if (wellbore is null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
wellbores.Add(wellbore);
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = new PaginationContainer<WellboreDto>
|
||||||
|
{
|
||||||
|
Skip = skip,
|
||||||
|
Take = take,
|
||||||
|
Count = wellbores.Count
|
||||||
|
};
|
||||||
|
|
||||||
|
if (result.Count < skip)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
result.Items = wellbores.Skip(skip).Take(take).ToList();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public async Task<int> InsertRangeAsync(
|
public async Task<int> InsertRangeAsync(
|
||||||
IEnumerable<WellOperationDto> wellOperationDtos,
|
IEnumerable<WellOperationDto> wellOperationDtos,
|
||||||
|
90
AsbCloudWebApi/Controllers/WellboreController.cs
Normal file
90
AsbCloudWebApi/Controllers/WellboreController.cs
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Exceptions;
|
||||||
|
using AsbCloudApp.Repositories;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace AsbCloudWebApi.Controllers;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ствол скважины
|
||||||
|
/// </summary>
|
||||||
|
[Authorize]
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/well/[controller]")]
|
||||||
|
public class WellboreController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly IWellOperationRepository wellOperationRepository;
|
||||||
|
|
||||||
|
public WellboreController(IWellOperationRepository wellOperationRepository)
|
||||||
|
{
|
||||||
|
this.wellOperationRepository = wellOperationRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение ствола скважины
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell">Id скважины</param>
|
||||||
|
/// <param name="idSectionType">Опциональный параметр. Id типа секции</param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
|
||||||
|
[HttpGet("{idWell:int}")]
|
||||||
|
[ProducesResponseType(typeof(WellboreDto), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public async Task<IActionResult> GetAsync(int idWell, int? idSectionType, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return Ok(await wellOperationRepository.GetWellboreAsync(idWell, idSectionType, cancellationToken));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение списка стволов скважин
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ids">Пары идентификаторов скважины и секции</param>
|
||||||
|
/// <param name="skip">Опциональный параметр. Количество пропускаемых записей</param>
|
||||||
|
/// <param name="take">Опциональный параметр. Количество получаемых записей</param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet]
|
||||||
|
[ProducesResponseType(typeof(PaginationContainer<WellboreDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public async Task<IActionResult> GetAllAsync([FromQuery] IEnumerable<string> ids,
|
||||||
|
int? skip,
|
||||||
|
int? take,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var request = new WellboreRequest
|
||||||
|
{
|
||||||
|
Ids = ParseIds(ids),
|
||||||
|
Skip = skip,
|
||||||
|
Take = take
|
||||||
|
};
|
||||||
|
|
||||||
|
return Ok(await wellOperationRepository.GetWellboresAsync(request, cancellationToken));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IEnumerable<(int, int?)> ParseIds(IEnumerable<string> ids)
|
||||||
|
{
|
||||||
|
var result = new List<(int, int?)>();
|
||||||
|
|
||||||
|
foreach (var id in ids)
|
||||||
|
{
|
||||||
|
var idPair = id.Split(',');
|
||||||
|
|
||||||
|
if (!int.TryParse(idPair[0], out var idWell))
|
||||||
|
throw new ArgumentInvalidException("Не удалось получить Id скважины", nameof(ids));
|
||||||
|
|
||||||
|
if (idPair.Length < 2 || !int.TryParse(idPair[1], out var idWellSectionType))
|
||||||
|
{
|
||||||
|
result.Add((idWell, null));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
result.Add((idWell, idWellSectionType));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user