Правка по результатам ревью

This commit is contained in:
Olga Nemt 2024-04-24 12:28:37 +05:00
parent 9926d3fcf2
commit 1c3f779f74
2 changed files with 19 additions and 15 deletions

View File

@ -99,6 +99,6 @@ public class WellOperationRequest : WellOperationRequestBase
/// Идентификаторы скважин /// Идентификаторы скважин
/// </summary> /// </summary>
[Required] [Required]
[Length(1, 1)] [Length(1, 100)]
public IEnumerable<int> IdsWell { get; } public IEnumerable<int> IdsWell { get; }
} }

View File

@ -196,7 +196,7 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
var operationsWithNpt = wellOperationsWithType var operationsWithNpt = wellOperationsWithType
.Where(o => WellOperationCategory.NonProductiveTimeSubIds.Contains(o.IdCategory)); .Where(o => WellOperationCategory.NonProductiveTimeSubIds.Contains(o.IdCategory));
var filteredWellOperations = GetByRequest(wellOperationsWithType, request); IEnumerable<WellOperation> filteredWellOperations = FilterByRequest(wellOperationsWithType.AsQueryable(), request);
var filteredWellOperationsPart = filteredWellOperations var filteredWellOperationsPart = filteredWellOperations
.Skip(skip) .Skip(skip)
@ -220,42 +220,46 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
return (result, count); return (result, count);
} }
private IEnumerable<WellOperation> GetByRequest(IEnumerable<WellOperation> entities, WellOperationRequest request) private T FilterByRequest<T>(T entities, WellOperationRequest request)
where T : IQueryable<WellOperation>, IEnumerable<WellOperation>
{ {
if (request.OperationType.HasValue) 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) 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) 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) 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) 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) if (request.GeDate.HasValue)
{ {
var geDateUtc = request.GeDate.Value.UtcDateTime; 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) if (request.LeDate.HasValue)
{ {
var leDateUtc = request.LeDate.Value.UtcDateTime; 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) if (request.SortFields?.Any() is true)
entities = entities.AsQueryable().SortBy(request.SortFields); entities = (T)entities.AsQueryable().SortBy(request.SortFields);
return entities; return entities;
} }
private async Task<IEnumerable<WellOperation>> BuildQuery(WellOperationRequest request, CancellationToken token) private async Task<IQueryable<WellOperation>> BuildQuery(WellOperationRequest request, CancellationToken token)
{ {
var entities = await GetByIdsWells(request.IdsWell, token); var query = GetQuery()
entities = GetByRequest(entities, request); .Where(e => request.IdsWell.Contains(e.IdWell))
.OrderBy(e => e.DateStart)
.AsQueryable();
query = FilterByRequest(query, request);
return entities; return query;
} }
public async Task<IEnumerable<SectionByOperationsDto>> GetSectionsAsync(IEnumerable<int> idsWells, CancellationToken token) public async Task<IEnumerable<SectionByOperationsDto>> GetSectionsAsync(IEnumerable<int> idsWells, CancellationToken token)