DD.WellWorkover.Cloud/AsbCloudWebApi/Controllers/AnalyticsController.cs
2021-07-27 14:43:30 +05:00

156 lines
7.0 KiB
C#

using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
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="idWell">id скважины</param>
/// <param name="categoryIds">список категорий</param>
/// <param name="begin">дата начала</param>
/// <param name="end">окончание</param>
/// <param name="skip">для пагинации кол-во записей пропустить</param>
/// <param name="take">для пагинации кол-во записей </param>
/// <returns>Список операций на скважине за все время</returns>
[HttpGet]
[Route("{idWell}/operationsByWell")]
[ProducesResponseType(typeof(PaginationContainer<TelemetryOperationDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetOperationsByWell(int idWell, int skip = 0, int take = 32,
[FromQuery] IEnumerable<int> categoryIds = default, DateTime begin = default, DateTime end = default)
{
int? idCompany = User.GetCompanyId();
if (idCompany is null || !wellService.IsCompanyOwnsWell((int)idCompany, idWell))
return Forbid();
var analytics = analyticsService.GetOperationsByWell(idWell, categoryIds, begin, end, skip, take);
if (analytics is null || analytics.Count == 0)
return NoContent();
return Ok(analytics);
}
/// <summary>
/// Возвращает данные по скважине "глубина-день"
/// </summary>
/// <param name="idWell">id скважины</param>
/// <returns>Коллекцию данных по скважине "глубина-день"</returns>
[HttpGet]
[Route("{idWell}/wellDepthToDay")]
[ProducesResponseType(typeof(IEnumerable<WellDepthToDayDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetWellDepthToDay(int idWell)
{
int? idCompany = User.GetCompanyId();
if (idCompany is null || !wellService.IsCompanyOwnsWell((int)idCompany, idWell))
return Forbid();
var wellDepthToDayData = analyticsService.GetWellDepthToDay(idWell);
if (wellDepthToDayData is null || !wellDepthToDayData.Any())
return NoContent();
return Ok(wellDepthToDayData);
}
/// <summary>
/// Возвращает данные по глубине скважины за период
/// </summary>
/// <param name="idWell">id скважины</param>
/// <param name="intervalSeconds">количество секунд в необходимом интервале времени</param>
/// <param name="workBeginSeconds">количество секунд в времени начала смены</param>
/// <returns>Коллекцию данных по глубине скважины за период</returns>
[HttpGet]
[Route("{idWell}/wellDepthToInterval")]
[ProducesResponseType(typeof(IEnumerable<WellDepthToIntervalDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetWellDepthToInterval(int idWell,
int intervalSeconds, int workBeginSeconds)
{
int? idCompany = User.GetCompanyId();
if (idCompany is null || !wellService.IsCompanyOwnsWell((int)idCompany, idWell))
return Forbid();
var wellDepthToIntervalData = analyticsService.GetWellDepthToInterval(idWell,
intervalSeconds, workBeginSeconds);
if (wellDepthToIntervalData is null || !wellDepthToIntervalData.Any())
return NoContent();
return Ok(wellDepthToIntervalData);
}
/// <summary>
/// Возвращает данные по операциям на скважине "операции-время"
/// </summary>
/// <param name="idWell">id скважины</param>
/// <param name="begin">дата начала интервала</param>
/// <param name="end">дата окончания интервала</param>
/// <returns>Коллекцию операций на скважине</returns>
[HttpGet]
[Route("{idWell}/operationsSummary")]
[ProducesResponseType(typeof(IEnumerable<TelemetryOperationDurationDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetOperationsSummary(int idWell, DateTime begin = default, DateTime end = default)
{
int? idCompany = User.GetCompanyId();
if (idCompany is null || !wellService.IsCompanyOwnsWell((int)idCompany, idWell))
return Forbid();
var analytics = analyticsService.GetOperationsSummary(idWell, begin, end);
if (analytics is null || !analytics.Any())
return NoContent();
return Ok(analytics);
}
/// <summary>
/// Возвращает детальные данные по операциям на скважине за период
/// </summary>
/// <param name="idWell">id скважины</param>
/// <param name="intervalSeconds">количество секунд в необходимом интервале времени</param>
/// <param name="workBeginSeconds">количество секунд в времени начала смены</param>
/// <returns>Коллекцию операций на скважине</returns>
[HttpGet]
[Route("{idWell}/operationsToInterval")]
[ProducesResponseType(typeof(IEnumerable<TelemetryOperationDurationDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetOperationsToInterval(int idWell,
int intervalSeconds, int workBeginSeconds)
{
int? idCompany = User.GetCompanyId();
if (idCompany is null || !wellService.IsCompanyOwnsWell((int)idCompany, idWell))
return Forbid();
var analytics = analyticsService.GetOperationsToInterval(idWell, intervalSeconds, workBeginSeconds);
if (analytics is null || !analytics.Any())
return NoContent();
return Ok(analytics);
}
}
}