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);