You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

159 lines
6.5 KiB
C#

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;
/// <summary>
///
/// </summary>
/// <param name="serviceProvider"></param>
public DataImportService(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
user = _serviceProvider.GetRequiredService<IUser>();
saasService = _serviceProvider.GetRequiredService<ISaasDbService>();
}
public async Task<DataResult<string>> ImportZYData(DataImportZY req)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
//var list = new List<CodeGoods>();
//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<CodeLanes>();
//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<CodeCarrier>();
//var countryList = tenantDb.Queryable<CodeCountry>().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<CodePort>();
//var laneList = tenantDb.Queryable<CodeLanes>().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();
foreach (var item in req.PortList)
{
item.PortNameZh = item.PortNameZh.IsNotNull() ? Regex.Unescape(item.PortNameZh) : "";
item.CountryNameCh = item.CountryNameCh.IsNotNull() ? Regex.Unescape(item.CountryNameCh) : "";
item.CountryNameCn = item.CountryNameCn.IsNotNull() ? Regex.Unescape(item.CountryNameCn) : "";
}
await tenantDb.Insertable(req.PortList).ExecuteCommandAsync();
return await Task.FromResult(DataResult<string>.Failed("导入成功!", MultiLanguageConst.DataImportSuccess));
}
public async Task<DataResult<string>> ImportZYGoods(DataImportZY req)
{
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
var list = new List<CodeGoods>();
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<string>.Failed("导入成功!", MultiLanguageConst.DataImportSuccess));
}
}
}