forked from ddrilling/AsbCloudServer
Добавлен метод получения индекса страницы с нужной операцией ГГД
This commit is contained in:
parent
887fc540ab
commit
15972b4ef7
@ -13,12 +13,21 @@ namespace AsbCloudApp.Repositories
|
|||||||
public interface IWellOperationRepository
|
public interface IWellOperationRepository
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить запись по Id
|
/// Получить индекс страницы с операцией
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="idWell"></param>
|
||||||
/// <param name="id"></param>
|
/// <param name="id"></param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="operationType"></param>
|
||||||
|
/// <param name="take"></param>
|
||||||
|
/// <param name="sortFields"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<WellOperationDto?> GetOrDefaultByIdAsync(int id, CancellationToken cancellationToken = default);
|
Task<int?> GetIndexPageWithOperationAsync(int idWell,
|
||||||
|
int id,
|
||||||
|
int operationType,
|
||||||
|
int? take,
|
||||||
|
IEnumerable<string>? sortFields,
|
||||||
|
CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Список секций
|
/// Список секций
|
||||||
|
@ -41,33 +41,42 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
|||||||
LazyWellSectionTypes = new(() => GetSectionTypes().ToDictionary(c => c.Id));
|
LazyWellSectionTypes = new(() => GetSectionTypes().ToDictionary(c => c.Id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<WellOperationDto?> GetOrDefaultByIdAsync(int id, CancellationToken cancellationToken = default)
|
public async Task<int?> GetIndexPageWithOperationAsync(int idWell,
|
||||||
|
int id,
|
||||||
|
int operationType,
|
||||||
|
int? take,
|
||||||
|
IEnumerable<string>? 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;
|
return null;
|
||||||
|
|
||||||
var firstWellOperation = await dbContext.WellOperations.Where(o => o.IdWell == entity.IdWell &&
|
query = sortFields?.Any() is true ? query.SortBy(sortFields) : query.OrderBy(e => e.DateStart);
|
||||||
o.IdType == entity.IdType)
|
|
||||||
.OrderBy(o => o.DateStart)
|
|
||||||
.FirstAsync(cancellationToken);
|
|
||||||
|
|
||||||
var operationsWithNpt = await dbContext.WellOperations
|
var count = await query.CountAsync(cancellationToken);
|
||||||
.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 indexPage = 1;
|
||||||
|
|
||||||
var dto = Convert(entity, timezoneOffset);
|
var skip = 0;
|
||||||
dto.Day = (entity.DateStart - firstWellOperation.DateStart).TotalDays;
|
take ??= 32;
|
||||||
dto.NptHours = operationsWithNpt
|
|
||||||
.Where(o => o.DateStart <= entity.DateStart)
|
|
||||||
.Sum(o => o.DurationHours);
|
|
||||||
|
|
||||||
return dto;
|
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() =>
|
||||||
|
@ -202,26 +202,34 @@ public class WellOperationController : ControllerBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение записи по Id
|
/// Получение индекса страницы с нужной операцией
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell">id скважины</param>
|
/// <param name="idWell">id скважины</param>
|
||||||
/// <param name="id">id операции</param>
|
/// <param name="id">id операции</param>
|
||||||
|
/// <param name="operationType">тип получаемых операций</param>
|
||||||
|
/// <param name="take">кол-во записей на странице</param>
|
||||||
|
/// <param name="sortFields">параметры сортировки страниц</param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet("{id}")]
|
[HttpGet("{id}")]
|
||||||
[Permission]
|
[Permission]
|
||||||
[ProducesResponseType(typeof(WellOperationDto), StatusCodes.Status200OK)]
|
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
|
||||||
public async Task<IActionResult> GetByIdAsync(int idWell, int id, CancellationToken token)
|
public async Task<IActionResult> GetIndexPageWithOperationAsync([FromRoute] int idWell,
|
||||||
|
[FromRoute] int id,
|
||||||
|
int operationType,
|
||||||
|
int? take,
|
||||||
|
[FromQuery] IEnumerable<string>? sortFields,
|
||||||
|
CancellationToken token)
|
||||||
{
|
{
|
||||||
if (!await CanUserAccessToWellAsync(idWell, token))
|
if (!await CanUserAccessToWellAsync(idWell, token))
|
||||||
return Forbid();
|
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 NoContent();
|
||||||
|
|
||||||
return Ok(dto);
|
return Ok(indexPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user