2023-09-25 11:56:40 +05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using AsbCloudApp.Data.ProcessMap;
|
|
|
|
|
using AsbCloudApp.Exceptions;
|
|
|
|
|
using AsbCloudApp.Repositories;
|
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System;
|
2023-09-26 14:31:37 +05:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2023-09-25 11:56:40 +05:00
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Проработка скважины
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class ProcessMapWellboreDevelopmentController : CrudWellRelatedController<ProcessMapWellboreDevelopmentDto,
|
|
|
|
|
IProcessMapWellboreDevelopmentRepository>
|
|
|
|
|
{
|
|
|
|
|
private readonly IUserRepository userRepository;
|
|
|
|
|
private readonly IProcessMapWellboreDevelopmentService processMapWellboreDevelopmentService;
|
|
|
|
|
|
|
|
|
|
public ProcessMapWellboreDevelopmentController(IWellService wellService,
|
|
|
|
|
IProcessMapWellboreDevelopmentRepository processMapWellboreDevelopmentRepository,
|
|
|
|
|
IUserRepository userRepository,
|
|
|
|
|
IProcessMapWellboreDevelopmentService processMapWellboreDevelopmentService)
|
|
|
|
|
: base(wellService, processMapWellboreDevelopmentRepository)
|
|
|
|
|
{
|
|
|
|
|
this.userRepository = userRepository;
|
|
|
|
|
this.processMapWellboreDevelopmentService = processMapWellboreDevelopmentService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавить запись проработки
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
/// <exception cref="ForbidException"></exception>
|
|
|
|
|
public override async Task<ActionResult<int>> InsertAsync(ProcessMapWellboreDevelopmentDto value, CancellationToken token)
|
|
|
|
|
{
|
2023-09-26 14:31:37 +05:00
|
|
|
|
value.IdUser = User.GetUserId()
|
|
|
|
|
?? throw new ForbidException("Неизвестный пользователь");
|
|
|
|
|
|
|
|
|
|
await AssertUserHasAccessToProcessMapWellboreDevelopmentAsync(value.IdWell, value.IdUser, token);
|
|
|
|
|
|
2023-09-25 11:56:40 +05:00
|
|
|
|
return await processMapWellboreDevelopmentService.InsertAsync(value, token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обновить запись проработки
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="value"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public override async Task<ActionResult<int>> UpdateAsync(ProcessMapWellboreDevelopmentDto value, CancellationToken token)
|
|
|
|
|
{
|
2023-09-26 14:31:37 +05:00
|
|
|
|
value.IdUser = User.GetUserId()
|
|
|
|
|
?? throw new ForbidException("Неизвестный пользователь");
|
|
|
|
|
|
|
|
|
|
await AssertUserHasAccessToProcessMapWellboreDevelopmentAsync(value.IdWell, value.IdUser, token);
|
2023-09-25 11:56:40 +05:00
|
|
|
|
|
|
|
|
|
return await processMapWellboreDevelopmentService.UpdateAsync(value, token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает проработки по uid телеметрии
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="uid">Уникальный ключ телеметрии</param>
|
|
|
|
|
/// <param name="updateFrom">Необязательный параметр. Начальная дата</param>
|
|
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("telemetry/{uid}")]
|
2023-09-26 14:31:37 +05:00
|
|
|
|
[AllowAnonymous]
|
2023-09-25 11:56:40 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<ProcessMapWellboreDevelopmentDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetByUidAsync(string uid, DateTime updateFrom, CancellationToken cancellationToken)
|
|
|
|
|
{
|
2023-09-26 14:31:37 +05:00
|
|
|
|
var dto = await processMapWellboreDevelopmentService.GetByTelemetryAsync(uid, updateFrom,
|
|
|
|
|
cancellationToken);
|
2023-09-25 11:56:40 +05:00
|
|
|
|
|
|
|
|
|
return Ok(dto);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-26 14:31:37 +05:00
|
|
|
|
private async Task AssertUserHasAccessToProcessMapWellboreDevelopmentAsync(int idUser, int idWell, CancellationToken cancellationToken)
|
2023-09-25 11:56:40 +05:00
|
|
|
|
{
|
2023-09-26 14:31:37 +05:00
|
|
|
|
var well = await wellService.GetOrDefaultAsync(idWell, cancellationToken)
|
|
|
|
|
?? throw new ForbidException($"Скважины с {idWell} не существует");
|
|
|
|
|
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
if (idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync(idCompany.Value, idWell, cancellationToken))
|
|
|
|
|
throw new ForbidException("Нет доступа к скважине");
|
2023-09-25 11:56:40 +05:00
|
|
|
|
|
2023-09-26 14:31:37 +05:00
|
|
|
|
if (well.IdState == 2 && !userRepository.HasPermission(idUser, "ProcessMap.editCompletedWell"))
|
|
|
|
|
throw new ForbidException("Недостаточно прав для редактирования РТК завершённой скважины");
|
2023-09-25 11:56:40 +05:00
|
|
|
|
}
|
|
|
|
|
}
|