2024-07-04 11:02:45 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
2021-05-18 12:33:23 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
2021-05-20 11:07:45 +05:00
|
|
|
|
using AsbCloudWebApi.SignalR;
|
2021-07-21 15:29:19 +05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2021-05-20 11:07:45 +05:00
|
|
|
|
using Microsoft.AspNetCore.SignalR;
|
2021-07-21 15:29:19 +05:00
|
|
|
|
using System.Collections.Generic;
|
2023-07-04 12:34:25 +05:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2021-08-11 16:54:42 +05:00
|
|
|
|
using System.Threading;
|
2021-07-21 15:29:19 +05:00
|
|
|
|
using System.Threading.Tasks;
|
2023-07-04 09:08:04 +05:00
|
|
|
|
using AsbCloudApp.Requests;
|
2023-10-30 12:13:38 +05:00
|
|
|
|
using AsbCloudWebApi.SignalR.Clients;
|
2021-05-18 12:33:23 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
namespace AsbCloudWebApi.Controllers;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Отчет (временная диаграмма с сообщениями)
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("api/well/{idWell}/report")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class ReportController : ControllerBase
|
2021-05-18 12:33:23 +05:00
|
|
|
|
{
|
2024-08-19 10:01:07 +05:00
|
|
|
|
private readonly IReportService reportService;
|
|
|
|
|
private readonly IWellService wellService;
|
|
|
|
|
private readonly IHubContext<ReportsHub, IReportHubClient> reportsHubContext;
|
|
|
|
|
|
|
|
|
|
public ReportController(
|
|
|
|
|
IReportService reportService,
|
|
|
|
|
IWellService wellService,
|
|
|
|
|
IHubContext<ReportsHub,
|
|
|
|
|
IReportHubClient> reportsHubContext)
|
|
|
|
|
{
|
|
|
|
|
this.reportService = reportService;
|
|
|
|
|
this.wellService = wellService;
|
|
|
|
|
this.reportsHubContext = reportsHubContext;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-18 12:33:23 +05:00
|
|
|
|
/// <summary>
|
2024-08-19 10:01:07 +05:00
|
|
|
|
/// Создает отчет по скважине с указанными параметрами
|
2021-05-18 12:33:23 +05:00
|
|
|
|
/// </summary>
|
2024-08-19 10:01:07 +05:00
|
|
|
|
/// <param name="idWell">Id скважины</param>
|
|
|
|
|
/// <param name="request">Параметры запроса</param>
|
|
|
|
|
/// <param name="token">Токен для отмены задачи</param>
|
|
|
|
|
/// <returns>id фоновой задачи формирования отчета</returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> CreateReportAsync([Required] int idWell,
|
|
|
|
|
[FromQuery] ReportParametersRequest request,
|
|
|
|
|
CancellationToken token)
|
2021-05-18 12:33:23 +05:00
|
|
|
|
{
|
2024-08-19 10:01:07 +05:00
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
var idUser = User.GetUserId();
|
|
|
|
|
|
|
|
|
|
if ((idCompany is null) || (idUser is null))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
2021-09-23 10:52:10 +05:00
|
|
|
|
idWell, token).ConfigureAwait(false))
|
2024-08-19 10:01:07 +05:00
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
void HandleReportProgressAsync(object progress, string id) =>
|
|
|
|
|
Task.Run(async() =>
|
|
|
|
|
{
|
|
|
|
|
await reportsHubContext.Clients.Group($"Report_{id}")
|
|
|
|
|
.GetReportProgress(progress, token);
|
|
|
|
|
}, token);
|
|
|
|
|
|
|
|
|
|
var id = reportService.EnqueueCreateReportWork(idWell, (int)idUser, request, HandleReportProgressAsync);
|
|
|
|
|
|
|
|
|
|
return Ok(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает имена всех отчетов по скважине
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
|
|
|
|
/// <param name="token">Токен для отмены задачи</param>
|
|
|
|
|
/// <returns>Список имен существующих отчетов (отчетов)</returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<string>), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetAllReportsNamesByWellAsync(int idWell, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
int? idCompany = User.GetCompanyId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null)
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var reports = await reportService.GetAllReportsByWellAsync(idWell, token).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return Ok(reports);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает прогнозируемое количество страниц будущего отчета
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">Id скважины</param>
|
|
|
|
|
/// <param name="request">Параметры запроса</param>
|
|
|
|
|
/// <param name="token">Токен для отмены задачи</param>
|
|
|
|
|
/// <returns>прогнозируемое кол-во страниц отчета</returns>
|
|
|
|
|
[HttpGet("reportSize")]
|
|
|
|
|
[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(string), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetReportSizeAsync([Required] int idWell,
|
|
|
|
|
[FromQuery] ReportParametersRequest request,
|
|
|
|
|
CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
int? idCompany = User.GetCompanyId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null)
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
2021-08-11 17:26:02 +05:00
|
|
|
|
idWell, token).ConfigureAwait(false))
|
2024-08-19 10:01:07 +05:00
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
int reportSize = reportService.GetReportPagesCount(idWell,
|
|
|
|
|
request.Begin, request.End, request.StepSeconds, request.Format);
|
|
|
|
|
|
|
|
|
|
return Ok(reportSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает даты самого старого и самого свежего отчетов в БД
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
|
|
|
|
/// <param name="token">Токен для отмены задачи</param>
|
|
|
|
|
/// <returns>Даты самого старого и самого свежего отчетов в БД</returns>
|
|
|
|
|
[HttpGet("datesRange")]
|
|
|
|
|
[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
[ProducesResponseType((int)System.Net.HttpStatusCode.NoContent)]
|
|
|
|
|
public async Task<IActionResult> GetReportsDateRangeAsync(int idWell, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
int? idCompany = User.GetCompanyId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null)
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
var wellReportsDatesRange = reportService.GetDatesRangeOrDefault(idWell);
|
2021-05-18 12:33:23 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
if (wellReportsDatesRange is null)
|
|
|
|
|
return NoContent();
|
2023-12-05 14:07:56 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
if (wellReportsDatesRange.From == wellReportsDatesRange.To)
|
|
|
|
|
return NoContent();
|
2023-12-05 14:07:56 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
return Ok(wellReportsDatesRange);
|
2021-05-18 12:33:23 +05:00
|
|
|
|
}
|
|
|
|
|
}
|