2021-04-07 18:01:56 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2021-07-02 15:02:56 +05:00
|
|
|
|
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-04-07 18:01:56 +05:00
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Контроллер сбора данных от буровых
|
|
|
|
|
/// </summary>
|
2021-08-17 09:39:05 +05:00
|
|
|
|
[Route("api/well/{idWell}/data")]
|
2021-04-07 18:01:56 +05:00
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class DataController : ControllerBase
|
|
|
|
|
{
|
2021-04-23 10:21:25 +05:00
|
|
|
|
private readonly IDataService telemetryDataService;
|
2021-05-17 12:53:30 +05:00
|
|
|
|
private readonly IWellService wellService;
|
2021-04-07 18:01:56 +05:00
|
|
|
|
|
2021-05-17 12:53:30 +05:00
|
|
|
|
public DataController(IDataService telemetryDataService, IWellService wellService)
|
2021-04-07 18:01:56 +05:00
|
|
|
|
{
|
|
|
|
|
this.telemetryDataService = telemetryDataService;
|
2021-05-17 12:53:30 +05:00
|
|
|
|
this.wellService = wellService;
|
2021-04-07 18:01:56 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2021-04-09 17:59:07 +05:00
|
|
|
|
/// Возвращает данные САУБ по скважине.
|
|
|
|
|
/// По умолчанию за последние 10 минут.
|
2021-04-07 18:01:56 +05:00
|
|
|
|
/// </summary>
|
2021-07-27 14:43:30 +05:00
|
|
|
|
/// <param name="idWell">id скважины</param>
|
2021-04-15 17:56:53 +05:00
|
|
|
|
/// <param name="begin">дата начала выборки. По умолчанию: текущее время - intervalSec</param>
|
|
|
|
|
/// <param name="intervalSec">интервал времени даты начала выборки, секунды</param>
|
|
|
|
|
/// <param name="approxPointsCount">желаемое количество точек. Если в выборке точек будет больше, то выборка будет прорежена.</param>
|
2021-08-11 16:54:42 +05:00
|
|
|
|
/// <param name="token">Токен завершения задачи</param>
|
2021-04-07 18:01:56 +05:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<DataSaubBaseDto>), (int)System.Net.HttpStatusCode.OK)]
|
2021-08-11 16:54:42 +05:00
|
|
|
|
public async Task<IActionResult> GetDataAsync(int idWell, DateTime begin = default,
|
|
|
|
|
int intervalSec = 600, int approxPointsCount = 1024, CancellationToken token = default)
|
2021-04-07 18:01:56 +05:00
|
|
|
|
{
|
2021-04-23 10:21:25 +05:00
|
|
|
|
if (begin == default)
|
2021-04-15 17:56:53 +05:00
|
|
|
|
begin = DateTime.Now.AddSeconds(-intervalSec);
|
2021-08-11 16:54:42 +05:00
|
|
|
|
var content = await telemetryDataService.GetAsync(idWell, begin,
|
2021-08-11 17:26:02 +05:00
|
|
|
|
intervalSec, approxPointsCount, token).ConfigureAwait(false);
|
2021-07-02 15:02:56 +05:00
|
|
|
|
|
|
|
|
|
if (content is null || !content.Any())
|
|
|
|
|
return NoContent();
|
|
|
|
|
|
2021-04-15 17:56:53 +05:00
|
|
|
|
return Ok(content);
|
2021-04-07 18:01:56 +05:00
|
|
|
|
}
|
2021-05-17 12:53:30 +05:00
|
|
|
|
|
2021-08-11 16:54:42 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает диапазон дат сохраненных данных.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
|
|
|
|
/// <param name="token">Токен завершения задачи</param>
|
|
|
|
|
/// <returns></returns>
|
2021-05-17 12:53:30 +05:00
|
|
|
|
[HttpGet]
|
2021-08-17 09:39:05 +05:00
|
|
|
|
[Route("dataDatesRange")]
|
2021-05-17 12:53:30 +05:00
|
|
|
|
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
|
2021-08-11 16:54:42 +05:00
|
|
|
|
public async Task<IActionResult> GetDataDatesRangeAsync(int idWell,
|
|
|
|
|
CancellationToken token = default)
|
2021-05-17 12:53:30 +05:00
|
|
|
|
{
|
2021-07-21 15:22:58 +05:00
|
|
|
|
int? idCompany = User.GetCompanyId();
|
2021-05-17 12:53:30 +05:00
|
|
|
|
|
2021-07-21 15:22:58 +05:00
|
|
|
|
if (idCompany is null)
|
2021-06-28 10:31:18 +05:00
|
|
|
|
return Forbid();
|
2021-05-17 12:53:30 +05:00
|
|
|
|
|
2021-08-11 16:54:42 +05:00
|
|
|
|
bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
2021-08-11 17:26:02 +05:00
|
|
|
|
idWell, token).ConfigureAwait(false);
|
2021-05-17 12:53:30 +05:00
|
|
|
|
|
2021-07-21 15:22:58 +05:00
|
|
|
|
if (!isCompanyOwnsWell)
|
2021-05-17 12:53:30 +05:00
|
|
|
|
return Forbid();
|
|
|
|
|
|
2021-08-11 16:54:42 +05:00
|
|
|
|
DatesRangeDto dataDatesRange = await telemetryDataService.GetDataDatesRangeAsync(idWell,
|
2021-08-11 17:26:02 +05:00
|
|
|
|
token).ConfigureAwait(false);
|
2021-05-17 12:53:30 +05:00
|
|
|
|
|
|
|
|
|
return Ok(dataDatesRange);
|
|
|
|
|
}
|
2021-04-07 18:01:56 +05:00
|
|
|
|
}
|
|
|
|
|
}
|