From 65ef2242e89f728501e31eb81be2d62156518e7b 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=20=D0=90=D0=BB=D0=B5=D0=BA?= =?UTF-8?q?=D1=81=D0=B0=D0=BD=D0=B4=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= Date: Mon, 24 Jul 2023 16:00:40 +0500 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B8=D0=BC=D0=BF=D0=BE=D1=80=D1=82?= =?UTF-8?q?=D0=B0/=D1=8D=D0=BA=D1=81=D0=BF=D0=BE=D1=80=D1=82=D0=B0=20?= =?UTF-8?q?=D0=A0=D0=A2=D0=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Добавил флаг, который определяет следует ли удалить РТК у скважины если импортируемый файл валидный. 2. Поправил пути в методах экспорта/импорта в контроллере РТК. --- .../Repositories/IProcessMapRepository.cs | 17 +++++++++++++---- .../Services/IProcessMapPlanImportService.cs | 4 +++- .../Repository/ProcessMapRepository.cs | 10 ++++++++++ .../ProcessMap/ProcessMapPlanImportService.cs | 6 +++++- .../Controllers/ProcessMapController.cs | 9 ++++++--- 5 files changed, 37 insertions(+), 9 deletions(-) diff --git a/AsbCloudApp/Repositories/IProcessMapRepository.cs b/AsbCloudApp/Repositories/IProcessMapRepository.cs index b126e18a..10710d9a 100644 --- a/AsbCloudApp/Repositories/IProcessMapRepository.cs +++ b/AsbCloudApp/Repositories/IProcessMapRepository.cs @@ -9,12 +9,12 @@ using System.Threading.Tasks; namespace AsbCloudApp.Repositories { /// - /// + /// РТК /// public interface IProcessMapPlanRepository : IRepositoryWellRelated { /// - /// . + /// Получить параметры бурения начиная с даты. /// /// /// @@ -24,11 +24,20 @@ namespace AsbCloudApp.Repositories DateTime? updateFrom, CancellationToken token = default); /// - /// + /// Получить параметры бурения /// /// /// /// - Task> GetProcessMapAsync(IEnumerable requests, CancellationToken token); + Task> GetProcessMapAsync(IEnumerable requests, + CancellationToken token); + + /// + /// Удалить РТК + /// + /// + /// + /// + Task RemoveRangeAsync(int idWell, CancellationToken cancellationToken); } } \ No newline at end of file diff --git a/AsbCloudApp/Services/IProcessMapPlanImportService.cs b/AsbCloudApp/Services/IProcessMapPlanImportService.cs index 84442df1..c5daa587 100644 --- a/AsbCloudApp/Services/IProcessMapPlanImportService.cs +++ b/AsbCloudApp/Services/IProcessMapPlanImportService.cs @@ -14,10 +14,12 @@ public interface IProcessMapPlanImportService /// /// /// + /// /// /// /// - Task ImportAsync(int idWell, int idUser, Stream stream, CancellationToken cancellationToken); + Task ImportAsync(int idWell, int idUser, bool deleteProcessMapPlansBeforeImport, Stream stream, + CancellationToken cancellationToken); /// /// Сформировать файл с данными diff --git a/AsbCloudInfrastructure/Repository/ProcessMapRepository.cs b/AsbCloudInfrastructure/Repository/ProcessMapRepository.cs index b80fe6d9..1d3fec14 100644 --- a/AsbCloudInfrastructure/Repository/ProcessMapRepository.cs +++ b/AsbCloudInfrastructure/Repository/ProcessMapRepository.cs @@ -60,6 +60,16 @@ namespace AsbCloudInfrastructure.Repository return dtos; } + public async Task RemoveRangeAsync(int idWell, CancellationToken cancellationToken) + { + var entitites = await dbContext.ProcessMap.Where(x => x.IdWell == idWell) + .ToListAsync(cancellationToken); + + dbContext.ProcessMap.RemoveRange(entitites); + + return await dbContext.SaveChangesAsync(cancellationToken); + } + public override async Task InsertAsync(ProcessMapPlanDto dto, CancellationToken token) { diff --git a/AsbCloudInfrastructure/Services/ProcessMap/ProcessMapPlanImportService.cs b/AsbCloudInfrastructure/Services/ProcessMap/ProcessMapPlanImportService.cs index 60fbc9bd..06551f24 100644 --- a/AsbCloudInfrastructure/Services/ProcessMap/ProcessMapPlanImportService.cs +++ b/AsbCloudInfrastructure/Services/ProcessMap/ProcessMapPlanImportService.cs @@ -52,7 +52,8 @@ public class ProcessMapPlanImportService : IProcessMapPlanImportService this.wellSectionTypeRepository = wellSectionTypeRepository; } - public async Task ImportAsync(int idWell, int idUser, Stream stream, CancellationToken cancellationToken) + public async Task ImportAsync(int idWell, int idUser, bool deleteProcessMapPlansBeforeImport, Stream stream, + CancellationToken cancellationToken) { sections = (await wellSectionTypeRepository.GetAllAsync(cancellationToken)).ToArray(); @@ -60,6 +61,9 @@ public class ProcessMapPlanImportService : IProcessMapPlanImportService var processPlanMaps = ParseWorkBook(workBook); + if (deleteProcessMapPlansBeforeImport) + await processMapPlanRepository.RemoveRangeAsync(idWell, cancellationToken); + foreach (var processPlanMap in processPlanMaps) { processPlanMap.IdWell = idWell; diff --git a/AsbCloudWebApi/Controllers/ProcessMapController.cs b/AsbCloudWebApi/Controllers/ProcessMapController.cs index 474c260c..95f41405 100644 --- a/AsbCloudWebApi/Controllers/ProcessMapController.cs +++ b/AsbCloudWebApi/Controllers/ProcessMapController.cs @@ -183,12 +183,14 @@ namespace AsbCloudWebApi.Controllers /// Импортирует плановой РТК из excel (xlsx) файла /// /// Id скважины + /// Удалить РТК перед импортом = 1, если файл валидный /// Загружаемый файл /// /// [HttpPost] - [Route("import")] + [Route("import/{idWell}/{options}")] public async Task ImportAsync(int idWell, + int options, [Required] IFormFile file, CancellationToken cancellationToken) { @@ -204,6 +206,7 @@ namespace AsbCloudWebApi.Controllers await processMapPlanImportService.ImportAsync(idWell, idUser.Value, + (options & 1) > 0, stream, cancellationToken); @@ -217,9 +220,9 @@ namespace AsbCloudWebApi.Controllers /// /// [HttpGet] - [Route("export")] + [Route("export/{idWell}")] [ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)] - public async Task ExportAsync([FromQuery] int idWell, CancellationToken cancellationToken) + public async Task ExportAsync(int idWell, CancellationToken cancellationToken) { int? idUser = User.GetUserId();