This commit is contained in:
FanLian
2023-08-07 16:58:51 +08:00
3 changed files with 129 additions and 7 deletions

View File

@@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DingTalk.Api.Request;
using JNPF.Common.Configuration;
using JNPF.Common.Contracts;
using JNPF.Common.Core.Manager;
using JNPF.Common.Extension;
using JNPF.Common.Helper;
@@ -68,7 +70,9 @@ namespace Tnb.WarehouseMgr
int row = 0;
try
{
List<Dictionary<string, string>> dics = WmsImportExcelToMemory(file);
//例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);
List<string> locCodes = new();
@@ -112,14 +116,35 @@ namespace Tnb.WarehouseMgr
return row > 0;
}
public async Task DataImport<T>(IFormFile file,Func<List<T>> getColumns) where T : BaseEntity<string>, new()
{
var nonBeNullColumnList = new List<string>();
var entityInfo = _db.EntityMaintenance.GetEntityInfo<T>();
foreach (var column in entityInfo.Columns)
{
if (!column.IsNullable)
{
nonBeNullColumnList.Add(column.DbColumnName);
}
}
var importData = WmsImport(file); //ImportExcelToMemory<T> where T:BaseEntity<string>,new()
var fillColumns = nonBeNullColumnList.Except(importData.Keys).ToList();
if (fillColumns?.Count > 0)
{
}
}
/// <summary>
/// WMS导入
/// </summary>
/// <returns></returns>
private static List<Dictionary<string, string>> WmsImportExcelToMemory(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
{
@@ -144,8 +169,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>();
@@ -162,11 +185,11 @@ namespace Tnb.WarehouseMgr
ICell cell = row.GetCell(columns.IndexOf(col));
dic.Add(col, cell.StringCellValue);
}
dics.Add(dic);
}
}
}
}
}
}
catch (Exception)
@@ -175,7 +198,7 @@ namespace Tnb.WarehouseMgr
throw;
}
return dics;
return dic;
}
/// <summary>