基础信息导入

usertest
cjy 4 months ago
parent 0748c51e1c
commit 7358c57160

@ -0,0 +1,88 @@
using DS.Module.Core;
using DS.WMS.Core.Code.Dtos;
using DS.WMS.Core.Code.Interface;
using DS.WMS.Core.Sys.Dtos;
using Microsoft.AspNetCore.Mvc;
namespace DS.WMS.AdminApi.Controllers;
/// <summary>
/// 基础信息导入服务
/// </summary>
public class CodeInfoImportController : ApiController
{
private readonly ICodeInfoImportService _invokeService;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="invokeService"></param>
public CodeInfoImportController(ICodeInfoImportService invokeService)
{
_invokeService = invokeService;
}
/// <summary>
/// 按Excel导入包装信息
/// </summary>
/// <param name="file">Excel文件</param>
/// <returns></returns>
[HttpPost]
[Route("ImportPackageByExcel")]
public async Task<DataResult<string>> ImportPackageByExcel(IFormFile file)
{
var res = await _invokeService.ImportPackageByExcel(file);
return res;
}
/// <summary>
/// 按Excel导入集装箱信息
/// </summary>
/// <param name="file">Excel文件</param>
/// <returns></returns>
[HttpPost]
[Route("ImportCtnByExcel")]
public async Task<DataResult<string>> ImportCtnByExcel(IFormFile file)
{
var res = await _invokeService.ImportCtnByExcel(file);
return res;
}
/// <summary>
/// 按Excel导入国家信息
/// </summary>
/// <param name="file">Excel文件</param>
/// <returns></returns>
[HttpPost]
[Route("ImportCountryByExcel")]
public async Task<DataResult<string>> ImportCountryByExcel(IFormFile file)
{
var res = await _invokeService.ImportCountryByExcel(file);
return res;
}
/// <summary>
/// 按Excel导入商品信息
/// </summary>
/// <param name="file">Excel文件</param>
/// <returns></returns>
[HttpPost]
[Route("ImportGoodsByExcel")]
public async Task<DataResult<string>> ImportGoodsByExcel(IFormFile file)
{
var res = await _invokeService.ImportGoodsByExcel(file);
return res;
}
/// <summary>
/// 按Excel导入港口信息
/// </summary>
/// <param name="file">Excel文件</param>
/// <returns></returns>
[HttpPost]
[Route("ImportPortByExcel")]
public async Task<DataResult<string>> ImportPortByExcel(IFormFile file)
{
var res = await _invokeService.ImportPortByExcel(file);
return res;
}
}

@ -0,0 +1,57 @@
using DS.Module.Core;
using FluentValidation;
namespace DS.WMS.Core.Code.Dtos;
/// <summary>
/// 国家请求导入实体
/// </summary>
public class CodeCountryExcelImportReq
{
/// <summary>
/// 国家唯一代码
/// </summary>
public string CountryCode { get; set; } = "";
/// <summary>
/// 国家名称
/// </summary>
public string CountryName { get; set; } = "";
/// <summary>
/// 国家英文名称
/// </summary>
public string CountryEnName { get; set; } = "";
/// <summary>
/// 所在大洲
/// </summary>
public string Chau { get; set; } = "";
/// <summary>
/// 首都
/// </summary>
public string Capital { get; set; } = "";
/// <summary>
/// 关税等级
/// </summary>
public int Tariff { get; set; }= 0;
/// <summary>
/// 吨位税
/// </summary>
public int TonnageTax { get; set; } = 0;
/// <summary>
/// 国家3字代码
/// </summary>
public string CountryCode3 { get; set; } = "";
/// <summary>
/// 国家描述
/// </summary>
public string Explain { get; set; } = "";
}

@ -0,0 +1,55 @@
using DS.Module.Core;
using FluentValidation;
namespace DS.WMS.Core.Code.Dtos;
/// <summary>
/// 集装箱信息导入请求实体
/// </summary>
public class CodeCtnExcelImportReq
{
/// <summary>
/// 集装箱尺寸
/// </summary>
public string CtnSize { get; set; } = "";
/// <summary>
/// 集装箱类型
/// </summary>
public string CtnType { get; set; }= "";
/// <summary>
/// 表现形式
/// </summary>
public string CtnName { get; set; }= "";
/// <summary>
/// EDI代码
/// </summary>
public string EdiCode { get; set; }= "";
/// <summary>
/// 箱皮重
/// </summary>
public decimal CtnWeight { get; set; }= 0;
/// <summary>
/// 中文说明
/// </summary>
public string CnExplain { get; set; }= "";
/// <summary>
/// 英文说明
/// </summary>
public string EnExplain { get; set; }= "";
/// <summary>
/// AFR代码
/// </summary>
public string AfrCode { get; set; }= "";
/// <summary>
/// 默认限重
/// </summary>
public decimal LimitWeight { get; set; } = 0;
/// <summary>
/// TEU
/// </summary>
public decimal TEU { get; set; }= 0;
}

