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

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

View File

@ -15,6 +15,7 @@ using AsbCloudApp.Data;
using AsbCloudApp.Requests.ParserOptions; using AsbCloudApp.Requests.ParserOptions;
using AsbCloudInfrastructure.Services.Parser; using AsbCloudInfrastructure.Services.Parser;
using AsbCloudApp.Data.ProcessMaps; using AsbCloudApp.Data.ProcessMaps;
using System.ComponentModel.DataAnnotations;
namespace AsbCloudWebApi.Controllers.ProcessMaps; namespace AsbCloudWebApi.Controllers.ProcessMaps;
@ -52,12 +53,13 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
[HttpPost] [HttpPost]
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)] [ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] [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); var idUser = await AssertUserHasAccessToWell(idWell, token);
foreach (var dto in dtos)
dto.IdWell = idWell;
var result = await repository.InsertRange(idUser, dtos, token); var result = await repository.InsertRange(idUser, dtos, token);
return Ok(result); return Ok(result);
} }
@ -74,11 +76,11 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
public async Task<IActionResult> ClearAndInsertRange([FromRoute] int idWell, IEnumerable<TDto> dtos, CancellationToken token) 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); var idUser = await AssertUserHasAccessToWell(idWell, token);
foreach (var dto in dtos)
dto.IdWell = idWell;
var request = new ProcessMapPlanBaseRequestWithWell(idWell); var request = new ProcessMapPlanBaseRequestWithWell(idWell);
var result = await repository.ClearAndInsertRange(idUser, request, dtos, token); var result = await repository.ClearAndInsertRange(idUser, request, dtos, token);
return Ok(result); return Ok(result);
@ -188,15 +190,14 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
public async Task<IActionResult> UpdateOrInsertRange([FromRoute] int idWell, IEnumerable<TDto> dtos, CancellationToken token) public async Task<IActionResult> UpdateOrInsertRange([FromRoute] int idWell, IEnumerable<TDto> dtos, CancellationToken token)
{ {
var first = dtos.FirstOrDefault(); if (!dtos.Any())
if (first is null)
return NoContent(); 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); var idUser = await AssertUserHasAccessToWell(idWell, token);
foreach (var dto in dtos)
dto.IdWell = idWell;
var result = await repository.UpdateOrInsertRange(idUser, dtos, token); var result = await repository.UpdateOrInsertRange(idUser, dtos, token);
return Ok(result); return Ok(result);
} }
@ -205,28 +206,31 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
/// Импорт РТК из excel (xlsx) файла /// Импорт РТК из excel (xlsx) файла
/// </summary> /// </summary>
/// <param name="idWell"></param> /// <param name="idWell"></param>
/// <param name="files"></param> /// <param name="file"></param>
/// <param name="token"></param> /// <param name="token"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost("parse")] [HttpPost("parse")]
[ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
public async Task<ActionResult<ParserResultDto<TDto>>> Parse(int idWell, public async Task<ActionResult<ParserResultDto<TDto>>> Parse(int idWell,
[FromForm] IFormFileCollection files, [Required] IFormFile file,
CancellationToken token) CancellationToken token)
{ {
await AssertUserHasAccessToWell(idWell, token); await AssertUserHasAccessToWell(idWell, token);
var stream = files.GetExcelFile(); var stream = file.GetExcelFile();
try try
{ {
var dto = parserService.Parse(stream, IParserOptionsRequest.Empty()); var dto = parserService.Parse(stream, IParserOptionsRequest.Empty());
foreach (var item in dto.Item)
item.Item.IdWell = idWell;
return Ok(dto); return Ok(dto);
} }
catch (FileFormatException ex) 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(); 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();
}
} }