diff --git a/AsbCloudApp/Repositories/IWellOperationRepository.cs b/AsbCloudApp/Repositories/IWellOperationRepository.cs
index 4f9eb807..7d507a0d 100644
--- a/AsbCloudApp/Repositories/IWellOperationRepository.cs
+++ b/AsbCloudApp/Repositories/IWellOperationRepository.cs
@@ -13,12 +13,21 @@ namespace AsbCloudApp.Repositories
public interface IWellOperationRepository
{
///
- /// Получить запись по Id
+ /// Получить индекс страницы с операцией
///
+ ///
///
- ///
+ ///
+ ///
+ ///
+ ///
///
- Task GetOrDefaultByIdAsync(int id, CancellationToken cancellationToken = default);
+ Task GetIndexPageWithOperationAsync(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 d110bab3..4907961c 100644
--- a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs
+++ b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs
@@ -40,34 +40,43 @@ public class WellOperationRepository : CrudRepositoryBase wellOperationCategoryRepository.Get(true, false).ToDictionary(c => c.Id));
LazyWellSectionTypes = new(() => GetSectionTypes().ToDictionary(c => c.Id));
}
-
- public async Task GetOrDefaultByIdAsync(int id, CancellationToken cancellationToken = default)
+
+ public async Task GetIndexPageWithOperationAsync(int idWell,
+ int id,
+ int operationType,
+ int? take,
+ IEnumerable? sortFields,
+ CancellationToken cancellationToken = default)
{
- var entity = await dbContext.WellOperations.FirstOrDefaultAsync(e => e.Id == id, cancellationToken);
+ var query = GetQuery()
+ .Where(o => o.IdType == operationType &&
+ o.IdWell == idWell);
- if (entity == null)
+ if (!await query.AnyAsync(x => x.Id == id, cancellationToken))
return null;
- var firstWellOperation = await dbContext.WellOperations.Where(o => o.IdWell == entity.IdWell &&
- o.IdType == entity.IdType)
- .OrderBy(o => o.DateStart)
- .FirstAsync(cancellationToken);
+ query = sortFields?.Any() is true ? query.SortBy(sortFields) : query.OrderBy(e => e.DateStart);
- var operationsWithNpt = await dbContext.WellOperations
- .Where(o => WellOperationCategory.NonProductiveTimeSubIds.Contains(o.IdCategory) &&
- o.IdWell == entity.IdWell &&
- o.IdType == entity.IdType)
- .ToArrayAsync(cancellationToken);
-
- var timezoneOffset = wellService.GetTimezone(entity.IdWell).Offset;
-
- var dto = Convert(entity, timezoneOffset);
- dto.Day = (entity.DateStart - firstWellOperation.DateStart).TotalDays;
- dto.NptHours = operationsWithNpt
- .Where(o => o.DateStart <= entity.DateStart)
- .Sum(o => o.DurationHours);
-
- return dto;
+ var count = await query.CountAsync(cancellationToken);
+
+ var indexPage = 1;
+
+ var skip = 0;
+ take ??= 32;
+
+ for (; skip < count; skip += take.Value)
+ {
+ var isExists = await query.Skip(skip)
+ .Take(take.Value)
+ .AnyAsync(x => x.Id == id, cancellationToken);
+
+ if (isExists)
+ break;
+
+ indexPage++;
+ }
+
+ return indexPage;
}
public IEnumerable GetSectionTypes() =>
diff --git a/AsbCloudWebApi/Controllers/WellOperationController.cs b/AsbCloudWebApi/Controllers/WellOperationController.cs
index 8f20f583..21540ae0 100644
--- a/AsbCloudWebApi/Controllers/WellOperationController.cs
+++ b/AsbCloudWebApi/Controllers/WellOperationController.cs
@@ -202,26 +202,34 @@ public class WellOperationController : ControllerBase
}
///
- /// Получение записи по Id
+ /// Получение индекса страницы с нужной операцией
///
/// id скважины
/// id операции
+ /// тип получаемых операций
+ /// кол-во записей на странице
+ /// параметры сортировки страниц
///
///
[HttpGet("{id}")]
[Permission]
- [ProducesResponseType(typeof(WellOperationDto), StatusCodes.Status200OK)]
- public async Task GetByIdAsync(int idWell, int id, CancellationToken token)
+ [ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
+ public async Task GetIndexPageWithOperationAsync([FromRoute] int idWell,
+ [FromRoute] int id,
+ int operationType,
+ int? take,
+ [FromQuery] IEnumerable? sortFields,
+ CancellationToken token)
{
if (!await CanUserAccessToWellAsync(idWell, token))
return Forbid();
- var dto = await wellOperationRepository.GetOrDefaultByIdAsync(id, token);
+ var indexPage = await wellOperationRepository.GetIndexPageWithOperationAsync(idWell, id, operationType, take, sortFields, token);
- if (dto == null)
+ if (!indexPage.HasValue)
return NoContent();
- return Ok(dto);
+ return Ok(indexPage);
}
///