using DS.Module.Core;
using DS.Module.Core.Extensions;
using DS.Module.SqlSugar;
using DS.Module.UserModule;
using DS.WMS.Core.Code.Dtos;
using DS.WMS.Core.Code.Entity;
using DS.WMS.Core.Code.Import;
using DS.WMS.Core.Code.Interface;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using MiniExcelLibs;
using NPOI.SS.Formula.Functions;
using SqlSugar;
using System.Text.RegularExpressions;
namespace DS.WMS.Core.Code.Method
{
public class DataImportService : IDataImportService
{
private readonly IServiceProvider _serviceProvider;
private readonly ISqlSugarClient db;
private readonly IUser user;
private readonly ISaasDbService saasService;
///
///
///
///
public DataImportService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService();
user = _serviceProvider.GetRequiredService();
saasService = _serviceProvider.GetRequiredService();
}
public async Task> ImportZYData(DataImportZY req)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
var list = new List();
foreach (var item in req.Hscode)
{
var data = new CodeGoods()
{
//GoodsCode = PinYinUtil.GetFristLetter((Regex.Unescape(item.HscodeName).Replace("\\","/"))),
GoodsCode = item.Hscode,
GoodName = Regex.Unescape(item.HscodeName.Replace("\\", "/")).Replace("\n", " ").Trim(),
HSCode = item.Hscode,
};
list.Add(data);
}
//Console.WriteLine(list);
await tenantDb.Insertable(list).ExecuteCommandAsync();
//var list = new List();
//foreach (var item in req.RouteList)
//{
// var data = new CodeLanes()
// {
// LaneCode = item.RouteNameEn,
// LaneEnName = item.RouteNameEn,
// LaneName = Regex.Unescape(item.RouteNameZh),
// LinkId = item.RouteId.ToString(),
// };
// list.Add(data);
//}
//await tenantDb.Insertable(list).ExecuteCommandAsync();
//var carrierlist = new List();
//var countryList = tenantDb.Queryable().ToList();
//foreach (var item in req.ShippingCompanyList)
//{
// var country = new CodeCountry();
// if (item.CountryNameCn.IsNotNull())
// {
// country = countryList.Where(x => x.CountryName.Contains(Regex.Unescape(item.CountryNameCn))).FirstOrDefault();
// }
// var data = new CodeCarrier()
// {
// Code = item.ShippingCode,
// EdiCode = item.ShippingCode,
// CnName = Regex.Unescape(item.ShippingNameCn),
// CnShortName = Regex.Unescape(item.ShippingAbbreviation),
// EnName = item.ShippingNameEn,
// OtherCode = item.ShippingAlias,
// WebSite = item.ShippingWebsite,
// CountryId = country.IsNotNull() ? country.Id: 0,
// CountryName = country.IsNotNull() ? country.CountryName : "",
// };
// carrierlist.Add(data);
//}
//await tenantDb.Insertable(carrierlist).ExecuteCommandAsync();
//var portlist = new List();
//var laneList = tenantDb.Queryable().ToList();
//foreach (var item in req.PortList)
//{
// var country = new CodeCountry();
// if (item.CountryNameCn.IsNotNull())
// {
// country = countryList.Where(x => x.CountryName.Contains(Regex.Unescape(item.CountryNameCn))).FirstOrDefault();
// }
// var lane = laneList.Where(x => x.LinkId == item.RouteId.ToString()).FirstOrDefault();
// var data = new CodePort()
// {
// PortName = item.PortNameEn,
// CnName = item.PortNameZh.IsNotNull() ? Regex.Unescape(item.PortNameZh) : "",
// EdiCode = item.PortCode,
// CountryId = country.IsNotNull() ? country.Id : 0,
// CountryName = country.IsNotNull() ? country.CountryName : "",
// LaneId = lane.IsNotNull() ? lane.Id : 0,
// Lane = lane.IsNotNull() ? lane.LaneName : "",
// LaneCode = lane.IsNotNull() ? lane.LaneCode : "",
// };
// portlist.Add(data);
//}
//await tenantDb.Insertable(portlist).ExecuteCommandAsync();
return await Task.FromResult(DataResult.Failed("导入成功!", MultiLanguageConst.DataImportSuccess));
}
public async Task> ImportZYGoods(DataImportZY req)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
var list = new List();
foreach (var item in req.Hscode)
{
var data = new CodeGoods()
{
GoodsCode = PinYinUtil.GetFristLetter(Regex.Unescape(item.HscodeName)),
GoodName = Regex.Unescape(item.HscodeName),
HSCode = item.Hscode,
};
list.Add(data);
}
await tenantDb.Insertable(list).ExecuteCommandAsync();
return await Task.FromResult(DataResult.Failed("导入成功!", MultiLanguageConst.DataImportSuccess));
}
}
}