forked from ddrilling/AsbCloudServer
Merge branch 'dev' of https://bitbucket.org/autodrilling/asbcloudserver into dev
This commit is contained in:
commit
47397e4ad6
@ -5,6 +5,7 @@ namespace AsbCloudApp.Services
|
|||||||
public interface IWellOperationImportService
|
public interface IWellOperationImportService
|
||||||
{
|
{
|
||||||
Stream Export(int idWell);
|
Stream Export(int idWell);
|
||||||
|
Stream GetExcelTemplateStream();
|
||||||
void Import(int idWell, Stream stream, bool deleteWellOperationsBeforeImport = false);
|
void Import(int idWell, Stream stream, bool deleteWellOperationsBeforeImport = false);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -9,7 +9,11 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="Services\WellOperationService\WellOperationImportTemplate.xltx" />
|
<None Remove="Services\WellOperationService\WellOperationImportTemplate.xlsx" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<EmbeddedResource Include="Services\WellOperationService\WellOperationImportTemplate.xlsx" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -90,16 +90,21 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
|
|||||||
return MakeExelFileStream(operations);
|
return MakeExelFileStream(operations);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Stream GetExcelTemplateStream() {
|
||||||
|
var stream = System.Reflection.Assembly.GetExecutingAssembly()
|
||||||
|
.GetManifestResourceStream("AsbCloudInfrastructure.Services.WellOperationService.WellOperationImportTemplate.xlsx");
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
private Stream MakeExelFileStream(IEnumerable<WellOperation> operations)
|
private Stream MakeExelFileStream(IEnumerable<WellOperation> operations)
|
||||||
{
|
{
|
||||||
using Stream ecxelTemplateStream = System.Reflection.Assembly.GetExecutingAssembly()
|
using Stream ecxelTemplateStream = GetExcelTemplateStream();
|
||||||
.GetManifestResourceStream("AsbCloudInfrastructure.Services.WellOperationService.WellOperationImportTemplate.xltx");
|
|
||||||
|
|
||||||
using var workbook = new XLWorkbook(ecxelTemplateStream, XLEventTracking.Disabled);
|
using var workbook = new XLWorkbook(ecxelTemplateStream, XLEventTracking.Disabled);
|
||||||
AddOperationsToWorkbook(workbook, operations);
|
AddOperationsToWorkbook(workbook, operations);
|
||||||
|
|
||||||
MemoryStream memoryStream = new MemoryStream();
|
MemoryStream memoryStream = new MemoryStream();
|
||||||
workbook.SaveAs(memoryStream);
|
workbook.SaveAs(memoryStream, new SaveOptions { });
|
||||||
memoryStream.Seek(0, SeekOrigin.Begin);
|
memoryStream.Seek(0, SeekOrigin.Begin);
|
||||||
return memoryStream;
|
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())
|
if (parseErrors.Any())
|
||||||
throw new FileFormatException(string.Join("\r\n", parseErrors));
|
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;
|
return operations;
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Binary file not shown.
@ -179,16 +179,15 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
/// Импортирует операции из excel (xlsx) файла
|
/// Импортирует операции из excel (xlsx) файла
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell">id скважины</param>
|
/// <param name="idWell">id скважины</param>
|
||||||
/// <param name="files">Коллекция файлов - 1 файл xlsx</param>
|
/// <param name="files">Коллекция из одного файла xlsx</param>
|
||||||
/// <param name="deleteWellOperationsBeforeImport">Удалить операции перед импортом, если фал валидный</param>
|
/// <param name="options">Удалить операции перед импортом = 1, если фал валидный</param>
|
||||||
/// <param name="token"> Токен отмены задачи </param>
|
/// <param name="token"> Токен отмены задачи </param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
[Route("import")]
|
[Route("import/{options}")]
|
||||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
public async Task<IActionResult> ImportAsync(int idWell,
|
||||||
public async Task<IActionResult> ImportAsync(int idWell,
|
|
||||||
[FromForm] IFormFileCollection files,
|
[FromForm] IFormFileCollection files,
|
||||||
bool deleteWellOperationsBeforeImport = false,
|
int options = 0,
|
||||||
CancellationToken token = default)
|
CancellationToken token = default)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
@ -205,13 +204,13 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
return BadRequest("нет файла");
|
return BadRequest("нет файла");
|
||||||
|
|
||||||
var file = files[0];
|
var file = files[0];
|
||||||
if(Path.GetExtension( file.FileName).ToLower() != "*.xlsx")
|
if(Path.GetExtension( file.FileName).ToLower() != ".xlsx")
|
||||||
return BadRequest("Требуется xlsx файл.");
|
return BadRequest("Требуется xlsx файл.");
|
||||||
using Stream stream = file.OpenReadStream();
|
using Stream stream = file.OpenReadStream();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
wellOperationImportService.Import(idWell, stream, deleteWellOperationsBeforeImport);
|
wellOperationImportService.Import(idWell, stream, (options & 1) > 0);
|
||||||
}
|
}
|
||||||
catch(FileFormatException ex)
|
catch(FileFormatException ex)
|
||||||
{
|
{
|
||||||
@ -222,7 +221,7 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Возвращает файл с диска на сервере
|
/// Создает excel файл с операциями по скважине
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="idWell">id скважины</param>
|
/// <param name="idWell">id скважины</param>
|
||||||
/// <param name="token"> Токен отмены задачи </param>
|
/// <param name="token"> Токен отмены задачи </param>
|
||||||
@ -246,6 +245,22 @@ namespace AsbCloudWebApi.Controllers
|
|||||||
return File(stream, "application/octet-stream", fileName);
|
return File(stream, "application/octet-stream", fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Возвращает шаблон файла импорта
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="token"> Токен отмены задачи </param>
|
||||||
|
/// <returns>Запрашиваемый файл</returns>
|
||||||
|
[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<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token = default)
|
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
int? idCompany = User.GetCompanyId();
|
int? idCompany = User.GetCompanyId();
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
{
|
{
|
||||||
"files": {
|
"files": {
|
||||||
"main.css": "/static/css/main.1a531ce4.chunk.css",
|
"main.css": "/static/css/main.e92a8ff6.chunk.css",
|
||||||
"main.js": "/static/js/main.d3cf7fb0.chunk.js",
|
"main.js": "/static/js/main.edfb453f.chunk.js",
|
||||||
"main.js.map": "/static/js/main.d3cf7fb0.chunk.js.map",
|
"main.js.map": "/static/js/main.edfb453f.chunk.js.map",
|
||||||
"runtime-main.js": "/static/js/runtime-main.b402d8a8.js",
|
"runtime-main.js": "/static/js/runtime-main.9eaada4e.js",
|
||||||
"runtime-main.js.map": "/static/js/runtime-main.b402d8a8.js.map",
|
"runtime-main.js.map": "/static/js/runtime-main.9eaada4e.js.map",
|
||||||
"static/js/2.f3289dc7.chunk.js": "/static/js/2.f3289dc7.chunk.js",
|
"static/js/2.d92842c3.chunk.js": "/static/js/2.d92842c3.chunk.js",
|
||||||
"static/js/2.f3289dc7.chunk.js.map": "/static/js/2.f3289dc7.chunk.js.map",
|
"static/js/2.d92842c3.chunk.js.map": "/static/js/2.d92842c3.chunk.js.map",
|
||||||
"static/js/3.a064d157.chunk.js": "/static/js/3.a064d157.chunk.js",
|
"static/js/3.5f51fb69.chunk.js": "/static/js/3.5f51fb69.chunk.js",
|
||||||
"static/js/3.a064d157.chunk.js.map": "/static/js/3.a064d157.chunk.js.map",
|
"static/js/3.5f51fb69.chunk.js.map": "/static/js/3.5f51fb69.chunk.js.map",
|
||||||
"index.html": "/index.html",
|
"index.html": "/index.html",
|
||||||
"static/css/main.1a531ce4.chunk.css.map": "/static/css/main.1a531ce4.chunk.css.map",
|
"static/css/main.e92a8ff6.chunk.css.map": "/static/css/main.e92a8ff6.chunk.css.map",
|
||||||
"static/js/2.f3289dc7.chunk.js.LICENSE.txt": "/static/js/2.f3289dc7.chunk.js.LICENSE.txt",
|
"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"
|
"static/media/pointer.e8df778c.svg": "/static/media/pointer.e8df778c.svg"
|
||||||
},
|
},
|
||||||
"entrypoints": [
|
"entrypoints": [
|
||||||
"static/js/runtime-main.b402d8a8.js",
|
"static/js/runtime-main.9eaada4e.js",
|
||||||
"static/js/2.f3289dc7.chunk.js",
|
"static/js/2.d92842c3.chunk.js",
|
||||||
"static/css/main.1a531ce4.chunk.css",
|
"static/css/main.e92a8ff6.chunk.css",
|
||||||
"static/js/main.d3cf7fb0.chunk.js"
|
"static/js/main.edfb453f.chunk.js"
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -1 +1 @@
|
|||||||
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="manifest" href="/manifest.json"/><title>АСБ Vision</title><link href="/static/css/main.1a531ce4.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function r(r){for(var n,a,i=r[0],c=r[1],l=r[2],s=0,p=[];s<i.length;s++)a=i[s],Object.prototype.hasOwnProperty.call(o,a)&&o[a]&&p.push(o[a][0]),o[a]=0;for(n in c)Object.prototype.hasOwnProperty.call(c,n)&&(e[n]=c[n]);for(f&&f(r);p.length;)p.shift()();return u.push.apply(u,l||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,i=1;i<t.length;i++){var c=t[i];0!==o[c]&&(n=!1)}n&&(u.splice(r--,1),e=a(a.s=t[0]))}return e}var n={},o={1:0},u=[];function a(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,a),t.l=!0,t.exports}a.e=function(e){var r=[],t=o[e];if(0!==t)if(t)r.push(t[2]);else{var n=new Promise((function(r,n){t=o[e]=[r,n]}));r.push(t[2]=n);var u,i=document.createElement("script");i.charset="utf-8",i.timeout=120,a.nc&&i.setAttribute("nonce",a.nc),i.src=function(e){return a.p+"static/js/"+({}[e]||e)+"."+{3:"a064d157"}[e]+".chunk.js"}(e);var c=new Error;u=function(r){i.onerror=i.onload=null,clearTimeout(l);var t=o[e];if(0!==t){if(t){var n=r&&("load"===r.type?"missing":r.type),u=r&&r.target&&r.target.src;c.message="Loading chunk "+e+" failed.\n("+n+": "+u+")",c.name="ChunkLoadError",c.type=n,c.request=u,t[1](c)}o[e]=void 0}};var l=setTimeout((function(){u({type:"timeout",target:i})}),12e4);i.onerror=i.onload=u,document.head.appendChild(i)}return Promise.all(r)},a.m=e,a.c=n,a.d=function(e,r,t){a.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.t=function(e,r){if(1&r&&(e=a(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(a.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)a.d(t,n,function(r){return e[r]}.bind(null,n));return t},a.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(r,"a",r),r},a.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},a.p="/",a.oe=function(e){throw console.error(e),e};var i=this.webpackJsonpasb_cloud_front_react=this.webpackJsonpasb_cloud_front_react||[],c=i.push.bind(i);i.push=r,i=i.slice();for(var l=0;l<i.length;l++)r(i[l]);var f=c;t()}([])</script><script src="/static/js/2.f3289dc7.chunk.js"></script><script src="/static/js/main.d3cf7fb0.chunk.js"></script></body></html>
|
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="manifest" href="/manifest.json"/><title>АСБ Vision</title><link href="/static/css/main.e92a8ff6.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function r(r){for(var n,a,i=r[0],c=r[1],l=r[2],s=0,p=[];s<i.length;s++)a=i[s],Object.prototype.hasOwnProperty.call(o,a)&&o[a]&&p.push(o[a][0]),o[a]=0;for(n in c)Object.prototype.hasOwnProperty.call(c,n)&&(e[n]=c[n]);for(f&&f(r);p.length;)p.shift()();return u.push.apply(u,l||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,i=1;i<t.length;i++){var c=t[i];0!==o[c]&&(n=!1)}n&&(u.splice(r--,1),e=a(a.s=t[0]))}return e}var n={},o={1:0},u=[];function a(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,a),t.l=!0,t.exports}a.e=function(e){var r=[],t=o[e];if(0!==t)if(t)r.push(t[2]);else{var n=new Promise((function(r,n){t=o[e]=[r,n]}));r.push(t[2]=n);var u,i=document.createElement("script");i.charset="utf-8",i.timeout=120,a.nc&&i.setAttribute("nonce",a.nc),i.src=function(e){return a.p+"static/js/"+({}[e]||e)+"."+{3:"5f51fb69"}[e]+".chunk.js"}(e);var c=new Error;u=function(r){i.onerror=i.onload=null,clearTimeout(l);var t=o[e];if(0!==t){if(t){var n=r&&("load"===r.type?"missing":r.type),u=r&&r.target&&r.target.src;c.message="Loading chunk "+e+" failed.\n("+n+": "+u+")",c.name="ChunkLoadError",c.type=n,c.request=u,t[1](c)}o[e]=void 0}};var l=setTimeout((function(){u({type:"timeout",target:i})}),12e4);i.onerror=i.onload=u,document.head.appendChild(i)}return Promise.all(r)},a.m=e,a.c=n,a.d=function(e,r,t){a.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.t=function(e,r){if(1&r&&(e=a(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(a.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)a.d(t,n,function(r){return e[r]}.bind(null,n));return t},a.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(r,"a",r),r},a.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},a.p="/",a.oe=function(e){throw console.error(e),e};var i=this.webpackJsonpasb_cloud_front_react=this.webpackJsonpasb_cloud_front_react||[],c=i.push.bind(i);i.push=r,i=i.slice();for(var l=0;l<i.length;l++)r(i[l]);var f=c;t()}([])</script><script src="/static/js/2.d92842c3.chunk.js"></script><script src="/static/js/main.edfb453f.chunk.js"></script></body></html>
|
Loading…
Reference in New Issue
Block a user