2021-11-01 16:41:25 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Services;
|
2021-08-29 17:25:16 +05:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
|
|
|
{
|
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;
|
|
|
|
|
private readonly IFileService fileService;
|
2021-11-01 16:41:25 +05:00
|
|
|
|
private readonly IWellService wellService;
|
2021-08-29 17:25:16 +05:00
|
|
|
|
|
2021-11-01 16:41:25 +05:00
|
|
|
|
public DrillingProgramController(IDrillingProgramService drillingProgramService,
|
|
|
|
|
IFileService fileService, IWellService wellService)
|
2021-08-29 17:25:16 +05:00
|
|
|
|
{
|
|
|
|
|
this.drillingProgramService = drillingProgramService;
|
|
|
|
|
this.fileService = fileService;
|
2021-11-01 16:41:25 +05:00
|
|
|
|
this.wellService = wellService;
|
2021-08-29 17:25:16 +05:00
|
|
|
|
}
|
2021-10-27 17:23:43 +05:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создает программу бурения
|
|
|
|
|
/// </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]
|
2021-10-28 16:59:00 +05:00
|
|
|
|
[ProducesResponseType(typeof(FileResult), (int)System.Net.HttpStatusCode.OK)]
|
2021-08-29 17:25:16 +05:00
|
|
|
|
public async Task<IActionResult> GetAsync(int idWell, CancellationToken token = default)
|
|
|
|
|
{
|
2021-11-01 16:41:25 +05:00
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
|
2021-11-02 16:33:49 +05:00
|
|
|
|
var fileChangerId = User.GetUserId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null || fileChangerId is null ||
|
|
|
|
|
!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false))
|
2021-11-01 16:41:25 +05:00
|
|
|
|
return Forbid();
|
|
|
|
|
|
2021-11-09 17:36:44 +05:00
|
|
|
|
var fileInfo = await drillingProgramService.GetOrCreateAsync(idWell,
|
2021-11-02 16:33:49 +05:00
|
|
|
|
(int)fileChangerId, token)
|
2021-08-29 17:25:16 +05:00
|
|
|
|
.ConfigureAwait(false);
|
2021-11-02 16:33:49 +05:00
|
|
|
|
|
2021-09-01 15:55:10 +05:00
|
|
|
|
if (fileInfo is null)
|
|
|
|
|
return NoContent();
|
2021-10-28 15:08:06 +05:00
|
|
|
|
|
2021-09-23 10:53:48 +05:00
|
|
|
|
var relativePath = fileService.GetUrl(fileInfo);
|
2021-10-28 16:59:00 +05:00
|
|
|
|
|
|
|
|
|
return PhysicalFile(Path.GetFullPath(relativePath), "application/octet-stream", fileInfo.Name);
|
|
|
|
|
}
|
2021-11-17 13:06:48 +05:00
|
|
|
|
|
2021-10-28 16:59:00 +05:00
|
|
|
|
/// <summary>
|
2021-10-29 12:47:18 +05:00
|
|
|
|
/// Создает программу бурения
|
2021-10-28 16:59:00 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"> id скважины </param>
|
2021-11-17 13:06:48 +05:00
|
|
|
|
/// <param name="fileShareService"></param>
|
2021-10-28 16:59:00 +05:00
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns> Возвращает ссылку на файл программы бурения в облаке </returns>
|
|
|
|
|
[HttpGet("webUrl")]
|
|
|
|
|
[ProducesResponseType(typeof(string), (int)System.Net.HttpStatusCode.OK)]
|
2021-11-17 13:06:48 +05:00
|
|
|
|
public async Task<IActionResult> GetOrCreateSharedUrlAsync(int idWell, [FromServices]IFileShareService fileShareService, CancellationToken token = default)
|
2021-10-28 16:59:00 +05:00
|
|
|
|
{
|
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-02 16:33:49 +05:00
|
|
|
|
|
2021-11-09 17:36:44 +05:00
|
|
|
|
if (idCompany is null || idUser is null ||
|
2021-11-02 16:33:49 +05:00
|
|
|
|
!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
2021-11-01 16:41:25 +05:00
|
|
|
|
idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2021-11-09 17:36:44 +05:00
|
|
|
|
var sharedUrl = await drillingProgramService.GetOrCreateSharedUrlAsync(idWell,
|
2021-11-17 13:06:48 +05:00
|
|
|
|
(int)idUser, fileShareService, token)
|
2021-10-29 12:47:18 +05:00
|
|
|
|
.ConfigureAwait(false);
|
2021-10-29 16:03:24 +05:00
|
|
|
|
|
2021-11-09 17:36:44 +05:00
|
|
|
|
return Ok(sharedUrl);
|
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>
|
2021-11-09 17:36:44 +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")]
|
2021-11-09 17:36:44 +05:00
|
|
|
|
public async Task<IActionResult> CreateFileMarkAsync(int idWell, FileMarkDto markDto, CancellationToken token = default)
|
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
|
|
|
|
|
2021-11-09 17:36:44 +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();
|
|
|
|
|
|
2021-11-09 17:36:44 +05:00
|
|
|
|
var result = await drillingProgramService.CreateFileMarkAsync(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>
|
2021-11-09 17:36:44 +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>
|
|
|
|
|
[HttpDelete("fileMark")]
|
|
|
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
2021-11-09 17:36:44 +05:00
|
|
|
|
public async Task<IActionResult> DeleteFileMarkAsync(int idWell, int idMark,
|
2021-11-01 16:41:25 +05:00
|
|
|
|
CancellationToken token = default)
|
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2021-11-09 17:36:44 +05:00
|
|
|
|
var result = await drillingProgramService.MarkFileMarkAsDeletedAsync(idMark, token)
|
|
|
|
|
.ConfigureAwait(false);
|
2021-11-01 16:41:25 +05:00
|
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2021-08-29 17:25:16 +05:00
|
|
|
|
}
|
|
|
|
|
}
|