DD.WellWorkover.Cloud/AsbCloudWebApi/Controllers/SAUB/TelemetryDataSaubController.cs
Степанов Дмитрий Александрович 57e2d70487 Фикс контроллеров
После рефакторинга контроллеров, был посеян баг. Был удалён contentType из File, что привело к тому, что файлы скачивались с расширением .htm.
2023-08-10 12:08:02 +05:00

67 lines
2.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using AsbCloudApp.Data.SAUB;
using AsbCloudApp.Services;
using AsbCloudWebApi.SignalR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using System.Threading.Tasks;
using System.Threading;
using System;
using Microsoft.AspNetCore.Http;
namespace AsbCloudWebApi.Controllers.SAUB
{
/// <summary>
/// Данные АКБ
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class TelemetryDataSaubController : TelemetryDataBaseController<TelemetryDataSaubDto>
{
private readonly ITelemetryDataSaubService telemetryDataSaubService;
public TelemetryDataSaubController(
ITelemetryService telemetryService,
ITelemetryDataSaubService telemetryDataService,
IWellService wellService,
IHubContext<TelemetryHub> telemetryHubContext)
: base(
telemetryService,
telemetryDataService,
wellService,
telemetryHubContext)
{
SignalRMethodGetDataName = "ReceiveDataSaub";
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);
}
}
}