diff --git a/PerMgr/Tnb.PerMgr.Interfaces/IPerProcessStandardsService.cs b/PerMgr/Tnb.PerMgr.Interfaces/IPerProcessStandardsService.cs
index aca8bcf1..c3208c25 100644
--- a/PerMgr/Tnb.PerMgr.Interfaces/IPerProcessStandardsService.cs
+++ b/PerMgr/Tnb.PerMgr.Interfaces/IPerProcessStandardsService.cs
@@ -16,6 +16,6 @@ namespace Tnb.PerMgr.Interfaces
/// 导入
///
///
- public Task Import(string id,ChunkModel input);
+ public Task> Import(string id,ChunkModel input);
}
}
\ No newline at end of file
diff --git a/PerMgr/Tnb.PerMgr/PerProcessStandardsService.cs b/PerMgr/Tnb.PerMgr/PerProcessStandardsService.cs
index 43e5d881..d92d02c0 100644
--- a/PerMgr/Tnb.PerMgr/PerProcessStandardsService.cs
+++ b/PerMgr/Tnb.PerMgr/PerProcessStandardsService.cs
@@ -1,6 +1,8 @@
using System.Data;
using JNPF;
+using JNPF.Common.Configuration;
using JNPF.Common.Core.Manager;
+using JNPF.Common.Core.Manager.Files;
using JNPF.Common.Enums;
using JNPF.Common.Helper;
using JNPF.Common.Models;
@@ -8,6 +10,7 @@ using JNPF.Common.Security;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.FriendlyException;
+using JNPF.Systems.Common;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
@@ -31,11 +34,18 @@ namespace Tnb.PerMgr
{
private readonly ISqlSugarRepository _repository;
private readonly IUserManager _userManager;
+ private readonly FileManager _fileManager;
+ private readonly FileService _fileService;
- public PerProcessStandardsService(ISqlSugarRepository repository, IUserManager userManager)
+ public PerProcessStandardsService(ISqlSugarRepository repository,
+ FileService fileService,
+ FileManager fileManager,
+ IUserManager userManager)
{
_userManager = userManager;
_repository = repository;
+ _fileManager = fileManager;
+ _fileService = fileService;
}
[AllowAnonymous]
@@ -95,15 +105,16 @@ namespace Tnb.PerMgr
}
[HttpPost]
- public async Task Import([FromForm]string id, [FromForm]ChunkModel input)
+ public async Task> Import([FromForm]string id, [FromForm]ChunkModel input)
{
int rowIndex = 1;
bool flag = false;
+ IWorkbook workbook = null;
try
{
using (Stream stream = input.file.OpenReadStream())
{
- IWorkbook workbook = null;
+
// 2007版本
if (input.fileName.IndexOf(".xlsx") > 0)
workbook = new XSSFWorkbook(stream);
@@ -134,6 +145,7 @@ namespace Tnb.PerMgr
ICell cell2 = row.GetCell(2);
PerProcessStandardsD item = new PerProcessStandardsD();
+ item.process_standards_id = id;
PerProcessParamType perProcessParamType = perProcessParamTypes.FirstOrDefault(x => x.name == cell0.StringCellValue);
if (perProcessParamType != null)
{
@@ -142,7 +154,7 @@ namespace Tnb.PerMgr
else
{
ICell errorCell = row.GetCell(errorColumnIndex) ?? row.CreateCell(errorColumnIndex);
- errorCell.SetCellValue("无该工艺参数类型");
+ errorCell.SetCellValue(",无该工艺参数类型");
errorCell.CellStyle = style;
flag = true;
}
@@ -170,6 +182,12 @@ namespace Tnb.PerMgr
{
list.Add(item);
}
+
+
+ if (row.GetCell(errorColumnIndex) != null)
+ {
+ row.GetCell(errorColumnIndex).SetCellValue(row.GetCell(errorColumnIndex).StringCellValue.Substring(1));
+ }
}
foreach (var item in list)
@@ -182,8 +200,6 @@ namespace Tnb.PerMgr
{
if (oldData.value != item.value)
{
- await _repository.AsSugarClient().Updateable()
- .SetColumns(x => x.value == item.value).ExecuteCommandAsync();
PerProcessStandardsH perProcessStandardsH = await _repository.AsSugarClient().Queryable().SingleAsync(x => x.id == oldData.process_standards_id);
PerProcessParam processParam = await _repository.AsSugarClient().Queryable().SingleAsync(x => x.id == oldData.process_param_id);
@@ -212,28 +228,43 @@ namespace Tnb.PerMgr
}
}
-
if (flag)
{
MemoryStream ms = new MemoryStream();
-
+
workbook.Write(ms);
MemoryStream ms2 = new MemoryStream(ms.ToArray());
ms2.Position = 0;
- FileStreamResult fileStreamResult = new FileStreamResult(ms2, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") { FileDownloadName = "导入报错说明.xlsx" };
- return fileStreamResult;
+ // FileStreamResult fileStreamResult = new FileStreamResult(ms2, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") { FileDownloadName = "导入报错说明.xlsx" };
+ // return fileStreamResult;
+ string fileName = $"工艺标准导入报错{DateTime.Now.Ticks}.xlsx";
+ await _fileManager.UploadFileByType(ms2, FileVariable.TemporaryFilePath, fileName);
+ return new Dictionary()
+ {
+ ["isSuccess"] = "false",
+ ["msg"] = "部分数据导入失败",
+ ["fileName"] = fileName,
+ };
}
else
{
- return new JsonResult("导入成功");
+ return new Dictionary()
+ {
+ ["isSuccess"] = "true",
+ ["msg"] = "导入成功",
+ };
}
+
}
}
catch (Exception e)
- {
+ {
+ Console.WriteLine(e.Message);
+ JNPF.Logging.Log.Error("工艺标准导入失败", e);
throw Oops.Bah("导入失败");
}
+
}
diff --git a/PerMgr/Tnb.PerMgr/Tnb.PerMgr.csproj b/PerMgr/Tnb.PerMgr/Tnb.PerMgr.csproj
index ddd2d646..70b75e15 100644
--- a/PerMgr/Tnb.PerMgr/Tnb.PerMgr.csproj
+++ b/PerMgr/Tnb.PerMgr/Tnb.PerMgr.csproj
@@ -8,6 +8,7 @@
+