From e66f716e62cb19e179af6d238c8d34437f8590bb Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Mon, 28 Aug 2023 09:43:32 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B7=D1=8E=D0=B8=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=90=D0=9F=D0=94=20=D0=BD=D0=B0=20=D0=90=D0=9F?= =?UTF-8?q?=D0=94=20=D0=B2=20=D1=80=D0=BE=D1=82=D0=BE=D1=80=D0=B5=20=D0=B8?= =?UTF-8?q?=20=D0=90=D0=9F=D0=94=20=D0=B2=20=D1=81=D0=BB=D0=B0=D0=B9=D0=B4?= =?UTF-8?q?=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Subsystems/ISubsystemOperationTimeService.cs | 8 ++++++++ .../Subsystems/SubsystemOperationTimeService.cs | 16 +++++++++++++++- .../SubsystemOperationTimeController.cs | 16 ++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/AsbCloudApp/Services/Subsystems/ISubsystemOperationTimeService.cs b/AsbCloudApp/Services/Subsystems/ISubsystemOperationTimeService.cs index 2f6fb8f5..746fa398 100644 --- a/AsbCloudApp/Services/Subsystems/ISubsystemOperationTimeService.cs +++ b/AsbCloudApp/Services/Subsystems/ISubsystemOperationTimeService.cs @@ -64,5 +64,13 @@ namespace AsbCloudApp.Services.Subsystems /// /// Task> GetStatByActiveWells(IEnumerable wellIds, CancellationToken token); + + /// + /// Получение периода, за который будет расчитываться статистика + /// + /// + /// + /// + Task> GetStatDateRangeAsync(SubsystemOperationTimeRequest request, CancellationToken token); } } diff --git a/AsbCloudInfrastructure/Services/Subsystems/SubsystemOperationTimeService.cs b/AsbCloudInfrastructure/Services/Subsystems/SubsystemOperationTimeService.cs index d866c974..11c3014b 100644 --- a/AsbCloudInfrastructure/Services/Subsystems/SubsystemOperationTimeService.cs +++ b/AsbCloudInfrastructure/Services/Subsystems/SubsystemOperationTimeService.cs @@ -109,6 +109,20 @@ namespace AsbCloudInfrastructure.Services.Subsystems return statList; } + public async Task> GetStatDateRangeAsync(SubsystemOperationTimeRequest request, CancellationToken token) + { + request.SelectMode = SubsystemOperationTimeRequest.SelectModeTrim; + var data = await GetOperationTimeAsync(request, token); + if (data is null) + return Enumerable.Empty(); + + var dateRanges = new List(); + dateRanges.Add(data.Min(d => d.DateStart)); + dateRanges.Add(data.Max(d => d.DateEnd)); + + return dateRanges.AsEnumerable(); + } + private static IEnumerable TrimOperation(IEnumerable data, DateTimeOffset? gtDate, DateTimeOffset? ltDate) { if (!ltDate.HasValue && !gtDate.HasValue) @@ -162,7 +176,7 @@ namespace AsbCloudInfrastructure.Services.Subsystems UsedTimeHours = periodGroup, KUsage = periodGroupDepth / depthIntervalSubsystem, SumDepthInterval = periodGroupDepth, - OperationCount = g.Count() + OperationCount = g.Count(), }; if (subsystemStat.KUsage > 1) subsystemStat.KUsage = 1; diff --git a/AsbCloudWebApi/Controllers/Subsystems/SubsystemOperationTimeController.cs b/AsbCloudWebApi/Controllers/Subsystems/SubsystemOperationTimeController.cs index 44deb4d9..879d61b7 100644 --- a/AsbCloudWebApi/Controllers/Subsystems/SubsystemOperationTimeController.cs +++ b/AsbCloudWebApi/Controllers/Subsystems/SubsystemOperationTimeController.cs @@ -53,6 +53,22 @@ namespace AsbCloudWebApi.Controllers.Subsystems return Ok(subsystemResult); } + /// + /// получить период, за который будет расчитываться статистика + /// + [HttpGet("dateRange")] + [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] + public async Task GetStatDateRangeAsync([FromQuery] SubsystemOperationTimeRequest request, CancellationToken token) + { + if (!await UserHasAccesToWellAsync(request.IdWell, token)) + return Forbid(); + if (!await IsValidRequest(request, token)) + return BadRequest("Запрашиваемый диапазон должен заканчиваться за 2 часа до текущего времени(после приведения к UTC)."); + + var dateRange = await subsystemOperationTimeService.GetStatDateRangeAsync(request, token); + return Ok(dateRange); + } + /// /// получить статистику по активным скважинам ///