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