From 53e1e07ca0683da21ac11501189d2abdc2e07964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B5=D0=BF=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Thu, 12 Oct 2023 16:03:34 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3=20=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=BE?= =?UTF-8?q?=D0=BB=D0=BB=D0=B5=D1=80=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProcessMaps/ProcessMapBaseController.cs | 55 ++++++++++------ ...cs => ProcessMapWellDrillingController.cs} | 49 +++++--------- .../ProcessMapWellReamController.cs | 17 +++++ .../WellReamProcessMapController.cs | 15 ----- .../SAUB/TelemetryProcessMapController.cs | 65 +++++++++---------- 5 files changed, 102 insertions(+), 99 deletions(-) rename AsbCloudWebApi/Controllers/ProcessMaps/{WellDrillingProcessMapController.cs => ProcessMapWellDrillingController.cs} (79%) create mode 100644 AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapWellReamController.cs delete mode 100644 AsbCloudWebApi/Controllers/ProcessMaps/WellReamProcessMapController.cs diff --git a/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapBaseController.cs b/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapBaseController.cs index 3a72930f..612f30e4 100644 --- a/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapBaseController.cs +++ b/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapBaseController.cs @@ -1,6 +1,7 @@ using System; using System.Threading; using System.Threading.Tasks; +using AsbCloudApp.Data; using AsbCloudApp.Data.ProcessMaps; using AsbCloudApp.Exceptions; using AsbCloudApp.Repositories; @@ -17,8 +18,8 @@ namespace AsbCloudWebApi.Controllers.ProcessMaps; [ApiController] [Route("api/well/{idWell}/[controller]")] [Authorize] -public abstract class ProcessMapBaseController : ControllerBase - where TProcessMap : ProcessMapBaseDto +public abstract class ProcessMapBaseController : ControllerBase + where T : ProcessMapPlanBaseDto { protected int IdUser { @@ -33,17 +34,21 @@ public abstract class ProcessMapBaseController : ControllerBase } } - protected readonly IWellService wellService; - protected readonly IRepositoryWellRelated repository; - protected readonly IUserRepository userRepository; + private readonly IWellService wellService; + private readonly IUserRepository userRepository; + private readonly ICrudRepository wellSectionRepository; + + protected readonly IRepositoryWellRelated repository; protected ProcessMapBaseController(IWellService wellService, - IRepositoryWellRelated repository, - IUserRepository userRepository) + IProcessMapPlanRepository repository, + IUserRepository userRepository, + ICrudRepository wellSectionRepository) { this.wellService = wellService; this.repository = repository; this.userRepository = userRepository; + this.wellSectionRepository = wellSectionRepository; } /// @@ -56,13 +61,15 @@ public abstract class ProcessMapBaseController : ControllerBase [HttpPost] [ProducesResponseType(typeof(int), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] - public virtual async Task InsertAsync(TProcessMap processMap, int idWell, CancellationToken cancellationToken) + public virtual async Task InsertAsync(T processMap, int idWell, CancellationToken cancellationToken) { - processMap.IdWell = idWell; + processMap.IdWell = idWell; processMap.IdUser = IdUser; processMap.LastUpdate = DateTime.UtcNow; - await AssertUserHasAccessToEditProcessMapAsync(processMap.IdWell, cancellationToken); + await CheckIsExistsWellSectionTypeAsync(processMap.IdWellSectionType, cancellationToken); + + await AssertUserHasAccessToEditProcessMapAsync(processMap.IdWell, cancellationToken); var result = await repository.InsertAsync(processMap, cancellationToken); @@ -79,17 +86,19 @@ public abstract class ProcessMapBaseController : ControllerBase [HttpPut] [ProducesResponseType(typeof(int), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] - public virtual async Task UpdateAsync(TProcessMap processMap, int idWell, CancellationToken cancellationToken) + public virtual async Task UpdateAsync(T processMap, int idWell, CancellationToken cancellationToken) { processMap.IdWell = idWell; processMap.IdUser = IdUser; processMap.LastUpdate = DateTime.UtcNow; - await AssertUserHasAccessToEditProcessMapAsync(idWell, cancellationToken); + await CheckIsExistsWellSectionTypeAsync(processMap.IdWellSectionType, cancellationToken); + + await AssertUserHasAccessToEditProcessMapAsync(idWell, cancellationToken); var result = await repository.UpdateAsync(processMap, cancellationToken); - if (result == ICrudRepository.ErrorIdNotFound) + if (result == ICrudRepository.ErrorIdNotFound) return this.ValidationBadRequest(nameof(processMap.Id), $"РТК с Id: {processMap.Id} не существует"); return Ok(result); @@ -98,17 +107,18 @@ public abstract class ProcessMapBaseController : ControllerBase /// /// Удаление РТК /// + /// Id удаляемой РТК /// Id скважины /// /// [HttpDelete] [ProducesResponseType(typeof(int), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] - public virtual async Task DeleteAsync(int idWell, CancellationToken cancellationToken) + public virtual async Task DeleteAsync(int id, int idWell, CancellationToken cancellationToken) { - await AssertUserHasAccessToEditProcessMapAsync(idWell, cancellationToken); + await AssertUserHasAccessToEditProcessMapAsync(idWell, cancellationToken); - var result = await repository.DeleteAsync(idWell, cancellationToken); + var result = await repository.DeleteAsync(id, cancellationToken); return Ok(result); } @@ -128,8 +138,7 @@ public abstract class ProcessMapBaseController : ControllerBase return Ok(processMaps); } - protected virtual async Task AssertUserHasAccessToEditProcessMapAsync(int idWell, - CancellationToken cancellationToken) + protected async Task AssertUserHasAccessToEditProcessMapAsync(int idWell, CancellationToken cancellationToken) { var well = await wellService.GetOrDefaultAsync(idWell, cancellationToken) ?? throw new ArgumentInvalidException(nameof(idWell),$"Скважины с {idWell} не существует"); @@ -140,7 +149,15 @@ public abstract class ProcessMapBaseController : ControllerBase !await wellService.IsCompanyInvolvedInWellAsync(idCompany.Value, idWell, cancellationToken)) throw new ForbidException("Нет доступа к скважине"); - if (well.IdState == 2 && !userRepository.HasPermission(IdUser, "WellDrillingProcessMap.editCompletedWell")) + if (well.IdState == 2 && !userRepository.HasPermission(IdUser, "ProcessMap.editCompletedWell")) throw new ForbidException("Недостаточно прав для редактирования РТК завершенной скважины"); } + + private async Task CheckIsExistsWellSectionTypeAsync(int idWellSectionType, CancellationToken cancellationToken) + { + var wellSection = await wellSectionRepository.GetOrDefaultAsync(idWellSectionType, cancellationToken); + + if (wellSection is null) + throw new ArgumentInvalidException(nameof(ProcessMapPlanWellDrillingDto.IdWellSectionType), $"Тип секции с Id: {idWellSectionType} не найден"); + } } \ No newline at end of file diff --git a/AsbCloudWebApi/Controllers/ProcessMaps/WellDrillingProcessMapController.cs b/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapWellDrillingController.cs similarity index 79% rename from AsbCloudWebApi/Controllers/ProcessMaps/WellDrillingProcessMapController.cs rename to AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapWellDrillingController.cs index 533ed9ca..e6126744 100644 --- a/AsbCloudWebApi/Controllers/ProcessMaps/WellDrillingProcessMapController.cs +++ b/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapWellDrillingController.cs @@ -16,30 +16,28 @@ using Microsoft.AspNetCore.SignalR; namespace AsbCloudWebApi.Controllers.ProcessMaps; -public class WellDrillingProcessMapController : ProcessMapBaseController +public class ProcessMapWellDrillingController : ProcessMapBaseController { private readonly IHubContext telemetryHubContext; - private readonly IWellDrillingProcessMapReportService wellDrillingProcessMapReportService; + private readonly IProcessMapReportWellDrillingService wellDrillingProcessMapReportService; private readonly IProcessMapReportExportService wellDrillingProcessMapReportExportService; private readonly IProcessMapImportService wellDrillingProcessMapImportService; - private readonly ICrudRepository wellSectionRepository; - public WellDrillingProcessMapController(IWellService wellService, - IWellDrillingProcessMapRepository repository, + public ProcessMapWellDrillingController(IWellService wellService, + IProcessMapPlanRepository repository, IUserRepository userRepository, IHubContext telemetryHubContext, IProcessMapReportExportService wellDrillingProcessMapReportExportService, IProcessMapImportService wellDrillingProcessMapImportService, - IWellDrillingProcessMapReportService wellDrillingProcessMapReportService, + IProcessMapReportWellDrillingService wellDrillingProcessMapReportService, ICrudRepository wellSectionRepository) - : base(wellService, repository, userRepository) + : base(wellService, repository, userRepository, wellSectionRepository) { this.telemetryHubContext = telemetryHubContext; this.wellDrillingProcessMapReportExportService = wellDrillingProcessMapReportExportService; this.wellDrillingProcessMapImportService = wellDrillingProcessMapImportService; this.wellDrillingProcessMapReportService = wellDrillingProcessMapReportService; - this.wellSectionRepository = wellSectionRepository; } /// @@ -49,11 +47,8 @@ public class WellDrillingProcessMapController : ProcessMapBaseControllerId скважины /// /// - public override async Task InsertAsync(WellDrillingProcessMapDto processMap, int idWell, - CancellationToken cancellationToken) + public override async Task InsertAsync(ProcessMapPlanWellDrillingDto processMap, int idWell, CancellationToken cancellationToken) { - await CheckIsExistsWellSectionTypeAsync(processMap.IdWellSectionType, cancellationToken); - var result = await base.InsertAsync(processMap, idWell, cancellationToken); await NotifyUsersBySignalR(idWell, cancellationToken); @@ -68,11 +63,8 @@ public class WellDrillingProcessMapController : ProcessMapBaseControllerId скважины /// /// - public override async Task UpdateAsync(WellDrillingProcessMapDto processMap, int idWell, - CancellationToken cancellationToken) + public override async Task UpdateAsync(ProcessMapPlanWellDrillingDto processMap, int idWell, CancellationToken cancellationToken) { - await CheckIsExistsWellSectionTypeAsync(processMap.IdWellSectionType, cancellationToken); - var result = await base.UpdateAsync(processMap, idWell, cancellationToken); await NotifyUsersBySignalR(idWell, cancellationToken); @@ -83,12 +75,13 @@ public class WellDrillingProcessMapController : ProcessMapBaseController /// Удаление РТК /// + /// Id удаляемой РТК /// Id скважины /// /// - public override async Task DeleteAsync(int idWell, CancellationToken cancellationToken) + public override async Task DeleteAsync(int id, int idWell, CancellationToken cancellationToken) { - var result = await base.DeleteAsync(idWell, cancellationToken); + var result = await base.DeleteAsync(id, idWell, cancellationToken); await NotifyUsersBySignalR(idWell, cancellationToken); @@ -102,7 +95,7 @@ public class WellDrillingProcessMapController : ProcessMapBaseController /// [HttpGet("report")] - [ProducesResponseType(typeof(WellDrillingProcessMapDto), StatusCodes.Status200OK)] + [ProducesResponseType(typeof(ProcessMapPlanWellDrillingDto), StatusCodes.Status200OK)] public async Task GetReportAsync(int idWell, CancellationToken cancellationToken) { var report = await wellDrillingProcessMapReportService.GetAsync(idWell, cancellationToken); @@ -139,9 +132,9 @@ public class WellDrillingProcessMapController : ProcessMapBaseController [HttpPost("import/{options}")] [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] - public async Task ImportAsync(int idWell, - int options, - [Required] IFormFile file, + public async Task ImportAsync(int idWell, + int options, + [Required] IFormFile file, CancellationToken cancellationToken) { await AssertUserHasAccessToEditProcessMapAsync(idWell, cancellationToken); @@ -158,7 +151,9 @@ public class WellDrillingProcessMapController : ProcessMapBaseController 0, stream, cancellationToken); - } + + await NotifyUsersBySignalR(idWell, cancellationToken); + } catch (FileFormatException ex) { return this.ValidationBadRequest(nameof(file), ex.Message); @@ -195,14 +190,6 @@ public class WellDrillingProcessMapController : ProcessMapBaseController +{ + public ProcessMapWellReamController(IWellService wellService, + IProcessMapPlanRepository repository, + IUserRepository userRepository, + ICrudRepository wellSectionRepository) + : base(wellService, repository, userRepository, wellSectionRepository) + { + } +} \ No newline at end of file diff --git a/AsbCloudWebApi/Controllers/ProcessMaps/WellReamProcessMapController.cs b/AsbCloudWebApi/Controllers/ProcessMaps/WellReamProcessMapController.cs deleted file mode 100644 index 43f9c26c..00000000 --- a/AsbCloudWebApi/Controllers/ProcessMaps/WellReamProcessMapController.cs +++ /dev/null @@ -1,15 +0,0 @@ -using AsbCloudApp.Data.ProcessMaps; -using AsbCloudApp.Repositories; -using AsbCloudApp.Services; - -namespace AsbCloudWebApi.Controllers.ProcessMaps; - -public class WellReamProcessMapController : ProcessMapBaseController -{ - public WellReamProcessMapController(IWellService wellService, - IWellReamProcessMapRepository repository, - IUserRepository userRepository) - : base(wellService, repository, userRepository) - { - } -} \ No newline at end of file diff --git a/AsbCloudWebApi/Controllers/SAUB/TelemetryProcessMapController.cs b/AsbCloudWebApi/Controllers/SAUB/TelemetryProcessMapController.cs index d5217c21..7128bca3 100644 --- a/AsbCloudWebApi/Controllers/SAUB/TelemetryProcessMapController.cs +++ b/AsbCloudWebApi/Controllers/SAUB/TelemetryProcessMapController.cs @@ -1,13 +1,13 @@ using System; using System.Collections.Generic; -using System.Threading.Tasks; using System.Threading; +using System.Threading.Tasks; using AsbCloudApp.Data.ProcessMaps; using AsbCloudApp.Repositories; using AsbCloudApp.Requests; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Http; using AsbCloudApp.Services; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; namespace AsbCloudWebApi.Controllers.SAUB; @@ -18,20 +18,17 @@ namespace AsbCloudWebApi.Controllers.SAUB; [Route("api/[controller]")] public class TelemetryProcessMapController : ControllerBase { - private readonly IWellService wellService; private readonly ITelemetryService telemetryService; - private readonly IWellDrillingProcessMapRepository wellDrillingProcessMapRepository; - private readonly IWellReamProcessMapRepository wellReamProcessMapRepository; + private readonly IProcessMapPlanRepository processMapPlanWellDrillingRepository; + private readonly IProcessMapPlanRepository processMapPlanWellReamRepository; - public TelemetryProcessMapController(IWellService wellService, - ITelemetryService telemetryService, - IWellDrillingProcessMapRepository wellDrillingProcessMapRepository, - IWellReamProcessMapRepository wellReamProcessMapRepository) + public TelemetryProcessMapController(ITelemetryService telemetryService, + IProcessMapPlanRepository processMapPlanWellDrillingRepository, + IProcessMapPlanRepository processMapPlanWellReamRepository) { - this.wellService = wellService; - this.telemetryService = telemetryService; - this.wellDrillingProcessMapRepository = wellDrillingProcessMapRepository; - this.wellReamProcessMapRepository = wellReamProcessMapRepository; + this.telemetryService = telemetryService; + this.processMapPlanWellDrillingRepository = processMapPlanWellDrillingRepository; + this.processMapPlanWellReamRepository = processMapPlanWellReamRepository; } /// @@ -42,22 +39,22 @@ public class TelemetryProcessMapController : ControllerBase /// /// [HttpGet("wellDrillingProcessMap")] - [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] + [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] public async Task GetWellDrillingProcessMapByUidAsync(string uid, DateTime updateFrom, CancellationToken cancellationToken) { var idWell = telemetryService.GetIdWellByTelemetryUid(uid); - - if (!idWell.HasValue) - return this.ValidationBadRequest(nameof(uid), $"Wrong uid {uid}"); - var wellDrillingProcessMaps = await wellDrillingProcessMapRepository.GetAsync(new WellDrillingProcessMapRequest - { - IdWell = idWell.Value, - UpdateFrom = updateFrom - }, cancellationToken); + if (!idWell.HasValue) + return this.ValidationBadRequest(nameof(uid), $"Wrong uid {uid}"); - return Ok(wellDrillingProcessMaps); + var wellDrillingProcessMaps = await processMapPlanWellDrillingRepository.GetAsync(new[] { new ProcessMapPlanRequest + { + IdWell = idWell.Value, + UpdateFrom = updateFrom + }}, cancellationToken); + + return Ok(wellDrillingProcessMaps); } /// @@ -68,23 +65,23 @@ public class TelemetryProcessMapController : ControllerBase /// /// [HttpGet("wellReamProcessMap")] - [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] + [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] public async Task GetWellReamProcessMapByUidAsync(string uid, DateTime updateFrom, - CancellationToken cancellationToken) + CancellationToken cancellationToken) { var idWell = telemetryService.GetIdWellByTelemetryUid(uid); - if (!idWell.HasValue) - return this.ValidationBadRequest(nameof(uid), $"Wrong uid {uid}"); + if (!idWell.HasValue) + return this.ValidationBadRequest(nameof(uid), $"Wrong uid {uid}"); - var wellReamProcessMaps = await wellReamProcessMapRepository.GetAsync(new WellReamProcessMapRequest - { - IdWell = idWell.Value, - UpdateFrom = updateFrom - }, cancellationToken); + var wellReamProcessMaps = await processMapPlanWellReamRepository.GetAsync(new[] { new ProcessMapPlanRequest + { + IdWell = idWell.Value, + UpdateFrom = updateFrom + }}, cancellationToken); - return Ok(wellReamProcessMaps); + return Ok(wellReamProcessMaps); } } \ No newline at end of file