From 0ba1b5c5fc7b519b39f609c4253a2473084aa938 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Mon, 22 Apr 2024 11:16:23 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3=20wellOperationRepository=20(=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=B4=D0=BE=D0=BB=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Requests/WellOperationRequest.cs | 115 +++++++++--------- .../Repository/WellOperationRepository.cs | 81 ++++-------- 2 files changed, 81 insertions(+), 115 deletions(-) diff --git a/AsbCloudApp/Requests/WellOperationRequest.cs b/AsbCloudApp/Requests/WellOperationRequest.cs index 08b7fad8..2dc6405b 100644 --- a/AsbCloudApp/Requests/WellOperationRequest.cs +++ b/AsbCloudApp/Requests/WellOperationRequest.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; namespace AsbCloudApp.Requests; @@ -8,44 +9,44 @@ namespace AsbCloudApp.Requests; /// public class WellOperationRequestBase : RequestBase { - /// - /// Больше или равно дате начала операции - /// - public DateTimeOffset? GeDate { get; set; } + /// + /// Больше или равно дате начала операции + /// + public DateTimeOffset? GeDate { get; set; } - /// - /// Меньше или равно дате окончания операции - /// - public DateTimeOffset? LeDate { get; set; } + /// + /// Меньше или равно дате окончания операции + /// + public DateTimeOffset? LeDate { get; set; } - /// - /// Больше или равно глубины скважины на начало операции. - /// - public double? GeDepth { get; set; } + /// + /// Больше или равно глубины скважины на начало операции. + /// + public double? GeDepth { get; set; } - /// - /// Меньше или равно глубины скважины на конец операции. - /// - public double? LeDepth { get; set; } + /// + /// Меньше или равно глубины скважины на конец операции. + /// + public double? LeDepth { get; set; } - /// - /// Идентификаторы категорий операции - /// - public IEnumerable? OperationCategoryIds { get; set; } + /// + /// Идентификаторы категорий операции + /// + public IEnumerable? OperationCategoryIds { get; set; } - /// - /// Тип операций - /// - /// 0 - плановая операция - /// 1 - фактическая операция - /// - /// - public int? OperationType { get; set; } + /// + /// Тип операций + /// + /// 0 - плановая операция + /// 1 - фактическая операция + /// + /// + public int? OperationType { get; set; } - /// - /// Идентификаторы конструкций секции - /// - public IEnumerable? SectionTypeIds { get; set; } + /// + /// Идентификаторы конструкций секции + /// + public IEnumerable? SectionTypeIds { get; set; } } /// @@ -53,32 +54,34 @@ public class WellOperationRequestBase : RequestBase /// public class WellOperationRequest : WellOperationRequestBase { - /// - public WellOperationRequest(IEnumerable idsWell) - { - IdsWell = idsWell; - } + /// + public WellOperationRequest(IEnumerable idsWell) + { + IdsWell = idsWell; + } - /// - public WellOperationRequest(WellOperationRequestBase request, IEnumerable idsWell) - : this(idsWell) - { - GeDepth = request.GeDepth; - LeDepth = request.LeDepth; - GeDate = request.GeDate; - LeDate = request.LeDate; + /// + public WellOperationRequest(WellOperationRequestBase request, IEnumerable idsWell) + : this(idsWell) + { + GeDepth = request.GeDepth; + LeDepth = request.LeDepth; + GeDate = request.GeDate; + LeDate = request.LeDate; - OperationCategoryIds = request.OperationCategoryIds; - OperationType = request.OperationType; - SectionTypeIds = request.SectionTypeIds; + OperationCategoryIds = request.OperationCategoryIds; + OperationType = request.OperationType; + SectionTypeIds = request.SectionTypeIds; - Skip = request.Skip; - Take = request.Take; - SortFields = request.SortFields; - } + Skip = request.Skip; + Take = request.Take; + SortFields = request.SortFields; + } - /// - /// Идентификаторы скважин - /// - public IEnumerable IdsWell { get; } + /// + /// Идентификаторы скважин + /// + [Required] + [Length(1, 1)] + public IEnumerable IdsWell { get; } } \ No newline at end of file diff --git a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs index bc3cee39..959ad0d9 100644 --- a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs +++ b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs @@ -28,8 +28,7 @@ public class WellOperationRepository : CrudRepositoryBase dbSet.Include(e => e.WellSectionType) - .Include(e => e.OperationCategory)) + : base(context, dbSet => dbSet) { this.memoryCache = memoryCache; this.wellOperationCategoryRepository = wellOperationCategoryRepository; @@ -44,7 +43,7 @@ public class WellOperationRepository : CrudRepositoryBase> GetAsync(WellOperationRequest request, CancellationToken token) { - var (items, _) = await GetPrivateAsync(request, token); + var (items, _) = await GetAsyncWithDaysAndNpv(request, token); return items; } @@ -53,7 +52,7 @@ public class WellOperationRepository : CrudRepositoryBase { @@ -166,61 +165,52 @@ public class WellOperationRepository : CrudRepositoryBase> GetByIdsWells(IEnumerable idsWells, CancellationToken token) { var query = GetQuery() + .Include(e => e.WellSectionType) + .Include(e => e.OperationCategory) .Where(e => idsWells.Contains(e.IdWell)) .OrderBy(e => e.DateStart); var entities = await query.ToArrayAsync(token); return entities; } - private async Task<(IEnumerable items, int count)> GetPrivateAsync(WellOperationRequest request, CancellationToken token) + private async Task<(IEnumerable items, int count)> GetAsyncWithDaysAndNpv(WellOperationRequest request, CancellationToken token) { var skip = request.Skip ?? 0; var take = request.Take ?? 32; - /* - каунт = сумма всех фильтеред1 - for{ - все записи по скважине и типу план/факт = wellOperationswithType - из wellOperationswithType выбираем первую операцию - из wellOperationswithType все НПВ - к wellOperationswithType применяем оставшиеся фильтры из buildquery = фильтеред1 - к фильтеред1 применить скип тэйк = фильтеред2 - фильтеред2 конвертировать в дто и рассчитать дэй и время нпв - ... - } - */ - var entities = await GetByIdsWells(request.IdsWell, token); var entitiesByWellAndType = entities .GroupBy(e => new { e.IdWell, e.IdType }) .Select(grp => grp.ToArray()); var result = new List(); - foreach (var wellOperationswithType in entitiesByWellAndType) + var count = 0; + foreach (var wellOperationsWithType in entitiesByWellAndType) { - var firstWellOperation = wellOperationswithType + var firstWellOperation = wellOperationsWithType .OrderBy(e => e.DateStart) - .FirstOrDefault(); + .FirstOrDefault()!; - //НПВ - var operationsWithNpt = wellOperationswithType + var operationsWithNpt = wellOperationsWithType .Where(o => WellOperationCategory.NonProductiveTimeSubIds.Contains(o.IdCategory)); - var filteredWellOperations = FilterOperations(wellOperationswithType, request); + var filteredWellOperations = GetByRequest(wellOperationsWithType, request); var filteredWellOperationsPart = filteredWellOperations .Skip(skip) .Take(take); var dtos = filteredWellOperationsPart - .Select(o => ConvertWithDrillingDaysAndNpvHours(o, firstWellOperation, operationsWithNpt, token)); + .Select(o => ConvertWithDrillingDaysAndNpvHours(o, firstWellOperation, operationsWithNpt)); + result.AddRange(dtos); + count += filteredWellOperations.Count(); } - return (result, entities.Count()); + return (result, count); } - private IEnumerable FilterOperations(IEnumerable entities, WellOperationRequest request) + private IEnumerable GetByRequest(IEnumerable entities, WellOperationRequest request) { if (request.OperationType.HasValue) entities = entities.Where(e => e.IdType == request.OperationType.Value); @@ -253,36 +243,7 @@ public class WellOperationRepository : CrudRepositoryBase> BuildQuery(WellOperationRequest request, CancellationToken token) { var entities = await GetByIdsWells(request.IdsWell, token); - - if (request.OperationType.HasValue) - entities = entities.Where(e => e.IdType == request.OperationType.Value); - - if (request.SectionTypeIds?.Any() is true) - entities = entities.Where(e => request.SectionTypeIds.Contains(e.IdWellSectionType)); - - if (request.OperationCategoryIds?.Any() is true) - entities = entities.Where(e => request.OperationCategoryIds.Contains(e.IdCategory)); - - if (request.GeDepth.HasValue) - entities = entities.Where(e => e.DepthEnd >= request.GeDepth.Value); - - if (request.LeDepth.HasValue) - entities = entities.Where(e => e.DepthEnd <= request.LeDepth.Value); - - if (request.GeDate.HasValue) - { - var geDateUtc = request.GeDate.Value.UtcDateTime; - entities = entities.Where(e => e.DateStart >= geDateUtc); - } - - if (request.LeDate.HasValue) - { - var leDateUtc = request.LeDate.Value.UtcDateTime; - entities = entities.Where(e => e.DateStart <= leDateUtc); - } - - if (request.SortFields?.Any() is true) - entities = entities.AsQueryable().SortBy(request.SortFields); + entities = GetByRequest(entities, request); return entities; } @@ -378,8 +339,7 @@ public class WellOperationRepository : CrudRepositoryBase wellOperationsWithNtp, - CancellationToken token) + IEnumerable wellOperationsWithNtp) { var dto = Convert(entity); dto.Day = (entity.DateStart - firstOperation.DateStart).TotalDays; @@ -401,6 +361,9 @@ public class WellOperationRepository : CrudRepositoryBase e.WellSectionType) + // .Include(e => e.OperationCategory) var timeZoneOffset = wellService.GetTimezone(src.IdWell).Offset; var dto = src.Adapt(); dto.DateStart = src.DateStart.ToOffset(timeZoneOffset);