From 12f6fda7b2c79bebb2d266f40727333640b38a76 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Thu, 28 Mar 2024 12:12:15 +0500 Subject: [PATCH] =?UTF-8?q?Fix=20ProcessMapReportDrillingService.CalcByInt?= =?UTF-8?q?ervals()=20=D1=83=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B8=D0=B7=D0=B2=D0=BE=D0=B4=D0=B8=D1=82?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D0=BB=D0=BE?= =?UTF-8?q?=D0=BA=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE=D0=B9=20=D1=84=D1=83=D0=BD?= =?UTF-8?q?=D0=BA=D1=86=D0=B8=D0=B8=20GetSection()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repository/WellOperationRepository.cs | 14 +++++---- .../Report/ProcessMapReportDrillingService.cs | 30 ++++++++++++++++--- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs index 329d2502..acdb1ef0 100644 --- a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs +++ b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs @@ -430,7 +430,14 @@ public class WellOperationRepository : IWellOperationRepository .Where(subOp => subOp.IdType == 1) .Where(subOp => WellOperationCategory.NonProductiveTimeSubIds.Contains(subOp.IdCategory)); - // TODO: Вынести query.Select из метода BuildQuery + var firstOperations = db.Set() + .Where(o => o.IdWell == request.IdWell) + .GroupBy(o => o.IdType) + .Select(group => new { + idType = group.Key, + Date = group.Min(o => o.DateStart), + }).ToDictionary(e => e.idType, e => e.Date); + var dtos = query.Select(o => new WellOperationDto { Id = o.Id, @@ -455,10 +462,7 @@ public class WellOperationRepository : IWellOperationRepository .Select(subOp => subOp.DurationHours) .Sum(), - Day = (o.DateStart - currentWellOperations - .Where(subOp => subOp.IdType == o.IdType) - .Where(subOp => subOp.DateStart <= o.DateStart) - .Min(subOp => subOp.DateStart)) + Day = (o.DateStart - firstOperations[o.IdType]) .TotalDays, IdUser = o.IdUser, LastUpdateDate = o.LastUpdateDate, diff --git a/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDrillingService.cs b/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDrillingService.cs index 5ee331d4..dae4f39b 100644 --- a/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDrillingService.cs +++ b/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDrillingService.cs @@ -64,6 +64,11 @@ public class ProcessMapReportDrillingService : IProcessMapReportDrillingService }; var wellOperations = await wellOperationRepository .GetAsync(requestWellOperationFact, token); + + var orderedWellOperations = wellOperations + .OrderBy(operation => operation.DateStart) + .ToArray(); + if (!wellOperations.Any()) return Enumerable.Empty(); @@ -76,13 +81,14 @@ public class ProcessMapReportDrillingService : IProcessMapReportDrillingService return Enumerable.Empty(); var wellOperationCategories = wellOperationCategoryRepository.Get(false); + var wellSectionTypes = wellOperationRepository.GetSectionTypes(); var result = CalcByIntervals( request, processMapPlanWellDrillings, - dataSaubStats, - wellOperations, + dataSaubStats, + orderedWellOperations, wellOperationCategories, wellSectionTypes); @@ -101,8 +107,23 @@ public class ProcessMapReportDrillingService : IProcessMapReportDrillingService var list = new List(); var firstElemInInterval = dataSaubStats[0]; - int GetSection(DataSaubStatDto data) - => wellOperations.MinBy(o => data.DateStart - o.DateStart)!.IdWellSectionType; + var orderedWellOperations = wellOperations + .OrderBy(o => o.DateStart) + .ToArray(); + + var lastFoundIndex = 1; + + int GetSection(DataSaubStatDto data) + { + if(lastFoundIndex < orderedWellOperations.Length - 1) + { + lastFoundIndex = Array.FindIndex(orderedWellOperations, lastFoundIndex, o => o.DateStart > data.DateStart) - 1; + lastFoundIndex = lastFoundIndex < 0 ? orderedWellOperations.Length - 1 : lastFoundIndex; + } + + var operation = orderedWellOperations[lastFoundIndex]; + return operation.IdWellSectionType; + } ProcessMapPlanDrillingDto? GetProcessMapPlan(int idWellSectionType, DataSaubStatDto data) => processMapPlanWellDrillings @@ -145,6 +166,7 @@ public class ProcessMapReportDrillingService : IProcessMapReportDrillingService .First(); var elem = CalcStat(processMapPlan, span, wellOperationCategoryName, wellSectionType); + if (elem is not null) list.Add(elem); }