using System;
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;
}
///
/// Возвращает данные по скважине "глубина-день"
///
/// id скважины
/// Коллекцию данных по скважине "глубина-день"
[HttpGet]
[Route("{wellId}/wellDepthToDay")]
[ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetWellDepthToDay(int wellId)
{
int? idCustomer = User.GetCustomerId();
if (idCustomer is null)
return BadRequest();
if (!wellService.CheckWellOwnership((int)idCustomer, wellId))
return Forbid();
var wellDepthToDayData = analyticsService.GetWellDepthToDay(wellId);
return Ok(wellDepthToDayData);
}
///
/// Возвращает данные по глубине скважины за период
///
/// id скважины
/// количество часов в интервале выборки
/// количество минут в интервале выборки
/// время начала рабочей смены (в часах)
/// время начала рабочей смены (в минутах)
/// Коллекцию данных по глубине скважины за период
[HttpGet]
[Route("{wellId}/wellDepthToInterval")]
[ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetWellDepthToInterval(int wellId, int intervalHours, int intervalMinutes, int workBeginHour, int workBeginMinutes)
{
int? idCustomer = User.GetCustomerId();
if (idCustomer is null)
return BadRequest();
if (!wellService.CheckWellOwnership((int)idCustomer, wellId))
return Forbid();
var wellDepthToIntervalData = analyticsService.GetWellDepthToInterval(wellId, intervalHours, intervalMinutes, workBeginHour, workBeginMinutes);
return Ok(wellDepthToIntervalData);
}
///
/// Возвращает данные по операциям на скважине "операции-время"
///
/// id скважины
/// дата начала интервала
/// дата окончания интервала
/// Коллекцию операций на скважине
[HttpGet]
[Route("{wellId}/operationsSummary")]
[ProducesResponseType(typeof(List), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetOperationsSummary(int wellId, DateTime begin = default, DateTime end = default)
{
int? idCustomer = User.GetCustomerId();
if (idCustomer is null)
return BadRequest();
if (!wellService.CheckWellOwnership((int)idCustomer, wellId))
return Forbid();
var analytics = analyticsService.GetOperationsSummary(wellId, begin, end);
return Ok(analytics);
}
///
/// Возвращает детальные данные по операциям на скважине за период
///
/// id скважины
/// дата начала интервала
/// дата окончания интервала
/// Коллекцию операций на скважине
[HttpGet]
[Route("{wellId}/operationsToTime")]
[ProducesResponseType(typeof(List), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetOperationsToTime(int wellId, DateTime begin = default, DateTime end = default)
{
int? idCustomer = User.GetCustomerId();
if (idCustomer is null)
return BadRequest();
if (!wellService.CheckWellOwnership((int)idCustomer, wellId))
return Forbid();
var analytics = GetOperationsToTime(wellId, begin, end);
return Ok(analytics);
}
}
}