2023-10-20 11:24:04 +05:00
|
|
|
using AsbCloudApp.Data;
|
|
|
|
using AsbCloudApp.Data.AutogeneratedDailyReport;
|
|
|
|
using AsbCloudApp.Requests;
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
using System.Net;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Контроллер для drill_test отчётов
|
|
|
|
/// </summary>
|
|
|
|
[ApiController]
|
|
|
|
[Route("api/well/{idWell}/[controller]")]
|
|
|
|
[Authorize]
|
2023-10-20 15:44:51 +05:00
|
|
|
public class DrillTestReportController : ControllerBase
|
2023-10-20 11:24:04 +05:00
|
|
|
{
|
|
|
|
private readonly IDrillTestReportService drillTestReportService;
|
|
|
|
private readonly IWellService wellService;
|
|
|
|
|
2023-10-20 15:44:51 +05:00
|
|
|
public DrillTestReportController(IDrillTestReportService drillTestReportService,
|
2023-10-20 11:24:04 +05:00
|
|
|
IWellService wellService)
|
|
|
|
{
|
|
|
|
this.drillTestReportService = drillTestReportService;
|
|
|
|
this.wellService = wellService;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Формирование отчёта
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="idWell">Id скважины</param>
|
|
|
|
/// <param name="id">Ключ entity test записи</param>
|
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet]
|
|
|
|
[ProducesResponseType(typeof(PhysicalFileResult), (int)HttpStatusCode.OK, "application/octet-stream")]
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
|
|
public async Task<IActionResult> GenerateReportAsync([FromRoute] int idWell,
|
|
|
|
[FromQuery] int id,
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, cancellationToken))
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
var reportFile = await drillTestReportService.GenerateAsync(idWell, id, cancellationToken);
|
|
|
|
|
|
|
|
return File(reportFile.stream, "application/octet-stream", reportFile.fileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Список файлов drill test отчётов
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="idWell">Id скважины</param>
|
|
|
|
/// <param name="request">Параметры запроса</param>
|
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet("all")]
|
|
|
|
[ProducesResponseType(typeof(PaginationContainer<AutoGeneratedDailyReportInfoDto>), (int)HttpStatusCode.OK)]
|
|
|
|
public async Task<IActionResult> GetListAsync([FromRoute][Required] int idWell,
|
|
|
|
[FromQuery] FileReportRequest request,
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, cancellationToken))
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
var reports = await drillTestReportService.GetListAsync(idWell,
|
|
|
|
request,
|
|
|
|
cancellationToken);
|
|
|
|
|
|
|
|
return Ok(reports);
|
|
|
|
}
|
|
|
|
|
|
|
|
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken cancellationToken)
|
|
|
|
{
|
|
|
|
int? idCompany = User.GetCompanyId();
|
|
|
|
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
idWell, cancellationToken).ConfigureAwait(false);
|
|
|
|
}
|
|
|
|
}
|