forked from ddrilling/AsbCloudServer
1. На странице фактических операций убрана пагинация
2. Фильтрация фактических операций по дате 3. Переписан запрос, формируюший список плановых операций для сопоставления
This commit is contained in:
parent
85c6b63c7a
commit
66f97678dd
@ -28,10 +28,11 @@ namespace AsbCloudApp.Repositories
|
||||
/// <summary>
|
||||
/// список плановых операций для сопоставления
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="currentDate"></param>
|
||||
/// <param name="token"></param>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<WellOperationDto>> GetOperationsPlanAsync(int idWell, CancellationToken token);
|
||||
Task<IEnumerable<WellOperationDto>> GetOperationsPlanAsync(int idWell, DateTime? currentDate, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// дата/время первой операции по скважине
|
||||
|
@ -58,35 +58,41 @@ namespace AsbCloudInfrastructure.Repository
|
||||
.GetOrCreateBasic<WellSectionType>(db)
|
||||
.ToDictionary(s => s.Id, s => s.Caption);
|
||||
|
||||
public async Task<IEnumerable<WellOperationDto>> GetOperationsPlanAsync(int idWell, CancellationToken token)
|
||||
public async Task<IEnumerable<WellOperationDto>> GetOperationsPlanAsync(int idWell, DateTime? currentDate, CancellationToken token)
|
||||
{
|
||||
var timezone = wellService.GetTimezone(idWell);
|
||||
DateTimeOffset? currentDateOffset = currentDate.HasValue
|
||||
? currentDate.Value.ToUtcDateTimeOffset(timezone.Hours)
|
||||
: null;
|
||||
|
||||
var lastFactOperation = await db.WellOperations
|
||||
.Where(x => x.IdType == WellOperation.IdOperationTypeFact)
|
||||
.Where(x => x.IdPlan != null)
|
||||
.Where(x => x.DateStart < currentDateOffset)
|
||||
.Include(x => x.OperationPlan)
|
||||
.OrderByDescending(x => x.DateStart)
|
||||
.FirstOrDefaultAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var query = db.WellOperations
|
||||
.Include(x => x.OperationCategory)
|
||||
.Include(x => x.WellSectionType)
|
||||
.Where(x => x.IdWell == idWell)
|
||||
.Where(x => x.IdType == WellOperation.IdOperationTypePlan);
|
||||
|
||||
|
||||
if (lastFactOperation is not null)
|
||||
if (lastFactOperation?.OperationPlan is not null)
|
||||
{
|
||||
var dateStart = lastFactOperation?.DateStart!;
|
||||
var dateStart = lastFactOperation.OperationPlan.DateStart;
|
||||
query = query.Where(x => x.DateStart >= dateStart);
|
||||
}
|
||||
|
||||
var timezone = wellService.GetTimezone(idWell);
|
||||
var timeZoneOffset = TimeSpan.FromHours(timezone.Hours);
|
||||
|
||||
var entities = await query
|
||||
.AsNoTracking()
|
||||
.ToArrayAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
var timeZoneOffset = TimeSpan.FromHours(timezone.Hours);
|
||||
var result = entities
|
||||
.Select(o => new WellOperationDto()
|
||||
{
|
||||
@ -96,7 +102,9 @@ namespace AsbCloudInfrastructure.Repository
|
||||
IdPlan = o.IdPlan,
|
||||
DepthStart = o.DepthStart,
|
||||
DateStart = DateTime.SpecifyKind(o.DateStart.UtcDateTime + timeZoneOffset, DateTimeKind.Unspecified),
|
||||
Id = o.Id
|
||||
Id = o.Id,
|
||||
IdWellSectionType = o.IdWellSectionType,
|
||||
WellSectionTypeName = o.WellSectionType?.Caption ?? string.Empty,
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ using AsbCloudApp.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
@ -64,18 +65,22 @@ namespace AsbCloudWebApi.Controllers
|
||||
/// Возвращает список плановых операций для сопоставления
|
||||
/// </summary>
|
||||
/// <param name="idWell">id скважины</param>
|
||||
/// <param name="currentDate">текущая дата для нахождения предыдущей фактической операции
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
[Route("operationsPlan")]
|
||||
[ProducesResponseType(typeof(IEnumerable<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetOperationsPlanAsync([FromRoute] int idWell, CancellationToken token)
|
||||
public async Task<IActionResult> GetOperationsPlanAsync(
|
||||
[FromRoute] int idWell,
|
||||
[FromQuery] DateTime? currentDate,
|
||||
CancellationToken token)
|
||||
{
|
||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||
return Forbid();
|
||||
|
||||
var result = await operationRepository
|
||||
.GetOperationsPlanAsync(idWell, token)
|
||||
.GetOperationsPlanAsync(idWell, currentDate, token)
|
||||
.ConfigureAwait(false);
|
||||
return Ok(result);
|
||||
}
|
||||
@ -86,10 +91,10 @@ namespace AsbCloudWebApi.Controllers
|
||||
/// <param name="idWell">id скважины</param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns>Список операций на скважине в контейнере для постраничного просмотра</returns>
|
||||
/// <returns>Список операций на скважине</returns>
|
||||
[HttpGet]
|
||||
[Permission]
|
||||
[ProducesResponseType(typeof(PaginationContainer<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
[ProducesResponseType(typeof(IEnumerable<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||
public async Task<IActionResult> GetOperationsAsync(
|
||||
[FromRoute] int idWell,
|
||||
[FromQuery] WellOperationRequestBase request,
|
||||
@ -99,7 +104,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
return Forbid();
|
||||
|
||||
var requestToService = new WellOperationRequest(request, idWell);
|
||||
var result = await operationRepository.GetPageAsync(
|
||||
var result = await operationRepository.GetAsync(
|
||||
requestToService,
|
||||
token)
|
||||
.ConfigureAwait(false);
|
||||
|
Loading…
Reference in New Issue
Block a user