DD.WellWorkover.Cloud/AsbCloudWebApi/Controllers/Trajectory/NnbTrajectoryController.cs

80 lines
3.3 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 System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
using AsbCloudInfrastructure.Services;
using AsbCloudInfrastructure.Services.Trajectory;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace AsbCloudWebApi.Controllers.Trajectory;
/// <summary>
/// Фактическая траектория из ННБ
/// </summary>
[Authorize]
[ApiController]
[Route("api/well/{idWell}/[controller]")]
public class NnbTrajectoryController : ControllerBase
{
private readonly ITrajectoryNnbRepository trajectoryNnbRepository;
private readonly NnbTrajectoryImportService factNnbTrajectoryImportService;
private readonly IWellService wellService;
public NnbTrajectoryController(
ITrajectoryNnbRepository trajectoryNnbRepository,
NnbTrajectoryImportService factNnbTrajectoryImportService,
IWellService wellService)
{
this.trajectoryNnbRepository = trajectoryNnbRepository;
this.factNnbTrajectoryImportService = factNnbTrajectoryImportService;
this.wellService = wellService;
this.wellService = wellService;
}
/// <summary>
/// Метод получения всех строк фактических траекторий по id скважины из ННБ
/// </summary>
/// <param name="idWell">Id скважины</param>
/// <param name="cancellationToken">Токен отмены операции</param>
/// <returns></returns>
[HttpGet]
[ProducesResponseType(typeof(IEnumerable<TrajectoryGeoFactDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetRowsAsync([FromRoute] int idWell,
CancellationToken cancellationToken)
{
var nnbFactTrajectories = await trajectoryNnbRepository.GetAsync(idWell,
cancellationToken);
return Ok(nnbFactTrajectories);
}
/// <summary>
/// Формируем excel файл с текущими строками фактической ннб-траектории
/// </summary>
/// <param name="idWell">id скважины</param>
/// <param name="token"> Токен отмены задачи </param>
/// <returns>Запрашиваемый файл</returns>
[HttpGet("export")]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK, "application/octet-stream")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> ExportAsync([FromRoute] int idWell, CancellationToken token)
{
if (!await CanUserAccessToWellAsync(idWell,
token).ConfigureAwait(false))
return Forbid();
var stream = await factNnbTrajectoryImportService.ExportAsync(idWell, token);
var fileName = await factNnbTrajectoryImportService.GetFileNameAsync(idWell, token);
return File(stream, "application/octet-stream", fileName);
}
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token)
{
int? idCompany = User.GetCompanyId();
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false);
}
}