导入功能修改
This commit is contained in:
@@ -20,6 +20,10 @@ using JNPF.VisualDev.Entitys.Dto.VisualDev;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
using Spire.Pdf.Lists;
|
||||
using Aop.Api.Domain;
|
||||
using NPOI.SS.UserModel;
|
||||
using NPOI.XSSF.UserModel;
|
||||
using NPOI.HSSF.UserModel;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Tnb.WarehouseMgr
|
||||
{
|
||||
@@ -55,6 +59,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;
|
||||
}
|
||||
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;
|
||||
@@ -79,36 +87,38 @@ namespace Tnb.WarehouseMgr
|
||||
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 =>
|
||||
var carryStdDic = await _db.Queryable<WmsCarrystd>().Where(it => cStdCodes.FindAll(x => x.ToString().IsNotEmptyOrNull() && x.ToString() != "").Contains(it.carrystd_code)).ToDictionaryAsync(x => x.carrystd_code, x => x.id);
|
||||
var whDic = await _db.Queryable<BasWarehouse>().Where(it => whCodes.FindAll(x => x.ToString().IsNotEmptyOrNull() && x.ToString() != "").Contains(it.whcode)).ToDictionaryAsync(x => x.whcode, x => x.id);
|
||||
var rgDic = await _db.Queryable<BasRegion>().Where(it => rgCodes.FindAll(x => x.ToString().IsNotEmptyOrNull() && x.ToString() != "").Contains(it.region_code)).ToDictionaryAsync(x => x.region_code, x => x.id);
|
||||
var orgId = _userManager.User.OrganizeId;
|
||||
var userId = _userManager.UserId;
|
||||
foreach (var l in locs)
|
||||
{
|
||||
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()!;
|
||||
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";
|
||||
});
|
||||
if (!carryStdDic.ContainsKey(l.carrystd_id)) throw new AppFriendlyException($"第{locs.IndexOf(l) + 1}个数据的载具规格有误", 500);
|
||||
if (!whDic.ContainsKey(l.wh_id)) throw new AppFriendlyException($"第{locs.IndexOf(l) + 1}个数据的仓库有误", 500);
|
||||
if (!rgDic.ContainsKey(l.region_id)) throw new AppFriendlyException($"第{locs.IndexOf(l) + 1}个数据的区域名称有误", 500);
|
||||
l.id = SnowflakeIdHelper.NextId();
|
||||
l.org_id = orgId;
|
||||
l.location_name = l.location_code;
|
||||
l.is_lock = 0;
|
||||
l.carrystd_id = carryStdDic[l.carrystd_id]?.ToString()!;
|
||||
l.wh_id = whDic[l.wh_id]?.ToString()!;
|
||||
l.region_id = rgDic[l.region_id]?.ToString();
|
||||
l.create_id = userId;
|
||||
l.modify_id = null;
|
||||
l.modify_time = null;
|
||||
l.is_mix = 1;
|
||||
l.is_use = "0";
|
||||
}
|
||||
|
||||
if (locs.Count > 1000)
|
||||
{
|
||||
await _db.Fastest<BasLocation>().BulkCopyAsync(locs);
|
||||
row = await _db.Fastest<BasLocation>().BulkCopyAsync(locs);
|
||||
}
|
||||
else if (locs.Count > 400)
|
||||
{
|
||||
_db.Utilities.PageEach(locs, 100, async pageList => {
|
||||
await _db.Insertable(pageList).ExecuteCommandAsync();
|
||||
row = await _db.Insertable(pageList).ExecuteCommandAsync();
|
||||
});
|
||||
}
|
||||
else
|
||||
@@ -130,5 +140,6 @@ namespace Tnb.WarehouseMgr
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,10 @@ using JNPF.VisualDev.Interfaces;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NPOI.HSSF.UserModel;
|
||||
using NPOI.SS.Formula;
|
||||
using NPOI.SS.UserModel;
|
||||
using NPOI.XSSF.UserModel;
|
||||
using SqlSugar;
|
||||
using Tnb.WarehouseMgr.Entities;
|
||||
using Tnb.WarehouseMgr.Interfaces;
|
||||
@@ -81,10 +84,15 @@ 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;
|
||||
}
|
||||
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 (sCode == eCode)
|
||||
throw new AppFriendlyException("起始点位不能等于终止点位", 500);
|
||||
if (dis.IsEmpty())
|
||||
throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}个数据距离不可为空", 500);
|
||||
pointCodes.Add(sCode);
|
||||
@@ -94,32 +102,35 @@ namespace Tnb.WarehouseMgr
|
||||
road = d.Adapt<WmsRoad>();
|
||||
roads.Add(road);
|
||||
}
|
||||
var points = await _db.Queryable<WmsPointH>().Where(it => pointCodes.Contains(it.point_code)).ToDictionaryAsync(x => x.point_code, x => x.id);
|
||||
var points = await _db.Queryable<WmsPointH>().Where(it => pointCodes.FindAll(x => x.ToString().IsNotEmptyOrNull() && x.ToString() != "").Contains(it.point_code)).ToDictionaryAsync(x => x.point_code, x => x.id);
|
||||
if (!points.IsNullOrEmpty())
|
||||
{
|
||||
roads.ForEach(x =>
|
||||
var orgId = _userManager.User.OrganizeId;
|
||||
var userId = _userManager.UserId;
|
||||
foreach (var r in roads)
|
||||
{
|
||||
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.road_code = $"{x.startpoint_code}-{x.endpoint_code}";
|
||||
x.status = 1;
|
||||
x.create_id = _userManager.UserId;
|
||||
x.modify_id = null;
|
||||
x.modify_time = null;
|
||||
});
|
||||
if (!points.ContainsKey(r.startpoint_code)) throw new AppFriendlyException($"第{roads.IndexOf(r) + 1}个数据的起始点位编号有误", 500);
|
||||
if (!points.ContainsKey(r.endpoint_code)) throw new AppFriendlyException($"第{roads.IndexOf(r) + 1}个数据的终止点位编号有误", 500);
|
||||
r.id = SnowflakeIdHelper.NextId();
|
||||
r.org_id = orgId;
|
||||
r.startpoint_id = points[r.startpoint_code]?.ToString() ?? throw new AppFriendlyException($"第{roads.IndexOf(r) + 1}个数据的起始点位编号有误", 500);
|
||||
r.endpoint_id = points[r.endpoint_code]?.ToString() ?? throw new AppFriendlyException($"第{roads.IndexOf(r) + 1}个数据的终止点位编号有误", 500);
|
||||
r.road_code = $"{r.startpoint_code}-{r.endpoint_code}";
|
||||
r.status = 1;
|
||||
r.create_id = userId;
|
||||
r.modify_id = null;
|
||||
r.modify_time = null;
|
||||
}
|
||||
}
|
||||
if (roads.Count > 1000)
|
||||
{
|
||||
await _db.Fastest<WmsRoad>().BulkCopyAsync(roads);
|
||||
row = await _db.Fastest<WmsRoad>().BulkCopyAsync(roads);
|
||||
}
|
||||
else if (roads.Count > 400)
|
||||
{
|
||||
_db.Utilities.PageEach(roads, 100, async pageList => {
|
||||
await _db.Insertable(pageList).ExecuteCommandAsync();
|
||||
_db.Utilities.PageEach(roads, 100, async pageList =>
|
||||
{
|
||||
row = await _db.Insertable(pageList).ExecuteCommandAsync();
|
||||
});
|
||||
}
|
||||
else
|
||||
@@ -129,7 +140,7 @@ namespace Tnb.WarehouseMgr
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
{
|
||||
throw Oops.Bah(ex.Message);
|
||||
}
|
||||
result = new VisualDevImportDataOutput()
|
||||
@@ -141,5 +152,6 @@ namespace Tnb.WarehouseMgr
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user