导入功能修改

This commit is contained in:
FanLian
2023-09-11 11:26:43 +08:00
parent 913b95eb4c
commit 7d45a0910a
3 changed files with 98 additions and 63 deletions

View File

@@ -10,7 +10,11 @@ using JNPF.FriendlyException;
using JNPF.VisualDev;
using JNPF.VisualDev.Entitys.Dto.VisualDev;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using NPOI.HSSF.UserModel;
using NPOI.SS.Formula;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using SqlSugar;
using Tnb.BasicData.Entities;
using Tnb.WarehouseMgr.Entities;
@@ -39,6 +43,7 @@ namespace Tnb.WarehouseMgr
VisualDevImportDataOutput result = new VisualDevImportDataOutput();
try
{
List<Dictionary<string, object>> dics = input.list;
List<WmsPointH> points = new List<WmsPointH>();
WmsPointH pt = new WmsPointH();
@@ -47,6 +52,10 @@ namespace Tnb.WarehouseMgr
//遍历字典,找出需要查询数据库拿的相关字段
foreach (var d in dics)
{
if (d.Select(x => x.Value.ToString()).ToList().Find(v => v != "" && v != string.Empty && v != null) == null)
{
continue;
}
d.ContainsKey("location_code");
var pCode = d["point_code"]?.ToString() ?? string.Empty;
var pName = d["point_name"]?.ToString() ?? string.Empty;
@@ -63,39 +72,41 @@ namespace Tnb.WarehouseMgr
pt = d.Adapt<WmsPointH>();
points.Add(pt);
}
var aDic = await _db.Queryable<WmsAreaH>().Where(it => aCodes.Contains(it.code)).ToDictionaryAsync(x => x.code, x => x.id);
var lDic = await _db.Queryable<BasLocation>().Where(it => lCodes.Contains(it.location_code)).ToDictionaryAsync(x => x.location_code, x => x.id);
points.ForEach(x =>
var aDic = await _db.Queryable<WmsAreaH>().Where(it => aCodes.FindAll(x => x.ToString().IsNotEmptyOrNull() && x.ToString() != "").Contains(it.code)).ToDictionaryAsync(x => x.code, x => x.id);
var lDic = await _db.Queryable<BasLocation>().Where(it => lCodes.FindAll(x => x.ToString().IsNotEmptyOrNull() && x.ToString() != "").Contains(it.location_code)).ToDictionaryAsync(x => x.location_code, x => x.id);
var orgId = _userManager.User.OrganizeId;
var userId = _userManager.UserId;
foreach (var p in points)
{
if (!aDic.ContainsKey(x.area_code)) throw new AppFriendlyException($"第{points.IndexOf(x) + 1}个数据的管理区编号有误", 500);
x.id = SnowflakeIdHelper.NextId();
x.org_id = _userManager.User.OrganizeId;
x.is_lock = 0;
x.status = 1;
x.point_x = 0;
x.point_y = 0;
x.point_z = 0;
x.location_id = x.location_code != null ? lDic[x.location_code]?.ToString() : null;
x.area_id = aDic[x.area_code]?.ToString() ?? throw new AppFriendlyException($"第{points.IndexOf(x) + 1}个数据的管理区编号编号有误", 500);
x.create_id = _userManager.UserId;
x.modify_id = null;
x.modify_time = null;
});
if (!aDic.ContainsKey(p.area_code)) throw new AppFriendlyException($"第{points.IndexOf(p) + 1}个数据的管理区编号有误", 500);
p.id = SnowflakeIdHelper.NextId();
p.org_id = orgId;
p.is_lock = 0;
p.status = 1;
p.point_x = 0;
p.point_y = 0;
p.point_z = 0;
p.location_id = p.location_code != null && p.location_code != string.Empty ? lDic[p.location_code]?.ToString() : null;
p.area_id = aDic[p.area_code]?.ToString() ?? throw new AppFriendlyException($"第{points.IndexOf(p) + 1}个数据的管理区编号编号有误", 500);
p.create_id = userId;
p.modify_id = null;
p.modify_time = null;
}
if (points.Count > 1000)
{
await _db.Fastest<WmsPointH>().BulkCopyAsync(points);
row = await _db.Fastest<WmsPointH>().BulkCopyAsync(points);
}
else if (points.Count > 400)
{
_db.Utilities.PageEach(points, 100, async pageList => {
await _db.Insertable(pageList).ExecuteCommandAsync();
_db.Utilities.PageEach(points, 100, async pageList =>
{
row = await _db.Insertable(pageList).ExecuteCommandAsync();
});
}
else
{
row = await _db.Insertable(points).ExecuteCommandAsync();
}
row = await _db.Insertable(points).ExecuteCommandAsync();
}
catch (Exception ex)
{
@@ -110,5 +121,6 @@ namespace Tnb.WarehouseMgr
};
return result;
}
}
}