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