forked from ddrilling/AsbCloudServer
126 lines
5.3 KiB
C#
126 lines
5.3 KiB
C#
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;
|
|
}
|
|
|
|
/// <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)
|
|
return BadRequest();
|
|
|
|
if (!wellService.CheckWellOwnership((int)idCustomer, wellId))
|
|
return Forbid();
|
|
|
|
var wellDepthToDayData = analyticsService.GetWellDepthToDay(wellId);
|
|
|
|
return Ok(wellDepthToDayData);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Возвращает данные по глубине скважины за период
|
|
/// </summary>
|
|
/// <param name="wellId">id скважины</param>
|
|
/// <param name="intervalHours">количество часов в интервале выборки</param>
|
|
/// <param name="intervalMinutes">количество минут в интервале выборки</param>
|
|
/// <param name="workBeginHour">время начала рабочей смены (в часах)</param>
|
|
/// <param name="workBeginMinutes">время начала рабочей смены (в минутах)</param>
|
|
/// <returns>Коллекцию данных по глубине скважины за период</returns>
|
|
[HttpGet]
|
|
[Route("{wellId}/wellDepthToInterval")]
|
|
[ProducesResponseType(typeof(IEnumerable<WellDepthToIntervalDto>), (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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Возвращает данные по операциям на скважине "операции-время"
|
|
/// </summary>
|
|
/// <param name="wellId">id скважины</param>
|
|
/// <param name="begin">дата начала интервала</param>
|
|
/// <param name="end">дата окончания интервала</param>
|
|
/// <returns>Коллекцию операций на скважине</returns>
|
|
[HttpGet]
|
|
[Route("{wellId}/operationsSummary")]
|
|
[ProducesResponseType(typeof(List<OperationPercentageDto>), (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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Возвращает детальные данные по операциям на скважине за период
|
|
/// </summary>
|
|
/// <param name="wellId">id скважины</param>
|
|
/// <param name="begin">дата начала интервала</param>
|
|
/// <param name="end">дата окончания интервала</param>
|
|
/// <returns>Коллекцию операций на скважине</returns>
|
|
|
|
[HttpGet]
|
|
[Route("{wellId}/operationsToTime")]
|
|
[ProducesResponseType(typeof(List<OperationPercentageDto>), (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);
|
|
}
|
|
}
|
|
}
|