forked from ddrilling/AsbCloudServer
Правки после ревью
This commit is contained in:
parent
ba2370ae15
commit
04c984e558
@ -48,7 +48,7 @@ namespace AsbCloudApp.Repositories
|
||||
int id,
|
||||
int operationType,
|
||||
int? take,
|
||||
IEnumerable<string> sortFields,
|
||||
IEnumerable<string>? sortFields,
|
||||
CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
|
@ -75,44 +75,42 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
||||
int id,
|
||||
int operationType,
|
||||
int? take,
|
||||
IEnumerable<string> sortFields,
|
||||
IEnumerable<string>? sortFields,
|
||||
CancellationToken token)
|
||||
{
|
||||
var query = GetQuery()
|
||||
.Where(o => o.IdType == operationType &&
|
||||
o.IdWell == idWell);
|
||||
var request = new WellOperationRequest(new[] { idWell })
|
||||
{
|
||||
OperationType = operationType,
|
||||
SortFields = sortFields,
|
||||
};
|
||||
|
||||
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 (wellOperations, count) = await GetWithDaysAndNpvAsync(request, token);
|
||||
|
||||
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);
|
||||
var page = wellOperations.Skip(skip)
|
||||
.Take(take.Value);
|
||||
|
||||
if (isExists)
|
||||
break;
|
||||
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;
|
||||
}
|
||||
|
||||
var request = new WellOperationRequest(new[] { idWell })
|
||||
{
|
||||
OperationType = operationType,
|
||||
Skip = skip,
|
||||
Take = take,
|
||||
SortFields = sortFields
|
||||
};
|
||||
|
||||
return await GetPageAsync(request, token);
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<WellGroupOpertionDto>> GetGroupOperationsStatAsync(WellOperationRequest request, CancellationToken token)
|
||||
|
@ -213,7 +213,7 @@ public class WellOperationController : ControllerBase
|
||||
/// <returns></returns>
|
||||
[HttpGet("getPageWithOperation")]
|
||||
[Permission]
|
||||
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(PaginationContainer<WellOperationDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetPageWithOperationAsync([FromRoute] int idWell,
|
||||
int id,
|
||||
int operationType,
|
||||
@ -224,12 +224,12 @@ public class WellOperationController : ControllerBase
|
||||
if (!await CanUserAccessToWellAsync(idWell, token))
|
||||
return Forbid();
|
||||
|
||||
var indexPage = await wellOperationRepository.GetPageAsync(idWell, id, operationType, take, sortFields, token);
|
||||
var paginationContainer = await wellOperationRepository.GetPageAsync(idWell, id, operationType, take, sortFields, token);
|
||||
|
||||
if (indexPage == null)
|
||||
if (paginationContainer == null)
|
||||
return NoContent();
|
||||
|
||||
return Ok(indexPage);
|
||||
return Ok(paginationContainer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Loading…
Reference in New Issue
Block a user