2024-07-04 11:02:45 +05:00
|
|
|
|
using AsbCloudApp.Data.SAUB;
|
2021-09-17 16:24:01 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using AsbCloudWebApi.SignalR;
|
2023-11-09 15:18:07 +05:00
|
|
|
|
using AsbCloudWebApi.SignalR.Clients;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2021-09-17 16:24:01 +05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.AspNetCore.SignalR;
|
2023-03-09 12:32:09 +05:00
|
|
|
|
using System;
|
2023-11-09 15:18:07 +05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2021-09-17 16:24:01 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
namespace AsbCloudWebApi.Controllers.SAUB;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Данные АКБ
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class TelemetryDataSaubController : TelemetryDataBaseController<TelemetryDataSaubDto>
|
2021-09-17 16:24:01 +05:00
|
|
|
|
{
|
2024-08-19 10:01:07 +05:00
|
|
|
|
private readonly ITelemetryDataSaubService telemetryDataSaubService;
|
|
|
|
|
|
|
|
|
|
public TelemetryDataSaubController(
|
|
|
|
|
ITelemetryService telemetryService,
|
|
|
|
|
ITelemetryDataSaubService telemetryDataService,
|
|
|
|
|
IWellService wellService,
|
|
|
|
|
IHubContext<TelemetryHub, ITelemetryHubClient> telemetryHubContext)
|
|
|
|
|
: base(
|
|
|
|
|
telemetryService,
|
|
|
|
|
telemetryDataService,
|
|
|
|
|
wellService,
|
|
|
|
|
telemetryHubContext)
|
|
|
|
|
{
|
|
|
|
|
telemetryDataSaubService = telemetryDataService;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-16 17:37:10 +05:00
|
|
|
|
/// <summary>
|
2024-08-19 10:01:07 +05:00
|
|
|
|
/// Выгрузка архива. Не более 3-х суток. Формат даты строгий.
|
2022-06-16 17:37:10 +05:00
|
|
|
|
/// </summary>
|
2024-08-19 10:01:07 +05:00
|
|
|
|
/// <param name="idWell">id скважины (из адресной строки)</param>
|
|
|
|
|
/// <param name="beginDate">начало интервала в формате: yyyy-MM-DD HH:mm</param>
|
|
|
|
|
/// <param name="endDate">конец интервала в формате: yyyy-MM-DD HH:mm</param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("{idWell}/export/csv")]
|
|
|
|
|
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK, "application/octet-stream")]
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
|
|
|
public async Task<IActionResult> GetZippedCsv(int idWell, DateTime beginDate, DateTime endDate, CancellationToken token)
|
2021-09-17 16:24:01 +05:00
|
|
|
|
{
|
2024-08-19 10:01:07 +05:00
|
|
|
|
int? idCompany = User.GetCompanyId();
|
2023-03-09 12:32:09 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
if (idCompany is null)
|
|
|
|
|
return Forbid();
|
2023-03-09 12:32:09 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false);
|
2023-03-09 12:32:09 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
if (!isCompanyOwnsWell)
|
|
|
|
|
return Forbid();
|
2023-03-09 12:32:09 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
var stream = await telemetryDataSaubService.GetZippedCsv(idWell, beginDate, endDate, token).ConfigureAwait(false);
|
|
|
|
|
var fileName = $"DataSaub idWell{idWell} {beginDate:yyyy-MM-DDTHH-mm} - {endDate:yyyy-MM-DDTHH-mm}.zip";
|
|
|
|
|
return File(stream, "application/octet-stream", fileName);
|
|
|
|
|
}
|
2023-11-09 15:55:49 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
protected override Task SignalRNotifyAsync(int idWell, IEnumerable<TelemetryDataSaubDto> dtos, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
return telemetryHubContext.Clients.Group($"well_{idWell}").ReceiveDataSaub(dtos, token);
|
2021-09-17 16:24:01 +05:00
|
|
|
|
}
|
|
|
|
|
}
|