From aef99cbf11be66150fdd367680600c5d3b83e70f Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Tue, 21 Feb 2023 13:22:24 +0500 Subject: [PATCH] =?UTF-8?q?1.=20=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B0=20=D0=BF?= =?UTF-8?q?=D0=BB=D0=B0=D0=BD=D0=BE=D0=B2=D1=8B=D1=85=20=D0=BE=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B0=D1=86=D0=B8=D1=8F=20=D0=B4=D0=BB=D1=8F=20=D1=81?= =?UTF-8?q?=D0=BE=D0=BF=D0=BE=D1=81=D1=82=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=202.=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D1=8C=20WellOpera?= =?UTF-8?q?tionPlanDto=20=D0=B4=D0=BB=D1=8F=20=D1=85=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BF=D0=BB=D0=B0=D0=BD=D0=BE=D0=B2=D1=8B=D1=85=20=D0=BE?= =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D0=B9=20=D0=B8=20=D0=B4?= =?UTF-8?q?=D0=B0=D1=82=D1=8B=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=D0=B4=D0=BD?= =?UTF-8?q?=D0=B5=D0=B9=20=D1=81=D0=BE=D0=BF=D0=BE=D1=81=D1=82=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=BD=D0=BE=D0=B9=20=D0=BF=D0=BB=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2=D0=BE=D0=B9=20=D0=BE=D0=BF=D0=B5=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=203.=20WellSectionTypeName=20=D0=B8=20CategoryName?= =?UTF-8?q?=20=D0=B2=20WellOperationDto=20=D0=BC=D0=BE=D0=B3=D1=83=D1=82?= =?UTF-8?q?=20=D0=B1=D1=8B=D1=82=D1=8C=20nullable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Data/WellOperationDto.cs | 4 +- AsbCloudApp/Data/WellOperationPlanDto.cs | 28 +++++++ .../Repositories/IWellOperationRepository.cs | 2 +- .../Repository/WellOperationRepository.cs | 73 +++++++++---------- .../Controllers/WellOperationController.cs | 6 +- 5 files changed, 69 insertions(+), 44 deletions(-) create mode 100644 AsbCloudApp/Data/WellOperationPlanDto.cs diff --git a/AsbCloudApp/Data/WellOperationDto.cs b/AsbCloudApp/Data/WellOperationDto.cs index 4bed0b54..e38dc10a 100644 --- a/AsbCloudApp/Data/WellOperationDto.cs +++ b/AsbCloudApp/Data/WellOperationDto.cs @@ -25,7 +25,7 @@ namespace AsbCloudApp.Data /// /// название секции скважины /// - public string WellSectionTypeName { get; set; } = null!; + public string? WellSectionTypeName { get; set; } /// /// id категории операции @@ -41,7 +41,7 @@ namespace AsbCloudApp.Data /// /// название категории операции /// - public string CategoryName { get; set; } = null!; + public string? CategoryName { get; set; } /// /// дополнительная информация по операции diff --git a/AsbCloudApp/Data/WellOperationPlanDto.cs b/AsbCloudApp/Data/WellOperationPlanDto.cs new file mode 100644 index 00000000..68f8a2fa --- /dev/null +++ b/AsbCloudApp/Data/WellOperationPlanDto.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AsbCloudApp.Data +{ + /// + /// класс, для хранения списка плановых операций для сопоставления + /// и даты последней сопоставленной плановой операции + /// +#nullable disable + public class WellOperationPlanDto + { + /// + /// коллекция плановых операций + /// + public IEnumerable WellOperationsPlan { get; set; } + + /// + /// дата последней сопоставленной плановой операции + /// + public DateTime DateLastAssosiatedPlanOperation { get; set; } + + } +#nullable disable +} diff --git a/AsbCloudApp/Repositories/IWellOperationRepository.cs b/AsbCloudApp/Repositories/IWellOperationRepository.cs index 07b02b32..6904ae43 100644 --- a/AsbCloudApp/Repositories/IWellOperationRepository.cs +++ b/AsbCloudApp/Repositories/IWellOperationRepository.cs @@ -32,7 +32,7 @@ namespace AsbCloudApp.Repositories /// /// /// - Task> GetOperationsPlanAsync(int idWell, DateTime? currentDate, CancellationToken token); + Task GetOperationsPlanAsync(int idWell, DateTime currentDate, CancellationToken token); /// /// дата/время первой операции по скважине diff --git a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs index 3efa316b..3e444a61 100644 --- a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs +++ b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs @@ -4,11 +4,9 @@ using AsbCloudApp.Requests; using AsbCloudApp.Services; using AsbCloudDb; using AsbCloudDb.Model; -using DocumentFormat.OpenXml.Office2016.Excel; using Mapster; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Caching.Memory; -using Org.BouncyCastle.Asn1.Ocsp; using System; using System.Collections.Generic; using System.Linq; @@ -65,54 +63,53 @@ namespace AsbCloudInfrastructure.Repository .GetOrCreateBasic(db) .ToDictionary(s => s.Id, s => s.Caption); - public async Task> GetOperationsPlanAsync(int idWell, DateTime? currentDate, 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 currentDateOffset = currentDate.ToUtcDateTimeOffset(timezone.Hours); + var timeZoneOffset = TimeSpan.FromHours(timezone.Hours); 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); + .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 + + var query = await db.WellOperations .Include(x => x.OperationCategory) .Include(x => x.WellSectionType) .Where(x => x.IdWell == idWell) - .Where(x => x.IdType == WellOperation.IdOperationTypePlan); + .Where(x => x.IdType == WellOperation.IdOperationTypePlan) + .AsNoTracking() + .ToArrayAsync(token) + .ConfigureAwait(false); - - if (lastFactOperation?.OperationPlan is not null) + + var result = new WellOperationPlanDto() { - var dateStart = lastFactOperation.OperationPlan.DateStart; - query = query.Where(x => x.DateStart >= dateStart); - } + WellOperationsPlan = query + .Select(o => new WellOperationDto() + { + IdWell = o.IdWell, + CategoryName = o.OperationCategory.Name, + IdCategory = o.IdCategory, + IdPlan = o.IdPlan, + DepthStart = o.DepthStart, + DateStart = DateTime.SpecifyKind(o.DateStart.UtcDateTime + timeZoneOffset, DateTimeKind.Unspecified), + Id = o.Id, + IdWellSectionType = o.IdWellSectionType, + WellSectionTypeName = o.WellSectionType?.Caption ?? string.Empty, + }), - var entities = await query - .AsNoTracking() - .ToArrayAsync(token) - .ConfigureAwait(false); + DateLastAssosiatedPlanOperation = lastFactOperation?.OperationPlan.DateStart is not null + ? DateTime.SpecifyKind(lastFactOperation.OperationPlan.DateStart.UtcDateTime + timeZoneOffset, DateTimeKind.Unspecified) + : DateTime.MinValue + }; - var timeZoneOffset = TimeSpan.FromHours(timezone.Hours); - var result = entities - .Select(o => new WellOperationDto() - { - IdWell = o.IdWell, - CategoryName = o.OperationCategory.Name, - IdCategory = o.IdCategory, - IdPlan = o.IdPlan, - DepthStart = o.DepthStart, - DateStart = DateTime.SpecifyKind(o.DateStart.UtcDateTime + timeZoneOffset, DateTimeKind.Unspecified), - 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 2e755945..95bbec44 100644 --- a/AsbCloudWebApi/Controllers/WellOperationController.cs +++ b/AsbCloudWebApi/Controllers/WellOperationController.cs @@ -65,15 +65,15 @@ namespace AsbCloudWebApi.Controllers /// Возвращает список плановых операций для сопоставления /// /// id скважины - /// текущая дата для нахождения предыдущей фактической операции + /// дата для нахождения последней сопоставленной плановой операции /// /// [HttpGet] [Route("operationsPlan")] - [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] + [ProducesResponseType(typeof(WellOperationPlanDto), (int)System.Net.HttpStatusCode.OK)] public async Task GetOperationsPlanAsync( [FromRoute] int idWell, - [FromQuery] DateTime? currentDate, + [FromQuery] DateTime currentDate, CancellationToken token) { if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))