2022-04-11 18:00:34 +05:00
|
|
|
|
using AsbCloudApp.Data.SAUB;
|
|
|
|
|
using AsbCloudApp.Services;
|
2021-11-24 16:16:17 +05:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
2022-04-11 18:00:34 +05:00
|
|
|
|
using System.Threading.Tasks;
|
2021-11-24 16:16:17 +05:00
|
|
|
|
|
2022-04-11 18:00:34 +05:00
|
|
|
|
namespace AsbCloudWebApi.Controllers.SAUB
|
2021-11-24 16:16:17 +05:00
|
|
|
|
{
|
2022-06-16 17:37:10 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Рекомендация уставок бурильщику
|
|
|
|
|
/// </summary>
|
2021-11-24 16:16:17 +05:00
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class SetpointsController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly ISetpointsService setpointsService;
|
|
|
|
|
private readonly IWellService wellService;
|
|
|
|
|
private const int ObsolescenceSecMin = 30;
|
|
|
|
|
private const int ObsolescenceSecMax = 6 * 60 * 60;
|
|
|
|
|
|
|
|
|
|
public SetpointsController(ISetpointsService setpointsService, IWellService wellService)
|
|
|
|
|
{
|
|
|
|
|
this.setpointsService = setpointsService;
|
|
|
|
|
this.wellService = wellService;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-24 17:58:53 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получает список запросов на изменение уставок.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("api/well/{idWell}/setpointsNames")]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<SetpointInfoDto>), (int)System.Net.HttpStatusCode.OK)]
|
2021-11-26 17:14:02 +05:00
|
|
|
|
[AllowAnonymous]
|
2021-11-24 17:58:53 +05:00
|
|
|
|
public IActionResult GetSetpointsNamesByIdWellAsync([FromRoute] int idWell)
|
|
|
|
|
{
|
2022-06-15 14:57:37 +05:00
|
|
|
|
var result = setpointsService.GetSetpointsNames();
|
2021-11-24 17:58:53 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-24 16:16:17 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавляет запрос на изменение заданий панели оператора.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
|
|
|
|
/// <param name="setpoints"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("api/well/{idWell}/setpoints")]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2021-11-24 16:16:17 +05:00
|
|
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
2023-07-03 14:33:34 +05:00
|
|
|
|
public async Task<IActionResult> InsertAsync(int idWell, SetpointsRequestDto setpoints, CancellationToken token)
|
2021-11-24 16:16:17 +05:00
|
|
|
|
{
|
|
|
|
|
int? idCompany = User.GetCompanyId();
|
|
|
|
|
int? idUser = User.GetUserId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null || idUser is null)
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
setpoints.IdAuthor = idUser ?? -1;
|
|
|
|
|
setpoints.IdWell = idWell;
|
|
|
|
|
setpoints.IdState = 1;
|
|
|
|
|
|
|
|
|
|
if (setpoints is null
|
|
|
|
|
|| setpoints.ObsolescenceSec > ObsolescenceSecMax
|
|
|
|
|
|| setpoints.ObsolescenceSec < ObsolescenceSecMin)
|
|
|
|
|
return BadRequest("Wrong ObsolescenceSec");
|
|
|
|
|
|
|
|
|
|
if (!setpoints.Setpoints.Any())
|
2022-01-05 17:50:45 +05:00
|
|
|
|
return BadRequest("Wrong setpoints count");
|
2021-11-24 16:16:17 +05:00
|
|
|
|
|
|
|
|
|
var result = await setpointsService.InsertAsync(setpoints, token)
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получает список запросов на изменение уставок.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("api/well/{idWell}/setpoints")]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2021-11-24 16:16:17 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<SetpointsRequestDto>), (int)System.Net.HttpStatusCode.OK)]
|
2023-07-03 14:33:34 +05:00
|
|
|
|
public async Task<IActionResult> GetByIdWellAsync([FromRoute] int idWell, CancellationToken token)
|
2021-11-24 16:16:17 +05:00
|
|
|
|
{
|
|
|
|
|
int? idCompany = User.GetCompanyId();
|
|
|
|
|
int? idUser = User.GetUserId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null || idUser is null)
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var result = await setpointsService.GetAsync(idWell, token)
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Отчет о принятии, или отклонении уставок оператором.
|
|
|
|
|
/// После уставка будет не изменяемой.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="uid"></param>
|
|
|
|
|
/// <param name="id"></param>
|
2022-01-05 17:50:45 +05:00
|
|
|
|
/// <param name="setpointsRequestDto">можно передать только новый state ex.: {state:3} - принято</param>
|
2021-11-24 16:16:17 +05:00
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPut("api/telemetry/{uid}/setpoints/{id}")]
|
|
|
|
|
[ProducesResponseType(typeof(SetpointsRequestDto), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
[AllowAnonymous]
|
2023-07-03 14:33:34 +05:00
|
|
|
|
public async Task<IActionResult> UpdateByTelemetryUidAsync([FromRoute] string uid, int id, SetpointsRequestDto setpointsRequestDto, CancellationToken token)
|
2022-04-11 18:00:34 +05:00
|
|
|
|
{
|
2022-06-16 12:33:05 +05:00
|
|
|
|
var result = await setpointsService.UpdateStateAsync(setpointsRequestDto, token)
|
2021-11-24 16:16:17 +05:00
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получает запросы на изменение уставок панели.
|
|
|
|
|
/// !!SIDE EFFECT: изменяет состояние запросов уставок на отправлено, это не позволит удалить эти уставки после отправки на панель.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="uid"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("api/telemetry/{uid}/setpoints")]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<SetpointsRequestDto>), (int)System.Net.HttpStatusCode.OK)]
|
2021-11-26 17:14:02 +05:00
|
|
|
|
[AllowAnonymous]
|
2023-07-03 14:33:34 +05:00
|
|
|
|
public async Task<IActionResult> GetByTelemetryUidAsync([FromRoute] string uid, CancellationToken token)
|
2021-11-24 16:16:17 +05:00
|
|
|
|
{
|
|
|
|
|
var result = await setpointsService.GetForPanelAsync(uid, token)
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2021-11-24 17:58:53 +05:00
|
|
|
|
/// Пробует удалить запрос на изменение уставок. Это будет выполнено, если запрос еще не был отправлен на панель.
|
2021-11-24 16:16:17 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <param name="token"></param>
|
2021-11-24 17:58:53 +05:00
|
|
|
|
/// <returns>1 - удалено, 0 и меньше - не удалено</returns>
|
2021-11-24 16:16:17 +05:00
|
|
|
|
[HttpDelete("api/well/{idWell}/setpoints/{id}")]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2023-07-03 14:33:34 +05:00
|
|
|
|
public async Task<IActionResult> TryDeleteByIdWellAsync(int idWell, int id, CancellationToken token)
|
2021-11-24 16:16:17 +05:00
|
|
|
|
{
|
|
|
|
|
int? idCompany = User.GetCompanyId();
|
|
|
|
|
int? idUser = User.GetUserId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null || idUser is null)
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2022-06-15 14:57:37 +05:00
|
|
|
|
var result = await setpointsService.TryDelete(id, token)
|
2021-11-24 16:16:17 +05:00
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|