工艺标准导入

This commit is contained in:
2023-06-09 11:04:05 +08:00
parent c619620da6
commit ac7646eecf
3 changed files with 45 additions and 13 deletions

View File

@@ -16,6 +16,6 @@ namespace Tnb.PerMgr.Interfaces
/// 导入 /// 导入
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public Task<IActionResult> Import(string id,ChunkModel input); public Task<Dictionary<string,string>> Import(string id,ChunkModel input);
} }
} }

View File

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

View File

@@ -8,6 +8,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\EquipMgr\Tnb.EquipMgr.Entities\Tnb.EquipMgr.Entities.csproj" /> <ProjectReference Include="..\..\EquipMgr\Tnb.EquipMgr.Entities\Tnb.EquipMgr.Entities.csproj" />
<ProjectReference Include="..\..\system\Tnb.Systems\Tnb.Systems.csproj" />
<ProjectReference Include="..\..\visualdev\Tnb.VisualDev.Engine\Tnb.VisualDev.Engine.csproj" /> <ProjectReference Include="..\..\visualdev\Tnb.VisualDev.Engine\Tnb.VisualDev.Engine.csproj" />
<ProjectReference Include="..\Tnb.PerMgr.Interfaces\Tnb.PerMgr.Interfaces.csproj" /> <ProjectReference Include="..\Tnb.PerMgr.Interfaces\Tnb.PerMgr.Interfaces.csproj" />
</ItemGroup> </ItemGroup>