using AsbCloudApp.Data.SAUB;
using AsbCloudApp.Services;
using AsbCloudWebApi.SignalR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using System.IO;
using System.Threading.Tasks;
using System.Threading;
using AsbCloudInfrastructure.Services;
using System;
namespace AsbCloudWebApi.Controllers.SAUB
{
///
/// Данные АКБ
///
[Route("api/[controller]")]
[ApiController]
public class TelemetryDataSaubController : TelemetryDataBaseController
{
private readonly ITelemetryDataSaubService telemetryDataSaubService;
public TelemetryDataSaubController(
ITelemetryService telemetryService,
ITelemetryDataSaubService telemetryDataService,
IWellService wellService,
IHubContext telemetryHubContext)
: base(
telemetryService,
telemetryDataService,
wellService,
telemetryHubContext)
{
SignalRMethodGetDataName = "ReceiveDataSaub";
telemetryDataSaubService = telemetryDataService;
}
///
/// Выгрузка архива. Не более 3-х суток. Формат даты строгий.
///
/// id скважины (из адресной строки)
/// начало интервала в формате: yyyy-MM-DD HH:mm
/// конец интервала в формате: yyyy-MM-DD HH:mm
///
///
[HttpGet("{idWell}/export/csv")]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
public async Task GetZippedCsv(int idWell, DateTime beginDate, DateTime endDate, CancellationToken token)
{
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();
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);
}
}
}