BaseWarehouse类,新增 ImportExcelToMemory,DataImport函数

This commit is contained in:
alex
2023-08-07 16:30:07 +08:00
parent 6602a4d7d2
commit af9265ea20
3 changed files with 129 additions and 7 deletions

View File

@@ -1,9 +1,11 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using JNPF.Common.Configuration;
using JNPF.Common.Contracts;
using JNPF.Common.Core.Manager;
using JNPF.Common.Extension;
using JNPF.Common.Helper;
@@ -45,6 +47,8 @@ namespace Tnb.WarehouseMgr
int row = 0;
try
{
//例1 获取所有表
List<Dictionary<string, string>> dics = WmsImport(file);
List<WmsCarryH> carrys = new List<WmsCarryH>();
var carryStdDic = await _db.Queryable<WmsCarrystd>().ToDictionaryAsync(x => x.carrystd_code, x => x.id);
@@ -83,17 +87,38 @@ namespace Tnb.WarehouseMgr
return false;
throw;
}
return row>0;
return row > 0;
}
public async Task DataImport<T>(IFormFile file) where T : BaseEntity<string>, new()
{
var nonBeNullColumnList = new List<string>();
var entityInfo = _db.EntityMaintenance.GetEntityInfo<T>();
foreach (var column in entityInfo.Columns)
{
if (!column.IsEmpty())
{
nonBeNullColumnList.Add(column.DbColumnName);
}
}
var importData = WmsImport(file);
var fillColumns = nonBeNullColumnList.Except(importData.Keys).ToList();
if (fillColumns?.Count > 0)
{
}
}
/// <summary>
/// WMS导入
/// </summary>
/// <returns></returns>
private static List<Dictionary<string, string>> WmsImport(IFormFile file)
private static Dictionary<string, string> WmsImport(IFormFile file)
{
int rowIndex = 1;
List<Dictionary<string, string>> dics = new List<Dictionary<string, string>>();
Dictionary<string, string> dic = new();
IWorkbook? workbook = null;
try
{
@@ -118,8 +143,6 @@ namespace Tnb.WarehouseMgr
font.Color = IndexedColors.Red.Index; // 将字体颜色设置为红色
style.SetFont(font);
var nameRow = sheet?.GetRow(0);
Dictionary<string, string> dic = new Dictionary<string, string>();
if (nameRow != null)
{
List<string> columns = new List<string>();
@@ -136,11 +159,11 @@ namespace Tnb.WarehouseMgr
ICell cell = row.GetCell(columns.IndexOf(col));
dic.Add(col, cell.StringCellValue);
}
dics.Add(dic);
}
}
}
}
}
}
catch (Exception)
@@ -149,7 +172,7 @@ namespace Tnb.WarehouseMgr
throw;
}
return dics;
return dic;
}
/// <summary>