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

150 lines
6.4 KiB
C#
Raw Normal View History

2021-07-21 15:29:19 +05:00
using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
2021-07-21 15:29:19 +05:00
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>
/// <returns>Список операций на скважине за все время</returns>
[HttpGet]
[Route("{wellId}/operations")]
[ProducesResponseType(typeof(IEnumerable<OperationDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetOperations(int wellId)
{
2021-07-21 15:22:58 +05:00
int? idCompany = User.GetCompanyId();
2021-07-21 15:22:58 +05:00
if (idCompany is null || !wellService.CheckWellOwnership((int)idCompany, wellId))
return Forbid();
var analytics = analyticsService.GetOperations(wellId);
if (analytics is null || !analytics.Any())
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)
{
2021-07-21 15:22:58 +05:00
int? idCompany = User.GetCompanyId();
2021-07-21 15:22:58 +05:00
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)]
2021-07-21 15:29:19 +05:00
public IActionResult GetWellDepthToInterval(int wellId,
int intervalSeconds, int workBeginSeconds)
{
2021-07-21 15:22:58 +05:00
int? idCompany = User.GetCompanyId();
2021-07-21 15:22:58 +05:00
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)
{
2021-07-21 15:22:58 +05:00
int? idCompany = User.GetCompanyId();
2021-07-21 15:22:58 +05:00
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)
{
2021-07-21 15:22:58 +05:00
int? idCompany = User.GetCompanyId();
2021-07-21 15:22:58 +05:00
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);
}
}
}