forked from ddrilling/AsbCloudServer
Рефакторинг + доработки
1. Переделал логику получения стволов скважин. 2. Поправил контроллер. 3. Рефакторинг DTO ствола.
This commit is contained in:
parent
04c2266591
commit
3702cf2e8c
@ -10,12 +10,12 @@ public class WellboreDto
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Идентификатор
|
/// Идентификатор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int? Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Название
|
/// Название
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? Name { get; set; }
|
public string Name { get; set; } = null!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Идентификатор скважины
|
/// Идентификатор скважины
|
||||||
@ -45,20 +45,20 @@ public class WellboreDto
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Начальная глубина ствола
|
/// Начальная глубина ствола
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double? DepthFrom { get; set; }
|
public double DepthFrom { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конечная глубина скважины
|
/// Конечная глубина скважины
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double? DepthTo { get; set; }
|
public double DepthTo { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Дата начала первой операции
|
/// Дата начала первой операции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTimeOffset? DateFrom { get; set; }
|
public DateTimeOffset DateFrom { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Дата завершения последней операции
|
/// Дата завершения последней операции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DateTimeOffset? DateTo { get; set; }
|
public DateTimeOffset DateTo { get; set; }
|
||||||
}
|
}
|
@ -78,10 +78,10 @@ namespace AsbCloudApp.Repositories
|
|||||||
/// Получение ствола скважины
|
/// Получение ствола скважины
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell"></param>
|
/// <param name="idWell"></param>
|
||||||
/// <param name="idWellSectionType"></param>
|
/// <param name="idSection"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<WellboreDto?> GetWellboreAsync(int idWell, int? idWellSectionType, CancellationToken cancellationToken);
|
Task<WellboreDto?> GetWellboreAsync(int idWell, int idSection, CancellationToken cancellationToken);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение стволов скважин
|
/// Получение стволов скважин
|
||||||
@ -89,8 +89,7 @@ namespace AsbCloudApp.Repositories
|
|||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<PaginationContainer<WellboreDto>> GetWellboresAsync(WellboreRequest request,
|
Task<IEnumerable<WellboreDto>> GetWellboresAsync(WellboreRequest request, CancellationToken cancellationToken);
|
||||||
CancellationToken cancellationToken);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавить несколько операций за один раз
|
/// Добавить несколько операций за один раз
|
||||||
|
@ -10,5 +10,5 @@ public class WellboreRequest : RequestBase
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Пары идентификаторов скважины и секции
|
/// Пары идентификаторов скважины и секции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IEnumerable<(int idWell, int? idWellSectionType)> Ids { get; set; } = null!;
|
public IEnumerable<(int idWell, int? idSection)> Ids { get; set; } = null!;
|
||||||
}
|
}
|
@ -255,77 +255,89 @@ namespace AsbCloudInfrastructure.Repository
|
|||||||
return dtos;
|
return dtos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<WellboreDto?> GetWellboreAsync(int idWell, int? idWellSectionType,
|
public async Task<WellboreDto?> GetWellboreAsync(int idWell, int idSection, CancellationToken cancellationToken)
|
||||||
CancellationToken cancellationToken)
|
|
||||||
{
|
{
|
||||||
var well = await db.Wells.Include(w => w.WellOperations)
|
var well = await db.Wells.Include(w => w.WellOperations)
|
||||||
.FirstOrDefaultAsync(w => w.Id == idWell, cancellationToken);
|
.FirstOrDefaultAsync(w => w.Id == idWell, cancellationToken);
|
||||||
|
|
||||||
if (well is null)
|
var section = await db.WellSectionTypes
|
||||||
|
.FirstOrDefaultAsync(w => w.Id == idSection, cancellationToken);
|
||||||
|
|
||||||
|
if (well is null || section is null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var factOperations = well.WellOperations.AsQueryable();
|
var factOperations = well.WellOperations
|
||||||
|
.Where(o => o.IdType == WellOperation.IdOperationTypeFact &&
|
||||||
|
o.IdWellSectionType == section.Id)
|
||||||
|
.OrderBy(o => o.DateStart);
|
||||||
|
|
||||||
var section = await db.WellSectionTypes
|
if (!factOperations.Any())
|
||||||
.FirstOrDefaultAsync(w => w.Id == idWellSectionType, cancellationToken);
|
return null;
|
||||||
|
|
||||||
if (section is not null)
|
var firstOperation = factOperations.First();
|
||||||
factOperations = factOperations.Where(w => w.IdWellSectionType == section.Id);
|
var lastOperation = factOperations.Last();
|
||||||
|
|
||||||
factOperations = factOperations.OrderBy(f => f.DateStart);
|
|
||||||
|
|
||||||
var firstOperation = factOperations.FirstOrDefault();
|
|
||||||
var lastOperation = factOperations.LastOrDefault();
|
|
||||||
|
|
||||||
return new WellboreDto
|
return new WellboreDto
|
||||||
{
|
{
|
||||||
Id = section?.Id,
|
Id = section.Id,
|
||||||
Name = section?.Caption,
|
Name = section.Caption,
|
||||||
IdWell = well.Id,
|
IdWell = well.Id,
|
||||||
WellName = well.Caption,
|
WellName = well.Caption,
|
||||||
IdWellState = well.IdState,
|
IdWellState = well.IdState,
|
||||||
IdWellTelemetry = well.IdTelemetry,
|
IdWellTelemetry = well.IdTelemetry,
|
||||||
WellTimezone = well.Timezone.Adapt<SimpleTimezoneDto>(),
|
WellTimezone = well.Timezone.Adapt<SimpleTimezoneDto>(),
|
||||||
DepthFrom = firstOperation?.DepthStart,
|
DepthFrom = firstOperation.DepthStart,
|
||||||
DepthTo = lastOperation?.DepthEnd,
|
DepthTo = lastOperation.DepthEnd,
|
||||||
DateFrom = firstOperation?.DateStart,
|
DateFrom = firstOperation.DateStart,
|
||||||
DateTo = lastOperation?.DateStart.AddHours(lastOperation.DurationHours),
|
DateTo = lastOperation.DateStart.AddHours(lastOperation.DurationHours),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<PaginationContainer<WellboreDto>> GetWellboresAsync(WellboreRequest request,
|
public async Task<IEnumerable<WellboreDto>> GetWellboresAsync(WellboreRequest request, CancellationToken cancellationToken)
|
||||||
CancellationToken cancellationToken)
|
|
||||||
{
|
{
|
||||||
var wellbores = new List<WellboreDto>();
|
var wellbores = new List<WellboreDto>();
|
||||||
|
|
||||||
var skip = request.Skip ?? 0;
|
var skip = request.Skip ?? 0;
|
||||||
var take = request.Take ?? 10;
|
var take = request.Take ?? 10;
|
||||||
|
|
||||||
foreach (var id in request.Ids)
|
var sections = GetSectionTypes()
|
||||||
{
|
.ToDictionary(w => w.Id, w => w);
|
||||||
var wellbore = await GetWellboreAsync(id.idWell,
|
|
||||||
id.idWellSectionType,
|
|
||||||
cancellationToken);
|
|
||||||
|
|
||||||
if (wellbore is null)
|
foreach (var (idWell, idSection) in request.Ids)
|
||||||
|
{
|
||||||
|
var well = await db.Wells.Include(w => w.WellOperations)
|
||||||
|
.FirstOrDefaultAsync(w => w.Id == idWell, cancellationToken);
|
||||||
|
|
||||||
|
if (well is null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
wellbores.Add(wellbore);
|
var factOperations = well.WellOperations
|
||||||
|
.Where(o => o.IdType == WellOperation.IdOperationTypeFact)
|
||||||
|
.OrderBy(o => o.DateStart)
|
||||||
|
.GroupBy(o => o.IdWellSectionType);
|
||||||
|
|
||||||
|
if(idSection.HasValue)
|
||||||
|
factOperations = factOperations.Where(w => w.Key == idSection);
|
||||||
|
|
||||||
|
wellbores.AddRange(from factOperation in factOperations
|
||||||
|
let firstOperation = factOperation.First()
|
||||||
|
let lastOperation = factOperation.Last()
|
||||||
|
select new WellboreDto
|
||||||
|
{
|
||||||
|
Id = sections[factOperation.Key].Id,
|
||||||
|
Name = sections[factOperation.Key].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),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = new PaginationContainer<WellboreDto>
|
return wellbores.Skip(skip).Take(take);
|
||||||
{
|
|
||||||
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/>
|
||||||
|
@ -6,6 +6,7 @@ using AsbCloudApp.Exceptions;
|
|||||||
using AsbCloudApp.Repositories;
|
using AsbCloudApp.Repositories;
|
||||||
using AsbCloudApp.Requests;
|
using AsbCloudApp.Requests;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers;
|
namespace AsbCloudWebApi.Controllers;
|
||||||
@ -29,15 +30,21 @@ public class WellboreController : ControllerBase
|
|||||||
/// Получение ствола скважины
|
/// Получение ствола скважины
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell">Id скважины</param>
|
/// <param name="idWell">Id скважины</param>
|
||||||
/// <param name="idSectionType">Опциональный параметр. Id типа секции</param>
|
/// <param name="idSection">Id типа секции скважины</param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
|
||||||
[HttpGet("{idWell:int}")]
|
[HttpGet("{idWell:int}/{idSection:int}")]
|
||||||
[ProducesResponseType(typeof(WellboreDto), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(WellboreDto), StatusCodes.Status200OK)]
|
||||||
public async Task<IActionResult> GetAsync(int idWell, int? idSectionType, CancellationToken cancellationToken)
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||||
|
public async Task<IActionResult> GetAsync(int idWell, int idSection, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return Ok(await wellOperationRepository.GetWellboreAsync(idWell, idSectionType, cancellationToken));
|
var wellbore = await wellOperationRepository.GetWellboreAsync(idWell, idSection, cancellationToken);
|
||||||
|
|
||||||
|
if (wellbore is null)
|
||||||
|
return NoContent();
|
||||||
|
|
||||||
|
return Ok(wellbore);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -49,7 +56,7 @@ public class WellboreController : ControllerBase
|
|||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[ProducesResponseType(typeof(PaginationContainer<WellboreDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<WellboreDto>), StatusCodes.Status200OK)]
|
||||||
public async Task<IActionResult> GetAllAsync([FromQuery] IEnumerable<string> ids,
|
public async Task<IActionResult> GetAllAsync([FromQuery] IEnumerable<string> ids,
|
||||||
int? skip,
|
int? skip,
|
||||||
int? take,
|
int? take,
|
||||||
|
Loading…
Reference in New Issue
Block a user