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