2021-08-24 16:47:10 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Collections.Generic;
|
2021-10-12 16:07:08 +05:00
|
|
|
|
using System.Linq;
|
2021-08-24 16:47:10 +05:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2022-06-16 17:37:10 +05:00
|
|
|
|
/// Статистика по операциям (заведенным вручную) на скважине
|
2021-08-24 16:47:10 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
[Route("api")]
|
2021-11-22 17:29:19 +05:00
|
|
|
|
public class OperationStatController : ControllerBase
|
2021-08-24 16:47:10 +05:00
|
|
|
|
{
|
2021-11-22 17:29:19 +05:00
|
|
|
|
private readonly IOperationsStatService operationsStatService;
|
2021-08-24 16:47:10 +05:00
|
|
|
|
private readonly IWellService wellService;
|
|
|
|
|
|
2021-11-22 17:29:19 +05:00
|
|
|
|
public OperationStatController(IOperationsStatService sectionsService, IWellService wellService)
|
2021-08-24 16:47:10 +05:00
|
|
|
|
{
|
2021-08-27 12:15:04 +05:00
|
|
|
|
this.operationsStatService = sectionsService;
|
2021-08-24 16:47:10 +05:00
|
|
|
|
this.wellService = wellService;
|
|
|
|
|
}
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-11-22 17:29:19 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Формирует данные по среднему и максимальному МСП на кусту по id скважины
|
|
|
|
|
/// </summary>
|
2022-01-05 17:50:45 +05:00
|
|
|
|
/// <param name="idWell">id скважины с данного куста (через нее будут получены данные)</param>
|
2021-11-22 17:29:19 +05:00
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns>Возвращает данные по среднему и максимальному МСП на кусту</returns>
|
2021-11-23 14:07:43 +05:00
|
|
|
|
[HttpGet("well/{idWell}/ropStat")]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2021-11-22 17:29:19 +05:00
|
|
|
|
[ProducesResponseType(typeof(ClusterRopStatDto), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetClusterRopStatByIdWellAsync([FromRoute] int idWell,
|
|
|
|
|
CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2022-03-16 16:07:37 +05:00
|
|
|
|
var result = await operationsStatService.GetRopStatAsync(
|
2021-11-22 17:29:19 +05:00
|
|
|
|
idWell, token).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-11-22 17:29:19 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Формирует данные по среднему и максимальному МСП на кусту по uid панели
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="uid">id передающей данные панели</param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns>Возвращает данные по среднему и максимальному МСП на кусту</returns>
|
2021-11-23 14:07:43 +05:00
|
|
|
|
[HttpGet("telemetry/{uid}/ropStat")]
|
2021-11-22 17:29:19 +05:00
|
|
|
|
[ProducesResponseType(typeof(ClusterRopStatDto), (int)System.Net.HttpStatusCode.OK)]
|
2021-11-23 14:07:43 +05:00
|
|
|
|
[AllowAnonymous]
|
2021-11-22 17:29:19 +05:00
|
|
|
|
public async Task<IActionResult> GetClusterRopStatByUidAsync([FromRoute] string uid,
|
|
|
|
|
CancellationToken token = default)
|
|
|
|
|
{
|
2022-03-16 16:07:37 +05:00
|
|
|
|
var idWell = wellService.TelemetryService.GetIdWellByTelemetryUid(uid);
|
|
|
|
|
|
2022-04-11 18:00:34 +05:00
|
|
|
|
if (idWell is null)
|
2022-03-16 16:07:37 +05:00
|
|
|
|
return NoContent();
|
|
|
|
|
|
|
|
|
|
var result = await operationsStatService.GetRopStatAsync(
|
|
|
|
|
(int)idWell, token).ConfigureAwait(false);
|
2021-11-22 17:29:19 +05:00
|
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2021-08-24 16:47:10 +05:00
|
|
|
|
|
2021-10-12 16:07:08 +05:00
|
|
|
|
/// <summary>
|
2022-01-05 17:50:45 +05:00
|
|
|
|
/// Получает статистику по скважинам куста
|
2021-10-12 16:07:08 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idCluster">id куста</param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
2021-08-24 16:47:10 +05:00
|
|
|
|
[HttpGet]
|
2023-03-27 09:40:51 +05:00
|
|
|
|
[Route("cluster/{idCluster}/stat")]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2021-08-25 11:30:50 +05:00
|
|
|
|
[ProducesResponseType(typeof(StatClusterDto), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetStatClusterAsync(int idCluster,
|
2021-08-24 16:47:10 +05:00
|
|
|
|
CancellationToken token = default)
|
|
|
|
|
{
|
2023-03-27 09:40:51 +05:00
|
|
|
|
int? idCompany = User.GetCompanyId();
|
|
|
|
|
if (idCompany is null)
|
2021-10-12 18:06:47 +05:00
|
|
|
|
return Forbid();
|
|
|
|
|
|
2023-03-27 09:40:51 +05:00
|
|
|
|
var result = await operationsStatService.GetStatClusterAsync(idCluster, idCompany.Value, token)
|
2021-08-24 16:47:10 +05:00
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-12 16:07:08 +05:00
|
|
|
|
/// <summary>
|
2022-01-05 17:50:45 +05:00
|
|
|
|
/// Получает статистику по списку скважин
|
2021-10-12 16:07:08 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWells">список скважин</param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[Route("wellsStats")]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2021-10-12 16:07:08 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<StatWellDto>), (int)System.Net.HttpStatusCode.OK)]
|
2023-02-15 17:57:32 +05:00
|
|
|
|
public async Task<IActionResult> GetWellsStatAsync([FromQuery] IEnumerable<int> idWells, CancellationToken token)
|
2021-10-12 16:07:08 +05:00
|
|
|
|
{
|
2023-02-15 17:57:32 +05:00
|
|
|
|
int? idCompany = User.GetCompanyId();
|
|
|
|
|
if (idCompany is null)
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var allowedWells = await wellService.GetAsync(new() { IdCompany = idCompany }, token);
|
|
|
|
|
|
|
|
|
|
var protectedIdWells = idWells.Where(id => allowedWells.Any(allowed => allowed.Id == id));
|
2021-10-12 16:07:08 +05:00
|
|
|
|
var result = await operationsStatService.GetWellsStatAsync(protectedIdWells, token)
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получает статистику по скважине
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
2021-08-24 16:47:10 +05:00
|
|
|
|
[HttpGet]
|
2021-08-25 11:30:50 +05:00
|
|
|
|
[Route("well/{idWell}/stat")]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2021-08-25 11:30:50 +05:00
|
|
|
|
[ProducesResponseType(typeof(StatWellDto), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetStatWellAsync(int idWell,
|
2021-08-24 16:47:10 +05:00
|
|
|
|
CancellationToken token = default)
|
|
|
|
|
{
|
2021-08-25 11:30:50 +05:00
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
2021-08-24 16:47:10 +05:00
|
|
|
|
|
2022-03-02 16:21:07 +05:00
|
|
|
|
var result = await operationsStatService.GetWellStatAsync(idWell, token)
|
2021-08-24 16:47:10 +05:00
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-12 16:07:08 +05:00
|
|
|
|
/// <summary>
|
2022-01-05 17:50:45 +05:00
|
|
|
|
/// Получает данные для графика глубина-день
|
2021-10-12 16:07:08 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
2021-08-27 12:15:04 +05:00
|
|
|
|
[HttpGet]
|
|
|
|
|
[Route("well/{idWell}/tvd")]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2021-08-27 12:15:04 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<PlanFactPredictBase<WellOperationDto>>), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetTvdAsync(int idWell,
|
|
|
|
|
CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var result = await operationsStatService.GetTvdAsync(idWell, token)
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-24 16:47:10 +05:00
|
|
|
|
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
int? idCompany = User.GetCompanyId();
|
|
|
|
|
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|