From 7358c57160aca5ab22af5f4d6731bbd2620eb5b4 Mon Sep 17 00:00:00 2001 From: cjy Date: Mon, 29 Jul 2024 09:22:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E7=A1=80=E4=BF=A1=E6=81=AF=E5=AF=BC?= =?UTF-8?q?=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/CodeInfoImportController.cs | 88 +++++ .../Code/Dtos/CodeCountryExcelImportReq.cs | 57 +++ .../Code/Dtos/CodeCtnExcelImportReq.cs | 55 +++ .../Code/Dtos/CodeGoodsExcelImportReq.cs | 83 +++++ .../Code/Dtos/CodePackageExcelImportReq.cs | 30 ++ .../Code/Dtos/CodePortExcelImportReq.cs | 49 +++ .../Code/Interface/ICodeInfoImportService.cs | 48 +++ .../Code/Method/CodeInfoImportService.cs | 349 ++++++++++++++++++ 8 files changed, 759 insertions(+) create mode 100644 ds-wms-service/DS.WMS.AdminApi/Controllers/CodeInfoImportController.cs create mode 100644 ds-wms-service/DS.WMS.Core/Code/Dtos/CodeCountryExcelImportReq.cs create mode 100644 ds-wms-service/DS.WMS.Core/Code/Dtos/CodeCtnExcelImportReq.cs create mode 100644 ds-wms-service/DS.WMS.Core/Code/Dtos/CodeGoodsExcelImportReq.cs create mode 100644 ds-wms-service/DS.WMS.Core/Code/Dtos/CodePackageExcelImportReq.cs create mode 100644 ds-wms-service/DS.WMS.Core/Code/Dtos/CodePortExcelImportReq.cs create mode 100644 ds-wms-service/DS.WMS.Core/Code/Interface/ICodeInfoImportService.cs create mode 100644 ds-wms-service/DS.WMS.Core/Code/Method/CodeInfoImportService.cs diff --git a/ds-wms-service/DS.WMS.AdminApi/Controllers/CodeInfoImportController.cs b/ds-wms-service/DS.WMS.AdminApi/Controllers/CodeInfoImportController.cs new file mode 100644 index 00000000..1b12ffab --- /dev/null +++ b/ds-wms-service/DS.WMS.AdminApi/Controllers/CodeInfoImportController.cs @@ -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; + +/// +/// 基础信息导入服务 +/// +public class CodeInfoImportController : ApiController +{ + private readonly ICodeInfoImportService _invokeService; + + /// + /// 构造函数 + /// + /// + public CodeInfoImportController(ICodeInfoImportService invokeService) + { + _invokeService = invokeService; + } + /// + /// 按Excel导入包装信息 + /// + /// Excel文件 + /// + [HttpPost] + [Route("ImportPackageByExcel")] + public async Task> ImportPackageByExcel(IFormFile file) + { + var res = await _invokeService.ImportPackageByExcel(file); + return res; + } + + /// + /// 按Excel导入集装箱信息 + /// + /// Excel文件 + /// + [HttpPost] + [Route("ImportCtnByExcel")] + public async Task> ImportCtnByExcel(IFormFile file) + { + var res = await _invokeService.ImportCtnByExcel(file); + return res; + } + + /// + /// 按Excel导入国家信息 + /// + /// Excel文件 + /// + [HttpPost] + [Route("ImportCountryByExcel")] + public async Task> ImportCountryByExcel(IFormFile file) + { + var res = await _invokeService.ImportCountryByExcel(file); + return res; + } + + /// + /// 按Excel导入商品信息 + /// + /// Excel文件 + /// + [HttpPost] + [Route("ImportGoodsByExcel")] + public async Task> ImportGoodsByExcel(IFormFile file) + { + var res = await _invokeService.ImportGoodsByExcel(file); + return res; + } + + /// + /// 按Excel导入港口信息 + /// + /// Excel文件 + /// + [HttpPost] + [Route("ImportPortByExcel")] + public async Task> ImportPortByExcel(IFormFile file) + { + var res = await _invokeService.ImportPortByExcel(file); + return res; + } +} \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeCountryExcelImportReq.cs b/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeCountryExcelImportReq.cs new file mode 100644 index 00000000..5cdb7db3 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeCountryExcelImportReq.cs @@ -0,0 +1,57 @@ +using DS.Module.Core; +using FluentValidation; + +namespace DS.WMS.Core.Code.Dtos; + +/// +/// 国家请求导入实体 +/// +public class CodeCountryExcelImportReq +{ + + /// + /// 国家唯一代码 + /// + public string CountryCode { get; set; } = ""; + + /// + /// 国家名称 + /// + public string CountryName { get; set; } = ""; + + /// + /// 国家英文名称 + /// + public string CountryEnName { get; set; } = ""; + + /// + /// 所在大洲 + /// + public string Chau { get; set; } = ""; + + /// + /// 首都 + /// + public string Capital { get; set; } = ""; + + /// + /// 关税等级 + /// + public int Tariff { get; set; }= 0; + + /// + /// 吨位税 + /// + public int TonnageTax { get; set; } = 0; + + /// + /// 国家3字代码 + /// + public string CountryCode3 { get; set; } = ""; + + /// + /// 国家描述 + /// + public string Explain { get; set; } = ""; +} + \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeCtnExcelImportReq.cs b/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeCtnExcelImportReq.cs new file mode 100644 index 00000000..3294e125 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeCtnExcelImportReq.cs @@ -0,0 +1,55 @@ +using DS.Module.Core; +using FluentValidation; + +namespace DS.WMS.Core.Code.Dtos; + +/// +/// 集装箱信息导入请求实体 +/// +public class CodeCtnExcelImportReq +{ + + + /// + /// 集装箱尺寸 + /// + public string CtnSize { get; set; } = ""; + /// + /// 集装箱类型 + /// + public string CtnType { get; set; }= ""; + /// + /// 表现形式 + /// + public string CtnName { get; set; }= ""; + /// + /// EDI代码 + /// + public string EdiCode { get; set; }= ""; + /// + /// 箱皮重 + /// + public decimal CtnWeight { get; set; }= 0; + /// + /// 中文说明 + /// + public string CnExplain { get; set; }= ""; + /// + /// 英文说明 + /// + public string EnExplain { get; set; }= ""; + + /// + /// AFR代码 + /// + public string AfrCode { get; set; }= ""; + + /// + /// 默认限重 + /// + public decimal LimitWeight { get; set; } = 0; + /// + /// TEU + /// + public decimal TEU { get; set; }= 0; +} diff --git a/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeGoodsExcelImportReq.cs b/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeGoodsExcelImportReq.cs new file mode 100644 index 00000000..615d9cd3 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeGoodsExcelImportReq.cs @@ -0,0 +1,83 @@ +using DS.Module.Core; +using FluentValidation; + +namespace DS.WMS.Core.Code.Dtos; + +/// +/// 商品导入请求实体 +/// +public class CodeGoodsExcelImportReq +{ + + /// + /// 商品编码 + /// + public string GoodsCode { get; set; }= ""; + + /// + /// 商品名称 + /// + public string GoodName { get; set; }= ""; + + /// + /// 物料号 + /// + public string GoodNo { get; set; }= ""; + + /// + /// 英文名称 + /// + public string EnName { get; set; }= ""; + /// + /// 商品描述 + /// + public string Description { get; set; }= ""; + + /// + /// 入库应收 + /// + public decimal ARRate { get; set; }= 0; + + /// + /// 入库应付 + /// + public decimal APRate { get; set; }= 0; + /// + /// 出库应收 + /// + public decimal AROutRate { get; set; }= 0; + + /// + /// 出库应付 + /// + public decimal APOutRate { get; set; } = 0; + + /// + /// 商品类型 + /// + public long GoodsTypeId { get; set; }= 0; + /// + /// 计费大类 + /// + public long GoodsFeeTypeId { get; set; }= 0; + + /// + /// 海关代码 + /// + public string HSCode { get; set; }= ""; + + /// + /// 申报计量单位 + /// + public string RuleUnit { get; set; }= ""; + + /// + /// 法定第一计量单位 + /// + public string RuleUnit1 { get; set; }= ""; + + /// + /// 法定第二计量单位 + /// + public string RuleUnit2 { get; set; }= ""; +} diff --git a/ds-wms-service/DS.WMS.Core/Code/Dtos/CodePackageExcelImportReq.cs b/ds-wms-service/DS.WMS.Core/Code/Dtos/CodePackageExcelImportReq.cs new file mode 100644 index 00000000..d08771fc --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Code/Dtos/CodePackageExcelImportReq.cs @@ -0,0 +1,30 @@ +using DS.Module.Core; +using FluentValidation; + +namespace DS.WMS.Core.Code.Dtos; + +/// +/// 包装类型Excel导入请求实体 +/// +public class CodePackageExcelImportReq +{ + + /// + /// 包装类型 + /// + public string PackageName { get; set; } + /// + /// 中文说明 + /// + public string CnExplain { get; set; } + /// + /// AFR代码 + /// + public string AfrCode { get; set; } + /// + /// EDI代码 + /// + public string EdiCode { get; set; } + +} + \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.Core/Code/Dtos/CodePortExcelImportReq.cs b/ds-wms-service/DS.WMS.Core/Code/Dtos/CodePortExcelImportReq.cs new file mode 100644 index 00000000..3402c4d6 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Code/Dtos/CodePortExcelImportReq.cs @@ -0,0 +1,49 @@ +using DS.Module.Core; +using FluentValidation; + +namespace DS.WMS.Core.Code.Dtos; + +/// +/// 港口请求导入实体 +/// +public class CodePortExcelImportReq +{ + /// + /// 港口英文名称 + /// + public string PortName { get; set; } = ""; + /// + /// 港口中文名称 + /// + public string CnName { get; set; }= ""; + /// + /// 国家名称 + /// + public string CountryName { get; set; }= ""; + /// + /// 所在大洲 + /// + public string Chau { get; set; }= ""; + /// + /// 说明 + /// + public string Explain { get; set; }= ""; + /// + /// 港口类型 + /// + public string PortType { get; set; }= ""; + + /// + /// 国家Id + /// + public long CountryId { get; set; } = 0; + /// + /// 航线Id + /// + public long LaneId { get; set; }= 0; + /// + /// EDI代码 + /// + public string EdiCode { get; set; } = ""; +} + \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.Core/Code/Interface/ICodeInfoImportService.cs b/ds-wms-service/DS.WMS.Core/Code/Interface/ICodeInfoImportService.cs new file mode 100644 index 00000000..06359db4 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Code/Interface/ICodeInfoImportService.cs @@ -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 + { + /// + /// 按Excel导入包装 + /// + /// + /// + public Task> ImportPackageByExcel(IFormFile file); + + /// + /// 按Excel导入集装箱 + /// + /// + /// + public Task> ImportCtnByExcel(IFormFile file); + + /// + /// 按Excel导入国家信息 + /// + /// + /// + public Task> ImportCountryByExcel(IFormFile file); + + /// + /// 按Excel导入商品信息 + /// + /// + /// + public Task> ImportGoodsByExcel(IFormFile file); + + /// + /// 按Excel导入港口信息 + /// + /// + /// + public Task> ImportPortByExcel(IFormFile file); + } +} diff --git a/ds-wms-service/DS.WMS.Core/Code/Method/CodeInfoImportService.cs b/ds-wms-service/DS.WMS.Core/Code/Method/CodeInfoImportService.cs new file mode 100644 index 00000000..0316a5d2 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Code/Method/CodeInfoImportService.cs @@ -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; + /// + /// + /// + /// + public CodeInfoImportService(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + db = _serviceProvider.GetRequiredService(); + user = _serviceProvider.GetRequiredService(); + saasService = _serviceProvider.GetRequiredService(); + } + /// + /// 按Excel导入包装 + /// + /// + /// + public async Task> ImportPackageByExcel(IFormFile file) + { + //未上传文件 + if (file == null || file.Length == 0) + { + return await Task.FromResult(DataResult.Failed("请上传Excel!")); + } + var formFile = file; + //DataResult api_Result = new Api_Result(); + //获取文件名 + var fileName = formFile.FileName; + // 获取文件后缀 + var fileExtension = Path.GetExtension(fileName); + // 判断后缀是否是xlsx或者xls + if (fileExtension != ".xlsx" && fileExtension != ".xls") + { + return DataResult.Failed("文件格式错误"); + } + var length = formFile.Length; + if (length > 1024 * 1024 * 10) + { + return DataResult.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(); + var packages = new List(); + 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().Where(x => codes.Contains(x.SystemCode)).Any()) + //{ + + // return DataResult.Failed("存在已有的系统编码,请检查"); + //} + //var configs = list.Adapt(); + await db.Insertable(packages).ExecuteCommandAsync(); + + return await Task.FromResult(DataResult.Failed("导入成功!", MultiLanguageConst.DataImportSuccess)); + + } + } + /// + /// 按Excel导入集装箱信息 + /// + /// + /// + public async Task> ImportCtnByExcel(IFormFile file) + { + //未上传文件 + if (file == null || file.Length == 0) + { + return await Task.FromResult(DataResult.Failed("请上传Excel!")); + } + var formFile = file; + //DataResult api_Result = new Api_Result(); + //获取文件名 + var fileName = formFile.FileName; + // 获取文件后缀 + var fileExtension = Path.GetExtension(fileName); + // 判断后缀是否是xlsx或者xls + if (fileExtension != ".xlsx" && fileExtension != ".xls") + { + return DataResult.Failed("文件格式错误"); + } + var length = formFile.Length; + if (length > 1024 * 1024 * 10) + { + return DataResult.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(); + var ctns = new List(); + 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().Where(x => codes.Contains(x.SystemCode)).Any()) + //{ + + // return DataResult.Failed("存在已有的系统编码,请检查"); + //} + //var configs = list.Adapt(); + await db.Insertable(ctns).ExecuteCommandAsync(); + + return await Task.FromResult(DataResult.Failed("导入成功!", MultiLanguageConst.DataImportSuccess)); + + } + } + /// + /// 按Excel导入国家信息 + /// + /// + /// + public async Task> ImportCountryByExcel(IFormFile file) + { + //未上传文件 + if (file == null || file.Length == 0) + { + return await Task.FromResult(DataResult.Failed("请上传Excel!")); + } + var formFile = file; + //DataResult api_Result = new Api_Result(); + //获取文件名 + var fileName = formFile.FileName; + // 获取文件后缀 + var fileExtension = Path.GetExtension(fileName); + // 判断后缀是否是xlsx或者xls + if (fileExtension != ".xlsx" && fileExtension != ".xls") + { + return DataResult.Failed("文件格式错误"); + } + var length = formFile.Length; + if (length > 1024 * 1024 * 10) + { + return DataResult.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(); + var countries = new List(); + 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.Failed("导入成功!", MultiLanguageConst.DataImportSuccess)); + + } + } + + /// + /// 按Excel导入商品信息 + /// + /// + /// + public async Task> ImportGoodsByExcel(IFormFile file) + { + //未上传文件 + if (file == null || file.Length == 0) + { + return await Task.FromResult(DataResult.Failed("请上传Excel!")); + } + var formFile = file; + //DataResult api_Result = new Api_Result(); + //获取文件名 + var fileName = formFile.FileName; + // 获取文件后缀 + var fileExtension = Path.GetExtension(fileName); + // 判断后缀是否是xlsx或者xls + if (fileExtension != ".xlsx" && fileExtension != ".xls") + { + return DataResult.Failed("文件格式错误"); + } + var length = formFile.Length; + if (length > 1024 * 1024 * 10) + { + return DataResult.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(); + var goods = new List(); + 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.Failed("导入成功!", MultiLanguageConst.DataImportSuccess)); + + } + } + + /// + /// 按Excel导入港口信息 + /// + /// + /// + public async Task> ImportPortByExcel(IFormFile file) + { + //未上传文件 + if (file == null || file.Length == 0) + { + return await Task.FromResult(DataResult.Failed("请上传Excel!")); + } + var formFile = file; + //DataResult api_Result = new Api_Result(); + //获取文件名 + var fileName = formFile.FileName; + // 获取文件后缀 + var fileExtension = Path.GetExtension(fileName); + // 判断后缀是否是xlsx或者xls + if (fileExtension != ".xlsx" && fileExtension != ".xls") + { + return DataResult.Failed("文件格式错误"); + } + var length = formFile.Length; + if (length > 1024 * 1024 * 10) + { + return DataResult.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(); + var ports = new List(); + 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.Failed("导入成功!", MultiLanguageConst.DataImportSuccess)); + + } + } + } +}