From 1c7423aaabe46259811031ff3c419ff63b90f198 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Fri, 29 Dec 2023 10:20:25 +0500 Subject: [PATCH 1/2] Fix DetectedOperationService.BuildQueryBase() --- .../DetectedOperationService.cs | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs index 9691c7fb..23a5d20b 100644 --- a/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs +++ b/AsbCloudInfrastructure/Services/DetectOperations/DetectedOperationService.cs @@ -173,35 +173,34 @@ namespace AsbCloudInfrastructure.Services.DetectOperations }; } - private IQueryable BuildQueryBase(WellDto well, DetectedOperationRequest request) { var query = db.Set() .Where(o => o.IdTelemetry == well.IdTelemetry); - if (request is not null) + if (request.IdsTelemetries.Any()) { - if (request.IdsTelemetries.Any()) - query = query.Where(o => request.IdsTelemetries.Contains(o.IdTelemetry)); + query = query + .Union(db.Set().Where(o => request.IdsTelemetries.Contains(o.IdTelemetry))); + } - if (request.IdsCategories.Any()) - query = query.Where(o => request.IdsCategories.Contains(o.IdCategory)); + if (request.IdsCategories.Any()) + query = query.Where(o => request.IdsCategories.Contains(o.IdCategory)); - if (request.GeDateStart is not null) - query = query.Where(o => o.DateStart >= request.GeDateStart.Value.Date.ToUtcDateTimeOffset(well.Timezone.Hours)); + if (request.GeDateStart is not null) + query = query.Where(o => o.DateStart >= request.GeDateStart.Value.Date.ToUtcDateTimeOffset(well.Timezone.Hours)); - if (request.LeDateEnd is not null) - query = query.Where(o => o.DateEnd <= request.LeDateEnd.Value.Date.ToUtcDateTimeOffset(well.Timezone.Hours)); + if (request.LeDateEnd is not null) + query = query.Where(o => o.DateEnd <= request.LeDateEnd.Value.Date.ToUtcDateTimeOffset(well.Timezone.Hours)); - if (request.GeDepth is not null) - query = query.Where(o => o.DepthStart >= request.GeDepth); + if (request.GeDepth is not null) + query = query.Where(o => o.DepthStart >= request.GeDepth); - if (request.LeDepth is not null) - query = query.Where(o => o.DepthEnd <= request.LeDepth); + if (request.LeDepth is not null) + query = query.Where(o => o.DepthEnd <= request.LeDepth); - if (request.IdTelemetryUser is not null) - query = query.Where(o => o.IdUsersAtStart == request.IdTelemetryUser); - } + if (request.IdTelemetryUser is not null) + query = query.Where(o => o.IdUsersAtStart == request.IdTelemetryUser); return query; } @@ -211,7 +210,7 @@ namespace AsbCloudInfrastructure.Services.DetectOperations IQueryable query = BuildQueryBase(well, request) .Include(o => o.OperationCategory); - if (request?.SortFields?.Any() == true) + if (request.SortFields?.Any() == true) { query = query.SortBy(request.SortFields); } @@ -220,10 +219,10 @@ namespace AsbCloudInfrastructure.Services.DetectOperations .OrderBy(o => o.DateStart) .ThenBy(o => o.DepthStart); - if (request?.Skip > 0) + if (request.Skip.HasValue) query = query.Skip((int)request.Skip); - if (request?.Take > 0) + if (request.Take.HasValue) query = query.Take((int)request.Take); return query; From e0ddd26278babb94359549cf11c62acc4c3cff6d Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Fri, 29 Dec 2023 11:08:02 +0500 Subject: [PATCH 2/2] Fix SubsystemService.GetStatAsync(..) --- .../Services/Subsystems/SubsystemService.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/AsbCloudInfrastructure/Services/Subsystems/SubsystemService.cs b/AsbCloudInfrastructure/Services/Subsystems/SubsystemService.cs index 34626f78..c5b38405 100644 --- a/AsbCloudInfrastructure/Services/Subsystems/SubsystemService.cs +++ b/AsbCloudInfrastructure/Services/Subsystems/SubsystemService.cs @@ -227,19 +227,17 @@ internal class SubsystemService : ISubsystemService var request = new DetectedOperationRequest { - IdsTelemetries = idsTelemetries, + IdWell = well.Id, IdsCategories = WellOperationCategory.MechanicalDrillingSubIds, GeDateStart = geDateStartUtc, LeDateEnd = leDateUtc, }; - var operations = await detectedOperationService + var telemetryOperations = await detectedOperationService .GetOperationsAsync(request, token); var wellStat = new SubsystemActiveWellStatDto { Well = well }; - var telemetryOperations = operations.Where(o => o.IdTelemetry == well.IdTelemetry); - if (!telemetryOperations.Any()) continue; @@ -250,6 +248,7 @@ internal class SubsystemService : ISubsystemService wellStat.SubsystemAPD = subsystemStat.FirstOrDefault(s => s.IdSubsystem == IdSubsystemAPD); wellStat.SubsystemOscillation = subsystemStat.FirstOrDefault(s => s.IdSubsystem == IdSubsystemOscillation); + wellsStat.Add(wellStat); } return wellsStat;