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

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="wellId">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("{wellId}/operationsByWell")]
[ProducesResponseType(typeof(PaginationContainer<OperationDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetOperationsByWell(int wellId, 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.CheckWellOwnership((int)idCompany, wellId))
return Forbid();
var analytics = analyticsService.GetOperationsByWell(wellId, categoryIds, begin, end, skip, take);
if (analytics is null || analytics.Count == 0)
return NoContent();
return Ok(analytics);
}
/// <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? idCompany = User.GetCompanyId();
if (idCompany is null || !wellService.CheckWellOwnership((int)idCompany, 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="intervalSeconds">количество секунд в необходимом интервале времени</param>
/// <param name="workBeginSeconds">количество секунд в времени начала смены</param>
/// <returns>Коллекцию данных по глубине скважины за период</returns>
[HttpGet]
[Route("{wellId}/wellDepthToInterval")]
[ProducesResponseType(typeof(IEnumerable<WellDepthToIntervalDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetWellDepthToInterval(int wellId,
int intervalSeconds, int workBeginSeconds)
{
int? idCompany = User.GetCompanyId();
if (idCompany is null || !wellService.CheckWellOwnership((int)idCompany, wellId))
return Forbid();
var wellDepthToIntervalData = analyticsService.GetWellDepthToInterval(wellId,
intervalSeconds, workBeginSeconds);
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? idCompany = User.GetCompanyId();
if (idCompany is null || !wellService.CheckWellOwnership((int)idCompany, 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="intervalSeconds">количество секунд в необходимом интервале времени</param>
/// <param name="workBeginSeconds">количество секунд в времени начала смены</param>
/// <returns>Коллекцию операций на скважине</returns>
[HttpGet]
[Route("{wellId}/operationsToInterval")]
[ProducesResponseType(typeof(IEnumerable<OperationDurationDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetOperationsToInterval(int wellId,
int intervalSeconds, int workBeginSeconds)
{
int? idCompany = User.GetCompanyId();
if (idCompany is null || !wellService.CheckWellOwnership((int)idCompany, wellId))
return Forbid();
var analytics = analyticsService.GetOperationsToInterval(wellId, intervalSeconds, workBeginSeconds);
if (analytics is null || !analytics.Any())
return NoContent();
return Ok(analytics);
}
}
}