DD.WellWorkover.Cloud/AsbCloudWebApi/Controllers/DataController.cs

73 lines
2.8 KiB
C#
Raw Normal View History

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;
using System.Linq;
2021-04-07 18:01:56 +05:00
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;
private readonly IWellService wellService;
2021-04-07 18:01:56 +05:00
public DataController(IDataService telemetryDataService, IWellService wellService)
2021-04-07 18:01:56 +05:00
{
this.telemetryDataService = telemetryDataService;
this.wellService = wellService;
2021-04-07 18:01:56 +05:00
}
/// <summary>
/// Возвращает данные САУБ по скважине.
/// По умолчанию за последние 10 минут.
2021-04-07 18:01:56 +05:00
/// </summary>
2021-07-27 14:43:30 +05:00
/// <param name="idWell">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]
2021-07-27 14:43:30 +05:00
[Route("{idWell}/data")]
2021-04-07 18:01:56 +05:00
[ProducesResponseType(typeof(IEnumerable<DataSaubBaseDto>), (int)System.Net.HttpStatusCode.OK)]
2021-07-27 14:43:30 +05:00
public IActionResult GetData(int idWell, 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)
begin = DateTime.Now.AddSeconds(-intervalSec);
2021-07-27 14:43:30 +05:00
var content = telemetryDataService.Get(idWell, begin, intervalSec, approxPointsCount);
if (content is null || !content.Any())
return NoContent();
return Ok(content);
2021-04-07 18:01:56 +05:00
}
[HttpGet]
2021-07-27 14:43:30 +05:00
[Route("{idWell}/dataDatesRange")]
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
2021-07-27 14:43:30 +05:00
public IActionResult GetDataDatesRange(int idWell)
{
2021-07-21 15:22:58 +05:00
int? idCompany = User.GetCompanyId();
2021-07-21 15:22:58 +05:00
if (idCompany is null)
return Forbid();
bool isCompanyOwnsWell = wellService.IsCompanyInvolvedInWell((int)idCompany, idWell);
2021-07-21 15:22:58 +05:00
if (!isCompanyOwnsWell)
return Forbid();
2021-07-27 14:43:30 +05:00
DatesRangeDto dataDatesRange = telemetryDataService.GetDataDatesRange(idWell);
return Ok(dataDatesRange);
}
2021-04-07 18:01:56 +05:00
}
}