修改导入功能

This commit is contained in:
FanLian
2023-08-10 11:13:55 +08:00
parent 12bd8e6de6
commit 8db0c10e59
4 changed files with 29 additions and 25 deletions

View File

@@ -61,6 +61,7 @@ namespace Tnb.WarehouseMgr
{
List<Dictionary<string, object>> dics = input.list;
List<WmsCarryH> carrys = new List<WmsCarryH>();
Dictionary<string, object>? locs = null;
List<string> locCodes = new();
List<string> cStdCodes = new();
WmsCarryH carryH = new WmsCarryH();
@@ -68,8 +69,7 @@ namespace Tnb.WarehouseMgr
foreach (var d in dics)
{
var cStdCode = d["carrystd_id"].ToString() ?? string.Empty;
//if (cStdCode == string.Empty) throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}个数据载具规格不可为空", 500);
locCodes.Add(d["location_code"]?.ToString() ?? string.Empty);
locCodes.Add(d["location_code"].ToString() ?? string.Empty);
cStdCodes.Add(cStdCode);
d["create_time"] = DateTime.Now;
d.Remove("modify_time");
@@ -77,18 +77,19 @@ namespace Tnb.WarehouseMgr
carrys.Add(carryH);
}
var carryStdDic = await _db.Queryable<WmsCarrystd>().Where(it => cStdCodes.Contains(it.carrystd_code)).ToDictionaryAsync(x => x.carrystd_code, x => x.id);
var locs = await _db.Queryable<BasLocation>().Where(it => locCodes.Contains(it.location_code)).ToDictionaryAsync(x => x.location_code, x => x.id);
if (locCodes?.Count > 0)
locs = await _db.Queryable<BasLocation>().Where(it => locCodes.Contains(it.location_code)).ToDictionaryAsync(x => x.location_code, x => x.id);
carrys.ForEach(x =>
{
if (!carryStdDic.Keys.Contains(x.carrystd_id)) throw new AppFriendlyException($"第{carrys.IndexOf(x) + 1}个数据的载具规格有误", 500);
if (!locs.Keys.Contains(x.location_code)) throw new AppFriendlyException($"第{carrys.IndexOf(x) + 1}个数据的库位编号有误", 500);
x.id = SnowflakeIdHelper.NextId();
x.org_id = _userManager.User.OrganizeId;
x.status = 1;
x.is_lock = 0;
x.carrystd_id = carryStdDic[x.carrystd_id].ToString() ?? throw new AppFriendlyException($"第{carrys.IndexOf(x) + 1}个数据的载具规格有误", 500);
x.carry_status = ((int)EnumCarryStatus.).ToString();
x.location_id = locs[x.location_code].ToString() ?? throw new AppFriendlyException($"第{carrys.IndexOf(x) + 1}个数据的库位编号有误", 500);
if (locs != null && x.location_code != null && x.location_code != string.Empty)
x.location_id = locs[x.location_code].ToString() ?? throw new AppFriendlyException($"第{carrys.IndexOf(x) + 1}个数据的库位编号有误", 500);
x.out_status = ((int)EnumOutStatus.).ToString();
x.is_check = 1;
x.create_id = _userManager.UserId;