2023-10-16 15:14:31 +05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2023-10-09 17:16:02 +05:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Data.ProcessMaps;
|
|
|
|
|
using AsbCloudApp.Repositories;
|
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using AsbCloudApp.Services.ProcessMaps;
|
2023-10-16 13:45:29 +05:00
|
|
|
|
using AsbCloudApp.Services.ProcessMaps.WellDrilling;
|
2023-10-09 17:16:02 +05:00
|
|
|
|
using AsbCloudWebApi.SignalR;
|
2023-10-30 12:13:38 +05:00
|
|
|
|
using AsbCloudWebApi.SignalR.Clients;
|
2023-10-09 17:16:02 +05:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.AspNetCore.SignalR;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers.ProcessMaps;
|
|
|
|
|
|
2023-10-19 10:31:28 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// РТК бурение
|
|
|
|
|
/// </summary>
|
2023-10-12 16:03:34 +05:00
|
|
|
|
public class ProcessMapWellDrillingController : ProcessMapBaseController<ProcessMapPlanWellDrillingDto>
|
2023-10-09 17:16:02 +05:00
|
|
|
|
{
|
2023-10-16 13:45:29 +05:00
|
|
|
|
private readonly IProcessMapReportWellDrillingService processMapReportWellDrillingService;
|
|
|
|
|
private readonly IProcessMapReportWellDrillingExportService processMapReportWellDrillingExportService;
|
|
|
|
|
private readonly IProcessMapPlanImportService processMapPlanImportService;
|
2023-10-09 17:16:02 +05:00
|
|
|
|
|
2023-10-16 13:45:29 +05:00
|
|
|
|
public override string SignalRMethod => "ProcessMapWellDrilling";
|
2023-10-09 17:16:02 +05:00
|
|
|
|
|
2023-10-12 16:03:34 +05:00
|
|
|
|
public ProcessMapWellDrillingController(IWellService wellService,
|
|
|
|
|
IProcessMapPlanRepository<ProcessMapPlanWellDrillingDto> repository,
|
2023-10-09 17:16:02 +05:00
|
|
|
|
IUserRepository userRepository,
|
2023-10-16 13:45:29 +05:00
|
|
|
|
IProcessMapReportWellDrillingExportService processMapReportWellDrillingExportService,
|
|
|
|
|
IProcessMapPlanImportService processMapPlanImportService,
|
|
|
|
|
IProcessMapReportWellDrillingService processMapReportWellDrillingService,
|
|
|
|
|
ICrudRepository<WellSectionTypeDto> wellSectionRepository,
|
2023-10-30 12:13:38 +05:00
|
|
|
|
IHubContext<TelemetryHub, ITelemetryHubClient> telemetryHubContext,
|
2023-10-16 13:45:29 +05:00
|
|
|
|
ITelemetryService telemetryService)
|
|
|
|
|
: base(wellService, repository, userRepository, wellSectionRepository, telemetryHubContext, telemetryService)
|
2023-10-09 17:16:02 +05:00
|
|
|
|
{
|
2023-10-16 13:45:29 +05:00
|
|
|
|
this.processMapReportWellDrillingExportService = processMapReportWellDrillingExportService;
|
|
|
|
|
this.processMapPlanImportService = processMapPlanImportService;
|
|
|
|
|
this.processMapReportWellDrillingService = processMapReportWellDrillingService;
|
2023-10-09 17:16:02 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-10-19 10:31:28 +05:00
|
|
|
|
/// Получение данных для отчета РТК бурение
|
2023-10-09 17:16:02 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">Id</param>
|
|
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("report")]
|
2023-10-16 15:14:31 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<ProcessMapPlanWellDrillingDto>), StatusCodes.Status200OK)]
|
2023-10-09 17:16:02 +05:00
|
|
|
|
public async Task<IActionResult> GetReportAsync(int idWell, CancellationToken cancellationToken)
|
|
|
|
|
{
|
2023-10-16 13:45:29 +05:00
|
|
|
|
var report = await processMapReportWellDrillingService.GetAsync(idWell, cancellationToken);
|
2023-10-09 17:16:02 +05:00
|
|
|
|
|
|
|
|
|
return Ok(report);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Экспорт отчета РТК бурение
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">Id скважины</param>
|
|
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("report/export")]
|
|
|
|
|
[ProducesResponseType(typeof(PhysicalFileResult), StatusCodes.Status200OK, "application/octet-stream")]
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
|
|
|
public async Task<IActionResult> ExportReportAsync(int idWell, CancellationToken cancellationToken)
|
|
|
|
|
{
|
2023-10-16 13:45:29 +05:00
|
|
|
|
var report = await processMapReportWellDrillingExportService.ExportAsync(idWell, cancellationToken);
|
2023-10-09 17:16:02 +05:00
|
|
|
|
|
|
|
|
|
if (report is null)
|
|
|
|
|
return NoContent();
|
|
|
|
|
|
|
|
|
|
return File(report.Value.File, "application/octet-stream", report.Value.Name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-10-19 10:31:28 +05:00
|
|
|
|
/// Импорт РТК бурение план
|
2023-10-09 17:16:02 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">Id скважины</param>
|
|
|
|
|
/// <param name="options"></param>
|
|
|
|
|
/// <param name="file"></param>
|
|
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("import/{options}")]
|
|
|
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
2023-10-12 16:03:34 +05:00
|
|
|
|
public async Task<IActionResult> ImportAsync(int idWell,
|
|
|
|
|
int options,
|
|
|
|
|
[Required] IFormFile file,
|
2023-10-09 17:16:02 +05:00
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
await AssertUserHasAccessToEditProcessMapAsync(idWell, cancellationToken);
|
|
|
|
|
|
|
|
|
|
if (Path.GetExtension(file.FileName).ToLower() != ".xlsx")
|
|
|
|
|
return this.ValidationBadRequest(nameof(file), "Требуется xlsx файл.");
|
|
|
|
|
|
|
|
|
|
using Stream stream = file.OpenReadStream();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-10-16 13:45:29 +05:00
|
|
|
|
await processMapPlanImportService.ImportAsync(idWell,
|
2023-10-09 17:16:02 +05:00
|
|
|
|
IdUser,
|
|
|
|
|
(options & 1) > 0,
|
|
|
|
|
stream,
|
|
|
|
|
cancellationToken);
|
2023-10-12 16:03:34 +05:00
|
|
|
|
|
2023-10-19 10:31:28 +05:00
|
|
|
|
await NotifyUsersBySignalR(idWell, cancellationToken);
|
|
|
|
|
}
|
2023-10-09 17:16:02 +05:00
|
|
|
|
catch (FileFormatException ex)
|
|
|
|
|
{
|
|
|
|
|
return this.ValidationBadRequest(nameof(file), ex.Message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2023-10-19 10:31:28 +05:00
|
|
|
|
/// Экспорт РТК бурение план
|
2023-10-09 17:16:02 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">Id скважины</param>
|
|
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("export")]
|
|
|
|
|
[ProducesResponseType(typeof(PhysicalFileResult), StatusCodes.Status200OK, "application/octet-stream")]
|
|
|
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
|
|
|
|
public async Task<IActionResult> ExportAsync(int idWell, CancellationToken cancellationToken)
|
|
|
|
|
{
|
2023-10-16 13:45:29 +05:00
|
|
|
|
var processMapsFile = await processMapPlanImportService.ExportAsync(idWell, cancellationToken);
|
2023-10-09 17:16:02 +05:00
|
|
|
|
|
|
|
|
|
return File(processMapsFile.File, "application/octet-stream", processMapsFile.Name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает шаблон файла для импорта
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Запрашиваемый файл</returns>
|
|
|
|
|
[HttpGet("template")]
|
|
|
|
|
[ProducesResponseType(typeof(PhysicalFileResult), StatusCodes.Status200OK, "application/octet-stream")]
|
|
|
|
|
public async Task<IActionResult> GetTemplateAsync(CancellationToken cancellationToken)
|
|
|
|
|
{
|
2023-10-16 13:45:29 +05:00
|
|
|
|
var template = await processMapPlanImportService.GetExcelTemplateStreamAsync(cancellationToken);
|
2023-10-09 17:16:02 +05:00
|
|
|
|
return File(template.File, "application/octet-stream", template.Name);
|
|
|
|
|
}
|
|
|
|
|
}
|