From dd711c4aa5dce10a52b8f33aefa433d462228d56 Mon Sep 17 00:00:00 2001 From: eugeniy_ivanov Date: Fri, 21 Oct 2022 15:52:51 +0500 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB=D0=BB=D0=B5?= =?UTF-8?q?=D1=80=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B4=D0=B8=D0=B0=D0=BF=D0=BE=D0=B7?= =?UTF-8?q?=D0=BE=D0=BD=D0=B0=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=20=D0=B0=D1=80=D0=B3=D1=83=D0=BC=D0=B5=D0=BD=D1=82=20=D0=BC?= =?UTF-8?q?=D0=B5=D1=82=D0=BE=D0=B4=D0=B0=20=D0=BF=D0=B5=D1=80=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=BE=D0=B5=D0=BD=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8?= =?UTF-8?q?=D0=BA=D0=B0=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20=D0=BC?= =?UTF-8?q?=D0=B5=D1=82=D0=BE=D0=B4=D0=B0=20=D0=B8=20=D0=B2=D0=BE=D0=B7?= =?UTF-8?q?=D0=B2=D1=80=D0=B0=D1=89=D0=B0=D0=B5=D0=BC=D0=BE=D0=B5=20=D0=B7?= =?UTF-8?q?=D0=BD=D0=B0=D1=87=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ISubsystemOperationTimeService.cs | 5 +-- .../SubsystemOperationTimeService.cs | 34 ++++++++++++------- .../SubsystemOperationTimeController.cs | 13 +++++++ 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/AsbCloudApp/Services/Subsystems/ISubsystemOperationTimeService.cs b/AsbCloudApp/Services/Subsystems/ISubsystemOperationTimeService.cs index 605d844c..e8332f36 100644 --- a/AsbCloudApp/Services/Subsystems/ISubsystemOperationTimeService.cs +++ b/AsbCloudApp/Services/Subsystems/ISubsystemOperationTimeService.cs @@ -1,5 +1,6 @@ using AsbCloudApp.Data.Subsystems; using AsbCloudApp.Requests; +using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -41,10 +42,10 @@ namespace AsbCloudApp.Services.Subsystems /// /// Временной диапазон за который есть статистика работы подсистем /// - /// + /// /// /// - Task?> GetDateRangeOperationTimeAsync(int idSubsystem, CancellationToken token); + Task?> GetDateRangeOperationTimeAsync(SubsystemOperationTimeRequest request, CancellationToken token); } #nullable disable } diff --git a/AsbCloudInfrastructure/Services/Subsystems/SubsystemOperationTimeService.cs b/AsbCloudInfrastructure/Services/Subsystems/SubsystemOperationTimeService.cs index 5b0fdbb1..09027db2 100644 --- a/AsbCloudInfrastructure/Services/Subsystems/SubsystemOperationTimeService.cs +++ b/AsbCloudInfrastructure/Services/Subsystems/SubsystemOperationTimeService.cs @@ -185,22 +185,28 @@ namespace AsbCloudInfrastructure.Services.Subsystems } - private async Task<(DateTimeOffset, DateTimeOffset)?> GetDateRangeOperationTime(int idSubsystem, CancellationToken token) + /// + public async Task?> GetDateRangeOperationTimeAsync(SubsystemOperationTimeRequest request, CancellationToken token) { - var dateRange = await db.SubsystemOperationTimes - .Where(o => o.Id == idSubsystem) - .GroupBy(o => o.IdSubsystem) - .Select(g => new - { - DateFirst = g.Min(o => o.DateStart), - DateLast = g.Max(o => o.DateEnd) - }) - .FirstOrDefaultAsync(token); - if (dateRange == null) - { + if (request.IdsSubsystems is null) return null; + List<(DateTimeOffset dateFirst, DateTimeOffset dateLast)> result = new(); + var dateRanges = await db.SubsystemOperationTimes + .Where(o => request.IdsSubsystems.Contains(o.IdSubsystem)) + .GroupBy(o => o.IdSubsystem) + .Select(g => new + { + DateFirst = g.Min(o => o.DateStart), + DateLast = g.Max(o => o.DateEnd) + }) + .ToListAsync(token); + if (dateRanges.Any() != true) + return null; + foreach (var dateRange in dateRanges) + { + var resultItem = (dateRange.DateFirst, dateRange.DateLast); + result.Add(resultItem); } - (DateTimeOffset dateFirst, DateTimeOffset dateLast) result = (dateRange.DateFirst, dateRange.DateLast); return result; } @@ -268,6 +274,8 @@ namespace AsbCloudInfrastructure.Services.Subsystems dto.DateEnd = operationTime.DateEnd.ToRemoteDateTime(well.Timezone.Hours); return dto; } + + } #nullable disable } diff --git a/AsbCloudWebApi/Controllers/Subsystems/SubsystemOperationTimeController.cs b/AsbCloudWebApi/Controllers/Subsystems/SubsystemOperationTimeController.cs index e4466d9d..e69ef535 100644 --- a/AsbCloudWebApi/Controllers/Subsystems/SubsystemOperationTimeController.cs +++ b/AsbCloudWebApi/Controllers/Subsystems/SubsystemOperationTimeController.cs @@ -59,6 +59,19 @@ namespace AsbCloudWebApi.Controllers.Subsystems return Ok(result); } + /// + /// получить доступный диапазон дат наработки подсистемы. + /// + [HttpGet("rangeDate")] + [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] + public async Task GetDateRangeOperationTimeAsync([FromQuery] SubsystemOperationTimeRequest request, CancellationToken token = default) + { + if (!await UserHasAccesToWellAsync(request.IdWell, token)) + return Forbid(); + var result = await subsystemOperationTimeService.GetDateRangeOperationTimeAsync(request, token); + return Ok(result); + } + /// /// получить список наработок подсистем ///