2021-05-18 12:33:23 +05:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using AsbCloudDb.Model;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Контроллер отчетов по буровым скважинам
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("api/well")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class ReportController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly IReportService reportService;
|
|
|
|
|
private readonly IWellService wellService;
|
|
|
|
|
|
2021-05-19 15:21:19 +05:00
|
|
|
|
public ReportController(IReportService reportService, IWellService wellService)
|
2021-05-18 12:33:23 +05:00
|
|
|
|
{
|
|
|
|
|
this.reportService = reportService;
|
|
|
|
|
this.wellService = wellService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создает отчет по скважине с указанными параметрами
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="wellId">id скважины</param>
|
|
|
|
|
/// <param name="begin">дата начала интервала</param>
|
|
|
|
|
/// <param name="end">дата окончания интервала</param>
|
2021-05-19 14:41:27 +05:00
|
|
|
|
/// <param name="stepSeconds">шаг интервала</param>
|
2021-05-18 12:33:23 +05:00
|
|
|
|
/// <param name="format">формат отчета (0-PDF, 1-LASS)</param>
|
|
|
|
|
/// <returns>id фоновой задачи формирования отчета</returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[Route("{wellId}/report")]
|
|
|
|
|
[ProducesResponseType(typeof(string), (int)System.Net.HttpStatusCode.OK)]
|
2021-05-19 14:41:27 +05:00
|
|
|
|
public IActionResult CreateReport(int wellId, int stepSeconds, int format, DateTime begin = default, DateTime end = default)
|
2021-05-18 12:33:23 +05:00
|
|
|
|
{
|
|
|
|
|
int? idCustomer = User.GetCustomerId();
|
|
|
|
|
|
|
|
|
|
if (idCustomer is null)
|
|
|
|
|
return BadRequest();
|
|
|
|
|
|
|
|
|
|
if (!wellService.CheckWellOwnership((int)idCustomer, wellId))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2021-05-19 14:41:27 +05:00
|
|
|
|
var id = reportService.CreateReport(wellId, stepSeconds, format, begin, end);
|
2021-05-18 12:33:23 +05:00
|
|
|
|
|
2021-05-19 14:41:27 +05:00
|
|
|
|
return Ok(id);
|
2021-05-18 12:33:23 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает файл-отчет с диска на сервере
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="wellId">id скважины</param>
|
|
|
|
|
/// <param name="reportName">имя запрашиваемого файла (отчета)</param>
|
|
|
|
|
/// <returns>файловый поток с отчетом</returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[Route("{wellId}/report")]
|
|
|
|
|
[ProducesResponseType(typeof(FileStreamResult), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public IActionResult GetReport([FromRoute] int wellId, [FromQuery] string reportName)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int? idCustomer = User.GetCustomerId();
|
|
|
|
|
|
|
|
|
|
if (idCustomer is null)
|
|
|
|
|
return BadRequest();
|
|
|
|
|
|
|
|
|
|
if (!wellService.CheckWellOwnership((int)idCustomer, wellId))
|
|
|
|
|
return Forbid();
|
2021-05-19 14:41:27 +05:00
|
|
|
|
// TODO: словарь content typoв
|
|
|
|
|
return PhysicalFile(Path.Combine(reportService.RootPath, $"{wellId}", reportName), "application/pdf", reportName);
|
2021-05-18 12:33:23 +05:00
|
|
|
|
}
|
|
|
|
|
catch (FileNotFoundException ex)
|
|
|
|
|
{
|
2021-05-19 14:41:27 +05:00
|
|
|
|
return NotFound($"Файл не найден. Текст ошибки: {ex.Message}");
|
2021-05-18 12:33:23 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает прогнозируемое количество страниц будущего отчета
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="wellId">id скважины</param>
|
|
|
|
|
/// <param name="begin">дата начала интервала</param>
|
|
|
|
|
/// <param name="end">дата окончания интервала</param>
|
2021-05-19 14:41:27 +05:00
|
|
|
|
/// <param name="stepSeconds">шаг интервала</param>
|
2021-05-18 12:33:23 +05:00
|
|
|
|
/// <param name="format">формат отчета (0-PDF, 1-LASS)</param>
|
|
|
|
|
/// <returns>прогнозируемое кол-во страниц отчета</returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[Route("{wellId}/reportSize")]
|
|
|
|
|
[ProducesResponseType(typeof(string), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public IActionResult GetReportSize(int wellId, int stepSeconds, int format, DateTime begin = default, DateTime end = default)
|
|
|
|
|
{
|
|
|
|
|
int? idCustomer = User.GetCustomerId();
|
|
|
|
|
|
|
|
|
|
if (idCustomer is null)
|
|
|
|
|
return BadRequest();
|
|
|
|
|
|
|
|
|
|
if (!wellService.CheckWellOwnership((int)idCustomer, wellId))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
int reportSize = reportService.GetReportPagesCount(wellId, begin, end, stepSeconds, format);
|
|
|
|
|
|
|
|
|
|
return Ok(reportSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает даты самого старого и самого свежего отчетов в БД
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="wellId">id скважины</param>
|
|
|
|
|
/// <returns>Даты самого старого и самого свежего отчетов в БД</returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[Route("{wellId}/reportsDatesRange")]
|
|
|
|
|
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public IActionResult GetReportsDateRange(int wellId)
|
|
|
|
|
{
|
|
|
|
|
int? idCustomer = User.GetCustomerId();
|
|
|
|
|
|
|
|
|
|
if (idCustomer is null)
|
|
|
|
|
return BadRequest();
|
|
|
|
|
|
|
|
|
|
if (!wellService.CheckWellOwnership((int)idCustomer, wellId))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
DatesRangeDto wellReportsDatesRange = reportService.GetReportsDatesRange(wellId);
|
|
|
|
|
|
|
|
|
|
return Ok(wellReportsDatesRange);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|