forked from ddrilling/AsbCloudServer
68 lines
2.7 KiB
C#
68 lines
2.7 KiB
C#
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
|
||
{
|
||
private readonly IDataService telemetryDataService;
|
||
private readonly IWellService wellService;
|
||
|
||
public DataController(IDataService telemetryDataService, IWellService wellService)
|
||
{
|
||
this.telemetryDataService = telemetryDataService;
|
||
this.wellService = wellService;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Возвращает данные САУБ по скважине.
|
||
/// По умолчанию за последние 10 минут.
|
||
/// </summary>
|
||
/// <param name="wellId">id скважины</param>
|
||
/// <param name="begin">дата начала выборки. По умолчанию: текущее время - intervalSec</param>
|
||
/// <param name="intervalSec">интервал времени даты начала выборки, секунды</param>
|
||
/// <param name="approxPointsCount">желаемое количество точек. Если в выборке точек будет больше, то выборка будет прорежена.</param>
|
||
/// <returns></returns>
|
||
[HttpGet]
|
||
[Route("{wellId}/data")]
|
||
[ProducesResponseType(typeof(IEnumerable<DataSaubBaseDto>), (int)System.Net.HttpStatusCode.OK)]
|
||
public IActionResult GetData(int wellId, DateTime begin = default, int intervalSec = 600, int approxPointsCount = 1024)
|
||
{
|
||
if (begin == default)
|
||
begin = DateTime.Now.AddSeconds(-intervalSec);
|
||
var content = telemetryDataService.Get(wellId, begin, intervalSec, approxPointsCount);
|
||
return Ok(content);
|
||
}
|
||
|
||
[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)
|
||
return Forbid();
|
||
|
||
bool isCustomerOwnsWell = wellService.CheckWellOwnership((int)idCustomer, wellId);
|
||
|
||
if (!isCustomerOwnsWell)
|
||
return Forbid();
|
||
|
||
DatesRangeDto dataDatesRange = telemetryDataService.GetDataDatesRange(wellId);
|
||
|
||
return Ok(dataDatesRange);
|
||
}
|
||
}
|
||
}
|