forked from ddrilling/AsbCloudServer
Merge pull request 'Получение индекса страницы с нужной операцией ГГД' (#287) from feature/well_operation into dev
Reviewed-on: https://test.digitaldrilling.ru:8443/DDrilling/AsbCloudServer/pulls/287
This commit is contained in:
commit
b2a31d92ec
@ -34,6 +34,23 @@ namespace AsbCloudApp.Repositories
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<PaginationContainer<WellOperationDto>> GetPageAsync(WellOperationRequest request, CancellationToken token);
|
Task<PaginationContainer<WellOperationDto>> GetPageAsync(WellOperationRequest request, CancellationToken token);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получить страницу с операцией
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell"></param>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="operationType"></param>
|
||||||
|
/// <param name="take"></param>
|
||||||
|
/// <param name="sortFields"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<PaginationContainer<WellOperationDto>?> GetPageAsync(int idWell,
|
||||||
|
int id,
|
||||||
|
int operationType,
|
||||||
|
int? take,
|
||||||
|
IEnumerable<string>? sortFields,
|
||||||
|
CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить статистику операции по скважине с группировкой по категориям
|
/// Получить статистику операции по скважине с группировкой по категориям
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -71,6 +71,48 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
|||||||
return paginationContainer;
|
return paginationContainer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<PaginationContainer<WellOperationDto>?> GetPageAsync(int idWell,
|
||||||
|
int id,
|
||||||
|
int operationType,
|
||||||
|
int? take,
|
||||||
|
IEnumerable<string>? sortFields,
|
||||||
|
CancellationToken token)
|
||||||
|
{
|
||||||
|
var request = new WellOperationRequest(new[] { idWell })
|
||||||
|
{
|
||||||
|
OperationType = operationType,
|
||||||
|
SortFields = sortFields,
|
||||||
|
};
|
||||||
|
|
||||||
|
var (wellOperations, count) = await GetWithDaysAndNpvAsync(request, token);
|
||||||
|
|
||||||
|
var skip = 0;
|
||||||
|
take ??= 32;
|
||||||
|
|
||||||
|
while (skip < count)
|
||||||
|
{
|
||||||
|
var page = wellOperations.Skip(skip)
|
||||||
|
.Take(take.Value);
|
||||||
|
|
||||||
|
if (page.Any(x => x.Id == id))
|
||||||
|
{
|
||||||
|
var paginationContainer = new PaginationContainer<WellOperationDto>
|
||||||
|
{
|
||||||
|
Skip = skip,
|
||||||
|
Take = take.Value,
|
||||||
|
Items = page,
|
||||||
|
Count = count
|
||||||
|
};
|
||||||
|
|
||||||
|
return paginationContainer;
|
||||||
|
}
|
||||||
|
|
||||||
|
skip += take.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<WellGroupOpertionDto>> GetGroupOperationsStatAsync(WellOperationRequest request, CancellationToken token)
|
public async Task<IEnumerable<WellGroupOpertionDto>> GetGroupOperationsStatAsync(WellOperationRequest request, CancellationToken token)
|
||||||
{
|
{
|
||||||
var query = BuildQuery(request);
|
var query = BuildQuery(request);
|
||||||
@ -209,9 +251,7 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
|||||||
var count = 0;
|
var count = 0;
|
||||||
foreach (var wellOperationsWithType in groupedByWellAndType)
|
foreach (var wellOperationsWithType in groupedByWellAndType)
|
||||||
{
|
{
|
||||||
var firstWellOperation = wellOperationsWithType
|
var firstWellOperation = wellOperationsWithType.MinBy(e => e.DateStart);
|
||||||
.OrderBy(e => e.DateStart)
|
|
||||||
.FirstOrDefault()!;
|
|
||||||
|
|
||||||
var operationsWithNpt = wellOperationsWithType
|
var operationsWithNpt = wellOperationsWithType
|
||||||
.Where(o => WellOperationCategory.NonProductiveTimeSubIds.Contains(o.IdCategory));
|
.Where(o => WellOperationCategory.NonProductiveTimeSubIds.Contains(o.IdCategory));
|
||||||
@ -225,10 +265,12 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
|||||||
if (request.Take != null)
|
if (request.Take != null)
|
||||||
filteredWellOperations = filteredWellOperations.Take((int)request.Take);
|
filteredWellOperations = filteredWellOperations.Take((int)request.Take);
|
||||||
|
|
||||||
|
var timezoneOffset = wellService.GetTimezone(wellOperationsWithType.Key.IdWell).Offset;
|
||||||
|
|
||||||
var dtos = filteredWellOperations
|
var dtos = filteredWellOperations
|
||||||
.Select(entity =>
|
.Select(entity =>
|
||||||
{
|
{
|
||||||
var dto = Convert(entity);
|
var dto = Convert(entity, timezoneOffset);
|
||||||
dto.Day = (entity.DateStart - firstWellOperation.DateStart).TotalDays;
|
dto.Day = (entity.DateStart - firstWellOperation.DateStart).TotalDays;
|
||||||
dto.NptHours = operationsWithNpt
|
dto.NptHours = operationsWithNpt
|
||||||
.Where(o => o.DateStart <= entity.DateStart)
|
.Where(o => o.DateStart <= entity.DateStart)
|
||||||
@ -427,15 +469,11 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override WellOperationDto Convert(WellOperation src)
|
private WellOperationDto Convert(WellOperation src, TimeSpan timezoneOffset)
|
||||||
{
|
{
|
||||||
//TODO: пока такое получение TimeZone скважины, нужно исправить на Lazy
|
|
||||||
//Хоть мы и тянем данные из кэша, но от получения TimeZone в этом методе нужно избавиться, пока так
|
|
||||||
var timeZoneOffset = wellService.GetTimezone(src.IdWell).Offset;
|
|
||||||
|
|
||||||
var dto = src.Adapt<WellOperationDto>();
|
var dto = src.Adapt<WellOperationDto>();
|
||||||
dto.DateStart = src.DateStart.ToOffset(timeZoneOffset);
|
dto.DateStart = src.DateStart.ToOffset(timezoneOffset);
|
||||||
dto.LastUpdateDate = src.LastUpdateDate.ToOffset(timeZoneOffset);
|
dto.LastUpdateDate = src.LastUpdateDate.ToOffset(timezoneOffset);
|
||||||
|
|
||||||
dto.OperationCategoryName = LazyWellCategories.Value.TryGetValue(src.IdCategory, out WellOperationCategoryDto? category) ? category.Name : string.Empty;
|
dto.OperationCategoryName = LazyWellCategories.Value.TryGetValue(src.IdCategory, out WellOperationCategoryDto? category) ? category.Name : string.Empty;
|
||||||
dto.WellSectionTypeCaption = LazyWellSectionTypes.Value.TryGetValue(src.IdWellSectionType, out WellSectionTypeDto? sectionType) ? sectionType.Caption : string.Empty;
|
dto.WellSectionTypeCaption = LazyWellSectionTypes.Value.TryGetValue(src.IdWellSectionType, out WellSectionTypeDto? sectionType) ? sectionType.Caption : string.Empty;
|
||||||
|
@ -187,7 +187,7 @@ public class WellOperationController : ControllerBase
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Permission]
|
[Permission]
|
||||||
[ProducesResponseType(typeof(PaginationContainer<WellOperationDto>), StatusCodes.Status200OK)]
|
[ProducesResponseType(typeof(PaginationContainer<WellOperationDto>), StatusCodes.Status200OK)]
|
||||||
public async Task<IActionResult> GetPageOperationsAsync(
|
public async Task<IActionResult> GetPageAsync(
|
||||||
[FromRoute] int idWell,
|
[FromRoute] int idWell,
|
||||||
[FromQuery] WellOperationRequestBase request,
|
[FromQuery] WellOperationRequestBase request,
|
||||||
CancellationToken token)
|
CancellationToken token)
|
||||||
@ -201,6 +201,37 @@ public class WellOperationController : ControllerBase
|
|||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение страницу с нужной операцией
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell">id скважины</param>
|
||||||
|
/// <param name="id">id операции</param>
|
||||||
|
/// <param name="operationType">тип получаемых операций</param>
|
||||||
|
/// <param name="take">кол-во записей на странице</param>
|
||||||
|
/// <param name="sortFields">параметры сортировки страниц</param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpGet("getPageWithOperation")]
|
||||||
|
[Permission]
|
||||||
|
[ProducesResponseType(typeof(PaginationContainer<WellOperationDto>), StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> GetPageWithOperationAsync([FromRoute] int idWell,
|
||||||
|
int id,
|
||||||
|
int operationType,
|
||||||
|
int? take,
|
||||||
|
[FromQuery] IEnumerable<string>? sortFields,
|
||||||
|
CancellationToken token)
|
||||||
|
{
|
||||||
|
if (!await CanUserAccessToWellAsync(idWell, token))
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
|
var paginationContainer = await wellOperationRepository.GetPageAsync(idWell, id, operationType, take, sortFields, token);
|
||||||
|
|
||||||
|
if (paginationContainer == null)
|
||||||
|
return NoContent();
|
||||||
|
|
||||||
|
return Ok(paginationContainer);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Создает excel файл с "сетевым графиком"
|
/// Создает excel файл с "сетевым графиком"
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user