165 lines
7.1 KiB
C#
165 lines
7.1 KiB
C#
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Extension;
|
|
using JNPF.Common.Security;
|
|
using JNPF.FriendlyException;
|
|
using JNPF.VisualDev;
|
|
using JNPF.VisualDev.Entitys.Dto.VisualDev;
|
|
using Mapster;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using SqlSugar;
|
|
using Tnb.BasicData.Entities;
|
|
using Tnb.WarehouseMgr.Entities;
|
|
|
|
namespace Tnb.WarehouseMgr
|
|
{
|
|
/// <summary>
|
|
/// 库位定义业务类
|
|
/// </summary>
|
|
[OverideVisualDev(ModuleConsts.MODULE_LOCATIONDEFINITION_ID)]
|
|
public class LocationDefinitionService : BaseWareHouseService
|
|
{
|
|
private readonly ISqlSugarClient _db;
|
|
private readonly IUserManager _userManager;
|
|
public LocationDefinitionService(ISqlSugarRepository<BasLocation> repository, IUserManager userManager)
|
|
{
|
|
_db = repository.AsSugarClient();
|
|
_userManager = userManager;
|
|
OverideFuncs.ImportDataAsync = DataImport;
|
|
}
|
|
|
|
private async Task<dynamic> DataImport(VisualDevImportDataInput input)
|
|
{
|
|
int row = 0;
|
|
List<Dictionary<string, object>> errorlist = new();
|
|
VisualDevImportDataOutput result = new();
|
|
try
|
|
{
|
|
List<Dictionary<string, object>> dics = input.list;
|
|
List<BasLocation> locs = new();
|
|
BasLocation loc = new();
|
|
List<string> cStdCodes = new();
|
|
List<string> whCodes = new();
|
|
List<string> rgCodes = new();
|
|
|
|
//遍历字典,找出需要查询数据库拿的相关字段
|
|
foreach (Dictionary<string, object> d in dics)
|
|
{
|
|
if (d.Select(x => x.Value.ToString()).ToList().Find(v => v != "" && v != string.Empty && v != null) == null)
|
|
{
|
|
continue;
|
|
}
|
|
string LCode = d["location_code"]?.ToString() ?? string.Empty;
|
|
if (LCode == string.Empty)
|
|
{
|
|
throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}个数据库位编号不可为空", 500);
|
|
}
|
|
|
|
string isType = d["is_type"]?.ToString() ?? string.Empty;
|
|
if (isType == string.Empty)
|
|
{
|
|
throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}个数据库位类型不可为空", 500);
|
|
}
|
|
|
|
string floor = d["floor"]?.ToString() ?? string.Empty;
|
|
if (floor == string.Empty)
|
|
{
|
|
throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}个数据楼层不可为空", 500);
|
|
}
|
|
|
|
string layers = d["layers"]?.ToString() ?? string.Empty;
|
|
string locLine = d["loc_line"]?.ToString() ?? string.Empty;
|
|
string 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);
|
|
}
|
|
|
|
string isSign = d["is_sign"]?.ToString() ?? string.Empty;
|
|
if (isSign == string.Empty)
|
|
{
|
|
throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}个数据自动签收不可为空", 500);
|
|
}
|
|
|
|
string cStdCode = d["carrystd_id"]?.ToString() ?? string.Empty;
|
|
string whCode = d["wh_id"]?.ToString() ?? string.Empty;
|
|
string 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);
|
|
}
|
|
|
|
Dictionary<string, object> 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);
|
|
Dictionary<string, object> 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);
|
|
Dictionary<string, object> 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);
|
|
string orgId = _userManager.User.OrganizeId;
|
|
string userId = _userManager.UserId;
|
|
foreach (BasLocation l in locs)
|
|
{
|
|
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 = JsonConvert.SerializeObject(new[] { 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)
|
|
{
|
|
row = await _db.Fastest<BasLocation>().BulkCopyAsync(locs);
|
|
}
|
|
else if (locs.Count > 400)
|
|
{
|
|
_db.Utilities.PageEach(locs, 100, async pageList =>
|
|
{
|
|
row = await _db.Insertable(pageList).ExecuteCommandAsync();
|
|
});
|
|
}
|
|
else
|
|
{
|
|
row = await _db.Insertable(locs).ExecuteCommandAsync();
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw Oops.Bah(ex.Message);
|
|
}
|
|
result = new VisualDevImportDataOutput()
|
|
{
|
|
snum = row,
|
|
fnum = 0,
|
|
failResult = errorlist,
|
|
resultType = errorlist.Count < 1 ? 0 : 1
|
|
};
|
|
return result;
|
|
}
|
|
|
|
}
|
|
}
|