1
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using JNPF.Common.Configuration;
|
using JNPF.Common.Configuration;
|
||||||
|
using JNPF.Common.Core.Manager;
|
||||||
using JNPF.Common.Extension;
|
using JNPF.Common.Extension;
|
||||||
using JNPF.Common.Helper;
|
using JNPF.Common.Helper;
|
||||||
using JNPF.Common.Models;
|
using JNPF.Common.Models;
|
||||||
@@ -26,9 +27,11 @@ namespace Tnb.WarehouseMgr
|
|||||||
public class WmsImportAndExportService
|
public class WmsImportAndExportService
|
||||||
{
|
{
|
||||||
private readonly ISqlSugarClient _db;
|
private readonly ISqlSugarClient _db;
|
||||||
public WmsImportAndExportService(ISqlSugarRepository<WmsCarryH> repository)
|
private readonly IUserManager _userManager;
|
||||||
|
public WmsImportAndExportService(ISqlSugarRepository<WmsCarryH> repository, IUserManager userManager)
|
||||||
{
|
{
|
||||||
_db = repository.AsSugarClient();
|
_db = repository.AsSugarClient();
|
||||||
|
_userManager = userManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -39,25 +42,48 @@ namespace Tnb.WarehouseMgr
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<dynamic> CarryImport(IFormFile file)
|
public async Task<dynamic> CarryImport(IFormFile file)
|
||||||
{
|
{
|
||||||
List<Dictionary<string, string>> dics = WmsImport(file);
|
int row = 0;
|
||||||
List<WmsCarryH> carrys = new List<WmsCarryH>();
|
try
|
||||||
var carryStds = await _db.Queryable<WmsCarrystd>().ToListAsync();
|
|
||||||
List<string> locCodes = new();
|
|
||||||
WmsCarryH carryH = new WmsCarryH();
|
|
||||||
if (carryStds != null)
|
|
||||||
{
|
{
|
||||||
string carryStdId = string.Empty;
|
List<Dictionary<string, string>> dics = WmsImport(file);
|
||||||
foreach (var d in dics)
|
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;
|
string carryStdId = string.Empty;
|
||||||
d.Remove("carrystd_code");
|
foreach (var d in dics)
|
||||||
d.Add("carrystd_id", carryStdId);
|
{
|
||||||
locCodes.Add(d["location_code"]);
|
var stdCodeKey = d["carrystd_code"];
|
||||||
carryH = d.Adapt<WmsCarryH>();
|
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>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user