DD.WellWorkover.Cloud/AsbCloudWebApi/Controllers/DrillFlowChartController.cs
2022-04-11 18:00:34 +05:00

183 lines
8.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudWebApi.Controllers
{
/// <summary>
/// Контроллер для коридоров бурения на панели
/// </summary>
[ApiController]
[Authorize]
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="updateFrom"> Дата, с которой следует искать новые параметры </param>
/// <param name="token"> Токен отмены задачи </param>
/// <returns> Список параметров для коридоров бурения </returns>
[HttpGet]
[Route("api/well/{idWell}/drillFlowChart")]
[Permission]
[ProducesResponseType(typeof(IEnumerable<DrillFlowChartDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetAsync(int idWell, DateTime updateFrom = default,
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,
updateFrom, token);
return Ok(dto);
}
/// <summary>
/// Возвращает все значения для коридоров бурения по uid панели
/// </summary>
/// <param name="uid"> uid панели </param>
/// <param name="updateFrom"> Дата, с которой следует искать новые параметры </param>
/// <param name="token"> Токен отмены задачи </param>
/// <returns> Список параметров для коридоров бурения </returns>
[HttpGet]
[Route("api/telemetry/{uid}/drillFlowChart")]
[AllowAnonymous]
[ProducesResponseType(typeof(IEnumerable<DrillFlowChartDto>), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetByTelemetryAsync(string uid, DateTime updateFrom = default, CancellationToken token = default)
{
var idWell = telemetryService.GetIdWellByTelemetryUid(uid);
if (idWell is null)
return BadRequest($"Wrong uid {uid}");
var dto = await drillFlowChartService.GetAllAsync((int)idWell,
updateFrom, token);
return Ok(dto);
}
/// <summary>
/// Сохраняет значения для коридоров бурения
/// </summary>
/// <param name="idWell"> id скважины </param>
/// <param name="drillFlowChartDto"> Параметры коридоров бурения</param>
/// <param name="token"> Токен отмены задачи </param>
/// <returns></returns>
[HttpPost]
[Route("api/well/{idWell}/drillFlowChart")]
[Permission]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> InsertAsync(int idWell,
DrillFlowChartDto drillFlowChartDto, 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, drillFlowChartDto, token);
return Ok(result);
}
/// <summary>
/// Добавляет массив объектов коридоров бурения
/// </summary>
/// <param name="idWell"> id скважины </param>
/// <param name="drillFlowChartParams"> Массив объектов параметров коридоров бурения</param>
/// <param name="token"> Токен отмены задачи </param>
/// <returns></returns>
[HttpPost]
[Route("api/well/{idWell}/drillFlowChart/range")]
[Permission]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> InsertRangeAsync(int idWell,
IEnumerable<DrillFlowChartDto> 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="drillFlowChart"> Параметры коридоров бурения</param>
/// <param name="token"> Токен отмены задачи </param>
/// <returns></returns>
[HttpPut]
[Route("api/well/{idWell}/drillFlowChart")]
[Permission]
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> EditAsync(int idWell,
DrillFlowChartDto drillFlowChart, 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, drillFlowChart.Id,
drillFlowChart, token);
return Ok(result);
}
/// <summary>
/// Удаляет значения выбранного коридора бурения
/// </summary>
/// <param name="idWell"> id скважины </param>
/// <param name="drillFlowChartParamsId"> Id объекта коридоров бурения</param>
/// <param name="token"> Токен отмены задачи </param>
/// <returns></returns>
[HttpDelete]
[Route("api/well/{idWell}/drillFlowChart")]
[Permission]
[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);
}
}
}