2022-04-11 18:00:34 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Collections.Generic;
|
2021-10-11 15:21:26 +05:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2022-06-16 17:37:10 +05:00
|
|
|
|
/// Режимы бурения
|
2021-10-11 15:21:26 +05:00
|
|
|
|
/// </summary>
|
2021-10-14 10:18:43 +05:00
|
|
|
|
[Route("api/well/{idWell}/drillParams/")]
|
2021-10-11 15:21:26 +05:00
|
|
|
|
[ApiController]
|
|
|
|
|
public class DrillParamsController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly IDrillParamsService drillParamsService;
|
2021-10-11 16:43:10 +05:00
|
|
|
|
private readonly IWellService wellService;
|
2021-10-11 15:21:26 +05:00
|
|
|
|
|
2021-10-11 16:43:10 +05:00
|
|
|
|
public DrillParamsController(IDrillParamsService drillParamsService,
|
|
|
|
|
IWellService wellService)
|
2021-10-11 15:21:26 +05:00
|
|
|
|
{
|
|
|
|
|
this.drillParamsService = drillParamsService;
|
2021-10-11 16:43:10 +05:00
|
|
|
|
this.wellService = wellService;
|
2021-10-11 15:21:26 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2022-01-05 17:50:45 +05:00
|
|
|
|
/// Возвращает автоматически рассчитанные значения для режимов бурения
|
2021-10-11 15:21:26 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"> id скважины </param>
|
|
|
|
|
/// <param name="startDepth"> Стартовая глубина </param>
|
|
|
|
|
/// <param name="endDepth"> Конечная глубина </param>
|
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns> Значения по умолчанию для режимов бурения </returns>
|
2021-10-13 12:27:40 +05:00
|
|
|
|
[HttpGet("autoParams")]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2022-04-11 18:00:34 +05:00
|
|
|
|
[ProducesResponseType(typeof(DrillParamsDto), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetDefaultAsync(int idWell,
|
2021-10-12 11:30:07 +05:00
|
|
|
|
double startDepth, double endDepth, CancellationToken token = default)
|
2021-10-11 15:21:26 +05:00
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
|
2021-10-11 16:43:10 +05:00
|
|
|
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false))
|
2021-10-11 15:21:26 +05:00
|
|
|
|
return Forbid();
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
|
|
|
|
var drillParamsDo = await drillParamsService.GetDefaultDrillParamsAsync(idWell,
|
2021-10-12 11:30:07 +05:00
|
|
|
|
startDepth, endDepth, token);
|
2021-10-11 15:21:26 +05:00
|
|
|
|
|
2021-10-11 16:43:10 +05:00
|
|
|
|
return Ok(drillParamsDo);
|
2021-10-11 15:21:26 +05:00
|
|
|
|
}
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-10-11 16:43:10 +05:00
|
|
|
|
/// <summary>
|
2021-10-12 11:30:07 +05:00
|
|
|
|
/// Возвращает все значения для режимов бурения на скважине
|
2021-10-11 16:43:10 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"> id скважины </param>
|
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns> Список параметров для режимов бурения на скважине </returns>
|
2021-10-12 12:50:04 +05:00
|
|
|
|
[HttpGet]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2022-04-11 18:00:34 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<DrillParamsDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetAllAsync(int idWell,
|
2021-10-11 16:43:10 +05:00
|
|
|
|
CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-10-11 16:43:10 +05:00
|
|
|
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2021-10-12 12:02:28 +05:00
|
|
|
|
var dto = await drillParamsService.GetAllAsync(idWell, token);
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-10-11 16:43:10 +05:00
|
|
|
|
return Ok(dto);
|
|
|
|
|
}
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-10-11 15:21:26 +05:00
|
|
|
|
/// <summary>
|
2021-10-11 16:43:10 +05:00
|
|
|
|
/// Сохраняет значения для режимов бурения по секции на скважине
|
2021-10-11 15:21:26 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"> id скважины </param>
|
|
|
|
|
/// <param name="drillParamsDto"> Параметры режимов бурений для секции</param>
|
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns></returns>
|
2021-10-12 12:50:04 +05:00
|
|
|
|
[HttpPost]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2022-04-11 18:00:34 +05:00
|
|
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> InsertAsync(int idWell,
|
2021-10-11 15:21:26 +05:00
|
|
|
|
DrillParamsDto drillParamsDto, CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
|
2021-10-11 16:43:10 +05:00
|
|
|
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false))
|
2021-10-11 15:21:26 +05:00
|
|
|
|
return Forbid();
|
2021-10-11 16:43:10 +05:00
|
|
|
|
|
2021-10-13 12:27:40 +05:00
|
|
|
|
var result = await drillParamsService.InsertAsync(idWell, drillParamsDto, token);
|
2021-10-11 15:21:26 +05:00
|
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-10-13 12:27:40 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавляет массив объектов режимов бурений
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"> id скважины </param>
|
|
|
|
|
/// <param name="drillParams"> Массив объектов параметров режима бурений для секции</param>
|
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("range")]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2022-04-11 18:00:34 +05:00
|
|
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> InsertRangeAsync(int idWell,
|
2021-10-13 12:27:40 +05:00
|
|
|
|
IEnumerable<DrillParamsDto> drillParams, CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-10-13 12:27:40 +05:00
|
|
|
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var result = await drillParamsService.InsertRangeAsync(idWell, drillParams,
|
|
|
|
|
token);
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-10-13 12:27:40 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2021-10-14 17:57:25 +05:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удаляет старые режимы бурения по скважине и добавляет новые
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">Id скважины для добавления</param>
|
|
|
|
|
/// <param name="drillParams">Новые режимы бурения </param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns>кол-во затронутых изменениями записей</returns>
|
|
|
|
|
[HttpPost("save")]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2021-10-14 17:57:25 +05:00
|
|
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> SaveAsync(int idWell, IEnumerable<DrillParamsDto> drillParams, CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var result = await drillParamsService.SaveAsync(idWell, drillParams,
|
|
|
|
|
token);
|
|
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-11 16:43:10 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Изменяет значения выбранного режима бурения
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"> id скважины </param>
|
2021-10-13 15:56:23 +05:00
|
|
|
|
/// <param name="dtoId"> id dto для изменения </param>
|
2021-10-11 16:43:10 +05:00
|
|
|
|
/// <param name="drillParamsDto"> Параметры режимов бурений для секции</param>
|
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns></returns>
|
2021-10-12 12:50:04 +05:00
|
|
|
|
[HttpPut]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2022-04-11 18:00:34 +05:00
|
|
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
2021-10-13 15:56:23 +05:00
|
|
|
|
public async Task<IActionResult> UpdateAsync(int idWell, int dtoId,
|
2021-10-11 16:43:10 +05:00
|
|
|
|
DrillParamsDto drillParamsDto, CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-10-11 16:43:10 +05:00
|
|
|
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2021-10-13 15:56:23 +05:00
|
|
|
|
var result = await drillParamsService.UpdateAsync(idWell, dtoId,
|
2021-10-11 16:43:10 +05:00
|
|
|
|
drillParamsDto, token);
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-10-11 16:43:10 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-10-11 16:43:10 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удаляет объект значений выбранного режима бурения
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"> id скважины </param>
|
|
|
|
|
/// <param name="drillParamsId"> Id объекта параметров режима бурений для секции</param>
|
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns></returns>
|
2021-10-12 12:50:04 +05:00
|
|
|
|
[HttpDelete]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2022-04-11 18:00:34 +05:00
|
|
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> DeleteAsync(int idWell,
|
2021-10-11 16:43:10 +05:00
|
|
|
|
int drillParamsId, CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-10-11 16:43:10 +05:00
|
|
|
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
|
|
|
|
var result = await drillParamsService.DeleteAsync(drillParamsId,
|
2021-10-11 16:43:10 +05:00
|
|
|
|
token);
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-10-11 16:43:10 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-10-13 12:27:40 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает значения для режимов бурения на композитной скважине
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"> id скважины </param>
|
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns> Список параметров для режимов бурения на композитной скважине </returns>
|
|
|
|
|
[HttpGet("composite")]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2022-04-11 18:00:34 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<DrillParamsDto>), (int)System.Net.HttpStatusCode.OK)]
|
2021-10-13 12:27:40 +05:00
|
|
|
|
public async Task<IActionResult> GetCompositeAllAsync(int idWell, CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-10-13 12:27:40 +05:00
|
|
|
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var dto = await drillParamsService.GetCompositeAllAsync(idWell, token);
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-10-13 12:27:40 +05:00
|
|
|
|
return Ok(dto);
|
|
|
|
|
}
|
2021-10-11 15:21:26 +05:00
|
|
|
|
}
|
|
|
|
|
}
|