146 lines
6.9 KiB
C#
146 lines
6.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Security;
|
|
using JNPF.FriendlyException;
|
|
using JNPF.VisualDev;
|
|
using Mapster;
|
|
using Microsoft.AspNetCore.Http;
|
|
using SqlSugar;
|
|
using Tnb.BasicData.Entities;
|
|
using Tnb.WarehouseMgr.Entities.Enums;
|
|
using Tnb.WarehouseMgr.Entities;
|
|
using JNPF.Common.Extension;
|
|
using JNPF.Logging;
|
|
using System.Reflection.Emit;
|
|
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
|
|
{
|
|
/// <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;
|
|
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)
|
|
{
|
|
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;
|
|
if (isType == string.Empty) throw new AppFriendlyException($"第{dics.IndexOf(d) + 1}个数据库位类型不可为空", 500);
|
|
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;
|
|
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 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.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(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)
|
|
{
|
|
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;
|
|
}
|
|
|
|
}
|
|
}
|