forked from ddrilling/AsbCloudServer
Фикс
Добавлено возвращение всей страницы
This commit is contained in:
parent
15972b4ef7
commit
a8af18959d
@ -12,23 +12,6 @@ namespace AsbCloudApp.Repositories
|
||||
/// </summary>
|
||||
public interface IWellOperationRepository
|
||||
{
|
||||
/// <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<int?> GetIndexPageWithOperationAsync(int idWell,
|
||||
int id,
|
||||
int operationType,
|
||||
int? take,
|
||||
IEnumerable<string>? sortFields,
|
||||
CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Список секций
|
||||
/// </summary>
|
||||
@ -50,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>
|
||||
/// Получить статистику операции по скважине с группировкой по категориям
|
||||
|
@ -41,44 +41,6 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
||||
LazyWellSectionTypes = new(() => GetSectionTypes().ToDictionary(c => c.Id));
|
||||
}
|
||||
|
||||
public async Task<int?> GetIndexPageWithOperationAsync(int idWell,
|
||||
int id,
|
||||
int operationType,
|
||||
int? take,
|
||||
IEnumerable<string>? sortFields,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var query = GetQuery()
|
||||
.Where(o => o.IdType == operationType &&
|
||||
o.IdWell == idWell);
|
||||
|
||||
if (!await query.AnyAsync(x => x.Id == id, cancellationToken))
|
||||
return null;
|
||||
|
||||
query = sortFields?.Any() is true ? query.SortBy(sortFields) : query.OrderBy(e => e.DateStart);
|
||||
|
||||
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<WellSectionTypeDto> GetSectionTypes() =>
|
||||
memoryCache
|
||||
.GetOrCreateBasic(dbContext.WellSectionTypes)
|
||||
@ -109,6 +71,50 @@ 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 query = GetQuery()
|
||||
.Where(o => o.IdType == operationType &&
|
||||
o.IdWell == idWell);
|
||||
|
||||
if (!await query.AnyAsync(x => x.Id == id, token))
|
||||
return null;
|
||||
|
||||
query = sortFields?.Any() is true ? query.SortBy(sortFields) : query.OrderBy(e => e.DateStart);
|
||||
|
||||
var skip = 0;
|
||||
take ??= 32;
|
||||
|
||||
var count = await query.CountAsync(token);
|
||||
|
||||
while (skip < count)
|
||||
{
|
||||
var isExists = await query.Skip(skip)
|
||||
.Take(take.Value)
|
||||
.AnyAsync(x => x.Id == id, token);
|
||||
|
||||
if (isExists)
|
||||
break;
|
||||
|
||||
skip += take.Value;
|
||||
}
|
||||
|
||||
var request = new WellOperationRequest(new[] { idWell })
|
||||
{
|
||||
OperationType = operationType,
|
||||
Skip = skip,
|
||||
Take = take,
|
||||
SortFields = sortFields
|
||||
};
|
||||
|
||||
return await GetPageAsync(request, token);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<WellGroupOpertionDto>> GetGroupOperationsStatAsync(WellOperationRequest request, CancellationToken token)
|
||||
{
|
||||
var query = BuildQuery(request);
|
||||
|
@ -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)
|
||||
@ -202,7 +202,7 @@ public class WellOperationController : ControllerBase
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение индекса страницы с нужной операцией
|
||||
/// Получение страницу с нужной операцией
|
||||
/// </summary>
|
||||
/// <param name="idWell">id скважины</param>
|
||||
/// <param name="id">id операции</param>
|
||||
@ -211,11 +211,11 @@ public class WellOperationController : ControllerBase
|
||||
/// <param name="sortFields">параметры сортировки страниц</param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{id}")]
|
||||
[HttpGet("getPageWithOperation")]
|
||||
[Permission]
|
||||
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetIndexPageWithOperationAsync([FromRoute] int idWell,
|
||||
[FromRoute] int id,
|
||||
public async Task<IActionResult> GetPageWithOperationAsync([FromRoute] int idWell,
|
||||
int id,
|
||||
int operationType,
|
||||
int? take,
|
||||
[FromQuery] IEnumerable<string>? sortFields,
|
||||
@ -224,9 +224,9 @@ public class WellOperationController : ControllerBase
|
||||
if (!await CanUserAccessToWellAsync(idWell, token))
|
||||
return Forbid();
|
||||
|
||||
var indexPage = await wellOperationRepository.GetIndexPageWithOperationAsync(idWell, id, operationType, take, sortFields, token);
|
||||
var indexPage = await wellOperationRepository.GetPageAsync(idWell, id, operationType, take, sortFields, token);
|
||||
|
||||
if (!indexPage.HasValue)
|
||||
if (indexPage == null)
|
||||
return NoContent();
|
||||
|
||||
return Ok(indexPage);
|
||||
|
Loading…
Reference in New Issue
Block a user