导入功能测试完善
This commit is contained in:
@@ -18,6 +18,7 @@ using JNPF.Logging;
|
||||
using System.Reflection.Emit;
|
||||
using JNPF.VisualDev.Entitys.Dto.VisualDev;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
using Spire.Pdf.Lists;
|
||||
|
||||
namespace Tnb.WarehouseMgr
|
||||
{
|
||||
@@ -39,55 +40,80 @@ 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<BasLocation> locs = new List<BasLocation>();
|
||||
BasLocation loc = new BasLocation();
|
||||
List<string> cStdCodes = new List<string>();
|
||||
List<string> whCodes = new List<string>();
|
||||
List<string> rgCodes = new List<string>();
|
||||
|
||||
//遍历字典,找出需要查询数据库拿的相关字段
|
||||
foreach (var d in dics)
|
||||
{
|
||||
var LCode = d["location_code"].ToString() ?? string.Empty;
|
||||
var LCode = d["location_code"]?.ToString() ?? string.Empty;
|
||||
if (LCode == string.Empty) throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}个数据库位编号不可为空", 500);
|
||||
var isType = d["is_type"].ToString() ?? string.Empty;
|
||||
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;
|
||||
var locColumn = d["loc_column"].ToString() ?? string.Empty;
|
||||
var layers = d["layers"]?.ToString() ?? string.Empty;
|
||||
var locLine = d["loc_line"]?.ToString() ?? string.Empty;
|
||||
var locColumn = d["loc_column"]?.ToString() ?? string.Empty;
|
||||
if (locLine == string.Empty || locColumn == string.Empty || layers == string.Empty) throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}个数据行列层不可为空", 500);
|
||||
var isSign = d["is_sign"].ToString() ?? string.Empty;
|
||||
if(isSign==string.Empty) throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}个数据自动签收不可为空", 500);
|
||||
var cStdCode = d["carrystd_id"].ToString() ?? string.Empty;
|
||||
var isSign = d["is_sign"]?.ToString() ?? string.Empty;
|
||||
if (isSign == string.Empty) throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}个数据自动签收不可为空", 500);
|
||||
var cStdCode = d["carrystd_id"]?.ToString() ?? string.Empty;
|
||||
var whCode = d["wh_id"]?.ToString() ?? string.Empty;
|
||||
var rgCode = d["region_id"]?.ToString() ?? string.Empty;
|
||||
cStdCodes.Add(cStdCode);
|
||||
whCodes.Add(whCode);
|
||||
rgCodes.Add(rgCode);
|
||||
d["create_time"] = DateTime.Now;
|
||||
d.Remove("modify_time");
|
||||
loc = d.Adapt<BasLocation>();
|
||||
locs.Add(loc);
|
||||
}
|
||||
|
||||
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.Keys.Contains(x.carrystd_id)) throw new AppFriendlyException($"第{locs.IndexOf(x) + 1}个数据的载具规格有误", 500);
|
||||
if (!carryStdDic.ContainsKey(x.carrystd_id)) throw new AppFriendlyException($"第{locs.IndexOf(x) + 1}个数据的载具规格有误", 500);
|
||||
if (!whDic.ContainsKey(x.wh_id)) throw new AppFriendlyException($"第{locs.IndexOf(x) + 1}个数据的仓库有误", 500);
|
||||
if (!rgDic.ContainsKey(x.region_id)) throw new AppFriendlyException($"第{locs.IndexOf(x) + 1}个数据的区域名称有误", 500);
|
||||
x.id = SnowflakeIdHelper.NextId();
|
||||
x.org_id = _userManager.User.OrganizeId;
|
||||
x.location_name = x.location_code;
|
||||
x.is_lock = 0;
|
||||
x.carrystd_id = carryStdDic[x.carrystd_id].ToString() ?? throw new AppFriendlyException($"第{locs.IndexOf(x) + 1}个数据的载具规格有误", 500);
|
||||
x.carrystd_id = carryStdDic[x.carrystd_id]?.ToString()!;
|
||||
x.wh_id = whDic[x.wh_id]?.ToString()!;
|
||||
x.region_id = rgDic[x.region_id]?.ToString();
|
||||
x.create_id = _userManager.UserId;
|
||||
x.modify_id = null;
|
||||
x.modify_time = null;
|
||||
x.is_mix = 1;
|
||||
x.is_use = "0";
|
||||
});
|
||||
|
||||
row = await _db.Insertable(locs).ExecuteCommandAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,6 +69,8 @@ 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;
|
||||
@@ -79,9 +81,9 @@ namespace Tnb.WarehouseMgr
|
||||
//遍历字典,找出需要查询数据库拿的相关字段
|
||||
foreach (var d in dics)
|
||||
{
|
||||
var sCode = d["startpoint_code"].ToString() ?? string.Empty;
|
||||
var eCode = d["endpoint_code"].ToString() ?? string.Empty;
|
||||
var dis = d["distance"].ToString() ?? string.Empty;
|
||||
var sCode = d["startpoint_code"]?.ToString() ?? string.Empty;
|
||||
var eCode = d["endpoint_code"]?.ToString() ?? string.Empty;
|
||||
var dis = d["distance"]?.ToString() ?? string.Empty;
|
||||
if(sCode == eCode) throw new AppFriendlyException("起始点位不能等于终止点位", 500);
|
||||
if (dis.IsEmpty())
|
||||
throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}个数据距离不可为空", 500);
|
||||
@@ -97,12 +99,12 @@ namespace Tnb.WarehouseMgr
|
||||
{
|
||||
roads.ForEach(x =>
|
||||
{
|
||||
if (!points.Keys.Contains(x.startpoint_code) ) throw new AppFriendlyException($"第{roads.IndexOf(x) + 1}个数据的起始点位编号有误", 500);
|
||||
if (!points.Keys.Contains(x.endpoint_code)) throw new AppFriendlyException($"第{roads.IndexOf(x) + 1}个数据的终止点位编号有误", 500);
|
||||
if (!points.ContainsKey(x.startpoint_code)) throw new AppFriendlyException($"第{roads.IndexOf(x) + 1}个数据的起始点位编号有误", 500);
|
||||
if (!points.ContainsKey(x.endpoint_code)) throw new AppFriendlyException($"第{roads.IndexOf(x) + 1}个数据的终止点位编号有误", 500);
|
||||
x.id = SnowflakeIdHelper.NextId();
|
||||
x.org_id = _userManager.User.OrganizeId;
|
||||
x.startpoint_id = points[x.startpoint_code].ToString() ?? throw new AppFriendlyException($"第{roads.IndexOf(x) + 1}个数据的起始点位编号有误", 500);
|
||||
x.endpoint_id = points[x.endpoint_code].ToString() ?? throw new AppFriendlyException($"第{roads.IndexOf(x) + 1}个数据的终止点位编号有误", 500);
|
||||
x.startpoint_id = points[x.startpoint_code]?.ToString() ?? throw new AppFriendlyException($"第{roads.IndexOf(x) + 1}个数据的起始点位编号有误", 500);
|
||||
x.endpoint_id = points[x.endpoint_code]?.ToString() ?? throw new AppFriendlyException($"第{roads.IndexOf(x) + 1}个数据的终止点位编号有误", 500);
|
||||
x.road_code = $"{x.startpoint_code}-{x.endpoint_code}";
|
||||
x.status = 1;
|
||||
x.create_id = _userManager.UserId;
|
||||
@@ -111,12 +113,20 @@ namespace Tnb.WarehouseMgr
|
||||
});
|
||||
}
|
||||
row = await _db.Insertable(roads).ExecuteCommandAsync();
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
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