forked from ddrilling/AsbCloudServer
168 lines
7.5 KiB
C#
168 lines
7.5 KiB
C#
|
using System.Collections.Generic;
|
||
|
using System.Threading;
|
||
|
using System.Threading.Tasks;
|
||
|
using Microsoft.AspNetCore.Mvc;
|
||
|
using AsbCloudApp.Data;
|
||
|
using AsbCloudApp.Services;
|
||
|
|
||
|
namespace AsbCloudWebApi.Controllers
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// Контроллер для корридоров бурения на панели
|
||
|
/// </summary>
|
||
|
[Route("api/drillFlowChartParams/{idWell}")]
|
||
|
[ApiController]
|
||
|
public class DrillFlowChartController : ControllerBase
|
||
|
{
|
||
|
private readonly IDrillFlowChartService drillFlowChartService;
|
||
|
private readonly ITelemetryService telemetryService;
|
||
|
private readonly IWellService wellService;
|
||
|
|
||
|
public DrillFlowChartController(IDrillFlowChartService drillFlowChartService,
|
||
|
ITelemetryService telemetryService, IWellService wellService)
|
||
|
{
|
||
|
this.drillFlowChartService = drillFlowChartService;
|
||
|
this.telemetryService = telemetryService;
|
||
|
this.wellService = wellService;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Возвращает все значения для корридоров бурения по id скважины
|
||
|
/// </summary>
|
||
|
/// <param name="idWell"> id скважины </param>
|
||
|
/// <param name="token"> Токен отмены задачи </param>
|
||
|
/// <returns> Список параметров для корридоров бурения </returns>
|
||
|
[HttpGet("paramsByIdWell")]
|
||
|
[ProducesResponseType(typeof(IEnumerable<DrillFlowChartParamsDto>), (int) System.Net.HttpStatusCode.OK)]
|
||
|
public async Task<IActionResult> GetAllAsync(int idWell, CancellationToken token = default)
|
||
|
{
|
||
|
var idCompany = User.GetCompanyId();
|
||
|
|
||
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||
|
idWell, token).ConfigureAwait(false))
|
||
|
return Forbid();
|
||
|
|
||
|
var dto = await drillFlowChartService.GetAllAsync(idWell, token);
|
||
|
|
||
|
return Ok(dto);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Возвращает все значения для корридоров бурения по uid панели
|
||
|
/// </summary>
|
||
|
/// <param name="uid"> uid панели </param>
|
||
|
/// <param name="token"> Токен отмены задачи </param>
|
||
|
/// <returns> Список параметров для корридоров бурения </returns>
|
||
|
[HttpGet]
|
||
|
[ProducesResponseType(typeof(IEnumerable<DrillFlowChartParamsDto>), (int) System.Net.HttpStatusCode.OK)]
|
||
|
public async Task<IActionResult> GetAllAsync(string uid, CancellationToken token = default)
|
||
|
{
|
||
|
var idCompany = User.GetCompanyId();
|
||
|
|
||
|
var idWell = telemetryService.GetidWellByTelemetryUid(uid);
|
||
|
|
||
|
if (idCompany is null || idWell is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||
|
(int)idWell, token).ConfigureAwait(false))
|
||
|
return Forbid();
|
||
|
|
||
|
var dto = await drillFlowChartService.GetAllAsync((int)idWell, token);
|
||
|
|
||
|
return Ok(dto);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Сохраняет значения для корридоров бурения
|
||
|
/// </summary>
|
||
|
/// <param name="idWell"> id скважины </param>
|
||
|
/// <param name="drillFlowChartParamsDto"> Параметры корридоров бурения</param>
|
||
|
/// <param name="token"> Токен отмены задачи </param>
|
||
|
/// <returns></returns>
|
||
|
[HttpPost]
|
||
|
[ProducesResponseType(typeof(int), (int) System.Net.HttpStatusCode.OK)]
|
||
|
public async Task<IActionResult> InsertAsync(int idWell,
|
||
|
DrillFlowChartParamsDto drillFlowChartParamsDto, 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 drillFlowChartService.InsertAsync(idWell, drillFlowChartParamsDto, token);
|
||
|
|
||
|
return Ok(result);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Добавляет массив объектов корридоров бурения
|
||
|
/// </summary>
|
||
|
/// <param name="idWell"> id скважины </param>
|
||
|
/// <param name="drillFlowChartParams"> Массив объектов параметров корридоров бурения</param>
|
||
|
/// <param name="token"> Токен отмены задачи </param>
|
||
|
/// <returns></returns>
|
||
|
[HttpPost("range")]
|
||
|
[ProducesResponseType(typeof(int), (int) System.Net.HttpStatusCode.OK)]
|
||
|
public async Task<IActionResult> InsertRangeAsync(int idWell,
|
||
|
IEnumerable<DrillFlowChartParamsDto> drillFlowChartParams, 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 drillFlowChartService.InsertRangeAsync(idWell, drillFlowChartParams,
|
||
|
token);
|
||
|
|
||
|
return Ok(result);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Изменяет значения выбранного корридора бурения
|
||
|
/// </summary>
|
||
|
/// <param name="idWell"> id скважины </param>
|
||
|
/// <param name="drillFlowChartParams"> Параметры корридоров бурения</param>
|
||
|
/// <param name="token"> Токен отмены задачи </param>
|
||
|
/// <returns></returns>
|
||
|
[HttpPut]
|
||
|
[ProducesResponseType(typeof(int), (int) System.Net.HttpStatusCode.OK)]
|
||
|
public async Task<IActionResult> EditAsync(int idWell,
|
||
|
DrillFlowChartParamsDto drillFlowChartParams, 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 drillFlowChartService.UpdateAsync(idWell,
|
||
|
drillFlowChartParams, token);
|
||
|
|
||
|
return Ok(result);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Удаляет значения выбранного корридора бурения
|
||
|
/// </summary>
|
||
|
/// <param name="idWell"> id скважины </param>
|
||
|
/// <param name="drillFlowChartParamsId"> Id объекта корридоров бурения</param>
|
||
|
/// <param name="token"> Токен отмены задачи </param>
|
||
|
/// <returns></returns>
|
||
|
[HttpDelete]
|
||
|
[ProducesResponseType(typeof(int), (int) System.Net.HttpStatusCode.OK)]
|
||
|
public async Task<IActionResult> DeleteAsync(int idWell,
|
||
|
int drillFlowChartParamsId, 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 drillFlowChartService.DeleteAsync(drillFlowChartParamsId,
|
||
|
token);
|
||
|
|
||
|
return Ok(result);
|
||
|
}
|
||
|
}
|
||
|
}
|