diff --git a/ds-wms-service/DS.Module.ExcelModule/EPPlusService.cs b/ds-wms-service/DS.Module.ExcelModule/EPPlusService.cs new file mode 100644 index 00000000..608dbd9d --- /dev/null +++ b/ds-wms-service/DS.Module.ExcelModule/EPPlusService.cs @@ -0,0 +1,179 @@ +using DS.Module.Core; +using DS.Module.ExcelModule.Model; +using LanguageExt.ClassInstances; +using LanguageExt; +using Microsoft.AspNet.SignalR.Hubs; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.DependencyInjection; +using MiniExcelLibs; +using Newtonsoft.Json.Linq; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NPOI.SS.UserModel; +using OfficeOpenXml; +using System.Data; +using Spire.Xls; + +namespace DS.Module.ExcelModule +{ + public class EPPlusService : IEPPlusService + { + private readonly IServiceProvider _serviceProvider; + private static string GetString(object obj) + { + try + { + if (obj == null) return ""; + return obj.ToString(); + } + catch (Exception ex) + { + return ""; + } + } + + /// + ///将指定的Excel的文件转换成DataTable (Excel的第一个sheet) + /// + /// 文件的绝对路径 + /// + public DataTable WorksheetToTable(string fullFielPath, int SheetIndex = 1) + { + try + { + string[] PathNames = fullFielPath.Split(new string[] { @"/" }, StringSplitOptions.RemoveEmptyEntries); + var ExcelFileName = PathNames[PathNames.Length - 1]; + + if (ExcelFileName.EndsWith(".xls")) + { + + var newExcelFileName = PathNames[PathNames.Length - 1].Replace(".xls", ".xlsx"); + + var _newFileFullname = Path.GetDirectoryName(fullFielPath) + "/" + newExcelFileName; + + Workbook book = new Workbook(); + book.LoadFromFile(fullFielPath); + book.SaveToFile(_newFileFullname, ExcelVersion.Version2013); + + fullFielPath = _newFileFullname; + } + + + FileInfo existingFile = new FileInfo(fullFielPath); + + ExcelPackage package = new ExcelPackage(existingFile); + ExcelWorksheet worksheet = package.Workbook.Worksheets[SheetIndex];//选定 指定页 + + return WorksheetToTable(worksheet); + } + catch (Exception e) + { + throw; + } + } + + public DataTable WorksheetToTable_NoTitle(string fullFielPath, int SheetIndex = 1) + { + try + { + string[] PathNames = fullFielPath.Split(new string[] { @"/" }, StringSplitOptions.RemoveEmptyEntries); + var ExcelFileName = PathNames[PathNames.Length - 1]; + + if (ExcelFileName.EndsWith(".xls")) + { + + var newExcelFileName = PathNames[PathNames.Length - 1].Replace(".xls", ".xlsx"); + + var _newFileFullname = Path.GetDirectoryName(fullFielPath) + "/" + newExcelFileName; + + Workbook book = new Workbook(); + book.LoadFromFile(fullFielPath); + book.SaveToFile(_newFileFullname, ExcelVersion.Version2013); + + fullFielPath = _newFileFullname; + } + + + FileInfo existingFile = new FileInfo(fullFielPath); + + ExcelPackage package = new ExcelPackage(existingFile); + ExcelWorksheet worksheet = package.Workbook.Worksheets[SheetIndex];//选定 指定页 + + return WorksheetToTable_NoTitle(worksheet); + } + catch (Exception e) + { + throw; + } + } + + /// + /// 将worksheet转成datatable + /// + /// 待处理的worksheet + /// 返回处理后的datatable + public DataTable WorksheetToTable(ExcelWorksheet worksheet) + { + //获取worksheet的行数 + int rows = worksheet.Dimension.End.Row; + //获取worksheet的列数 + int cols = worksheet.Dimension.End.Column; + + DataTable dt = new DataTable(worksheet.Name); + DataRow dr = null; + for (int i = 1; i <= rows; i++) + { + if (i > 1) + dr = dt.Rows.Add(); + + for (int j = 1; j <= cols; j++) + { + //默认将第一行设置为datatable的标题 + if (i == 1) + dt.Columns.Add(GetString(worksheet.Cells[i, j].Value)); + //剩下的写入datatable + else + dr[j - 1] = GetString(worksheet.Cells[i, j].Value); + } + } + return dt; + } + + public DataTable WorksheetToTable_NoTitle(ExcelWorksheet worksheet) + { + //获取worksheet的行数 + int rows = worksheet.Dimension.End.Row; + //获取worksheet的列数 + int cols = worksheet.Dimension.End.Column; + + DataTable dt = new DataTable(worksheet.Name); + DataRow dr = null; + for (int i = 1; i <= rows; i++) + { + //if (i > 1) + dr = dt.Rows.Add(); + + for (int j = 1; j <= cols; j++) + { + //默认将第一行设置为datatable的标题 + if (i == 1) + { + dt.Columns.Add(GetString(worksheet.Cells[i, j].Value)); + dr[j - 1] = GetString(worksheet.Cells[i, j].Value); + } + //剩下的写入datatable + else + { + dr[j - 1] = GetString(worksheet.Cells[i, j].Value); + } + } + } + return dt; + } + + } +} diff --git a/ds-wms-service/DS.Module.ExcelModule/ExcelService.cs b/ds-wms-service/DS.Module.ExcelModule/ExcelService.cs index 9b00c669..0039da56 100644 --- a/ds-wms-service/DS.Module.ExcelModule/ExcelService.cs +++ b/ds-wms-service/DS.Module.ExcelModule/ExcelService.cs @@ -56,6 +56,7 @@ namespace DS.Module.ExcelModule return DataResult.Success(path); } + public MemoryStream ExportExcelStreamByColumn(ExportByColumnReq req) { var filename = Guid.NewGuid() + ".xlsx"; diff --git a/ds-wms-service/DS.Module.ExcelModule/IEPPlusService.cs b/ds-wms-service/DS.Module.ExcelModule/IEPPlusService.cs new file mode 100644 index 00000000..63ce5f30 --- /dev/null +++ b/ds-wms-service/DS.Module.ExcelModule/IEPPlusService.cs @@ -0,0 +1,19 @@ +using DS.Module.Core; +using DS.Module.ExcelModule.Model; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DS.Module.ExcelModule +{ + public interface IEPPlusService + { + public DataTable WorksheetToTable(string fullFielPath, int SheetIndex = 1); + + public DataTable WorksheetToTable_NoTitle(string fullFielPath, int SheetIndex = 1); + } +} diff --git a/ds-wms-service/DS.Module.Nuget/DS.Module.Nuget.csproj b/ds-wms-service/DS.Module.Nuget/DS.Module.Nuget.csproj index f8d32785..77021e1e 100644 --- a/ds-wms-service/DS.Module.Nuget/DS.Module.Nuget.csproj +++ b/ds-wms-service/DS.Module.Nuget/DS.Module.Nuget.csproj @@ -15,6 +15,7 @@ + @@ -50,6 +51,7 @@ + diff --git a/ds-wms-service/DS.WMS.Core/ContainerManagement/Method/CM_BaseInfoService.cs b/ds-wms-service/DS.WMS.Core/ContainerManagement/Method/CM_BaseInfoService.cs index 962f0b72..b6e787af 100644 --- a/ds-wms-service/DS.WMS.Core/ContainerManagement/Method/CM_BaseInfoService.cs +++ b/ds-wms-service/DS.WMS.Core/ContainerManagement/Method/CM_BaseInfoService.cs @@ -17,7 +17,11 @@ using DS.WMS.Core.Sys.Entity; using Mapster; using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json; +using NPOI.HPSF; using SqlSugar; +using DS.Module; +using DS.Module.ExcelModule; +using DS.Module.ExcelModule.Model; namespace DS.WMS.ContainerManagement.Info.Method; @@ -27,6 +31,7 @@ public class CM_BaseInfoService : ICM_BaseInfoService private readonly ISqlSugarClient db; private readonly IUser user; private readonly ISaasDbService saasService; + private readonly IEPPlusService epplusService; /// /// @@ -38,6 +43,7 @@ public class CM_BaseInfoService : ICM_BaseInfoService db = _serviceProvider.GetRequiredService(); user = _serviceProvider.GetRequiredService(); saasService = _serviceProvider.GetRequiredService(); + epplusService = _serviceProvider.GetRequiredService(); } /// @@ -264,6 +270,11 @@ public class CM_BaseInfoService : ICM_BaseInfoService /// public DataResult CM_DealExcel(CM_DealExcelReq req) { + + var _dt = epplusService.WorksheetToTable("excel文件地址"); + + + return DataResult.Successed($"调用成功!{JsonConvert.SerializeObject(req)}", MultiLanguageConst.DataUpdateSuccess); var tenantDb = saasService.GetBizDbScopeById(user.TenantId); @@ -280,6 +291,8 @@ public class CM_BaseInfoService : ICM_BaseInfoService { return DataResult.Successed($"", MultiLanguageConst.DataUpdateSuccess); + + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); diff --git a/ds-wms-service/DS.WMS.Core/DS.WMS.Core.csproj b/ds-wms-service/DS.WMS.Core/DS.WMS.Core.csproj index abd819bc..abc0c171 100644 --- a/ds-wms-service/DS.WMS.Core/DS.WMS.Core.csproj +++ b/ds-wms-service/DS.WMS.Core/DS.WMS.Core.csproj @@ -45,6 +45,7 @@ + diff --git a/ds-wms-service/DS.WMS.Core/Op/EDI/YTEdiHelper.cs b/ds-wms-service/DS.WMS.Core/Op/EDI/YTEdiHelper.cs index 624ec52a..f3a07dc7 100644 --- a/ds-wms-service/DS.WMS.Core/Op/EDI/YTEdiHelper.cs +++ b/ds-wms-service/DS.WMS.Core/Op/EDI/YTEdiHelper.cs @@ -431,6 +431,11 @@ namespace DS.WMS.Core.Op.EDI } } + if (!new string[] { "ORI", "TER", "EXP" }.Contains(headData.ISSUETYPE)) + { + error = error + "
提单号:" + headData.MBLNO + "签单方式未识别"; + } + if (string.IsNullOrEmpty(headData.DESCRIPTION)) { error = error + "
提单号:" + headData.MBLNO + " 货物描述不能为空"; @@ -831,15 +836,20 @@ namespace DS.WMS.Core.Op.EDI } else ISSUETYPE = "EXP"; */ - if (bill.ISSUETYPE == "ORIGINAL") - { - ISSUETYPE = "ORI"; - } - else if (bill.ISSUETYPE == "TELEX") + //if (bill.ISSUETYPE == "ORIGINAL") + //{ + // ISSUETYPE = "ORI"; + //} + //else if (bill.ISSUETYPE == "TELEX") + //{ + // ISSUETYPE = "TER"; + //} + //else ISSUETYPE = "EXP"; + + if(new string[] { "ORI", "TER", "EXP" }.Contains(bill.ISSUETYPE)) { - ISSUETYPE = "TER"; + ISSUETYPE = bill.ISSUETYPE; } - else ISSUETYPE = "EXP"; r.WriteLine("03:" + ISSUETYPE + ":" + bill.ISSUEPLACEID.Trim() + ":" + bill.ISSUEPLACE.Trim() + ":" + GetDateStr(bill.ISSUEDATE, "yyyyMMdd") + ":" + GetBillNum2(bill.NOBILL) + ":" + bill.PREPARDAT + ":" + bill.PAYABLEAT + "'"); icount++; diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/SeaExportBookingOrClosingEDIService.cs b/ds-wms-service/DS.WMS.Core/Op/Method/SeaExportBookingOrClosingEDIService.cs index 91e7f764..a3641dda 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Method/SeaExportBookingOrClosingEDIService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Method/SeaExportBookingOrClosingEDIService.cs @@ -1383,12 +1383,19 @@ namespace DS.WMS.Core.Op.Method #region 签单方式EDI ////签单方式EDI - if (!string.IsNullOrWhiteSpace(order.IssueType)) + if (!string.IsNullOrWhiteSpace(order.IssueTypeCode)) { - long issueTypeId = long.Parse(order.IssueType); + //long issueTypeId = long.Parse(order.IssueType); + + var codeIssue = tenantDb.Queryable().First(t => t.EdiCode == order.IssueTypeCode); + + if (codeIssue == null) + { + return DataResult.Failed($"签单方式{order.IssueTypeCode}的基础代码未找到"); + } var mapInfo = tenantDb.Queryable() - .First(t => t.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase) && t.CarrierId == order.CarrierId && t.Id == issueTypeId); + .First(t => t.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase) && t.CarrierId == order.CarrierId && t.LinkId == codeIssue.Id); if (mapInfo != null) { @@ -1397,15 +1404,13 @@ namespace DS.WMS.Core.Op.Method else { //签单方式EDI - var codeService = tenantDb.Queryable().First(x => x.Status == StatusEnum.Enable && x.Id == issueTypeId); - - if (codeService != null && !string.IsNullOrWhiteSpace(codeService.EdiCode)) + if (codeIssue != null && !string.IsNullOrWhiteSpace(codeIssue.EdiCode)) { - primaryModel.ISSUETYPE = codeService.EdiCode; + primaryModel.ISSUETYPE = codeIssue.EdiCode; } else { - return DataResult.Failed($"签单方式{order.Service}的基础代码未找到"); + return DataResult.Failed($"签单方式{order.Service}的基础代码 EdiCode 未配置"); } } } @@ -1512,7 +1517,7 @@ namespace DS.WMS.Core.Op.Method primaryModel.EDIATTNEMAIL = ediExtModel.EDIAttnMail; - if (string.IsNullOrWhiteSpace(primaryModel.EDIATTNEMAIL)) + if (string.IsNullOrWhiteSpace(primaryModel.EDIATTNEMAIL) && ediRouteEnum != EDIRouteEnum.YT) { primaryModel.EDIATTNEMAIL = ftpSet.SendEmail; }