2021-10-14 10:18:43 +05:00
|
|
|
|
using System;
|
2021-10-13 17:34:32 +05:00
|
|
|
|
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>
|
2021-10-14 10:18:43 +05:00
|
|
|
|
[Route("api/well/{idWell}/drillFlowChart/")]
|
2021-10-13 17:34:32 +05:00
|
|
|
|
[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>
|
2021-10-14 10:18:43 +05:00
|
|
|
|
/// <param name="updateFrom"> Дата, с которой следует искать новые параметры </param>
|
2021-10-13 17:34:32 +05:00
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns> Список параметров для корридоров бурения </returns>
|
2021-10-14 10:18:43 +05:00
|
|
|
|
[HttpGet]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<DrillFlowChartDto>), (int) System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetAllAsync(int idWell, DateTime updateFrom,
|
|
|
|
|
CancellationToken token = default)
|
2021-10-13 17:34:32 +05:00
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2021-10-14 10:18:43 +05:00
|
|
|
|
var dto = await drillFlowChartService.GetAllAsync(idWell,
|
|
|
|
|
updateFrom, token);
|
2021-10-13 17:34:32 +05:00
|
|
|
|
|
|
|
|
|
return Ok(dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает все значения для корридоров бурения по uid панели
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="uid"> uid панели </param>
|
2021-10-14 10:18:43 +05:00
|
|
|
|
/// <param name="updateFrom"> Дата, с которой следует искать новые параметры </param>
|
2021-10-13 17:34:32 +05:00
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns> Список параметров для корридоров бурения </returns>
|
2021-10-14 10:18:43 +05:00
|
|
|
|
[HttpGet("{uid}")]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<DrillFlowChartDto>), (int) System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetAllAsync(string uid, DateTime updateFrom, CancellationToken token = default)
|
2021-10-13 17:34:32 +05:00
|
|
|
|
{
|
|
|
|
|
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();
|
|
|
|
|
|
2021-10-14 10:18:43 +05:00
|
|
|
|
var dto = await drillFlowChartService.GetAllAsync((int)idWell,
|
|
|
|
|
updateFrom, token);
|
2021-10-13 17:34:32 +05:00
|
|
|
|
|
|
|
|
|
return Ok(dto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сохраняет значения для корридоров бурения
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"> id скважины </param>
|
2021-10-14 10:18:43 +05:00
|
|
|
|
/// <param name="drillFlowChartDto"> Параметры корридоров бурения</param>
|
2021-10-13 17:34:32 +05:00
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ProducesResponseType(typeof(int), (int) System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> InsertAsync(int idWell,
|
2021-10-14 10:18:43 +05:00
|
|
|
|
DrillFlowChartDto drillFlowChartDto, CancellationToken token = default)
|
2021-10-13 17:34:32 +05:00
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2021-10-14 10:18:43 +05:00
|
|
|
|
var result = await drillFlowChartService.InsertAsync(idWell, drillFlowChartDto, token);
|
2021-10-13 17:34:32 +05:00
|
|
|
|
|
|
|
|
|
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,
|
2021-10-14 10:18:43 +05:00
|
|
|
|
IEnumerable<DrillFlowChartDto> drillFlowChartParams, CancellationToken token = default)
|
2021-10-13 17:34:32 +05:00
|
|
|
|
{
|
|
|
|
|
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>
|
2021-10-14 10:18:43 +05:00
|
|
|
|
/// <param name="drillFlowChart"> Параметры корридоров бурения</param>
|
2021-10-13 17:34:32 +05:00
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPut]
|
|
|
|
|
[ProducesResponseType(typeof(int), (int) System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> EditAsync(int idWell,
|
2021-10-14 10:18:43 +05:00
|
|
|
|
DrillFlowChartDto drillFlowChart, CancellationToken token = default)
|
2021-10-13 17:34:32 +05:00
|
|
|
|
{
|
|
|
|
|
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,
|
2021-10-14 10:18:43 +05:00
|
|
|
|
drillFlowChart, token);
|
2021-10-13 17:34:32 +05:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|