forked from ddrilling/AsbCloudServer
Правка по результатам ревью
This commit is contained in:
parent
9926d3fcf2
commit
1c3f779f74
@ -99,6 +99,6 @@ public class WellOperationRequest : WellOperationRequestBase
|
||||
/// Идентификаторы скважин
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Length(1, 1)]
|
||||
[Length(1, 100)]
|
||||
public IEnumerable<int> IdsWell { get; }
|
||||
}
|
@ -196,7 +196,7 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
||||
var operationsWithNpt = wellOperationsWithType
|
||||
.Where(o => WellOperationCategory.NonProductiveTimeSubIds.Contains(o.IdCategory));
|
||||
|
||||
var filteredWellOperations = GetByRequest(wellOperationsWithType, request);
|
||||
IEnumerable<WellOperation> filteredWellOperations = FilterByRequest(wellOperationsWithType.AsQueryable(), request);
|
||||
|
||||
var filteredWellOperationsPart = filteredWellOperations
|
||||
.Skip(skip)
|
||||
@ -220,42 +220,46 @@ public class WellOperationRepository : CrudRepositoryBase<WellOperationDto, Well
|
||||
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)
|
||||
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<IEnumerable<WellOperation>> BuildQuery(WellOperationRequest request, CancellationToken token)
|
||||
private async Task<IQueryable<WellOperation>> 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<IEnumerable<SectionByOperationsDto>> GetSectionsAsync(IEnumerable<int> idsWells, CancellationToken token)
|
||||
|
Loading…
Reference in New Issue
Block a user