DD.WellWorkover.Cloud/AsbCloudWebApi/Controllers/AnalyticsController.cs

128 lines
5.5 KiB
C#

using System;
using System.Linq;
using System.Collections.Generic;
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
namespace AsbCloudWebApi.Controllers
{
[Route("api/analytics")]
[ApiController]
[Authorize]
public class AnalyticsController : ControllerBase
{
private readonly IAnalyticsService analyticsService;
private readonly IWellService wellService;
public AnalyticsController(IAnalyticsService analyticsService, IWellService wellService)
{
this.analyticsService = analyticsService;
this.wellService = wellService;
}
/// <summary>
/// Возвращает данные по скважине "глубина-день"
/// </summary>
/// <param name="wellId">id скважины</param>
/// <returns>Коллекцию данных по скважине "глубина-день"</returns>
[HttpGet]
[Route("{wellId}/wellDepthToDay")]
[ProducesResponseType(typeof(IEnumerable<WellDepthToDayDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetWellDepthToDay(int wellId)
{
int? idCustomer = User.GetCustomerId();
if (idCustomer is null || !wellService.CheckWellOwnership((int)idCustomer, wellId))
return Forbid();
var wellDepthToDayData = analyticsService.GetWellDepthToDay(wellId);
if (wellDepthToDayData is null || !wellDepthToDayData.Any())
return NoContent();
return Ok(wellDepthToDayData);
}
/// <summary>
/// Возвращает данные по глубине скважины за период
/// </summary>
/// <param name="wellId">id скважины</param>
/// <param name="intervalHoursTimestamp">количество секунд в необходимом интервале времени</param>
/// <param name="workBeginTimestamp">количество секунд в времени начала смены</param>
/// <returns>Коллекцию данных по глубине скважины за период</returns>
[HttpGet]
[Route("{wellId}/wellDepthToInterval")]
[ProducesResponseType(typeof(IEnumerable<WellDepthToIntervalDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetWellDepthToInterval(int wellId,
int intervalHoursTimestamp, int workBeginTimestamp)
{
int? idCustomer = User.GetCustomerId();
if (idCustomer is null || !wellService.CheckWellOwnership((int)idCustomer, wellId))
return Forbid();
var wellDepthToIntervalData = analyticsService.GetWellDepthToInterval(wellId,
intervalHoursTimestamp, workBeginTimestamp);
if (wellDepthToIntervalData is null || !wellDepthToIntervalData.Any())
return NoContent();
return Ok(wellDepthToIntervalData);
}
/// <summary>
/// Возвращает данные по операциям на скважине "операции-время"
/// </summary>
/// <param name="wellId">id скважины</param>
/// <param name="begin">дата начала интервала</param>
/// <param name="end">дата окончания интервала</param>
/// <returns>Коллекцию операций на скважине</returns>
[HttpGet]
[Route("{wellId}/operationsSummary")]
[ProducesResponseType(typeof(IEnumerable<OperationDurationDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetOperationsSummary(int wellId, DateTime begin = default, DateTime end = default)
{
int? idCustomer = User.GetCustomerId();
if (idCustomer is null || !wellService.CheckWellOwnership((int)idCustomer, wellId))
return Forbid();
var analytics = analyticsService.GetOperationsSummary(wellId, begin, end);
if (analytics is null || !analytics.Any())
return NoContent();
return Ok(analytics);
}
/// <summary>
/// Возвращает детальные данные по операциям на скважине за период
/// </summary>
/// <param name="wellId">id скважины</param>
/// <param name="intervalHoursTimestamp">количество секунд в необходимом интервале времени</param>
/// <param name="workBeginTimestamp">количество секунд в времени начала смены</param>
/// <returns>Коллекцию операций на скважине</returns>
[HttpGet]
[Route("{wellId}/operationsToInterval")]
[ProducesResponseType(typeof(IEnumerable<OperationDurationDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetOperationsToInterval(int wellId,
int intervalHoursTimestamp, int workBeginTimestamp)
{
int? idCustomer = User.GetCustomerId();
if (idCustomer is null || !wellService.CheckWellOwnership((int)idCustomer, wellId))
return Forbid();
var analytics = analyticsService.GetOperationsToInterval(wellId, intervalHoursTimestamp, workBeginTimestamp);
if (analytics is null || !analytics.Any())
return NoContent();
return Ok(analytics);
}
}
}