2021-11-01 16:41:25 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
2022-02-12 11:28:16 +05:00
|
|
|
|
using AsbCloudApp.Exceptions;
|
2021-11-01 16:41:25 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
2021-08-29 17:25:16 +05:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2022-02-12 11:28:16 +05:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2021-08-29 17:25:16 +05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2022-02-17 15:37:27 +05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2021-08-29 17:25:16 +05:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
|
|
|
{
|
2022-06-16 17:37:10 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Формирование программы бурения
|
|
|
|
|
/// </summary>
|
2021-08-29 17:29:24 +05:00
|
|
|
|
[Route("api/well/{idWell}/drillingProgram")]
|
2021-08-29 17:25:16 +05:00
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class DrillingProgramController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly IDrillingProgramService drillingProgramService;
|
2021-11-01 16:41:25 +05:00
|
|
|
|
private readonly IWellService wellService;
|
2021-08-29 17:25:16 +05:00
|
|
|
|
|
2022-02-17 15:37:27 +05:00
|
|
|
|
public DrillingProgramController(IDrillingProgramService drillingProgramService, IWellService wellService)
|
2021-08-29 17:25:16 +05:00
|
|
|
|
{
|
|
|
|
|
this.drillingProgramService = drillingProgramService;
|
2021-11-01 16:41:25 +05:00
|
|
|
|
this.wellService = wellService;
|
2021-08-29 17:25:16 +05:00
|
|
|
|
}
|
2022-02-12 11:28:16 +05:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Список категорий файлов из которых состоит программа бурения
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("categories")]
|
|
|
|
|
[ProducesResponseType(typeof(FileCategoryDto[]), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetCategories(CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var result = await drillingProgramService.GetCategoriesAsync(token);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2022-02-17 15:37:27 +05:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Список пользователей
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("availableUsers")]
|
|
|
|
|
[ProducesResponseType(typeof(FileCategoryDto[]), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetAvailableUsers(int idWell, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var result = await drillingProgramService.GetAvailableUsers(idWell, token);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-27 17:23:43 +05:00
|
|
|
|
/// <summary>
|
2022-02-12 11:28:16 +05:00
|
|
|
|
/// Состояние процесса согласования программы бурения
|
2021-10-27 17:23:43 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"> id скважины </param>
|
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
2021-10-28 16:59:00 +05:00
|
|
|
|
/// <returns> Возвращает файл программы бурения </returns>
|
2021-08-29 17:25:16 +05:00
|
|
|
|
[HttpGet]
|
2022-02-12 11:28:16 +05:00
|
|
|
|
[ProducesResponseType(typeof(DrillingProgramStateDto), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetStateAsync(int idWell, CancellationToken token)
|
2021-08-29 17:25:16 +05:00
|
|
|
|
{
|
2021-11-01 16:41:25 +05:00
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
|
2022-02-12 11:28:16 +05:00
|
|
|
|
var idUser = User.GetUserId();
|
2021-11-02 16:33:49 +05:00
|
|
|
|
|
2022-02-28 14:44:15 +05:00
|
|
|
|
if (idCompany is null || idUser is null ||
|
2021-11-02 16:33:49 +05:00
|
|
|
|
!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false))
|
2021-11-01 16:41:25 +05:00
|
|
|
|
return Forbid();
|
2021-10-28 16:59:00 +05:00
|
|
|
|
|
2022-02-12 11:28:16 +05:00
|
|
|
|
var result = await drillingProgramService.GetStateAsync(idWell, (int)idUser, token);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-28 14:44:15 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Сброс ошибки формирования ПБ
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("ClearError")]
|
2022-03-02 17:41:22 +05:00
|
|
|
|
[Permission("DrillingProgram.get")]
|
2022-02-28 14:44:15 +05:00
|
|
|
|
public IActionResult ClearError(int idWell)
|
|
|
|
|
{
|
|
|
|
|
drillingProgramService.ClearError(idWell);
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-12 11:28:16 +05:00
|
|
|
|
/// <summary>
|
2022-02-17 15:37:27 +05:00
|
|
|
|
/// Загрузка файла для части программы бурения
|
2022-02-12 11:28:16 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
2022-02-18 14:16:35 +05:00
|
|
|
|
/// <param name="idFileCategory">ID части программы. Не путать с категорией файла</param>
|
2022-02-12 11:28:16 +05:00
|
|
|
|
/// <param name="files"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
2022-02-18 14:16:35 +05:00
|
|
|
|
[HttpPost("part/{idFileCategory}")]
|
2022-03-02 17:41:22 +05:00
|
|
|
|
[Permission("DrillingProgram.get")]
|
2022-02-17 15:37:27 +05:00
|
|
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
2022-02-12 11:28:16 +05:00
|
|
|
|
public async Task<IActionResult> AddFile(
|
|
|
|
|
int idWell,
|
2022-02-18 14:16:35 +05:00
|
|
|
|
int idFileCategory,
|
2022-04-11 18:00:34 +05:00
|
|
|
|
[FromForm] IFormFileCollection files,
|
2022-02-12 11:28:16 +05:00
|
|
|
|
CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
int? idCompany = User.GetCompanyId();
|
|
|
|
|
int? idUser = User.GetUserId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null || idUser is null)
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
if (files.Count > 1)
|
|
|
|
|
return BadRequest(ArgumentInvalidException.MakeValidationError(nameof(files), "only 1 file can be uploaded"));
|
|
|
|
|
|
|
|
|
|
if (files.Count == 0)
|
2022-05-18 17:02:03 +05:00
|
|
|
|
return BadRequest(ArgumentInvalidException.MakeValidationError(nameof(files), "at list 1 file should be uploaded"));
|
2022-02-08 10:25:05 +05:00
|
|
|
|
|
2022-02-12 11:28:16 +05:00
|
|
|
|
var fileName = files[0].FileName;
|
2023-01-25 05:32:32 +05:00
|
|
|
|
|
2022-02-12 11:28:16 +05:00
|
|
|
|
var fileStream = files[0].OpenReadStream();
|
2022-04-11 18:00:34 +05:00
|
|
|
|
var result = await drillingProgramService.AddFile(idWell, idFileCategory, (int)idUser, fileName, fileStream, token);
|
2022-02-08 10:25:05 +05:00
|
|
|
|
|
2022-02-12 11:28:16 +05:00
|
|
|
|
return Ok(result);
|
2021-10-28 16:59:00 +05:00
|
|
|
|
}
|
2021-11-17 13:06:48 +05:00
|
|
|
|
|
2021-10-28 16:59:00 +05:00
|
|
|
|
/// <summary>
|
2022-02-17 15:37:27 +05:00
|
|
|
|
/// Добавляет разделы программы бурения
|
2021-10-28 16:59:00 +05:00
|
|
|
|
/// </summary>
|
2022-02-12 11:28:16 +05:00
|
|
|
|
/// <param name="idWell"></param>
|
2022-02-17 15:37:27 +05:00
|
|
|
|
/// <param name="idFileCategories">Список категорий файлов, по которым будут добавлены части ПБ</param>
|
2022-02-12 11:28:16 +05:00
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("part")]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2022-02-17 15:37:27 +05:00
|
|
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> AddPartsAsync(int idWell, [Required] IEnumerable<int> idFileCategories, CancellationToken token)
|
2021-10-28 16:59:00 +05:00
|
|
|
|
{
|
2022-02-12 11:28:16 +05:00
|
|
|
|
int? idCompany = User.GetCompanyId();
|
|
|
|
|
int? idUser = User.GetUserId();
|
2021-11-01 16:41:25 +05:00
|
|
|
|
|
2022-02-12 11:28:16 +05:00
|
|
|
|
if (idCompany is null || idUser is null)
|
|
|
|
|
return Forbid();
|
2021-11-02 16:33:49 +05:00
|
|
|
|
|
2022-02-12 11:28:16 +05:00
|
|
|
|
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false))
|
2021-11-01 16:41:25 +05:00
|
|
|
|
return Forbid();
|
2022-02-12 11:28:16 +05:00
|
|
|
|
|
2022-02-17 15:37:27 +05:00
|
|
|
|
var result = await drillingProgramService.AddPartsAsync(idWell, idFileCategories, token);
|
2022-02-12 11:28:16 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2022-02-17 15:37:27 +05:00
|
|
|
|
/// Удаляет разделы программы бурения
|
2022-02-12 11:28:16 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
2022-02-17 15:37:27 +05:00
|
|
|
|
/// <param name="idFileCategories">Список категорий файлов, по которым будут удалены части ПБ</param>
|
2022-02-12 11:28:16 +05:00
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
2022-02-17 15:37:27 +05:00
|
|
|
|
[HttpDelete("part")]
|
2022-02-12 11:28:16 +05:00
|
|
|
|
[Permission]
|
2022-02-17 15:37:27 +05:00
|
|
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> RemovePartsAsync(int idWell, [Required] IEnumerable<int> idFileCategories, CancellationToken token)
|
2022-02-12 11:28:16 +05:00
|
|
|
|
{
|
|
|
|
|
int? idCompany = User.GetCompanyId();
|
|
|
|
|
int? idUser = User.GetUserId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null || idUser is null)
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2022-02-17 15:37:27 +05:00
|
|
|
|
var result = await drillingProgramService.RemovePartsAsync(idWell, idFileCategories, token);
|
2022-02-12 11:28:16 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-17 15:37:27 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавить пользователя в список publishers или approvers части программы бурения
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
|
|
|
|
/// <param name="idUser"></param>
|
2022-02-18 14:16:35 +05:00
|
|
|
|
/// <param name="idFileCategory"></param>
|
2022-02-17 15:37:27 +05:00
|
|
|
|
/// <param name="idUserRole"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
2022-02-18 14:16:35 +05:00
|
|
|
|
[HttpPost("part/{idFileCategory}/user")]
|
2022-02-12 11:28:16 +05:00
|
|
|
|
[Permission]
|
2022-02-17 15:37:27 +05:00
|
|
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
2023-07-03 14:33:34 +05:00
|
|
|
|
public async Task<IActionResult> AddUserAsync(int idWell, [Required] int idUser, int idFileCategory, [Required] int idUserRole, CancellationToken token)
|
2022-02-12 11:28:16 +05:00
|
|
|
|
{
|
|
|
|
|
int? idCompany = User.GetCompanyId();
|
|
|
|
|
int? idUserEditor = User.GetUserId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null || idUserEditor is null)
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2022-02-18 14:16:35 +05:00
|
|
|
|
var result = await drillingProgramService.AddUserAsync(idWell, idFileCategory, idUser, idUserRole, token);
|
2022-02-12 11:28:16 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-17 15:37:27 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удалить пользователя из списка publishers или approvers части программы бурения
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
|
|
|
|
/// <param name="idUser"></param>
|
2022-02-18 14:16:35 +05:00
|
|
|
|
/// <param name="idFileCategory"></param>
|
2022-02-17 15:37:27 +05:00
|
|
|
|
/// <param name="idUserRole"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
2022-02-18 14:16:35 +05:00
|
|
|
|
[HttpDelete("part/{idFileCategory}/user/{idUser}")]
|
2022-02-12 11:28:16 +05:00
|
|
|
|
[Permission]
|
2022-02-17 15:37:27 +05:00
|
|
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
2023-07-03 14:33:34 +05:00
|
|
|
|
public async Task<IActionResult> RemoveUserAsync(int idWell, int idUser, int idFileCategory, [Required] int idUserRole, CancellationToken token)
|
2022-02-12 11:28:16 +05:00
|
|
|
|
{
|
|
|
|
|
int? idCompany = User.GetCompanyId();
|
|
|
|
|
int? idUserEditor = User.GetUserId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null || idUserEditor is null)
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2022-04-11 18:00:34 +05:00
|
|
|
|
var result = await drillingProgramService.RemoveUserAsync(idWell, idFileCategory, idUser, idUserRole, token);
|
2022-02-12 11:28:16 +05:00
|
|
|
|
return Ok(result);
|
2021-10-27 17:00:27 +05:00
|
|
|
|
}
|
2021-11-09 17:36:44 +05:00
|
|
|
|
|
2021-11-01 16:41:25 +05:00
|
|
|
|
/// <summary>
|
2022-02-12 11:28:16 +05:00
|
|
|
|
/// Создает метку для файла входящего в программу бурения, заменить существующую
|
2021-11-01 16:41:25 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"> id скважины </param>
|
2021-11-09 17:36:44 +05:00
|
|
|
|
/// <param name="markDto">метка файла</param>
|
2021-11-01 16:41:25 +05:00
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("fileMark")]
|
2022-03-02 17:41:22 +05:00
|
|
|
|
[Permission("DrillingProgram.get")]
|
2022-02-12 11:28:16 +05:00
|
|
|
|
public async Task<IActionResult> AddOrReplaceFileMarkAsync(int idWell, FileMarkDto markDto, CancellationToken token)
|
2021-11-01 16:41:25 +05:00
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
|
2021-11-09 17:36:44 +05:00
|
|
|
|
var idUser = User.GetUserId();
|
2021-11-01 16:41:25 +05:00
|
|
|
|
|
2022-04-11 18:00:34 +05:00
|
|
|
|
if (idCompany is null || idUser is null ||
|
2021-11-01 16:41:25 +05:00
|
|
|
|
!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2022-02-12 11:28:16 +05:00
|
|
|
|
var result = await drillingProgramService.AddOrReplaceFileMarkAsync(markDto, (int)idUser, token)
|
2021-11-01 16:41:25 +05:00
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2021-11-09 17:36:44 +05:00
|
|
|
|
|
2021-11-01 16:41:25 +05:00
|
|
|
|
/// <summary>
|
2022-01-05 17:50:45 +05:00
|
|
|
|
/// Помечает метку у файла входящего, в программу бурения, как удаленную
|
2021-11-01 16:41:25 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"> id скважины </param>
|
2021-11-09 17:36:44 +05:00
|
|
|
|
/// <param name="idMark"> id метки </param>
|
2021-11-01 16:41:25 +05:00
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns></returns>
|
2022-02-17 15:37:27 +05:00
|
|
|
|
[HttpDelete("fileMark/{idMark}")]
|
2022-03-02 17:41:22 +05:00
|
|
|
|
[Permission("DrillingProgram.get")]
|
2021-11-01 16:41:25 +05:00
|
|
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
2022-02-12 11:28:16 +05:00
|
|
|
|
public async Task<IActionResult> MarkAsDeletedFileMarkAsync(int idWell, int idMark,
|
|
|
|
|
CancellationToken token)
|
2021-11-01 16:41:25 +05:00
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2022-02-12 11:28:16 +05:00
|
|
|
|
var result = await drillingProgramService.MarkAsDeletedFileMarkAsync(idMark, token)
|
2021-11-09 17:36:44 +05:00
|
|
|
|
.ConfigureAwait(false);
|
2021-11-01 16:41:25 +05:00
|
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2021-08-29 17:25:16 +05:00
|
|
|
|
}
|
|
|
|
|
}
|