From f325accca195a240b45c38f529779eb7aa8fc5fb 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: Fri, 8 Dec 2023 13:11:28 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D0=B8=D0=BC=D0=BF?= =?UTF-8?q?=D0=BE=D1=80=D1=82=D0=B0=20=D0=BE=D0=BF=D0=B5=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B9=20=D0=BF=D0=BE=20=D1=81=D0=BA=D0=B2=D0=B0=D0=B6?= =?UTF-8?q?=D0=B8=D0=BD=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/WellOperationController.cs | 86 +++++++++++++++---- 1 file changed, 70 insertions(+), 16 deletions(-) diff --git a/AsbCloudWebApi/Controllers/WellOperationController.cs b/AsbCloudWebApi/Controllers/WellOperationController.cs index 45db3f0e..cab7e32c 100644 --- a/AsbCloudWebApi/Controllers/WellOperationController.cs +++ b/AsbCloudWebApi/Controllers/WellOperationController.cs @@ -16,6 +16,7 @@ using AsbCloudApp.Data.WellOperationImport; using AsbCloudApp.Services.WellOperationImport; using AsbCloudApp.Data.WellOperationImport.Options; using AsbCloudApp.Exceptions; +using AsbCloudDb.Model; namespace AsbCloudWebApi.Controllers { @@ -344,46 +345,88 @@ namespace AsbCloudWebApi.Controllers return Ok(result); } - /// - /// Импорт операций из excel (xlsx) файла. Стандартный заполненный шаблон + /// Импорт фактических операций из excel (xlsx) файла. Стандартный заполненный шаблон /// /// id скважины - /// Параметры для парсинга файла /// Коллекция из одного файла xlsx + /// Удалить операции перед сохранением /// /// - [HttpPost("import/default")] + [HttpPost("import/fact/default/{deleteBeforeInsert:bool}")] [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status204NoContent)] [Permission] - public Task ImportDefaultExcelFileAsync(int idWell, - [FromQuery] WellOperationImportDefaultOptionsDto options, + public Task ImportFactDefaultExcelFileAsync(int idWell, [FromForm] IFormFileCollection files, - CancellationToken cancellationToken) => ImportExcelFileAsync(idWell, files, options, - (stream, _) => wellOperationDefaultExcelParser.Parse(stream, options), - cancellationToken); + bool deleteBeforeInsert, + CancellationToken cancellationToken) + { + var options = new WellOperationImportDefaultOptionsDto + { + IdType = WellOperation.IdOperationTypeFact + }; + + return ImportExcelFileAsync(idWell, files, options, + (stream, _) => wellOperationDefaultExcelParser.Parse(stream, options), + deleteBeforeInsert, + cancellationToken); + } + + /// + /// Импорт плановых операций из excel (xlsx) файла. Стандартный заполненный шаблон + /// + /// id скважины + /// Коллекция из одного файла xlsx + /// + /// + [HttpPost("import/plan/default")] + [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] + [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [Permission] + public Task ImportPlanDefaultExcelFileAsync(int idWell, + [FromForm] IFormFileCollection files, + CancellationToken cancellationToken) + { + var options = new WellOperationImportDefaultOptionsDto + { + IdType = WellOperation.IdOperationTypePlan + }; + + return ImportExcelFileAsync(idWell, files, options, + (stream, _) => wellOperationDefaultExcelParser.Parse(stream, options), + null, + cancellationToken); + } /// /// Импорт операций из excel (xlsx) файла. ГПНХ (Хантос) /// /// id скважины - /// Параметры для парсинга файла /// Коллекция из одного файла xlsx /// /// - [HttpPost("import/gazpromKhantos")] + [HttpPost("import/plan/gazpromKhantos")] [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status204NoContent)] [Permission] - public Task ImportGazpromKhantosExcelFileAsync(int idWell, - [FromQuery] WellOperationImportGazpromKhantosOptionsDto options, + public Task ImportPlanGazpromKhantosExcelFileAsync(int idWell, [FromForm] IFormFileCollection files, - CancellationToken cancellationToken) => ImportExcelFileAsync(idWell, files, options, - (stream, _) => wellOperationGazpromKhantosExcelParser.Parse(stream, options), - cancellationToken); + CancellationToken cancellationToken) + { + var options = new WellOperationImportGazpromKhantosOptionsDto + { + IdType = WellOperation.IdOperationTypePlan + }; + + return ImportExcelFileAsync(idWell, files, options, + (stream, _) => wellOperationGazpromKhantosExcelParser.Parse(stream, options), + null, + cancellationToken); + } /// /// Создает excel файл с операциями по скважине @@ -451,9 +494,11 @@ namespace AsbCloudWebApi.Controllers return File(stream, "application/octet-stream", fileName); } + //TODO: deleteBeforeInsert тоже быстрый костыль private async Task ImportExcelFileAsync(int idWell, [FromForm] IFormFileCollection files, TOptions options, Func parseMethod, + bool? deleteBeforeInsert, CancellationToken cancellationToken) where TOptions : IWellOperationImportOptions { @@ -495,6 +540,15 @@ namespace AsbCloudWebApi.Controllers if (!wellOperations.Any()) return NoContent(); + + //TODO: очень быстрый костыль + if (deleteBeforeInsert is not null && options.IdType == WellOperation.IdOperationTypeFact) + { + return await InsertRangeAsync(idWell, options.IdType, + deleteBeforeInsert.Value, + wellOperations, + cancellationToken); + } return Ok(wellOperations); }