From 1c3f779f7445a320bd232bf939f680b37a4e2633 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Wed, 24 Apr 2024 12:28:37 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B0=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D1=80=D0=B5=D0=B7=D1=83=D0=BB=D1=8C=D1=82=D0=B0=D1=82?= =?UTF-8?q?=D0=B0=D0=BC=20=D1=80=D0=B5=D0=B2=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Requests/WellOperationRequest.cs | 2 +- .../Repository/WellOperationRepository.cs | 32 +++++++++++-------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/AsbCloudApp/Requests/WellOperationRequest.cs b/AsbCloudApp/Requests/WellOperationRequest.cs index 71f5e7d0..fa866378 100644 --- a/AsbCloudApp/Requests/WellOperationRequest.cs +++ b/AsbCloudApp/Requests/WellOperationRequest.cs @@ -99,6 +99,6 @@ public class WellOperationRequest : WellOperationRequestBase /// Идентификаторы скважин /// [Required] - [Length(1, 1)] + [Length(1, 100)] public IEnumerable IdsWell { get; } } \ No newline at end of file diff --git a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs index ba457362..bdbd1f0c 100644 --- a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs +++ b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs @@ -196,7 +196,7 @@ public class WellOperationRepository : CrudRepositoryBase WellOperationCategory.NonProductiveTimeSubIds.Contains(o.IdCategory)); - var filteredWellOperations = GetByRequest(wellOperationsWithType, request); + IEnumerable filteredWellOperations = FilterByRequest(wellOperationsWithType.AsQueryable(), request); var filteredWellOperationsPart = filteredWellOperations .Skip(skip) @@ -220,42 +220,46 @@ public class WellOperationRepository : CrudRepositoryBase GetByRequest(IEnumerable entities, WellOperationRequest request) + private T FilterByRequest(T entities, WellOperationRequest request) + where T : IQueryable, IEnumerable { if (request.OperationType.HasValue) - entities = entities.Where(e => e.IdType == request.OperationType.Value); + entities = (T)entities.Where(e => e.IdType == request.OperationType.Value); if (request.SectionTypeIds?.Any() is true) - entities = entities.Where(e => request.SectionTypeIds.Contains(e.IdWellSectionType)); + entities = (T)entities.Where(e => request.SectionTypeIds.Contains(e.IdWellSectionType)); if (request.OperationCategoryIds?.Any() is true) - entities = entities.Where(e => request.OperationCategoryIds.Contains(e.IdCategory)); + entities = (T)entities.Where(e => request.OperationCategoryIds.Contains(e.IdCategory)); if (request.GeDepth.HasValue) - entities = entities.Where(e => e.DepthEnd >= request.GeDepth.Value); + entities = (T)entities.Where(e => e.DepthEnd >= request.GeDepth.Value); if (request.LeDepth.HasValue) - entities = entities.Where(e => e.DepthEnd <= request.LeDepth.Value); + entities = (T)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); + entities = (T)entities.Where(e => e.DateStart >= geDateUtc); } if (request.LeDate.HasValue) { var leDateUtc = request.LeDate.Value.UtcDateTime; - entities = entities.Where(e => e.DateStart <= leDateUtc); + entities = (T)entities.Where(e => e.DateStart <= leDateUtc); } if (request.SortFields?.Any() is true) - entities = entities.AsQueryable().SortBy(request.SortFields); + entities = (T)entities.AsQueryable().SortBy(request.SortFields); return entities; } - private async Task> BuildQuery(WellOperationRequest request, CancellationToken token) + private async Task> BuildQuery(WellOperationRequest request, CancellationToken token) { - var entities = await GetByIdsWells(request.IdsWell, token); - entities = GetByRequest(entities, request); + var query = GetQuery() + .Where(e => request.IdsWell.Contains(e.IdWell)) + .OrderBy(e => e.DateStart) + .AsQueryable(); + query = FilterByRequest(query, request); - return entities; + return query; } public async Task> GetSectionsAsync(IEnumerable idsWells, CancellationToken token)