81 lines
2.8 KiB
C#
81 lines
2.8 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;
|
|
|
|
namespace Tnb.WarehouseMgr
|
|
{
|
|
[OverideVisualDev(ModuleConsts.MODULE_LOCATIONDEFINITION_ID)]
|
|
public class LocationDefinitionService : ExcelDataImportManager
|
|
{
|
|
private readonly ISqlSugarClient _db;
|
|
private readonly IUserManager _userManager;
|
|
public LocationDefinitionService(ISqlSugarRepository<BasLocation> repository, IUserManager userManager)
|
|
{
|
|
_db = repository.AsSugarClient();
|
|
_userManager = userManager;
|
|
OverideFuncs.ImportAsync = DataImport;
|
|
}
|
|
|
|
private async Task<dynamic> DataImport(IFormFile file)
|
|
{
|
|
int row = 0;
|
|
try
|
|
{
|
|
List<Dictionary<string, object>> dics = await ImportExcelToMemory(file);
|
|
List<BasLocation> locs = new List<BasLocation>();
|
|
BasLocation loc = new BasLocation();
|
|
var carryStdDic = await _db.Queryable<WmsCarrystd>().ToDictionaryAsync(x => x.carrystd_code, x => x.id);
|
|
if (carryStdDic?.Count > 0)
|
|
{
|
|
string carryStdId = string.Empty;
|
|
foreach (var d in dics)
|
|
{
|
|
var stdCodeKey = d["carrystd_id"].ToString();
|
|
carryStdId = carryStdDic.ContainsKey(stdCodeKey) ? carryStdDic[stdCodeKey]?.ToString() ?? "" : "";
|
|
d["carrystd_id"] = carryStdId;
|
|
loc = d.Adapt<BasLocation>();
|
|
locs.Add(loc);
|
|
}
|
|
}
|
|
locs.ForEach(x =>
|
|
{
|
|
x.id = SnowflakeIdHelper.NextId();
|
|
x.org_id = _userManager.User.OrganizeId;
|
|
x.is_lock = 0;
|
|
x.create_id = _userManager.UserId;
|
|
x.create_time = DateTime.Now;
|
|
x.modify_id = null;
|
|
x.modify_time = null;
|
|
x.is_mix = 1;
|
|
});
|
|
|
|
await _db.Ado.BeginTranAsync();
|
|
row = await _db.Insertable(locs).ExecuteCommandAsync();
|
|
await _db.Ado.CommitTranAsync();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
await _db.Ado.RollbackTranAsync();
|
|
Log.Error("导入失败", ex);
|
|
throw Oops.Bah("导入失败");
|
|
}
|
|
return row > 0;
|
|
}
|
|
}
|
|
}
|