2021-04-02 17:28:07 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
2023-10-22 17:57:39 +05:00
|
|
|
|
using AsbCloudApp.Exceptions;
|
2021-04-02 17:28:07 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
2023-05-02 16:47:16 +05:00
|
|
|
|
using AsbCloudDb.Model;
|
2021-04-02 17:28:07 +05:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Collections.Generic;
|
2023-05-02 16:47:16 +05:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2021-08-11 16:54:42 +05:00
|
|
|
|
using System.Threading;
|
2021-08-11 12:11:21 +05:00
|
|
|
|
using System.Threading.Tasks;
|
2021-04-02 17:28:07 +05:00
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
|
|
|
{
|
2022-06-16 17:37:10 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Инфо о скважине
|
|
|
|
|
/// </summary>
|
2021-04-07 18:01:56 +05:00
|
|
|
|
[Route("api/well")]
|
2021-04-02 17:28:07 +05:00
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class WellController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly IWellService wellService;
|
|
|
|
|
|
|
|
|
|
public WellController(IWellService wellService)
|
|
|
|
|
{
|
|
|
|
|
this.wellService = wellService;
|
|
|
|
|
}
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-10-18 12:38:49 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает список доступных скважин
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns>Список скважин</returns>
|
2021-04-02 17:28:07 +05:00
|
|
|
|
[HttpGet]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2021-04-02 17:28:07 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)]
|
2023-07-03 14:33:34 +05:00
|
|
|
|
public async Task<IActionResult> GetWellsAsync(CancellationToken token)
|
2021-04-02 17:28:07 +05:00
|
|
|
|
{
|
2021-07-21 15:22:58 +05:00
|
|
|
|
var idCompany = User.GetCompanyId();
|
2021-04-02 17:28:07 +05:00
|
|
|
|
|
2021-07-21 15:22:58 +05:00
|
|
|
|
if (idCompany is null)
|
2021-05-18 11:11:16 +05:00
|
|
|
|
return NoContent();
|
|
|
|
|
|
2023-02-15 17:57:32 +05:00
|
|
|
|
var wells = await wellService.GetAsync(new() { IdCompany = idCompany },
|
|
|
|
|
token).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return Ok(wells);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает список доступных скважин
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns>Список скважин</returns>
|
|
|
|
|
[HttpGet("wellTree")]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<DepositBranchDto>), (int)System.Net.HttpStatusCode.OK)]
|
2023-07-03 14:33:34 +05:00
|
|
|
|
public async Task<IActionResult> GetWellTreeAsync(CancellationToken token)
|
2023-02-15 17:57:32 +05:00
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null)
|
|
|
|
|
return NoContent();
|
|
|
|
|
|
|
|
|
|
var wells = await wellService.GetWellTreeAsync((int)idCompany,
|
2021-08-11 17:26:02 +05:00
|
|
|
|
token).ConfigureAwait(false);
|
2021-04-02 17:28:07 +05:00
|
|
|
|
|
|
|
|
|
return Ok(wells);
|
|
|
|
|
}
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-10-20 16:18:07 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает информацию о требуемой скважине
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"> Id требуемой скважины </param>
|
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns>Информация о требуемой скважине </returns>
|
2022-01-05 17:50:45 +05:00
|
|
|
|
[HttpGet("{idWell}")]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2023-07-05 16:00:06 +05:00
|
|
|
|
[ProducesResponseType(typeof(WellMapInfoWithTelemetryStat), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
[ProducesResponseType((int)System.Net.HttpStatusCode.NoContent)]
|
2023-07-03 14:33:34 +05:00
|
|
|
|
public async Task<IActionResult> GetAsync(int idWell, CancellationToken token)
|
2021-10-20 16:18:07 +05:00
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
|
2022-04-11 18:00:34 +05:00
|
|
|
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync(idCompany ?? default, idWell, token).ConfigureAwait(false))
|
2022-06-09 11:19:52 +05:00
|
|
|
|
return Forbid();
|
2021-10-20 16:18:07 +05:00
|
|
|
|
|
2023-07-05 16:00:06 +05:00
|
|
|
|
var well = await wellService.GetOrDefaultStatAsync(idWell, token);
|
2023-07-05 14:22:22 +05:00
|
|
|
|
|
|
|
|
|
return Ok(well);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-18 12:38:49 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Редактирует указанные поля скважины
|
|
|
|
|
/// </summary>
|
2021-10-18 16:30:14 +05:00
|
|
|
|
/// <param name="dto"> Объект параметров скважины.
|
|
|
|
|
/// IdWellType: 1 - Наклонно-направленная, 2 - Горизонтальная.
|
|
|
|
|
/// State: 0 - Неизвестно, 1 - В работе, 2 - Завершена.</param>
|
2021-10-18 12:38:49 +05:00
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns></returns>
|
2022-06-09 11:19:52 +05:00
|
|
|
|
[HttpPut]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2021-10-18 12:38:49 +05:00
|
|
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
2022-06-09 11:19:52 +05:00
|
|
|
|
public async Task<IActionResult> UpdateWellAsync(WellDto dto,
|
2023-07-03 14:33:34 +05:00
|
|
|
|
CancellationToken token)
|
2021-10-18 12:38:49 +05:00
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
2022-06-09 11:19:52 +05:00
|
|
|
|
dto.Id, token).ConfigureAwait(false))
|
2021-10-18 12:38:49 +05:00
|
|
|
|
return Forbid();
|
|
|
|
|
|
2022-06-09 11:19:52 +05:00
|
|
|
|
var result = await wellService.UpdateAsync(dto, token)
|
2021-10-18 16:30:14 +05:00
|
|
|
|
.ConfigureAwait(false);
|
2021-10-18 12:38:49 +05:00
|
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
|
|
|
|
|
}
|
2023-05-02 16:47:16 +05:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обновляет статус скважины
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">ключ скважины</param>
|
|
|
|
|
/// <param name="idState">статус: 0 - Неизвестно, 1 - В работе, 2 - Завершена.</param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPut("{idWell}/state")]
|
|
|
|
|
[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> UpdateWellStateAsync(int idWell,
|
|
|
|
|
[Range(0, 2, ErrorMessage = "Статус некорректен")] int idState,
|
2023-07-03 14:33:34 +05:00
|
|
|
|
CancellationToken token)
|
2023-05-02 16:47:16 +05:00
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2023-10-20 15:46:44 +05:00
|
|
|
|
var dto = await wellService.GetOrDefaultAsync(idWell, token);
|
2023-10-22 17:57:39 +05:00
|
|
|
|
|
|
|
|
|
if (dto is null)
|
|
|
|
|
return this.ValidationBadRequest(nameof(idWell), $"Скважина с id: {idWell} недоступна");
|
|
|
|
|
|
|
|
|
|
dto.IdState = idState;
|
2023-05-02 16:47:16 +05:00
|
|
|
|
|
|
|
|
|
var result = await wellService.UpdateAsync(dto, token)
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
|
|
|
|
|
}
|
2021-04-02 17:28:07 +05:00
|
|
|
|
}
|
|
|
|
|
}
|