From 85c6b63c7a6dfa90a6539d1ae8650b9c58e6720a Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Fri, 17 Feb 2023 09:25:34 +0500 Subject: [PATCH] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=20?= =?UTF-8?q?=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20BuildQuery=20=D0=B2=20WellOper?= =?UTF-8?q?ationRepository:=20=D0=B2=D0=BD=D0=B0=D1=87=D0=B0=D0=BB=D0=B5?= =?UTF-8?q?=20=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=D0=B0=D1=86=D0=B8=D1=8F?= =?UTF-8?q?,=20=D0=B4=D0=B0=D0=BB=D0=B5=D0=B5=20-=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B5=D0=BA=D1=86=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repository/WellOperationRepository.cs | 82 ++++++++++--------- 1 file changed, 44 insertions(+), 38 deletions(-) diff --git a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs index a2b449d5..f53e6f69 100644 --- a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs +++ b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs @@ -294,41 +294,8 @@ namespace AsbCloudInfrastructure.Repository var query = db.WellOperations .Include(s => s.WellSectionType) .Include(s => s.OperationCategory) - .Where(o => o.IdWell == request.IdWell) - .Select(o => new WellOperationDto - { - Id = o.Id, - IdPlan = o.IdPlan, - IdType = o.IdType, - IdWell = o.IdWell, - IdWellSectionType = o.IdWellSectionType, - IdCategory = o.IdCategory, + .Where(o => o.IdWell == request.IdWell); - CategoryName = o.WellSectionType.Caption, - WellSectionTypeName = o.WellSectionType.Caption, - - DateStart = DateTime.SpecifyKind(o.DateStart.UtcDateTime + timeZoneOffset, DateTimeKind.Unspecified), - DepthStart = o.DepthStart, - DepthEnd = o.DepthEnd, - DurationHours = o.DurationHours, - CategoryInfo = o.CategoryInfo, - Comment = o.Comment, - - NptHours = db.WellOperations - .Where(subOp => subOp.IdWell == request.IdWell) - .Where(subOp => subOp.IdType == 1) - .Where(subOp => WellOperationCategory.NonProductiveTimeSubIds.Contains(subOp.IdCategory)) - .Where(subOp => subOp.DateStart <= o.DateStart) - .Select(subOp => subOp.DurationHours) - .Sum(), - - Day = (o.DateStart - db.WellOperations - .Where(subOp => subOp.IdWell == request.IdWell) - .Where(subOp => subOp.IdType == o.IdType) - .Where(subOp => subOp.DateStart <= o.DateStart) - .Min(subOp => subOp.DateStart)) - .TotalDays, - }); if (request.OperationType.HasValue) query = query.Where(e => e.IdType == request.OperationType.Value); @@ -357,19 +324,58 @@ namespace AsbCloudInfrastructure.Repository query = query.Where(e => e.DateStart <= leDateOffset); } + var currentWellOperations = db.WellOperations + .Where(subOp => subOp.IdWell == request.IdWell); + + var wellOperationsWithCategoryNPT = currentWellOperations + .Where(subOp => subOp.IdType == 1) + .Where(subOp => WellOperationCategory.NonProductiveTimeSubIds.Contains(subOp.IdCategory)); + + + var result = query.Select(o => new WellOperationDto + { + Id = o.Id, + IdPlan = o.IdPlan, + IdType = o.IdType, + IdWell = o.IdWell, + IdWellSectionType = o.IdWellSectionType, + IdCategory = o.IdCategory, + + CategoryName = o.WellSectionType.Caption, + WellSectionTypeName = o.WellSectionType.Caption, + + DateStart = DateTime.SpecifyKind(o.DateStart.UtcDateTime + timeZoneOffset, DateTimeKind.Unspecified), + DepthStart = o.DepthStart, + DepthEnd = o.DepthEnd, + DurationHours = o.DurationHours, + CategoryInfo = o.CategoryInfo, + Comment = o.Comment, + + NptHours = wellOperationsWithCategoryNPT + .Where(subOp => subOp.DateStart <= o.DateStart) + .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)) + .TotalDays, + }); + if (request.SortFields?.Any() == true) { - query = query.SortBy(request.SortFields); + result = result.SortBy(request.SortFields); } else { - query = query + result = result .OrderBy(e => e.DateStart) .ThenBy(e => e.DepthEnd) .ThenBy(e => e.Id); - } + }; - return query; + return result; } } #nullable disable