diff --git a/AsbCloudApp/Repositories/IWellOperationRepository.cs b/AsbCloudApp/Repositories/IWellOperationRepository.cs index fcf31f00..612d58d9 100644 --- a/AsbCloudApp/Repositories/IWellOperationRepository.cs +++ b/AsbCloudApp/Repositories/IWellOperationRepository.cs @@ -33,6 +33,23 @@ namespace AsbCloudApp.Repositories /// /// Task> GetPageAsync(WellOperationRequest request, CancellationToken token); + + /// + /// Получить страницу с операцией + /// + /// + /// + /// + /// + /// + /// + /// + Task?> GetPageAsync(int idWell, + int id, + int operationType, + int? take, + IEnumerable? sortFields, + CancellationToken token); /// /// Получить статистику операции по скважине с группировкой по категориям diff --git a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs index 8fa9433d..843956cb 100644 --- a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs +++ b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs @@ -40,7 +40,7 @@ public class WellOperationRepository : CrudRepositoryBase wellOperationCategoryRepository.Get(true, false).ToDictionary(c => c.Id)); LazyWellSectionTypes = new(() => GetSectionTypes().ToDictionary(c => c.Id)); } - + public IEnumerable GetSectionTypes() => memoryCache .GetOrCreateBasic(dbContext.WellSectionTypes) @@ -71,6 +71,48 @@ public class WellOperationRepository : CrudRepositoryBase?> GetPageAsync(int idWell, + int id, + int operationType, + int? take, + IEnumerable? 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 + { + Skip = skip, + Take = take.Value, + Items = page, + Count = count + }; + + return paginationContainer; + } + + skip += take.Value; + } + + return null; + } + public async Task> GetGroupOperationsStatAsync(WellOperationRequest request, CancellationToken token) { var query = BuildQuery(request); @@ -209,9 +251,7 @@ public class WellOperationRepository : CrudRepositoryBase 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 { - 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(); - 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; diff --git a/AsbCloudWebApi/Controllers/WellOperationController.cs b/AsbCloudWebApi/Controllers/WellOperationController.cs index eda82a08..90b7404f 100644 --- a/AsbCloudWebApi/Controllers/WellOperationController.cs +++ b/AsbCloudWebApi/Controllers/WellOperationController.cs @@ -187,7 +187,7 @@ public class WellOperationController : ControllerBase [HttpGet] [Permission] [ProducesResponseType(typeof(PaginationContainer), StatusCodes.Status200OK)] - public async Task GetPageOperationsAsync( + public async Task GetPageAsync( [FromRoute] int idWell, [FromQuery] WellOperationRequestBase request, CancellationToken token) @@ -201,6 +201,37 @@ public class WellOperationController : ControllerBase return Ok(result); } + /// + /// Получение страницу с нужной операцией + /// + /// id скважины + /// id операции + /// тип получаемых операций + /// кол-во записей на странице + /// параметры сортировки страниц + /// + /// + [HttpGet("getPageWithOperation")] + [Permission] + [ProducesResponseType(typeof(PaginationContainer), StatusCodes.Status200OK)] + public async Task GetPageWithOperationAsync([FromRoute] int idWell, + int id, + int operationType, + int? take, + [FromQuery] IEnumerable? 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); + } + /// /// Создает excel файл с "сетевым графиком" ///