2021-08-24 16:47:10 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Контроллер секций скважины
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
[Route("api")]
|
|
|
|
|
public class WellOperationStatController : ControllerBase
|
|
|
|
|
{
|
2021-08-27 12:15:04 +05:00
|
|
|
|
private readonly IWellOperationsStatService operationsStatService;
|
2021-08-24 16:47:10 +05:00
|
|
|
|
private readonly IWellService wellService;
|
|
|
|
|
|
|
|
|
|
public WellOperationStatController(IWellOperationsStatService sectionsService, IWellService wellService)
|
|
|
|
|
{
|
2021-08-27 12:15:04 +05:00
|
|
|
|
this.operationsStatService = sectionsService;
|
2021-08-24 16:47:10 +05:00
|
|
|
|
this.wellService = wellService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2021-08-25 11:30:50 +05:00
|
|
|
|
[Route("cluster/{idCluster}/stat")]
|
|
|
|
|
[ProducesResponseType(typeof(StatClusterDto), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetStatClusterAsync(int idCluster,
|
2021-08-24 16:47:10 +05:00
|
|
|
|
CancellationToken token = default)
|
|
|
|
|
{
|
2021-08-25 11:30:50 +05:00
|
|
|
|
// TODO: Fix next commented lines
|
|
|
|
|
//if (!await CanUserAccessToWellAsync(idCluster, token).ConfigureAwait(false))
|
|
|
|
|
// return Forbid();
|
2021-08-24 16:47:10 +05:00
|
|
|
|
|
2021-08-27 12:15:04 +05:00
|
|
|
|
var result = await operationsStatService.GetStatClusterAsync(idCluster, token)
|
2021-08-24 16:47:10 +05:00
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
2021-08-25 11:30:50 +05:00
|
|
|
|
[Route("well/{idWell}/stat")]
|
|
|
|
|
[ProducesResponseType(typeof(StatWellDto), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetStatWellAsync(int idWell,
|
2021-08-24 16:47:10 +05:00
|
|
|
|
CancellationToken token = default)
|
|
|
|
|
{
|
2021-08-25 11:30:50 +05:00
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
2021-08-24 16:47:10 +05:00
|
|
|
|
|
2021-08-27 12:15:04 +05:00
|
|
|
|
var result = await operationsStatService.GetStatWellAsync(idWell, token)
|
2021-08-24 16:47:10 +05:00
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-25 11:30:50 +05:00
|
|
|
|
|
2021-08-27 12:15:04 +05:00
|
|
|
|
[HttpGet]
|
|
|
|
|
[Route("well/{idWell}/tvd")]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<PlanFactPredictBase<WellOperationDto>>), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetTvdAsync(int idWell,
|
|
|
|
|
CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var result = await operationsStatService.GetTvdAsync(idWell, token)
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-24 16:47:10 +05:00
|
|
|
|
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
int? idCompany = User.GetCompanyId();
|
|
|
|
|
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|