|
|
|
@ -0,0 +1,349 @@
|
|
|
|
|
using DS.Module.Core;
|
|
|
|
|
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.Interface;
|
|
|
|
|
using DS.WMS.Core.Op.Dtos;
|
|
|
|
|
using DS.WMS.Core.Op.Entity;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using MiniExcelLibs;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using static NPOI.HSSF.Util.HSSFColor;
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.Code.Method
|
|
|
|
|
{
|
|
|
|
|
public class CodeInfoImportService: ICodeInfoImportService
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
|
private readonly ISqlSugarClient db;
|
|
|
|
|
private readonly IUser user;
|
|
|
|
|
private readonly ISaasDbService saasService;
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="serviceProvider"></param>
|
|
|
|
|
public CodeInfoImportService(IServiceProvider serviceProvider)
|
|
|
|
|
{
|
|
|
|
|
_serviceProvider = serviceProvider;
|
|
|
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
|
|
|
user = _serviceProvider.GetRequiredService<IUser>();
|
|
|
|
|
saasService = _serviceProvider.GetRequiredService<ISaasDbService>();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 按Excel导入包装
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="file"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult<string>> ImportPackageByExcel(IFormFile file)
|
|
|
|
|
{
|
|
|
|
|
//未上传文件
|
|
|
|
|
if (file == null || file.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
return await Task.FromResult(DataResult<string>.Failed("请上传Excel!"));
|
|
|
|
|
}
|
|
|
|
|
var formFile = file;
|
|
|
|
|
//DataResult<string> api_Result = new Api_Result<string>();
|
|
|
|
|
//获取文件名
|
|
|
|
|
var fileName = formFile.FileName;
|
|
|
|
|
// 获取文件后缀
|
|
|
|
|
var fileExtension = Path.GetExtension(fileName);
|
|
|
|
|
// 判断后缀是否是xlsx或者xls
|
|
|
|
|
if (fileExtension != ".xlsx" && fileExtension != ".xls")
|
|
|
|
|
{
|
|
|
|
|
return DataResult<string>.Failed("文件格式错误");
|
|
|
|
|
}
|
|
|
|
|
var length = formFile.Length;
|
|
|
|
|
if (length > 1024 * 1024 * 10)
|
|
|
|
|
{
|
|
|
|
|
return DataResult<string>.Failed("文件大小不能超过10M");
|
|
|
|
|
}
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
// MemoryStream 内存流 在内存当中创建一个流(开辟空间)
|
|
|
|
|
using (var stream = new MemoryStream())
|
|
|
|
|
{
|
|
|
|
|
//将文件写入内存流
|
|
|
|
|
formFile.CopyTo(stream);
|
|
|
|
|
//将流的位置归零
|
|
|
|
|
stream.Position = 0;
|
|
|
|
|
//将内存流转成List集合
|
|
|
|
|
var list = await stream.QueryAsync<CodePackageExcelImportReq>();
|
|
|
|
|
var packages = new List<CodePackage>();
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
|
|
|
|
var package = new CodePackage()
|
|
|
|
|
{
|
|
|
|
|
PackageName = item.PackageName,
|
|
|
|
|
CnExplain = item.CnExplain,
|
|
|
|
|
AfrCode = item.AfrCode,
|
|
|
|
|
EdiCode = item.EdiCode,
|
|
|
|
|
};
|
|
|
|
|
packages.Add(package);
|
|
|
|
|
}
|
|
|
|
|
//var codes = configs.Select(c => c.SystemCode).ToList();
|
|
|
|
|
//if (tenantDb.Queryable<BookingGoodsStatusConfig>().Where(x => codes.Contains(x.SystemCode)).Any())
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
|
|
// return DataResult<string>.Failed("存在已有的系统编码,请检查");
|
|
|
|
|
//}
|
|
|
|
|
//var configs = list.Adapt<BookingGoodsStatusConfig>();
|
|
|
|
|
await db.Insertable(packages).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
return await Task.FromResult(DataResult<string>.Failed("导入成功!", MultiLanguageConst.DataImportSuccess));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 按Excel导入集装箱信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="file"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult<string>> ImportCtnByExcel(IFormFile file)
|
|
|
|
|
{
|
|
|
|
|
//未上传文件
|
|
|
|
|
if (file == null || file.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
return await Task.FromResult(DataResult<string>.Failed("请上传Excel!"));
|
|
|
|
|
}
|
|
|
|
|
var formFile = file;
|
|
|
|
|
//DataResult<string> api_Result = new Api_Result<string>();
|
|
|
|
|
//获取文件名
|
|
|
|
|
var fileName = formFile.FileName;
|
|
|
|
|
// 获取文件后缀
|
|
|
|
|
var fileExtension = Path.GetExtension(fileName);
|
|
|
|
|
// 判断后缀是否是xlsx或者xls
|
|
|
|
|
if (fileExtension != ".xlsx" && fileExtension != ".xls")
|
|
|
|
|
{
|
|
|
|
|
return DataResult<string>.Failed("文件格式错误");
|
|
|
|
|
}
|
|
|
|
|
var length = formFile.Length;
|
|
|
|
|
if (length > 1024 * 1024 * 10)
|
|
|
|
|
{
|
|
|
|
|
return DataResult<string>.Failed("文件大小不能超过10M");
|
|
|
|
|
}
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
// MemoryStream 内存流 在内存当中创建一个流(开辟空间)
|
|
|
|
|
using (var stream = new MemoryStream())
|
|
|
|
|
{
|
|
|
|
|
//将文件写入内存流
|
|
|
|
|
formFile.CopyTo(stream);
|
|
|
|
|
//将流的位置归零
|
|
|
|
|
stream.Position = 0;
|
|
|
|
|
//将内存流转成List集合
|
|
|
|
|
var list = await stream.QueryAsync<CodeCtnExcelImportReq>();
|
|
|
|
|
var ctns = new List<CodeCtn>();
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
|
|
|
|
var ctn = new CodeCtn()
|
|
|
|
|
{
|
|
|
|
|
CtnSize = item.CtnSize,
|
|
|
|
|
CtnType = item.CtnType,
|
|
|
|
|
CnExplain= item.CnExplain,
|
|
|
|
|
EnExplain= item.EnExplain,
|
|
|
|
|
CtnName = item.CtnName,
|
|
|
|
|
LimitWeight= item.LimitWeight,
|
|
|
|
|
TEU= item.TEU,
|
|
|
|
|
AfrCode = item.AfrCode,
|
|
|
|
|
EdiCode = item.EdiCode,
|
|
|
|
|
};
|
|
|
|
|
ctns.Add(ctn);
|
|
|
|
|
}
|
|
|
|
|
//var codes = configs.Select(c => c.SystemCode).ToList();
|
|
|
|
|
//if (tenantDb.Queryable<BookingGoodsStatusConfig>().Where(x => codes.Contains(x.SystemCode)).Any())
|
|
|
|
|
//{
|
|
|
|
|
|
|
|
|
|
// return DataResult<string>.Failed("存在已有的系统编码,请检查");
|
|
|
|
|
//}
|
|
|
|
|
//var configs = list.Adapt<BookingGoodsStatusConfig>();
|
|
|
|
|
await db.Insertable(ctns).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
return await Task.FromResult(DataResult<string>.Failed("导入成功!", MultiLanguageConst.DataImportSuccess));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 按Excel导入国家信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="file"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult<string>> ImportCountryByExcel(IFormFile file)
|
|
|
|
|
{
|
|
|
|
|
//未上传文件
|
|
|
|
|
if (file == null || file.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
return await Task.FromResult(DataResult<string>.Failed("请上传Excel!"));
|
|
|
|
|
}
|
|
|
|
|
var formFile = file;
|
|
|
|
|
//DataResult<string> api_Result = new Api_Result<string>();
|
|
|
|
|
//获取文件名
|
|
|
|
|
var fileName = formFile.FileName;
|
|
|
|
|
// 获取文件后缀
|
|
|
|
|
var fileExtension = Path.GetExtension(fileName);
|
|
|
|
|
// 判断后缀是否是xlsx或者xls
|
|
|
|
|
if (fileExtension != ".xlsx" && fileExtension != ".xls")
|
|
|
|
|
{
|
|
|
|
|
return DataResult<string>.Failed("文件格式错误");
|
|
|
|
|
}
|
|
|
|
|
var length = formFile.Length;
|
|
|
|
|
if (length > 1024 * 1024 * 10)
|
|
|
|
|
{
|
|
|
|
|
return DataResult<string>.Failed("文件大小不能超过10M");
|
|
|
|
|
}
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
// MemoryStream 内存流 在内存当中创建一个流(开辟空间)
|
|
|
|
|
using (var stream = new MemoryStream())
|
|
|
|
|
{
|
|
|
|
|
//将文件写入内存流
|
|
|
|
|
formFile.CopyTo(stream);
|
|
|
|
|
//将流的位置归零
|
|
|
|
|
stream.Position = 0;
|
|
|
|
|
//将内存流转成List集合
|
|
|
|
|
var list = await stream.QueryAsync<CodeCountryExcelImportReq>();
|
|
|
|
|
var countries = new List<CodeCountry>();
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
|
|
|
|
var country = new CodeCountry()
|
|
|
|
|
{
|
|
|
|
|
CountryCode = item.CountryCode,
|
|
|
|
|
CountryName = item.CountryName,
|
|
|
|
|
CountryEnName = item.CountryEnName,
|
|
|
|
|
Capital = item.Capital,
|
|
|
|
|
Chau = item.Chau,
|
|
|
|
|
CountryCode3 = item.CountryCode,
|
|
|
|
|
Tariff = item.Tariff,
|
|
|
|
|
Explain = item.Explain,
|
|
|
|
|
TonnageTax = item.TonnageTax,
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
countries.Add(country);
|
|
|
|
|
}
|
|
|
|
|
await db.Insertable(countries).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
return await Task.FromResult(DataResult<string>.Failed("导入成功!", MultiLanguageConst.DataImportSuccess));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 按Excel导入商品信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="file"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult<string>> ImportGoodsByExcel(IFormFile file)
|
|
|
|
|
{
|
|
|
|
|
//未上传文件
|
|
|
|
|
if (file == null || file.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
return await Task.FromResult(DataResult<string>.Failed("请上传Excel!"));
|
|
|
|
|
}
|
|
|
|
|
var formFile = file;
|
|
|
|
|
//DataResult<string> api_Result = new Api_Result<string>();
|
|
|
|
|
//获取文件名
|
|
|
|
|
var fileName = formFile.FileName;
|
|
|
|
|
// 获取文件后缀
|
|
|
|
|
var fileExtension = Path.GetExtension(fileName);
|
|
|
|
|
// 判断后缀是否是xlsx或者xls
|
|
|
|
|
if (fileExtension != ".xlsx" && fileExtension != ".xls")
|
|
|
|
|
{
|
|
|
|
|
return DataResult<string>.Failed("文件格式错误");
|
|
|
|
|
}
|
|
|
|
|
var length = formFile.Length;
|
|
|
|
|
if (length > 1024 * 1024 * 10)
|
|
|
|
|
{
|
|
|
|
|
return DataResult<string>.Failed("文件大小不能超过10M");
|
|
|
|
|
}
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
// MemoryStream 内存流 在内存当中创建一个流(开辟空间)
|
|
|
|
|
using (var stream = new MemoryStream())
|
|
|
|
|
{
|
|
|
|
|
//将文件写入内存流
|
|
|
|
|
formFile.CopyTo(stream);
|
|
|
|
|
//将流的位置归零
|
|
|
|
|
stream.Position = 0;
|
|
|
|
|
//将内存流转成List集合
|
|
|
|
|
var list = await stream.QueryAsync<CodeGoodsExcelImportReq>();
|
|
|
|
|
var goods = new List<CodeGoods>();
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
|
|
|
|
var good = new CodeGoods()
|
|
|
|
|
{
|
|
|
|
|
GoodsCode = item.GoodsCode,
|
|
|
|
|
GoodName = item.GoodName,
|
|
|
|
|
};
|
|
|
|
|
goods.Add(good);
|
|
|
|
|
}
|
|
|
|
|
await db.Insertable(goods).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
return await Task.FromResult(DataResult<string>.Failed("导入成功!", MultiLanguageConst.DataImportSuccess));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 按Excel导入港口信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="file"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<DataResult<string>> ImportPortByExcel(IFormFile file)
|
|
|
|
|
{
|
|
|
|
|
//未上传文件
|
|
|
|
|
if (file == null || file.Length == 0)
|
|
|
|
|
{
|
|
|
|
|
return await Task.FromResult(DataResult<string>.Failed("请上传Excel!"));
|
|
|
|
|
}
|
|
|
|
|
var formFile = file;
|
|
|
|
|
//DataResult<string> api_Result = new Api_Result<string>();
|
|
|
|
|
//获取文件名
|
|
|
|
|
var fileName = formFile.FileName;
|
|
|
|
|
// 获取文件后缀
|
|
|
|
|
var fileExtension = Path.GetExtension(fileName);
|
|
|
|
|
// 判断后缀是否是xlsx或者xls
|
|
|
|
|
if (fileExtension != ".xlsx" && fileExtension != ".xls")
|
|
|
|
|
{
|
|
|
|
|
return DataResult<string>.Failed("文件格式错误");
|
|
|
|
|
}
|
|
|
|
|
var length = formFile.Length;
|
|
|
|
|
if (length > 1024 * 1024 * 10)
|
|
|
|
|
{
|
|
|
|
|
return DataResult<string>.Failed("文件大小不能超过10M");
|
|
|
|
|
}
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
// MemoryStream 内存流 在内存当中创建一个流(开辟空间)
|
|
|
|
|
using (var stream = new MemoryStream())
|
|
|
|
|
{
|
|
|
|
|
//将文件写入内存流
|
|
|
|
|
formFile.CopyTo(stream);
|
|
|
|
|
//将流的位置归零
|
|
|
|
|
stream.Position = 0;
|
|
|
|
|
//将内存流转成List集合
|
|
|
|
|
var list = await stream.QueryAsync<CodePortExcelImportReq>();
|
|
|
|
|
var ports = new List<CodePort>();
|
|
|
|
|
foreach (var item in list)
|
|
|
|
|
{
|
|
|
|
|
var good = new CodePort()
|
|
|
|
|
{
|
|
|
|
|
PortName = item.PortName,
|
|
|
|
|
CnName = item.CnName,
|
|
|
|
|
EdiCode = item.EdiCode,
|
|
|
|
|
CountryName = item.CountryName,
|
|
|
|
|
Chau = item.Chau,
|
|
|
|
|
Explain = item.Explain,
|
|
|
|
|
PortType = item.PortType,
|
|
|
|
|
};
|
|
|
|
|
ports.Add(good);
|
|
|
|
|
}
|
|
|
|
|
await db.Insertable(ports).ExecuteCommandAsync();
|
|
|
|
|
|
|
|
|
|
return await Task.FromResult(DataResult<string>.Failed("导入成功!", MultiLanguageConst.DataImportSuccess));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|