@ -0,0 +1,83 @@
using DS.Module.Core;
using FluentValidation;
namespace DS.WMS.Core.Code.Dtos;
/// <summary>
/// 商品导入请求实体
/// </summary>
public class CodeGoodsExcelImportReq
{
/// <summary>
/// 商品编码
/// </summary>
public string GoodsCode { get; set; }= "";
/// <summary>
/// 商品名称
/// </summary>
public string GoodName { get; set; }= "";
/// <summary>
/// 物料号
/// </summary>
public string GoodNo { get; set; }= "";
/// <summary>
/// 英文名称
/// </summary>
public string EnName { get; set; }= "";
/// <summary>
/// 商品描述
/// </summary>
public string Description { get; set; }= "";
/// <summary>
/// 入库应收
/// </summary>
public decimal ARRate { get; set; }= 0;
/// <summary>
/// 入库应付
/// </summary>
public decimal APRate { get; set; }= 0;
/// <summary>
/// 出库应收
/// </summary>
public decimal AROutRate { get; set; }= 0;
/// <summary>
/// 出库应付
/// </summary>
public decimal APOutRate { get; set; } = 0;
/// <summary>
/// 商品类型
/// </summary>
public long GoodsTypeId { get; set; }= 0;
/// <summary>
/// 计费大类
/// </summary>
public long GoodsFeeTypeId { get; set; }= 0;
/// <summary>
/// 海关代码
/// </summary>
public string HSCode { get; set; }= "";
/// <summary>
/// 申报计量单位
/// </summary>
public string RuleUnit { get; set; }= "";
/// <summary>
/// 法定第一计量单位
/// </summary>
public string RuleUnit1 { get; set; }= "";
/// <summary>
/// 法定第二计量单位
/// </summary>
public string RuleUnit2 { get; set; }= "";
}

@ -0,0 +1,30 @@
using DS.Module.Core;
using FluentValidation;
namespace DS.WMS.Core.Code.Dtos;
/// <summary>
/// 包装类型Excel导入请求实体
/// </summary>
public class CodePackageExcelImportReq
{
/// <summary>
/// 包装类型
/// </summary>
public string PackageName { get; set; }
/// <summary>
/// 中文说明
/// </summary>
public string CnExplain { get; set; }
/// <summary>
/// AFR代码
/// </summary>
public string AfrCode { get; set; }
/// <summary>
/// EDI代码
/// </summary>
public string EdiCode { get; set; }
}

@ -0,0 +1,49 @@
using DS.Module.Core;
using FluentValidation;
namespace DS.WMS.Core.Code.Dtos;
/// <summary>
/// 港口请求导入实体
/// </summary>
public class CodePortExcelImportReq
{
/// <summary>
/// 港口英文名称
/// </summary>
public string PortName { get; set; } = "";
/// <summary>
/// 港口中文名称
/// </summary>
public string CnName { get; set; }= "";
/// <summary>
/// 国家名称
/// </summary>
public string CountryName { get; set; }= "";
/// <summary>
/// 所在大洲
/// </summary>
public string Chau { get; set; }= "";
/// <summary>
/// 说明
/// </summary>
public string Explain { get; set; }= "";
/// <summary>
/// 港口类型
/// </summary>
public string PortType { get; set; }= "";
/// <summary>
/// 国家Id
/// </summary>
public long CountryId { get; set; } = 0;
/// <summary>
/// 航线Id
/// </summary>
public long LaneId { get; set; }= 0;
/// <summary>
/// EDI代码
/// </summary>
public string EdiCode { get; set; } = "";
}

@ -0,0 +1,48 @@
using DS.Module.Core;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DS.WMS.Core.Code.Interface
{
public interface ICodeInfoImportService
{
/// <summary>
/// 按Excel导入包装
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
public Task<DataResult<string>> ImportPackageByExcel(IFormFile file);
/// <summary>
/// 按Excel导入集装箱
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
public Task<DataResult<string>> ImportCtnByExcel(IFormFile file);
/// <summary>
/// 按Excel导入国家信息
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
public Task<DataResult<string>> ImportCountryByExcel(IFormFile file);
/// <summary>
/// 按Excel导入商品信息
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
public Task<DataResult<string>> ImportGoodsByExcel(IFormFile file);
/// <summary>
/// 按Excel导入港口信息
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
public Task<DataResult<string>> ImportPortByExcel(IFormFile file);
}
}

@ -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));
}
}
}
}
Loading…
Cancel
Save