2023-04-07 04:51:30 +05:00
|
|
|
|
using AsbCloudApp.Data.GTR;
|
|
|
|
|
using AsbCloudApp.Repositories;
|
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using AsbCloudDb.Model;
|
|
|
|
|
using AsbCloudWebApi.SignalR;
|
2023-03-31 11:10:16 +05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2023-04-07 04:51:30 +05:00
|
|
|
|
using Microsoft.AspNetCore.SignalR;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2023-03-31 11:10:16 +05:00
|
|
|
|
|
2023-04-17 20:58:20 +05:00
|
|
|
|
namespace AsbCloudWebApi.Controllers.SAUB
|
2023-03-31 11:10:16 +05:00
|
|
|
|
{
|
2023-05-19 16:51:41 +05:00
|
|
|
|
|
2023-03-31 11:10:16 +05:00
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class GtrWitsController : ControllerBase
|
2023-04-17 20:58:20 +05:00
|
|
|
|
|
2023-03-31 11:10:16 +05:00
|
|
|
|
{
|
2023-04-07 04:51:30 +05:00
|
|
|
|
protected readonly IWellService wellService;
|
|
|
|
|
private readonly ITelemetryService telemetryService;
|
2023-04-11 00:32:06 +05:00
|
|
|
|
private readonly IGtrRepository gtrRepository;
|
2023-04-07 04:51:30 +05:00
|
|
|
|
private readonly IHubContext<TelemetryHub> telemetryHubContext;
|
|
|
|
|
|
2023-04-18 16:07:29 +05:00
|
|
|
|
public string SignalRMethodGetDataName { get; protected set; } = "ReceiveData";
|
2023-04-07 04:51:30 +05:00
|
|
|
|
|
|
|
|
|
public GtrWitsController(
|
|
|
|
|
ITelemetryService telemetryService,
|
2023-04-11 00:32:06 +05:00
|
|
|
|
IGtrRepository gtrRepository,
|
2023-04-07 04:51:30 +05:00
|
|
|
|
IWellService wellService,
|
|
|
|
|
IHubContext<TelemetryHub> telemetryHubContext)
|
|
|
|
|
{
|
|
|
|
|
this.telemetryService = telemetryService;
|
2023-04-11 00:32:06 +05:00
|
|
|
|
this.gtrRepository = gtrRepository;
|
2023-04-07 04:51:30 +05:00
|
|
|
|
this.wellService = wellService;
|
|
|
|
|
this.telemetryHubContext = telemetryHubContext;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-04-17 20:58:20 +05:00
|
|
|
|
/// Получить загруженные данные ГТИ по скважине
|
2023-04-07 04:51:30 +05:00
|
|
|
|
/// </summary>
|
2023-04-11 00:32:06 +05:00
|
|
|
|
/// <param name = "idWell" > id скважины</param>
|
|
|
|
|
/// <param name = "begin" > дата начала выборки.По умолчанию: текущее время - intervalSec</param>
|
|
|
|
|
/// <param name = "intervalSec" > интервал времени даты начала выборки, секунды</param>
|
|
|
|
|
/// <param name = "approxPointsCount" > желаемое количество точек. Если в выборке точек будет больше, то выборка будет прорежена.</param>
|
|
|
|
|
/// <param name = "token" > Токен завершения задачи</param>
|
2023-04-07 04:51:30 +05:00
|
|
|
|
/// <returns></returns>
|
2023-04-11 00:32:06 +05:00
|
|
|
|
[HttpGet("{idWell}")]
|
2023-04-17 20:59:27 +05:00
|
|
|
|
[Permission]
|
2023-04-18 16:07:29 +05:00
|
|
|
|
public async Task<ActionResult<IEnumerable<WitsRecordDto>>> GetDataAsync(int idWell, DateTime? begin,
|
2023-04-11 00:32:06 +05:00
|
|
|
|
int intervalSec = 600, int approxPointsCount = 1024, CancellationToken token = default)
|
|
|
|
|
{
|
2023-04-17 20:59:27 +05:00
|
|
|
|
int? idCompany = User.GetCompanyId();
|
2023-04-07 04:51:30 +05:00
|
|
|
|
|
2023-04-17 20:59:27 +05:00
|
|
|
|
if (idCompany is null)
|
|
|
|
|
return Forbid();
|
2023-04-07 04:51:30 +05:00
|
|
|
|
|
2023-04-17 20:59:27 +05:00
|
|
|
|
bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false);
|
2023-04-07 04:51:30 +05:00
|
|
|
|
|
2023-04-17 20:59:27 +05:00
|
|
|
|
if (!isCompanyOwnsWell)
|
|
|
|
|
return Forbid();
|
2023-04-07 04:51:30 +05:00
|
|
|
|
|
2023-04-11 00:32:06 +05:00
|
|
|
|
var content = await gtrRepository.GetAsync(idWell, begin,
|
|
|
|
|
intervalSec, approxPointsCount, token).ConfigureAwait(false);
|
2023-04-07 04:51:30 +05:00
|
|
|
|
|
2023-04-11 00:32:06 +05:00
|
|
|
|
return Ok(content);
|
|
|
|
|
}
|
2023-04-11 12:06:05 +05:00
|
|
|
|
|
2023-05-18 15:31:27 +05:00
|
|
|
|
/// <summary>
|
2023-05-19 12:45:07 +05:00
|
|
|
|
/// получение последних данных ГТИ по ключу record
|
2023-05-18 15:31:27 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
|
|
|
|
/// <param name="idRecord">id record</param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
2023-05-16 09:17:17 +05:00
|
|
|
|
[HttpGet("{idWell}/{idRecord}")]
|
|
|
|
|
[Permission]
|
2023-05-19 12:45:07 +05:00
|
|
|
|
public async Task<ActionResult<IEnumerable<WitsItemRecordDto>>> GetLastDataByRecordIdAsync(int idWell, int idRecord, CancellationToken token = default)
|
2023-05-16 09:17:17 +05:00
|
|
|
|
{
|
|
|
|
|
int? idCompany = User.GetCompanyId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null)
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
if (!isCompanyOwnsWell)
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2023-05-19 12:45:07 +05:00
|
|
|
|
var content = await gtrRepository.GetLastDataByRecordIdAsync(idWell, idRecord, token).ConfigureAwait(false);
|
2023-05-16 09:17:17 +05:00
|
|
|
|
|
|
|
|
|
return Ok(content);
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-17 20:58:20 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Метод для получения WITS записи от панели оператора.
|
|
|
|
|
/// Сохраняет в БД.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="uid">уникальный идентификатор телеметрии</param>
|
|
|
|
|
/// <param name="dto">WITS запись</param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("{uid}")]
|
2023-04-11 12:06:05 +05:00
|
|
|
|
public async Task<IActionResult> PostDataAsync(
|
|
|
|
|
string uid,
|
2023-04-17 20:58:20 +05:00
|
|
|
|
[FromBody] WitsRecordDto dto,
|
2023-04-11 12:06:05 +05:00
|
|
|
|
CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
var idTelemetry = telemetryService.GetOrCreateTelemetryIdByUid(uid);
|
|
|
|
|
await gtrRepository.SaveDataAsync(idTelemetry, dto, token).ConfigureAwait(false);
|
2023-04-14 00:46:31 +05:00
|
|
|
|
var idWell = telemetryService.GetIdWellByTelemetryUid(uid);
|
|
|
|
|
if (idWell is not null && dto is not null)
|
2023-04-17 20:58:20 +05:00
|
|
|
|
_ = Task.Run(() => telemetryHubContext.Clients.Group($"well_{idWell}_gtr")
|
2023-04-18 16:07:29 +05:00
|
|
|
|
.SendAsync(SignalRMethodGetDataName, dto), CancellationToken.None);
|
2023-04-11 12:06:05 +05:00
|
|
|
|
return Ok();
|
|
|
|
|
}
|
2023-03-31 11:10:16 +05:00
|
|
|
|
}
|
2023-05-19 16:51:41 +05:00
|
|
|
|
|
2023-03-31 11:10:16 +05:00
|
|
|
|
}
|