1
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using JNPF.Common.Configuration;
|
||||
using JNPF.Common.Core.Manager;
|
||||
using JNPF.Common.Extension;
|
||||
using JNPF.Common.Helper;
|
||||
using JNPF.Common.Models;
|
||||
@@ -26,9 +27,11 @@ namespace Tnb.WarehouseMgr
|
||||
public class WmsImportAndExportService
|
||||
{
|
||||
private readonly ISqlSugarClient _db;
|
||||
public WmsImportAndExportService(ISqlSugarRepository<WmsCarryH> repository)
|
||||
private readonly IUserManager _userManager;
|
||||
public WmsImportAndExportService(ISqlSugarRepository<WmsCarryH> repository, IUserManager userManager)
|
||||
{
|
||||
_db = repository.AsSugarClient();
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,25 +42,48 @@ namespace Tnb.WarehouseMgr
|
||||
/// <returns></returns>
|
||||
public async Task<dynamic> CarryImport(IFormFile file)
|
||||
{
|
||||
List<Dictionary<string, string>> dics = WmsImport(file);
|
||||
List<WmsCarryH> carrys = new List<WmsCarryH>();
|
||||
var carryStds = await _db.Queryable<WmsCarrystd>().ToListAsync();
|
||||
List<string> locCodes = new();
|
||||
WmsCarryH carryH = new WmsCarryH();
|
||||
if (carryStds != null)
|
||||
int row = 0;
|
||||
try
|
||||
{
|
||||
string carryStdId = string.Empty;
|
||||
foreach (var d in dics)
|
||||
List<Dictionary<string, string>> dics = WmsImport(file);
|
||||
List<WmsCarryH> carrys = new List<WmsCarryH>();
|
||||
var carryStdDic = await _db.Queryable<WmsCarrystd>().ToDictionaryAsync(x => x.carrystd_code, x => x.id);
|
||||
List<string> locCodes = new();
|
||||
WmsCarryH carryH = new WmsCarryH();
|
||||
if (carryStdDic?.Count > 0)
|
||||
{
|
||||
carryStdId = carryStds.Find(x => x.carrystd_code == d["carrystd_code"])!.id;
|
||||
d.Remove("carrystd_code");
|
||||
d.Add("carrystd_id", carryStdId);
|
||||
locCodes.Add(d["location_code"]);
|
||||
carryH = d.Adapt<WmsCarryH>();
|
||||
string carryStdId = string.Empty;
|
||||
foreach (var d in dics)
|
||||
{
|
||||
var stdCodeKey = d["carrystd_code"];
|
||||
carryStdId = carryStdDic.ContainsKey(stdCodeKey) ? carryStdDic[stdCodeKey]?.ToString() ?? "" : "";
|
||||
d.Add("carrystd_id", carryStdId);
|
||||
locCodes.Add(d["location_code"]);
|
||||
carryH = d.Adapt<WmsCarryH>();
|
||||
carrys.Add(carryH);
|
||||
}
|
||||
var locs = await _db.Queryable<BasLocation>().Where(it => locCodes.Contains(it.location_code)).ToDictionaryAsync(x => x.location_code, x => x.id);
|
||||
foreach (var loc in locCodes)
|
||||
{
|
||||
var c = carrys.Find(x => x.location_code == loc);
|
||||
if (c != null)
|
||||
c.location_id = locs[loc].ToString();
|
||||
}
|
||||
carrys.ForEach(x =>
|
||||
{
|
||||
x.id = SnowflakeIdHelper.NextId();
|
||||
x.create_id = _userManager.UserId;
|
||||
x.create_time = DateTime.Now;
|
||||
});
|
||||
}
|
||||
var locs = await _db.Queryable<BasLocation>().Where(it=>locCodes.Contains(it.location_code)).ToListAsync();
|
||||
row = await _db.Storageable(carrys).ExecuteCommandAsync();
|
||||
}
|
||||
return Task.FromResult(0);
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
throw;
|
||||
}
|
||||
return row>0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user