导入功能测试完善
This commit is contained in:
@@ -34,32 +34,39 @@ namespace Tnb.WarehouseMgr
|
||||
private async Task<dynamic> DataImport(VisualDevImportDataInput input)
|
||||
{
|
||||
int row = 0;
|
||||
var errorlist = new List<Dictionary<string, object>>();
|
||||
VisualDevImportDataOutput result = new VisualDevImportDataOutput();
|
||||
try
|
||||
{
|
||||
List<Dictionary<string, object>> dics = input.list;
|
||||
List<WmsPointH> points = new List<WmsPointH>();
|
||||
WmsPointH pt = new WmsPointH();
|
||||
List<string> aCodes = new List<string>();
|
||||
List<string> lCodes = new List<string>();
|
||||
//遍历字典,找出需要查询数据库拿的相关字段
|
||||
foreach (var d in dics)
|
||||
{
|
||||
var pCode = d["point_code"].ToString() ?? string.Empty;
|
||||
var pName = d["point_name"].ToString() ?? string.Empty;
|
||||
var aCode = d["area_code"].ToString() ?? string.Empty;
|
||||
var floor = d["floor"].ToString() ?? string.Empty;
|
||||
d.ContainsKey("location_code");
|
||||
var pCode = d["point_code"]?.ToString() ?? string.Empty;
|
||||
var pName = d["point_name"]?.ToString() ?? string.Empty;
|
||||
var aCode = d["area_code"]?.ToString() ?? string.Empty;
|
||||
var lCode = d["location_code"]?.ToString() ?? string.Empty;
|
||||
var floor = d["floor"]?.ToString() ?? string.Empty;
|
||||
if (pCode == string.Empty) throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}个数据点位编号不可为空", 500);
|
||||
if (pName == string.Empty) throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}个数据点位名称不可为空", 500);
|
||||
if (floor == string.Empty) throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}个数据楼层不可为空", 500);
|
||||
aCodes.Add(aCode);
|
||||
lCodes.Add(lCode);
|
||||
d["create_time"] = DateTime.Now;
|
||||
d.Remove("modify_time");
|
||||
pt = d.Adapt<WmsPointH>();
|
||||
points.Add(pt);
|
||||
}
|
||||
var areas = await _db.Queryable<WmsAreaH>().Where(it => aCodes.Contains(it.code)).ToDictionaryAsync(x => x.code, x => x.id);
|
||||
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 =>
|
||||
{
|
||||
if (!areas.Keys.Contains(x.area_code)) throw new AppFriendlyException($"第{points.IndexOf(x) + 1}个数据的管理区编号有误", 500);
|
||||
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;
|
||||
@@ -67,7 +74,8 @@ namespace Tnb.WarehouseMgr
|
||||
x.point_x = 0;
|
||||
x.point_y = 0;
|
||||
x.point_z = 0;
|
||||
x.area_id = areas[x.area_code].ToString() ?? throw new AppFriendlyException($"第{points.IndexOf(x) + 1}个数据的管理区编号编号有误", 500);
|
||||
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;
|
||||
@@ -78,7 +86,14 @@ namespace Tnb.WarehouseMgr
|
||||
{
|
||||
throw Oops.Bah(ex.Message);
|
||||
}
|
||||
return row > 0;
|
||||
result = new VisualDevImportDataOutput()
|
||||
{
|
||||
snum = row,
|
||||
fnum = 0,
|
||||
failResult = errorlist,
|
||||
resultType = errorlist.Count < 1 ? 0 : 1
|
||||
};
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user