diff --git a/AsbCloudApp/Data/OperationDto.cs b/AsbCloudApp/Data/OperationDto.cs new file mode 100644 index 00000000..b74cd57e --- /dev/null +++ b/AsbCloudApp/Data/OperationDto.cs @@ -0,0 +1,13 @@ +using System; + +namespace AsbCloudApp.Data +{ + public class OperationDto + { + public string Name { get; set; } + public DateTime Begin { get; set; } + public DateTime End { get; set; } + public double OperationStartDepth { get; set; } + public double OperationEndDepth { get; set; } + } +} diff --git a/AsbCloudApp/Services/IAnalyticsService.cs b/AsbCloudApp/Services/IAnalyticsService.cs index 6654ee68..9a085a8e 100644 --- a/AsbCloudApp/Services/IAnalyticsService.cs +++ b/AsbCloudApp/Services/IAnalyticsService.cs @@ -7,6 +7,7 @@ namespace AsbCloudApp.Services { public interface IAnalyticsService { + IEnumerable GetOperations(int wellId); IEnumerable GetWellDepthToDay(int wellId); IEnumerable GetWellDepthToInterval(int wellId, int intervalHoursTimestamp, int workBeginTimestamp); diff --git a/AsbCloudInfrastructure/Services/AnalyticsService.cs b/AsbCloudInfrastructure/Services/AnalyticsService.cs index 6e9a0f5b..0a663b4a 100644 --- a/AsbCloudInfrastructure/Services/AnalyticsService.cs +++ b/AsbCloudInfrastructure/Services/AnalyticsService.cs @@ -28,6 +28,28 @@ namespace AsbCloudInfrastructure.Services operationDetectorService = new OperationDetectorService(operations); } + public IEnumerable GetOperations(int wellId) + { + var telemetry = telemetryService.GetTelemetryByWellId(wellId); + + if (telemetry is null) + return null; + + var operations = (from a in db.TelemetryAnalysis + where a.IdTelemetry == telemetry.Id + join o in db.Operations on a.IdOperation equals o.Id + select new OperationDto + { + Name = o.Name, + Begin = DateTimeOffset.FromUnixTimeSeconds(a.UnixDate).DateTime, + End = DateTimeOffset.FromUnixTimeSeconds(a.UnixDate + a.Duration).DateTime, + OperationStartDepth = a.OperationStartDepth ?? 0.0, + OperationEndDepth = a.OperationEndDepth ?? 0.0 + }).ToList().OrderBy(op => op.Begin); + + return operations; + } + public IEnumerable GetWellDepthToDay(int wellId) { var telemetry = telemetryService.GetTelemetryByWellId(wellId); diff --git a/AsbCloudWebApi/Controllers/AnalyticsController.cs b/AsbCloudWebApi/Controllers/AnalyticsController.cs index e7947017..82c06521 100644 --- a/AsbCloudWebApi/Controllers/AnalyticsController.cs +++ b/AsbCloudWebApi/Controllers/AnalyticsController.cs @@ -22,6 +22,29 @@ namespace AsbCloudWebApi.Controllers this.wellService = wellService; } + /// + /// Возвращает список операций на скважине за все время + /// + /// id скважины + /// Список операций на скважине за все время + [HttpGet] + [Route("{wellId}/operations")] + [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] + public IActionResult GetOperations(int wellId) + { + int? idCustomer = User.GetCustomerId(); + + if (idCustomer is null || !wellService.CheckWellOwnership((int)idCustomer, wellId)) + return Forbid(); + + var analytics = analyticsService.GetOperations(wellId); + + if (analytics is null || !analytics.Any()) + return NoContent(); + + return Ok(analytics); + } + /// /// Возвращает данные по скважине "глубина-день" /// @@ -104,7 +127,6 @@ namespace AsbCloudWebApi.Controllers /// количество секунд в необходимом интервале времени /// количество секунд в времени начала смены /// Коллекцию операций на скважине - [HttpGet] [Route("{wellId}/operationsToInterval")] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)]