forked from ddrilling/AsbCloudServer
Фикс импорта операций по скважине
This commit is contained in:
parent
74463559b3
commit
f325accca1
@ -16,6 +16,7 @@ using AsbCloudApp.Data.WellOperationImport;
|
|||||||
using AsbCloudApp.Services.WellOperationImport;
|
using AsbCloudApp.Services.WellOperationImport;
|
||||||
using AsbCloudApp.Data.WellOperationImport.Options;
|
using AsbCloudApp.Data.WellOperationImport.Options;
|
||||||
using AsbCloudApp.Exceptions;
|
using AsbCloudApp.Exceptions;
|
||||||
|
using AsbCloudDb.Model;
|
||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers
|
namespace AsbCloudWebApi.Controllers
|
||||||
{
|
{
|
||||||
@ -344,46 +345,88 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Импорт операций из excel (xlsx) файла. Стандартный заполненный шаблон
|
/// Импорт фактических операций из excel (xlsx) файла. Стандартный заполненный шаблон
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell">id скважины</param>
|
/// <param name="idWell">id скважины</param>
|
||||||
/// <param name="options">Параметры для парсинга файла</param>
|
|
||||||
/// <param name="files">Коллекция из одного файла xlsx</param>
|
/// <param name="files">Коллекция из одного файла xlsx</param>
|
||||||
|
/// <param name="deleteBeforeInsert">Удалить операции перед сохранением</param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("import/default")]
|
[HttpPost("import/fact/default/{deleteBeforeInsert:bool}")]
|
||||||
[ProducesResponseType(typeof(IEnumerable<WellOperationDto>), StatusCodes.Status200OK)]
|
[ProducesResponseType(typeof(IEnumerable<WellOperationDto>), StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
||||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||||
[Permission]
|
[Permission]
|
||||||
public Task<IActionResult> ImportDefaultExcelFileAsync(int idWell,
|
public Task<IActionResult> ImportFactDefaultExcelFileAsync(int idWell,
|
||||||
[FromQuery] WellOperationImportDefaultOptionsDto options,
|
|
||||||
[FromForm] IFormFileCollection files,
|
[FromForm] IFormFileCollection files,
|
||||||
CancellationToken cancellationToken) => ImportExcelFileAsync(idWell, files, options,
|
bool deleteBeforeInsert,
|
||||||
(stream, _) => wellOperationDefaultExcelParser.Parse(stream, options),
|
CancellationToken cancellationToken)
|
||||||
cancellationToken);
|
{
|
||||||
|
var options = new WellOperationImportDefaultOptionsDto
|
||||||
|
{
|
||||||
|
IdType = WellOperation.IdOperationTypeFact
|
||||||
|
};
|
||||||
|
|
||||||
|
return ImportExcelFileAsync(idWell, files, options,
|
||||||
|
(stream, _) => wellOperationDefaultExcelParser.Parse(stream, options),
|
||||||
|
deleteBeforeInsert,
|
||||||
|
cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Импорт плановых операций из excel (xlsx) файла. Стандартный заполненный шаблон
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell">id скважины</param>
|
||||||
|
/// <param name="files">Коллекция из одного файла xlsx</param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("import/plan/default")]
|
||||||
|
[ProducesResponseType(typeof(IEnumerable<WellOperationDto>), StatusCodes.Status200OK)]
|
||||||
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||||
|
[Permission]
|
||||||
|
public Task<IActionResult> 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);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Импорт операций из excel (xlsx) файла. ГПНХ (Хантос)
|
/// Импорт операций из excel (xlsx) файла. ГПНХ (Хантос)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell">id скважины</param>
|
/// <param name="idWell">id скважины</param>
|
||||||
/// <param name="options">Параметры для парсинга файла</param>
|
|
||||||
/// <param name="files">Коллекция из одного файла xlsx</param>
|
/// <param name="files">Коллекция из одного файла xlsx</param>
|
||||||
/// <param name="cancellationToken"></param>
|
/// <param name="cancellationToken"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("import/gazpromKhantos")]
|
[HttpPost("import/plan/gazpromKhantos")]
|
||||||
[ProducesResponseType(typeof(IEnumerable<WellOperationDto>), StatusCodes.Status200OK)]
|
[ProducesResponseType(typeof(IEnumerable<WellOperationDto>), StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
||||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||||
[Permission]
|
[Permission]
|
||||||
public Task<IActionResult> ImportGazpromKhantosExcelFileAsync(int idWell,
|
public Task<IActionResult> ImportPlanGazpromKhantosExcelFileAsync(int idWell,
|
||||||
[FromQuery] WellOperationImportGazpromKhantosOptionsDto options,
|
|
||||||
[FromForm] IFormFileCollection files,
|
[FromForm] IFormFileCollection files,
|
||||||
CancellationToken cancellationToken) => ImportExcelFileAsync(idWell, files, options,
|
CancellationToken cancellationToken)
|
||||||
(stream, _) => wellOperationGazpromKhantosExcelParser.Parse(stream, options),
|
{
|
||||||
cancellationToken);
|
var options = new WellOperationImportGazpromKhantosOptionsDto
|
||||||
|
{
|
||||||
|
IdType = WellOperation.IdOperationTypePlan
|
||||||
|
};
|
||||||
|
|
||||||
|
return ImportExcelFileAsync(idWell, files, options,
|
||||||
|
(stream, _) => wellOperationGazpromKhantosExcelParser.Parse(stream, options),
|
||||||
|
null,
|
||||||
|
cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Создает excel файл с операциями по скважине
|
/// Создает excel файл с операциями по скважине
|
||||||
@ -451,9 +494,11 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
return File(stream, "application/octet-stream", fileName);
|
return File(stream, "application/octet-stream", fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: deleteBeforeInsert тоже быстрый костыль
|
||||||
private async Task<IActionResult> ImportExcelFileAsync<TOptions>(int idWell, [FromForm] IFormFileCollection files,
|
private async Task<IActionResult> ImportExcelFileAsync<TOptions>(int idWell, [FromForm] IFormFileCollection files,
|
||||||
TOptions options,
|
TOptions options,
|
||||||
Func<Stream, TOptions, SheetDto> parseMethod,
|
Func<Stream, TOptions, SheetDto> parseMethod,
|
||||||
|
bool? deleteBeforeInsert,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
where TOptions : IWellOperationImportOptions
|
where TOptions : IWellOperationImportOptions
|
||||||
{
|
{
|
||||||
@ -495,6 +540,15 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
|
|
||||||
if (!wellOperations.Any())
|
if (!wellOperations.Any())
|
||||||
return NoContent();
|
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);
|
return Ok(wellOperations);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user