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;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Контроллер сбора данных от буровых
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("api/well")]
|
|
|
|
|
[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-04-15 17:56:53 +05:00
|
|
|
|
/// <param name="wellId">id скважины</param>
|
|
|
|
|
/// <param name="begin">дата начала выборки. По умолчанию: текущее время - intervalSec</param>
|
|
|
|
|
/// <param name="intervalSec">интервал времени даты начала выборки, секунды</param>
|
|
|
|
|
/// <param name="approxPointsCount">желаемое количество точек. Если в выборке точек будет больше, то выборка будет прорежена.</param>
|
2021-04-07 18:01:56 +05:00
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[Route("{wellId}/data")]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<DataSaubBaseDto>), (int)System.Net.HttpStatusCode.OK)]
|
2021-04-30 17:35:35 +05:00
|
|
|
|
public IActionResult GetData(int wellId, DateTime begin = default, int intervalSec = 600, int approxPointsCount = 1024)
|
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);
|
|
|
|
|
var content = telemetryDataService.Get(wellId, begin, intervalSec, approxPointsCount);
|
|
|
|
|
return Ok(content);
|
2021-04-07 18:01:56 +05:00
|
|
|
|
}
|
2021-05-17 12:53:30 +05:00
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[Route("{wellId}/dataDatesRange")]
|
|
|
|
|
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public IActionResult GetDataDatesRange(int wellId)
|
|
|
|
|
{
|
|
|
|
|
int? idCustomer = User.GetCustomerId();
|
|
|
|
|
|
|
|
|
|
if (idCustomer is null)
|
2021-06-28 10:31:18 +05:00
|
|
|
|
return Forbid();
|
2021-05-17 12:53:30 +05:00
|
|
|
|
|
|
|
|
|
bool isCustomerOwnsWell = wellService.CheckWellOwnership((int)idCustomer, wellId);
|
|
|
|
|
|
|
|
|
|
if (!isCustomerOwnsWell)
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
DatesRangeDto dataDatesRange = telemetryDataService.GetDataDatesRange(wellId);
|
|
|
|
|
|
|
|
|
|
return Ok(dataDatesRange);
|
|
|
|
|
}
|
2021-04-07 18:01:56 +05:00
|
|
|
|
}
|
|
|
|
|
}
|