2021-08-16 14:19:43 +05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading;
|
2021-08-13 17:25:06 +05:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2021-08-18 16:57:20 +05:00
|
|
|
|
using System;
|
2021-08-13 17:25:06 +05:00
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2021-08-16 14:19:43 +05:00
|
|
|
|
/// Контроллер вручную внесенных операций на скважине
|
2021-08-13 17:25:06 +05:00
|
|
|
|
/// </summary>
|
2021-08-17 09:39:05 +05:00
|
|
|
|
[Route("api/well/{idWell}/wellOperations")]
|
2021-08-13 17:25:06 +05:00
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class WellOperationController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly IWellOperationService operationService;
|
|
|
|
|
private readonly IWellService wellService;
|
|
|
|
|
|
|
|
|
|
public WellOperationController(IWellOperationService operationService, IWellService wellService)
|
|
|
|
|
{
|
|
|
|
|
this.operationService = operationService;
|
|
|
|
|
this.wellService = wellService;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 14:19:43 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает список имен типов операций на скважине
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2021-08-13 17:25:06 +05:00
|
|
|
|
[HttpGet]
|
2021-08-17 09:39:05 +05:00
|
|
|
|
[Route("categories")]
|
2021-08-19 12:24:57 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<WellOperationCategoryDto>), (int)System.Net.HttpStatusCode.OK)]
|
2021-08-17 09:39:05 +05:00
|
|
|
|
public IActionResult GetCategories()
|
2021-08-16 14:19:43 +05:00
|
|
|
|
{
|
2021-08-17 09:20:31 +05:00
|
|
|
|
var result = operationService.GetCategories();
|
2021-08-16 14:19:43 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2021-08-18 16:57:20 +05:00
|
|
|
|
/// Отфильтрованный список операций на скважине. Если не применять фильтр, то вернется весь список. Сортированный по глубине затем по дате
|
2021-08-16 14:19:43 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
2021-08-18 16:57:20 +05:00
|
|
|
|
/// <param name="opertaionType">фильтр по план = 0, факт = 1</param>
|
|
|
|
|
/// <param name="sectionTypeIds">фильтр по списку id конструкций секции</param>
|
|
|
|
|
/// <param name="operationCategoryIds">фильтр по списку id категорий операции</param>
|
|
|
|
|
/// <param name="begin">фильтр по началу операции</param>
|
|
|
|
|
/// <param name="end">фильтр по окончанию операции</param>
|
2021-08-23 16:59:26 +05:00
|
|
|
|
/// <param name="minDepth">фильтр по минимальной глубине скважины</param>
|
|
|
|
|
/// <param name="maxDepth">фильтр по максимальной глубине скважины</param>
|
2021-08-18 16:57:20 +05:00
|
|
|
|
/// <param name="skip"></param>
|
|
|
|
|
/// <param name="take"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns>Список операций на скважине в контейнере для постраничного просмотра</returns>
|
2021-08-16 14:19:43 +05:00
|
|
|
|
[HttpGet]
|
|
|
|
|
[ProducesResponseType(typeof(PaginationContainer<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)]
|
2021-08-18 17:25:40 +05:00
|
|
|
|
public async Task<IActionResult> GetOperationsAsync(
|
2021-08-18 16:57:20 +05:00
|
|
|
|
int idWell,
|
|
|
|
|
int? opertaionType = default,
|
|
|
|
|
[FromQuery] IEnumerable<int> sectionTypeIds = default,
|
|
|
|
|
[FromQuery] IEnumerable<int> operationCategoryIds = default,
|
|
|
|
|
DateTime begin = default,
|
|
|
|
|
DateTime end = default,
|
2021-08-23 16:59:26 +05:00
|
|
|
|
double minDepth = double.MinValue,
|
|
|
|
|
double maxDepth = double.MaxValue,
|
2021-08-18 16:57:20 +05:00
|
|
|
|
int skip = 0,
|
|
|
|
|
int take = 32,
|
2021-08-13 17:25:06 +05:00
|
|
|
|
CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2021-08-18 16:57:20 +05:00
|
|
|
|
var result = await operationService.GetOperationsAsync(
|
|
|
|
|
idWell,
|
|
|
|
|
opertaionType,
|
|
|
|
|
sectionTypeIds,
|
|
|
|
|
operationCategoryIds,
|
|
|
|
|
begin,
|
|
|
|
|
end,
|
2021-08-23 16:59:26 +05:00
|
|
|
|
minDepth,
|
|
|
|
|
maxDepth,
|
2021-08-18 16:57:20 +05:00
|
|
|
|
skip,
|
|
|
|
|
take,
|
|
|
|
|
token)
|
|
|
|
|
.ConfigureAwait(false);
|
2021-08-13 17:25:06 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 14:19:43 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает нужную операцию на скважине
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
|
|
|
|
/// <param name="idOperation">id нужной операции</param>
|
|
|
|
|
/// <param name="token">Токен отмены задачи</param>
|
|
|
|
|
/// <returns>Нужную операцию на скважине</returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[Route("{idOperation}")]
|
|
|
|
|
[ProducesResponseType(typeof(WellOperationDto), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetAsync(int idWell, int idOperation,
|
|
|
|
|
CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var result = await operationService.GetAsync(idOperation, token).ConfigureAwait(false);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавляет новые операции на скважине
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
|
|
|
|
/// <param name="values">Данные о добавляемых операциях</param>
|
|
|
|
|
/// <param name="token">Токен отмены задачи</param>
|
|
|
|
|
/// <returns>Количество добавленых в БД строк</returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> InsertRangeAsync(int idWell, [FromBody] IEnumerable<WellOperationDto> values,
|
|
|
|
|
CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var result = await operationService.InsertRangeAsync(idWell, values, token)
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обновляет выбранную операцию на скважине
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
|
|
|
|
/// <param name="idOperation">id выбраной операции</param>
|
|
|
|
|
/// <param name="value">Новые данные для выбраной операции</param>
|
|
|
|
|
/// <param name="token">Токен отмены задачи</param>
|
|
|
|
|
/// <returns>Количество обновленных в БД строк</returns>
|
|
|
|
|
[HttpPut("{idOperation}")]
|
|
|
|
|
[ProducesResponseType(typeof(WellOperationDto), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> UpdateAsync(int idWell, int idOperation,
|
|
|
|
|
[FromBody] WellOperationDto value, CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var result = await operationService.UpdateAsync(idWell, idOperation, value, token)
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удаляет выбраную операцию на скважине
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
|
|
|
|
/// <param name="idOperation">id выбраной операции</param>
|
|
|
|
|
/// <param name="token">Токен отмены задачи</param>
|
|
|
|
|
/// <returns>Количество удаленных из БД строк</returns>
|
|
|
|
|
[HttpDelete("{idOperation}")]
|
|
|
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> DeleteAsync(int idWell, int idOperation, CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell,
|
|
|
|
|
token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var result = await operationService.DeleteAsync(new int[] { idOperation }, token)
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-13 17:25:06 +05:00
|
|
|
|
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
int? idCompany = User.GetCompanyId();
|
|
|
|
|
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|