Merge branch 'feature/#27942032-well-composite-operations' of http://test.digitaldrilling.ru:8080/DDrilling/AsbCloudServer into feature/#27942032-well-composite-operations

This commit is contained in:
Olga Nemt 2024-03-13 09:52:29 +05:00
commit 5cbe97e950
3 changed files with 68 additions and 34 deletions

View File

@ -42,6 +42,34 @@ namespace AsbCloudApp.Requests
/// фильтр по списку id конструкций секции
/// </summary>
public IEnumerable<int>? SectionTypeIds { get; set; }
/// <summary>
/// Параметры для запроса списка операций.
/// Базовый конструктор
/// </summary>
public WellOperationRequestBase()
{ }
/// <summary>
/// Параметры для запроса списка операций.
/// Копирующий конструктор
/// </summary>
/// <param name="request"></param>
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;
}
}
/// <summary>
@ -65,21 +93,9 @@ namespace AsbCloudApp.Requests
/// <param name="request"></param>
/// <param name="idWell"></param>
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;
}
}

View File

@ -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<TDto> : ControllerBase
[HttpPost]
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
public async Task<IActionResult> InsertRange([FromRoute] int idWell, IEnumerable<TDto> dtos, CancellationToken token)
public async Task<IActionResult> InsertRange([FromRoute][Range(0,int.MaxValue)] int idWell, IEnumerable<TDto> 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<TDto> : ControllerBase
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
public async Task<IActionResult> ClearAndInsertRange([FromRoute] int idWell, IEnumerable<TDto> 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<TDto> : ControllerBase
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
public async Task<IActionResult> UpdateOrInsertRange([FromRoute] int idWell, IEnumerable<TDto> 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<TDto> : ControllerBase
/// Импорт РТК из excel (xlsx) файла
/// </summary>
/// <param name="idWell"></param>
/// <param name="files"></param>
/// <param name="file"></param>
/// <param name="token"></param>
/// <returns></returns>
[HttpPost("parse")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
public async Task<ActionResult<ParserResultDto<TDto>>> 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);
}
}

View File

@ -113,4 +113,18 @@ public static class Extensions
return file.OpenReadStream();
}
/// <summary>
/// Получение Excel
/// </summary>
/// <param name="files"></param>
/// <returns></returns>
/// <exception cref="ArgumentInvalidException"></exception>
public static Stream GetExcelFile(this IFormFile file)
{
if (Path.GetExtension(file.FileName).ToLower() != ".xlsx")
throw new ArgumentInvalidException(nameof(file), "Требуется .xlsx файл.");
return file.OpenReadStream();
}
}