From 66f97678dd3f3267f4e6d0091d707217fcfd47e8 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Mon, 20 Feb 2023 15:17:49 +0500 Subject: [PATCH] =?UTF-8?q?1.=20=D0=9D=D0=B0=20=D1=81=D1=82=D1=80=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D1=86=D0=B5=20=D1=84=D0=B0=D0=BA=D1=82=D0=B8=D1=87?= =?UTF-8?q?=D0=B5=D1=81=D0=BA=D0=B8=D1=85=20=D0=BE=D0=BF=D0=B5=D1=80=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D0=B9=20=D1=83=D0=B1=D1=80=D0=B0=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=BF=D0=B0=D0=B3=D0=B8=D0=BD=D0=B0=D1=86=D0=B8=D1=8F=202.=20?= =?UTF-8?q?=D0=A4=D0=B8=D0=BB=D1=8C=D1=82=D1=80=D0=B0=D1=86=D0=B8=D1=8F=20?= =?UTF-8?q?=D1=84=D0=B0=D0=BA=D1=82=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=B8?= =?UTF-8?q?=D1=85=20=D0=BE=D0=BF=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D0=B9=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D0=B4=D0=B0=D1=82=D0=B5=203.=20=D0=9F=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D0=BF=D0=B8=D1=81=D0=B0=D0=BD=20=D0=B7=D0=B0=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D1=81,=20=D1=84=D0=BE=D1=80=D0=BC=D0=B8=D1=80?= =?UTF-8?q?=D1=83=D1=8E=D1=88=D0=B8=D0=B9=20=D1=81=D0=BF=D0=B8=D1=81=D0=BE?= =?UTF-8?q?=D0=BA=20=D0=BF=D0=BB=D0=B0=D0=BD=D0=BE=D0=B2=D1=8B=D1=85=20?= =?UTF-8?q?=D0=BE=D0=BF=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D0=B9=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D1=81=D0=BE=D0=BF=D0=BE=D1=81=D1=82=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repositories/IWellOperationRepository.cs | 3 ++- .../Repository/WellOperationRepository.cs | 22 +++++++++++++------ .../Controllers/WellOperationController.cs | 15 ++++++++----- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/AsbCloudApp/Repositories/IWellOperationRepository.cs b/AsbCloudApp/Repositories/IWellOperationRepository.cs index 5f2979a9..980899f9 100644 --- a/AsbCloudApp/Repositories/IWellOperationRepository.cs +++ b/AsbCloudApp/Repositories/IWellOperationRepository.cs @@ -28,10 +28,11 @@ namespace AsbCloudApp.Repositories /// /// список плановых операций для сопоставления /// + /// /// /// /// - Task> GetOperationsPlanAsync(int idWell, CancellationToken token); + Task> GetOperationsPlanAsync(int idWell, DateTime? currentDate, CancellationToken token); /// /// дата/время первой операции по скважине diff --git a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs index f53e6f69..c478ce30 100644 --- a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs +++ b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs @@ -58,35 +58,41 @@ namespace AsbCloudInfrastructure.Repository .GetOrCreateBasic(db) .ToDictionary(s => s.Id, s => s.Caption); - public async Task> GetOperationsPlanAsync(int idWell, CancellationToken token) + public async Task> 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; } diff --git a/AsbCloudWebApi/Controllers/WellOperationController.cs b/AsbCloudWebApi/Controllers/WellOperationController.cs index e8e5d2d6..21f58d3a 100644 --- a/AsbCloudWebApi/Controllers/WellOperationController.cs +++ b/AsbCloudWebApi/Controllers/WellOperationController.cs @@ -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 /// Возвращает список плановых операций для сопоставления /// /// id скважины + /// текущая дата для нахождения предыдущей фактической операции /// /// [HttpGet] [Route("operationsPlan")] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] - public async Task GetOperationsPlanAsync([FromRoute] int idWell, CancellationToken token) + public async Task 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 /// id скважины /// /// - /// Список операций на скважине в контейнере для постраничного просмотра + /// Список операций на скважине [HttpGet] [Permission] - [ProducesResponseType(typeof(PaginationContainer), (int)System.Net.HttpStatusCode.OK)] + [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] public async Task 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);