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); + } + /// /// получить статистику по активным скважинам ///