diff --git a/AsbCloudApp/Services/IWellOperationImportService.cs b/AsbCloudApp/Services/IWellOperationImportService.cs
index 7ef96ab3..e0f2e39d 100644
--- a/AsbCloudApp/Services/IWellOperationImportService.cs
+++ b/AsbCloudApp/Services/IWellOperationImportService.cs
@@ -5,6 +5,7 @@ namespace AsbCloudApp.Services
public interface IWellOperationImportService
{
Stream Export(int idWell);
+ Stream GetExcelTemplateStream();
void Import(int idWell, Stream stream, bool deleteWellOperationsBeforeImport = false);
}
}
\ No newline at end of file
diff --git a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj
index 0c41213b..9b3889b7 100644
--- a/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj
+++ b/AsbCloudInfrastructure/AsbCloudInfrastructure.csproj
@@ -9,7 +9,11 @@
-
+
+
+
+
+
diff --git a/AsbCloudInfrastructure/Services/WellOperationService/WellOperationImportService.cs b/AsbCloudInfrastructure/Services/WellOperationService/WellOperationImportService.cs
index 87f76289..3355ff89 100644
--- a/AsbCloudInfrastructure/Services/WellOperationService/WellOperationImportService.cs
+++ b/AsbCloudInfrastructure/Services/WellOperationService/WellOperationImportService.cs
@@ -90,16 +90,21 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
return MakeExelFileStream(operations);
}
+ public Stream GetExcelTemplateStream() {
+ var stream = System.Reflection.Assembly.GetExecutingAssembly()
+ .GetManifestResourceStream("AsbCloudInfrastructure.Services.WellOperationService.WellOperationImportTemplate.xlsx");
+ return stream;
+ }
+
private Stream MakeExelFileStream(IEnumerable operations)
{
- using Stream ecxelTemplateStream = System.Reflection.Assembly.GetExecutingAssembly()
- .GetManifestResourceStream("AsbCloudInfrastructure.Services.WellOperationService.WellOperationImportTemplate.xltx");
+ using Stream ecxelTemplateStream = GetExcelTemplateStream();
using var workbook = new XLWorkbook(ecxelTemplateStream, XLEventTracking.Disabled);
AddOperationsToWorkbook(workbook, operations);
MemoryStream memoryStream = new MemoryStream();
- workbook.SaveAs(memoryStream);
+ workbook.SaveAs(memoryStream, new SaveOptions { });
memoryStream.Seek(0, SeekOrigin.Begin);
return memoryStream;
}
@@ -225,12 +230,14 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
}
};
- // проверка диапазона дат
- if (operations.Min(o => o.DateStart) - operations.Max(o => o.DateStart) > drillingDurationLimitMax)
- parseErrors.Add($"Лист {sheet.Name} содержит диапазон дат больше {drillingDurationLimitMax}");
-
if (parseErrors.Any())
throw new FileFormatException(string.Join("\r\n", parseErrors));
+ else
+ {
+ if (operations.Any())
+ if (operations.Min(o => o.DateStart) - operations.Max(o => o.DateStart) > drillingDurationLimitMax)
+ parseErrors.Add($"Лист {sheet.Name} содержит диапазон дат больше {drillingDurationLimitMax}");
+ }
return operations;
}
diff --git a/AsbCloudInfrastructure/Services/WellOperationService/WellOperationImportTemplate.xlsx b/AsbCloudInfrastructure/Services/WellOperationService/WellOperationImportTemplate.xlsx
new file mode 100644
index 00000000..1798d7d8
Binary files /dev/null and b/AsbCloudInfrastructure/Services/WellOperationService/WellOperationImportTemplate.xlsx differ
diff --git a/AsbCloudInfrastructure/Services/WellOperationService/WellOperationImportTemplate.xltx b/AsbCloudInfrastructure/Services/WellOperationService/WellOperationImportTemplate.xltx
deleted file mode 100644
index 0197218c..00000000
Binary files a/AsbCloudInfrastructure/Services/WellOperationService/WellOperationImportTemplate.xltx and /dev/null differ
diff --git a/AsbCloudWebApi/Controllers/WellOperationController.cs b/AsbCloudWebApi/Controllers/WellOperationController.cs
index 9c218049..1a9d4ec9 100644
--- a/AsbCloudWebApi/Controllers/WellOperationController.cs
+++ b/AsbCloudWebApi/Controllers/WellOperationController.cs
@@ -179,16 +179,15 @@ namespace AsbCloudWebApi.Controllers
/// Импортирует операции из excel (xlsx) файла
///
/// id скважины
- /// Коллекция файлов - 1 файл xlsx
- /// Удалить операции перед импортом, если фал валидный
+ /// Коллекция из одного файла xlsx
+ /// Удалить операции перед импортом = 1, если фал валидный
/// Токен отмены задачи
///
[HttpPost]
- [Route("import")]
- [ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
- public async Task ImportAsync(int idWell,
+ [Route("import/{options}")]
+ public async Task ImportAsync(int idWell,
[FromForm] IFormFileCollection files,
- bool deleteWellOperationsBeforeImport = false,
+ int options = 0,
CancellationToken token = default)
{
int? idCompany = User.GetCompanyId();
@@ -205,13 +204,13 @@ namespace AsbCloudWebApi.Controllers
return BadRequest("нет файла");
var file = files[0];
- if(Path.GetExtension( file.FileName).ToLower() != "*.xlsx")
+ if(Path.GetExtension( file.FileName).ToLower() != ".xlsx")
return BadRequest("Требуется xlsx файл.");
using Stream stream = file.OpenReadStream();
try
{
- wellOperationImportService.Import(idWell, stream, deleteWellOperationsBeforeImport);
+ wellOperationImportService.Import(idWell, stream, (options & 1) > 0);
}
catch(FileFormatException ex)
{
@@ -222,7 +221,7 @@ namespace AsbCloudWebApi.Controllers
}
///
- /// Возвращает файл с диска на сервере
+ /// Создает excel файл с операциями по скважине
///
/// id скважины
/// Токен отмены задачи
@@ -246,6 +245,22 @@ namespace AsbCloudWebApi.Controllers
return File(stream, "application/octet-stream", fileName);
}
+ ///
+ /// Возвращает шаблон файла импорта
+ ///
+ /// Токен отмены задачи
+ /// Запрашиваемый файл
+ [HttpGet]
+ [Route("tamplate")]
+ [AllowAnonymous]
+ [ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
+ public IActionResult GetTamplate()
+ {
+ var stream = wellOperationImportService.GetExcelTemplateStream();
+ var fileName = "ЕЦП_шаблон_файла_операций.xlsx";
+ return File(stream, "application/octet-stream", fileName);
+ }
+
private async Task CanUserAccessToWellAsync(int idWell, CancellationToken token = default)
{
int? idCompany = User.GetCompanyId();
diff --git a/AsbCloudWebApi/wwwroot/asset-manifest.json b/AsbCloudWebApi/wwwroot/asset-manifest.json
index dd67d6f5..ae1c9c68 100644
--- a/AsbCloudWebApi/wwwroot/asset-manifest.json
+++ b/AsbCloudWebApi/wwwroot/asset-manifest.json
@@ -1,23 +1,23 @@
{
"files": {
- "main.css": "/static/css/main.1a531ce4.chunk.css",
- "main.js": "/static/js/main.d3cf7fb0.chunk.js",
- "main.js.map": "/static/js/main.d3cf7fb0.chunk.js.map",
- "runtime-main.js": "/static/js/runtime-main.b402d8a8.js",
- "runtime-main.js.map": "/static/js/runtime-main.b402d8a8.js.map",
- "static/js/2.f3289dc7.chunk.js": "/static/js/2.f3289dc7.chunk.js",
- "static/js/2.f3289dc7.chunk.js.map": "/static/js/2.f3289dc7.chunk.js.map",
- "static/js/3.a064d157.chunk.js": "/static/js/3.a064d157.chunk.js",
- "static/js/3.a064d157.chunk.js.map": "/static/js/3.a064d157.chunk.js.map",
+ "main.css": "/static/css/main.e92a8ff6.chunk.css",
+ "main.js": "/static/js/main.edfb453f.chunk.js",
+ "main.js.map": "/static/js/main.edfb453f.chunk.js.map",
+ "runtime-main.js": "/static/js/runtime-main.9eaada4e.js",
+ "runtime-main.js.map": "/static/js/runtime-main.9eaada4e.js.map",
+ "static/js/2.d92842c3.chunk.js": "/static/js/2.d92842c3.chunk.js",
+ "static/js/2.d92842c3.chunk.js.map": "/static/js/2.d92842c3.chunk.js.map",
+ "static/js/3.5f51fb69.chunk.js": "/static/js/3.5f51fb69.chunk.js",
+ "static/js/3.5f51fb69.chunk.js.map": "/static/js/3.5f51fb69.chunk.js.map",
"index.html": "/index.html",
- "static/css/main.1a531ce4.chunk.css.map": "/static/css/main.1a531ce4.chunk.css.map",
- "static/js/2.f3289dc7.chunk.js.LICENSE.txt": "/static/js/2.f3289dc7.chunk.js.LICENSE.txt",
+ "static/css/main.e92a8ff6.chunk.css.map": "/static/css/main.e92a8ff6.chunk.css.map",
+ "static/js/2.d92842c3.chunk.js.LICENSE.txt": "/static/js/2.d92842c3.chunk.js.LICENSE.txt",
"static/media/pointer.e8df778c.svg": "/static/media/pointer.e8df778c.svg"
},
"entrypoints": [
- "static/js/runtime-main.b402d8a8.js",
- "static/js/2.f3289dc7.chunk.js",
- "static/css/main.1a531ce4.chunk.css",
- "static/js/main.d3cf7fb0.chunk.js"
+ "static/js/runtime-main.9eaada4e.js",
+ "static/js/2.d92842c3.chunk.js",
+ "static/css/main.e92a8ff6.chunk.css",
+ "static/js/main.edfb453f.chunk.js"
]
}
\ No newline at end of file
diff --git a/AsbCloudWebApi/wwwroot/index.html b/AsbCloudWebApi/wwwroot/index.html
index 22d65a14..7896c513 100644
--- a/AsbCloudWebApi/wwwroot/index.html
+++ b/AsbCloudWebApi/wwwroot/index.html
@@ -1 +1 @@
-АСБ Vision
\ No newline at end of file
+АСБ Vision
\ No newline at end of file