2021-07-21 15:29:19 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
2021-06-17 15:12:39 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
2021-06-16 14:47:36 +05:00
|
|
|
|
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;
|
2021-08-11 16:54:42 +05:00
|
|
|
|
using System.Threading;
|
2021-08-11 12:11:21 +05:00
|
|
|
|
using System.Threading.Tasks;
|
2021-06-16 14:47:36 +05:00
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/analytics")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class AnalyticsController : ControllerBase
|
|
|
|
|
{
|
2021-06-17 15:12:39 +05:00
|
|
|
|
private readonly IAnalyticsService analyticsService;
|
|
|
|
|
private readonly IWellService wellService;
|
|
|
|
|
|
|
|
|
|
public AnalyticsController(IAnalyticsService analyticsService, IWellService wellService)
|
|
|
|
|
{
|
|
|
|
|
this.analyticsService = analyticsService;
|
|
|
|
|
this.wellService = wellService;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-20 15:13:26 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает список операций на скважине за все время
|
|
|
|
|
/// </summary>
|
2021-07-27 14:43:30 +05:00
|
|
|
|
/// <param name="idWell">id скважины</param>
|
2021-07-21 16:49:24 +05:00
|
|
|
|
/// <param name="categoryIds">список категорий</param>
|
|
|
|
|
/// <param name="begin">дата начала</param>
|
|
|
|
|
/// <param name="end">окончание</param>
|
|
|
|
|
/// <param name="skip">для пагинации кол-во записей пропустить</param>
|
|
|
|
|
/// <param name="take">для пагинации кол-во записей </param>
|
2021-08-11 16:54:42 +05:00
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
2021-07-20 15:13:26 +05:00
|
|
|
|
/// <returns>Список операций на скважине за все время</returns>
|
|
|
|
|
[HttpGet]
|
2021-07-27 14:43:30 +05:00
|
|
|
|
[Route("{idWell}/operationsByWell")]
|
2021-07-27 13:32:00 +05:00
|
|
|
|
[ProducesResponseType(typeof(PaginationContainer<TelemetryOperationDto>), (int)System.Net.HttpStatusCode.OK)]
|
2021-08-11 12:11:21 +05:00
|
|
|
|
public async Task<IActionResult> GetOperationsByWellAsync(int idWell, int skip = 0, int take = 32,
|
2021-08-11 16:54:42 +05:00
|
|
|
|
[FromQuery] IEnumerable<int> categoryIds = default, DateTime begin = default, DateTime end = default,
|
|
|
|
|
CancellationToken token = default)
|
2021-07-20 15:13:26 +05:00
|
|
|
|
{
|
2021-07-21 15:22:58 +05:00
|
|
|
|
int? idCompany = User.GetCompanyId();
|
2021-07-20 15:13:26 +05:00
|
|
|
|
|
2021-08-11 16:54:42 +05:00
|
|
|
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token))
|
2021-07-20 15:13:26 +05:00
|
|
|
|
return Forbid();
|
|
|
|
|
|
2021-08-11 16:54:42 +05:00
|
|
|
|
var analytics = await analyticsService.GetOperationsByWellAsync(idWell, categoryIds, begin, end, skip, take, token);
|
2021-07-20 15:13:26 +05:00
|
|
|
|
|
2021-07-21 16:49:24 +05:00
|
|
|
|
if (analytics is null || analytics.Count == 0)
|
2021-07-20 15:13:26 +05:00
|
|
|
|
return NoContent();
|
|
|
|
|
|
|
|
|
|
return Ok(analytics);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-17 15:12:39 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает данные по скважине "глубина-день"
|
|
|
|
|
/// </summary>
|
2021-07-27 14:43:30 +05:00
|
|
|
|
/// <param name="idWell">id скважины</param>
|
2021-08-11 16:54:42 +05:00
|
|
|
|
/// <param name="token">Токен отмены задачи</param>
|
2021-06-17 15:12:39 +05:00
|
|
|
|
/// <returns>Коллекцию данных по скважине "глубина-день"</returns>
|
|
|
|
|
[HttpGet]
|
2021-07-27 14:43:30 +05:00
|
|
|
|
[Route("{idWell}/wellDepthToDay")]
|
2021-06-22 09:49:53 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<WellDepthToDayDto>), (int)System.Net.HttpStatusCode.OK)]
|
2021-08-11 16:54:42 +05:00
|
|
|
|
public async Task<IActionResult> GetWellDepthToDayAsync(int idWell,
|
|
|
|
|
CancellationToken token = default)
|
2021-06-17 15:12:39 +05:00
|
|
|
|
{
|
2021-07-21 15:22:58 +05:00
|
|
|
|
int? idCompany = User.GetCompanyId();
|
2021-06-17 15:12:39 +05:00
|
|
|
|
|
2021-08-11 16:54:42 +05:00
|
|
|
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token))
|
2021-06-17 15:12:39 +05:00
|
|
|
|
return Forbid();
|
|
|
|
|
|
2021-08-11 16:54:42 +05:00
|
|
|
|
var wellDepthToDayData = await analyticsService.GetWellDepthToDayAsync(idWell, token);
|
2021-06-17 15:12:39 +05:00
|
|
|
|
|
2021-07-02 15:02:56 +05:00
|
|
|
|
if (wellDepthToDayData is null || !wellDepthToDayData.Any())
|
|
|
|
|
return NoContent();
|
|
|
|
|
|
2021-06-17 15:12:39 +05:00
|
|
|
|
return Ok(wellDepthToDayData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает данные по глубине скважины за период
|
|
|
|
|
/// </summary>
|
2021-07-27 14:43:30 +05:00
|
|
|
|
/// <param name="idWell">id скважины</param>
|
2021-07-20 11:50:35 +05:00
|
|
|
|
/// <param name="intervalSeconds">количество секунд в необходимом интервале времени</param>
|
|
|
|
|
/// <param name="workBeginSeconds">количество секунд в времени начала смены</param>
|
2021-08-11 16:54:42 +05:00
|
|
|
|
/// <param name="token">Токен отмены задачи</param>
|
2021-06-17 15:12:39 +05:00
|
|
|
|
/// <returns>Коллекцию данных по глубине скважины за период</returns>
|
|
|
|
|
[HttpGet]
|
2021-07-27 14:43:30 +05:00
|
|
|
|
[Route("{idWell}/wellDepthToInterval")]
|
2021-06-22 09:49:53 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<WellDepthToIntervalDto>), (int)System.Net.HttpStatusCode.OK)]
|
2021-08-11 12:11:21 +05:00
|
|
|
|
public async Task<IActionResult> GetWellDepthToIntervalAsync(int idWell,
|
2021-08-11 16:54:42 +05:00
|
|
|
|
int intervalSeconds, int workBeginSeconds, CancellationToken token = default)
|
2021-06-17 15:12:39 +05:00
|
|
|
|
{
|
2021-07-21 15:22:58 +05:00
|
|
|
|
int? idCompany = User.GetCompanyId();
|
2021-06-17 15:12:39 +05:00
|
|
|
|
|
2021-08-11 16:54:42 +05:00
|
|
|
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token))
|
2021-06-17 15:12:39 +05:00
|
|
|
|
return Forbid();
|
|
|
|
|
|
2021-08-11 12:11:21 +05:00
|
|
|
|
var wellDepthToIntervalData = await analyticsService.GetWellDepthToIntervalAsync(idWell,
|
2021-08-11 16:54:42 +05:00
|
|
|
|
intervalSeconds, workBeginSeconds, token);
|
2021-06-17 15:12:39 +05:00
|
|
|
|
|
2021-07-02 15:02:56 +05:00
|
|
|
|
if (wellDepthToIntervalData is null || !wellDepthToIntervalData.Any())
|
|
|
|
|
return NoContent();
|
|
|
|
|
|
2021-06-17 15:12:39 +05:00
|
|
|
|
return Ok(wellDepthToIntervalData);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-16 14:47:36 +05:00
|
|
|
|
/// <summary>
|
2021-06-22 09:49:53 +05:00
|
|
|
|
/// Возвращает данные по операциям на скважине "операции-время"
|
2021-06-16 14:47:36 +05:00
|
|
|
|
/// </summary>
|
2021-07-27 14:43:30 +05:00
|
|
|
|
/// <param name="idWell">id скважины</param>
|
2021-06-16 14:47:36 +05:00
|
|
|
|
/// <param name="begin">дата начала интервала</param>
|
|
|
|
|
/// <param name="end">дата окончания интервала</param>
|
2021-08-11 16:54:42 +05:00
|
|
|
|
/// <param name="token">Токен отмены задачи</param>
|
2021-06-16 14:47:36 +05:00
|
|
|
|
/// <returns>Коллекцию операций на скважине</returns>
|
2021-06-22 09:49:53 +05:00
|
|
|
|
[HttpGet]
|
2021-07-27 14:43:30 +05:00
|
|
|
|
[Route("{idWell}/operationsSummary")]
|
2021-07-27 13:32:00 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<TelemetryOperationDurationDto>), (int)System.Net.HttpStatusCode.OK)]
|
2021-08-11 16:54:42 +05:00
|
|
|
|
public async Task<IActionResult> GetOperationsSummaryAsync(int idWell, DateTime begin = default,
|
|
|
|
|
DateTime end = default, CancellationToken token = default)
|
2021-06-22 09:49:53 +05:00
|
|
|
|
{
|
2021-07-21 15:22:58 +05:00
|
|
|
|
int? idCompany = User.GetCompanyId();
|
2021-06-22 09:49:53 +05:00
|
|
|
|
|
2021-08-11 16:54:42 +05:00
|
|
|
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token))
|
2021-06-22 09:49:53 +05:00
|
|
|
|
return Forbid();
|
|
|
|
|
|
2021-08-11 16:54:42 +05:00
|
|
|
|
var analytics = await analyticsService .GetOperationsSummaryAsync(idWell, begin, end, token);
|
2021-06-22 09:49:53 +05:00
|
|
|
|
|
2021-07-02 15:02:56 +05:00
|
|
|
|
if (analytics is null || !analytics.Any())
|
|
|
|
|
return NoContent();
|
|
|
|
|
|
2021-06-22 09:49:53 +05:00
|
|
|
|
return Ok(analytics);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает детальные данные по операциям на скважине за период
|
|
|
|
|
/// </summary>
|
2021-07-27 14:43:30 +05:00
|
|
|
|
/// <param name="idWell">id скважины</param>
|
2021-07-20 11:50:35 +05:00
|
|
|
|
/// <param name="intervalSeconds">количество секунд в необходимом интервале времени</param>
|
|
|
|
|
/// <param name="workBeginSeconds">количество секунд в времени начала смены</param>
|
2021-08-11 16:54:42 +05:00
|
|
|
|
/// <param name="token">Токен отмены задачи</param>
|
2021-06-22 09:49:53 +05:00
|
|
|
|
/// <returns>Коллекцию операций на скважине</returns>
|
2021-06-16 14:47:36 +05:00
|
|
|
|
[HttpGet]
|
2021-07-27 14:43:30 +05:00
|
|
|
|
[Route("{idWell}/operationsToInterval")]
|
2021-07-27 13:32:00 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<TelemetryOperationDurationDto>), (int)System.Net.HttpStatusCode.OK)]
|
2021-08-11 12:11:21 +05:00
|
|
|
|
public async Task<IActionResult> GetOperationsToIntervalAsync(int idWell,
|
2021-08-11 16:54:42 +05:00
|
|
|
|
int intervalSeconds, int workBeginSeconds, CancellationToken token = default)
|
2021-06-16 14:47:36 +05:00
|
|
|
|
{
|
2021-07-21 15:22:58 +05:00
|
|
|
|
int? idCompany = User.GetCompanyId();
|
2021-06-17 15:12:39 +05:00
|
|
|
|
|
2021-08-11 16:54:42 +05:00
|
|
|
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync ((int)idCompany, idWell, token))
|
2021-06-17 15:12:39 +05:00
|
|
|
|
return Forbid();
|
|
|
|
|
|
2021-08-11 16:54:42 +05:00
|
|
|
|
var analytics = await analyticsService.GetOperationsToIntervalAsync(idWell,
|
|
|
|
|
intervalSeconds, workBeginSeconds, token);
|
2021-06-16 14:47:36 +05:00
|
|
|
|
|
2021-07-02 15:02:56 +05:00
|
|
|
|
if (analytics is null || !analytics.Any())
|
|
|
|
|
return NoContent();
|
|
|
|
|
|
2021-06-16 14:47:36 +05:00
|
|
|
|
return Ok(analytics);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|