导入功能优化不同数据量插入语句
This commit is contained in:
@@ -19,6 +19,7 @@ using System.Reflection.Emit;
|
||||
using JNPF.VisualDev.Entitys.Dto.VisualDev;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
using Spire.Pdf.Lists;
|
||||
using Aop.Api.Domain;
|
||||
|
||||
namespace Tnb.WarehouseMgr
|
||||
{
|
||||
@@ -50,7 +51,7 @@ namespace Tnb.WarehouseMgr
|
||||
List<string> cStdCodes = new List<string>();
|
||||
List<string> whCodes = new List<string>();
|
||||
List<string> rgCodes = new List<string>();
|
||||
|
||||
|
||||
//遍历字典,找出需要查询数据库拿的相关字段
|
||||
foreach (var d in dics)
|
||||
{
|
||||
@@ -58,7 +59,7 @@ namespace Tnb.WarehouseMgr
|
||||
if (LCode == string.Empty) throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}个数据库位编号不可为空", 500);
|
||||
var isType = d["is_type"]?.ToString() ?? string.Empty;
|
||||
if (isType == string.Empty) throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}个数据库位类型不可为空", 500);
|
||||
var floor = d["floor"]? .ToString() ?? string.Empty;
|
||||
var floor = d["floor"]?.ToString() ?? string.Empty;
|
||||
if (floor == string.Empty) throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}个数据楼层不可为空", 500);
|
||||
var layers = d["layers"]?.ToString() ?? string.Empty;
|
||||
var locLine = d["loc_line"]?.ToString() ?? string.Empty;
|
||||
@@ -81,7 +82,7 @@ namespace Tnb.WarehouseMgr
|
||||
var carryStdDic = await _db.Queryable<WmsCarrystd>().Where(it => cStdCodes.Contains(it.carrystd_code)).ToDictionaryAsync(x => x.carrystd_code, x => x.id);
|
||||
var whDic = await _db.Queryable<BasWarehouse>().Where(it => whCodes.Contains(it.whcode)).ToDictionaryAsync(x => x.whcode, x => x.id);
|
||||
var rgDic = await _db.Queryable<BasRegion>().Where(it => rgCodes.Contains(it.region_code)).ToDictionaryAsync(x => x.region_code, x => x.id);
|
||||
|
||||
|
||||
locs.ForEach(x =>
|
||||
{
|
||||
if (!carryStdDic.ContainsKey(x.carrystd_id)) throw new AppFriendlyException($"第{locs.IndexOf(x) + 1}个数据的载具规格有误", 500);
|
||||
@@ -100,7 +101,21 @@ namespace Tnb.WarehouseMgr
|
||||
x.is_mix = 1;
|
||||
x.is_use = "0";
|
||||
});
|
||||
row = await _db.Insertable(locs).ExecuteCommandAsync();
|
||||
if (locs.Count > 1000)
|
||||
{
|
||||
await _db.Fastest<BasLocation>().BulkCopyAsync(locs);
|
||||
}
|
||||
else if (locs.Count > 400)
|
||||
{
|
||||
_db.Utilities.PageEach(locs, 100, async pageList => {
|
||||
await _db.Insertable(pageList).ExecuteCommandAsync();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
row = await _db.Insertable(locs).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -10,6 +10,7 @@ using JNPF.FriendlyException;
|
||||
using JNPF.VisualDev;
|
||||
using JNPF.VisualDev.Entitys.Dto.VisualDev;
|
||||
using Mapster;
|
||||
using NPOI.SS.Formula;
|
||||
using SqlSugar;
|
||||
using Tnb.BasicData.Entities;
|
||||
using Tnb.WarehouseMgr.Entities;
|
||||
@@ -80,6 +81,20 @@ namespace Tnb.WarehouseMgr
|
||||
x.modify_id = null;
|
||||
x.modify_time = null;
|
||||
});
|
||||
if (points.Count > 1000)
|
||||
{
|
||||
await _db.Fastest<WmsPointH>().BulkCopyAsync(points);
|
||||
}
|
||||
else if (points.Count > 400)
|
||||
{
|
||||
_db.Utilities.PageEach(points, 100, async pageList => {
|
||||
await _db.Insertable(pageList).ExecuteCommandAsync();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
row = await _db.Insertable(points).ExecuteCommandAsync();
|
||||
}
|
||||
row = await _db.Insertable(points).ExecuteCommandAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -112,8 +112,21 @@ namespace Tnb.WarehouseMgr
|
||||
x.modify_time = null;
|
||||
});
|
||||
}
|
||||
row = await _db.Insertable(roads).ExecuteCommandAsync();
|
||||
|
||||
if (roads.Count > 1000)
|
||||
{
|
||||
await _db.Fastest<WmsRoad>().BulkCopyAsync(roads);
|
||||
}
|
||||
else if (roads.Count > 400)
|
||||
{
|
||||
_db.Utilities.PageEach(roads, 100, async pageList => {
|
||||
await _db.Insertable(pageList).ExecuteCommandAsync();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
row = await _db.Insertable(roads).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user