2023-11-28 15:54:47 +05:00
|
|
|
|
using AsbCloudApp.Data.Trajectory;
|
2023-11-22 13:14:37 +05:00
|
|
|
|
using AsbCloudApp.Repositories;
|
2023-11-29 12:06:57 +05:00
|
|
|
|
using AsbCloudApp.Requests;
|
2023-11-22 13:14:37 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
2023-11-28 15:54:47 +05:00
|
|
|
|
using AsbCloudInfrastructure.Services.Trajectory.Export;
|
2023-11-22 13:14:37 +05:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers.Trajectory
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Плановые и фактические траектории (загрузка и хранение)
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public abstract class TrajectoryController<Tdto> : ControllerBase
|
|
|
|
|
where Tdto : TrajectoryGeoDto
|
|
|
|
|
{
|
2023-11-28 15:54:47 +05:00
|
|
|
|
protected abstract string fileName { get; set; }
|
2023-11-22 13:14:37 +05:00
|
|
|
|
|
|
|
|
|
private readonly IWellService wellService;
|
2023-11-28 15:54:47 +05:00
|
|
|
|
private readonly TrajectoryExportService<Tdto> trajectoryExportService;
|
|
|
|
|
private readonly ITrajectoryRepository<Tdto> trajectoryRepository;
|
2023-11-22 13:14:37 +05:00
|
|
|
|
|
|
|
|
|
public TrajectoryController(IWellService wellService,
|
2023-11-28 15:54:47 +05:00
|
|
|
|
TrajectoryExportService<Tdto> trajectoryExportService,
|
|
|
|
|
ITrajectoryRepository<Tdto> trajectoryRepository)
|
2023-11-22 13:14:37 +05:00
|
|
|
|
{
|
2023-11-28 15:54:47 +05:00
|
|
|
|
this.trajectoryExportService = trajectoryExportService;
|
2023-11-22 13:14:37 +05:00
|
|
|
|
this.wellService = wellService;
|
|
|
|
|
this.trajectoryRepository = trajectoryRepository;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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();
|
2023-11-28 15:54:47 +05:00
|
|
|
|
var stream = await trajectoryExportService.ExportAsync(idWell, token);
|
|
|
|
|
var fileName = await trajectoryExportService.GetFileNameAsync(idWell, token);
|
2023-11-22 13:14:37 +05:00
|
|
|
|
return File(stream, "application/octet-stream", fileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получаем список всех строк координат траектории (для клиента)
|
|
|
|
|
/// </summary>
|
2023-11-30 09:40:51 +05:00
|
|
|
|
/// <param name="idWell">ключ скважины</param>
|
2023-11-22 13:14:37 +05:00
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns>Список добавленных координат траектории</returns>
|
|
|
|
|
//[ProducesResponseType(typeof(IEnumerable<Tdto>), (int)System.Net.HttpStatusCode.OK)]
|
2023-11-30 09:40:51 +05:00
|
|
|
|
public async Task<IActionResult> GetAsync(int idWell, CancellationToken token)
|
2023-11-22 13:14:37 +05:00
|
|
|
|
{
|
2023-11-30 09:40:51 +05:00
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell,
|
2023-11-22 13:14:37 +05:00
|
|
|
|
token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
2023-11-30 09:40:51 +05:00
|
|
|
|
var result = await trajectoryRepository.GetAsync(idWell, token);
|
2023-11-22 13:14:37 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|