Fix DetectedOperationService.BuildQueryBase()

This commit is contained in:
ngfrolov 2023-12-29 10:20:25 +05:00
parent f9a6279d0d
commit 1c7423aaab
Signed by untrusted user who does not match committer: ng.frolov
GPG Key ID: E99907A0357B29A7

View File

@ -173,35 +173,34 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
}; };
} }
private IQueryable<DetectedOperation> BuildQueryBase(WellDto well, DetectedOperationRequest request) private IQueryable<DetectedOperation> BuildQueryBase(WellDto well, DetectedOperationRequest request)
{ {
var query = db.Set<DetectedOperation>() var query = db.Set<DetectedOperation>()
.Where(o => o.IdTelemetry == well.IdTelemetry); .Where(o => o.IdTelemetry == well.IdTelemetry);
if (request is not null) if (request.IdsTelemetries.Any())
{ {
if (request.IdsTelemetries.Any()) query = query
query = query.Where(o => request.IdsTelemetries.Contains(o.IdTelemetry)); .Union(db.Set<DetectedOperation>().Where(o => request.IdsTelemetries.Contains(o.IdTelemetry)));
}
if (request.IdsCategories.Any()) if (request.IdsCategories.Any())
query = query.Where(o => request.IdsCategories.Contains(o.IdCategory)); query = query.Where(o => request.IdsCategories.Contains(o.IdCategory));
if (request.GeDateStart is not null) if (request.GeDateStart is not null)
query = query.Where(o => o.DateStart >= request.GeDateStart.Value.Date.ToUtcDateTimeOffset(well.Timezone.Hours)); query = query.Where(o => o.DateStart >= request.GeDateStart.Value.Date.ToUtcDateTimeOffset(well.Timezone.Hours));
if (request.LeDateEnd is not null) if (request.LeDateEnd is not null)
query = query.Where(o => o.DateEnd <= request.LeDateEnd.Value.Date.ToUtcDateTimeOffset(well.Timezone.Hours)); query = query.Where(o => o.DateEnd <= request.LeDateEnd.Value.Date.ToUtcDateTimeOffset(well.Timezone.Hours));
if (request.GeDepth is not null) if (request.GeDepth is not null)
query = query.Where(o => o.DepthStart >= request.GeDepth); query = query.Where(o => o.DepthStart >= request.GeDepth);
if (request.LeDepth is not null) if (request.LeDepth is not null)
query = query.Where(o => o.DepthEnd <= request.LeDepth); query = query.Where(o => o.DepthEnd <= request.LeDepth);
if (request.IdTelemetryUser is not null) if (request.IdTelemetryUser is not null)
query = query.Where(o => o.IdUsersAtStart == request.IdTelemetryUser); query = query.Where(o => o.IdUsersAtStart == request.IdTelemetryUser);
}
return query; return query;
} }
@ -211,7 +210,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
IQueryable<DetectedOperation> query = BuildQueryBase(well, request) IQueryable<DetectedOperation> query = BuildQueryBase(well, request)
.Include(o => o.OperationCategory); .Include(o => o.OperationCategory);
if (request?.SortFields?.Any() == true) if (request.SortFields?.Any() == true)
{ {
query = query.SortBy(request.SortFields); query = query.SortBy(request.SortFields);
} }
@ -220,10 +219,10 @@ namespace AsbCloudInfrastructure.Services.DetectOperations
.OrderBy(o => o.DateStart) .OrderBy(o => o.DateStart)
.ThenBy(o => o.DepthStart); .ThenBy(o => o.DepthStart);
if (request?.Skip > 0) if (request.Skip.HasValue)
query = query.Skip((int)request.Skip); query = query.Skip((int)request.Skip);
if (request?.Take > 0) if (request.Take.HasValue)
query = query.Take((int)request.Take); query = query.Take((int)request.Take);
return query; return query;