2024-07-04 11:02:45 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
2021-04-02 17:28:07 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Collections.Generic;
|
2023-05-02 16:47:16 +05:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2021-08-11 16:54:42 +05:00
|
|
|
|
using System.Threading;
|
2021-08-11 12:11:21 +05:00
|
|
|
|
using System.Threading.Tasks;
|
2024-09-02 10:16:04 +05:00
|
|
|
|
using AsbCloudApp.Services.WellReport;
|
2024-08-23 16:43:09 +05:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2021-04-02 17:28:07 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
namespace AsbCloudWebApi.Controllers;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Инфо о скважине
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("api/well")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class WellController : ControllerBase
|
2021-04-02 17:28:07 +05:00
|
|
|
|
{
|
2024-08-19 10:01:07 +05:00
|
|
|
|
private readonly IWellService wellService;
|
2024-09-02 10:16:04 +05:00
|
|
|
|
private readonly IWellReportExportService wellReportExportService;
|
2024-08-19 10:01:07 +05:00
|
|
|
|
|
2024-09-02 10:16:04 +05:00
|
|
|
|
public WellController(IWellService wellService, IWellReportExportService wellReportExportService)
|
|
|
|
|
{
|
|
|
|
|
this.wellService = wellService;
|
|
|
|
|
this.wellReportExportService = wellReportExportService;
|
|
|
|
|
}
|
2024-08-19 10:01:07 +05:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает список доступных скважин
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns>Список скважин</returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetWellsAsync(CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null)
|
|
|
|
|
return NoContent();
|
|
|
|
|
|
|
|
|
|
var wells = await wellService.GetAsync(new() { IdCompany = idCompany },
|
|
|
|
|
token).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return Ok(wells);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-16 17:37:10 +05:00
|
|
|
|
/// <summary>
|
2024-08-19 10:01:07 +05:00
|
|
|
|
/// Возвращает список доступных скважин
|
2022-06-16 17:37:10 +05:00
|
|
|
|
/// </summary>
|
2024-08-19 10:01:07 +05:00
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns>Список скважин</returns>
|
|
|
|
|
[HttpGet("wellTree")]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<DepositBranchDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetWellTreeAsync(CancellationToken token)
|
2021-04-02 17:28:07 +05:00
|
|
|
|
{
|
2024-08-19 10:01:07 +05:00
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null)
|
|
|
|
|
return NoContent();
|
|
|
|
|
|
|
|
|
|
var wells = await wellService.GetWellTreeAsync((int)idCompany,
|
|
|
|
|
token).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return Ok(wells);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает информацию о требуемой скважине
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"> Id требуемой скважины </param>
|
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns>Информация о требуемой скважине </returns>
|
|
|
|
|
[HttpGet("{idWell}")]
|
|
|
|
|
[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(WellMapInfoWithTelemetryStat), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
[ProducesResponseType((int)System.Net.HttpStatusCode.NoContent)]
|
|
|
|
|
public async Task<IActionResult> GetAsync(int idWell, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync(idCompany ?? default, idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var well = await wellService.GetOrDefaultStatAsync(idWell, token);
|
|
|
|
|
|
|
|
|
|
return Ok(well);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Редактирует указанные поля скважины
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dto"> Объект параметров скважины.
|
|
|
|
|
/// IdWellType: 1 - Наклонно-направленная, 2 - Горизонтальная.
|
|
|
|
|
/// State: 0 - Неизвестно, 1 - В работе, 2 - Завершена.</param>
|
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPut]
|
|
|
|
|
[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> UpdateWellAsync(WellDto dto,
|
|
|
|
|
CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
dto.Id, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var result = await wellService.UpdateAsync(dto, token)
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обновляет статус скважины
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">ключ скважины</param>
|
|
|
|
|
/// <param name="idState">статус: 0 - Неизвестно, 1 - В работе, 2 - Завершена.</param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPut("{idWell}/state")]
|
|
|
|
|
[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> UpdateWellStateAsync(int idWell,
|
|
|
|
|
[Range(0, 2, ErrorMessage = "Статус некорректен")] int idState,
|
|
|
|
|
CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var dto = await wellService.GetOrDefaultAsync(idWell, token);
|
|
|
|
|
|
|
|
|
|
if (dto is null)
|
|
|
|
|
return this.ValidationBadRequest(nameof(idWell), $"Скважина с id: {idWell} недоступна");
|
|
|
|
|
|
|
|
|
|
dto.IdState = idState;
|
|
|
|
|
|
|
|
|
|
var result = await wellService.UpdateAsync(dto, token)
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
|
2021-04-02 17:28:07 +05:00
|
|
|
|
}
|
2024-08-23 16:43:09 +05:00
|
|
|
|
|
2024-09-02 10:16:04 +05:00
|
|
|
|
//TODO: навзание пока такое. У нас в API уже есть метод с такой сигнатурой.
|
|
|
|
|
|
2024-08-23 16:43:09 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получить отчёт по скважине
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-09-02 10:16:04 +05:00
|
|
|
|
[HttpGet("{idWell}/report/export")]
|
|
|
|
|
[ProducesResponseType(typeof(PhysicalFileResult), StatusCodes.Status200OK, "application/octet-stream")]
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
|
|
|
public async Task<IActionResult> ExportAsync(int idWell, CancellationToken token)
|
2024-08-23 16:43:09 +05:00
|
|
|
|
{
|
2024-09-02 10:16:04 +05:00
|
|
|
|
var report = await wellReportExportService.ExportAsync(idWell, token);
|
|
|
|
|
|
|
|
|
|
if (report is null)
|
|
|
|
|
return NoContent();
|
2024-08-23 16:43:09 +05:00
|
|
|
|
|
2024-09-02 10:16:04 +05:00
|
|
|
|
return File(report.Value.File, "application/octet-stream", report.Value.Name);
|
2024-08-23 16:43:09 +05:00
|
|
|
|
}
|
2021-04-02 17:28:07 +05:00
|
|
|
|
}
|