diff --git a/AsbCloudApp/Requests/WellOperationRequest.cs b/AsbCloudApp/Requests/WellOperationRequest.cs index 89cd6858..3296c4ad 100644 --- a/AsbCloudApp/Requests/WellOperationRequest.cs +++ b/AsbCloudApp/Requests/WellOperationRequest.cs @@ -6,7 +6,7 @@ namespace AsbCloudApp.Requests /// /// параметры для запроса списка операций /// - public class WellOperationRequestBase: RequestBase + public class WellOperationRequestBase : RequestBase { /// /// фильтр по дате начала операции @@ -42,12 +42,40 @@ namespace AsbCloudApp.Requests /// фильтр по списку id конструкций секции /// public IEnumerable? SectionTypeIds { get; set; } + + /// + /// Параметры для запроса списка операций. + /// Базовый конструктор + /// + public WellOperationRequestBase() + { } + + /// + /// Параметры для запроса списка операций. + /// Копирующий конструктор + /// + /// + public WellOperationRequestBase(WellOperationRequestBase request) + { + GeDepth = request.GeDepth; + LeDepth = request.LeDepth; + GeDate = request.GeDate; + LtDate = request.LtDate; + + OperationCategoryIds = request.OperationCategoryIds; + OperationType = request.OperationType; + SectionTypeIds = request.SectionTypeIds; + + Skip = request.Skip; + Take = request.Take; + SortFields = request.SortFields; + } } /// /// Параметры для запроса списка операций (с id скважины) /// - public class WellOperationRequest: WellOperationRequestBase + public class WellOperationRequest : WellOperationRequestBase { /// /// id скважины @@ -57,7 +85,7 @@ namespace AsbCloudApp.Requests /// /// ctor /// - public WellOperationRequest(){} + public WellOperationRequest() { } /// /// копирующий конструктор @@ -65,21 +93,9 @@ namespace AsbCloudApp.Requests /// /// public WellOperationRequest(WellOperationRequestBase request, int idWell) + :base(request) { - this.IdWell = idWell; - - this.GeDepth = request.GeDepth; - this.LeDepth = request.LeDepth; - this.GeDate = request.GeDate; - this.LtDate = request.LtDate; - - this.OperationCategoryIds = request.OperationCategoryIds; - this.OperationType = request.OperationType; - this.SectionTypeIds = request.SectionTypeIds; - - this.Skip= request.Skip; - this.Take= request.Take; - this.SortFields = request.SortFields; + IdWell = idWell; } } diff --git a/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapPlanBaseController.cs b/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapPlanBaseController.cs index 09d735fe..45da7f11 100644 --- a/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapPlanBaseController.cs +++ b/AsbCloudWebApi/Controllers/ProcessMaps/ProcessMapPlanBaseController.cs @@ -15,6 +15,7 @@ using AsbCloudApp.Data; using AsbCloudApp.Requests.ParserOptions; using AsbCloudInfrastructure.Services.Parser; using AsbCloudApp.Data.ProcessMaps; +using System.ComponentModel.DataAnnotations; namespace AsbCloudWebApi.Controllers.ProcessMaps; @@ -52,12 +53,13 @@ public abstract class ProcessMapPlanBaseController : ControllerBase [HttpPost] [ProducesResponseType(typeof(int), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] - public async Task InsertRange([FromRoute] int idWell, IEnumerable dtos, CancellationToken token) + public async Task InsertRange([FromRoute][Range(0,int.MaxValue)] int idWell, IEnumerable dtos, CancellationToken token) { - if (idWell == 0 || dtos.Any(d => d.IdWell != idWell)) - return this.ValidationBadRequest(nameof(dtos), "all dtos should contain same idWell"); - var idUser = await AssertUserHasAccessToWell(idWell, token); + + foreach (var dto in dtos) + dto.IdWell = idWell; + var result = await repository.InsertRange(idUser, dtos, token); return Ok(result); } @@ -74,11 +76,11 @@ public abstract class ProcessMapPlanBaseController : ControllerBase [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] public async Task ClearAndInsertRange([FromRoute] int idWell, IEnumerable dtos, CancellationToken token) { - if (idWell == 0 || dtos.Any(d => d.IdWell != idWell)) - return this.ValidationBadRequest(nameof(dtos), "all dtos should contain same idWell"); - var idUser = await AssertUserHasAccessToWell(idWell, token); + foreach (var dto in dtos) + dto.IdWell = idWell; + var request = new ProcessMapPlanBaseRequestWithWell(idWell); var result = await repository.ClearAndInsertRange(idUser, request, dtos, token); return Ok(result); @@ -188,15 +190,14 @@ public abstract class ProcessMapPlanBaseController : ControllerBase [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] public async Task UpdateOrInsertRange([FromRoute] int idWell, IEnumerable dtos, CancellationToken token) { - var first = dtos.FirstOrDefault(); - if (first is null) + if (!dtos.Any()) return NoContent(); - - if (idWell == 0 || dtos.Any(d => d.IdWell != idWell)) - return this.ValidationBadRequest(nameof(dtos), "all dtos should contain same idWell"); - + var idUser = await AssertUserHasAccessToWell(idWell, token); + foreach (var dto in dtos) + dto.IdWell = idWell; + var result = await repository.UpdateOrInsertRange(idUser, dtos, token); return Ok(result); } @@ -205,28 +206,31 @@ public abstract class ProcessMapPlanBaseController : ControllerBase /// Импорт РТК из excel (xlsx) файла /// /// - /// + /// /// /// [HttpPost("parse")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] public async Task>> Parse(int idWell, - [FromForm] IFormFileCollection files, + [Required] IFormFile file, CancellationToken token) { await AssertUserHasAccessToWell(idWell, token); - var stream = files.GetExcelFile(); + var stream = file.GetExcelFile(); try { var dto = parserService.Parse(stream, IParserOptionsRequest.Empty()); + foreach (var item in dto.Item) + item.Item.IdWell = idWell; + return Ok(dto); } catch (FileFormatException ex) { - return this.ValidationBadRequest(nameof(files), ex.Message); + return this.ValidationBadRequest(nameof(file), ex.Message); } } diff --git a/AsbCloudWebApi/Extensions.cs b/AsbCloudWebApi/Extensions.cs index 59c72e37..26cea7ba 100644 --- a/AsbCloudWebApi/Extensions.cs +++ b/AsbCloudWebApi/Extensions.cs @@ -113,4 +113,18 @@ public static class Extensions return file.OpenReadStream(); } + + /// + /// Получение Excel + /// + /// + /// + /// + public static Stream GetExcelFile(this IFormFile file) + { + if (Path.GetExtension(file.FileName).ToLower() != ".xlsx") + throw new ArgumentInvalidException(nameof(file), "Требуется .xlsx файл."); + + return file.OpenReadStream(); + } } \ No newline at end of file