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
@ -33,6 +33,23 @@ namespace AsbCloudApp.Repositories
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
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>
|
||||
/// Получить статистику операции по скважине с группировкой по категориям
|
||||
|
@ -40,7 +40,7 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
||||
LazyWellCategories = new(() => wellOperationCategoryRepository.Get(true, false).ToDictionary(c => c.Id));
|
||||
LazyWellSectionTypes = new(() => GetSectionTypes().ToDictionary(c => c.Id));
|
||||
}
|
||||
|
||||
|
||||
public IEnumerable<WellSectionTypeDto> GetSectionTypes() =>
|
||||
memoryCache
|
||||
.GetOrCreateBasic(dbContext.WellSectionTypes)
|
||||
@ -71,6 +71,48 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
||||
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)
|
||||
{
|
||||
var query = BuildQuery(request);
|
||||
@ -209,9 +251,7 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
||||
var count = 0;
|
||||
foreach (var wellOperationsWithType in groupedByWellAndType)
|
||||
{
|
||||
var firstWellOperation = wellOperationsWithType
|
||||
.OrderBy(e => e.DateStart)
|
||||
.FirstOrDefault()!;
|
||||
var firstWellOperation = wellOperationsWithType.MinBy(e => e.DateStart);
|
||||
|
||||
var operationsWithNpt = wellOperationsWithType
|
||||
.Where(o => WellOperationCategory.NonProductiveTimeSubIds.Contains(o.IdCategory));
|
||||
@ -224,11 +264,13 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
||||
filteredWellOperations = filteredWellOperations.Skip((int)request.Skip);
|
||||
if (request.Take != null)
|
||||
filteredWellOperations = filteredWellOperations.Take((int)request.Take);
|
||||
|
||||
var timezoneOffset = wellService.GetTimezone(wellOperationsWithType.Key.IdWell).Offset;
|
||||
|
||||
var dtos = filteredWellOperations
|
||||
.Select(entity =>
|
||||
{
|
||||
var dto = Convert(entity);
|
||||
var dto = Convert(entity, timezoneOffset);
|
||||
dto.Day = (entity.DateStart - firstWellOperation.DateStart).TotalDays;
|
||||
dto.NptHours = operationsWithNpt
|
||||
.Where(o => o.DateStart <= entity.DateStart)
|
||||
@ -427,15 +469,11 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
||||
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>();
|
||||
dto.DateStart = src.DateStart.ToOffset(timeZoneOffset);
|
||||
dto.LastUpdateDate = src.LastUpdateDate.ToOffset(timeZoneOffset);
|
||||
dto.DateStart = src.DateStart.ToOffset(timezoneOffset);
|
||||
dto.LastUpdateDate = src.LastUpdateDate.ToOffset(timezoneOffset);
|
||||
|
||||
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;
|
||||
|
@ -187,7 +187,7 @@ public class WellOperationController : ControllerBase
|
||||
[HttpGet]
|
||||
[Permission]
|
||||
[ProducesResponseType(typeof(PaginationContainer<WellOperationDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetPageOperationsAsync(
|
||||
public async Task<IActionResult> GetPageAsync(
|
||||
[FromRoute] int idWell,
|
||||
[FromQuery] WellOperationRequestBase request,
|
||||
CancellationToken token)
|
||||
@ -201,6 +201,37 @@ public class WellOperationController : ControllerBase
|
||||
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>
|
||||
/// Создает excel файл с "сетевым графиком"
|
||||
/// </summary>
|
||||
|
Loading…
Reference in New Issue
Block a user