DD.WellWorkover.Cloud/AsbCloudWebApi/Controllers/SAUB/TelemetryDataSaubController.cs

73 lines
3.0 KiB
C#
Raw Normal View History

2022-04-08 13:10:06 +05:00
using AsbCloudApp.Data.SAUB;
using AsbCloudApp.Services;
using AsbCloudWebApi.SignalR;
using AsbCloudWebApi.SignalR.Clients;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
2022-04-11 18:00:34 +05:00
namespace AsbCloudWebApi.Controllers.SAUB
{
2022-06-16 17:37:10 +05:00
/// <summary>
/// Данные АКБ
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class TelemetryDataSaubController : TelemetryDataBaseController<TelemetryDataSaubDto>
{
private readonly ITelemetryDataSaubService telemetryDataSaubService;
public TelemetryDataSaubController(
ITelemetryService telemetryService,
2023-01-17 15:39:36 +05:00
ITelemetryDataSaubService telemetryDataService,
IWellService wellService,
IHubContext<TelemetryHub, ITelemetryHubClient> telemetryHubContext)
: base(
telemetryService,
telemetryDataService,
wellService,
telemetryHubContext)
{
telemetryDataSaubService = telemetryDataService;
}
/// <summary>
/// Выгрузка архива. Не более 3-х суток. Формат даты строгий.
/// </summary>
/// <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)
{
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);
}
2023-11-09 15:55:49 +05:00
protected override Task SignalRNotifyAsync(int idWell, IEnumerable<TelemetryDataSaubDto> dtos, CancellationToken token)
{
return telemetryHubContext.Clients.Group($"well_{idWell}").ReceiveDataSaub(dtos, token);
}
}
}