From 504f0f9e4b54f1fac1259e81df54f13577acc39d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ZR20090193-=E9=99=88=E6=95=AC=E5=8B=87?= Date: Mon, 20 May 2024 17:12:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E8=88=B1=E6=88=AA=E5=8D=95=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Constants/MultiLanguageConst.cs | 7 + .../{Enum => Enums}/AuditStatusEnum.cs | 0 .../DS.Module.Core/Enums/EDIRouteEnum.cs | 56 + .../{Enum => Enums}/FlowStatusEnum.cs | 0 .../{Enum => Enums}/ResultCode.cs | 0 .../{Enum => Enums}/StatusEnum.cs | 0 .../{Enum => Enums}/TenantTypeEnum.cs | 0 .../{Enum => Enums}/UserTypeEnum.cs | 0 .../Extensions/CollectionExtensions.cs | 4 +- .../DS.Module.Core/Extensions/Extensions.cs | 10 + .../DS.Module.Nuget/DS.Module.Nuget.csproj | 2 + .../DS.WMS.Core/Code/Dtos/CodeEdiSetReq.cs | 2 +- .../DS.WMS.Core/Code/Dtos/CodeEdiSetRes.cs | 2 +- .../DS.WMS.Core/Code/Dtos/CodeIssueTypeReq.cs | 7 + .../DS.WMS.Core/Code/Dtos/CodeIssueTypeRes.cs | 4 + .../DS.WMS.Core/Code/Dtos/CodeServiceReq.cs | 7 +- .../DS.WMS.Core/Code/Dtos/CodeServiceRes.cs | 7 +- .../DS.WMS.Core/Code/Entity/CodeEdiSet.cs | 2 +- .../DS.WMS.Core/Code/Entity/CodeIssueType.cs | 6 + .../DS.WMS.Core/Code/Entity/CodeService.cs | 8 +- ds-wms-service/DS.WMS.Core/DS.WMS.Core.csproj | 1 + .../DS.WMS.Core/Map/Dtos/MappingFrtReq.cs | 80 + .../DS.WMS.Core/Map/Dtos/MappingFrtRes.cs | 71 + .../Map/Dtos/MappingIssueTypeReq.cs | 5 +- .../Map/Dtos/MappingIssueTypeRes.cs | 5 +- .../DS.WMS.Core/Map/Entity/MappingFrt.cs | 57 + .../Map/Entity/MappingIssueType.cs | 7 +- .../Map/Interface/IMappingFrtService.cs | 49 + .../Map/Method/MappingFrtService.cs | 129 + .../DS.WMS.Core/Op/Dtos/EDIBaseModel.cs | 83 + .../Op/Dtos/SeaExportCtnDetailEDIBaseModel.cs | 58 + .../Op/Dtos/SeaExportCtnEDIBaseModel.cs | 87 + .../Op/Dtos/SeaExportEDIBaseModel.cs | 599 +++++ .../DS.WMS.Core/Op/Dtos/SeaExportEdiReq.cs | 196 ++ .../DS.WMS.Core/Op/Dtos/SeaExportEdiRes.cs | 197 ++ .../DS.WMS.Core/Op/Dtos/SeaExportReq.cs | 36 +- .../DS.WMS.Core/Op/Dtos/SeaExportRes.cs | 33 +- .../DS.WMS.Core/Op/EDI/ESLEdiHelper.cs | 1130 ++++++++ .../DS.WMS.Core/Op/EDI/EdiDataResult.cs | 63 + .../DS.WMS.Core/Op/EDI/EmailApiDto.cs | 33 + .../DS.WMS.Core/Op/EDI/InttraEdiHelper.cs | 2319 ++++++++++++++++ .../DS.WMS.Core/Op/EDI/MellEdiHelper.cs | 1097 ++++++++ .../DS.WMS.Core/Op/EDI/PILEdiHelper.cs | 1908 ++++++++++++++ .../DS.WMS.Core/Op/EDI/TSLEdiHelper.cs | 2157 +++++++++++++++ .../DS.WMS.Core/Op/EDI/VOLTAEdiHelper.cs | 344 +++ .../DS.WMS.Core/Op/EDI/WYEdiHelper.cs | 956 +++++++ .../DS.WMS.Core/Op/EDI/XiahuozhiHelpler.cs | 1576 +++++++++++ .../DS.WMS.Core/Op/EDI/YMLEdiHelper.cs | 1874 +++++++++++++ .../DS.WMS.Core/Op/EDI/YTEdiHelper.cs | 1205 +++++++++ .../DS.WMS.Core/Op/Entity/SeaExport.cs | 89 +- .../DS.WMS.Core/Op/Entity/SeaExportEdi.cs | 223 ++ .../Op/Interface/ISeaExportService.cs | 6 + .../Op/Method/OpCtnDetailService.cs | 2 +- .../DS.WMS.Core/Op/Method/SeaExportService.cs | 2330 +++++++++++++++-- .../Controllers/MappingFrtController.cs | 92 + .../Controllers/SeaExportController.cs | 12 + .../DS.WMS.OpApi/Logs/internal-nlog.txt | 28 + ds-wms-service/DS.WMS.OpApi/appsettings.json | 10 + ds-wms-service/DS.WMS.Test/SaasTest.cs | 12 +- 59 files changed, 19065 insertions(+), 218 deletions(-) rename ds-wms-service/DS.Module.Core/{Enum => Enums}/AuditStatusEnum.cs (100%) create mode 100644 ds-wms-service/DS.Module.Core/Enums/EDIRouteEnum.cs rename ds-wms-service/DS.Module.Core/{Enum => Enums}/FlowStatusEnum.cs (100%) rename ds-wms-service/DS.Module.Core/{Enum => Enums}/ResultCode.cs (100%) rename ds-wms-service/DS.Module.Core/{Enum => Enums}/StatusEnum.cs (100%) rename ds-wms-service/DS.Module.Core/{Enum => Enums}/TenantTypeEnum.cs (100%) rename ds-wms-service/DS.Module.Core/{Enum => Enums}/UserTypeEnum.cs (100%) create mode 100644 ds-wms-service/DS.WMS.Core/Map/Dtos/MappingFrtReq.cs create mode 100644 ds-wms-service/DS.WMS.Core/Map/Dtos/MappingFrtRes.cs create mode 100644 ds-wms-service/DS.WMS.Core/Map/Entity/MappingFrt.cs create mode 100644 ds-wms-service/DS.WMS.Core/Map/Interface/IMappingFrtService.cs create mode 100644 ds-wms-service/DS.WMS.Core/Map/Method/MappingFrtService.cs create mode 100644 ds-wms-service/DS.WMS.Core/Op/Dtos/EDIBaseModel.cs create mode 100644 ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportCtnDetailEDIBaseModel.cs create mode 100644 ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportCtnEDIBaseModel.cs create mode 100644 ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportEDIBaseModel.cs create mode 100644 ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportEdiReq.cs create mode 100644 ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportEdiRes.cs create mode 100644 ds-wms-service/DS.WMS.Core/Op/EDI/ESLEdiHelper.cs create mode 100644 ds-wms-service/DS.WMS.Core/Op/EDI/EdiDataResult.cs create mode 100644 ds-wms-service/DS.WMS.Core/Op/EDI/EmailApiDto.cs create mode 100644 ds-wms-service/DS.WMS.Core/Op/EDI/InttraEdiHelper.cs create mode 100644 ds-wms-service/DS.WMS.Core/Op/EDI/MellEdiHelper.cs create mode 100644 ds-wms-service/DS.WMS.Core/Op/EDI/PILEdiHelper.cs create mode 100644 ds-wms-service/DS.WMS.Core/Op/EDI/TSLEdiHelper.cs create mode 100644 ds-wms-service/DS.WMS.Core/Op/EDI/VOLTAEdiHelper.cs create mode 100644 ds-wms-service/DS.WMS.Core/Op/EDI/WYEdiHelper.cs create mode 100644 ds-wms-service/DS.WMS.Core/Op/EDI/XiahuozhiHelpler.cs create mode 100644 ds-wms-service/DS.WMS.Core/Op/EDI/YMLEdiHelper.cs create mode 100644 ds-wms-service/DS.WMS.Core/Op/EDI/YTEdiHelper.cs create mode 100644 ds-wms-service/DS.WMS.Core/Op/Entity/SeaExportEdi.cs create mode 100644 ds-wms-service/DS.WMS.MainApi/Controllers/MappingFrtController.cs diff --git a/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs b/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs index b93ef169..2251dc30 100644 --- a/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs +++ b/ds-wms-service/DS.Module.Core/Constants/MultiLanguageConst.cs @@ -69,6 +69,13 @@ public static class MultiLanguageConst [Description("箱型映射信息不存在")] public const string MappingCtnNotExist = "MappingCtn_Not_Exist"; + + [Description("付款方式映射信息已存在")] + public const string MappingFrtExist = "MappingFrt_Exist"; + + [Description("付款方式映射信息不存在")] + public const string MappingFrtNotExist = "MappingFrt_Not_Exist"; + [Description("包装映射信息已存在")] public const string MappingPackageExist = "MappingPackage_Exist"; diff --git a/ds-wms-service/DS.Module.Core/Enum/AuditStatusEnum.cs b/ds-wms-service/DS.Module.Core/Enums/AuditStatusEnum.cs similarity index 100% rename from ds-wms-service/DS.Module.Core/Enum/AuditStatusEnum.cs rename to ds-wms-service/DS.Module.Core/Enums/AuditStatusEnum.cs diff --git a/ds-wms-service/DS.Module.Core/Enums/EDIRouteEnum.cs b/ds-wms-service/DS.Module.Core/Enums/EDIRouteEnum.cs new file mode 100644 index 00000000..e1c9c7cc --- /dev/null +++ b/ds-wms-service/DS.Module.Core/Enums/EDIRouteEnum.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DS.Module.Core +{ + /// + /// 订舱或截单通道枚举 + /// + public enum EDIRouteEnum + { + /// + /// 德翔 + /// + TSL, + /// + /// 太平 + /// + PIL, + /// + /// 阳明 + /// + YML, + /// + /// 易通(适用ONE) + /// + YT, + /// + /// + /// + WY, + /// + /// 未指定 + /// + NULL, + + /// + /// 阿联酋航运 + /// + ESL, + /// + /// 玛丽亚娜 + /// + MELL, + /// + /// 沃尔塔航运 + /// + VOL, + /// + /// INTTRA + /// + INTTRA + } +} diff --git a/ds-wms-service/DS.Module.Core/Enum/FlowStatusEnum.cs b/ds-wms-service/DS.Module.Core/Enums/FlowStatusEnum.cs similarity index 100% rename from ds-wms-service/DS.Module.Core/Enum/FlowStatusEnum.cs rename to ds-wms-service/DS.Module.Core/Enums/FlowStatusEnum.cs diff --git a/ds-wms-service/DS.Module.Core/Enum/ResultCode.cs b/ds-wms-service/DS.Module.Core/Enums/ResultCode.cs similarity index 100% rename from ds-wms-service/DS.Module.Core/Enum/ResultCode.cs rename to ds-wms-service/DS.Module.Core/Enums/ResultCode.cs diff --git a/ds-wms-service/DS.Module.Core/Enum/StatusEnum.cs b/ds-wms-service/DS.Module.Core/Enums/StatusEnum.cs similarity index 100% rename from ds-wms-service/DS.Module.Core/Enum/StatusEnum.cs rename to ds-wms-service/DS.Module.Core/Enums/StatusEnum.cs diff --git a/ds-wms-service/DS.Module.Core/Enum/TenantTypeEnum.cs b/ds-wms-service/DS.Module.Core/Enums/TenantTypeEnum.cs similarity index 100% rename from ds-wms-service/DS.Module.Core/Enum/TenantTypeEnum.cs rename to ds-wms-service/DS.Module.Core/Enums/TenantTypeEnum.cs diff --git a/ds-wms-service/DS.Module.Core/Enum/UserTypeEnum.cs b/ds-wms-service/DS.Module.Core/Enums/UserTypeEnum.cs similarity index 100% rename from ds-wms-service/DS.Module.Core/Enum/UserTypeEnum.cs rename to ds-wms-service/DS.Module.Core/Enums/UserTypeEnum.cs diff --git a/ds-wms-service/DS.Module.Core/Extensions/CollectionExtensions.cs b/ds-wms-service/DS.Module.Core/Extensions/CollectionExtensions.cs index 0ed9a10f..7672b6d6 100644 --- a/ds-wms-service/DS.Module.Core/Extensions/CollectionExtensions.cs +++ b/ds-wms-service/DS.Module.Core/Extensions/CollectionExtensions.cs @@ -57,7 +57,7 @@ public static partial class Extensions /// 数据源 /// 键条件 /// - public static IEnumerable DistinctBy(this IEnumerable source, + public static IEnumerable SqlSugarDistinctBy(this IEnumerable source, Func keySelector) { return source.GroupBy(keySelector).Select(gropby => gropby.First()); @@ -74,7 +74,7 @@ public static partial class Extensions public static IList ToDistinctBy(this IEnumerable source, Func keySelector) { - return source.DistinctBy(keySelector).ToList(); + return source.SqlSugarDistinctBy(keySelector).ToList(); } /// diff --git a/ds-wms-service/DS.Module.Core/Extensions/Extensions.cs b/ds-wms-service/DS.Module.Core/Extensions/Extensions.cs index b1c64dbf..21a43ec7 100644 --- a/ds-wms-service/DS.Module.Core/Extensions/Extensions.cs +++ b/ds-wms-service/DS.Module.Core/Extensions/Extensions.cs @@ -573,4 +573,14 @@ public static partial class Extensions return jt as JObject; } + + /// + /// JSON 字符串转 JObject + /// + /// + /// + public static JObject ToJObject(this string json) + { + return json == null ? JObject.Parse("{}") : JObject.Parse(json.Replace(" ", "")); + } } \ No newline at end of file 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 e5af8014..7c616a6d 100644 --- a/ds-wms-service/DS.Module.Nuget/DS.Module.Nuget.csproj +++ b/ds-wms-service/DS.Module.Nuget/DS.Module.Nuget.csproj @@ -32,6 +32,8 @@ + + diff --git a/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeEdiSetReq.cs b/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeEdiSetReq.cs index e7040d24..0709b0a2 100644 --- a/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeEdiSetReq.cs +++ b/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeEdiSetReq.cs @@ -30,7 +30,7 @@ namespace DS.WMS.Core.Code.Dtos /// /// 文件夹 /// - public string FOLDERNAME { get; set; } + public string FolderName { get; set; } /// /// 用户名 /// diff --git a/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeEdiSetRes.cs b/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeEdiSetRes.cs index 9f05efda..865d8f96 100644 --- a/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeEdiSetRes.cs +++ b/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeEdiSetRes.cs @@ -31,7 +31,7 @@ namespace DS.WMS.Core.Code.Dtos /// /// 文件夹 /// - public string FOLDERNAME { get; set; } + public string FolderName { get; set; } /// /// 用户名 /// diff --git a/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeIssueTypeReq.cs b/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeIssueTypeReq.cs index 84f38456..df6488f3 100644 --- a/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeIssueTypeReq.cs +++ b/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeIssueTypeReq.cs @@ -1,5 +1,6 @@ using DS.Module.Core; using FluentValidation; +using SqlSugar; namespace DS.WMS.Core.Code.Dtos; @@ -29,6 +30,10 @@ public class CodeIssueTypeReq /// public string CopyNoBill { get; set; } /// + /// EDI代码 + /// + public string EdiCode { get; set; } + /// /// 状态 0 启用 1 禁用 /// public StatusEnum? Status { get; set; } = StatusEnum.Enable; @@ -52,5 +57,7 @@ public class CodeIssueTypeReqValidator : AbstractValidator .NotEmpty().WithName("签单方式"); this.RuleFor(o => o.EnName) .NotEmpty().WithName("英文名称"); + this.RuleFor(o => o.EdiCode) + .NotEmpty().WithName("EDI代码"); } } \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeIssueTypeRes.cs b/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeIssueTypeRes.cs index 20f601e3..1f79fe58 100644 --- a/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeIssueTypeRes.cs +++ b/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeIssueTypeRes.cs @@ -28,6 +28,10 @@ public class CodeIssueTypeRes /// public string CopyNoBill { get; set; } /// + /// EDI代码 + /// + public string EdiCode { get; set; } + /// /// 状态 0 启用 1 禁用 /// public StatusEnum? Status { get; set; } = StatusEnum.Enable; diff --git a/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeServiceReq.cs b/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeServiceReq.cs index e3419e9e..e12f86d5 100644 --- a/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeServiceReq.cs +++ b/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeServiceReq.cs @@ -21,7 +21,10 @@ public class CodeServiceReq /// 中文名称 /// public string CnName { get; set; }= ""; - + /// + /// EDI代码 + /// + public string EdiCode { get; set; } /// /// 状态 0 启用 1 禁用 /// @@ -44,5 +47,7 @@ public class CodeServiceReqValidator : AbstractValidator { this.RuleFor(o => o.ServiceName) .NotEmpty().WithName("运输条款-英文名称"); + this.RuleFor(o => o.EdiCode) + .NotEmpty().WithName("EDI代码"); } } \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeServiceRes.cs b/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeServiceRes.cs index 209cf8e6..e6f1f866 100644 --- a/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeServiceRes.cs +++ b/ds-wms-service/DS.WMS.Core/Code/Dtos/CodeServiceRes.cs @@ -19,8 +19,11 @@ public class CodeServiceRes /// 中文名称 /// public string CnName { get; set; } - - + + /// + /// EDI代码 + /// + public string EdiCode { get; set; } /// /// 状态 0 启用 1 禁用 /// diff --git a/ds-wms-service/DS.WMS.Core/Code/Entity/CodeEdiSet.cs b/ds-wms-service/DS.WMS.Core/Code/Entity/CodeEdiSet.cs index 4171a87a..082ee7e8 100644 --- a/ds-wms-service/DS.WMS.Core/Code/Entity/CodeEdiSet.cs +++ b/ds-wms-service/DS.WMS.Core/Code/Entity/CodeEdiSet.cs @@ -28,7 +28,7 @@ public class CodeEdiSet : BaseModel /// 文件夹 /// [SugarColumn(ColumnDescription = "文件夹", Length = 40,IsNullable = true)] - public string FOLDERNAME { get; set; } + public string FolderName { get; set; } /// /// 用户名 /// diff --git a/ds-wms-service/DS.WMS.Core/Code/Entity/CodeIssueType.cs b/ds-wms-service/DS.WMS.Core/Code/Entity/CodeIssueType.cs index 5cd47644..f03e5e27 100644 --- a/ds-wms-service/DS.WMS.Core/Code/Entity/CodeIssueType.cs +++ b/ds-wms-service/DS.WMS.Core/Code/Entity/CodeIssueType.cs @@ -30,6 +30,12 @@ public class CodeIssueType: BaseModel /// [SugarColumn(ColumnDescription = "副本份数", Length = 5,IsNullable = true)] public string CopyNoBill { get; set; } + + /// + /// EDI代码 + /// + [SugarColumn(ColumnDescription = "EDI代码", Length = 5, IsNullable = true)] + public string EdiCode { get; set; } /// /// 状态 0启用 1禁用 /// diff --git a/ds-wms-service/DS.WMS.Core/Code/Entity/CodeService.cs b/ds-wms-service/DS.WMS.Core/Code/Entity/CodeService.cs index f9524178..321126ec 100644 --- a/ds-wms-service/DS.WMS.Core/Code/Entity/CodeService.cs +++ b/ds-wms-service/DS.WMS.Core/Code/Entity/CodeService.cs @@ -19,8 +19,12 @@ public class CodeService: BaseModel /// [SugarColumn(ColumnDescription = "中文名称", Length = 50,IsNullable = true)] public string CnName { get; set; } - - + + /// + /// EDI代码 + /// + [SugarColumn(ColumnDescription = "EDI代码", Length = 5, IsNullable = true)] + public string EdiCode { get; set; } /// /// 状态 0启用 1禁用 /// 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 a802aba9..1b3e1ed2 100644 --- a/ds-wms-service/DS.WMS.Core/DS.WMS.Core.csproj +++ b/ds-wms-service/DS.WMS.Core/DS.WMS.Core.csproj @@ -26,6 +26,7 @@ + diff --git a/ds-wms-service/DS.WMS.Core/Map/Dtos/MappingFrtReq.cs b/ds-wms-service/DS.WMS.Core/Map/Dtos/MappingFrtReq.cs new file mode 100644 index 00000000..c8a48baf --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Map/Dtos/MappingFrtReq.cs @@ -0,0 +1,80 @@ +using DS.Module.Core; +using DS.WMS.Core.Code.Dtos; +using FluentValidation; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DS.WMS.Core.Map.Dtos +{ + /// + /// 付款方式映射信息请求 + /// + public class MappingFrtReq + { + /// + /// 主键Id + /// + public long Id { get; set; } + + /// + /// 关联业务id + /// + public long LinkId { get; set; } + /// + /// 代码 + /// + public string Code { get; set; } + /// + /// 模块 + /// + public string Module { get; set; } + + /// + /// 映射代码 + /// + public string MapCode { get; set; } + + /// + /// 映射名称 + /// + public string MapName { get; set; } + + /// + /// 船司Id + /// + public long CarrierId { get; set; } + + /// + /// 状态 0 启用 1 禁用 + /// + public StatusEnum? Status { get; set; } = StatusEnum.Enable; + /// + /// 备注 + /// + public string Note { get; set; } = ""; + } + /// + /// 验证 + /// + public class MappingFrtReqValidator : AbstractValidator + { + /// + /// 构造函数 + /// + public MappingFrtReqValidator() + { + this.RuleFor(o => o.LinkId) + .NotEmpty().WithName("付款方式Id"); + this.RuleFor(o => o.Module) + .NotEmpty().WithName("模块"); + this.RuleFor(o => o.MapCode) + .NotEmpty().WithName("映射代码"); + this.RuleFor(o => o.MapName) + .NotEmpty().WithName("映射名称"); + } + } +} diff --git a/ds-wms-service/DS.WMS.Core/Map/Dtos/MappingFrtRes.cs b/ds-wms-service/DS.WMS.Core/Map/Dtos/MappingFrtRes.cs new file mode 100644 index 00000000..4805a05f --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Map/Dtos/MappingFrtRes.cs @@ -0,0 +1,71 @@ +using DS.Module.Core; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DS.WMS.Core.Map.Dtos +{ + /// + /// 付款方式映射信息返回 + /// + public class MappingFrtRes + { + /// + /// 主键Id + /// + public long Id { get; set; } + + /// + /// 关联业务id + /// + public long LinkId { get; set; } + + /// + /// 代码 + /// + public string Code { get; set; } + + /// + /// 模块 + /// + public string Module { get; set; } + + /// + /// 映射代码 + /// + public string MapCode { get; set; } + + /// + /// 映射名称 + /// + public string MapName { get; set; } + /// + /// 付款方式名称 + /// + public string FrtName { get; set; } + /// + /// 船公司名称 + /// + public string CarrierName { get; set; } + /// + /// 船司Id + /// + public long CarrierId { get; set; } + + /// + /// 状态 0 启用 1 禁用 + /// + public StatusEnum? Status { get; set; } = StatusEnum.Enable; + /// + /// 备注 + /// + public string Note { get; set; } = ""; + /// + /// 创建时间 + /// + public DateTime CreateTime { get; set; } + } +} diff --git a/ds-wms-service/DS.WMS.Core/Map/Dtos/MappingIssueTypeReq.cs b/ds-wms-service/DS.WMS.Core/Map/Dtos/MappingIssueTypeReq.cs index 932fc97c..e1afbf3c 100644 --- a/ds-wms-service/DS.WMS.Core/Map/Dtos/MappingIssueTypeReq.cs +++ b/ds-wms-service/DS.WMS.Core/Map/Dtos/MappingIssueTypeReq.cs @@ -42,8 +42,11 @@ namespace DS.WMS.Core.Map.Dtos /// 映射名称 /// public string MapName { get; set; } - + /// + /// 船司Id + /// + public long CarrierId { get; set; } /// /// 状态 0 启用 1 禁用 /// diff --git a/ds-wms-service/DS.WMS.Core/Map/Dtos/MappingIssueTypeRes.cs b/ds-wms-service/DS.WMS.Core/Map/Dtos/MappingIssueTypeRes.cs index 9bf3d7ef..a94359db 100644 --- a/ds-wms-service/DS.WMS.Core/Map/Dtos/MappingIssueTypeRes.cs +++ b/ds-wms-service/DS.WMS.Core/Map/Dtos/MappingIssueTypeRes.cs @@ -46,7 +46,10 @@ namespace DS.WMS.Core.Map.Dtos ///// 签单方式名称 ///// //public string IssueTypeName { get; set; } - + /// + /// 船司Id + /// + public long CarrierId { get; set; } /// /// 状态 0 启用 1 禁用 /// diff --git a/ds-wms-service/DS.WMS.Core/Map/Entity/MappingFrt.cs b/ds-wms-service/DS.WMS.Core/Map/Entity/MappingFrt.cs new file mode 100644 index 00000000..6e872fc4 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Map/Entity/MappingFrt.cs @@ -0,0 +1,57 @@ +using DS.Module.Core; +using DS.Module.Core.Data; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DS.WMS.Core.Map.Entity +{ + /// + /// 付款方式映射信息 + /// + [SqlSugar.SugarTable("op_map_frt", "付款方式映射信息")] + public class MappingFrt : BaseModel + { + /// + /// 关联业务id + /// + public long LinkId { get; set; } + /// + /// 代码 + /// + [SugarColumn(ColumnDescription = "代码", Length = 100, IsNullable = false)] + public string Code { get; set; } + /// + /// 模块 + /// + [SugarColumn(ColumnDescription = "模块", Length = 100, IsNullable = false)] + public string Module { get; set; } + + /// + /// 映射代码 + /// + [SugarColumn(ColumnDescription = "映射代码", Length = 100, IsNullable = false)] + public string MapCode { get; set; } + + /// + /// 映射名称 + /// + [SugarColumn(ColumnDescription = "映射名称", Length = 100, IsNullable = true)] + public string MapName { get; set; } + + /// + /// 船司Id + /// + [SugarColumn(ColumnDescription = "船司Id", IsNullable = true,DefaultValue ="0")] + public long CarrierId { get; set; } + + /// + /// 状态 0启用 1禁用 + /// + [SugarColumn(ColumnDescription = "状态", DefaultValue = "0")] + public StatusEnum? Status { get; set; } = StatusEnum.Enable; + } +} diff --git a/ds-wms-service/DS.WMS.Core/Map/Entity/MappingIssueType.cs b/ds-wms-service/DS.WMS.Core/Map/Entity/MappingIssueType.cs index ae4cf4bd..3b79665a 100644 --- a/ds-wms-service/DS.WMS.Core/Map/Entity/MappingIssueType.cs +++ b/ds-wms-service/DS.WMS.Core/Map/Entity/MappingIssueType.cs @@ -41,7 +41,12 @@ namespace DS.WMS.Core.Map.Entity /// [SugarColumn(ColumnDescription = "映射名称", Length = 100, IsNullable = true)] public string MapName { get; set; } - + + /// + /// 船司Id + /// + [SugarColumn(ColumnDescription = "船司Id", IsNullable = true, DefaultValue = "0")] + public long CarrierId { get; set; } /// /// 状态 0启用 1禁用 /// diff --git a/ds-wms-service/DS.WMS.Core/Map/Interface/IMappingFrtService.cs b/ds-wms-service/DS.WMS.Core/Map/Interface/IMappingFrtService.cs new file mode 100644 index 00000000..5ecce67f --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Map/Interface/IMappingFrtService.cs @@ -0,0 +1,49 @@ +using DS.Module.Core; +using DS.Module.Core.Data; +using DS.WMS.Core.Map.Dtos; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DS.WMS.Core.Map.Interface +{ + public interface IMappingFrtService + { + /// + /// 列表 + /// + /// + /// + DataResult> GetListByPage(PageRequest request); + + + /// + /// 编辑 + /// + /// + /// + DataResult EditMappingFrt(MappingFrtReq req); + + /// + /// 获取详情 + /// + /// + /// + DataResult GetMappingFrtInfo(string id); + + /// + /// 删除 + /// + /// + /// + public DataResult DelMappingFrt(IdModel req); + /// + /// 批量删除 + /// + /// + /// + public DataResult BatchDelMappingFrt(IdModel req); + } +} diff --git a/ds-wms-service/DS.WMS.Core/Map/Method/MappingFrtService.cs b/ds-wms-service/DS.WMS.Core/Map/Method/MappingFrtService.cs new file mode 100644 index 00000000..7dcc052e --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Map/Method/MappingFrtService.cs @@ -0,0 +1,129 @@ +using DS.Module.Core; +using DS.Module.Core.Data; +using DS.Module.SqlSugar; +using DS.Module.UserModule; +using DS.WMS.Core.Code.Dtos; +using DS.WMS.Core.Info.Dtos; +using DS.WMS.Core.Info.Entity; +using DS.WMS.Core.Map.Dtos; +using DS.WMS.Core.Map.Entity; +using DS.WMS.Core.Map.Interface; +using Microsoft.Extensions.DependencyInjection; +using SqlSugar; +using DS.Module.Core.Extensions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Org.BouncyCastle.Ocsp; +using Mapster; +using DS.WMS.Core.Fee.Entity; +using DS.WMS.Core.Code.Entity; + +namespace DS.WMS.Core.Map.Method +{ + public class MappingFrtService : IMappingFrtService + { + private readonly IServiceProvider _serviceProvider; + private readonly ISqlSugarClient db; + private readonly IUser user; + private readonly ISaasDbService saasService; + /// + /// + /// + /// + public MappingFrtService(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + db = _serviceProvider.GetRequiredService(); + user = _serviceProvider.GetRequiredService(); + saasService = _serviceProvider.GetRequiredService(); + } + public DataResult BatchDelMappingFrt(IdModel req) + { + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); + var list = tenantDb.Queryable().Where(x => req.Ids.Contains(x.Id)).ToList(); + ; + if (list.Count > 0) + { + tenantDb.Deleteable(list).ExecuteCommand(); + } + return DataResult.Successed("删除成功!", MultiLanguageConst.DataDelSuccess); + } + + public DataResult DelMappingFrt(IdModel req) + { + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); + var info = tenantDb.Queryable().Where(x => x.Id == long.Parse(req.Id)).First(); + if (info == null) + { + return DataResult.Failed("付款方式映射信息不存在!", MultiLanguageConst.MappingFrtNotExist); + } + + tenantDb.Deleteable(info).ExecuteCommand(); + return DataResult.Successed("删除成功!", MultiLanguageConst.DataDelSuccess); + } + + public DataResult EditMappingFrt(MappingFrtReq req) + { + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); + if (req.Id == 0) + { + + if (tenantDb.Queryable().Where(x => x.LinkId == req.LinkId && x.Module == req.Module).Any()) + { + return DataResult.Failed("付款方式映射信息已存在!", MultiLanguageConst.MappingFrtExist); + } + + var data = req.Adapt(); + + var entity = tenantDb.Insertable(data).ExecuteReturnEntity(); + + return DataResult.Successed("添加成功!", entity.Id, MultiLanguageConst.DataCreateSuccess); + } + else + { + var info = tenantDb.Queryable().Where(x => x.Id == req.Id).First(); + + info = req.Adapt(info); + + tenantDb.Updateable(info).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand(); + return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess); + } + } + + public DataResult> GetListByPage(PageRequest request) + { + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); + //序列化查询条件 + var whereList = db.ConfigQuery.Context.Utilities.JsonToConditionalModels(request.QueryCondition); + var data = tenantDb.Queryable() + .Where(whereList) + .Select() + .Mapper(it => + { + it.CarrierName = tenantDb.Queryable().Where(x => x.Id == it.CarrierId).Select(n => n.ShortName).First(); + it.FrtName = tenantDb.Queryable().Where(x => x.Id == it.LinkId).Select(n => n.FrtName).First(); + } + ).ToQueryPage(request.PageCondition); + return data; + } + + public DataResult GetMappingFrtInfo(string id) + { + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); + var data = tenantDb.Queryable() + .Where(a => a.Id == long.Parse(id)) + .Select() + .Mapper(it => + { + it.CarrierName = tenantDb.Queryable().Where(x => x.Id == it.CarrierId).Select(n => n.ShortName).First(); + it.FrtName = tenantDb.Queryable().Where(x => x.Id == it.LinkId).Select(n => n.FrtName).First(); + } + ) + .First(); + return DataResult.Success(data, MultiLanguageConst.DataQuerySuccess); + } + } +} diff --git a/ds-wms-service/DS.WMS.Core/Op/Dtos/EDIBaseModel.cs b/ds-wms-service/DS.WMS.Core/Op/Dtos/EDIBaseModel.cs new file mode 100644 index 00000000..467bbcc6 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Op/Dtos/EDIBaseModel.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DS.WMS.Core.Op.Dtos +{ + /// + /// EDI基类 + /// + public class EDIBaseModel + { + /// + /// 发送方代码 M + /// + public string SENDCODE { get; set; } + + /// + /// 发送方名称 M + /// + public string SENDNAME { get; set; } + + /// + /// 接收方代码 M + /// + public string RECEIVECODE { get; set; } + + /// + /// 文件类型 (B订舱,E SI确认)M + /// + public string filetype { get; set; } + + /// + /// 文件功能 (9原始,1 更新,5 退舱 )M + /// + public string filerole { get; set; } + + /// + /// 文件路径 M + /// + public string filerpath { get; set; } + + /// + /// 是否使用货代代码。 M + /// + public bool UseForWarderCode { get; set; } + /// + /// 货代代码。 O + /// + public string ForWarderCode { get; set; } + + /// + /// 货代名称 O + /// + public string ForWarderName { get; set; } + + /// + /// 业务信息列表 M + /// + public List BSLIST { get; set; } + + /// + /// 发送方公司代码 + /// + public string SENDCOMPANYCODE { get; set; } + + /// + /// 发送方部门代码 + /// + public string SENDSUBCOMPANYCODE { get; set; } + + /// + /// 发送方别名代码 + /// + public string ALIASSENDCODE { get; set; } + + /// + /// 发货方代码 + /// + public string SENDSHIPPERCODE { get; set; } + } +} diff --git a/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportCtnDetailEDIBaseModel.cs b/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportCtnDetailEDIBaseModel.cs new file mode 100644 index 00000000..bcd7dbbc --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportCtnDetailEDIBaseModel.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DS.WMS.Core.Op.Dtos +{ + /// + /// 海运出口EDI集装箱的货物信息 + /// + public class SeaExportCtnDetailEDIBaseModel + { + /// + /// 箱号 M + /// + public string CNTRNO { get; set; } + + /// + /// HS编码 M + /// + public string HSCODE { get; set; } + + /// + /// 唛头 M + /// + public string MARKS { get; set; } + + /// + /// 货物描述 M + /// + public string DESCRIPTION { get; set; } + + /// + /// 件数 M + /// + public Int32 PKGS { get; set; } + + /// + /// 包装 M + /// + public string KINDPKGS { get; set; } + + /// + /// 包装代码 M + /// + public string KINDPKGS_EDI_CODE { get; set; } + + /// + /// 重量 M + /// + public decimal KGS { get; set; } + /// + /// 体积 M + /// + public decimal CBM { get; set; } + } +} diff --git a/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportCtnEDIBaseModel.cs b/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportCtnEDIBaseModel.cs new file mode 100644 index 00000000..ba0e2ec8 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportCtnEDIBaseModel.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DS.WMS.Core.Op.Dtos +{ + /// + /// 海运出口EDI集装箱信息 + /// + public class SeaExportCtnEDIBaseModel + { + /// + /// 箱型EDI代码 M + /// + public string CTNALLCODE { get; set; } + + /// + /// + /// + public Int32 CTNNUM { get; set; } + + /// + /// + /// + public Int32 TEU { get; set; } + + /// + /// 箱号 M + /// + public string CNTRNO { get; set; } + + /// + /// 箱状态 + /// + public string CTNSTATUS { get; set; } + + /// + /// 封号 M + /// + public string SEALNO { get; set; } + + /// + /// 件数 M + /// + public Int32 PKGS { get; set; } + + /// + /// 包装 M + /// + public string KINDPKGS { get; set; } + + /// + /// 包装代码 M + /// + public string KINDPKGS_EDI_CODE { get; set; } + + /// + /// 重量 M + /// + public decimal KGS { get; set; } + /// + /// 体积 M + /// + public decimal CBM { get; set; } + /// + /// 箱皮重 + /// + public decimal TAREWEIGHT { get; set; } + + /// + /// 称重重量 + /// + public string WEIGHKGS { get; set; } + + /// + /// 称重方式 (累加、总重) + /// + public string WEIGHTYPE { get; set; } + + /// + /// 称重签名 + /// + public string WEIGHSIGN { get; set; } + } +} diff --git a/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportEDIBaseModel.cs b/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportEDIBaseModel.cs new file mode 100644 index 00000000..4d62c7f0 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportEDIBaseModel.cs @@ -0,0 +1,599 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DS.WMS.Core.Op.Dtos +{ + /// + /// 海运出口EDI主信息 + /// + public class SeaExportEDIBaseModel + { + /// + /// 委托方 + /// + public string WEITUO { get; set; } + + /// + /// 操作英文名称 M + /// + public string OpEName { get; set; } + + /// + /// 操作电话 M + /// + public string OpTel { get; set; } + /// + /// 操作邮箱 M + /// + public string OpEmail { get; set; } + + /// + /// EDI联系人名称 O + /// + public string EDIATTN { get; set; } + + /// + /// EDI联系人电话 O + /// + public string EDIATTNTEL { get; set; } + /// + /// EDI联系人邮箱 O + /// + public string EDIATTNEMAIL { get; set; } + /// + /// 订舱编号 O + /// + public string ORDERNO { get; set; } + + /// + /// 场站 M + /// + public string YARD { get; set; } + + /// + /// 场站代码 M + /// + public string YARDEDICODE { get; set; } + + + /// + /// 主提单号 M + /// + public string MBLNO { get; set; } + + /// + /// 付费方式代码 M + /// + public string BLFRTEDICODE { get; set; } + + + /// + /// 付费方式 M + /// + public string BLFRT { get; set; } + + /// + /// 船名 O + /// + public string VESSEL { get; set; } + + /// + /// 船舶呼号 O + /// + public string VESSELID { get; set; } + + + /// + /// 航次 O + /// + public string VOYNO { get; set; } + + + /// + /// 内部航次 O + /// + public string NVOYNO { get; set; } + + /// + /// 开船日期 M + /// + public string ETD { get; set; } + + /// + /// 预抵日期 M + /// + public string ETA { get; set; } + + /// + /// 截港日期 O + /// + public string CLOSINGDATE { get; set; } + + /// + /// EDI备注 + /// + public string EDIREMARK { get; set; } + + /// + /// SI备注 + /// + public string SIREMARK { get; set; } + + /// + /// NVO NO + /// + public string NVONO { get; set; } + + /// + /// 船公司ID + /// + public string CARRIERID { get; set; } + + /// + /// 船公司名称 M + /// + public string CARRIER { get; set; } + /// + /// 船公司EDI代码 M + /// + public string CARRIEREDICODE { get; set; } + + /// + /// 发货人 M + /// + public string SHIPPER { get; set; } + + /// + /// 收货人 M + /// + public string CONSIGNEE { get; set; } + + /// + /// 通知人 M + /// + public string NOTIFYPARTY { get; set; } + + /// + /// 第二通知人 + /// + public string NOTIFYPARTY2 { get; set; } + + /// + /// AMS收货人 + /// + public string AMSCONSIGNEE { get; set; } + + /// + /// AMS通知人 + /// + public string AMSNOTIFYPARTY { get; set; } + + + /// + /// 收货地所在国家 O + /// + public string BYCOUNTRY { get; set; } + + ///// + ///// AMS发货人 O + ///// + //public string AMSSHIPPER { get; set; } + + ///// + ///// AMS收货人 O + ///// + //public string AMSCONSIGNEE { get; set; } + + ///// + ///// AMS通知人 O + ///// + //public string AMSNOTIFYPARTY { get; set; } + + /// + /// HS编码 + /// + public string HSCODE { get; set; } + + /// + /// MasterBOLIndicator + /// + public string MasterBOLIndicator { get; set; } + + /// + /// 商品名称 + /// + public string GOODSNAME { get; set; } + + /// + /// 货类代码 + /// + public string GOODCLASSCODE { get; set; } + + /// + /// 唛头 M + /// + public string MARKS { get; set; } + + /// + /// 货物描述 M + /// + public string DESCRIPTION { get; set; } + + /// + /// 收货地代码(每船公司可能不同) + /// + public string PLACERECEIPTID { get; set; } + + /// + /// 收货地 + /// + public string PLACERECEIPT { get; set; } + + /// + /// 起运港代码(每船公司可能不同) M + /// + public string PORTLOADID { get; set; } + + /// + /// 起运港 M + /// + public string PORTLOAD { get; set; } + + /// + ///卸货港代码(每船公司可能不同) M + /// + public string PORTDISCHARGEID { get; set; } + + /// + /// 卸货港 M + /// + public string PORTDISCHARGE { get; set; } + + /// + ///中转港代码 + /// + public string TRANSPORTID { get; set; } + + /// + /// 中转港 + /// + public string TRANSPORT { get; set; } + + /// + ///交货地代码M + /// + public string PLACEDELIVERYID { get; set; } + + /// + /// 交货地 M + /// + public string PLACEDELIVERY { get; set; } + + /// + ///目的地代码(每船公司可能不同) + /// + public string DESTINATIONID { get; set; } + + /// + /// 目的地 + /// + public string DESTINATION { get; set; } + + /// + /// 件数 M + /// + public Int32 PKGS { get; set; } + + /// + /// 包装 M + /// + public string KINDPKGS { get; set; } + + /// + /// 包装代码 M + /// + public string KINDPKGS_EDI_CODE { get; set; } + + /// + /// 重量 M + /// + public decimal KGS { get; set; } + /// + /// 体积 M + /// + public decimal CBM { get; set; } + + /// + /// 货物标识 M + /// + public string CARGOID { get; set; } + + /// + /// 第一层包装皮重 O + /// + public decimal KINGTAREWEIGHT { get; set; } + + /// + /// 危险品类别 O + /// + public string DCLASS { get; set; } + + /// + /// 危险品编号 O + /// + public string DUNNO { get; set; } + + /// + /// 危险品页号 C + /// + public string DPAGE { get; set; } + + /// + /// 危险品标签 C + /// + public string DLABEL { get; set; } + + /// + /// 设置温度 O + /// + public string TEMPSET { get; set; } + + /// + /// 设置最低温度 C + /// + public string TEMPMIN { get; set; } + + /// + /// 设置最高温度 C + /// + public string TEMPMAX { get; set; } + + /// + /// 通风度 O + /// + public string REEFERF { get; set; } + + /// + /// 湿度 + /// + public string HUMIDITY { get; set; } + + /// + /// 预付地点 O + /// + public string PREPARDAT { get; set; } + + /// + /// 到付地点 O + /// + public string PAYABLEAT { get; set; } + + /// + /// 预付地点EDI代码 O + /// + public string PREPARDATID { get; set; } + + /// + /// 到付地点EDI代码 O + /// + public string PAYABLEATID { get; set; } + + /// + /// 签单方式 M(SI) + /// + public string ISSUETYPE { get; set; } + + /// + /// 提单份数 M(SI) + /// + public string NOBILL { get; set; } + + /// + /// 签单地点 M(SI) + /// + public string ISSUEPLACE { get; set; } + + /// + /// 签单日期 + /// + public string ISSUEDATE { get; set; } + + /// + /// 提单副本份数 M(SI) + /// + public string COPYNOBILL { get; set; } + /// + /// 签单地点EDI代码 M(SI) + /// + public string ISSUEPLACEID { get; set; } + + /// + /// 运输条款 M + /// + public string SERVICE { get; set; } + + /// + /// 运费协议号 M + /// + public string CONTRACTNO { get; set; } + + /// + /// 服务合同号 + /// + public string SERVICECONTRACTNO { get; set; } + + /// + /// ESL航线代码 M + /// + public string ESLLINECODE { get; set; } + + /// + /// 收货人邮编 O + /// + public string CONSIGNEEPOSTCODE { get; set; } + + /// + /// 收货人国家 O + /// + public string CONSIGNEECOUNTRY { get; set; } + + /// + /// 收货人税号 O + /// + public string CONSIGNEETAXNO { get; set; } + + /// + /// 通知人邮编 O + /// + public string NOTIFYPARTYPOSTCODE { get; set; } + + /// + /// 通知人国家 O + /// + public string NOTIFYPARTYCOUNTRY { get; set; } + + /// + /// 通知人税号 O + /// + public string NOTIFYPARTYTAXNO { get; set; } + + /// + /// 货物NCM编号 O + /// + public string GOODSNCM { get; set; } + + /// + /// 收货人DOOR地址 O + /// + public string CONSIGNEEDOORADDR { get; set; } + + /// + /// 发货人DOOR地址 O + /// + public string SHIPPERDOORADDR { get; set; } + + /// + /// SCAC代码 O + /// + public string SCACCODE { get; set; } + + /// + /// ITN编号 O + /// + public string ITNCODE { get; set; } + /// + /// 付费方 O + /// + public string FREIGHTPAYER { get; set; } + + /// + /// AMS代码 O + /// + public string AMSCODE { get; set; } + /// + /// 是否SOC箱 O + /// + public bool ISCONTAINERSOC { get; set; } + + /// + /// 拆并单列表 O + /// + public string BSNOLIST { get; set; } + + /// + /// 集装箱明细 M + /// + public List CTNLIST { get; set; } + + /// + /// 集装箱多品名明细 M + /// + public List CTNGOODSLIST { get; set; } + + /// + /// 收货人EDI代码 O + /// + public string ConsigneeEdiCode { get; set; } + + /// + /// 发货人EDI代码 O + /// + public string ShipperEdiCode { get; set; } + + /// + /// 太平销售的代码 M + /// + public string SalesRepCode { get; set; } + + /// + /// ACI HBL O(加拿大) + /// + public string ACIHBL { get; set; } + /// + /// S0C C0C O(加拿大) + /// + public string S0CC0C { get; set; } + + /// + /// '欧盟港口、伊朗港口、KHI' + /// + public string cKHI { get; set; } + + /// + /// '南美东' + /// + public string cNCM { get; set; } + + /// + /// '巴西线的木质包装情况' + /// + public string wNCM { get; set; } + + /* + 待确认字段(YML) + */ + /// + /// ERN CODE + /// + public string ERNCODE { get; set; } + + /// + /// TAC CODE + /// + public string TACCODE { get; set; } + + /// + /// VAE CODE + /// + public string VAECODE { get; set; } + + /// + /// FEC CODE + /// + public string FECCODE { get; set; } + + /// + /// 订舱人说明 + /// + public string ORDERREMARK { get; set; } + + + /// + /// 运输条款EDI代码 M + /// + public string SERVICEEDICODE { get; set; } + + /// + /// 商品代码 + /// + public string GOODSCODE { get; set; } + + /// + /// CNPTNo + /// + public string CNPTNo { get; set; } + } +} diff --git a/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportEdiReq.cs b/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportEdiReq.cs new file mode 100644 index 00000000..d4ec91af --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportEdiReq.cs @@ -0,0 +1,196 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DS.WMS.Core.Op.Dtos +{ + /// + /// 海运出口Edi请求 + /// + public class SeaExportEdiReq + { + /// + /// 主键Id + /// + public long Id { get; set; } + + /// + /// 业务Id + /// + public long BusinessId { get; set; } + + /// + /// 委托方 + /// + [Description("委托方")] + public string CustomerName { get; set; } + + /// + /// 发送方EDI代码 + /// + public string SendCode { get; set; } + + /// + /// 接收方EDI代码 + /// + public string ReceiveCode { get; set; } + + /// + /// 通知方EDI代码 + /// + public string NotifyCdoe { get; set; } + + /// + /// 销售EDI代码 + /// + public string SalerCode { get; set; } + + /// + /// Master Bol Indicator + /// + public string MasterBolIndicator { get; set; } + + /// + /// EMANIFEST HBL + /// + public string EmanifestHbl { get; set; } + + /// + /// 收货人EDI代码 + /// + public string ConsigneeEdiCode { get; set; } + + /// + /// 发货人EDI代码 + /// + public string ShipperEdiCode { get; set; } + + /// + /// EDI联系人名称 + /// + public string EDIAttn { get; set; } + + /// + /// EDI联系人电话 + /// + public string EDIAttnTel { get; set; } + + /// + /// EDI联系人邮箱 + /// + public string EDIAttnMail { get; set; } + + /// + /// AMS收货人 + /// + public string AMSConsignee { get; set; } + + /// + /// AMS通知人 + /// + public string AMSNotifyParty { get; set; } + + /// + /// 操作英文名称 + /// + public string OpEName { get; set; } + + /// + /// 操作电话 + /// + public string OpTel { get; set; } + + /// + /// 操作邮箱 + /// + public string OpEmail { get; set; } + + /// + /// ACI HBL + /// + public string ACIHBL { get; set; } + /// + /// S0C C0C + /// + public string S0CC0C { get; set; } + + /// + /// 商品名称 + /// + public string GoodsName { get; set; } + + /// + /// Master Bol Indicator名称 + /// + public string MasterBolIndicatorName { get; set; } + + /// + /// 销售EDI名称 + /// + public string SalerCodeName { get; set; } + + /// + /// 欧盟港口、伊朗港口、KHI + /// + public string CKHI { get; set; } + + /// + /// 南美东 + /// + public string CNCM { get; set; } + + /// + /// 巴西线的木质包装情况 + /// + public string WNCM { get; set; } + + /// + /// 订舱人说明 + /// + public string OrderRemark { get; set; } + + /// + /// 辅助字段1 + /// + public string ExRemark1 { get; set; } + + /// + /// 辅助字段2 + /// + public string ExRemark2 { get; set; } + + /// + /// 辅助字段3 + /// + public string ExRemark3 { get; set; } + + /// + /// 辅助字段4 + /// + public string ExRemark4 { get; set; } + + /// + /// 第一层包装皮重 + /// + public decimal? KingTareweight { get; set; } + + + /// + /// 箱满仓业务员 + /// + public string XMCYWY { get; set; } + + /// + /// EMC Name accout + /// + public string EmcNameAccount { get; set; } + + /// + /// CNPTNo + /// + public string CNPTNo { get; set; } + } +} diff --git a/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportEdiRes.cs b/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportEdiRes.cs new file mode 100644 index 00000000..57a7a390 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportEdiRes.cs @@ -0,0 +1,197 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DS.WMS.Core.Op.Dtos +{ + /// + /// 海运出口Edi返回 + /// + public class SeaExportEdiRes + { + /// + /// 主键Id + /// + public long Id { get; set; } + + /// + /// 业务Id + /// + public long BusinessId { get; set; } + + /// + /// 委托方 + /// + [Description("委托方")] + public string CustomerName { get; set; } + + /// + /// 发送方EDI代码 + /// + public string SendCode { get; set; } + + /// + /// 接收方EDI代码 + /// + public string ReceiveCode { get; set; } + + /// + /// 通知方EDI代码 + /// + public string NotifyCdoe { get; set; } + + /// + /// 销售EDI代码 + /// + public string SalerCode { get; set; } + + /// + /// Master Bol Indicator + /// + public string MasterBolIndicator { get; set; } + + /// + /// EMANIFEST HBL + /// + public string EmanifestHbl { get; set; } + + /// + /// 收货人EDI代码 + /// + public string ConsigneeEdiCode { get; set; } + + /// + /// 发货人EDI代码 + /// + public string ShipperEdiCode { get; set; } + + /// + /// EDI联系人名称 + /// + public string EDIAttn { get; set; } + + /// + /// EDI联系人电话 + /// + public string EDIAttnTel { get; set; } + + /// + /// EDI联系人邮箱 + /// + public string EDIAttnMail { get; set; } + + /// + /// AMS收货人 + /// + public string AMSConsignee { get; set; } + + /// + /// AMS通知人 + /// + public string AMSNotifyParty { get; set; } + + /// + /// 操作英文名称 + /// + public string OpEName { get; set; } + + /// + /// 操作电话 + /// + public string OpTel { get; set; } + + /// + /// 操作邮箱 + /// + public string OpEmail { get; set; } + + /// + /// ACI HBL + /// + public string ACIHBL { get; set; } + /// + /// S0C C0C + /// + public string S0CC0C { get; set; } + + /// + /// 商品名称 + /// + public string GoodsName { get; set; } + + /// + /// Master Bol Indicator名称 + /// + public string MasterBolIndicatorName { get; set; } + + /// + /// 销售EDI名称 + /// + public string SalerCodeName { get; set; } + + /// + /// 欧盟港口、伊朗港口、KHI + /// + public string CKHI { get; set; } + + /// + /// 南美东 + /// + public string CNCM { get; set; } + + /// + /// 巴西线的木质包装情况 + /// + public string WNCM { get; set; } + + /// + /// 订舱人说明 + /// + public string OrderRemark { get; set; } + + /// + /// 辅助字段1 + /// + public string ExRemark1 { get; set; } + + /// + /// 辅助字段2 + /// + public string ExRemark2 { get; set; } + + /// + /// 辅助字段3 + /// + public string ExRemark3 { get; set; } + + /// + /// 辅助字段4 + /// + public string ExRemark4 { get; set; } + + /// + /// 第一层包装皮重 + /// + public decimal? KingTareweight { get; set; } + + + /// + /// 箱满仓业务员 + /// + public string XMCYWY { get; set; } + + /// + /// EMC Name accout + /// + public string EmcNameAccount { get; set; } + + /// + /// CNPTNo + /// + public string CNPTNo { get; set; } + } +} diff --git a/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportReq.cs b/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportReq.cs index ea3985d4..9e7e246c 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportReq.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportReq.cs @@ -18,6 +18,12 @@ public class SeaExportReq /// public List CtnInfo { get; set; } + /// + /// Edi信息 + /// + public SeaExportEdiReq EdiInfo { get; set; } + + /// /// 主单Id /// @@ -311,7 +317,10 @@ public class SeaExportReq /// 货物描述 /// public string Description { get; set; } - + /// + /// 品名Id + /// + public long GoodsId { get; set; } /// /// 品名 t_code_goods /// @@ -572,10 +581,10 @@ public class SeaExportReq /// public string BookingType { get; set; } - ///// - ///// 订舱编号 - ///// - //public string BookingNo { get; set; } + /// + /// 订舱编号 + /// + public string BookingNo { get; set; } /// /// Desc:保险人 @@ -1053,6 +1062,23 @@ public class SeaExportReq /// 通知人 t_info_client CUSTNAME /// public string NotifyParty { get; set; } + + /// + /// 内部航次 + /// + public string InnerVoyno { get; set; } + /// + /// 第二通知人Id t_info_client CUSTNAME + /// + public long? SecondNotifyPartyId { get; set; } + /// + /// 第二通知人 t_info_client CUSTNAME + /// + public string SecondNotifyParty { get; set; } + /// + /// 第二通知人内容 + /// + public string SecondNotifyPartyContent { get; set; } } /// diff --git a/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportRes.cs b/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportRes.cs index 06cd3f51..357d24ef 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportRes.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Dtos/SeaExportRes.cs @@ -8,6 +8,10 @@ namespace DS.WMS.Core.Op.Dtos; /// public class SeaExportRes { + /// + /// Edi信息 + /// + public SeaExportEdiRes EdiInfo { get; set; } /// /// 主键Id /// @@ -322,7 +326,10 @@ public class SeaExportRes /// 品名 t_code_goods /// public string GoodsName { get; set; } - + /// + /// 品名Id + /// + public long GoodsId { get; set; } /// /// 货物毛重 /// @@ -579,10 +586,10 @@ public class SeaExportRes /// public string BookingType { get; set; } - ///// - ///// 订舱编号 - ///// - //public string BookingNo { get; set; } + /// + /// 订舱编号 + /// + public string BookingNo { get; set; } /// /// Desc:保险人 @@ -1087,4 +1094,20 @@ public class SeaExportRes /// 通知人 t_info_client CUSTNAME /// public string NotifyParty { get; set; } + /// + /// 内部航次 + /// + public string InnerVoyno { get; set; } + /// + /// 第二通知人Id t_info_client CUSTNAME + /// + public long? SecondNotifyPartyId { get; set; } + /// + /// 第二通知人 t_info_client CUSTNAME + /// + public string SecondNotifyParty { get; set; } + /// + /// 第二通知人内容 + /// + public string SecondNotifyPartyContent { get; set; } } \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.Core/Op/EDI/ESLEdiHelper.cs b/ds-wms-service/DS.WMS.Core/Op/EDI/ESLEdiHelper.cs new file mode 100644 index 00000000..73fb6c6d --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Op/EDI/ESLEdiHelper.cs @@ -0,0 +1,1130 @@ +using DS.Module.Core; +using DS.WMS.Core.Op.Dtos; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace DS.WMS.Core.Op.EDI +{ + public class ESLEdiHelper + { + + public ESLEdiHelper() + { + } + + #region 基本函数 + + public static string GetBillNum2(string str) + { + if (str == "ZERO") return "00"; + if (str == "ONE") return "01"; + if (str == "TWO") return "02"; + if (str == "THREE") return "03"; + if (str == "FOUR") return "04"; + if (str == "FIVE") return "05"; + if (str == "SIX") return "06"; + if (str == "SERVEN") return "07"; + if (str == "EIGHT") return "08"; + if (str == "NINE") return "09"; + if (str == "TEN") return "10"; + else return ""; + } + + + public static string GetDateStr(string datestr, string dateformat) + { + var result = ""; + + if (datestr == null || datestr == "") + { + result = ""; + } + else + { + result = Convert.ToDateTime(datestr).ToString(dateformat); + + } + + return result; + + } + + #region 判断中文字符 + public static bool IsChinese(char c) + { + return (int)c > 0x80; + } + public static bool StringIsChinese(string str) + { + var result = false; + for (int i = 1; i < str.Length; i++) + { + if (IsChinese(str[i])) + { + result = true; + return result; + } + } + for (int i = 0; i < str.Length; i++) + { + string stemp = str.Substring(i, 1); + int ilen = System.Text.Encoding.Default.GetByteCount(stemp); + if (ilen == 2) + { + result = true; + return result; + } + + } + + return result; + } + + #endregion + + public static string formatListStr(List DestList, int lineCount, bool isformat = false) + { + var result = ""; + for (var i = 0; i < lineCount; i++) + { + if (DestList.Count > i) + { + if (isformat) + result = result + formatEdiStr("txt", DestList[i]); + else + result = result + DestList[i]; + } + if (i != (lineCount - 1)) + result = result + ":"; + + + } + return result; + } + + + #region 文本字段判断每行是否符合 + /// + /// edi 文本格式处理判断(例如:1行35个字符不超过5行) + /// + /// 文件类型(例如:txt、xml) + /// 要处理的数据 + /// 每行长度 + /// 主提单号 + /// 数据类型(例如:发货人内容、货描等) + /// 限制录入的行数(“0”代表不限制) + /// 限录后多出的放到货描中的数据的连接符(例如:“*”发货人内容、“**”收件人等) + /// + public static System.String formatlengthError(string fileType, string str, int length, string sMBLNO, string sType, int rowNum, string sSymbol, bool isHuoMiao) + { + string error = ""; + string Shipping = str; + if (fileType == "txt") + { + Shipping = formatEdiStr("txt", str); + } + else if (fileType == "xml") + { + Shipping = formatEdiStr("txt", str); + } + string[] argAGENT = Shipping.Split(new string[] { "\r\n" }, StringSplitOptions.None); + if (argAGENT.Length > 0) + { + if (argAGENT.Length == 1) + { + argAGENT = Shipping.Split(new string[] { "\n" }, StringSplitOptions.None); + if (argAGENT.Length > 0) + { + if (argAGENT.Length > rowNum && rowNum != 0) + { + if (isHuoMiao) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据!"; + } + else + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据,多余信息请手动以“" + sSymbol + "”号开头放到货物描述中!(例如:“货描内容" + sSymbol + "超出部分”)"; + } + } + for (int j = 0; j < argAGENT.Length; j++) + { + //List AgentList = formatlengthStr(argAGENT[j].ToString(), 35); + if (argAGENT[j].ToString().Length > length) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 第" + (j + 1) + "行超过" + length + "个字符"; + } + } + } + } + else + { + if (argAGENT.Length > rowNum && rowNum != 0) + { + if (isHuoMiao) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据!"; + } + else + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据,多余信息请手动以“" + sSymbol + "”号开头放到货物描述中!(例如:“货描内容" + sSymbol + "超出部分”)"; + } + } + for (int j = 0; j < argAGENT.Length; j++) + { + //List AgentList = formatlengthStr(argAGENT[j].ToString(), 35); + if (argAGENT[j].ToString().Length > length) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 第" + (j + 1) + "行超过" + length + "个字符"; + } + } + } + } + return error; + } + #endregion + + #region 字符转义 + /// + /// 各种文本转义字符 + /// + /// 文件类型(例如:txt、xml) + /// 文本字符串 + /// + public static string formatEdiStr(string fileType, string str) + { + if (str == null) + str = string.Empty; + + if (fileType == "txt") + { + return str.Replace("?", "??").Replace(":", "?:").Replace("+", "?+").Replace("'", "?'"); + } + else if (fileType == "xml") + { + return str.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace("\"", """).Replace("'", "'"); + } + else if (fileType == "sitc") + { + return str.Replace("?", "??").Replace(":", "?:").Replace("'", "?'"); + } + else + { + return str; + } + } + #endregion + #region 格式化每行 + public static List formatlengthStr(string str, int length, bool formatstr = false, bool nodelsp = false) + { + str = str.Replace("\r\n", "\\"); + str = str.Replace("\n", "\\"); + str = str.Replace("\r", " "); + string[] StrList = str.Split('\\'); + var strtemp = ""; + var strnewline = ""; + var strtempnewline = ""; + char[] spstring = { ' ', ';', ',', '.', ':', '/', '(', ')', '?', '+', '-' }; + List DestList = new List(); + for (var i = 0; i <= StrList.Length - 1; i++) + { + if (StrList[i].Length <= length) + { + if (formatstr) + DestList.Add(formatEdiStr("txt", StrList[i])); + else + DestList.Add(StrList[i]); + + } + else + { + strtemp = StrList[i] + " "; + strtempnewline = ""; + strnewline = ""; + for (var j = 0; j < strtemp.Length; j++) + { + strtempnewline = strtempnewline + strtemp[j]; + if (strtemp[j] == ' ' || strtemp[j] == ':' || strtemp[j] == ',' || strtemp[j] == '.' || strtemp[j] == ':' || strtemp[j] == '/' + || strtemp[j] == '?' || strtemp[j] == ')' || strtemp[j] == '}' || strtemp[j] == '+' || strtemp[j] == '-') + { + if ((strnewline.Length + strtempnewline.Length) <= length) + strnewline = strnewline + strtempnewline; + else + { + if (formatstr) + DestList.Add(formatEdiStr("txt", strnewline)); + else + DestList.Add(strnewline); + strnewline = strtempnewline; + + } + strtempnewline = ""; + } + } + if (nodelsp) + { + if (formatstr) + DestList.Add(formatEdiStr("txt", strnewline)); + else DestList.Add(strnewline); + } + else if (strnewline.Trim() != "") + { + if (formatstr) + DestList.Add(formatEdiStr("txt", strnewline)); + else DestList.Add(strnewline); + } + } + + } + + return DestList; + } + #endregion + #endregion + + #region 检查 + public static string IsCreateESLEDI(EDIBaseModel InttrEdi) + { + var error = ""; + + if (string.IsNullOrEmpty(InttrEdi.SENDCODE)) + { error = error + "
发送方代码不能为空"; } + + if (string.IsNullOrEmpty(InttrEdi.SENDNAME)) + { error = error + "
发送方名称不能为空"; } + + if (string.IsNullOrEmpty(InttrEdi.RECEIVECODE)) + { error = error + "
接收方代码不能为空"; } + + if (InttrEdi.filetype == "B") + { + if (InttrEdi.UseForWarderCode) + { + if (string.IsNullOrEmpty(InttrEdi.ForWarderCode)) + { error = error + "
货代代码不能为空"; } + + if (string.IsNullOrEmpty(InttrEdi.ForWarderName)) + { error = error + "
货代称呼不能为空"; } + } + } + + + foreach (var headData in InttrEdi.BSLIST) + { + + if (string.IsNullOrEmpty(headData.MBLNO)) + { error = error + "
主提单号不能为空"; } + + if (string.IsNullOrEmpty(headData.BLFRT)) + { error = error + "
提单号:" + headData.MBLNO + " 付费方式不能为空"; } + + //2023-01-04 JHQ 跟韩训涛确认,ESL这里不处理航线代码,去掉不为空校验,并在生成EDI报文时,对ESL航线代码赋空串 + //if (string.IsNullOrEmpty(headData.ESLLINECODE)) + //{ error = error + "
提单号:" + headData.MBLNO + " ESL航线代码不能为空"; } + + if (InttrEdi.filetype == "E") + { + if (string.IsNullOrEmpty(headData.VESSEL)) + { error = error + "
提单号:" + headData.MBLNO + " 船名不能为空"; } + + if (string.IsNullOrEmpty(headData.VOYNO)) + { error = error + "
提单号:" + headData.MBLNO + " 航次不能为空"; } + + if (string.IsNullOrEmpty(headData.ETD)) + { + error = error + "
提单号:" + headData.MBLNO + " 开船日期不能为空"; + return error; + } + } + + if (string.IsNullOrEmpty(headData.PORTLOADID) || headData.PORTLOADID.Length != 5) + { error = error + "
提单号:" + headData.MBLNO + " 装货港代码不能为空或录入不正确(必须是5位代码)"; } + + if (string.IsNullOrEmpty(headData.PORTLOAD)) + { error = error + "
提单号:" + headData.MBLNO + " 装货港不能为空"; } + + + if (string.IsNullOrEmpty(headData.PORTDISCHARGEID) || headData.PORTDISCHARGEID.Length != 5) + { error = error + "
提单号:" + headData.MBLNO + " 卸货港代码不能为空或录入不正确(必须是5位代码)"; } + if (string.IsNullOrEmpty(headData.PORTDISCHARGE)) + { error = error + "
提单号:" + headData.MBLNO + " 卸货港不能为空"; } + + if (string.IsNullOrEmpty(headData.PLACEDELIVERY) || headData.PLACEDELIVERYID.Length != 5) + { error = error + "
提单号:" + headData.MBLNO + " 交货地代码不能为空或录入不正确(必须是5位代码)"; } + if (string.IsNullOrEmpty(headData.PLACEDELIVERY)) + { error = error + "
提单号:" + headData.MBLNO + " 交货地不能为空"; } + + if (string.IsNullOrEmpty(headData.DESTINATION)) + { + if (string.IsNullOrEmpty(headData.DESTINATIONID) || headData.DESTINATIONID.Length != 5) + { error = error + "
提单号:" + headData.MBLNO + " 目的地代码不能为空或录入不正确(必须是5位代码)"; } + } + + if (string.IsNullOrEmpty(headData.ESLLINECODE)) + { error = error + "
提单号:" + headData.MBLNO + " 航司航线不能为空"; } + + if (string.IsNullOrWhiteSpace(headData.CONTRACTNO)) + { error = error + "
提单号:" + headData.MBLNO + " 运费协议号不能为空"; } + + if (string.IsNullOrEmpty(headData.KINDPKGS_EDI_CODE)) + { error = error + "
提单号:" + headData.MBLNO + " 包装EDI代码不能为空"; } + if (headData.PKGS == 0) + { error = error + "
提单号:" + headData.MBLNO + " 件数不能为0"; } + if (headData.KGS == 0) + { error = error + "
提单号:" + headData.MBLNO + " 毛重不能为0"; } + if (headData.CBM == 0) + { error = error + "
提单号:" + headData.MBLNO + " 尺码不能为0"; } + + if (string.IsNullOrEmpty(headData.CARGOID)) + { error = error + "
提单号:" + headData.MBLNO + " 货物标识不能为空"; } + + if (headData.CARGOID == "D") + { + if (string.IsNullOrEmpty(headData.DCLASS)) + { error = error + "
提单号:" + headData.MBLNO + " 危险品分类不能为空"; } + + if (string.IsNullOrEmpty(headData.DUNNO)) + { error = error + "
提单号:" + headData.MBLNO + " 危险品编号不能为空"; } + } + if (headData.CARGOID == "R") + { + if (headData.TEMPSET == null || headData.TEMPSET == "") + { error = error + "
提单号:" + headData.MBLNO + " 设置温度不能为空"; } + if (headData.REEFERF == null || headData.REEFERF == "") + { error = error + "
提单号:" + headData.MBLNO + " 通风度不能为空"; } + } + + if (string.IsNullOrEmpty(headData.MARKS)) + { + error = error + "
提单号:" + headData.MBLNO + " 唛头不能为空"; + } + else + { + if (StringIsChinese(headData.MARKS)) + { + error = error + "
提单号:" + headData.MBLNO + " 唛头含有中文或双字节字符"; + } + else + { + error += formatlengthError("txt", headData.MARKS, 35, headData.MBLNO, "唛头", 0, "", false); + } + } + + if (string.IsNullOrEmpty(headData.DESCRIPTION)) + { + error = error + "
提单号:" + headData.MBLNO + " 货物描述不能为空"; + } + else + { + if (StringIsChinese(headData.DESCRIPTION)) + { + error = error + "
提单号:" + headData.MBLNO + " 货物描述含有中文或双字节字符"; + } + else + { + //error += formatlengthError("txt", bill.DESCRIPTION, 35, bill.MBLNO, "货物描述", 0, ""); + } + } + + + if (string.IsNullOrEmpty(headData.SHIPPER)) + { + error = error + "
提单号:" + headData.MBLNO + " 发货人不能为空"; + } + else + { + if (StringIsChinese(headData.SHIPPER)) + { + error = error + "
提单号:" + headData.MBLNO + " 发货人含有中文或双字节字符"; + } + else + { + + //2023-04-04 经和川操作确认不对收、发、通信息判断每行35个字符判断,考虑判断方法判断了行数,这里暂时改外调大单行的最大字符数35改为70 + if (headData.CARRIEREDICODE == "HLCU") + { + error += formatlengthError("txt", headData.SHIPPER, 70, headData.MBLNO, "发货人", 6, "-", false); + } + else + { + error += formatlengthError("txt", headData.SHIPPER, 70, headData.MBLNO, "发货人", 6, "*", false); + } + + } + } + //} + + + + if (string.IsNullOrEmpty(headData.CONSIGNEE)) + { + error = error + "
提单号:" + headData.MBLNO + " 收货人不能为空"; + } + else + { + if (StringIsChinese(headData.CONSIGNEE)) + { + error = error + "
提单号:" + headData.MBLNO + " 收货人含有中文或双字节字符"; + } + else + { + //2023-04-04 经和川操作确认不对收、发、通信息判断每行35个字符判断,考虑判断方法判断了行数,这里暂时改外调大单行的最大字符数35改为70 + + if (headData.CARRIEREDICODE == "HLCU") + { + error += formatlengthError("txt", headData.CONSIGNEE, 70, headData.MBLNO, "收货人", 6, "--", false); + } + else + { + error += formatlengthError("txt", headData.CONSIGNEE, 70, headData.MBLNO, "收货人", 6, "**", false); + } + } + } + + + + + if (string.IsNullOrEmpty(headData.NOTIFYPARTY)) + { + error = error + "
提单号:" + headData.MBLNO + " 通知人不能为空"; + } + else + { + if (StringIsChinese(headData.NOTIFYPARTY)) + { + error = error + "
提单号:" + headData.MBLNO + " 通知人含有中文或双字节字符"; + } + else + { + //2023-04-04 经和川操作确认不对收、发、通信息判断每行35个字符判断,考虑判断方法判断了行数,这里暂时改外调大单行的最大字符数35改为70 + + if (headData.CARRIEREDICODE == "HLCU") + { + error += formatlengthError("txt", headData.NOTIFYPARTY, 70, headData.MBLNO, "通知人", 6, "---", false); + } + else + { + error += formatlengthError("txt", headData.NOTIFYPARTY, 70, headData.MBLNO, "通知人", 6, "***", false); + } + } + } + + if (!string.IsNullOrEmpty(headData.NOTIFYPARTY2)) + { + error += formatlengthError("txt", headData.NOTIFYPARTY2, 35, headData.MBLNO, "第二通知人", 5, "", false); + } + + var ctnlist = headData.CTNLIST; + if (ctnlist.Count == 0) { error = error + "
提单号:" + headData.MBLNO + " 集装箱信息不能为空"; }; + + #region 集装箱判断检查 + if (ctnlist.Count != 0) + { + Decimal dlPKGS = 0; + Decimal dlKGS = 0; + Decimal dlCBM = 0; + foreach (var ctn in ctnlist) + { + if (string.IsNullOrEmpty(ctn.CTNALLCODE)) + { error = error + "
提单号:" + headData.MBLNO + " 集装箱箱型EDI代码不能为空"; } + if (ctn.CTNALLCODE != null && (ctn.CTNALLCODE.IndexOf("RH") > 0 || ctn.CTNALLCODE.IndexOf("RF") > 0) && (headData.CARGOID != "R")) + { + { error = error + "
提单号:" + headData.MBLNO + " 集装箱箱型为冻柜,货类代码请选择冻柜"; } + } + + if (InttrEdi.filetype == "E") + { + + if (string.IsNullOrEmpty(ctn.CNTRNO)) + { error = error + "
提单号:" + headData.MBLNO + " 箱号不能为空"; } + if (string.IsNullOrEmpty(ctn.SEALNO)) + { error = error + "
提单号:" + headData.MBLNO + " 封号不能为空"; } + + if (ctn.KINDPKGS != headData.KINDPKGS) + { error = error + "
提单号:" + headData.MBLNO + " 中的包装类型与集装箱的包装类型不同"; } + dlPKGS += Convert.ToDecimal(ctn.PKGS); + dlKGS += Convert.ToDecimal(ctn.KGS); + dlCBM += Convert.ToDecimal(ctn.CBM); + } + } + if (InttrEdi.filetype == "E") + { + if (dlPKGS != Convert.ToDecimal(headData.PKGS)) + { error = error + "
提单号:" + headData.MBLNO + " 集装箱件数合计数必须等于委托单总件数"; } + if (dlKGS != Convert.ToDecimal(headData.KGS)) + { error = error + "
提单号:" + headData.MBLNO + " 集装箱重量合计数必须等于委托单总重量数"; } + if (dlCBM != Convert.ToDecimal(headData.CBM)) + { error = error + "
提单号:" + headData.MBLNO + " 集装箱尺码合计数必须等于委托单总尺码数"; } + } + } + + if (InttrEdi.filetype == "E") + { + if (headData.CTNGOODSLIST != null && headData.CTNGOODSLIST.Count > 0) + { + foreach (var ctn in ctnlist) + { + var isfind = false; + Int32 ctngoodssumpkgs = 0; + decimal ctngoodssumkgs = 0; + decimal ctngoodssumcbm = 0; + headData.CTNGOODSLIST.ForEach(i => + { + if (i.CNTRNO == ctn.CNTRNO) + { + isfind = true; + ctngoodssumpkgs = ctngoodssumpkgs + i.PKGS; + ctngoodssumkgs = ctngoodssumkgs + i.KGS; + ctngoodssumcbm = ctngoodssumcbm + i.CBM; + } + }); + if (!isfind) + { + error = error + "
提单号:" + headData.MBLNO + "的“" + ctn.CNTRNO + "”未添加分箱明细!"; + } + else + { + if (ctngoodssumpkgs != Convert.ToDecimal(ctn.PKGS)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctn.CNTRNO + " 分箱明细件数合计数不等于集装箱件数"; } + if (ctngoodssumkgs != Convert.ToDecimal(ctn.KGS)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctn.CNTRNO + " 分箱明细毛重合计数不等于集装箱毛重"; } + if (ctngoodssumcbm != Convert.ToDecimal(ctn.CBM)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctn.CNTRNO + " 分箱明细尺码合计数不等于集装箱毛重"; } + + } + + } + + foreach (var ctngood in headData.CTNGOODSLIST) + { + if (string.IsNullOrEmpty(ctngood.KINDPKGS)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱明细包装类型不能为空"; } + if (string.IsNullOrEmpty(ctngood.DESCRIPTION)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱货物描述不能为空"; } + else + { + error += formatlengthError("txt", ctngood.DESCRIPTION, 70, headData.MBLNO, "的“" + ctngood.CNTRNO + "”箱号的分箱货物描述", 0, "", false); + } + //if (string.IsNullOrEmpty(ctngood.HSCODE)) + //{ error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱HS编码不能为空"; } + if (string.IsNullOrEmpty(ctngood.KINDPKGS_EDI_CODE)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱明细包装类型代码不能为空"; } + + } + + } + + #endregion + + + } + + //2023-03-03 经过测试东胜的EDI根据付费方式,区分 到付-需要填到付地点不能填预付地点,预付只能填预付地点不能填到付地点 + //跟韩工确认增加判断 + if (!string.IsNullOrWhiteSpace(headData.BLFRT) && headData.BLFRT.IndexOf("PREPAID") >= 0) + { + if (string.IsNullOrWhiteSpace(headData.PREPARDAT)) + { + error = error + "
提单号:" + headData.MBLNO + " 付费方式是预付,预付地点不能为空"; + } + + if (!string.IsNullOrWhiteSpace(headData.PAYABLEAT)) + { + error = error + "
提单号:" + headData.MBLNO + " 付费方式是预付,到付地点不能填写"; + } + } + else if (!string.IsNullOrWhiteSpace(headData.BLFRT) && headData.BLFRT.IndexOf("COLLECT") >= 0) + { + if (string.IsNullOrWhiteSpace(headData.PAYABLEAT)) + { + error = error + "
提单号:" + headData.MBLNO + " 付费方式是到付,到付地点不能为空"; + } + + if (!string.IsNullOrWhiteSpace(headData.PREPARDAT)) + { + error = error + "
提单号:" + headData.MBLNO + " 付费方式是到付,预付地点不能填写"; + } + } + } + return error; + } + #endregion + + #region 生成报文(订舱(InttrEdi.filetype=="B"),截单(InttrEdi.filetype=="E")) + public static EdiDataResult CreateEdiESL(EDIBaseModel InttrEdi) + { + /* + 注意的几个问题 + 1、SERVICECONTRACTNO(服务合同号)查了原来大简云的记录,前端没有录入的编辑框,后台也没有做数据对应,一直是空着的。不确定是否影响到EDI的报文。 + */ + EdiDataResult result = new EdiDataResult { Succeeded = false }; + + + + var filetype = "IFTMIN"; + if (InttrEdi.filetype != "E") filetype = "IFTMBF"; + + string filename = InttrEdi.filerpath + "\\" + filetype + "_" + InttrEdi.BSLIST[0].MBLNO + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt"; + + //如果是部署linux需要修改路径 + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + filename = filename.Replace("\\", "/"); + + FileStream f = new FileStream(filename, FileMode.Create); + StreamWriter r = new StreamWriter(f, Encoding.Default); + var icount = 0; + var bsno = ""; + var isfirst = true; + + foreach (var bill in InttrEdi.BSLIST) + { + //2023-01-04 JHQ 跟韩训涛确认,ESL这里不处理航线代码,去掉不为空校验,并在生成EDI报文时,对ESL航线代码赋空串 + if (bill.ESLLINECODE == null) + bill.ESLLINECODE = string.Empty; + + //2022-01-04 + if (InttrEdi.ForWarderName == null) + InttrEdi.ForWarderName = string.Empty; + + if (isfirst) + { + if (InttrEdi.filetype == "E") + r.WriteLine("00:IFTMIN:BOOKING:" + InttrEdi.filerole + ":" + InttrEdi.SENDCODE + ":" + InttrEdi.RECEIVECODE + ":" + DateTime.Now.ToString("yyyyMMddHHmm") + "'"); + else + r.WriteLine("00:IFTMBF:BOOKING:" + InttrEdi.filerole + ":" + InttrEdi.SENDCODE + ":" + InttrEdi.RECEIVECODE + ":" + DateTime.Now.ToString("yyyyMMddHHmm") + "'"); + isfirst = false; + icount++; + + } + + //2023-03-03 修改运输条款SERVICE改为EDI的映射值,经过韩工确认 + if (InttrEdi.filetype == "E") + { + r.WriteLine("02" + + ":" + bill.ORDERNO//2 REFERENCE NO. 运编号 X(35) 一般为流水号 M + + ":" + bill.MBLNO//3 B\L NO. 提单号 X(20) 船公司的提单号 C + + ":" + bill.SERVICEEDICODE//4 DELIVERY TERM 交货条款 X(9) CY-CY(pier-pier/port):30CY-CFS(pier/port-door):29CFS-CY(door-pier/port):28CFS-CFS(door-door):27 M + + ":" + formatEdiStr("txt", InttrEdi.ForWarderName.Replace("\n", " ").Replace("\r", " "))//5 BOOKING PARTY 订舱人说明 X(70) 货代方企业名称或代码 C + + ":" + InttrEdi.RECEIVECODE//6 ISSUE PARTY CODE 签单人代码 X(13) 即接受订舱的人的代码 M + + ":"//7 ISSUE PARTY 签单人说明 X(35)   C + + ":"//8 APPLICANT 询价单位 X(13) 向船公司询价的单位代码 C + + ":"//9 FOB BK PARTY 国外订舱单位 X(13) 国外FOB货订舱单位的代码 C + + ":"//10 B/L TRANSHIP ID 转船标识 X(1) Y/N C + + ":"//11 BATCH ID 分批 X(1) Y/N C + + ":"//12 SHIPMENT DATE 装期 9(8) CCYYMMDD C + + ":"//13 EXPIRY DATE 效期 9(8) CCYYMMDD C + + ":" + bill.CONTRACTNO//14 QUOTATION NO. 运费协议号 X(30) MAERSK为必选 C + + ":"//15 CHARGE TYPE 费率本代码 X(1)   C + + ":" + bill.SERVICECONTRACTNO//16 S/C NO. 合约号 X(30)   C + + ":" + bill.ORDERNO//17 BOOKING NO. 船公司订舱编号 X(20) 船公司系统内部订舱编号 C + + ":::"//18 SLOT CHARTER ID 舱位互用标识 X(1)   C + + ":" + bill.EDIATTNEMAIL//21 AMS CODE AMS代码 X(15)   C + + ":" + bill.EDIATTN//22 AMS CODE AMS代码 X(15)   C + + ":" + bill.EDIATTNTEL//23 AMS CODE AMS代码 X(15)   C + //注:QUOTATION NO.项填本票订舱货的运价是通过向中集询价后定下的特殊运价编号。 + + "'"); + + } + else + { + //2023-03-03 修改运输条款SERVICE改为EDI的映射值,经过韩工确认 + r.WriteLine("02" + + ":" + bill.ORDERNO//2 REFERENCE NO. 运编号 X(35) 一般为流水号 M + + ":" + bill.MBLNO//3 B\L NO. 提单号 X(20) 船公司的提单号 C + + ":" + bill.SERVICEEDICODE//4 DELIVERY TERM 交货条款 X(9) CY-CY(pier-pier/port):30CY-CFS(pier/port-door):29CFS-CY(door-pier/port):28CFS-CFS(door-door):27 M + + ":" + formatEdiStr("txt", InttrEdi.ForWarderName.Replace("\n", " ").Replace("\r", " "))//5 BOOKING PARTY 订舱人说明 X(70) 货代方企业名称或代码 C + + ":" + InttrEdi.RECEIVECODE//6 ISSUE PARTY CODE 签单人代码 X(13) 即接受订舱的人的代码 M + + ":"//7 ISSUE PARTY 签单人说明 X(35)   C + + ":"//8 APPLICANT 询价单位 X(13) 向船公司询价的单位代码 C + + ":"//9 FOB BK PARTY 国外订舱单位 X(13) 国外FOB货订舱单位的代码 C + + ":"//10 B/L TRANSHIP ID 转船标识 X(1) Y/N C + + ":"//11 BATCH ID 分批 X(1) Y/N C + + ":"//12 SHIPMENT DATE 装期 9(8) CCYYMMDD C + + ":"//13 EXPIRY DATE 效期 9(8) CCYYMMDD C + + ":" + bill.CONTRACTNO//14 QUOTATION NO. 运费协议号 X(30) MAERSK为必选 C + + ":"//15 CHARGE TYPE 费率本代码 X(1)   C + + ":" + bill.SERVICECONTRACTNO//16 S/C NO. 合约号 X(30)   C + /* 2023-04-10 经过测试发现会吧这个订舱编号写到备注里,这里选择去掉填写订舱编号 + + ":" + bill.ORDERNO//17 BOOKING NO. 船公司订舱编号 X(20) 船公司系统内部订舱编号 C + */ + + ":"//17 BOOKING NO. 船公司订舱编号 X(20) 船公司系统内部订舱编号 C + + ":"//18 SLOT CHARTER ID 舱位互用标识 X(1)   C + + ":" + bill.EDIATTNEMAIL//21 AMS CODE AMS代码 X(15)   C + + ":" + bill.EDIATTN//22 AMS CODE AMS代码 X(15)   C + + ":" + bill.EDIATTNTEL//23 AMS CODE AMS代码 X(15)   C + //注:QUOTATION NO.项填本票订舱货的运价是通过向中集询价后定下的特殊运价编号。 + + "'"); + } + icount++; + + var ISSUETYPE = ""; + + /* 2022-01-04 这里新订舱系统的签单方式代码已变更采用新的编码来判断 + if (bill.ISSUETYPE == "正本") + { + ISSUETYPE = "ORI"; + } + else if (bill.ISSUETYPE == "电放") + { + ISSUETYPE = "TER"; + } + else ISSUETYPE = "EXP"; + */ + + if (bill.ISSUETYPE == "ORIGINAL") + { + //正本 + ISSUETYPE = "ORI"; + } + else if (bill.ISSUETYPE == "TELEX") + { + //电放 + ISSUETYPE = "TER"; + } + 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++; + + + r.WriteLine("11:" + bill.ESLLINECODE + ":" + bill.VESSEL + ":" + bill.VOYNO + ":::" + InttrEdi.RECEIVECODE + "::" + GetDateStr(bill.ETD, "yyyyMMdd") + ":::::'"); + icount++; + + + + r.WriteLine("12" + + ":" + bill.PLACERECEIPTID//2 PLACE CODE OF RECEIPT 收货地代码 X(5) OOCL、HLC的订舱要求必选 O + + ":" + bill.PLACERECEIPT//3 PLACE OF RECEIPT 收货地 X(35)   C + + ":" + bill.PORTLOADID//4 LOAD PORT CODE 装货港代码 X(5) OOCL的订舱要求必选 O + + ":" + bill.PORTLOAD//5 LOAD PORT 装货港 X(35)   C + + ":" + bill.PORTDISCHARGEID//6 DISCHARGE PORT CODE 卸货港代码 X(5) OOCL的订舱要求必选 M + + ":" + bill.PORTDISCHARGE//7 DISCHARGE PORT 卸货港 X(35)   C + + ":" + bill.TRANSPORTID //8 TRANSFER PORT CODE 中转港代码 X(5)   C + + ":" + bill.TRANSPORT//9 TRANSFER PORT 中转港 X(35)   C + + ":" + bill.PLACEDELIVERYID//10 PLACE OF DELIVERY CODE 交货地代码 X(5) OOCL的订舱要求必选 O + + ":" + bill.PLACEDELIVERY//11 PLACE OF DELIVERY 交货地 X(35)   C + + ":" + bill.DESTINATIONID//12 FINAL DESTINATION CODE 目的地代码 X(5)   C + + ":" + bill.DESTINATION//13 FINAL DESTINATION CODE 目的地 X(35)   C + + "'"); + + icount = icount + 1; + + r.WriteLine("14:" + bill.BLFRTEDICODE + ":" + bill.BLFRT + "'"); + if (InttrEdi.filetype == "E") + r.WriteLine("15:::" + bill.BLFRTEDICODE + ":" + bill.PAYABLEATID + ":::::'"); + else + r.WriteLine("15:::" + bill.BLFRTEDICODE + "::::::'"); + icount = icount + 2; + + + var Shipping = ""; + if (InttrEdi.filetype == "E") + Shipping = formatEdiStr("txt", bill.SIREMARK); + else + Shipping = formatEdiStr("txt", bill.EDIREMARK); + + List ShippingList = formatlengthStr(Shipping, 70); + + if (Shipping != "") + { + r.WriteLine("17:" + formatListStr(ShippingList, 5) + "'"); + icount++; + } + + + Shipping = formatEdiStr("txt", bill.SHIPPER); + /* + 2023-04-06 ESL的EDI去掉校验后,这里需要截取需要按照最大35来截取 + ShippingList = formatlengthStr(Shipping, 75); + */ + ShippingList = formatlengthStr(Shipping, 35); + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + r.WriteLine("20::" + formatListStr(ShippingList, 6) + "'"); + icount = icount + 1; + + } + + + + Shipping = formatEdiStr("txt", bill.CONSIGNEE); + /* + 2023-04-06 ESL的EDI去掉校验后,这里需要截取需要按照最大35来截取 + ShippingList = formatlengthStr(Shipping, 75); + */ + ShippingList = formatlengthStr(Shipping, 35); + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + r.WriteLine("21::" + formatListStr(ShippingList, 6) + "'"); + icount = icount + 1; + + } + + + Shipping = formatEdiStr("txt", bill.NOTIFYPARTY); + /* + 2023-04-06 ESL的EDI去掉校验后,这里需要截取需要按照最大35来截取 + ShippingList = formatlengthStr(Shipping, 75); + */ + ShippingList = formatlengthStr(Shipping, 35); + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + r.WriteLine("22::" + formatListStr(ShippingList, 6) + "'"); + icount = icount + 1; + + } + + + if (InttrEdi.filetype == "E") + { + Shipping = formatEdiStr("txt", bill.NOTIFYPARTY2); + ShippingList = formatlengthStr(Shipping, 75); + + if (Shipping != "") + { + + r.WriteLine("23::" + formatListStr(ShippingList, 6) + "'"); + icount = icount + 1; + + + + } + + } + + + var cargoid = bill.CARGOID; + if (cargoid == "" || cargoid == " ") cargoid = "S"; + + r.WriteLine("41:1:" + bill.HSCODE + ":" + cargoid + ":" + bill.PKGS.ToString() + ":" + bill.KINDPKGS_EDI_CODE + ":" + bill.KINDPKGS + ":" + bill.KGS.ToString("0.###") + ":" + + bill.CBM.ToString("0.###") + "::::::" + bill.KGS.ToString("0.###") + ":::'"); + + icount = icount + 1; + if (cargoid == "R") + r.WriteLine("43::::::::::" + bill.REEFERF + ":C:" + bill.TEMPSET + ":" + bill.TEMPMIN + ":" + bill.TEMPMAX + ":::::'"); + else if (cargoid == "D") + r.WriteLine("43:" + bill.DCLASS + ":" + bill.DPAGE + ":" + bill.DUNNO + ":" + bill.DLABEL + "::::::::::::'"); + + icount = icount + 1; + + + Shipping = formatEdiStr("txt", bill.MARKS); + ShippingList = formatlengthStr(Shipping, 35); + + for (var i = 0; i < Math.Ceiling(Convert.ToDecimal(Convert.ToDecimal(ShippingList.Count) / Convert.ToDecimal(10))); i++) + { + var tempstr = "44:"; + for (var z = 0; z < 10; z++) + { + if ((i * 10 + z) < ShippingList.Count) + tempstr = tempstr + ShippingList[i * 10 + z]; + if (z < 9) tempstr = tempstr + ":"; + } + if (tempstr != "44:") + { + r.WriteLine(tempstr + "'"); + icount++; + } + } + + Shipping = formatEdiStr("txt", bill.DESCRIPTION); + ShippingList = formatlengthStr(Shipping, 70); + + var m = 1; + var strtemp = ""; + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + + for (var i = 0; i < ShippingList.Count; i++) + { + if (ShippingList[i] != "") + { + if (m <= 5) + { + if (m == 1) strtemp = "47:" + ShippingList[i] + ":"; + else + { + if (m == 5) + strtemp = strtemp + ShippingList[i]; + else + strtemp = strtemp + ShippingList[i] + ":"; + } + } + else + { + m = 1; + r.WriteLine(strtemp + "'"); + strtemp = "47:" + ShippingList[i] + ":"; + icount = icount + 1; + } + m = m + 1; + } + } + } + if (strtemp != "") + { + r.WriteLine(strtemp + "'"); + icount = icount + 1; + } + + var ISSOC = "N"; + if (bill.ISCONTAINERSOC) ISSOC = "Y"; + + var ctnsumlist = new List(); + + foreach (var ctn in bill.CTNLIST) + { + var newctnsum = ctnsumlist.Find(x => x.CTNALLCODE == ctn.CTNALLCODE); + if (newctnsum == null) + { + var ctnsum = new SeaExportCtnEDIBaseModel(); + ctnsum.CTNALLCODE = ctn.CTNALLCODE; + ctnsum.CTNNUM = ctn.CTNNUM; + if (bill.ISCONTAINERSOC && !string.IsNullOrEmpty(ctn.CNTRNO)) + { + if (!string.IsNullOrEmpty(ctnsum.CNTRNO)) + { + ctnsum.CNTRNO = ctn.CNTRNO; + } + else + { + ctnsum.CNTRNO = ctnsum.CNTRNO + "," + ctn.CNTRNO; + + } + } + ctnsumlist.Add(ctnsum); + + } + else + { + newctnsum.CTNNUM = newctnsum.CTNNUM + ctn.CTNNUM; + if (bill.ISCONTAINERSOC && !string.IsNullOrEmpty(ctn.CNTRNO)) + { + if (!string.IsNullOrEmpty(newctnsum.CNTRNO)) + { + newctnsum.CNTRNO = ctn.CNTRNO; + } + else + { + newctnsum.CNTRNO = newctnsum.CNTRNO + "," + ctn.CNTRNO; + + } + } + + } + } + foreach (var ctnsum in ctnsumlist) + { + if (InttrEdi.filetype == "E") + { + r.WriteLine("48:" + ctnsum.CTNALLCODE + ":" + ctnsum.CTNNUM + ":F:::::" + ISSOC + "'"); + icount = icount + 1; + } + else + { + var cntrnostr = ""; + var isrstr = "N"; + if (cargoid == "R") isrstr = "Y"; + r.WriteLine("48:" + ctnsum.CTNALLCODE + ":" + ctnsum.CTNNUM + ":F:::::" + ISSOC + ":" + cntrnostr + ":::" + isrstr + "'"); + icount = icount + 1; + + } + + } + + foreach (var ctn in bill.CTNLIST) + { + + if (InttrEdi.filetype == "E") + { + r.WriteLine("51:" + ctn.CNTRNO + ":" + ctn.CTNALLCODE + ":" + + ctn.SEALNO + ":" + ctn.PKGS.ToString() + ":" + ctn.KGS.ToString("0.###") + "::" + ctn.CBM.ToString("0.###") + ":" + bill.EDIATTNEMAIL + "'"); + icount = icount + 1; + + if (bill.CTNGOODSLIST != null && bill.CTNGOODSLIST.Count != 0) + { + foreach (var ctnhs in bill.CTNGOODSLIST) + { + r.WriteLine("53:" + ctnhs.HSCODE + ":" + ctnhs.PKGS.ToString() + ":" + + ctnhs.KGS.ToString("0.###") + ":" + ctnhs.CBM.ToString("0.###") + ":" + ctnhs.KINDPKGS_EDI_CODE + ":" + ctnhs.KINDPKGS + "'"); + icount = icount + 1; + Shipping = formatEdiStr("txt", ctnhs.DESCRIPTION); + ShippingList = formatlengthStr(Shipping, 70); + m = 1; + strtemp = ""; + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + + for (var i = 0; i < ShippingList.Count; i++) + { + if (ShippingList[i] != "") + { + if (m <= 5) + { + if (m == 1) strtemp = "54:" + ShippingList[i] + ":"; + else + { + if (m == 5) + strtemp = strtemp + ShippingList[i]; + else + strtemp = strtemp + ShippingList[i] + ":"; + } + } + else + { + m = 1; + r.WriteLine(strtemp + "'"); + strtemp = "54:" + ShippingList[i] + ":"; + icount = icount + 1; + } + m = m + 1; + } + } + } + if (strtemp != "") + { + r.WriteLine(strtemp + "'"); + icount = icount + 1; + } + + + } + } + } + else + { + if (!string.IsNullOrEmpty(ctn.CNTRNO)) + { + r.WriteLine("51:" + ctn.CNTRNO + ":" + ctn.CTNALLCODE + ":" + + ctn.SEALNO + ":" + ctn.PKGS.ToString() + ":" + ctn.KGS.ToString("0.###") + ":'"); + icount = icount + 1; + } + } + //} + } + + } + + icount = icount + 1; + r.WriteLine("99:" + icount.ToString() + "'"); + r.Close(); + f.Close(); + + result.Succeeded = true; + result.ExtraData1 = filename; + return result; + } + #endregion + + + + } + +} diff --git a/ds-wms-service/DS.WMS.Core/Op/EDI/EdiDataResult.cs b/ds-wms-service/DS.WMS.Core/Op/EDI/EdiDataResult.cs new file mode 100644 index 00000000..d19ba4a9 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Op/EDI/EdiDataResult.cs @@ -0,0 +1,63 @@ +using DS.Module.Core; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DS.WMS.Core.Op.EDI +{ + /// + /// Edi 返回 + /// + public class EdiDataResult + { + /// + /// 获取 是否成功 + /// + public bool Succeeded = false; + /// + /// 获取或设置 返回消息 + /// + public string Message { get; set; } + /// + /// 返回 + /// + public string Data { get; set; } + /// + /// 拓展数据1 + /// + public string ExtraData1 { get; set; } + /// + /// 拓展数据1 + /// + public string ExtraData2 { get; set; } + + /// + /// + /// + /// + /// + public static EdiDataResult Failed(string message) + { + return new EdiDataResult() + { + Succeeded = false, + Message = message + }; + } + /// + /// + /// + /// + /// + public static EdiDataResult Success(string message) + { + return new EdiDataResult() + { + Succeeded = true, + Message = message + }; + } + } +} diff --git a/ds-wms-service/DS.WMS.Core/Op/EDI/EmailApiDto.cs b/ds-wms-service/DS.WMS.Core/Op/EDI/EmailApiDto.cs new file mode 100644 index 00000000..d86d2281 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Op/EDI/EmailApiDto.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DS.WMS.Core.Op.EDI +{ + /// + /// + /// + public class EmailApiDto + { + public string SendTo { get; set; } + + public string Title { get; set; } + + public string Body { get; set; } + + public string SmtpConfig { get; set; } = "NOREPLAY"; + + public bool isCallback { get; set; } = false; + + public List Attaches { get; set; } + } + + public class AttachesInfo + { + public string AttachName { get; set; } + + public string AttachContent { get; set; } + } +} diff --git a/ds-wms-service/DS.WMS.Core/Op/EDI/InttraEdiHelper.cs b/ds-wms-service/DS.WMS.Core/Op/EDI/InttraEdiHelper.cs new file mode 100644 index 00000000..da627b97 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Op/EDI/InttraEdiHelper.cs @@ -0,0 +1,2319 @@ +using DS.Module.Core; +using DS.WMS.Core.Op.Dtos; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace DS.WMS.Core.Op.EDI +{ + /// + /// INTTRA 订舱、截单帮助类 + /// + public class InttraEdiHelper + { + public InttraEdiHelper() + { + } + + #region 基本函数 + public static string GetCarrierName(string str) + { + if (str == "MAEU") return "MAERSK LINE"; + if (str == "MCCQ") return "MCC TRANSPORT SINGAPORE"; + if (str == "ANNU") return "ANL CONTAINER LINE"; + if (str == "CMDU") return "CMA CGM"; + if (str == "CHNL") return "CNC"; + if (str == "HLCU") return "HAPAG-LLOYD"; + if (str == "SUDU") return "HAMBURG"; + if (str == "MSCU") return "MSC"; + if (str == "DAAE") return "DELMAS"; + if (str == "UASC") return "UASC"; + if (str == "COSU") return "COSCO"; + if (str == "OOLU") return "OOCL"; + else return ""; + } + public static string GetBillNum(string str) + { + if (str == "ZERO") return "0"; + if (str == "ONE") return "1"; + if (str == "TWO") return "2"; + if (str == "THREE") return "3"; + if (str == "FOUR") return "4"; + if (str == "FIVE") return "5"; + if (str == "SIX") return "6"; + if (str == "SERVEN") return "7"; + if (str == "EIGHT") return "8"; + if (str == "NINE") return "9"; + if (str == "TEN") return "10"; + else return ""; + } + public static string GetBillNum2(string str) + { + if (str == "ZERO") return "00"; + if (str == "ONE") return "01"; + if (str == "TWO") return "02"; + if (str == "THREE") return "03"; + if (str == "FOUR") return "04"; + if (str == "FIVE") return "05"; + if (str == "SIX") return "06"; + if (str == "SERVEN") return "07"; + if (str == "EIGHT") return "08"; + if (str == "NINE") return "09"; + if (str == "TEN") return "10"; + else return ""; + } + + #region 判断中文字符 + public static bool IsChinese(char c) + { + return (int)c > 0x80; + } + public static bool StringIsChinese(string str) + { + var result = false; + for (int i = 1; i < str.Length; i++) + { + if (IsChinese(str[i])) + { + result = true; + return result; + } + } + for (int i = 0; i < str.Length; i++) + { + string stemp = str.Substring(i, 1); + int ilen = System.Text.Encoding.Default.GetByteCount(stemp); + if (ilen == 2) + { + result = true; + return result; + } + + } + + return result; + } + + #endregion + + #region 文本字段判断每行是否符合 + /// + /// edi 文本格式处理判断(例如:1行35个字符不超过5行) + /// + /// 文件类型(例如:txt、xml) + /// 要处理的数据 + /// 每行长度 + /// 主提单号 + /// 数据类型(例如:发货人内容、货描等) + /// 限制录入的行数(“0”代表不限制) + /// 限录后多出的放到货描中的数据的连接符(例如:“*”发货人内容、“**”收件人等) + /// + public static System.String formatlengthError(string fileType, string str, int length, string sMBLNO, string sType, int rowNum, string sSymbol, bool isHuoMiao) + { + string error = ""; + string Shipping = str; + if (fileType == "txt") + { + Shipping = formatEdiStr("txt", str); + } + else if (fileType == "xml") + { + Shipping = formatEdiStr("txt", str); + } + string[] argAGENT = Shipping.Split(new string[] { "\r\n" }, StringSplitOptions.None); + if (argAGENT.Length > 0) + { + if (argAGENT.Length == 1) + { + argAGENT = Shipping.Split(new string[] { "\n" }, StringSplitOptions.None); + if (argAGENT.Length > 0) + { + if (argAGENT.Length > rowNum && rowNum != 0) + { + if (isHuoMiao) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据!"; + } + else + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据,多余信息请手动以“" + sSymbol + "”号开头放到货物描述中!(例如:“货描内容" + sSymbol + "超出部分”)"; + } + } + for (int j = 0; j < argAGENT.Length; j++) + { + //List AgentList = formatlengthStr(argAGENT[j].ToString(), 35); + if (argAGENT[j].ToString().Length > length) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 第" + (j + 1) + "行超过" + length + "个字符"; + } + } + } + } + else + { + if (argAGENT.Length > rowNum && rowNum != 0) + { + if (isHuoMiao) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据!"; + } + else + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据,多余信息请手动以“" + sSymbol + "”号开头放到货物描述中!(例如:“货描内容" + sSymbol + "超出部分”)"; + } + } + for (int j = 0; j < argAGENT.Length; j++) + { + //List AgentList = formatlengthStr(argAGENT[j].ToString(), 35); + if (argAGENT[j].ToString().Length > length) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 第" + (j + 1) + "行超过" + length + "个字符"; + } + } + } + } + return error; + } + #endregion + + #region 字符转义 + /// + /// 各种文本转义字符 + /// + /// 文件类型(例如:txt、xml) + /// 文本字符串 + /// + public static string formatEdiStr(string fileType, string str) + { + if (str == null) + str = string.Empty; + + if (fileType == "txt") + { + return str.Replace("?", "??").Replace(":", "?:").Replace("+", "?+").Replace("'", "?'"); + } + else if (fileType == "xml") + { + return str.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace("\"", """).Replace("'", "'"); + } + else if (fileType == "sitc") + { + return str.Replace("?", "??").Replace(":", "?:").Replace("'", "?'"); + } + else + { + return str; + } + } + #endregion + #region 格式化每行 + public static List formatlengthStr(string str, int length, bool formatstr = false, bool nodelsp = false) + { + str = str.Replace("\r\n", "\\"); + str = str.Replace("\n", "\\"); + str = str.Replace("\r", " "); + string[] StrList = str.Split('\\'); + var strtemp = ""; + var strnewline = ""; + var strtempnewline = ""; + char[] spstring = { ' ', ';', ',', '.', ':', '/', '(', ')', '?', '+', '-' }; + List DestList = new List(); + for (var i = 0; i <= StrList.Length - 1; i++) + { + if (StrList[i].Length <= length) + { + if (formatstr) + DestList.Add(formatEdiStr("txt", StrList[i])); + else + DestList.Add(StrList[i]); + + } + else + { + strtemp = StrList[i] + " "; + strtempnewline = ""; + strnewline = ""; + for (var j = 0; j < strtemp.Length; j++) + { + strtempnewline = strtempnewline + strtemp[j]; + if (strtemp[j] == ' ' || strtemp[j] == ':' || strtemp[j] == ',' || strtemp[j] == '.' || strtemp[j] == ':' || strtemp[j] == '/' + || strtemp[j] == '?' || strtemp[j] == ')' || strtemp[j] == '}' || strtemp[j] == '+' || strtemp[j] == '-') + { + if ((strnewline.Length + strtempnewline.Length) <= length) + strnewline = strnewline + strtempnewline; + else + { + if (formatstr) + DestList.Add(formatEdiStr("txt", strnewline)); + else + DestList.Add(strnewline); + strnewline = strtempnewline; + + } + strtempnewline = ""; + } + } + if (nodelsp) + { + if (formatstr) + DestList.Add(formatEdiStr("txt", strnewline)); + else DestList.Add(strnewline); + } + else if (strnewline.Trim() != "") + { + if (formatstr) + DestList.Add(formatEdiStr("txt", strnewline)); + else DestList.Add(strnewline); + } + } + + } + + return DestList; + } + #endregion + #endregion + + #region 检查 + public static string IsCreateINTTR(EDIBaseModel InttrEdi) + { + var error = ""; + + if (string.IsNullOrEmpty(InttrEdi.SENDCODE)) + { error = error + "
发送方代码不能为空"; } + + if (string.IsNullOrEmpty(InttrEdi.SENDNAME)) + { error = error + "
发送方名称不能为空"; } + + if (string.IsNullOrEmpty(InttrEdi.RECEIVECODE)) + { error = error + "
接收方代码不能为空"; } + + if (InttrEdi.filetype == "B") + { + //if (InttrEdi.UseForWarderCode) + //{ + // if (string.IsNullOrEmpty(InttrEdi.ForWarderCode)) + // { error = error + "
货代代码不能为空"; } + + // if (string.IsNullOrEmpty(InttrEdi.ForWarderName)) + // { error = error + "
货代称呼不能为空"; } + //} + } + + + foreach (var headData in InttrEdi.BSLIST) + { + + if (InttrEdi.filetype == "B") + { + if (InttrEdi.UseForWarderCode) + { + if (string.IsNullOrEmpty(headData.ORDERNO)) + { error = error + "
订舱编号不能为空"; } + } + } + + + if (headData.CARRIERID != "YML") + { + if (string.IsNullOrEmpty(headData.OpEName)) + { error = error + "
操作的英文名不能为空"; } + + if (string.IsNullOrEmpty(headData.OpTel)) + { error = error + "
操作的电话不能为空"; } + + if (string.IsNullOrEmpty(headData.OpEmail)) + { error = error + "
操作的邮箱不能为空"; } + } + if (string.IsNullOrEmpty(headData.MBLNO)) + { error = error + "
主提单号不能为空"; } + + if (string.IsNullOrEmpty(headData.BLFRT)) + { error = error + "
提单号:" + headData.MBLNO + " 付费方式不能为空"; } + + if (string.IsNullOrEmpty(headData.SERVICE)) + { error = error + "
提单号:" + headData.MBLNO + " 运输条款不能为空"; } + + if (string.IsNullOrEmpty(headData.CONTRACTNO)) + { error = error + "
提单号:" + headData.MBLNO + " 运费协议号不能为空"; } + if (string.IsNullOrEmpty(headData.CARGOID)) + { error = error + "
提单号:" + headData.MBLNO + " 货物标识不能为空"; } + + + if (headData.CARGOID == "D" || headData.SERVICE == "DOOR-DOOR" || headData.SERVICE == "DOOR-CY" || headData.SERVICE == "CY-DOOR") + { + if (headData.CARRIERID != "YML") + { + if (string.IsNullOrEmpty(headData.EDIATTN)) + { error = error + "
EDI信息联系人不能为空"; } + + if (string.IsNullOrEmpty(headData.EDIATTNTEL)) + { error = error + "
EDI信息联系人电话不能为空"; } + + if (string.IsNullOrEmpty(headData.EDIATTNEMAIL)) + { error = error + "
EDI信息联系人邮箱不能为空"; } + } + } + + + if (InttrEdi.filetype == "E") + { + if (string.IsNullOrEmpty(headData.VESSEL)) + { error = error + "
提单号:" + headData.MBLNO + " 船名不能为空"; } + + if (string.IsNullOrEmpty(headData.VOYNO)) + { error = error + "
提单号:" + headData.MBLNO + " 航次不能为空"; } + } + if (InttrEdi.filetype == "E") + { + if (headData.SIREMARK.IndexOf("PLEASE BOOK OCEAN CARRIER") > -1 || headData.SIREMARK.ToString().Trim() == "") + { + if (headData.CARRIEREDICODE == "COSU") + { + error = error + "
提单号:" + headData.MBLNO + " 请在SI备注中输入:COSCO 销售的营销代码(此代码船公司会直接提供)"; + } + else + { + //if (carrier != "YML") + //error = error + "
提单号:" + bill.MBLNO + " EDI备注中不能为空"; + } + } + else + { + if (StringIsChinese(headData.SIREMARK)) + { + error = error + "
提单号:" + headData.MBLNO + " SI备注中含有中文或双字节字符"; + } + + } + } + else + { + if (headData.EDIREMARK.IndexOf("PLEASE BOOK OCEAN CARRIER") > -1 || headData.EDIREMARK.ToString().Trim() == "") + { + if (headData.CARRIEREDICODE == "COSU") + { + error = error + "
提单号:" + headData.MBLNO + " 请在EDI备注中输入:COSCO 销售的营销代码(此代码船公司会直接提供)"; + } + else + { + //if (carrier != "YML") + //error = error + "
提单号:" + bill.MBLNO + " EDI备注中不能为空"; + } + } + else + { + if (StringIsChinese(headData.EDIREMARK)) + { + error = error + "
提单号:" + headData.MBLNO + " EDI备注中含有中文或双字节字符"; + } + } + } + //if (string.IsNullOrEmpty(headData.CARRIER)) + //{ error = error + "
提单号:" + headData.MBLNO + " 船公司不能为空"; } + + if (string.IsNullOrEmpty(headData.CARRIEREDICODE)) + { error = error + "
提单号:" + headData.MBLNO + " 船公司EDI代码不能为空"; } + + + if (string.IsNullOrEmpty(headData.SHIPPER)) + { + error = error + "
提单号:" + headData.MBLNO + " 发货人不能为空"; + } + else + { + if (StringIsChinese(headData.SHIPPER)) + { + error = error + "
提单号:" + headData.MBLNO + " 发货人含有中文或双字节字符"; + } + else + { + if (headData.CARRIEREDICODE == "HLCU") + { + error += formatlengthError("txt", headData.SHIPPER, 35, headData.MBLNO, "发货人", 6, "-", false); + } + else + { + error += formatlengthError("txt", headData.SHIPPER, 35, headData.MBLNO, "发货人", 6, "*", false); + } + } + } + //} + + + + if (string.IsNullOrEmpty(headData.CONSIGNEE)) + { + error = error + "
提单号:" + headData.MBLNO + " 收货人不能为空"; + } + else + { + if (StringIsChinese(headData.CONSIGNEE)) + { + error = error + "
提单号:" + headData.MBLNO + " 收货人含有中文或双字节字符"; + } + else + { + if (headData.CARRIEREDICODE == "HLCU") + { + error += formatlengthError("txt", headData.CONSIGNEE, 35, headData.MBLNO, "收货人", 6, "--", false); + } + else + { + error += formatlengthError("txt", headData.CONSIGNEE, 35, headData.MBLNO, "收货人", 6, "**", false); + } + } + } + + + if (headData.SERVICE == "CY-DOOR") + { + if (string.IsNullOrEmpty(headData.CONSIGNEEDOORADDR)) + { + error = error + "
提单号:" + headData.MBLNO + " 运输条款为:CY-DOOR,EDI信息中的DOOR地址不能为空"; + } + else + { + if (StringIsChinese(headData.CONSIGNEEDOORADDR)) + { + error = error + "
提单号:" + headData.MBLNO + " DOOR地址含有中文或双字节字符"; + } + } + } + if (headData.SERVICE == "DOOR-CY") + { + if (string.IsNullOrEmpty(headData.SHIPPERDOORADDR)) + { + error = error + "
提单号:" + headData.MBLNO + " 运输条款为:DOOR-CY,EDI信息中的联系人地址不能为空"; + } + else + { + if (StringIsChinese(headData.SHIPPERDOORADDR)) + { + error = error + "
提单号:" + headData.MBLNO + " 联系人地址含有中文或双字节字符"; + } + } + } + + + if (string.IsNullOrEmpty(headData.NOTIFYPARTY)) + { + //CMA 订舱时可以不填通知人 + if (headData.CARRIEREDICODE != "CMDU") + { + error = error + "
提单号:" + headData.MBLNO + " 通知人不能为空"; + } + } + else + { + if (StringIsChinese(headData.NOTIFYPARTY)) + { + error = error + "
提单号:" + headData.MBLNO + " 通知人含有中文或双字节字符"; + } + else + { + if (headData.CARRIEREDICODE == "HLCU") + { + error += formatlengthError("txt", headData.NOTIFYPARTY, 35, headData.MBLNO, "通知人", 6, "---", false); + } + else + { + error += formatlengthError("txt", headData.NOTIFYPARTY, 35, headData.MBLNO, "通知人", 6, "***", false); + } + } + } + + if (!string.IsNullOrEmpty(headData.NOTIFYPARTY2)) + { + error += formatlengthError("txt", headData.NOTIFYPARTY2, 35, headData.MBLNO, "第二通知人", 5, "", false); + } + + if (string.IsNullOrEmpty(headData.MARKS)) + { + error = error + "
提单号:" + headData.MBLNO + " 唛头不能为空"; + } + else + { + if (StringIsChinese(headData.MARKS)) + { + error = error + "
提单号:" + headData.MBLNO + " 唛头含有中文或双字节字符"; + } + else + { + error += formatlengthError("txt", headData.MARKS, 35, headData.MBLNO, "唛头", 0, "", false); + } + } + + if (string.IsNullOrEmpty(headData.DESCRIPTION)) + { + error = error + "
提单号:" + headData.MBLNO + " 货物描述不能为空"; + } + else + { + if (StringIsChinese(headData.DESCRIPTION)) + { + error = error + "
提单号:" + headData.MBLNO + " 货物描述含有中文或双字节字符"; + } + else + { + //error += formatlengthError("txt", bill.DESCRIPTION, 35, bill.MBLNO, "货物描述", 0, ""); + } + } + if (string.IsNullOrEmpty(headData.PORTLOADID) || headData.PORTLOADID.Length != 5) + { error = error + "
提单号:" + headData.MBLNO + " 装货港代码不能为空或录入不正确(必须是5位代码)"; } + + if (string.IsNullOrEmpty(headData.PORTLOAD)) + { error = error + "
提单号:" + headData.MBLNO + " 装货港不能为空"; } + + if (string.IsNullOrEmpty(headData.ETD)) + { + error = error + "
提单号:" + headData.MBLNO + " 开船日期不能为空"; + return error; + } + if (string.IsNullOrEmpty(headData.PORTDISCHARGEID) || headData.PORTDISCHARGEID.Length != 5) + { error = error + "
提单号:" + headData.MBLNO + " 卸货港代码不能为空或录入不正确(必须是5位代码)"; } + if (string.IsNullOrEmpty(headData.PORTDISCHARGE)) + { error = error + "
提单号:" + headData.MBLNO + " 卸货港不能为空"; } + if (string.IsNullOrEmpty(headData.DESTINATION)) + { + if (string.IsNullOrEmpty(headData.DESTINATIONID) || headData.DESTINATIONID.Length != 5) + { error = error + "
提单号:" + headData.MBLNO + " 目的地代码不能为空或录入不正确(必须是5位代码)"; } + } + if (string.IsNullOrEmpty(headData.KINDPKGS_EDI_CODE)) + { error = error + "
提单号:" + headData.MBLNO + " 包装EDI代码不能为空"; } + if (headData.PKGS == 0) + { error = error + "
提单号:" + headData.MBLNO + " 件数不能为0"; } + if (headData.KGS == 0) + { error = error + "
提单号:" + headData.MBLNO + " 毛重不能为0"; } + if (headData.CBM == 0) + { error = error + "
提单号:" + headData.MBLNO + " 尺码不能为0"; } + + if (headData.CARGOID == "D") + { + if (string.IsNullOrEmpty(headData.DCLASS)) + { error = error + "
提单号:" + headData.MBLNO + " 危险品分类不能为空"; } + + if (string.IsNullOrEmpty(headData.DUNNO)) + { error = error + "
提单号:" + headData.MBLNO + " 危险品编号不能为空"; } + } + if (headData.CARGOID == "R") + { + if (headData.TEMPSET == null || headData.TEMPSET == "") + { error = error + "
提单号:" + headData.MBLNO + " 设置温度不能为空"; } + if (headData.REEFERF == null || headData.REEFERF == "") + { error = error + "
提单号:" + headData.MBLNO + " 通风度不能为空"; } + } + + if (headData.BLFRT != null && headData.BLFRT.IndexOf("PREPAID") >= 0) + { + if (string.IsNullOrEmpty(headData.PREPARDAT)) + { error = error + "
提单号:" + headData.MBLNO + " 预付地点不能为空"; } + if (string.IsNullOrEmpty(headData.PREPARDATID)) + { error = error + "
提单号:" + headData.MBLNO + " 预付地点EDI代码不能为空"; } + } + else if (headData.BLFRT != null && headData.BLFRT.IndexOf("COLLECT") >= 0) + { + if (string.IsNullOrEmpty(headData.PAYABLEAT)) + { error = error + "
提单号:" + headData.MBLNO + " 到付地点不能为空"; } + if (string.IsNullOrEmpty(headData.PAYABLEATID)) + { error = error + "
提单号:" + headData.MBLNO + " 到付地点EDI代码不能为空"; } + } + + if (InttrEdi.filetype == "E") + { + if (string.IsNullOrEmpty(headData.ISSUEPLACEID)) + { error = error + "
提单号:" + headData.MBLNO + " 签单地点或到签单地点EDI代码不能为空"; } + } + var ctnlist = headData.CTNLIST; + if (ctnlist.Count == 0) { error = error + "
提单号:" + headData.MBLNO + " 集装箱信息不能为空"; }; + + if (InttrEdi.filetype == "E") + { + #region 集装箱判断检查 + if (ctnlist.Count != 0) + { + Decimal dlPKGS = 0; + Decimal dlKGS = 0; + Decimal dlCBM = 0; + foreach (var ctn in ctnlist) + { + if (string.IsNullOrEmpty(ctn.CTNALLCODE)) + { error = error + "
提单号:" + headData.MBLNO + " 集装箱箱型EDI代码不能为空"; } + if (string.IsNullOrEmpty(ctn.CNTRNO)) + { error = error + "
提单号:" + headData.MBLNO + " 箱号不能为空"; } + if (string.IsNullOrEmpty(ctn.SEALNO)) + { error = error + "
提单号:" + headData.MBLNO + " 封号不能为空"; } + if (headData.BYCOUNTRY == "BRAZIL") + { + // 20240402 if (string.IsNullOrEmpty(ctn.TAREWEIGHT) || Convert.ToDecimal(ctn.TAREWEIGHT) == 0) + if (ctn.TAREWEIGHT == 0) + { error = error + "
提单号:" + headData.MBLNO + " 箱皮重不能为空"; } + } + if (ctn.KINDPKGS != headData.KINDPKGS) + { error = error + "
提单号:" + headData.MBLNO + " 中的包装类型与集装箱的包装类型不同"; } + dlPKGS += Convert.ToDecimal(ctn.PKGS); + dlKGS += Convert.ToDecimal(ctn.KGS); + dlCBM += Convert.ToDecimal(ctn.CBM); + } + + if (dlPKGS != Convert.ToDecimal(headData.PKGS)) + { error = error + "
提单号:" + headData.MBLNO + " 集装箱件数合计数必须等于委托单总件数"; } + if (dlKGS != Convert.ToDecimal(headData.KGS)) + { error = error + "
提单号:" + headData.MBLNO + " 集装箱重量合计数必须等于委托单总重量数"; } + if (dlCBM != Convert.ToDecimal(headData.CBM)) + { error = error + "
提单号:" + headData.MBLNO + " 集装箱尺码合计数必须等于委托单总尺码数"; } + } + if (headData.CTNGOODSLIST != null && headData.CTNGOODSLIST.Count > 0) + { + foreach (var ctn in ctnlist) + { + var isfind = false; + Int32 ctngoodssumpkgs = 0; + decimal ctngoodssumkgs = 0; + decimal ctngoodssumcbm = 0; + headData.CTNGOODSLIST.ForEach(i => + { + if (i.CNTRNO == ctn.CNTRNO) + { + isfind = true; + ctngoodssumpkgs = ctngoodssumpkgs + i.PKGS; + ctngoodssumkgs = ctngoodssumkgs + i.KGS; + ctngoodssumcbm = ctngoodssumcbm + i.CBM; + } + }); + if (!isfind) + { + error = error + "
提单号:" + headData.MBLNO + "的“" + ctn.CNTRNO + "”未添加分箱明细!"; + } + else + { + if (ctngoodssumpkgs != Convert.ToDecimal(ctn.PKGS)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctn.CNTRNO + " 分箱明细件数合计数不等于集装箱件数"; } + if (ctngoodssumkgs != Convert.ToDecimal(ctn.KGS)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctn.CNTRNO + " 分箱明细毛重合计数不等于集装箱毛重"; } + if (ctngoodssumcbm != Convert.ToDecimal(ctn.CBM)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctn.CNTRNO + " 分箱明细尺码合计数不等于集装箱毛重"; } + + } + + } + + foreach (var ctngood in headData.CTNGOODSLIST) + { + if (string.IsNullOrEmpty(ctngood.KINDPKGS)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱明细包装类型不能为空"; } + if (string.IsNullOrEmpty(ctngood.DESCRIPTION)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱货物描述不能为空"; } + else + { + error += formatlengthError("txt", ctngood.DESCRIPTION, 70, headData.MBLNO, "的“" + ctngood.CNTRNO + "”箱号的分箱货物描述", 0, "", false); + } + //if (string.IsNullOrEmpty(ctngood.HSCODE)) + //{ error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱HS编码不能为空"; } + if (string.IsNullOrEmpty(ctngood.KINDPKGS_EDI_CODE)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱明细包装类型代码不能为空"; } + + } + + } + + #endregion + + if (headData.BYCOUNTRY == "USA") + { + if (string.IsNullOrEmpty(headData.CONSIGNEEPOSTCODE)) + { error = error + "
提单号:" + headData.MBLNO + " 收货人邮编不能为空"; } + if (string.IsNullOrEmpty(headData.NOTIFYPARTYPOSTCODE)) + { error = error + "
提单号:" + headData.MBLNO + " 通知人邮编不能为空"; } + } + else if (headData.BYCOUNTRY == "CANADA") + { + if (string.IsNullOrEmpty(headData.CONSIGNEEPOSTCODE)) + { error = error + "
提单号:" + headData.MBLNO + " 收货人邮编不能为空"; } + } + else if (headData.BYCOUNTRY == "BRAZIL") + { + if (string.IsNullOrEmpty(headData.CONSIGNEECOUNTRY)) + { error = error + "
提单号:" + headData.MBLNO + " 收货人国家代码不能为空"; } + if (string.IsNullOrEmpty(headData.CONSIGNEETAXNO)) + { error = error + "
提单号:" + headData.MBLNO + " 收货人税号不能为空"; } + if (string.IsNullOrEmpty(headData.NOTIFYPARTYCOUNTRY)) + { error = error + "
提单号:" + headData.MBLNO + " 通知人国家代码不能为空"; } + if (string.IsNullOrEmpty(headData.NOTIFYPARTYTAXNO)) + { error = error + "
提单号:" + headData.MBLNO + " 通知人税号不能为空"; } + if (string.IsNullOrEmpty(headData.GOODSNCM)) + { error = error + "
提单号:" + headData.MBLNO + " 货物NCM编码不能为空"; } + } + } + + } + return error; + } + #endregion + + #region 订舱 + public static EdiDataResult CreateEdiINTTR(EDIBaseModel InttrEdi) + { + EdiDataResult result = new EdiDataResult { Succeeded = false }; + + string filename = InttrEdi.filerpath + "\\" + InttrEdi.BSLIST[0].MBLNO + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt"; + + //如果是部署linux需要修改路径 + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + filename = filename.Replace("\\", "/"); + + //if (System.IO.File.Exists(filename)) + //{ + // System.IO.File.Delete(filename); + //} + FileStream f = new FileStream(filename, FileMode.Create); + StreamWriter r = new StreamWriter(f, Encoding.Default); + var icount = 0; + var bsno = ""; + foreach (var bill in InttrEdi.BSLIST) + { + bsno = bill.ORDERNO; + r.WriteLine("UNB+UNOC:2+" + InttrEdi.SENDCODE + "SO:ZZZ+" + InttrEdi.RECEIVECODE + ":ZZZ+" + DateTime.Now.ToString("yyMMdd:HHmm") + "+" + bill.ORDERNO + "'"); + r.WriteLine("UNH+" + bill.ORDERNO + "+IFTMBF:D:99B:UN'"); + icount = icount + 2; + + if (bill.CARRIEREDICODE == "HLCU") + { + if (InttrEdi.filerole == "9") + r.WriteLine("BGM+335+" + bill.ORDERNO + "SO+9'"); + else if (InttrEdi.filerole == "1") + r.WriteLine("BGM+335+" + bill.ORDERNO + "SO+1'"); + else + r.WriteLine("BGM+335+" + bill.ORDERNO + "SO+5'"); + + } + else + { + if (InttrEdi.filerole == "9") + r.WriteLine("BGM+335+" + bill.MBLNO + "SO+9'"); + else if (InttrEdi.filerole == "1") + r.WriteLine("BGM+335+" + bill.ORDERNO + "SO+1'"); + else + r.WriteLine("BGM+335+" + bill.MBLNO + "SO+5'"); + + } + + r.WriteLine("DTM+137:" + DateTime.Now.ToString("yyyyMMddHHmm") + ":203'"); + icount = icount + 2; + + if (bill.SERVICEEDICODE.ToUpper() == "DOOR-DOOR") + { + r.WriteLine("TSR+27+2'"); + } + else if (bill.SERVICEEDICODE.ToUpper() == "DOOR-CY") + { + r.WriteLine("TSR+28+2'"); + } + else if (bill.SERVICEEDICODE.ToUpper() == "CY-DOOR") + { + r.WriteLine("TSR+29+2'"); + } + else + { + r.WriteLine("TSR+30+2'"); + } + + var str_pay = ""; + if (bill.BLFRT.IndexOf("PREPAID") >= 0) + str_pay = bill.PREPARDAT; + if (bill.BLFRT.IndexOf("COLLECT") >= 0) + str_pay = bill.PAYABLEAT; + + /* 2024-04-08 JHQ 参考东胜去掉了 + if (bill.CARRIEREDICODE == "HLCU") + { + r.WriteLine("FTX+AAI+++" + bill.BLFRT + " Payable at " + str_pay + " " + bill.SERVICE + " " + bill.CONTRACTNO + " " + + bill.PKGS.ToString() + bill.KINDPKGS + " " + formatEdiStr("txt", bill.EDIREMARK.Replace("\r\n", " ").Replace("\n", " ").Replace("\r", " ")) + "'"); + } + else if (bill.CARRIEREDICODE == "COSU") + { + r.WriteLine("FTX+AAI+++" + bill.BLFRT + " Payable at " + str_pay + " " + formatEdiStr("txt", bill.EDIREMARK.Replace("\r\n", " ").Replace("\n", " ").Replace("\r", " ")) + "'"); + } + else + { + + r.WriteLine("FTX+AAI+++" + bill.BLFRT + " Payable at " + str_pay + " " + bill.SERVICE + " " + + bill.PKGS.ToString() + bill.KINDPKGS + " " + formatEdiStr("txt", bill.EDIREMARK.Replace("\r\n", " ").Replace("\n", " ").Replace("\r", " ")) + "'"); + } + icount = icount + 2; + */ + + icount = icount + 1; + + var Shipping = ""; + Shipping = formatEdiStr("txt", bill.EDIREMARK); + Shipping = Shipping.Replace("\n", "\\"); + Shipping = Shipping.Replace("\r", " "); + string[] EdiRemarkList = Shipping.Split('\\'); + if (EdiRemarkList.Length != 0) + { + for (var i = 0; i < EdiRemarkList.Length; i++) + { + r.WriteLine("FTX+AAI+++" + EdiRemarkList[i] + "'"); + icount = icount + 1; + } + } + + /*件重尺*/ + r.WriteLine("CNT+7:" + Math.Round(bill.KGS, 3) + ":KGM'");//按照四舍五入的国际标准 + r.WriteLine("CNT+11:" + bill.PKGS.ToString() + "'"); + r.WriteLine("CNT+15:" + Math.Round(bill.CBM, 3) + ":MTQ'"); + + icount = icount + 3; + + //2024-04-08 这里看2.0文档显示不使用 CNT + if (bill.CARRIEREDICODE == "UASC") + { + if (bill.CTNLIST.Count > 0) + { + var ctnnum = 0; + foreach (var ctn in bill.CTNLIST) + { + ctnnum = ctnnum + ctn.CTNNUM; + } + r.WriteLine("CNT+16:" + ctnnum.ToString() + "'"); + icount = icount + 1; + } + + } + + if (bill.BLFRT == "FREIGHT COLLECT") + { + if (!string.IsNullOrWhiteSpace(bill.PAYABLEAT)) + { + r.WriteLine("LOC+57+" + bill.PREPARDATID + "::6:" + bill.PAYABLEAT + "'"); + icount = icount + 1; + } + } + else + { + r.WriteLine("LOC+57+" + bill.PREPARDATID + "::6:" + bill.PREPARDAT + "'"); + icount = icount + 1; + + } + + if (InttrEdi.UseForWarderCode) + { + r.WriteLine("RFF+FF:" + bill.ORDERNO.Trim() + "'"); + r.WriteLine("RFF+ON:" + bill.ORDERNO.Trim() + "'"); + icount = icount + 2; + } + else + { + if (bill.ORDERNO.Trim() != "") + { + r.WriteLine("RFF+FF:" + bill.ORDERNO.Trim() + "'"); + r.WriteLine("RFF+ON:" + bill.ORDERNO.Trim() + "'"); + icount = icount + 2; + } + } + + if (bill.CARRIEREDICODE != "COSU") + { + if (bill.CARRIEREDICODE == "HLCU") + { + //r.WriteLine("RFF+ON:" + bill.CUSTNO + "'"); + r.WriteLine("RFF+BM:" + bill.MBLNO + "'"); + } + else + { + r.WriteLine("RFF+BN:" + bill.MBLNO + "'"); + r.WriteLine("RFF+BM:" + bill.MBLNO + "'"); + } + icount = icount + 2; + } + r.WriteLine("RFF+CT:" + bill.CONTRACTNO + "'"); + + if (bill.BLFRT.IndexOf("PREPAID") >= 0) + r.WriteLine("CPI+4++P'"); + else if (bill.BLFRT.IndexOf("COLLECT") >= 0) + r.WriteLine("CPI+4++C'"); + else + r.WriteLine("CPI+4++B'"); + icount = icount + 2; + + var voyno = ""; + if (!string.IsNullOrEmpty(bill.NVOYNO)) voyno = bill.NVOYNO; else voyno = bill.VOYNO; + + if (voyno.IndexOf(".") >= 0) + voyno = voyno.Substring(voyno.IndexOf(".") + 1, voyno.Length - voyno.IndexOf(".") - 1); + + + r.WriteLine("TDT+20+" + voyno + "+1++" + bill.CARRIEREDICODE + "+++:::" + bill.VESSEL + "'"); + r.WriteLine("LOC+9+" + bill.PORTLOADID + ":139:6:" + bill.PORTLOAD + "'"); + r.WriteLine("DTM+133:" + Convert.ToDateTime(bill.ETD).ToString("yyyyMMdd") + ":102'");//yyyyMMddHHmm + + if (!string.IsNullOrEmpty(bill.PLACERECEIPTID)) + r.WriteLine("LOC+88+" + bill.PLACERECEIPTID + ":139:6:" + bill.PLACERECEIPT + "'"); + else + r.WriteLine("LOC+88+" + bill.PORTLOADID + ":139:6:" + bill.PORTLOAD + "'"); + + r.WriteLine("LOC+11+" + bill.PORTDISCHARGEID + ":139:6:" + bill.PORTDISCHARGE + "'"); + icount = icount + 5; + + if (!string.IsNullOrWhiteSpace(bill.DESTINATIONID)) + { + r.WriteLine("LOC+7+" + bill.DESTINATIONID + ":139:6:" + bill.DESTINATION + "'"); + icount = icount + 1; + } + + //处理发货人 + Shipping = string.Empty; + var DescriptionShipper = string.Empty; + + Shipping = formatEdiStr("txt", bill.SHIPPER); + + List ShippingList = formatlengthStr(Shipping, 35); + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + for (var i = 0; i < ShippingList.Count; i++) + { + if (i == 0) Shipping = "NAD+CZ+++" + ShippingList[0] + "+"; + if (i == 1) Shipping = Shipping + ShippingList[i]; + if (i == 2 || i == 3) Shipping = Shipping + ":" + ShippingList[i]; + if (i >= 4 && ShippingList.Count > 5) + { + if (i == 4) + { + if (ShippingList[i].Length > 34) + { + Shipping = Shipping + ":" + ShippingList[i].Substring(0, 34); + DescriptionShipper = ShippingList[i].Substring(34); + } + else + Shipping = Shipping + ":" + ShippingList[i]; + + if (bill.CARRIEREDICODE == "HLCU") + { + Shipping = Shipping + "-"; + DescriptionShipper = "-" + DescriptionShipper; + } + else + { + Shipping = Shipping + "*"; + DescriptionShipper = "*" + DescriptionShipper; + } + + } + else if (i > 4) + { + + DescriptionShipper = DescriptionShipper + " " + ShippingList[i]; + } + + } + else + if (i == 4) Shipping = Shipping + ":" + ShippingList[i]; + } + } + + r.WriteLine(Shipping + "'"); + icount = icount + 1; + + Shipping = formatEdiStr("txt", bill.CONSIGNEE); + ShippingList = formatlengthStr(Shipping, 35); + + var DescriptionConsignee = ""; + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + + for (var i = 0; i < ShippingList.Count; i++) + { + if (i == 0) Shipping = "NAD+CN+++" + ShippingList[0] + "+"; + if (i == 1) Shipping = Shipping + ShippingList[i]; + if (i == 2 || i == 3) Shipping = Shipping + ":" + ShippingList[i]; + if (i >= 4 && ShippingList.Count > 5) + { + if (i == 4) + { + if (ShippingList[i].Length > 33) + { + Shipping = Shipping + ":" + ShippingList[i].Substring(0, 33); + DescriptionConsignee = ShippingList[i].Substring(33); + } + else + Shipping = Shipping + ":" + ShippingList[i]; + + if (bill.CARRIEREDICODE == "HLCU") + { + Shipping = Shipping + "--"; + DescriptionConsignee = "--" + DescriptionConsignee; + } + else + { + Shipping = Shipping + "**"; + DescriptionConsignee = "**" + DescriptionConsignee; + } + + } + else if (i > 4) + { + + DescriptionConsignee = DescriptionConsignee + " " + ShippingList[i]; + } + + } + else + if (i == 4) Shipping = Shipping + ":" + ShippingList[i]; + } + } + + if (bill.BYCOUNTRY == "USA") + { + Shipping = Shipping + "+++" + bill.CONSIGNEEPOSTCODE; + r.WriteLine(Shipping + "'"); + } + else if (bill.BYCOUNTRY == "CANADA") + { + Shipping = Shipping + "+++" + bill.CONSIGNEEPOSTCODE + "+CA"; + r.WriteLine(Shipping + "'"); + } + else if (bill.BYCOUNTRY == "BRAZIL") + { + Shipping = Shipping + "++++" + bill.CONSIGNEECOUNTRY; + r.WriteLine(Shipping + "'"); + r.WriteLine("RFF+GN:" + bill.CONSIGNEETAXNO + "'"); + icount = icount + 1; + + } + else r.WriteLine(Shipping + "'"); + + icount = icount + 1; + + Shipping = formatEdiStr("txt", bill.NOTIFYPARTY); + ShippingList = formatlengthStr(Shipping, 35); + + var DescriptionNotifyparty = ""; + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + for (var i = 0; i < ShippingList.Count; i++) + { + if (i == 0) Shipping = "NAD+NI+++" + ShippingList[0] + "+"; + if (i == 1) Shipping = Shipping + ShippingList[i]; + if (i == 2 || i == 3) Shipping = Shipping + ":" + ShippingList[i]; + if (i >= 4 && ShippingList.Count > 5) + { + if (i == 4) + { + if (ShippingList[i].Length > 32) + { + Shipping = Shipping + ":" + ShippingList[i].Substring(0, 32); + DescriptionNotifyparty = ShippingList[i].Substring(32); + } + else + Shipping = Shipping + ":" + ShippingList[i]; + if (bill.CARRIEREDICODE == "HLCU") + { + Shipping = Shipping + "---"; + DescriptionNotifyparty = "---" + DescriptionNotifyparty; + } + else + { + Shipping = Shipping + "***"; + DescriptionNotifyparty = "***" + DescriptionNotifyparty; + } + + } + else if (i > 4) + { + + DescriptionNotifyparty = DescriptionNotifyparty + " " + ShippingList[i]; + } + + } + else + if (i == 4) Shipping = Shipping + ":" + ShippingList[i]; + } + } + + if (bill.BYCOUNTRY == "USA") + { + Shipping = Shipping + "+++" + bill.NOTIFYPARTYPOSTCODE; + r.WriteLine(Shipping + "'"); + } + else if (bill.BYCOUNTRY == "BRAZIL") + { + if (!string.IsNullOrWhiteSpace(bill.NOTIFYPARTYCOUNTRY)) + Shipping = Shipping + "++++" + bill.NOTIFYPARTYCOUNTRY; + r.WriteLine(Shipping + "'"); + if (!string.IsNullOrWhiteSpace(bill.NOTIFYPARTYTAXNO)) + { + r.WriteLine("RFF+GN:" + bill.NOTIFYPARTYTAXNO + "'"); + icount = icount + 1; + + } + } + else r.WriteLine(Shipping + "'"); + icount = icount + 1; + + r.WriteLine("NAD+CA+" + bill.CARRIEREDICODE + ":160:86++" + GetCarrierName(bill.CARRIEREDICODE) + "'"); + icount = icount + 1; + + if (bill.SERVICEEDICODE == "DOOR-DOOR") + { + Shipping = formatEdiStr("txt", bill.SHIPPER); + ShippingList = formatlengthStr(Shipping, 35); + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + for (var i = 0; i < ShippingList.Count; i++) + { + if (i == 0) Shipping = "NAD+SF+++" + ShippingList[0] + "+"; + if (i == 1) Shipping = Shipping + ShippingList[i]; + if (i >= 2) Shipping = Shipping + ":" + ShippingList[i]; + } + } + r.WriteLine(Shipping + "'"); + + r.WriteLine("CTA+IC+:" + bill.EDIATTN + "'"); + r.WriteLine("COM+" + bill.EDIATTNTEL + ":TE'"); + r.WriteLine("COM+" + bill.EDIATTNEMAIL + ":EM'"); + icount = icount + 4; + Shipping = formatEdiStr("txt", bill.CONSIGNEE); + if (Shipping.ToUpper().IndexOf("TO ORDER") >= 0 || Shipping.ToUpper().IndexOf("SAME AS") >= 0) + Shipping = formatEdiStr("txt", bill.NOTIFYPARTY); + + ShippingList = formatlengthStr(Shipping, 35); + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + for (var i = 0; i < ShippingList.Count; i++) + { + if (i == 0) Shipping = "NAD+ST+++" + ShippingList[0] + "+"; + if (i == 1) Shipping = Shipping + ShippingList[i]; + if (i >= 2) Shipping = Shipping + ":" + ShippingList[i]; + } + } + r.WriteLine(Shipping + "'"); + + r.WriteLine("CTA+IC+:" + bill.EDIATTN + "'"); + r.WriteLine("COM+" + bill.EDIATTNTEL + ":TE'"); + r.WriteLine("COM+" + bill.EDIATTNEMAIL + ":EM'"); + icount = icount + 4; + } + if (bill.SERVICE == "DOOR-CY") + { + Shipping = formatEdiStr("txt", bill.SHIPPERDOORADDR); + ShippingList = formatlengthStr(Shipping, 35); + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + for (var i = 0; i < ShippingList.Count; i++) + { + if (i == 0) Shipping = "NAD+SF+++" + ShippingList[0] + "+"; + if (i == 1) Shipping = Shipping + ShippingList[i]; + if (i >= 2) Shipping = Shipping + ":" + ShippingList[i]; + } + } + r.WriteLine(Shipping + "'"); + + r.WriteLine("CTA+IC+:" + bill.EDIATTN + "'"); + r.WriteLine("COM+" + bill.EDIATTNTEL + ":TE'"); + r.WriteLine("COM+" + bill.EDIATTNEMAIL + ":EM'"); + icount = icount + 4; + } + + if (bill.SERVICE == "CY-DOOR") + { + Shipping = formatEdiStr("txt", bill.CONSIGNEEDOORADDR); + ShippingList = formatlengthStr(Shipping, 35); + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + for (var i = 0; i < ShippingList.Count; i++) + { + if (i == 0) Shipping = "NAD+ST+++" + ShippingList[0] + "+"; + if (i == 1) Shipping = Shipping + ShippingList[i]; + if (i >= 2) Shipping = Shipping + ":" + ShippingList[i]; + } + } + r.WriteLine(Shipping + "'"); + + r.WriteLine("CTA+IC+:" + bill.EDIATTN + "'"); + r.WriteLine("COM+" + bill.EDIATTNTEL + ":TE'"); + r.WriteLine("COM+" + bill.EDIATTNEMAIL + ":EM'"); + icount = icount + 4; + } + + + if (!string.IsNullOrWhiteSpace(bill.WEITUO)) + { + if (bill.WEITUO.Length > 35) + r.WriteLine("NAD+FW+++" + formatEdiStr("txt", bill.WEITUO.Substring(0, 35)) + "+" + formatEdiStr("txt", bill.WEITUO.Substring(35)) + "'"); + else + r.WriteLine("NAD+FW+++" + formatEdiStr("txt", bill.WEITUO) + "'"); + + } + else + { + + if (InttrEdi.UseForWarderCode) + { + r.WriteLine("NAD+FW+" + InttrEdi.ForWarderCode + ":160:86++" + InttrEdi.ForWarderName + "'"); + icount++; + } + else + { + if (InttrEdi.SENDNAME.Length > 35) + r.WriteLine("NAD+FW+" + InttrEdi.SENDCODE + ":160:86++" + InttrEdi.SENDNAME.Substring(0, 35) + "+" + InttrEdi.SENDNAME.Substring(35) + "'"); + else + r.WriteLine("NAD+FW+" + InttrEdi.SENDCODE + ":160:86++" + InttrEdi.SENDNAME + "'"); + } + } + + + if (InttrEdi.SENDNAME.Length > 35) + r.WriteLine("NAD+HI+" + InttrEdi.SENDCODE + ":160:86++" + InttrEdi.SENDNAME.Substring(0, 35) + "+" + InttrEdi.SENDNAME.Substring(35) + "'"); + else + r.WriteLine("NAD+HI+" + InttrEdi.SENDCODE + ":160:86++" + InttrEdi.SENDNAME + "'"); + + //r.WriteLine("CTA+IC+:" +billams.ATTN+ "'"); + //r.WriteLine("COM+" +billams.ATTNTEL+ ":TE'"); + //r.WriteLine("COM+" + billams.ATTNEMAIL + ":EM'"); + + + r.WriteLine("CTA+IC+:" + bill.OpEName + "'"); + r.WriteLine("COM+" + bill.OpTel + ":TE'"); + r.WriteLine("COM+" + bill.OpEmail + ":EM'"); + + r.WriteLine("NAD+MR+++" + InttrEdi.SENDNAME + "'"); + //r.WriteLine("CTA+NT+:" +billams.ATTN+ "'"); + //r.WriteLine("COM+" + billams.ATTNEMAIL + ":EM'"); + r.WriteLine("CTA+NT+:" + bill.OpEName + "'"); + r.WriteLine("COM+" + bill.OpEmail + ":EM'"); + + r.WriteLine("GID+1+" + bill.PKGS.ToString() + ":" + bill.KINDPKGS_EDI_CODE + "::6:" + bill.KINDPKGS + "'"); + + icount = icount + 8; + + if (!string.IsNullOrWhiteSpace(bill.HSCODE)) + { + r.WriteLine("PIA+5+" + bill.HSCODE + ":HS'"); + icount = icount + 1; + + } + Shipping = formatEdiStr("txt", bill.DESCRIPTION); + Shipping = Shipping.Replace("\n", "\\"); + Shipping = Shipping.Replace("\r", " "); + string[] DescriptionList = Shipping.Split('\\'); + if (DescriptionList.Length != 0) + { + + for (var i = 0; i < DescriptionList.Length; i++) + { + r.WriteLine("FTX+AAA+++" + DescriptionList[i] + "'"); + icount = icount + 1; + + } + } + if (!string.IsNullOrWhiteSpace(DescriptionShipper)) + { + r.WriteLine("FTX+AAA+++" + DescriptionShipper + "'"); + icount = icount + 1; + + } + if (!string.IsNullOrWhiteSpace(DescriptionConsignee)) + { + r.WriteLine("FTX+AAA+++" + DescriptionConsignee + "'"); + icount = icount + 1; + + } + if (!string.IsNullOrWhiteSpace(DescriptionNotifyparty)) + { + r.WriteLine("FTX+AAA+++" + DescriptionNotifyparty + "'"); + icount = icount + 1; + + } + + r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(bill.KGS, 3) + "'"); + r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(bill.CBM, 3) + "'"); + icount = icount + 2; + + Shipping = formatEdiStr("txt", bill.MARKS); + + Shipping = Shipping.Replace("\n", "\\"); + Shipping = Shipping.Replace("\r", " "); + string[] MarksList = Shipping.Split('\\'); + if (MarksList.Length != 0) + { + + for (var i = 0; i < MarksList.Length; i++) + { + r.WriteLine("PCI++" + MarksList[i] + "'"); + icount = icount + 1; + + } + } + //危险品 + if (bill.CARGOID == "D") + { + r.WriteLine("DGS+IMD+" + bill.DCLASS + "+" + bill.DUNNO + "'"); + r.WriteLine("CTA+HG+:" + bill.EDIATTN + "'"); + r.WriteLine("COM+" + bill.EDIATTNTEL + ":TE'"); + icount = icount + 3; + } + + var ctnsumlist = new List(); + foreach (var ctn in bill.CTNLIST) + { + var isfind = false; + ctnsumlist.ForEach(i => + { + if (i.CTNALLCODE == ctn.CTNALLCODE) + { + i.CTNNUM = i.CTNNUM + ctn.CTNNUM; + isfind = true; + } + }); + + if (!isfind) + { + var ctnnum = new SeaExportCtnEDIBaseModel(); + ctnnum.CTNALLCODE = ctn.CTNALLCODE; + ctnnum.CTNNUM = ctn.CTNNUM; + ctnsumlist.Add(ctnnum); + } + } + foreach (var ctn in ctnsumlist) + { + if (bill.ISCONTAINERSOC) + r.WriteLine("EQD+CN++" + ctn.CTNALLCODE + "+1'"); + else + r.WriteLine("EQD+CN++" + ctn.CTNALLCODE + "+2'"); + + r.WriteLine("EQN+" + ctn.CTNNUM.ToString() + "'"); + icount = icount + 2; + + if (bill.CARGOID == "R") + { + if (!string.IsNullOrWhiteSpace(bill.REEFERF)) + r.WriteLine("MEA+AAE+AAS+CBM:" + bill.REEFERF + "'"); + if (!string.IsNullOrWhiteSpace(bill.HUMIDITY)) + r.WriteLine("MEA+AAE+AAO+HMD:" + bill.HUMIDITY + "'"); + + //温度这里如果是带小数点的值,会导致错误,这里需要慎重 + var tempset = bill.TEMPSET; + if (!string.IsNullOrWhiteSpace(tempset)) + { + var fuhao = ""; + if (tempset.IndexOf("-") == 0) + { + fuhao = "-"; + tempset = tempset.Replace("-", ""); + } + if (tempset.Length < 3) + { + for (int i = 0; i < 3 - tempset.Length + 1; i++) + { + tempset = "0" + tempset; + } + } + tempset = fuhao + tempset; + } + else + { + tempset = "000"; + } + r.WriteLine("TMP+2+" + tempset + ":CEL'"); + icount = icount + 2; + + + } + + } + + } + r.WriteLine("UNT+" + icount.ToString() + "+" + bsno + "'"); + r.WriteLine("UNZ+" + InttrEdi.BSLIST.Count.ToString() + "+" + bsno + "'"); + r.Close(); + f.Close(); + + //result.succ = true; + //result.extra = filename; + //return result; + result.Succeeded = true; + result.ExtraData1 = filename; + return result; + } + #endregion + + #region 确认 + public static EdiDataResult CreateEdiINTTRSI(EDIBaseModel InttrEdi) + { + var result = new EdiDataResult { Succeeded = false }; + + string filename = InttrEdi.filerpath + "\\" + InttrEdi.BSLIST[0].MBLNO + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt"; + + //如果是部署linux需要修改路径 + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + filename = filename.Replace("\\", "/"); + + //if (System.IO.File.Exists(filename)) + //{ + // System.IO.File.Delete(filename); + //} + FileStream f = new FileStream(filename, FileMode.Create); + StreamWriter r = new StreamWriter(f, Encoding.Default); + + var icount = 0; + var bsno = ""; + foreach (var bill in InttrEdi.BSLIST) + { + bsno = bill.ORDERNO; + r.WriteLine("UNB+UNOC:2+" + InttrEdi.SENDCODE + ":ZZZ+" + InttrEdi.RECEIVECODE + ":ZZZ+" + DateTime.Now.ToString("yyMMdd:HHmm") + "+" + bill.ORDERNO + "'"); + r.WriteLine("UNH+" + bill.ORDERNO + "+IFTMIN:D:99B:UN'"); + if (InttrEdi.filerole == "9") + r.WriteLine("BGM+340+" + bill.MBLNO + "+9'"); + else + r.WriteLine("BGM+340+" + bill.MBLNO + "+5'"); + + + + if (bill.SERVICEEDICODE.ToUpper() == "DOOR-DOOR") + { + r.WriteLine("TSR+27+2'"); + } + else if (bill.SERVICEEDICODE.ToUpper() == "DOOR-CY") + { + r.WriteLine("TSR+28+2'"); + } + else if (bill.SERVICEEDICODE.ToUpper() == "CY-DOOR") + { + r.WriteLine("TSR+29+2'"); + } + else + { + r.WriteLine("TSR+30+2'"); + } + + var str_pay = ""; + if (bill.BLFRTEDICODE.IndexOf("PREPAID") >= 0) + str_pay = bill.PREPARDAT; + if (bill.BLFRTEDICODE.IndexOf("COLLECT") >= 0) + str_pay = bill.PAYABLEAT; + + /* + r.WriteLine("FTX+AAI+++" + bill.BLFRTEDICODE + " Payable at " + str_pay + " " + bill.SERVICEEDICODE + " " + + bill.PKGS.ToString() + bill.KINDPKGS + "'"); + icount = icount + 5; + */ + icount = icount + 3; + + var Shipping = ""; + Shipping = formatEdiStr("txt", bill.SIREMARK); + Shipping = Shipping.Replace("\n", "\\"); + Shipping = Shipping.Replace("\r", " "); + string[] EdiRemarkList = Shipping.Split('\\'); + if (EdiRemarkList.Length != 0) + { + + for (var i = 0; i < EdiRemarkList.Length; i++) + { + r.WriteLine("FTX+AAI+++" + EdiRemarkList[i] + "'"); + icount = icount + 1; + + } + } + + if (bill.BYCOUNTRY == "USA") + { + if (bill.SCACCODE != "") + r.WriteLine("FTX+CCI++MFS+1:US:" + bill.SCACCODE + "'"); + else + r.WriteLine("FTX+CCI++MFS+5:US'"); + icount = icount + 1; + + } + else if (bill.BYCOUNTRY == "CANADA") + { + if (bill.SCACCODE != "") + r.WriteLine("FTX+CCI++MFS+1:CA:" + bill.SCACCODE + "'"); + else + r.WriteLine("FTX+CCI++MFS+5:CA'"); + icount = icount + 1; + + } + r.WriteLine("CNT+7:" + Math.Round(bill.KGS, 3) + ":KGM'"); + r.WriteLine("CNT+11:" + bill.PKGS.ToString() + "'"); + r.WriteLine("CNT+15:" + Math.Round(bill.CBM, 3) + ":MTQ'"); + + icount = icount + 3; + + if (bill.CARRIEREDICODE == "UASC") + { + if (bill.CTNLIST.Count > 0) + { + var ctnnum = 0; + foreach (var ctn in bill.CTNLIST) + { + ctnnum = ctnnum + ctn.CTNNUM; + } + r.WriteLine("CNT+16:" + ctnnum.ToString() + "'"); + icount = icount + 1; + } + + } + + if (bill.BLFRT == "FREIGHT COLLECT") + { + if (bill.PAYABLEAT != "") + { + r.WriteLine("LOC+57+" + bill.PREPARDATID + "::6:" + bill.PAYABLEAT + "'"); + icount = icount + 1; + } + } + else + { + r.WriteLine("LOC+57+" + bill.PREPARDATID + "::6:" + bill.PREPARDAT + "'"); + icount = icount + 1; + } + + r.WriteLine("LOC+73+" + bill.ISSUEPLACEID + "::6:" + bill.ISSUEPLACE + "'"); + icount = icount + 1; + + + + if (bill.CARRIEREDICODE == "MASK") + { + Shipping = formatEdiStr("txt", bill.BSNOLIST); + Shipping = Shipping.Replace("\n", "\\"); + Shipping = Shipping.Replace("\r", " "); + EdiRemarkList = Shipping.Split('\\'); + if (EdiRemarkList.Length != 0) + { + + for (var i = 0; i < EdiRemarkList.Length; i++) + { + r.WriteLine("RFF+BN:" + EdiRemarkList[i] + "'"); + icount = icount + 1; + + } + } + else + { + //if (billams.ORDERNO != "") + // r.WriteLine("RFF+BN:" + billams.ORDERNO + "'"); + //else + r.WriteLine("RFF+BN:" + bill.MBLNO + "'"); + icount = icount + 1; + + } + } + else + { + //if (billams.ORDERNO != "") + // r.WriteLine("RFF+BN:" + billams.ORDERNO + "'"); + //else + r.WriteLine("RFF+BN:" + bill.MBLNO + "'"); + icount = icount + 1; + + } + r.WriteLine("RFF+BM:" + bill.MBLNO + "'"); + + + + + r.WriteLine("RFF+CT:" + bill.CONTRACTNO + "'"); + icount = icount + 2; + + + if (bill.CARRIEREDICODE == "UASC") + { + r.WriteLine("RFF+SI:" + bill.ORDERNO + "'"); + icount = icount + 1; + + } + if (bill.BYCOUNTRY == "USA") + { + r.WriteLine("REF+TN:" + bill.ITNCODE + "'"); + icount = icount + 1; + + } + + if (bill.BLFRT.IndexOf("PREPAID") >= 0) + r.WriteLine("CPI+4++P'"); + else if (bill.BLFRT.IndexOf("COLLECT") >= 0) + r.WriteLine("CPI+4++C'"); + else + r.WriteLine("CPI+4++B'"); + icount = icount + 1; + + var voyno = ""; + if (bill.VOYNO.IndexOf(".") >= 0) + { + voyno = bill.VOYNO.Substring(bill.VOYNO.IndexOf(".") + 1, bill.VOYNO.Length - bill.VOYNO.IndexOf(".") - 1); + } + else + { + voyno = bill.VOYNO; + } + r.WriteLine("TDT+20+" + voyno + "+1++" + bill.CARRIEREDICODE + "+++:::" + bill.VESSEL + "'"); + r.WriteLine("LOC+9+" + bill.PORTLOADID + ":139:6:" + bill.PORTLOAD + "'"); + + r.WriteLine("LOC+88+" + bill.PORTLOADID + ":139:6:" + bill.PORTLOAD + "'"); + r.WriteLine("LOC+11+" + bill.PORTDISCHARGEID + ":139:6:" + bill.PORTDISCHARGE + "'"); + icount = icount + 4; + + if (!string.IsNullOrWhiteSpace(bill.DESTINATION)) + { + r.WriteLine("LOC+7+" + bill.DESTINATIONID + ":139:6:" + bill.DESTINATION + "'"); + icount = icount + 1; + + } + + var DescriptionShipper = ""; + Shipping = formatEdiStr("txt", bill.SHIPPER); + + List ShippingList = formatlengthStr(Shipping, 35); + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + + for (var i = 0; i < ShippingList.Count; i++) + { + if (i == 0) Shipping = "NAD+CZ+++" + ShippingList[0] + "+"; + if (i == 1) Shipping = Shipping + ShippingList[i]; + if (i == 2 || i == 3) Shipping = Shipping + ":" + ShippingList[i]; + if (i >= 4 && ShippingList.Count > 5) + { + if (i == 4) + { + if (ShippingList[i].Length > 34) + { + Shipping = Shipping + ":" + ShippingList[i].Substring(0, 34); + DescriptionShipper = ShippingList[i].Substring(34); + } + else + Shipping = Shipping + ":" + ShippingList[i]; + if (bill.CARRIEREDICODE == "HLCU") + { + Shipping = Shipping + "-"; + DescriptionShipper = "-" + DescriptionShipper; + } + else + { + Shipping = Shipping + "*"; + DescriptionShipper = "*" + DescriptionShipper; + } + + } + else if (i > 4) + { + + DescriptionShipper = DescriptionShipper + " " + ShippingList[i]; + } + + } + else + if (i == 4) Shipping = Shipping + ":" + ShippingList[i]; + } + } + + r.WriteLine(Shipping + "'"); + icount = icount + 1; + Shipping = formatEdiStr("txt", bill.CONSIGNEE); + + ShippingList = formatlengthStr(Shipping, 35); + + var DescriptionConsignee = ""; + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + + for (var i = 0; i < ShippingList.Count; i++) + { + if (i == 0) Shipping = "NAD+CN+++" + ShippingList[0] + "+"; + if (i == 1) Shipping = Shipping + ShippingList[i]; + if (i == 2 || i == 3) Shipping = Shipping + ":" + ShippingList[i]; + if (i >= 4 && ShippingList.Count > 5) + { + if (i == 4) + { + if (ShippingList[i].Length > 33) + { + Shipping = Shipping + ":" + ShippingList[i].Substring(0, 33); + DescriptionConsignee = ShippingList[i].Substring(33); + } + else + Shipping = Shipping + ":" + ShippingList[i]; + if (bill.CARRIEREDICODE == "HLCU") + { + Shipping = Shipping + "--"; + DescriptionConsignee = "--" + DescriptionConsignee; + } + else + { + Shipping = Shipping + "**"; + DescriptionConsignee = "**" + DescriptionConsignee; + } + + } + else if (i > 4) + { + + DescriptionConsignee = DescriptionConsignee + " " + ShippingList[i]; + } + + } + else + if (i == 4) Shipping = Shipping + ":" + ShippingList[i]; + } + } + + if (bill.BYCOUNTRY == "USA") + { + Shipping = Shipping + "+++" + bill.CONSIGNEEPOSTCODE; + r.WriteLine(Shipping + "'"); + } + else if (bill.BYCOUNTRY == "CANADA") + { + Shipping = Shipping + "+++" + bill.CONSIGNEEPOSTCODE + "+CA"; + r.WriteLine(Shipping + "'"); + } + else if (bill.BYCOUNTRY == "BRAZIL") + { + Shipping = Shipping + "++++" + bill.CONSIGNEECOUNTRY; + r.WriteLine(Shipping + "'"); + r.WriteLine("RFF+GN:" + bill.CONSIGNEETAXNO + "'"); + icount = icount + 1; + + } + else r.WriteLine(Shipping + "'"); + icount = icount + 1; + + /*2024-04-08 JHQ 看文档2.0应该没有这段代码了 + if (!string.IsNullOrEmpty(bill.WEITUO)) + { + if (bill.WEITUO.Length > 35) + r.WriteLine("NAD+FW+++" + formatEdiStr("txt", bill.WEITUO.Substring(0, 35)) + "+" + formatEdiStr("txt", bill.WEITUO.Substring(35)) + "'"); + else + r.WriteLine("NAD+FW+++" + formatEdiStr("txt", bill.WEITUO) + "'"); + + } + else + { + + if (InttrEdi.UseForWarderCode) + { + r.WriteLine("NAD+FW+" + InttrEdi.ForWarderCode + ":160:86++" + InttrEdi.ForWarderName + "'"); + icount++; + } + else + { + if (InttrEdi.SENDNAME.Length > 35) + r.WriteLine("NAD+FW+" + InttrEdi.SENDCODE + ":160:86++" + InttrEdi.SENDNAME.Substring(0, 35) + "+" + InttrEdi.SENDNAME.Substring(35) + "'"); + else + r.WriteLine("NAD+FW+" + InttrEdi.SENDCODE + ":160:86++" + InttrEdi.SENDNAME + "'"); + } + } + icount++; + */ + + + + + Shipping = formatEdiStr("txt", bill.NOTIFYPARTY); + + ShippingList = formatlengthStr(Shipping, 35); + + var DescriptionNotifyparty = ""; + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + + for (var i = 0; i < ShippingList.Count; i++) + { + if (i == 0) Shipping = "NAD+NI+++" + ShippingList[0] + "+"; + if (i == 1) Shipping = Shipping + ShippingList[i]; + if (i == 2 || i == 3) Shipping = Shipping + ":" + ShippingList[i]; + if (i >= 4 && ShippingList.Count > 5) + { + if (i == 4) + { + if (ShippingList[i].Length > 32) + { + Shipping = Shipping + ":" + ShippingList[i].Substring(0, 32); + DescriptionNotifyparty = ShippingList[i].Substring(32); + } + else + Shipping = Shipping + ":" + ShippingList[i]; + if (bill.CARRIEREDICODE == "HLCU") + { + Shipping = Shipping + "---"; + DescriptionNotifyparty = "---" + DescriptionNotifyparty; + } + else + { + Shipping = Shipping + "***"; + DescriptionNotifyparty = "***" + DescriptionNotifyparty; + } + + } + else if (i > 4) + { + + DescriptionNotifyparty = DescriptionNotifyparty + " " + ShippingList[i]; + } + + } + else + if (i == 4) Shipping = Shipping + ":" + ShippingList[i]; + } + } + + if (bill.BYCOUNTRY == "USA") + { + Shipping = Shipping + "+++" + bill.NOTIFYPARTYPOSTCODE; + r.WriteLine(Shipping + "'"); + } + else if (bill.BYCOUNTRY == "BRAZIL") + { + if (bill.NOTIFYPARTYCOUNTRY != "") + Shipping = Shipping + "++++" + bill.NOTIFYPARTYCOUNTRY; + r.WriteLine(Shipping + "'"); + if (bill.NOTIFYPARTYTAXNO != "") + { + r.WriteLine("RFF+GN:" + bill.NOTIFYPARTYTAXNO + "'"); + icount = icount + 1; + + } + } + else r.WriteLine(Shipping + "'"); + icount = icount + 1; + + /* 2024-04-08 JHQ 参考文档2.0去掉了 + Shipping = formatEdiStr("txt", bill.NOTIFYPARTY2); + ShippingList = formatlengthStr(Shipping, 35); + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + for (var i = 0; i < ShippingList.Count; i++) + { + if (i == 0) Shipping = "NAD+N1+++" + ShippingList[0] + "+"; + if (i == 1) Shipping = Shipping + ShippingList[i]; + if (i == 2 || i == 3) Shipping = Shipping + ":" + ShippingList[i]; + if (i == 4) Shipping = Shipping + ":" + ShippingList[i]; + } + r.WriteLine(Shipping + "'"); + } + */ + + + r.WriteLine("NAD+CA+" + bill.CARRIEREDICODE + ":160:86++" + GetCarrierName(bill.CARRIEREDICODE) + "'"); + icount = icount + 1; + + if (InttrEdi.SENDNAME.Length > 35) + r.WriteLine("NAD+HI+" + InttrEdi.SENDCODE + ":160:86++" + InttrEdi.SENDNAME.Substring(0, 35) + "+" + InttrEdi.SENDNAME.Substring(35) + "'"); + else + r.WriteLine("NAD+HI+" + InttrEdi.SENDCODE + ":160:86++" + InttrEdi.SENDNAME + "'"); + + r.WriteLine("CTA+IC+:" + bill.EDIATTN + "'"); + r.WriteLine("COM+" + bill.EDIATTNTEL + ":TE'"); + r.WriteLine("COM+" + bill.EDIATTNEMAIL + ":EM'"); + icount = icount + 5; + var copynum = GetBillNum(bill.COPYNOBILL); + + //正本 + if (bill.ISSUETYPE.Equals("ORIGINAL", StringComparison.OrdinalIgnoreCase)) + { + r.WriteLine("DOC+706+++" + GetBillNum(bill.NOBILL) + "'"); + icount = icount + 1; + if (copynum != "") + { + r.WriteLine("DOC+707+++" + copynum + "'"); + icount = icount + 1; + } + + } + else if (bill.ISSUETYPE.Equals("SEAWAY BILL", StringComparison.OrdinalIgnoreCase) || bill.ISSUETYPE == "海运单" || bill.ISSUETYPE.ToUpper() == "SEAWAY" || bill.ISSUETYPE.ToUpper() == "SEAWAY BILL" || bill.ISSUETYPE.ToUpper() == "WAYBILL" || bill.ISSUETYPE.ToUpper() == "SWB正本" + || bill.ISSUETYPE.ToUpper() == "SWB无正本") + { + //海运单 + r.WriteLine("DOC+710+++" + GetBillNum(bill.NOBILL) + "'"); + icount = icount + 1; + + } + else if (bill.ISSUETYPE.Equals("TELEX", StringComparison.OrdinalIgnoreCase) || bill.ISSUETYPE.ToUpper() == "BILL COPY" || bill.ISSUETYPE == "电放") + { + //电放 + r.WriteLine("DOC+706+++" + GetBillNum(bill.NOBILL) + "'"); + icount = icount + 1; + if (copynum != "") + { + r.WriteLine("DOC+707+++" + copynum + "'"); + icount = icount + 1; + } + + } + else if (bill.ISSUETYPE == "正副本") + { + r.WriteLine("DOC+706+++" + GetBillNum(bill.NOBILL) + "'"); + icount = icount + 1; + if (copynum != "") + { + r.WriteLine("DOC+707+++" + copynum + "'"); + icount = icount + 1; + } + + } + else if (bill.ISSUETYPE.ToUpper() == "HOUSE BILL") + { + r.WriteLine("DOC+714+++" + GetBillNum(bill.NOBILL) + "'"); + icount = icount + 1; + + } + + //判断集装箱是否包含分箱明细 + + if (bill.CTNGOODSLIST == null || bill.CTNGOODSLIST.Count == 0) + { + #region 取委托单货描、唛头信息 + r.WriteLine("GID+1+" + bill.PKGS.ToString() + ":" + bill.KINDPKGS_EDI_CODE + "::6:" + bill.KINDPKGS + "'"); + + icount = icount + 1; + + if (bill.HSCODE != "") + { + r.WriteLine("PIA+5+" + bill.HSCODE + ":HS'"); + icount = icount + 1; + + } + + Shipping = formatEdiStr("txt", bill.DESCRIPTION); + + Shipping = Shipping.Replace("\n", "\\"); + Shipping = Shipping.Replace("\r", " "); + string[] DescriptionList = Shipping.Split('\\'); + if (DescriptionList.Length != 0) + { + + for (var i = 0; i < DescriptionList.Length; i++) + { + //if (DescriptionList[i] != "") + //{ + r.WriteLine("FTX+AAA+++" + DescriptionList[i] + "'"); + icount = icount + 1; + //} + + } + } + if (DescriptionShipper != "") + { + r.WriteLine("FTX+AAA+++" + DescriptionShipper + "'"); + icount = icount + 1; + + } + if (DescriptionConsignee != "") + { + r.WriteLine("FTX+AAA+++" + DescriptionConsignee + "'"); + icount = icount + 1; + + } + if (DescriptionNotifyparty != "") + { + r.WriteLine("FTX+AAA+++" + DescriptionNotifyparty + "'"); + icount = icount + 1; + + } + r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(bill.KGS, 3) + "'"); + r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(bill.CBM, 3) + "'"); + + icount = icount + 2; + + + if (!string.IsNullOrEmpty(bill.GOODSNCM)) + { + r.WriteLine("RFF+ABT:" + bill.GOODSNCM + "'"); + icount = icount + 1; + + } + Shipping = formatEdiStr("txt", bill.MARKS); + + Shipping = Shipping.Replace("\n", "\\"); + Shipping = Shipping.Replace("\r", " "); + string[] MarksList = Shipping.Split('\\'); + if (MarksList.Length != 0) + { + + for (var i = 0; i < MarksList.Length; i++) + { + + //if (MarksList[i] != "") + //{ + r.WriteLine("PCI++" + MarksList[i] + "'"); + icount = icount + 1; + //} + + } + } + + foreach (var ctn in bill.CTNLIST) + { + r.WriteLine("SGP+" + ctn.CNTRNO + "+" + ctn.PKGS.ToString() + "'"); + r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(ctn.KGS, 3) + "'"); + r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(ctn.CBM, 3) + "'"); + icount = icount + 3; + } + #endregion + } + else + { + + if (bill.CARRIEREDICODE == "UASC" || bill.CARRIEREDICODE == "HLCU" || bill.CARRIEREDICODE == "CMDU") + { + #region 取集装箱分箱_货描、唛头信息 + if (bill.CTNGOODSLIST != null) + { + if (bill.CTNGOODSLIST.Count > 0) + { + var i = 0; + foreach (var ctngood in bill.CTNGOODSLIST) + { + //GID+1+400:CT::6:CARTONS' + r.WriteLine("GID+" + (i + 1) + "+" + ctngood.PKGS.ToString() + ":" + ctngood.KINDPKGS_EDI_CODE + "::6:" + ctngood.KINDPKGS + "'"); + icount++; + //PIA+5+HS_CODE1:HS' + r.WriteLine("PIA+5+" + ctngood.HSCODE + ":HS'"); + icount++; + //FTX+AAA+++MATERIAL 1' + //FTX+AAA+++HS-NO 39023012' + Shipping = formatEdiStr("txt", ctngood.DESCRIPTION); + Shipping = Shipping.Replace("\n", "\\"); + Shipping = Shipping.Replace("\r", " "); + string[] DescriptionList = Shipping.Split('\\'); + if (DescriptionList.Length != 0) + { + for (var j = 0; j < DescriptionList.Length; j++) + { + r.WriteLine("FTX+AAA+++" + DescriptionList[j] + "'"); + icount++; + } + } + //MEA+AAE+WT+KGM:3000' + //MEA+AAE+AAW+MTQ:110.11' + r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(ctngood.KGS, 3) + "'"); + icount++; + r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(ctngood.CBM, 3) + "'"); + icount++; + //PCI++MARKS AND NUMBERS:FOR MATERIAL 1: OUR PONUMBER: PO_123456' + //if (isbill != 1) + //{ + // Shipping = formatEdiStr("txt", bill.MARKS); + //} + //else + //{ + Shipping = formatEdiStr("txt", ctngood.MARKS); + //} + if (string.IsNullOrEmpty(ctngood.MARKS)) Shipping = formatEdiStr("txt", bill.MARKS); + + Shipping = Shipping.Replace("\n", "\\"); + Shipping = Shipping.Replace("\r", " "); + string[] MarksList = Shipping.Split('\\'); + if (MarksList.Length != 0) + { + for (var j = 0; j < MarksList.Length; j++) + { + r.WriteLine("PCI++" + MarksList[j] + "'"); + icount++; + } + } + if (!string.IsNullOrEmpty(bill.GOODSNCM)) + { + r.WriteLine("RFF+ABT:" + bill.GOODSNCM + "'"); + icount++; + } + // + + //SGP+MSCU1234567+100' + r.WriteLine("SGP+" + ctngood.CNTRNO + "+" + ctngood.PKGS.ToString() + "'"); + //MEA+AAE+WT+KGM:1000' + r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(ctngood.KGS, 3) + "'"); + //MEA+AAE+AAW+MTQ:50.11' + r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(ctngood.CBM, 3) + "'"); + icount = icount + 3; + i = i + 1; + } + } + } + #endregion + + } + else + { + + #region 取集装箱分箱_货描、唛头信息 + + + var ctngoodssumlist = new List(); + foreach (var ctn in bill.CTNGOODSLIST) + { + var isfind = false; + ctngoodssumlist.ForEach(i => + { + if (i.HSCODE == ctn.HSCODE && i.KINDPKGS == ctn.KINDPKGS && i.DESCRIPTION == ctn.DESCRIPTION && i.MARKS == ctn.MARKS) + { + i.PKGS = i.PKGS + ctn.PKGS; + i.KGS = i.KGS + ctn.KGS; + i.CBM = i.CBM + ctn.CBM; + isfind = true; + } + }); + if (!isfind) + { + var ctnnum = new SeaExportCtnDetailEDIBaseModel(); + ctnnum.HSCODE = ctn.HSCODE; + ctnnum.KINDPKGS = ctn.KINDPKGS; + ctnnum.KINDPKGS_EDI_CODE = ctn.KINDPKGS_EDI_CODE; + ctnnum.DESCRIPTION = ctn.DESCRIPTION; + ctnnum.MARKS = ctn.MARKS; + ctnnum.PKGS = ctn.PKGS; + ctnnum.KGS = ctn.KGS; + ctnnum.CBM = ctn.CBM; + ctngoodssumlist.Add(ctnnum); + } + } + + if (ctngoodssumlist != null) + { + if (ctngoodssumlist.Count > 0) + { + var goodct = 0; + foreach (var ctngoodsum in ctngoodssumlist) + { + //GID+1+400:CT::6:CARTONS' + r.WriteLine("GID+" + (goodct + 1) + "+" + ctngoodsum.PKGS.ToString() + ":" + ctngoodsum.KINDPKGS_EDI_CODE + "::6:" + ctngoodsum.KINDPKGS + "'"); + icount++; + //PIA+5+HS_CODE1:HS' + r.WriteLine("PIA+5+" + ctngoodsum.HSCODE + ":HS'"); + icount++; + //FTX+AAA+++MATERIAL 1' + //FTX+AAA+++HS-NO 39023012' + Shipping = formatEdiStr("txt", ctngoodsum.DESCRIPTION); + Shipping = Shipping.Replace("\n", "\\"); + Shipping = Shipping.Replace("\r", " "); + string[] DescriptionList = Shipping.Split('\\'); + if (DescriptionList.Length != 0) + { + for (var j = 0; j < DescriptionList.Length; j++) + { + r.WriteLine("FTX+AAA+++" + DescriptionList[j] + "'"); + icount++; + } + } + //MEA+AAE+WT+KGM:3000' + //MEA+AAE+AAW+MTQ:110.11' + r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(Convert.ToDecimal(ctngoodsum.KGS), 3) + "'"); + icount++; + r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(Convert.ToDecimal(ctngoodsum.CBM), 3) + "'"); + icount++; + //PCI++MARKS AND NUMBERS:FOR MATERIAL 1: OUR PONUMBER: PO_123456' + //if (isbill != 1) + //{ + // Shipping = formatEdiStr("txt", bill.MARKS); + //} + //else + //{ + Shipping = formatEdiStr("txt", ctngoodsum.MARKS); + //} + + if (ctngoodsum.MARKS == "") Shipping = formatEdiStr("txt", bill.MARKS); + + + Shipping = Shipping.Replace("\n", "\\"); + Shipping = Shipping.Replace("\r", " "); + string[] MarksList = Shipping.Split('\\'); + if (MarksList.Length != 0) + { + for (var j = 0; j < MarksList.Length; j++) + { + r.WriteLine("PCI++" + MarksList[j] + "'"); + icount++; + } + } + if (!string.IsNullOrEmpty(bill.GOODSNCM)) + { + r.WriteLine("RFF+ABT:" + bill.GOODSNCM + "'"); + icount++; + } + goodct = goodct + 1; + bill.CTNGOODSLIST.ForEach(i => + { + if (i.HSCODE == ctngoodsum.HSCODE && i.KINDPKGS == ctngoodsum.KINDPKGS && i.DESCRIPTION == ctngoodsum.DESCRIPTION && i.MARKS == ctngoodsum.MARKS) + { + //SGP+MSCU1234567+100' + r.WriteLine("SGP+" + i.CNTRNO + "+" + i.PKGS.ToString() + "'"); + //MEA+AAE+WT+KGM:1000' + r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(Convert.ToDecimal(i.KGS), 3) + "'"); + //MEA+AAE+AAW+MTQ:50.11' + r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(Convert.ToDecimal(i.CBM), 3) + "'"); + icount = icount + 3; + } + }); + } + } + } + #endregion + } + + } + + if (bill.CARGOID == "D") + { + r.WriteLine("DGS+IMD+" + bill.DCLASS + "+" + bill.DUNNO + "'"); + r.WriteLine("CTA+HG+:" + bill.EDIATTN + "'"); + r.WriteLine("COM+" + bill.EDIATTNTEL + ":TE'"); + icount = icount + 3; + } + + #region 集装箱 主箱循环 + + foreach (var ctn in bill.CTNLIST) + { + if (bill.ISCONTAINERSOC) + r.WriteLine("EQD+CN+" + ctn.CNTRNO + "+" + ctn.CTNALLCODE + "+1'"); + else + r.WriteLine("EQD+CN+" + ctn.CNTRNO + "+" + ctn.CTNALLCODE + "+2'"); + + r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(ctn.KGS, 3) + "'"); + r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(ctn.CBM, 3) + "'"); + + icount = icount + 3; + + if (bill.CARGOID == "R") + { + if (bill.REEFERF != "") + { + r.WriteLine("MEA+AAE+AAS+CBM:" + bill.REEFERF + "'"); + icount = icount + 1; + } + } + r.WriteLine("SEL+" + ctn.SEALNO + "+CA'"); + icount = icount + 1; + + if (bill.CARGOID == "R") + { + r.WriteLine("TMP+2+" + bill.TEMPSET + ":CEL'"); + icount = icount + 1; + } + + } + #endregion + } + r.WriteLine("UNT+" + icount.ToString() + "+" + bsno + "'"); + r.WriteLine("UNZ+" + InttrEdi.BSLIST.Count.ToString() + "+" + bsno + "'"); + r.Close(); + f.Close(); + + result.Succeeded = true; + result.ExtraData1 = filename; + return result; + } + #endregion + } +} diff --git a/ds-wms-service/DS.WMS.Core/Op/EDI/MellEdiHelper.cs b/ds-wms-service/DS.WMS.Core/Op/EDI/MellEdiHelper.cs new file mode 100644 index 00000000..f458ec5a --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Op/EDI/MellEdiHelper.cs @@ -0,0 +1,1097 @@ +using DS.Module.Core; +using DS.WMS.Core.Op.Dtos; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace DS.WMS.Core.Op.EDI +{ + /// + /// 太平玛利亚 + /// + public class MellEdiHelper + { + public MellEdiHelper() + { + } + + #region 格式化每行 + public static List formatlengthStr(string str, int length, bool formatstr = false, bool nodelsp = false) + { + str = str.Replace("\r\n", "\\"); + str = str.Replace("\n", "\\"); + str = str.Replace("\r", " "); + string[] StrList = str.Split('\\'); + var strtemp = ""; + var strnewline = ""; + var strtempnewline = ""; + char[] spstring = { ' ', ';', ',', '.', ':', '/', '(', ')', '?', '+', '-' }; + List DestList = new List(); + for (var i = 0; i <= StrList.Length - 1; i++) + { + if (StrList[i].Length <= length) + { + if (formatstr) + DestList.Add(formatEdiStr("txt", StrList[i])); + else + DestList.Add(StrList[i]); + + } + else + { + strtemp = StrList[i] + " "; + strtempnewline = ""; + strnewline = ""; + for (var j = 0; j < strtemp.Length; j++) + { + strtempnewline = strtempnewline + strtemp[j]; + if (strtemp[j] == ' ' || strtemp[j] == ':' || strtemp[j] == ',' || strtemp[j] == '.' || strtemp[j] == ':' || strtemp[j] == '/' + || strtemp[j] == '?' || strtemp[j] == ')' || strtemp[j] == '}' || strtemp[j] == '+' || strtemp[j] == '-') + { + if ((strnewline.Length + strtempnewline.Length) <= length) + strnewline = strnewline + strtempnewline; + else + { + if (formatstr) + DestList.Add(formatEdiStr("txt", strnewline)); + else + DestList.Add(strnewline); + strnewline = strtempnewline; + + } + strtempnewline = ""; + } + } + if (nodelsp) + { + if (formatstr) + DestList.Add(formatEdiStr("txt", strnewline)); + else DestList.Add(strnewline); + } + else if (strnewline.Trim() != "") + { + if (formatstr) + DestList.Add(formatEdiStr("txt", strnewline)); + else DestList.Add(strnewline); + } + } + + } + + return DestList; + } + #endregion + + public static string GetDateStr(string datestr, string dateformat) + { + var result = ""; + + if (datestr == null || datestr == "") + { + result = ""; + } + else + { + result = Convert.ToDateTime(datestr).ToString(dateformat); + + } + + return result; + + } + + #region 字符转义 + /// + /// 各种文本转义字符 + /// + /// 文件类型(例如:txt、xml) + /// 文本字符串 + /// + public static string formatEdiStr(string fileType, string str) + { + if (str == null) + str = string.Empty; + + if (fileType == "txt") + { + return str.Replace("?", "??").Replace(":", "?:").Replace("+", "?+").Replace("'", "?'"); + } + else if (fileType == "xml") + { + return str.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace("\"", """).Replace("'", "'"); + } + else if (fileType == "sitc") + { + return str.Replace("?", "??").Replace(":", "?:").Replace("'", "?'"); + } + else + { + return str; + } + } + #endregion + + #region 文本字段判断每行是否符合 + /// + /// edi 文本格式处理判断(例如:1行35个字符不超过5行) + /// + /// 文件类型(例如:txt、xml) + /// 要处理的数据 + /// 每行长度 + /// 主提单号 + /// 数据类型(例如:发货人内容、货描等) + /// 限制录入的行数(“0”代表不限制) + /// 限录后多出的放到货描中的数据的连接符(例如:“*”发货人内容、“**”收件人等) + /// + public static System.String formatlengthError(string fileType, string str, int length, string sMBLNO, string sType, int rowNum, string sSymbol, bool isHuoMiao) + { + string error = ""; + string Shipping = str; + if (fileType == "txt") + { + //Shipping = formatEdiStr("txt", str); + } + else if (fileType == "xml") + { + Shipping = formatEdiStr("txt", str); + } + string[] argAGENT = Shipping.Split(new string[] { "\r\n" }, StringSplitOptions.None); + if (argAGENT.Length > 0) + { + if (argAGENT.Length == 1) + { + argAGENT = Shipping.Split(new string[] { "\n" }, StringSplitOptions.None); + if (argAGENT.Length > 0) + { + if (argAGENT.Length > rowNum && rowNum != 0) + { + if (isHuoMiao) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据!"; + } + else + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据,多余信息请手动以放到货物描述中!(例如:“货描内容" + sSymbol + "超出部分”)"; + } + } + for (int j = 0; j < argAGENT.Length; j++) + { + //List AgentList = formatlengthStr(argAGENT[j].ToString(), 35); + if (argAGENT[j].ToString().Length > length) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 第" + (j + 1) + "行超过" + length + "个字符"; + } + } + } + } + else + { + if (argAGENT.Length > rowNum && rowNum != 0) + { + if (isHuoMiao) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据!"; + } + else + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据,多余信息请手动放到货物描述中!(例如:“货描内容" + sSymbol + "超出部分”)"; + } + } + for (int j = 0; j < argAGENT.Length; j++) + { + //List AgentList = formatlengthStr(argAGENT[j].ToString(), 35); + if (argAGENT[j].ToString().Length > length) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 第" + (j + 1) + "行超过" + length + "个字符"; + } + } + } + } + return error; + } + #endregion + + public static bool IsChinese(char c) + { + return (int)c > 0x80; + } + + public static bool StringIsChinese(string str) + { + var result = false; + for (int i = 1; i < str.Length; i++) + { + if (IsChinese(str[i])) + { + result = true; + return result; + } + } + for (int i = 0; i < str.Length; i++) + { + string stemp = str.Substring(i, 1); + int ilen = System.Text.Encoding.Default.GetByteCount(stemp); + if (ilen == 2) + { + result = true; + return result; + } + + } + + return result; + } + + public static string IsCreatePILMELL(EDIBaseModel InttrEdi) + { + var error = ""; + foreach (var bill in InttrEdi.BSLIST) + { + if (InttrEdi.filetype == "B") + { + if (InttrEdi.UseForWarderCode) + { + if (InttrEdi.ForWarderCode?.Trim() == "") + { error = error + "
货代代码不能为空"; } + + if (InttrEdi.ForWarderName.Trim() == "") + { error = error + "
货代称呼不能为空"; } + + if (bill.ORDERNO.Trim() == "") + { error = error + "
订舱编号不能为空"; } + } + } + //if (bill.OP == null || bill.OP == "") + //{ error = error + "
操作不能为空"; } + + if (bill.CARRIERID != "YML") + { + if (string.IsNullOrWhiteSpace(bill.OpEName)) + { error = error + "
操作的英文名不能为空"; } + + if (string.IsNullOrWhiteSpace(bill.OpTel)) + { error = error + "
操作的电话不能为空"; } + } + + if (bill.SERVICE == "DOOR-DOOR" || bill.SERVICE == "DOOR-CY" || bill.SERVICE == "CY-DOOR") + { + if (bill.CARRIERID != "YML") + { + if (string.IsNullOrWhiteSpace(bill.EDIATTN)) + { error = error + "
EDI信息联系人不能为空"; } + + if (string.IsNullOrWhiteSpace(bill.EDIATTNTEL)) + { error = error + "
EDI信息联系人电话不能为空"; } + + if (string.IsNullOrWhiteSpace(bill.EDIATTNEMAIL)) + { error = error + "
EDI信息联系人邮箱不能为空"; } + } + } + + if (bill.CARGOID == "D") + { + if (bill.CARRIERID != "YML") + { + if (string.IsNullOrEmpty(bill.EDIATTN)) + { + } + else + { + if (bill.EDIATTN == null || bill.EDIATTN == "") + { error = error + "
EDI信息联系人不能为空"; } + + if (bill.EDIATTNTEL == null || bill.EDIATTNTEL == "") + { error = error + "
EDI信息联系人电话不能为空"; } + + if (bill.EDIATTNEMAIL == null || bill.EDIATTNEMAIL == "") + { error = error + "
EDI信息联系人邮箱不能为空"; } + } + } + } + + if (bill.MBLNO == null || bill.MBLNO == "") + { } + else + { + if (StringIsChinese(bill.MBLNO)) + { + error = error + "
提单号:" + bill.MBLNO + " 提单号含有中文或双字节字符"; + } + } + + if ((bill.BLFRT == null || bill.BLFRT == "")) + { error = error + "
提单号:" + bill.MBLNO + " 付费方式不能为空"; } + + //if (filetype == "E") + //{ + //if (carrier != "MAEU") + //if ((bill.HSCODE == null || bill.HSCODE == "")) + //{ error = error + "
提单号:" + bill.MBLNO + " HSCODE不能为空"; } + if (bill.CARRIEREDICODE != "MCCQ" && bill.CARRIEREDICODE != "MAEU" && bill.CARRIEREDICODE != "SUDU") + { + if (bill.VESSEL == null || bill.VESSEL == "") + { error = error + "
提单号:" + bill.MBLNO + " 船名不能为空"; } + + if (bill.VOYNO == null || bill.VOYNO == "") + { error = error + "
提单号:" + bill.MBLNO + " 航次不能为空"; } + } + //} + if (InttrEdi.filetype == "E") + { + if (bill.SIREMARK.IndexOf("PLEASE BOOK OCEAN CARRIER") > -1 || bill.SIREMARK.ToString().Trim() == "") + { + if (bill.CARRIEREDICODE == "COSU") + { + error = error + "
提单号:" + bill.MBLNO + " 请在SI备注中输入:COSCO 销售的营销代码(此代码船公司会直接提供)"; + } + else + { + //if (carrier != "YML") + //error = error + "
提单号:" + bill.MBLNO + " EDI备注中不能为空"; + } + } + else + { + if (StringIsChinese(bill.SIREMARK)) + { + error = error + "
提单号:" + bill.MBLNO + " SI备注中含有中文或双字节字符"; + } + //if (bill.EDIREMARK.ToString().Trim()!="" && BasicDataRefDAL.isHasChinese(bill.EDIREMARK)) + //{ + // error = error + "
提单号:" + bill.MBLNO + " 请在EDI备注中输入:英文(不允许录入中文)"; + //} + } + } + else + { + if (bill.EDIREMARK.IndexOf("PLEASE BOOK OCEAN CARRIER") > -1 || bill.EDIREMARK.ToString().Trim() == "") + { + if (bill.CARRIEREDICODE == "COSU") + { + error = error + "
提单号:" + bill.MBLNO + " 请在EDI备注中输入:COSCO 销售的营销代码(此代码船公司会直接提供)"; + } + else + { + //if (carrier != "YML") + //error = error + "
提单号:" + bill.MBLNO + " EDI备注中不能为空"; + } + } + else + { + if (StringIsChinese(bill.EDIREMARK)) + { + error = error + "
提单号:" + bill.MBLNO + " EDI备注中含有中文或双字节字符"; + } + //if (bill.EDIREMARK.ToString().Trim()!="" && BasicDataRefDAL.isHasChinese(bill.EDIREMARK)) + //{ + // error = error + "
提单号:" + bill.MBLNO + " 请在EDI备注中输入:英文(不允许录入中文)"; + //} + } + } + if (bill.CARRIER == null || bill.CARRIER == "") + { error = error + "
提单号:" + bill.MBLNO + " 船公司不能为空"; } + else + { + if (string.IsNullOrWhiteSpace(bill.CARRIEREDICODE)) + { error = error + "
提单号:" + bill.MBLNO + " 船公司EDI代码不能为空"; } + } + + if (string.IsNullOrWhiteSpace(bill.SHIPPER)) + { + error = error + "
提单号:" + bill.MBLNO + " 发货人不能为空"; + } + else + { + if (StringIsChinese(bill.SHIPPER)) + { + error = error + "
提单号:" + bill.MBLNO + " 发货人含有中文或双字节字符"; + } + } + + if (bill.CONSIGNEE == "") + { + error = error + "
提单号:" + bill.MBLNO + " 收货人不能为空"; + } + else + { + if (StringIsChinese(bill.CONSIGNEE)) + { + error = error + "
提单号:" + bill.MBLNO + " 收货人含有中文或双字节字符"; + } + } + /* + if (bill.SERVICE == "CY-DOOR") + { + if (bill.DOORADDR == "") + { + error = error + "
提单号:" + bill.MBLNO + " 运输条款为:CY-DOOR,EDI信息中的DOOR地址不能为空"; + } + else + { + if (StringIsChinese(bill.DOORADDR)) + { + error = error + "
提单号:" + bill.MBLNO + " DOOR地址含有中文或双字节字符"; + } + } + } + if (bill.SERVICE == "DOOR-CY") + { + if (bill.ATTNADDR == "") + { + error = error + "
提单号:" + bill.MBLNO + " 运输条款为:DOOR-CY,EDI信息中的联系人地址不能为空"; + } + else + { + if (StringIsChinese(bill.ATTNADDR)) + { + error = error + "
提单号:" + bill.MBLNO + " 联系人地址含有中文或双字节字符"; + } + } + } + */ + if (bill.NOTIFYPARTY == "") + { + error = error + "
提单号:" + bill.MBLNO + " 通知人不能为空"; + } + else + { + if (StringIsChinese(bill.NOTIFYPARTY)) + { + error = error + "
提单号:" + bill.MBLNO + " 通知人含有中文或双字节字符"; + } + else + { + //if (carrier == "HLCU") + //{ + // error += formatlengthError("txt", bill.NOTIFYPARTY, 35, bill.MBLNO, "通知人", 6, "---", false); + //} + //else + //{ + // error += formatlengthError("txt", bill.NOTIFYPARTY, 35, bill.MBLNO, "通知人", 6, "***", false); + //} + } + } + + if (bill.MARKS == "") + { + error = error + "
提单号:" + bill.MBLNO + " 唛头不能为空"; + } + else + { + if (StringIsChinese(bill.MARKS)) + { + error = error + "
提单号:" + bill.MBLNO + " 唛头含有中文或双字节字符"; + } + else + { + error += formatlengthError("txt", bill.MARKS, 35, bill.MBLNO, "唛头", 0, "", false); + } + } + + if (bill.DESCRIPTION == "") + { + error = error + "
提单号:" + bill.MBLNO + " 货物描述不能为空"; + } + else + { + if (StringIsChinese(bill.DESCRIPTION)) + { + error = error + "
提单号:" + bill.MBLNO + " 货物描述含有中文或双字节字符"; + } + else + { + //error += formatlengthError("txt", bill.DESCRIPTION, 35, bill.MBLNO, "货物描述", 0, ""); + } + } + + if (string.IsNullOrWhiteSpace(bill.PORTLOADID) || bill.PORTLOADID.Length != 5) + { error = error + "
提单号:" + bill.MBLNO + " 装货港代码不能为空或录入不正确(必须是5位代码)"; } + + + if (bill.PORTLOAD == null || bill.PORTLOAD == "") + { error = error + "
提单号:" + bill.MBLNO + " 装货港不能为空"; } + + if (bill.ETD == null || bill.ETD == "") + { + error = error + "
提单号:" + bill.MBLNO + " 开船日期不能为空"; + return error; + } + + if (string.IsNullOrWhiteSpace(bill.PORTDISCHARGEID) || bill.PORTDISCHARGEID.Length != 5) + { error = error + "
提单号:" + bill.MBLNO + " 卸货港代码不能为空或录入不正确(必须是5位代码)"; } + + if (bill.PORTDISCHARGE == null || bill.PORTDISCHARGE == "") + { error = error + "
提单号:" + bill.MBLNO + " 卸货港不能为空"; } + + if (string.IsNullOrWhiteSpace(bill.DESTINATIONID) || bill.DESTINATIONID.Length != 5) + { error = error + "
提单号:" + bill.MBLNO + " 目的地代码不能为空或录入不正确(必须是5位代码)"; } + + if (string.IsNullOrWhiteSpace(bill.KINDPKGS_EDI_CODE)) + { error = error + "
提单号:" + bill.MBLNO + " 包装EDI代码不能为空"; } + + if (Convert.ToDecimal(bill.PKGS) == 0) + { error = error + "
提单号:" + bill.MBLNO + " 货物件数不能为空"; } + if (Convert.ToDecimal(bill.KGS) == 0) + { error = error + "
提单号:" + bill.MBLNO + " 货物重量不能为空"; } + if (Convert.ToDecimal(bill.CBM) == 0) + { error = error + "
提单号:" + bill.MBLNO + " 货物尺码不能为空"; } + + + if (bill.CARRIEREDICODE != "MCCQ" && bill.CARRIEREDICODE != "MAEU" && bill.CARRIEREDICODE != "SUDU" && bill.CARRIEREDICODE != "CMDU") + { + if (bill.HSCODE == null || bill.HSCODE == "") + { error = error + "
提单号:" + bill.MBLNO + " HS编码不能为空"; } + } + + if (bill.CARGOID == null || bill.CARGOID == "") + { error = error + "
提单号:" + bill.MBLNO + " 货物标示不能为空"; } + + if (bill.CARGOID == "D") + { + if (bill.DCLASS == null || bill.DCLASS == "") + { error = error + "
提单号:" + bill.MBLNO + " 危险品分类不能为空"; } + + if (bill.DUNNO == null || bill.DUNNO == "") + { error = error + "
提单号:" + bill.MBLNO + " 危险品编号不能为空"; } + } + if (bill.CARGOID == "R") + { + if (bill.TEMPSET == null || bill.TEMPSET == "") + { error = error + "
提单号:" + bill.MBLNO + " 设置温度不能为空"; } + if (bill.REEFERF == null || bill.REEFERF == "") + { error = error + "
提单号:" + bill.MBLNO + " 通风度不能为空"; } + } + + if (bill.BLFRT.IndexOf("PREPAID") >= 0) + { + if (bill.CARRIERID == "YML") + { + if (bill.PREPARDATID == "") + { error = error + "
提单号:" + bill.MBLNO + " 预付地点或预付地点EDI代码不能为空"; } + } + else + { + if ((bill.PREPARDATID == "")) + { error = error + "
提单号:" + bill.MBLNO + " 预付地点或预付地点EDI代码不能为空"; } + } + } + + if (bill.BLFRT.IndexOf("COLLECT") >= 0) + { + if (string.IsNullOrWhiteSpace(bill.PAYABLEAT)) + { error = error + "
提单号:" + bill.MBLNO + " 到付地点或到付地点EDI代码不能为空"; } + } + + if (InttrEdi.filetype == "E") + { + if (string.IsNullOrWhiteSpace(bill.ISSUEPLACEID)) + { error = error + "
提单号:" + bill.MBLNO + " 签单地点或到签单地点EDI代码不能为空"; } + + } + + if ((bill.SERVICE == null || bill.SERVICE == "")) + { error = error + "
提单号:" + bill.MBLNO + " 运输条款不能为空"; } + + + if (bill.CTNLIST.Count == 0) { error = error + "
提单号:" + bill.MBLNO + " 集装箱信息不能为空"; }; + + if (InttrEdi.filetype == "E") + { + #region 集装箱判断检查 + string sCtnCntrno = ""; + int iCTN = 0; + int iCTNDetail = 0; + if (bill.CTNLIST.Count != 0) + { + Decimal dlPKGS = 0; + Decimal dlKGS = 0; + Decimal dlCBM = 0; + foreach (var ctn in bill.CTNLIST) + { + if (string.IsNullOrWhiteSpace(ctn.CTNALLCODE)) + { error = error + "
提单号:" + bill.MBLNO + " 集装箱箱型EDI代码不能为空"; } + + + if (ctn.CNTRNO == null || ctn.CNTRNO == "") + { error = error + "
提单号:" + bill.MBLNO + " 箱号不能为空"; } + if (ctn.SEALNO == null || ctn.SEALNO == "") + { error = error + "
提单号:" + bill.MBLNO + " 封号不能为空"; } + if (bill.BYCOUNTRY == "BRAZIL") + { + if (ctn.TAREWEIGHT == 0) + { error = error + "
提单号:" + bill.MBLNO + " 箱皮重不能为空"; } + } + if (ctn.KINDPKGS != bill.KINDPKGS) + { error = error + "
提单号:" + bill.MBLNO + " 中的包装类型与集装箱的包装类型不同"; } + + sCtnCntrno += "、" + ctn.CNTRNO; + + iCTN++; + // + dlPKGS += ctn.PKGS; + dlKGS += ctn.KGS; + dlCBM += ctn.CBM; + } + + if (dlPKGS != Convert.ToInt32(bill.PKGS)) + { error = error + "
提单号:" + bill.MBLNO + " 集装箱件数合计数必须等于委托单总件数"; } + if (dlKGS != Convert.ToDecimal(bill.KGS)) + { error = error + "
提单号:" + bill.MBLNO + " 集装箱重量合计数必须等于委托单总重量数"; } + if (dlCBM != Convert.ToDecimal(bill.CBM)) + { error = error + "
提单号:" + bill.MBLNO + " 集装箱尺码合计数必须等于委托单总尺码数"; } + } + #endregion + + if (bill.BYCOUNTRY == "USA") + { + if (bill.CONSIGNEEPOSTCODE == null || bill.CONSIGNEEPOSTCODE == "") + { error = error + "
提单号:" + bill.MBLNO + " 收货人邮编不能为空"; } + if (bill.NOTIFYPARTYPOSTCODE == null || bill.NOTIFYPARTYPOSTCODE == "") + { error = error + "
提单号:" + bill.MBLNO + " 通知人邮编不能为空"; } + } + else if (bill.BYCOUNTRY == "CANADA") + { + if (bill.CONSIGNEEPOSTCODE == null || bill.CONSIGNEEPOSTCODE == "") + { error = error + "
提单号:" + bill.MBLNO + " 收货人邮编不能为空"; } + } + else if (bill.BYCOUNTRY == "BRAZIL") + { + if (bill.CONSIGNEECOUNTRY == null || bill.CONSIGNEECOUNTRY == "") + { error = error + "
提单号:" + bill.MBLNO + " 收货人国家代码不能为空"; } + if (bill.CONSIGNEETAXNO == null || bill.CONSIGNEETAXNO == "") + { error = error + "
提单号:" + bill.MBLNO + " 收货人税号不能为空"; } + if (bill.NOTIFYPARTYCOUNTRY == null || bill.NOTIFYPARTYCOUNTRY == "") + { error = error + "
提单号:" + bill.MBLNO + " 通知人国家代码不能为空"; } + if (bill.NOTIFYPARTYTAXNO == null || bill.NOTIFYPARTYTAXNO == "") + { error = error + "
提单号:" + bill.MBLNO + " 通知人税号不能为空"; } + if (bill.GOODSNCM == null || bill.GOODSNCM == "") + { error = error + "
提单号:" + bill.MBLNO + " 货物NCM编码不能为空"; } + } + } + else + { + } + + if (bill.CARRIERID == "YML") + { + //2023-03-07 SHIPPERCOUNTRY 没有这个字段 + //???if (string.IsNullOrEmpty(bill.SHIPPERCOUNTRY)) error = error + "
提单号:" + bill.MBLNO + " 发货人国家代码不能为空"; + if (string.IsNullOrEmpty(bill.CONSIGNEECOUNTRY)) error = error + "
提单号:" + bill.MBLNO + " 收货人国家代码不能为空"; + + + } + } + return error; + } + + /// + /// + /// + /// + /// + public static EdiDataResult CreateEdiPILMELL(EDIBaseModel InttrEdi) + { + var result = new EdiDataResult { Succeeded = false }; + + string dir = InttrEdi.filerpath + "\\" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + "\\"; + + //如果是部署linux需要修改路径 + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + dir = dir.Replace("\\", "/"); + + if (!Directory.Exists(dir)) + { + Directory.CreateDirectory(dir); + } + + string filename = dir + InttrEdi.BSLIST.FirstOrDefault().MBLNO + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt"; + + FileStream f = new FileStream(filename, FileMode.Create); + StreamWriter r = new StreamWriter(f, Encoding.Default); + + var icount = 0; + var bsno = ""; + + /* + 2023-03-13 跟韩工确认当前帮助类根据不同的用户需要选择不同的报文版本 + UNOC:2-适用客户和川; + UNOB:1-适用其他客户,需要到具体客户时来配置。 + 考虑 InttrEdi.SENDCOMPANYCODE - 发送方部门代码,本帮助类未适用,所以改用这个字段配置 + UNOC-(UNOC:2);UNOB-(UNOB:1) + */ + string sendCompanyCode = "UNOB:1"; + if (!string.IsNullOrWhiteSpace(InttrEdi.SENDCOMPANYCODE) + && InttrEdi.SENDCOMPANYCODE.Equals("UNOC", StringComparison.OrdinalIgnoreCase)) + { + sendCompanyCode = "UNOC:2"; + } + + r.WriteLine("UNB+" + sendCompanyCode + "+" + InttrEdi.SENDCODE + "SO:ZZZ+" + InttrEdi.RECEIVECODE + ":ZZZ+" + DateTime.Now.ToString("yyMMdd:HHmm") + "+" + InttrEdi.BSLIST.FirstOrDefault().ORDERNO + "'"); + icount = icount + 1; + foreach (var bill in InttrEdi.BSLIST) + { + bsno = bill.ORDERNO; + + r.WriteLine("UNH+" + bill.ORDERNO + "+IFTMBF:D:99B:UN'"); + + + icount = icount + 1; + + if (InttrEdi.filerole == "9") + r.WriteLine("BGM+335+" + bill.MBLNO + "+9'"); + else + r.WriteLine("BGM+335+" + bill.MBLNO + "+5'"); + + r.WriteLine("DTM+137:" + DateTime.Now.ToString("yyyyMMddHHmm") + ":203'"); + icount = icount + 2; + + if (bill.SERVICE.ToUpper() == "DOOR-DOOR") + { + r.WriteLine("TSR+16+2'"); + } + else if (bill.SERVICE.ToUpper() == "DOOR-CY") + { + r.WriteLine("TSR+15+2'"); + } + else if (bill.SERVICE.ToUpper() == "CY-DOOR") + { + r.WriteLine("TSR+17+2'"); + } + else if (bill.SERVICE.ToUpper() == "CFS-CFS") + { + r.WriteLine("TSR+14+2'"); + } + else + { + r.WriteLine("TSR+11+2'"); + } + + icount = icount + 1; + + var str_pay = ""; + if (bill.BLFRT.IndexOf("PREPAID") >= 0) + str_pay = bill.PREPARDAT; + if (bill.BLFRT.IndexOf("COLLECT") >= 0) + str_pay = bill.PAYABLEAT; + + r.WriteLine("LOC+88+" + bill.PORTLOADID + ":139:6:" + bill.PORTLOAD + "'"); + icount = icount + 1; + + if (!string.IsNullOrWhiteSpace(bill.DESTINATION)) + { + r.WriteLine("LOC+7+" + bill.DESTINATIONID + ":139:6:" + bill.DESTINATION + "'"); + icount = icount + 1; + } + + r.WriteLine("DTM+95:" + GetDateStr(bill.ISSUEDATE, "yyyyMMdd") + ":102'"); + icount = icount + 1; + + r.WriteLine("RFF+BN:" + bill.MBLNO + "'"); + r.WriteLine("RFF+BM:" + bill.MBLNO + "'"); + + icount = icount + 2; + + if (!string.IsNullOrEmpty(bill.CONTRACTNO)) + { + r.WriteLine("RFF+CT:" + formatEdiStr("txt", bill.CONTRACTNO) + "'"); + icount = icount + 1; + } + + + var voyno = ""; + if (bill.VOYNO.IndexOf(".") >= 0) + voyno = bill.VOYNO.Substring(bill.VOYNO.IndexOf(".") + 1, bill.VOYNO.Length - bill.VOYNO.IndexOf(".") - 1); + else + voyno = bill.VOYNO; + + r.WriteLine("TDT+20+" + voyno + "+1++MELL:172+++:::" + bill.VESSEL + "'"); + r.WriteLine("LOC+9+" + bill.PORTLOADID + ":139:6:" + bill.PORTLOAD + "'"); + r.WriteLine("DTM+133:" + GetDateStr(bill.ETD, "yyyyMMdd") + ":102'");//yyyyMMddHHmm + r.WriteLine("LOC+11+" + bill.PORTDISCHARGEID + ":139:6:" + bill.PORTDISCHARGE + "'"); + icount = icount + 4; + + var Shipping = ""; + var DescriptionShipper = ""; + + Shipping = formatEdiStr("txt", bill.SHIPPER); + + List ShippingList = formatlengthStr(Shipping, 35); + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + for (var i = 0; i < ShippingList.Count; i++) + { + if (i == 0) Shipping = "NAD+CZ+" + InttrEdi.SENDSUBCOMPANYCODE + "+" + ShippingList[0] + ":"; + if (i == 1) Shipping = Shipping + ShippingList[i]; + if (i == 2 || i == 3) Shipping = Shipping + ":" + ShippingList[i]; + if (i >= 4 && ShippingList.Count > 5) + { + if (i == 4) + { + if (ShippingList[i].Length > 34) + { + Shipping = Shipping + ":" + ShippingList[i].Substring(0, 34); + DescriptionShipper = ShippingList[i].Substring(34); + } + else + Shipping = Shipping + ":" + ShippingList[i]; + + Shipping = Shipping + "*"; + DescriptionShipper = "*" + DescriptionShipper; + + } + else if (i > 4) + { + + DescriptionShipper = DescriptionShipper + " " + ShippingList[i]; + } + + } + else + if (i == 4) Shipping = Shipping + ":" + ShippingList[i]; + } + } + + r.WriteLine(Shipping + "'"); + icount = icount + 1; + + if (!string.IsNullOrWhiteSpace(bill.BYCOUNTRY)) + Shipping = formatEdiStr("txt", bill.AMSCONSIGNEE); + else + Shipping = formatEdiStr("txt", bill.CONSIGNEE); + + ShippingList = formatlengthStr(Shipping, 35); + + var DescriptionConsignee = ""; + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + + for (var i = 0; i < ShippingList.Count; i++) + { + if (i == 0) Shipping = "NAD+CN+" + InttrEdi.SENDSUBCOMPANYCODE + "+" + ShippingList[0] + ":"; + if (i == 1) Shipping = Shipping + ShippingList[i]; + if (i == 2 || i == 3) Shipping = Shipping + ":" + ShippingList[i]; + if (i >= 4 && ShippingList.Count > 5) + { + if (i == 4) + { + if (ShippingList[i].Length > 33) + { + Shipping = Shipping + ":" + ShippingList[i].Substring(0, 33); + DescriptionConsignee = ShippingList[i].Substring(33); + } + else + Shipping = Shipping + ":" + ShippingList[i]; + + Shipping = Shipping + "**"; + DescriptionConsignee = "**" + DescriptionConsignee; + + } + else if (i > 4) + { + + DescriptionConsignee = DescriptionConsignee + " " + ShippingList[i]; + } + + } + else + if (i == 4) Shipping = Shipping + ":" + ShippingList[i]; + } + } + r.WriteLine(Shipping + "'"); + icount = icount + 1; + + if (!string.IsNullOrWhiteSpace(bill.BYCOUNTRY)) + Shipping = formatEdiStr("txt", bill.AMSNOTIFYPARTY); + else + Shipping = formatEdiStr("txt", bill.NOTIFYPARTY); + + + ShippingList = formatlengthStr(Shipping, 35); + + var DescriptionNotifyparty = ""; + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + + for (var i = 0; i < ShippingList.Count; i++) + { + if (i == 0) Shipping = "NAD+NI+" + InttrEdi.SENDSUBCOMPANYCODE + "+" + ShippingList[0] + ":"; + if (i == 1) Shipping = Shipping + ShippingList[i]; + if (i == 2 || i == 3) Shipping = Shipping + ":" + ShippingList[i]; + if (i >= 4 && ShippingList.Count > 5) + { + if (i == 4) + { + if (ShippingList[i].Length > 32) + { + Shipping = Shipping + ":" + ShippingList[i].Substring(0, 32); + DescriptionNotifyparty = ShippingList[i].Substring(32); + } + else + Shipping = Shipping + ":" + ShippingList[i]; + + Shipping = Shipping + "***"; + DescriptionNotifyparty = "***" + DescriptionNotifyparty; + + } + else if (i > 4) + { + + DescriptionNotifyparty = DescriptionNotifyparty + " " + ShippingList[i]; + } + + } + else + if (i == 4) Shipping = Shipping + ":" + ShippingList[i]; + } + } + + if (bill.BYCOUNTRY == "USA") + { + Shipping = Shipping + "+++" + bill.NOTIFYPARTYPOSTCODE; + r.WriteLine(Shipping + "'"); + } + else if (bill.BYCOUNTRY == "BRAZIL") + { + if (!string.IsNullOrWhiteSpace(bill.NOTIFYPARTYCOUNTRY)) + Shipping = Shipping + "++++" + bill.NOTIFYPARTYCOUNTRY; + + r.WriteLine(Shipping + "'"); + + if (!string.IsNullOrWhiteSpace(bill.NOTIFYPARTYTAXNO)) + { + r.WriteLine("RFF+GN:" + bill.NOTIFYPARTYTAXNO + "'"); + icount = icount + 1; + + } + } + else r.WriteLine(Shipping + "'"); + icount = icount + 1; + + r.WriteLine("NAD+BP+" + InttrEdi.ALIASSENDCODE + "+" + InttrEdi.SENDNAME + ":160:86+'"); + icount = icount + 1; + r.WriteLine("NAD+AP+" + InttrEdi.SENDSUBCOMPANYCODE + "+" + InttrEdi.SENDNAME + ":160:86+'"); + + icount = icount + 1; + + if (bill.BLFRT.IndexOf("PREPAID") >= 0) + r.WriteLine("CPI+4++P'"); + else if (bill.BLFRT.IndexOf("COLLECT") >= 0) + r.WriteLine("CPI+4++C'"); + else + r.WriteLine("CPI+4++B'"); + icount = icount + 1; + + r.WriteLine("GID+1+" + bill.PKGS.ToString() + ":" + bill.KINDPKGS_EDI_CODE.Trim() + "::6:" + bill.KINDPKGS + "'"); + + icount = icount + 1; + + if (!string.IsNullOrWhiteSpace(bill.HSCODE)) + { + r.WriteLine("PIA+5+" + bill.HSCODE + ":HS'"); + icount = icount + 1; + + } + + Shipping = formatEdiStr("txt", bill.DESCRIPTION); + + Shipping = Shipping.Replace("\n", "\\"); + Shipping = Shipping.Replace("\r", " "); + string[] DescriptionList = Shipping.Split('\\'); + if (DescriptionList.Length != 0) + { + + for (var i = 0; i < DescriptionList.Length; i++) + { + if (i <= 1) + { + r.WriteLine("FTX+AAA+++" + DescriptionList[i] + "'"); + icount = icount + 1; + } + + } + } + + r.WriteLine("MEA+AAE+G+KGM:" + Math.Round(Convert.ToDecimal(bill.KGS), 3) + "'"); + r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(Convert.ToDecimal(bill.CBM), 3) + "'"); + + icount = icount + 2; + + + if (bill.CARGOID == "D") + { + r.WriteLine("DGS+IMD+" + bill.DCLASS + "+" + bill.DUNNO + "'"); + r.WriteLine("CTA+HG+:" + bill.EDIATTN + "'"); + r.WriteLine("COM+" + bill.EDIATTNTEL + ":TE'"); + icount = icount + 3; + } + + foreach (var ctn in bill.CTNLIST) + { + if (bill.ISCONTAINERSOC) + r.WriteLine("EQD+CN++" + ctn.CTNALLCODE + "+1'"); + else + r.WriteLine("EQD+CN++" + ctn.CTNALLCODE + "+2'"); + + r.WriteLine("EQN+" + ctn.CTNNUM.ToString() + "'"); + icount = icount + 2; + + if (bill.CARGOID == "R") + { + if (bill.REEFERF != "" && bill.REEFERF != "0") + { + r.WriteLine("MEA+AAE+AAS+CBM:" + bill.REEFERF + "'"); + icount = icount + 1; + } + + if (bill.HUMIDITY != "") + { + r.WriteLine("MEA+AAE+AAO+HMD:" + bill.HUMIDITY + "'"); + icount = icount + 1; + } + + r.WriteLine("TMP+2+" + bill.TEMPSET.Replace("+", "") + ":CEL'"); + icount = icount + 1; + + + } + + } + + } + r.WriteLine("UNT+" + icount.ToString() + "+" + bsno + "'"); + r.WriteLine("UNZ+" + InttrEdi.BSLIST.Count.ToString() + "+" + bsno + "'"); + r.Close(); + f.Close(); + + result.Succeeded = true; + result.ExtraData1 = filename; + result.ExtraData2 = GetEmailTopic(InttrEdi); + return result; + } + + /// + /// 获取邮件主题 + /// + /// + /// + public static string GetEmailTopic(EDIBaseModel inttrEdi) + { + if (inttrEdi.filetype.Equals("B", StringComparison.OrdinalIgnoreCase)) + { + return "[CNTAO-QJM] IFTMBF" + inttrEdi.BSLIST.FirstOrDefault().MBLNO?.Trim(); + } + else if (inttrEdi.filetype.Equals("E", StringComparison.OrdinalIgnoreCase)) + { + return inttrEdi.BSLIST.FirstOrDefault().MBLNO?.Trim() + " " + "ESI"; + } + + return string.Empty; + } + } +} diff --git a/ds-wms-service/DS.WMS.Core/Op/EDI/PILEdiHelper.cs b/ds-wms-service/DS.WMS.Core/Op/EDI/PILEdiHelper.cs new file mode 100644 index 00000000..94b699b4 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Op/EDI/PILEdiHelper.cs @@ -0,0 +1,1908 @@ +using DS.Module.Core; +using DS.WMS.Core.Op.Dtos; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace DS.WMS.Core.Op.EDI +{ + public class PILEdiHelper + { + + public PILEdiHelper() + { + } + + #region 基本函数 + + public static string GetDateStr(string datestr, string dateformat) + { + var result = ""; + + if (datestr == null || datestr == "") + { + result = ""; + } + else + { + result = Convert.ToDateTime(datestr).ToString(dateformat); + + } + + return result; + + } + + #region 判断中文字符 + public static bool IsChinese(char c) + { + return (int)c > 0x80; + } + public static bool StringIsChinese(string str) + { + var result = false; + for (int i = 1; i < str.Length; i++) + { + if (IsChinese(str[i])) + { + result = true; + return result; + } + } + for (int i = 0; i < str.Length; i++) + { + string stemp = str.Substring(i, 1); + int ilen = System.Text.Encoding.Default.GetByteCount(stemp); + if (ilen == 2) + { + result = true; + return result; + } + + } + + return result; + } + + #endregion + + + + #region 文本字段判断每行是否符合 + /// + /// edi 文本格式处理判断(例如:1行35个字符不超过5行) + /// + /// 文件类型(例如:txt、xml) + /// 要处理的数据 + /// 每行长度 + /// 主提单号 + /// 数据类型(例如:发货人内容、货描等) + /// 限制录入的行数(“0”代表不限制) + /// 限录后多出的放到货描中的数据的连接符(例如:“*”发货人内容、“**”收件人等) + /// + public static System.String formatlengthError(string fileType, string str, int length, string sMBLNO, string sType, int rowNum, string sSymbol, bool isHuoMiao) + { + string error = ""; + string Shipping = str; + if (fileType == "txt") + { + //Shipping = formatEdiStr("txt", str); + } + else if (fileType == "xml") + { + Shipping = formatEdiStr("txt", str); + } + string[] argAGENT = Shipping.Split(new string[] { "\r\n" }, StringSplitOptions.None); + if (argAGENT.Length > 0) + { + if (argAGENT.Length == 1) + { + argAGENT = Shipping.Split(new string[] { "\n" }, StringSplitOptions.None); + if (argAGENT.Length > 0) + { + if (argAGENT.Length > rowNum && rowNum != 0) + { + if (isHuoMiao) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据!"; + } + else + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据,多余信息请手动以放到货物描述中!(例如:“货描内容" + sSymbol + "超出部分”)"; + } + } + for (int j = 0; j < argAGENT.Length; j++) + { + //List AgentList = formatlengthStr(argAGENT[j].ToString(), 35); + if (argAGENT[j].ToString().Length > length) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 第" + (j + 1) + "行超过" + length + "个字符"; + } + } + } + } + else + { + if (argAGENT.Length > rowNum && rowNum != 0) + { + if (isHuoMiao) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据!"; + } + else + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据,多余信息请手动放到货物描述中!(例如:“货描内容" + sSymbol + "超出部分”)"; + } + } + for (int j = 0; j < argAGENT.Length; j++) + { + //List AgentList = formatlengthStr(argAGENT[j].ToString(), 35); + if (argAGENT[j].ToString().Length > length) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 第" + (j + 1) + "行超过" + length + "个字符"; + } + } + } + } + return error; + } + #endregion + + #region 字符转义 + /// + /// 各种文本转义字符 + /// + /// 文件类型(例如:txt、xml) + /// 文本字符串 + /// + public static string formatEdiStr(string fileType, string str) + { + if (str == null) + str = string.Empty; + + if (fileType == "txt") + { + return str.Replace("?", "??").Replace(":", "?:").Replace("+", "?+").Replace("'", "?'"); + } + else if (fileType == "xml") + { + return str.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace("\"", """).Replace("'", "'"); + } + else if (fileType == "sitc") + { + return str.Replace("?", "??").Replace(":", "?:").Replace("'", "?'"); + } + else + { + return str; + } + } + #endregion + #region 格式化每行 + public static List formatlengthStr(string str, int length, bool formatstr = false, bool nodelsp = false) + { + str = str.Replace("\r\n", "\\"); + str = str.Replace("\n", "\\"); + str = str.Replace("\r", " "); + string[] StrList = str.Split('\\'); + var strtemp = ""; + var strnewline = ""; + var strtempnewline = ""; + char[] spstring = { ' ', ';', ',', '.', ':', '/', '(', ')', '?', '+', '-' }; + List DestList = new List(); + for (var i = 0; i <= StrList.Length - 1; i++) + { + if (StrList[i].Length <= length) + { + if (formatstr) + DestList.Add(formatEdiStr("txt", StrList[i])); + else + DestList.Add(StrList[i]); + + } + else + { + strtemp = StrList[i] + " "; + strtempnewline = ""; + strnewline = ""; + for (var j = 0; j < strtemp.Length; j++) + { + strtempnewline = strtempnewline + strtemp[j]; + if (strtemp[j] == ' ' || strtemp[j] == ':' || strtemp[j] == ',' || strtemp[j] == '.' || strtemp[j] == ':' || strtemp[j] == '/' + || strtemp[j] == '?' || strtemp[j] == ')' || strtemp[j] == '}' || strtemp[j] == '+' || strtemp[j] == '-') + { + if ((strnewline.Length + strtempnewline.Length) <= length) + strnewline = strnewline + strtempnewline; + else + { + if (formatstr) + DestList.Add(formatEdiStr("txt", strnewline)); + else + DestList.Add(strnewline); + strnewline = strtempnewline; + + } + strtempnewline = ""; + } + } + if (nodelsp) + { + if (formatstr) + DestList.Add(formatEdiStr("txt", strnewline)); + else DestList.Add(strnewline); + } + else if (strnewline.Trim() != "") + { + if (formatstr) + DestList.Add(formatEdiStr("txt", strnewline)); + else DestList.Add(strnewline); + } + } + + } + + return DestList; + } + #endregion + + public static string GetmpStr(string str, int len) + { + var strhead = ""; + + if (str.IndexOf("-") >= 0) + { + strhead = "-"; + str.Replace("-", ""); + } + + string result = str; + + for (var i = 0; i <= len - str.Length - 2; i++) + { + result = "0" + result; + } + + return result; + } + + public static string GetSpaceStr(string str, int len, string substr = " ") + { + + if (substr == "0") + { + if (str.IndexOf(".") >= 0) + str = str.Substring(0, str.IndexOf(".")); + } + string result = str; + if (str.Length >= len) + { + result = str.Substring(0, len); + + } + else + { + for (var i = 0; i <= len - str.Length - 1; i++) + { + if (substr == "0") + result = "0" + result; + else + result = result + substr; + } + } + return result; + } + public static string GetPILServiceStr(string str) + { + string result = "Y"; + str = str.ToUpper(); + char splitstr = '-'; + if (str.IndexOf("-") > 0) + { + splitstr = '-'; + } + else if (str.IndexOf("/") > 0) + { + splitstr = '/'; + } + var strList = str.Split(splitstr); + var i = 1; + var strhead = ""; + var strbotton = ""; + foreach (var substr in strList) + { + if (i == 1) + { + if (substr == "CY") strhead = "Y"; + else if (substr == "CFS") strhead = "F"; + else if (substr == "FO") strhead = "O"; + else if (substr == "DOOR") strhead = "O"; + else if (substr == "HOOK") strhead = "K"; + else if (substr == "TACKLE") strhead = "L"; + } + if (i == 2) + { + if (substr == "CY") strbotton = "Y"; + else if (substr == "CFS") strbotton = "F"; + else if (substr == "FO") strbotton = "O"; + else if (substr == "DOOR") strbotton = "O"; + else if (substr == "HOOK") strbotton = "K"; + else if (substr == "TACKLE") strbotton = "L"; + + } + i = i + 1; + } + if (strhead == "") strhead = "Y"; + if (strbotton == "") strbotton = "Y"; + result = strhead + strbotton; + + return result; + } + + #endregion + + #region 检查 + public static string IsCreatePILEDI(EDIBaseModel InttrEdi) + { + var error = ""; + + if (string.IsNullOrEmpty(InttrEdi.SENDCODE)) + { error = error + "
发送方代码不能为空"; } + + if (string.IsNullOrEmpty(InttrEdi.SENDNAME)) + { error = error + "
发送方名称不能为空"; } + + if (string.IsNullOrEmpty(InttrEdi.RECEIVECODE)) + { error = error + "
接收方代码不能为空"; } + + //2023-03-03 确认需要增加货代名称不能为空,这里对比东胜是填的订舱代理名称,这里需要人工填写 + if (string.IsNullOrEmpty(InttrEdi.ForWarderName)) + { error = error + "
货代称呼不能为空"; } + + + //if (InttrEdi.filetype == "B") + //{ + // if (InttrEdi.UseForWarderCode) + // { + // if (string.IsNullOrEmpty(InttrEdi.ForWarderCode)) + // { error = error + "
货代代码不能为空"; } + + // if (string.IsNullOrEmpty(InttrEdi.ForWarderName)) + // { error = error + "
货代称呼不能为空"; } + // } + //} + + + foreach (var bill in InttrEdi.BSLIST) + { + + if (string.IsNullOrEmpty(bill.ORDERNO)) + { error = error + "|订舱单号不能为空"; } + + //2023-03-21 跟韩工确认PIL不需要判断场站EDI去掉验证 + //if (bill.PORTLOADID == "CNTAO") + //{ + // if (string.IsNullOrEmpty(bill.YARD) || string.IsNullOrEmpty(bill.YARDEDICODE)) + // { error = error + "|场站和场站EDI代码不能为空"; } + //} + + if (string.IsNullOrEmpty(bill.MBLNO)) + { error = error + "|主提单号不能为空"; } + + if (string.IsNullOrEmpty(bill.BLFRT)) + { error = error + "
提单号:" + bill.MBLNO + "付费方式不能为空"; } + + if (string.IsNullOrEmpty(bill.PORTLOADID)) + { error = error + "
提单号:" + bill.MBLNO + "装货港代码不能为空"; } + + if (string.IsNullOrEmpty(bill.PORTLOAD)) + { error = error + "
提单号:" + bill.MBLNO + "装货港不能为空"; } + + if (string.IsNullOrEmpty(bill.ETD)) + { + error = error + "
提单号:" + bill.MBLNO + "开船日期不能为空"; + return error; + } + + if (string.IsNullOrEmpty(bill.ETA)) + { + error = error + "
提单号:" + bill.MBLNO + "预抵日期不能为空"; + return error; + } + + //2023-04-14 经韩工查看东胜的PIL逻辑,订舱时货物品名非必填,这里判断改为只截单时提醒 + if (InttrEdi.filetype.Equals("E", StringComparison.OrdinalIgnoreCase)) + { + if (string.IsNullOrEmpty(bill.GOODSNAME)) + { + error = error + "
提单号:" + bill.MBLNO + "货物品名不能为空"; + return error; + } + } + + if (string.IsNullOrEmpty(bill.PORTDISCHARGEID)) + { error = error + "
提单号:" + bill.MBLNO + "卸货港代码不能为空"; } + + if (string.IsNullOrEmpty(bill.PLACEDELIVERYID)) + { error = error + "
提单号:" + bill.MBLNO + "交货代码不能为空"; } + + if (bill.PLACEDELIVERY == null || bill.PLACEDELIVERY == "") + { error = error + "
提单号:" + bill.MBLNO + "交货地不能为空"; } + if (bill.DESTINATION == null || bill.DESTINATION == "") + { error = error + "
提单号:" + bill.MBLNO + "目的地不能为空"; } + + if (bill.ISSUEPLACE == null || bill.ISSUEPLACE == "") + { error = error + "
提单号:" + bill.ISSUEPLACE + "签单地点不能为空"; } + + if (bill.PKGS == 0) + { error = error + "
提单号:" + bill.MBLNO + "货物件数不能为空"; } + + if (bill.KGS == 0) + { error = error + "
提单号:" + bill.MBLNO + "货物毛重不能为空"; } + + if (bill.CBM == 0) + { error = error + "
提单号:" + bill.CBM + "货物尺码不能为空"; } + + if (InttrEdi.filetype.Equals("B", StringComparison.OrdinalIgnoreCase)) + { + if (string.IsNullOrWhiteSpace(bill.ShipperEdiCode)) + { error = error + "
提单号:" + bill.MBLNO + "发货人EDI代码不能为空"; } + + if (bill.BLFRT.IndexOf("FREIGHT PREPAID") < 0) + { + if (string.IsNullOrWhiteSpace(bill.ConsigneeEdiCode)) + { error = error + "
提单号:" + bill.MBLNO + "付款方式是到付时,收货人EDI代码不能为空"; } + } + + if (string.IsNullOrWhiteSpace(bill.CNPTNo)) + { error = error + "
提单号:" + bill.MBLNO + "CNPT NO不能为空"; } + } + + + if (bill.CARGOID == null || bill.CARGOID == "") + { error = error + "
提单号:" + bill.MBLNO + "货物标示不能为空"; } + + //2023-05-19 增加运费协议号必填 + if (string.IsNullOrWhiteSpace(bill.CONTRACTNO)) + { error = error + "
提单号:" + bill.MBLNO + "运费协议号不能为空"; } + + if (bill.CARGOID == "D") + { + if (bill.DCLASS == null || bill.DCLASS == "") + { error = error + "
提单号:" + bill.MBLNO + "危险品分类不能为空"; } + + if (bill.DUNNO == null || bill.DUNNO == "") + { error = error + "
提单号:" + bill.MBLNO + "危险品编号不能为空"; } + + if (bill.DUNNO.Length != 4) + { error = error + "
提单号:" + bill.MBLNO + "危险品编号必须是4位数字"; } + } + + if (bill.CARGOID == "R") + { + + if (bill.TEMPSET == null || bill.TEMPSET == "") + { error = error + "
提单号:" + bill.MBLNO + "设置温度不能为空"; } + else + { + if (bill.TEMPSET.IndexOf("+") < 0 && bill.TEMPSET.IndexOf("-") < 0 && bill.TEMPSET.IndexOf(".") < 0) + { error = error + "
提单号:" + bill.MBLNO + "温度格式输入不正确,请输入如此格式: -0.10 或 +0.10"; } + + } + if (bill.TEMPMAX == null || bill.TEMPMAX == "") + { error = error + "
提单号:" + bill.MBLNO + "最高温度不能为空"; } + else + { + if (bill.TEMPMAX.IndexOf("+") < 0 && bill.TEMPMAX.IndexOf("-") < 0 && bill.TEMPMAX.IndexOf(".") < 0) + { error = error + "
提单号:" + bill.MBLNO + "温度格式输入不正确,请输入如此格式: -0.10 或 +0.10"; } + + } + + if (bill.TEMPMIN == null || bill.TEMPMIN == "") + { error = error + "
提单号:" + bill.MBLNO + "最低温度不能为空"; } + else + { + if (bill.TEMPMIN.IndexOf("+") < 0 && bill.TEMPMIN.IndexOf("-") < 0 && bill.TEMPMIN.IndexOf(".") < 0) + { error = error + "
提单号:" + bill.MBLNO + "温度格式输入不正确,请输入如此格式: -0.10 或 +0.10"; } + + } + + } + + if (string.IsNullOrEmpty(bill.MARKS)) + { + error = error + "
提单号:" + bill.MBLNO + " 唛头不能为空"; + } + else + { + if (StringIsChinese(bill.MARKS)) + { + error = error + "
提单号:" + bill.MBLNO + " 唛头含有中文或双字节字符"; + } + else + { + error += formatlengthError("txt", bill.MARKS, 35, bill.MBLNO, "唛头", 0, "", false); + } + } + + if (string.IsNullOrEmpty(bill.DESCRIPTION)) + { + error = error + "
提单号:" + bill.MBLNO + " 货物描述不能为空"; + } + else + { + if (StringIsChinese(bill.DESCRIPTION)) + { + error = error + "
提单号:" + bill.MBLNO + " 货物描述含有中文或双字节字符"; + } + else + { + //error += formatlengthError("txt", bill.DESCRIPTION, 35, bill.MBLNO, "货物描述", 0, ""); + } + } + + + if (string.IsNullOrEmpty(bill.SHIPPER)) + { + error = error + "
提单号:" + bill.MBLNO + " 发货人不能为空"; + } + else + { + if (StringIsChinese(bill.SHIPPER)) + { + error = error + "
提单号:" + bill.MBLNO + " 发货人含有中文或双字节字符"; + } + else error += formatlengthError("txt", bill.SHIPPER, 35, bill.MBLNO, "发货人", 5, "*", false); + /* + EDI校验,通过和川操作确认应调整最大行数为5行,将最大6行改为5行 + */ + } + //} + + + + if (string.IsNullOrEmpty(bill.CONSIGNEE)) + { + error = error + "
提单号:" + bill.MBLNO + " 收货人不能为空"; + } + else + { + if (StringIsChinese(bill.CONSIGNEE)) + { + error = error + "
提单号:" + bill.MBLNO + " 收货人含有中文或双字节字符"; + } + else error += formatlengthError("txt", bill.CONSIGNEE, 35, bill.MBLNO, "收货人", 5, "*", false); + /* + EDI校验,通过和川操作确认应调整最大行数为5行,将最大6行改为5行 + */ + } + + + + + if (string.IsNullOrEmpty(bill.NOTIFYPARTY)) + { + error = error + "
提单号:" + bill.MBLNO + " 通知人不能为空"; + } + else + { + if (StringIsChinese(bill.NOTIFYPARTY)) + { + error = error + "
提单号:" + bill.MBLNO + " 通知人含有中文或双字节字符"; + } + else error += formatlengthError("txt", bill.NOTIFYPARTY, 35, bill.MBLNO, "通知人", 5, "*", false); + /* + EDI校验,通过和川操作确认应调整最大行数为5行,将最大6行改为5行 + */ + } + + + var ctnlist = bill.CTNLIST; + if (ctnlist.Count == 0) { error = error + "
提单号:" + bill.MBLNO + " 集装箱信息不能为空"; }; + + + if (ctnlist.Count != 0) + { + Decimal dlPKGS = 0; + Decimal dlKGS = 0; + Decimal dlCBM = 0; + foreach (var ctn in ctnlist) + { + if (string.IsNullOrEmpty(ctn.CTNALLCODE)) + { error = error + "
提单号:" + bill.MBLNO + " 集装箱箱型EDI代码不能为空"; } + if (string.IsNullOrEmpty(ctn.KINDPKGS_EDI_CODE)) + { error = error + "
提单号:" + bill.MBLNO + " 集装箱包装EDI代码不能为空"; } + + + if ((ctn.CTNALLCODE.IndexOf("RH") > 0 || ctn.CTNALLCODE.IndexOf("RF") > 0) && (bill.CARGOID != "R")) + { + { error = error + "
提单号:" + bill.MBLNO + " 集装箱箱型为冻柜,货类代码请选择冻柜"; } + } + + if (InttrEdi.filetype == "E") + { + + //if (string.IsNullOrEmpty(ctn.CNTRNO)) + //{ error = error + "
提单号:" + bill.MBLNO + " 箱号不能为空"; } + //if (string.IsNullOrEmpty(ctn.SEALNO)) + //{ error = error + "
提单号:" + bill.MBLNO + " 封号不能为空"; } + + if (ctn.KINDPKGS != bill.KINDPKGS) + { error = error + "
提单号:" + bill.MBLNO + " 中的包装类型与集装箱的包装类型不同"; } + dlPKGS += Convert.ToDecimal(ctn.PKGS); + dlKGS += Convert.ToDecimal(ctn.KGS); + dlCBM += Convert.ToDecimal(ctn.CBM); + } + } + if (InttrEdi.filetype == "E") + { + if (dlPKGS != Convert.ToDecimal(bill.PKGS)) + { error = error + "
提单号:" + bill.MBLNO + " 集装箱件数合计数必须等于委托单总件数"; } + if (dlKGS != Convert.ToDecimal(bill.KGS)) + { error = error + "
提单号:" + bill.MBLNO + " 集装箱重量合计数必须等于委托单总重量数"; } + if (dlCBM != Convert.ToDecimal(bill.CBM)) + { error = error + "
提单号:" + bill.MBLNO + " 集装箱尺码合计数必须等于委托单总尺码数"; } + } + } + //太平新Edi接口判断 + if (bill.HSCODE == null || bill.HSCODE == "") + { error = error + "
提单号:" + bill.MBLNO + "HS编码 不能为空"; } + + if (bill.MasterBOLIndicator == null || bill.MasterBOLIndicator == "") + { error = error + "
提单号:" + bill.MBLNO + "Master BOL Indicator 不能为空"; } + + if (bill.BLFRT.IndexOf("FREIGHT COLLECT") > -1)//运费到付 + { + if (bill.ConsigneeEdiCode == null || bill.ConsigneeEdiCode == "") + { error = error + "
提单号:" + bill.MBLNO + "收货人Edi代码 不能为空"; } + } + else + { + if (bill.ShipperEdiCode == null || bill.ShipperEdiCode == "") + { error = error + "
提单号:" + bill.MBLNO + "发货人Edi代码 不能为空"; } + } + + if (bill.SalesRepCode == null || bill.SalesRepCode == "") + { error = error + "
提单号:" + bill.MBLNO + "太平销售的Edi代码 不能为空"; } + + if (bill.BYCOUNTRY == "CANADA") + { + if (bill.ACIHBL == null || bill.ACIHBL == "") + { error = error + "
提单号:" + bill.MBLNO + "ACI HBL 不能为空"; } + + if (bill.S0CC0C == null || bill.S0CC0C == "") + { error = error + "
提单号:" + bill.MBLNO + "S0C C0C 不能为空"; } + } + + if (InttrEdi.filetype == "E") + { + if (bill.BYCOUNTRY == "USA") + { + if (bill.CONTRACTNO == null || bill.CONTRACTNO.ToString().Trim() == "") + { error = error + "
提单号:" + bill.MBLNO + "运费协议号 不能为空"; } + } + } + + + } + return error; + } + #endregion + + #region 生成报文(订舱(filetype=="B"),截单(filetype=="E")) + public static EdiDataResult CreateEdiPIL(EDIBaseModel InttrEdi) + { + var result = new EdiDataResult { Succeeded = false }; + + var estr = ""; + if (InttrEdi.filetype == "E") + { + //2023-03-28 确认需要把截单报文的文件名去掉ESI英文 + //estr = "ESI"; + } + else + { + estr = "EDI"; + } + var SENDCODE = ""; + SENDCODE = InttrEdi.SENDCODE; + // + + string dir = InttrEdi.filerpath + "\\" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + "\\"; + //string filename = + InttrEdi.BSLIST[0].MBLNO + estr + ".pms"; + + //如果是部署linux需要修改路径 + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + dir = dir.Replace("\\", "/"); + + if (!Directory.Exists(dir)) + { + Directory.CreateDirectory(dir); + } + + string filename = dir + InttrEdi.BSLIST[0].MBLNO + estr + ".pms"; + + //if (System.IO.File.Exists(filename)) + //{ + // System.IO.File.Delete(filename); + //} + FileStream f = new FileStream(filename, FileMode.Create); + StreamWriter r = new StreamWriter(f, Encoding.Default); + var icount = 0; + var tempstr = ""; + + #region 00 + //tempstr = "00DOC" + GetSpaceStr("", 22) + GetSpaceStr(SENDCODE, 8) + GetSpaceStr("", 6) + DateTime.Now.ToString("yyyyMMddHHmm") + GetSpaceStr("", 1) + // + portload + portload; + //if (filetype == "E") + // tempstr = tempstr + "4.01"; + //else + // tempstr = tempstr + "PBK"; + //r.WriteLine(GetSpaceStr(tempstr, 250)); + + tempstr = "00";//1//RECORD-ID//M//9(2)//1//2//00 + tempstr += "DOC";//2//Data-type ID//M//X(3)//3//5//DOC=BL, BKG=Booking + tempstr += GetSpaceStr("", 20);//3//File Description//O//X(20)//6//25// + tempstr += GetSpaceStr("", 2);//4//Filler//M//X(2)//26//27//Spaces + tempstr += GetSpaceStr(SENDCODE, 8);//5//Sender-Code//M//X(8)//28//35//Sender/Receiver Code List + tempstr += GetSpaceStr("", 6);//6//Filler//M//X(6)//36//41// + tempstr += DateTime.Now.ToString("yyyyMMddHHmm");//7//File Send time//M//9(12)//42//53//YYYYMMDDHHMM + tempstr += GetSpaceStr("", 1);//8//Filler//M//X(1)//54//54//Spaces + tempstr += InttrEdi.BSLIST[0].PORTLOADID;//9//Sender Port Code//M//X(5)//55//59// + tempstr += InttrEdi.BSLIST[0].PORTLOADID;//10//Receiver Port Code//M//X(5)//60//64// + if (InttrEdi.filetype == "E") + { + tempstr += "4.02";//11//EDI Version//M//X(4) //65//68//Default to "PBK" / esi:4.01 + } + else + { + tempstr += "PBK";//11//EDI Version//M//X(4) //65//68//Default to "PBK" / esi:4.01 + } + tempstr += GetSpaceStr("", 15);//12//Sender Ver Control ID//C//X(15)//69//83//Sender's ASFS/AFMS software version; blank if not applicable + tempstr += GetSpaceStr("", 167);//13//Filler//M//X(167)//84//250//Spaces + r.WriteLine(GetSpaceStr(tempstr, 250)); + #endregion + + foreach (var bill in InttrEdi.BSLIST) + { + icount = icount + 1; + + + + #region 11 + var eta = ""; + if (bill.ETA == "" || bill.ETA == null) + { + eta = DateTime.Now.ToString("yyyyMMdd"); + } + else { eta = bill.ETA.Replace("-", ""); } + var etd = ""; + if (bill.ETD == "" || bill.ETD == null) + { + etd = GetSpaceStr("", 8); + } + else { etd = bill.ETD.Replace("-", ""); } + + //tempstr = "11" + GetSpaceStr("", 1) + GetSpaceStr(bill.VESSELID, 10) + GetSpaceStr(bill.VESSEL, 20) + GetSpaceStr(bill.VOYNO, 8) + eta + etd + // + GetSpaceStr(bill.VESSELID + bill.VOYNO, 12) + eta; + //r.WriteLine(GetSpaceStr(tempstr, 250)); + + tempstr = "11";//1//RECORD-ID//M//9(2)//1//2//11// + tempstr += GetSpaceStr("", 1);//2//Filler//M//X(1)//3//3//Spaces// + if (bill.VOYNO.ToString().Trim().Length < 4) + { + tempstr += GetSpaceStr(bill.VOYNO.ToString().Trim(), 10);//3//Vessel Code//M//X(10)//4//13//和vessel有关的,即field 4和 field 3 都必填 + } + else + { + tempstr += GetSpaceStr(bill.VOYNO.ToString().Trim().Substring(0, 4), 10);//3//Vessel Code//M//X(10)//4//13//和vessel有关的,即field 4和 field 3 都必填 + } + tempstr += GetSpaceStr(bill.VESSEL, 20);//4//Vessel Name//M//X(20)//14//33//和vessel有关的,即field 4和 field 3 都必填 + tempstr += GetSpaceStr("", 8);//5//Voyage No.//M//X(8)//34//41//Alternate Voyage Reference (Commercial voyage)//但是和voyage有关的,即field 5和field 8不用填//不用填 + //tempstr += GetSpaceStr("", 8);//5//Voyage No.//M//X(8)//34//41//Alternate Voyage Reference (Commercial voyage)//不用填 + tempstr += eta;//6//Arrival Date//M//9(8)//42//49//YYYYMMDD (ATA or ETA if ATA not available)// + tempstr += etd;//7//Sailing Date//M//9(8)//50//57//YYYYMMDD (ATD or ETD if ATD not available)// + tempstr += GetSpaceStr("", 12);//8//webCSM Voyage No.//O//X(12)//58//69//webCSM System Voyage Reference//但是和voyage有关的,即field 5和field 8不用填//不要填 + tempstr += eta;//9//Berthing Date//O//9(8)//70//77//YYYYMMDD (ATB or ETB if ATB not available)// + if (bill.VOYNO.ToString().Trim().Length < 5) + { + tempstr += GetSpaceStr("", 12);//10//Export Local Voyage Reference//O//X(12)//78//89//Export Local Voyage in relation to Sender Port(customs/port reporting)//ENHANCEMENT,填写原field 8的内容,报关用 + } + else + { + tempstr += GetSpaceStr(bill.VOYNO.ToString().Trim().Substring(4), 12);//10//Export Local Voyage Reference//O//X(12)//78//89//Export Local Voyage in relation to Sender Port(customs/port reporting)//ENHANCEMENT,填写原field 8的内容,报关用 + } + tempstr += GetSpaceStr("", 12);//11//Import Local Voyage Reference//O//X(12)//90//101//Import Local Voyage in relation to Sender Port(customs/port reporting)//内部航次 + tempstr += GetSpaceStr("", 149);//12//Filler//M//X(149)//102//250//Spaces// + r.WriteLine(GetSpaceStr(tempstr, 250)); + #endregion + + //2023-02-23 测试订舱这里开头加“+”经韩工确认使用此规则 + #region 12 + tempstr = "12";//1 //RECORD-ID//M//9(2)//1 //2 //12 + if (InttrEdi.filetype == "E") + { + tempstr += GetSpaceStr(bill.MBLNO, 20);//2 //webCSM Booking Reference//M//X(20)//3 //22 //webCSM System Job Reference如果需要,填写原field 3的custom ref//bill.ORDERNO + } + else + { + tempstr += GetSpaceStr("+", 20);//2 //webCSM Booking Reference//M//X(20)//3 //22 //webCSM System Job Reference如果需要,填写原field 3的custom ref + } + tempstr += GetSpaceStr(bill.MBLNO, 20);//3 //webCSM BL Number//C//X(20)//23 //42 //Pre-assigned BKG Refmandtory (PIL's bkg ref nbr),预放提单号 + if (bill.PORTLOADID == "CNTAO") + { + tempstr += GetSpaceStr(bill.MBLNO, 20);//4 //Original Bill of Lading//C//X(20)//43 //62 //webCSM External B/L Reference, only if external BL is used + } + else + { + tempstr += GetSpaceStr("", 20);//4 //Original Bill of Lading//C//X(20)//43 //62 //webCSM External B/L Reference, only if external BL is used + } + + tempstr += GetSpaceStr("", 5);//5 //Filler//M//X(5)//63 //67 //Spaces + tempstr += GetSpaceStr(bill.PORTDISCHARGEID, 5);//6 //Port of Discharge//M//X(5)//68 //72 //Next Discharge Port for the voyage generated + tempstr += GetSpaceStr(bill.PORTLOADID, 5);//7 //Port of Loading//M//X(5)//73 //77 //Load Port for the voyage generated + tempstr += "FF";//8 //BL Movement Type//M//X(2)//78 //79 //F:FCL, L:LCL, M:MTY, T:TFCL, Y:TMTY, eg. FF=FCL/FCL + tempstr += "PP";//9 //Movement Terms//O//X(2)//80 //81 //D:Door, P:Port, R:Ramp, eg. DD=Door/Door + tempstr += GetSpaceStr(GetPILServiceStr(bill.SERVICE), 2);//10 //Freight Terms//M//X(2)//82 //83 //Y:CY, F:CFS, I:FI, O:FO, D:Door, K:Hook, L:Tackle eg. YY=CY/CY + tempstr += GetSpaceStr("", 3);//11 //Filler//M//X(3)//84 //86 //Spaces + if (bill.BLFRT.IndexOf("FREIGHT COLLECT") > -1) + { + tempstr += "C";//12 //BL Prepaid/Collect//C//X(1)//87 //87 //P-Prepaid, C-Collect for BOF charge, mandatory if Rec 61 exists//mandtory,到付预付必填,第三地填C + } + else if (bill.BLFRT.IndexOf("PREPAID") > -1)//预付 + { + tempstr += "P";//12 //BL Prepaid/Collect//C//X(1)//87 //87 //P-Prepaid, C-Collect for BOF charge, mandatory if Rec 61 exists//mandtory,到付预付必填,第三地填C + } + else + { + tempstr += "C";//12 //BL Prepaid/Collect//C//X(1)//87 //87 //P-Prepaid, C-Collect for BOF charge, mandatory if Rec 61 exists//mandtory,到付预付必填,第三地填C + } + tempstr += "N";//13 //BL Tranship Flag//M//X(1)//88 //88 //Y or N + tempstr += "N";//14 //BL All Empty CTN Flag//M//X(1)//89 //89 //Y or N + if (bill.CLOSINGDATE == "") + { + tempstr += GetSpaceStr("", 8);//15 //Loading Date//C//X(8)//90 //97 //YYYYMMDD, mandatory if record submitted is BL + } + else + { + tempstr += Convert.ToDateTime(bill.CLOSINGDATE).ToString("yyyyMMdd");//15 //Loading Date//C//X(8)//90 //97 //YYYYMMDD, mandatory if record submitted is BL + } + if (bill.PORTLOADID == "CNSHA" && InttrEdi.filetype != "E") + { + tempstr += GetSpaceStr("", 20);//16 //Original_reference//C//X(20)//98 //117 //webCSM Alternate Booking Reference, only if alt booking ref is used + } + else + { + tempstr += GetSpaceStr(bill.MBLNO, 20);//16 //Original_reference//C//X(20)//98 //117 //webCSM Alternate Booking Reference, only if alt booking ref is used + } + tempstr += GetSpaceStr("", 20);//17 //Bkg Pty Reference//O//X(20)//118 //137 //webCSM Bkg Party Reference + tempstr += "F";//18 //Booking_Party_indicator//M//X(1)//138 //138 //D-Deciding Pty, N-Notify Pty, C-Consignee, S-Shipper, F-Forwarder + tempstr += GetSpaceStr("", 20);//19 //Part MBL//C//X(20)//139 //158 //Not for part BL purpose + tempstr += GetSpaceStr("", 20);//20 //BL Paid By//C//X(20)//159 //178 //Freight Absorbed by BL Reference, only if BL's frt is paid by other BL + tempstr += GetSpaceStr("", 12);//21 //Customs Bill of Lading//C//X(12)//179 //190 //Customs BL Reference (12 char) - only for US/CA Customs requirement + if (bill.ETD == "") + { + tempstr += GetSpaceStr("", 8);//22 //Booking Date//M//X(8)//191 //198 //YYYYMMDD + } + else + { + tempstr += Convert.ToDateTime(bill.ETD).ToString("yyyyMMdd");//22 //Booking Date//M//X(8)//191 //198 //YYYYMMDD + } + //tempstr += eta;//23 //Slot Owner//M//X(3)//199 //201 // + tempstr += GetSpaceStr("PI", 3);//24 //Cntr Operator//M//X(3)//202 //204 // + tempstr += GetSpaceStr("PI", 3);//25 //Filler//M//X(46)//205 //250 //Spaces + r.WriteLine(GetSpaceStr(tempstr, 250)); + #endregion + + #region 13 + tempstr = "13";//1 //RECORD-ID//M//9(2)//1 //2 //13 + tempstr += GetSpaceStr("", 3);//2 //Filler//M//X(3)//3 //5 //Spaces + tempstr += GetSpaceStr(bill.PORTLOADID, 5);//3 //Port of Origin//M//X(5)//6 //10 //refer Port Code (Place of receipt) + tempstr += GetSpaceStr(bill.PORTDISCHARGEID, 5);//4 //Port of Discharge//M//X(5)//11 //15 //refer Port code (Port of Discharge - final) + tempstr += GetSpaceStr("", 5);//5 //Port of Trans//C//X(5)//16 //20 //refer Port code (1st T/S port), only if Transshipment involved + tempstr += GetSpaceStr(bill.PLACEDELIVERYID, 5);//6 //Final Destination//M//X(5)//21 //25 //refer Port Code (Place of delivery) + tempstr += GetSpaceStr("", 20);//7 //Final Destination (Name)//M//X(20)//26 //45 // + tempstr += GetSpaceStr("", 10);//8 //Route Code//O//X(10)//46 //55 //webCSM Route Code (out from webCSM only) + tempstr += GetSpaceStr("", 45);//9 //Filler//M//X(45)//56 //100 //Spaces + tempstr += GetSpaceStr("", 5);//10 //Transhipment Port 1//C//X(5)//101 //105 //1st Transhipment Port, only if Transshipment involved + tempstr += GetSpaceStr("", 5);//11 //Transhipment Port 2//C//X(5)//106 //110 //2nd Transhipment Port, only if 2nd Transshipment involved + tempstr += GetSpaceStr("", 5);//12 //Transhipment Port 3//C//X(5)//111 //115 //3rd Transhipment Port, only if 3rd Transshipment involved + //eta = GetPortEDICode(bill.PORTDISCHARGEID, "PIL").Substring(2, 3); + //if (eta == "SSZ" || eta == "BUE" || eta == "MVD" || eta == "PNG" || eta == "NVT" || eta == "RIO") + //{ + // tempstr += "U";//13 //Master BOL Indicator//M//X(1)//116 //116 //1=Carrier filing HBL, 2=Self filing HBL, 3=Not Applicable/Straight bl//mandtory,1/船公司发HBL,2/自己发,3/无HBL。美国线必填,加拿大线填在record 73 + + //} + //else + //{ + // tempstr += "N";//13 //Master BOL Indicator//M//X(1)//116 //116 //1=Carrier filing HBL, 2=Self filing HBL, 3=Not Applicable/Straight bl//mandtory,1/船公司发HBL,2/自己发,3/无HBL。美国线必填,加拿大线填在record 73 + + //} + tempstr += bill.MasterBOLIndicator;//13 //Master BOL Indicator//M//X(1)//116 //116 //1=Carrier filing HBL, 2=Self filing HBL, 3=Not Applicable/Straight bl//mandtory,1/船公司发HBL,2/自己发,3/无HBL。美国线必填,加拿大线填在record 73 + + tempstr += GetSpaceStr("", 3);//14 //Job Status //O//X(3)//117 //119 //webCSM Job Status (out from webCSM only) + tempstr += GetSpaceStr("", 3);//15 //B/L Status//O//X(3)//120 //122 //webCSM B/L Status (out from webCSM only) + tempstr += GetSpaceStr("", 1);//16 //Export Haulage//O//X(1)//123 //123 //M:Merchant Haulage, C:Carrier Haulage + tempstr += GetSpaceStr("", 1);//17 //Import Haulage//O//X(1)//124 //124 //M:Merchant Haulage, C:Carrier Haulage + tempstr += GetSpaceStr("", 35);//18 //EDI301 Reference//C//X(35)//125 //159 //Shipping Portal's booking reference (eg. GT Nexus, INTTRA) + tempstr += GetSpaceStr("", 91);//19 //Filler//M//X(91)//160 //250 //Spaces + r.WriteLine(GetSpaceStr(tempstr, 250)); + #endregion + + if (InttrEdi.filetype == "E") + { + #region 15 + tempstr = "15";//1//RECORD-ID//M//9(2)//1//2//15 + tempstr += GetSpaceStr(bill.PLACERECEIPT, 50);//2//Origin Freeform//O//X(50)//3//52//BL location text for Port of Origin//收货地 + tempstr += GetSpaceStr(bill.PORTLOAD, 50);//3//Load Port Freeform//O//X(50)//53//102//BL location text for Port of Load//装货港 + tempstr += GetSpaceStr(bill.PORTDISCHARGE, 50);//4//Discharge Port Freeform//O//X(50)//103//152//BL location text for Port of Discharge//卸货港 + /* + * 2023-04-04 参考韩工最新代码调整取值 + tempstr += GetSpaceStr(bill.PLACEDELIVERY, 50);//5//Destination Freeform//O//X(50)//153//202//BL location text for Port of Delivery//交货地点 + */ + tempstr += GetSpaceStr(bill.DESTINATION, 50); + tempstr += GetSpaceStr(bill.VOYNO, 30);//6//Freeform Voyage//O//X(30)//203//232//BL voyage freeform/ + /* + * 2023-04-04 参考韩工最新代码调整去掉赋值航次号 + tempstr += GetSpaceStr(bill.VOYNO, 30);//6//Freeform Voyage//O//X(30)//203//232//BL voyage freeform//航次 + */ + tempstr += GetSpaceStr("", 30);//6//Freeform Voyage//O//X(30)//203//232//BL voyage freeform//航次 + tempstr += GetSpaceStr("", 18);//7//Filler//M//X(18)//233//250//Spaces + r.WriteLine(GetSpaceStr(tempstr, 250)); + #endregion + } + + #region 16 + tempstr = "16";//1//RECORD-ID//M//9(2)//1//2//16 + tempstr += GetSpaceStr("", 3);//2//Filler//M//X(3)//3//5//Spaces + //if (bill.BLFRT.IndexOf("FREIGHT COLLECT") > -1)//运费到付 + //{ + // tempstr += GetSpaceStr("", 10);//3//Shipper Code//O//X(10)//6//15//webcsm Partner Code//mandtory for CIF shpts,预付必填 + //} + //else + //{ + tempstr += GetSpaceStr(bill.ShipperEdiCode, 10);//3//Shipper Code//O//X(10)//6//15//webcsm Partner Code//mandtory for CIF shpts,预付必填 + //} + tempstr += GetSpaceStr("", 3);//4//Shipper Code//O//X(3)//16//18//webcsm Partner Subcode + tempstr += GetSpaceStr("", 4);//5//Filler//M//X(4)//19//22//Spaces + var Shipping = ""; + Shipping = bill.SHIPPER; + List ShippingList = formatlengthStr(Shipping, 35); + for (var i = 0; i < ShippingList.Count; i++) + { + /* + EDI校验,通过和川操作确认应调整最大行数为5行,将最大6行改为5行 + */ + if (i <= 5) + { + tempstr += GetSpaceStr(ShippingList[i], 35);//6//Shipper-Item (1)//M//X(35)//23//57//Shipper Name, Address line 1 + } + } + //6//Shipper-Item (1)//M//X(35)//23//57//Shipper Name, Address line 1 + //7//Shipper-item (2)//M//X(35)//58//92//Shipper Name, Address line 2 + //8//Shipper-item (3)//M//X(35)//93//127//Shipper Name, Address line 3 + //9//Shipper-item (4)//M//X(35)//128//162//Shipper Name, Address line 4 + //10//Shipper-item (5)//M//X(35)//163//197//Shipper Name, Address line 5 + //11//Shipper-item (6)//M//X(35)//198//232//Shipper Name, Address line 6 + //12//SCAC Code//O//X(4)//233//236// + //13//Filler//M//X(14)//237//250//Spaces + r.WriteLine(GetSpaceStr(tempstr, 250)); + #endregion + + #region 17 + tempstr = "17";//1 //RECORD-ID//M//9(2)//1 //2 //17 + tempstr += GetSpaceStr("", 3);//2 //Filler//M//X(3)//3 //5 //Spaces + //if (bill.BLFRT == "FREIGHT PREPAID") + //{ + // tempstr += GetSpaceStr(agent, 10);//3 //Booking Party Code//O//X(10)//6 //15 //webcsm Partner Code + //} + //else + //{ + // tempstr += GetSpaceStr(cagent, 10);//3 //Booking Party Code//O//X(10)//6 //15 //webcsm Partner Code + //} + if (bill.BLFRT.IndexOf("FREIGHT PREPAID") > -1)//运费预付 + { + tempstr += GetSpaceStr(bill.ShipperEdiCode, 10);//3 //Booking Party Code//O//X(10)//6 //15 //webcsm Partner Code + } + else + { + tempstr += GetSpaceStr(bill.ConsigneeEdiCode, 10);//3//Shipper Code//O//X(10)//6//15//webcsm Partner Code//mandtory for CIF shpts,预付必填 + } + if (bill.PORTLOADID == "CNTAO" && InttrEdi.filetype != "E") + { + tempstr += GetSpaceStr("", 3);//4 //Booking Party Code//O//X(3)//16 //18 //webcsm Partner Subcode//mandtory,订舱单位代码(customer code) + } + else + { + tempstr += GetSpaceStr("001", 3);//4 //Booking Party Code//O//X(3)//16 //18 //webcsm Partner Subcode//mandtory,订舱单位代码(customer code) + } + tempstr += GetSpaceStr("", 4);//5 //Filler//M//X(4)//19 //22 //Spaces + int iLs = (!string.IsNullOrWhiteSpace(InttrEdi.ForWarderName) ? InttrEdi.ForWarderName.Length : 0) / 35; + int iLs2 = (!string.IsNullOrWhiteSpace(InttrEdi.ForWarderName) ? InttrEdi.ForWarderName.Length : 0) % 35; + int n = 0; + for (int i = 0; i < iLs; i++) + { + tempstr += GetSpaceStr(InttrEdi.ForWarderName.Substring(i * 35, 35), 35);//6 //Booking Party-Item (1)//M//X(35)//23 //57 //Booking Party Name, Address line 1; + n = i + 1; + } + if (iLs < 6) + { + if (iLs2 > 0) + { + tempstr += GetSpaceStr(InttrEdi.ForWarderName.Substring(n * 35), 35);//6 //Booking Party-Item (1)//M//X(35)//23 //57 //Booking Party Name, Address line 1-6; + } + if ((iLs + 1) < 6) + { + for (int i = 0; i < (6 - iLs - 1); i++) + { + tempstr += GetSpaceStr("", 35);//6 //Booking Party-Item (1)//M//X(35)//23 //57 //Booking Party Name, Address line 6; + } + } + } + tempstr += GetSpaceStr("", 4);//12 //SCAC Code//O//X(4)//233 //236 // + tempstr += GetSpaceStr("", 14);//13 //Filler//M//X(14)//237 //250 //Spaces + tempstr = GetSpaceStr(tempstr, 236); + + /* + 2023-05-31 经过手工测试PIL订舱报文,这里应该延用东胜的报文逻辑取CNPT No + + if (bill.BLFRT.IndexOf("FREIGHT PREPAID") > -1)//运费预付 + { + tempstr += GetSpaceStr(bill.ShipperEdiCode, 10);//3 //Booking Party Code//O//X(10)//6 //15 //webcsm Partner Code + } + else + { + tempstr += GetSpaceStr(bill.ConsigneeEdiCode, 10);//3//Shipper Code//O//X(10)//6//15//webcsm Partner Code//mandtory for CIF shpts,预付必填 + } + */ + tempstr += GetSpaceStr(bill.CNPTNo, 10);//3 //Booking Party Code//O//X(10)//6 //15 //webcsm Partner Code + + r.WriteLine(GetSpaceStr(tempstr, 250)); + #endregion + + #region 18 + + var contractno = bill.CONTRACTNO; + + tempstr = "18";//1 //RECORD-ID//M//9(2)//1 //2 //18 + tempstr += GetSpaceStr("", 3);//2 //Filler//M//X(3)//3 //5 //Spaces + //if (bill.CONTRACTNO == "") + //{ + // if (bill.BLFRT == "FREIGHT PREPAID") + // { + // tempstr += GetSpaceStr(agent, 10);//3 //Deciding Party Code//O//X(10)//6 //15 //webcsm Partner Code//mandtory (DUM000001),填RFA;美国线的S/C或者TAA填写在record 74,美国线留空 + // } + // else + // { + // tempstr += GetSpaceStr(cagent, 10);//3 //Deciding Party Code//O//X(10)//6 //15 //webcsm Partner Code//mandtory (DUM000001),填RFA;美国线的S/C或者TAA填写在record 74,美国线留空 + // } + //} + //else + //{ + // tempstr += GetSpaceStr(bill.CONTRACTNO, 10);//3 //Deciding Party Code//O//X(10)//6 //15 //webcsm Partner Code + //} + if (bill.BYCOUNTRY == "USA") + { + tempstr += GetSpaceStr("", 11);//3 //Deciding Party Code//O//X(10)//6 //15 //webcsm Partner Code//mandtory (DUM000001),填RFA;美国线的S/C或者TAA填写在record 74,美国线留空 + } + else + { + if (string.IsNullOrWhiteSpace(contractno)) + { + tempstr += GetSpaceStr("DUM000001", 11);//3 //Deciding Party Code//O//X(10)//6 //15 //webcsm Partner Code//mandtory (DUM000001),填RFA;美国线的S/C或者TAA填写在record 74,美国线留空 + } + else + { + tempstr += GetSpaceStr(contractno, 11);//3 //Deciding Party Code//O//X(10)//6 //15 //webcsm Partner Code + } + } + if (bill.PORTLOADID == "CNTAO" && InttrEdi.filetype != "E") + { + tempstr += GetSpaceStr("", 2);//4 //Deciding Party Code//O//X(3)//16 //18 //webcsm Partner Subcode + } + else + { + tempstr += GetSpaceStr("01", 2);//4 //Deciding Party Code//O//X(3)//16 //18 //webcsm Partner Subcode + } + tempstr += GetSpaceStr("", 1);//5 //Special Rate Indicator//C//X(1)//19 //19 //Denote special account with fixed exchange rates (out from webCSM only) + tempstr += GetSpaceStr("", 3);//6 //Filler//M//X(3)//20 //22 //Spaces + Shipping = ""; + if (bill.BLFRT == "FREIGHT PREPAID") + { + Shipping = bill.SHIPPER; + } + else + { + Shipping = bill.CONSIGNEE; + } + ShippingList = formatlengthStr(Shipping, 35); + for (var i = 0; i < ShippingList.Count; i++) + { + if (i <= 6) + { + tempstr += GetSpaceStr(ShippingList[i], 35);//7 //Deciding-Item (1)//M//X(35)//23 //57 //Deciding Party Name, Address line 1 + } + } + + + //var iLS = ShippingList.Count - 6; + //if (iLS > 0) + //{ + // for (var i = 0; i < iLS; i++) + // { + // tempstr += GetSpaceStr("", 35);//7 //Deciding-Item (1)//M//X(35)//23 //57 //Deciding Party Name, Address line 1 + // } + //} + //7 //Deciding-Item (1)//M//X(35)//23 //57 //Deciding Party Name, Address line 1 + //8 //Deciding-item (2)//M//X(35)//58 //92 //Deciding Party Name, Address line 2 + //9 //Deciding-item (3)//M//X(35)//93 //127 //Deciding Party Name, Address line 3 + //10 //Deciding-Item (4)//M//X(35)//128 //162 //Deciding Party Name, Address line 4 + //11 //Deciding-item (5)//M//X(35)//163 //197 //Deciding Party Name, Address line 5 + //12 //Deciding-item (6)//M//X(35)//198 //232 //Deciding Party Name, Address line 6 + tempstr = GetSpaceStr(tempstr, 232); + tempstr += GetSpaceStr("", 4);//12 //SCAC Code//O//X(4)//233 //236 // + tempstr += GetSpaceStr(bill.SalesRepCode, 14);//13 //Filler//M//X(14)//237 //250 //Spaces + r.WriteLine(GetSpaceStr(tempstr, 250)); + #endregion + + #region 21 + tempstr = "21";//1 //RECORD-ID//M//9(2)//1 //2 //21 + tempstr += GetSpaceStr("", 3);//2 //Filler//M//X(3)//3 //5 //Spaces + if (bill.BLFRT.IndexOf("FREIGHT COLLECT") > -1)//运费到付 + { + tempstr += GetSpaceStr(bill.ConsigneeEdiCode, 10);//3 //Consignee Code//O//X(10)//6 //15 //webcsm Partner Code//mandtory for FOB shpts,收货人代码,到付必填。跟客服要 + } + else + { + tempstr += GetSpaceStr("", 10);//3 //Consignee Code//O//X(10)//6 //15 //webcsm Partner Code//mandtory for FOB shpts,收货人代码,到付必填 + } + tempstr += GetSpaceStr("", 3);//4 //Consignee Code//O//X(3)//16 //18 //webcsm Partner Subcode + tempstr += GetSpaceStr("", 4);//5 //Filler//M//X(4)//19 //22 //Spaces + Shipping = ""; + Shipping = bill.CONSIGNEE; + ShippingList = formatlengthStr(Shipping, 35); + for (var i = 0; i < ShippingList.Count; i++) + { + /* + EDI校验,通过和川操作确认应调整最大行数为5行,将最大6行改为5行 + */ + if (i <= 5) + { + tempstr += GetSpaceStr(ShippingList[i], 35);//6 //Consignee item - (1)//M//X(35)//23 //57 //Consignee Name, Address line 1 + } + } + //6 //Consignee item - (1)//M//X(35)//23 //57 //Consignee Name, Address line 1 + //7 //Consignee item - (2)//M//X(35)//58 //92 //Consignee Name, Address line 2 + //8 //Consignee item - (3)//M//X(35)//93 //127 //Consignee Name, Address line 3 + //9 //Consignee item - (4)//M//X(35)//128 //162 //Consignee Name, Address line 4 + //10 //Consignee item - (5)//M//X(35)//163 //197 //Consignee Name, Address line 5 + //11 //Consignee item - (6)//M//X(35)//198 //232 //Consignee Name, Address line 6 + //12 //SCAC Code//O//X(4)//233 //236 // + //13 //Filler//M//X(14)//237 //250 //Spaces + r.WriteLine(GetSpaceStr(tempstr, 250)); + #endregion + + #region 26 + tempstr = "26";//1 //RECORD-ID//M//9(2)//1 //2 //26 + tempstr += GetSpaceStr("", 2);//2 //Filler//M//X(2)//3 //4 //Spaces + tempstr += "1";//3 //Notify Party Count//M//9(1)//5 //5 //I = 1 to 3 notify party + tempstr += GetSpaceStr("", 10);//4 //Notify Code//O//X(10)//6 //15 //webcsm Partner Code + tempstr += GetSpaceStr("", 3);//5 //Notify Code//O//X(3)//16 //18 //webcsm Partner Subcode + tempstr += GetSpaceStr("", 4);//6 //Filler//M//X(4)//19 //22 //Spaces + Shipping = ""; + Shipping = bill.NOTIFYPARTY; + ShippingList = formatlengthStr(Shipping, 35); + for (var i = 0; i < ShippingList.Count; i++) + { + /* + EDI校验,通过和川操作确认应调整最大行数为5行,将最大6行改为5行 + */ + if (i <= 5) + { + tempstr += GetSpaceStr(ShippingList[i], 35);//7 //Notify Field-(1)//M//X(35)//23 //57 //Notify Party Name, Address line 1 + } + } + //7 //Notify Field-(1)//M//X(35)//23 //57 //Notify Party Name, Address line 1 + //8 //Notify Field-(2)//M//X(35)//58 //92 //Notify Party Name, Address line 2 + //9 //Notify Field-(3)//M//X(35)//93 //127 //Notify Party Name, Address line 3 + //10 //Notify Field-(4)//M//X(35)//128 //162 //Notify Party Name, Address line 4 + //11 //Notify Field-(5)//M//X(35)//163 //197 //Notify Party Name, Address line 5 + //12 //Notify Field-(6)//M//X(35)//198 //232 //Notify Party Name, Address line 6 + //12 //SCAC Code//O//X(4)//233 //236 // + //13 //Filler//M//X(14)//237 //250 //Spaces + r.WriteLine(GetSpaceStr(tempstr, 250)); + #endregion + + var soc = "N"; + if (bill.ISCONTAINERSOC) + { + soc = "S"; + } + List ctnsumlist = new List(); + foreach (var ctn in bill.CTNLIST) + { + var isfind = false; + ctnsumlist.ForEach(i => + { + if (i.CTNALLCODE == ctn.CTNALLCODE) + { + i.CTNNUM = i.CTNNUM + ctn.CTNNUM; + i.KGS = i.KGS + ctn.KGS; + if (ctn.CTNALLCODE.IndexOf("40") > 0) + i.TEU = i.TEU + ctn.CTNNUM * 2; + else + i.TEU = i.TEU + ctn.CTNNUM * 1; + i.PKGS = i.PKGS + ctn.PKGS; + i.CBM = i.CBM + ctn.CBM; + i.CTNNUM = i.CTNNUM + ctn.CTNNUM; + isfind = true; + } + }); + if (!isfind) + { + var ctnnum = new SeaExportCtnEDIBaseModel(); + ctnnum.CTNALLCODE = ctn.CTNALLCODE; + ctnnum.KGS = ctn.KGS; + if (ctn.CTNALLCODE.IndexOf("40") > 0) + ctnnum.TEU = ctn.CTNNUM * 2; + else + ctnnum.TEU = ctn.CTNNUM * 1; + ctnnum.PKGS = ctn.PKGS; + ctnnum.CBM = ctn.CBM; + ctnnum.CTNNUM = ctn.CTNNUM; + ctnsumlist.Add(ctnnum); + } + } + + var ctnline = 1; + foreach (var ctn in ctnsumlist) + { + if (InttrEdi.filetype == "E") + { + #region ESI + #region 41 + tempstr = "41";//1 //RECORD-ID//M//9(2)//1 //2 //41 + tempstr += GetSpaceStr("", 3);//2 //Filler//M//X(3)//3 //5 //Spaces + tempstr += GetSpaceStr(ctnline.ToString(), 3, "0");//3 //Cargo Sequence#//M//9(3)//6 //8 //001 to 999 (line-items) + if (bill.HSCODE.ToString().Length > 6) + { + tempstr += GetSpaceStr(bill.HSCODE.ToString().Substring(0, 6), 9);//4 //Commodity Code//M//X(9)//9 //17 //6 Digits HS CODE//mandtory,Hscode,必填,商品编码前6位 + } + else + { + tempstr += GetSpaceStr(bill.HSCODE.ToString(), 9);//4 //Commodity Code//M//X(9)//9 //17 //6 Digits HS CODE//mandtory,Hscode,必填,商品编码前6位 + } + tempstr += "Y";//5 //BL Override//M//X(1)//18 //18 //Y or N, Y=lumpsum weights used, (out from webCSM only) + tempstr += GetSpaceStr(ctn.CTNNUM.ToString(), 6, "0");//6 //No of packages/Containers//M//9(6)//19 //24 //Number of Containers for the cargo line + tempstr += GetSpaceStr(ctn.TEU.ToString(), 4, "0");//7 //TEU Utilisation//C//9(4)//25 //28 //Actual TEU utilised, eg. OOG's slot kill or Flatrack bundled units + tempstr += GetSpaceStr((ctn.KGS * 1000).ToString("0.###"), 11, "0");//8 //Cargo Gross Weight//C//9(8)v999//29 //39 //Mandatory, except for Empties + tempstr += GetSpaceStr("", 11, "0");//9 //Cargo Nett Weight//C//9(8)v999//40 //50 //Mandatory, except for Empties + tempstr += GetSpaceStr((ctn.CBM * 1000).ToString("0.###"), 10, "0");//10 //Cargo Gross Measurement//C//9(7)v999//51 //60 //Mandatory, except for Empties + tempstr += GetSpaceStr((ctn.CBM * 1000).ToString("0.###"), 10, "0");//11 //Cargo Nett Measurement//C//9(7)v999//61 //70 //Mandatory, except for Empties + tempstr += GetSpaceStr(bill.GOODSNAME, 48);//12 //Commodity Name//O//X(48)//71 //118 // + //tempstr += GetSpaceStr(GetGOODEDICode(bill.GOODSNAME), 4);//13 //webcsm Commodity Code//O//X(4)//119 //122 //webCSM Standard Commodity Code + tempstr += GetSpaceStr("", 4);//13 //webcsm Commodity Code//O//X(4)//119 //122 //webCSM Standard Commodity Code + tempstr += GetSpaceStr(ctn.CTNALLCODE, 4);//14 //webcsm Package Code//M//X(4)//123 //126 //eg 20GP, 40GP etc. + tempstr += "KGM";//15 //UOM Weight//M//X(3)//127 //129 //Default to METRIC = KGM + tempstr += "MTQ";//16 //UOM Measurement//M//X(3)//130 //132 //Default to METRIC = MTQ + tempstr += GetSpaceStr(soc, 1);//17 //Equipment Flag //M//X(1)//133 //133 //Y:COC cntr required, N:cntr not required, S:SOC//mandtory,只要有SOC箱子就要填S + tempstr += GetSpaceStr("", 117);//18 //Filler//M//X(117)//134 //250 //Spaces + r.WriteLine(GetSpaceStr(tempstr, 250)); + #endregion + + #region 44 + if (ctnline == 1) + { + Shipping = bill.MARKS; + ShippingList = formatlengthStr(Shipping, 20); + for (var i = 0; i < Math.Ceiling(Convert.ToDecimal(Convert.ToDecimal(ShippingList.Count) / Convert.ToDecimal(12))); i++) + { + tempstr = "44";//1 //RECORD-ID//M//9(2)//1 //2 //44 + tempstr += GetSpaceStr("", 3);//2 //Filler//M//X(3)//3 //5 //Spaces + tempstr += GetSpaceStr(ctnline.ToString(), 3, "0");//3 //Cargo Sequence No#//M//9(3)//6 //8 //001 to 999 (line-items) + for (var z = 0; z < 12; z++) + { + if ((i * 12 + z) < ShippingList.Count) + { + tempstr += GetSpaceStr(ShippingList[i * 12 + z], 20);//4 //Mark-no-(1)//O//X(20)//9 //28 + } + } + //4 //Mark-no-(1)//O//X(20)//9 //28 // + //5 //Mark-no-(2)//O//X(20)//29 //48 // + //6 //Mark-no-(3)//O//X(20)//49 //68 // + //7 //Mark-no-(4)//O//X(20)//69 //88 // + //8 //Mark-no-(5)//O//X(20)//89 //108 // + //9 //Mark-no-(6)//O//X(20)//109 //128 // + //10 //Mark-no-(7)//O//X(20)//129 //148 // + //11 //Mark-no-(8)//O//X(20)//149 //168 // + //12 //Mark-no-(9)//O//X(20)//169 //188 // + //13 //Mark-no-(10)//O//X(20)//189 //208 // + //14 //Mark-no-(11)//O//X(20)//209 //228 // + //15 //Mark-no-(12)//O//X(20)//229 //248 // + //16 //Filler//M//X(2)//249 //250 //Spaces + r.WriteLine(GetSpaceStr(tempstr, 250)); + } + } + #endregion + + #region 47 + if (ctnline == 1) + { + Shipping = bill.DESCRIPTION; + ShippingList = formatlengthStr(Shipping, 30); + for (var i = 0; i < Math.Ceiling(Convert.ToDecimal(Convert.ToDecimal(ShippingList.Count) / Convert.ToDecimal(8))); i++) + { + tempstr = "47";//1 //RECORD-ID//M//9(2)//1 //2 //47 + tempstr += GetSpaceStr("", 3);//2 //Filler//M//X(3)//3 //5 //Spaces + tempstr += GetSpaceStr(ctnline.ToString(), 3, "0");//3 //Cargo Sequence No#//M//9(3)//6 //8 //001 to 999 (line-items) + for (var z = 0; z < 8; z++) + { + if ((i * 8 + z) < ShippingList.Count) + { + tempstr += GetSpaceStr(ShippingList[i * 8 + z], 30);//4 //Cargo Description- (1)//O//X(30)//9 //38 // + } + } + //4 //Cargo Description- (1)//O//X(30)//9 //38 // + //5 //Cargo Description- (2)//O//X(30)//39 //68 // + //6 //Cargo Description- (3)//O//X(30)//69 //98 // + //7 //Cargo Description- (4)//O//X(30)//99 //128 // + //8 //Cargo Description- (5)//O//X(30)//129 //158 // + //9 //Cargo Description- (6)//O//X(30)//159 //188 // + //10 //Cargo Description- (7)//O//X(30)//189 //218 // + //11 //Cargo Description- (8)//O//X(30)//219 //248 // + //12 //Filler//M//X(2)//249 //250 //Spaces + r.WriteLine(GetSpaceStr(tempstr, 250)); + } + } + #endregion + + + var m = 1; + foreach (var ctndetail in bill.CTNLIST) + { + if (ctndetail.CTNALLCODE == ctn.CTNALLCODE) + { + if (string.IsNullOrWhiteSpace(ctndetail.CTNSTATUS)) ctndetail.CTNSTATUS = "F"; + + if (!string.IsNullOrWhiteSpace(ctndetail.CNTRNO)) + { + #region 51 + tempstr = "51";//1//RECORD-ID//M//9(2)//1//2//51 + tempstr += GetSpaceStr("", 3);//2//Filler//M//X(3)//3//5//Spaces + tempstr += GetSpaceStr(ctnline.ToString(), 3, "0");//3//Cargo Sequence No#//M//9(3)//6//8//001 to 999 (line-items) + tempstr += GetSpaceStr(m.ToString(), 3, "0");//4//Equipment Sequence No//M//9(3)//9//11//001 to 999 + tempstr += GetSpaceStr(ctndetail.CNTRNO, 11);//5//Container No//M//X(11)//12//22//Container Number + if (bill.ISCONTAINERSOC) + { + tempstr += "Y";//6//Container SOC//M//X(1)//23//23//Y or N + } + else + { + tempstr += "N";//6//Container SOC//M//X(1)//23//23//Y or N + } + tempstr += ctn.CTNALLCODE;//7//Cntr Size/type code//M//X(4)//24//27//ISO Size/type eg 2200 + tempstr += ctndetail.CTNSTATUS;//8//Cntr Loading Status//M//X(1)//28//28//F-Full, P-Part, E-Empty + tempstr += GetSpaceStr("", 3);//9//Cntr Operator//O//X(3)//29//31// + tempstr += GetSpaceStr("", 3);//10//UOM Weight//M//X(3)//32//34//Default to METRIC = KGM + tempstr += GetSpaceStr("", 3);//11//UOM Measurement//M//X(3)//35//37//Default to METRIC = MTQ + tempstr += GetSpaceStr("", 9);//12//Filler//M//X(9)//38//46//Spaces + tempstr += GetSpaceStr(ctndetail.PKGS.ToString(), 6, "0");//13//Cntr No of Packages//O//9(6)//47//52//Number of Packages in the Container + //tempstr += GetSpaceStr(ctndetail.KINDPKGS, 8);//14//Cntr Kind of Packages//O//X(8)//53//60//Package Description (limited to 8 characters) + tempstr += GetSpaceStr(ctndetail.KINDPKGS_EDI_CODE, 8);//14//Cntr Kind of Packages//O//X(8)//53//60//Package Description (limited to 8 characters) + tempstr += GetSpaceStr((ctndetail.KGS * 1000).ToString("0.###"), 9, "0");//15//Cntr Cargo Gross Weight//O//9(6)v999//61//69//Cargo Gross Weight per the container unit + tempstr += GetSpaceStr("", 9, "0");//16//Cntr Tare Weight//O//9(6)v999//70//78//Container Tare Weight + tempstr += GetSpaceStr((ctndetail.CBM * 1000).ToString("0.###"), 9, "0");//17//Cntr Cargo Measurement//O//9(6)v999//79//87//Measurement per the container unit + tempstr += GetSpaceStr("", 9, "0");//18//Cntr Cargo Net Weight//O//9(6)v999//88//96//Cargo Net Weight per the container unit + tempstr += GetSpaceStr(ctndetail.KINDPKGS_EDI_CODE, 5);//19//webCSM Package Code//O//X(5)//97//101//Package code within the container eg BX (boxes) + tempstr += GetSpaceStr("", 20);//20//Seal No (Shipper)//O//X(20)//102//121//Shipper's Seal Number + tempstr += GetSpaceStr(ctndetail.SEALNO, 20);//21//Seal No (Carrier)//O//X(20)//122//141//Carrier's Seal Number + tempstr += GetSpaceStr("", 20);//22//Seal No (Customs)//O//X(20)//142//161//Customs' Seal Number + tempstr += GetSpaceStr("", 20);//23//Seal No (Others)//O//X(20)//162//181//4th Seal Number + tempstr += GetSpaceStr("", 1);//24//Shortship Flag//C//X(1)//182//182//Y:Shortship, S:Shortland, O:Overland, else leave blank + tempstr += GetSpaceStr("", 20);//25//Part BL Cross-reference (Their Ref)//C//X(20)//183//202//Cross-ref to Main/Sub OBL of Part containers, only applicable to Part BLs + tempstr += GetSpaceStr("", 48);//26//Filler//M//X(48)//203//250//Spaces + + r.WriteLine(GetSpaceStr(tempstr, 250)); + #endregion + } + + if (bill.CARGOID == "R") + { + #region 54 冻柜 + var tmpset = ""; + if (bill.TEMPSET.IndexOf("-") >= 0) + { + tmpset = "-"; + } + else + { + tmpset = "0"; + } + bill.TEMPSET = bill.TEMPSET.Replace("+", "").Replace("-", ""); + + tempstr = "54";//1 //RECORD-ID//M//9(2)//1 //2 //54 + tempstr += GetSpaceStr("", 3);//2 //Filler//M//X(3)//3 //5 //Spaces + tempstr += GetSpaceStr(ctnline.ToString(), 3, "0");//3 //Cargo Sequence No#//货物的序列号//M//9(3)//6 //8 //001 to 999 (line-items) + tempstr += GetSpaceStr(m.ToString(), 3, "0");//4 //Equipment Sequence No设备序列号//M//9(3)//9 //11 //001 to 999 + tempstr += "C";//5 //Reefer Temperature UOM冷藏温度计量单位//M//X(1)//12 //12 //C or F (C=Celsius, F=Fahrenheit) + tempstr += GetSpaceStr("", 5);//6 //Reefer Min Temperature//C//9(3)v99//13 //17 //If MAX exists, MIN should exists + tempstr += GetSpaceStr("", 5);//7 //Reefer Max Temperature//C//9(3)v99//18 //22 //If MIN exists, MAX should exists + tempstr += tmpset + GetSpaceStr((Convert.ToDecimal(bill.TEMPSET) * 100).ToString(), 4, "0");//8 //Reefer Preset Temperature冷藏温度设定//C//9(3)v99//23 //27 //Blank if no Preset required + tempstr += "N";//9 //Reefer Gensets Required冷藏机组的要求//M//X(1)//28 //28 //Y or N + if (bill.REEFERF != "") + { + tempstr += GetSpaceStr((Convert.ToDecimal(bill.REEFERF) * 100).ToString(), 5, "0");//10 //Reefer Vent Open Value冷藏等开放价值//C//9(3)v99//29 //33 //Blank if Vent Status = 'Closed', else value in relation to Vent UOM如果等待空白状态=“闭合”,其他的值等计量单位 + } + else + { + tempstr += GetSpaceStr("", 5);//10 //Reefer Vent Open Value冷藏等开放价值//C//9(3)v99//29 //33 //Blank if Vent Status = 'Closed', else value in relation to Vent UOM如果等待空白状态=“闭合”,其他的值等计量单位 + } + tempstr += "Y";//11 //Pretrip Flag//M//X(1)//34 //34 //Y or N + tempstr += tmpset + GetSpaceStr((Convert.ToDecimal(bill.TEMPSET) * 100).ToString(), 4, "0");//12 //Carriage Temperature运输温度//C//9(3)v99//35 //39 //For operating reefers, at least one temperature field must not be blank + if (bill.REEFERF != "") + { + tempstr += "H";//13 //Reefer Vent Status冷藏通风状况/UOM//C//X(1)//40 //40 //C:Closed, F:CFM, H:M3/H, P:Percentage, O:Open + } + else + { + tempstr += "C";//13 //Reefer Vent Status冷藏通风状况/UOM//C//X(1)//40 //40 //C:Closed, F:CFM, H:M3/H, P:Percentage, O:Open + } + tempstr += GetSpaceStr("", 210);//14 //Filler//M//X(210)//41 //250 //Spaces + r.WriteLine(GetSpaceStr(tempstr, 250)); + #endregion + } + else if (bill.CARGOID == "D") + { + #region 55 危险品紧急联系信息 + tempstr = "55";//1//RECORD-ID//M//9(2)//1//2//55//record-id + tempstr += GetSpaceStr("", 1);//2//Filler//M//X(1)//3//3//Spaces//填料 + tempstr += "01";//3//DG Sequence No//M//9(2)//4//5//Default to "01", Rec 55 is needed only once for each equipment seq//DG的序列号 + tempstr += GetSpaceStr(ctnline.ToString(), 3, "0");//4//Cargo Sequence No#//M//9(3)//6//8//001 to 999 (line-items)//货物没有#序列 + tempstr += GetSpaceStr(m.ToString(), 3, "0");//5//Equipment Sequence No//M//9(3)//9//11//001 to 999//设备序列号 + tempstr += GetSpaceStr(bill.EDIATTN, 35);//6//Emergency Contact//O//X(35)//12//46////急救联系 + tempstr += GetSpaceStr("", 35);//7//Emergency Tel//O//X(35)//47//81////急救电话 + tempstr += GetSpaceStr("", 100);//8//Emergency Email//O//X(100)//82//181////急救的电子邮件 + tempstr += GetSpaceStr("", 20);//9//Emergency Reference//O//X(20)//182//201////急救参考 + tempstr += GetSpaceStr("", 49);//10//Filler//M//X(49)//202//250//Spaces//填料 + r.WriteLine(GetSpaceStr(tempstr, 250)); + #endregion + + #region 56 危险品//56 01001001//2556//a//4.1 //2 //KGM//008220000//009516000//N + tempstr = "56";//1//RECORD-ID M 9(2) 1//2//56 + tempstr += GetSpaceStr("", 1);//2//Filler M X(1) 3//3//Spaces 填料 + tempstr += GetSpaceStr("01", 2);//3//DG Sequence No M 9(2) 4//5//01 to 99, to denote multiple DG items in each equipment seq (cntr) DG的序列号 + tempstr += GetSpaceStr(ctnline.ToString(), 3, "0");//4//Cargo Sequence No# M 9(3) 6//8//001 to 999 (line-items)//货物没有#序列 + tempstr += GetSpaceStr(m.ToString(), 3, "0");//5//Equipment Sequence No M 9(3) 9//11//001 to 999 设备序列号 + tempstr += GetSpaceStr(bill.DUNNO, 4);//6//UN Number M X(4) 12//15// 联合国编号 + tempstr += GetSpaceStr("", 1);//7//UN Variant M X(1) 16//16// 联合国的变体 + tempstr += GetSpaceStr(bill.DCLASS, 4);//8//IMO Class M X(4) 17//20// 国际海事组织类 + tempstr += GetSpaceStr("", 3);//9//PSA Class O X(3) 21//23// PSA类 + tempstr += "KGM";//10//UOM M X(3) 24//26//Default to METRIC, eg. KGM 计量单位 + tempstr += GetSpaceStr(((ctn.KGS - ctn.TAREWEIGHT) * 1000).ToString("0.###"), 9, "0");//11//Net Weight C 9(6)v999 27//35//Weight of DG item 净重量 + tempstr += GetSpaceStr((ctn.KGS * 1000).ToString("0.###"), 9, "0");//12//Gross Weight C 9(6)v999 36//44//Weight of DG item 总重量 + tempstr += "N";//13//Marine Pollutant M X(1) 45//45//Y or N 海洋污染物 + tempstr += GetSpaceStr(bill.DPAGE, 10);//14//IMDG Page O X(10) 46//55// 危规页码 + tempstr += GetSpaceStr("", 4);//15//DOT Packaging Group O X(4) 56//59// 点包装集团 + tempstr += GetSpaceStr("", 10);//16//Filler M X(10) 60//69//Spaces 填料 + tempstr += GetSpaceStr("", 25);//17//Flashpoint O X(25) 70//94// 闪点 + tempstr += GetSpaceStr("", 3);//18//Packing Group O X(3) 95//97// 包装组 + tempstr += GetSpaceStr(ctndetail.KINDPKGS_EDI_CODE, 5);//19//Outer Package Code O X(5) 98//102//webCSM Package Code 外包装编码 + tempstr += GetSpaceStr(ctndetail.PKGS.ToString("0.###"), 9, "0");//20//Outer Quantity O 9(9) 103//111// 外量 + tempstr += GetSpaceStr("", 5);//21//Inner Package Code O X(5) 112//116//webCSM Package Code 内包装代码 + tempstr += GetSpaceStr("", 9);//22//Inner Quantity O 9(9) 117//125// 内部变量 + tempstr += GetSpaceStr("", 5);//23//Next Inner Package Code O X(5) 126//130//webCSM Package Code 下一个内部包代码 + tempstr += GetSpaceStr("", 9);//24//Next Inner Quantity O 9(9) 131//139// 下一个内部变量 + tempstr += GetSpaceStr("", 50);//25//Chemical Name O X(50) 140//189// 化学名称 + tempstr += GetSpaceStr("", 20);//26//Our Reference O X(20) 190//209// 我们的参考 + tempstr += GetSpaceStr("", 21);//28//Filler M X(21) 230//250//Spaces 填料 + r.WriteLine(GetSpaceStr(tempstr, 250)); + #endregion + } + m = m + 1; + } + } + #endregion + } + else + { + #region EDI + #region 41 + tempstr = "41";//1 //RECORD-ID//M//9(2)//1 //2 //41 + tempstr += GetSpaceStr("", 3);//2 //Filler//M//X(3)//3 //5 //Spaces + tempstr += GetSpaceStr(ctnline.ToString(), 3, "0");//3 //Cargo Sequence#//M//9(3)//6 //8 //001 to 999 (line-items) + //tempstr += GetSpaceStr(GetGOODEDICode(bill.GOODSNAME), 9);//4 //Commodity Code//M//X(9)//9 //17 //6 Digits HS CODE + if (bill.HSCODE.ToString().Length > 6) + { + tempstr += GetSpaceStr(bill.HSCODE.ToString().Substring(0, 6), 9);//4 //Commodity Code//M//X(9)//9 //17 //6 Digits HS CODE + } + else + { + tempstr += GetSpaceStr(bill.HSCODE.ToString(), 9);//4 //Commodity Code//M//X(9)//9 //17 //6 Digits HS CODE + } + tempstr += "Y";//5 //BL Override//M//X(1)//18 //18 //Y or N, Y=lumpsum weights used, (out from webCSM only) + tempstr += GetSpaceStr(ctn.CTNNUM.ToString(), 6, "0");//6 //No of packages/Containers//M//9(6)//19 //24 //Number of Containers for the cargo line + tempstr += GetSpaceStr(ctn.TEU.ToString(), 4, "0");//7 //TEU Utilisation//C//9(4)//25 //28 //Actual TEU utilised, eg. OOG's slot kill or Flatrack bundled units + tempstr += GetSpaceStr((ctn.KGS * 1000).ToString("0.###"), 11, "0");//8 //Cargo Gross Weight//C//9(8)v999//29 //39 //Mandatory, except for Empties + tempstr += GetSpaceStr("", 11, "0");//9 //Cargo Nett Weight//C//9(8)v999//40 //50 //Mandatory, except for Empties + tempstr += GetSpaceStr((ctn.CBM * 1000).ToString("0.###"), 10, "0");//10 //Cargo Gross Measurement//C//9(7)v999//51 //60 //Mandatory, except for Empties + tempstr += GetSpaceStr((ctn.CBM * 1000).ToString("0.###"), 10, "0");//11 //Cargo Nett Measurement//C//9(7)v999//61 //70 //Mandatory, except for Empties + tempstr += GetSpaceStr(bill.GOODSNAME, 48);//12 //Commodity Name//O//X(48)//71 //118 // + //tempstr += GetSpaceStr(GetGOODEDICode(bill.GOODSNAME), 4);//13 //webcsm Commodity Code//O//X(4)//119 //122 //webCSM Standard Commodity Code + //2023-03-27 跟韩工确认这里加入商品代码 + //tempstr += GetSpaceStr("", 4);//13 //webcsm Commodity Code//O//X(4)//119 //122 //webCSM Standard Commodity Code + tempstr += GetSpaceStr(bill.GOODSCODE, 4);//13 //webcsm Commodity Code//O//X(4)//119 //122 //webCSM Standard Commodity Code + tempstr += GetSpaceStr(ctn.CTNALLCODE, 4);//14 //webcsm Package Code//M//X(4)//123 //126 //eg 20GP, 40GP etc. + tempstr += "KGM";//15 //UOM Weight//M//X(3)//127 //129 //Default to METRIC = KGM + tempstr += "MTQ";//16 //UOM Measurement//M//X(3)//130 //132 //Default to METRIC = MTQ + tempstr += GetSpaceStr(soc, 1); ;//17 //Equipment Flag //M//X(1)//133 //133 //Y:COC cntr required, N:cntr not required, S:SOC + tempstr += GetSpaceStr("", 117);//18 //Filler//M//X(117)//134 //250 //Spaces + r.WriteLine(GetSpaceStr(tempstr, 250)); + #endregion + + #region 44 + Shipping = bill.MARKS; + ShippingList = formatlengthStr(Shipping, 20); + for (var i = 0; i < Math.Ceiling(Convert.ToDecimal(Convert.ToDecimal(ShippingList.Count) / Convert.ToDecimal(12))); i++) + { + tempstr = "44";//1 //RECORD-ID//M//9(2)//1 //2 //44 + tempstr += GetSpaceStr("", 3);//2 //Filler//M//X(3)//3 //5 //Spaces + tempstr += GetSpaceStr(ctnline.ToString(), 3, "0");//3 //Cargo Sequence No#//M//9(3)//6 //8 //001 to 999 (line-items) + for (var z = 0; z < 12; z++) + { + if ((i * 12 + z) < ShippingList.Count) + { + tempstr += GetSpaceStr(ShippingList[i * 12 + z], 20);//4 //Mark-no-(1)//O//X(20)//9 //28 + } + } + //4 //Mark-no-(1)//O//X(20)//9 //28 // + //5 //Mark-no-(2)//O//X(20)//29 //48 // + //6 //Mark-no-(3)//O//X(20)//49 //68 // + //7 //Mark-no-(4)//O//X(20)//69 //88 // + //8 //Mark-no-(5)//O//X(20)//89 //108 // + //9 //Mark-no-(6)//O//X(20)//109 //128 // + //10 //Mark-no-(7)//O//X(20)//129 //148 // + //11 //Mark-no-(8)//O//X(20)//149 //168 // + //12 //Mark-no-(9)//O//X(20)//169 //188 // + //13 //Mark-no-(10)//O//X(20)//189 //208 // + //14 //Mark-no-(11)//O//X(20)//209 //228 // + //15 //Mark-no-(12)//O//X(20)//229 //248 // + //16 //Filler//M//X(2)//249 //250 //Spaces + r.WriteLine(GetSpaceStr(tempstr, 250)); + } + #endregion + + if (ctnline == 1) + { + #region 47 + tempstr = "47";//1 //RECORD-ID//M//9(2)//1 //2 //47 + tempstr += GetSpaceStr("", 3);//2 //Filler//M//X(3)//3 //5 //Spaces + tempstr += GetSpaceStr(ctnline.ToString(), 3, "0");//3 //Cargo Sequence No#//M//9(3)//6 //8 //001 to 999 (line-items) + tempstr += bill.PKGS.ToString() + bill.KINDPKGS;//4 //Cargo Description- (1)//O//X(30)//9 //38 // + //5 //Cargo Description- (2)//O//X(30)//39 //68 // + //6 //Cargo Description- (3)//O//X(30)//69 //98 // + //7 //Cargo Description- (4)//O//X(30)//99 //128 // + //8 //Cargo Description- (5)//O//X(30)//129 //158 // + //9 //Cargo Description- (6)//O//X(30)//159 //188 // + //10 //Cargo Description- (7)//O//X(30)//189 //218 // + //11 //Cargo Description- (8)//O//X(30)//219 //248 // + //12 //Filler//M//X(2)//249 //250 //Spaces + r.WriteLine(GetSpaceStr(tempstr, 250)); + #endregion + } + + #region 47 description + Shipping = bill.DESCRIPTION; + ShippingList = formatlengthStr(Shipping, 30); + for (var i = 0; i < Math.Ceiling(Convert.ToDecimal(Convert.ToDecimal(ShippingList.Count) / Convert.ToDecimal(8))); i++) + { + tempstr = "47";//1 //RECORD-ID//M//9(2)//1 //2 //47 + tempstr += GetSpaceStr("", 3);//2 //Filler//M//X(3)//3 //5 //Spaces + tempstr += GetSpaceStr(ctnline.ToString(), 3, "0");//3 //Cargo Sequence No#//M//9(3)//6 //8 //001 to 999 (line-items) + for (var z = 0; z < 8; z++) + { + if ((i * 8 + z) < ShippingList.Count) + { + tempstr += GetSpaceStr(ShippingList[i * 8 + z], 30);//4 //Cargo Description- (1)//O//X(30)//9 //38 // + } + } + //4 //Cargo Description- (1)//O//X(30)//9 //38 // + //5 //Cargo Description- (2)//O//X(30)//39 //68 // + //6 //Cargo Description- (3)//O//X(30)//69 //98 // + //7 //Cargo Description- (4)//O//X(30)//99 //128 // + //8 //Cargo Description- (5)//O//X(30)//129 //158 // + //9 //Cargo Description- (6)//O//X(30)//159 //188 // + //10 //Cargo Description- (7)//O//X(30)//189 //218 // + //11 //Cargo Description- (8)//O//X(30)//219 //248 // + //12 //Filler//M//X(2)//249 //250 //Spaces + r.WriteLine(GetSpaceStr(tempstr, 250)); + } + #endregion + + for (var m = 1; m <= ctn.CTNNUM; ++m) + { + if (bill.CARGOID == "R") + { + #region 54 冻柜 + var tmpset = ""; + if (bill.TEMPSET.IndexOf("-") >= 0) + tmpset = "-"; + else + tmpset = "0"; + bill.TEMPSET = bill.TEMPSET.Replace("+", "").Replace("-", ""); + + tempstr = "54";//1 //RECORD-ID//M//9(2)//1 //2 //54 + tempstr += GetSpaceStr("", 3);//2 //Filler//M//X(3)//3 //5 //Spaces + tempstr += GetSpaceStr(ctnline.ToString(), 3, "0");//3 //Cargo Sequence No#//货物的序列号//M//9(3)//6 //8 //001 to 999 (line-items) + tempstr += GetSpaceStr(m.ToString(), 3, "0");//4 //Equipment Sequence No设备序列号//M//9(3)//9 //11 //001 to 999 + tempstr += "C";//5 //Reefer Temperature UOM冷藏温度计量单位//M//X(1)//12 //12 //C or F (C=Celsius, F=Fahrenheit) + tempstr += GetSpaceStr("", 5);//6 //Reefer Min Temperature//C//9(3)v99//13 //17 //If MAX exists, MIN should exists + tempstr += GetSpaceStr("", 5);//7 //Reefer Max Temperature//C//9(3)v99//18 //22 //If MIN exists, MAX should exists + tempstr += tmpset + GetSpaceStr((Convert.ToDecimal(bill.TEMPSET) * 100).ToString(), 4, "0");//8 //Reefer Preset Temperature冷藏温度设定//C//9(3)v99//23 //27 //Blank if no Preset required + tempstr += "N";//9 //Reefer Gensets Required冷藏机组的要求//M//X(1)//28 //28 //Y or N + if (bill.REEFERF != "") + { + tempstr += GetSpaceStr((Convert.ToDecimal(bill.REEFERF) * 100).ToString(), 5, "0");//10 //Reefer Vent Open Value冷藏等开放价值//C//9(3)v99//29 //33 //Blank if Vent Status = 'Closed', else value in relation to Vent UOM如果等待空白状态=“闭合”,其他的值等计量单位 + } + else + { + tempstr += GetSpaceStr("", 5);//10 //Reefer Vent Open Value冷藏等开放价值//C//9(3)v99//29 //33 //Blank if Vent Status = 'Closed', else value in relation to Vent UOM如果等待空白状态=“闭合”,其他的值等计量单位 + } + tempstr += "Y";//11 //Pretrip Flag//M//X(1)//34 //34 //Y or N + tempstr += tmpset + GetSpaceStr((Convert.ToDecimal(bill.TEMPSET) * 100).ToString(), 4, "0");//12 //Carriage Temperature运输温度//C//9(3)v99//35 //39 //For operating reefers, at least one temperature field must not be blank + if (bill.REEFERF != "") + { + tempstr += "H";//13 //Reefer Vent Status冷藏通风状况/UOM//C//X(1)//40 //40 //C:Closed, F:CFM, H:M3/H, P:Percentage, O:Open + } + else + { + tempstr += "C";//13 //Reefer Vent Status冷藏通风状况/UOM//C//X(1)//40 //40 //C:Closed, F:CFM, H:M3/H, P:Percentage, O:Open + } + tempstr += GetSpaceStr("", 210);//14 //Filler//M//X(210)//41 //250 //Spaces + r.WriteLine(GetSpaceStr(tempstr, 250)); + #endregion + } + else if (bill.CARGOID == "D") + { + #region 55 危险品紧急联系信息 + tempstr = "55";//1//RECORD-ID//M//9(2)//1//2//55//record-id + tempstr += GetSpaceStr("", 1);//2//Filler//M//X(1)//3//3//Spaces//填料 + tempstr += "01";//3//DG Sequence No//M//9(2)//4//5//Default to "01", Rec 55 is needed only once for each equipment seq//DG的序列号 + tempstr += GetSpaceStr(ctnline.ToString(), 3, "0");//4//Cargo Sequence No#//M//9(3)//6//8//001 to 999 (line-items)//货物没有#序列 + tempstr += GetSpaceStr(m.ToString(), 3, "0");//5//Equipment Sequence No//M//9(3)//9//11//001 to 999//设备序列号 + tempstr += GetSpaceStr(bill.EDIATTN, 35);//6//Emergency Contact//O//X(35)//12//46////急救联系 + tempstr += GetSpaceStr("", 35);//7//Emergency Tel//O//X(35)//47//81////急救电话 + tempstr += GetSpaceStr("", 100);//8//Emergency Email//O//X(100)//82//181////急救的电子邮件 + tempstr += GetSpaceStr("", 20);//9//Emergency Reference//O//X(20)//182//201////急救参考 + tempstr += GetSpaceStr("", 49);//10//Filler//M//X(49)//202//250//Spaces//填料 + r.WriteLine(GetSpaceStr(tempstr, 250)); + #endregion + + #region 56 危险品//56 01001001//2556//a//4.1 //2 //KGM//008220000//009516000//N + tempstr = "56";//1//RECORD-ID M 9(2) 1//2//56 + tempstr += GetSpaceStr("", 1);//2//Filler M X(1) 3//3//Spaces 填料 + tempstr += GetSpaceStr("01", 2);//3//DG Sequence No M 9(2) 4//5//01 to 99, to denote multiple DG items in each equipment seq (cntr) DG的序列号 + tempstr += GetSpaceStr(ctnline.ToString(), 3, "0");//4//Cargo Sequence No# M 9(3) 6//8//001 to 999 (line-items)//货物没有#序列 + tempstr += GetSpaceStr(m.ToString(), 3, "0");//5//Equipment Sequence No M 9(3) 9//11//001 to 999 设备序列号 + tempstr += GetSpaceStr(bill.DUNNO, 4);//6//UN Number M X(4) 12//15// 联合国编号 + tempstr += GetSpaceStr("", 1);//7//UN Variant M X(1) 16//16// 联合国的变体 + tempstr += GetSpaceStr(bill.DCLASS, 4);//8//IMO Class M X(4) 17//20// 国际海事组织类 + tempstr += GetSpaceStr("", 3);//9//PSA Class O X(3) 21//23// PSA类 + tempstr += "KGM";//10//UOM M X(3) 24//26//Default to METRIC, eg. KGM 计量单位 + tempstr += GetSpaceStr(((ctn.KGS - ctn.TAREWEIGHT) * 1000).ToString("0.###"), 9, "0");//11//Net Weight C 9(6)v999 27//35//Weight of DG item 净重量 + tempstr += GetSpaceStr((ctn.KGS * 1000).ToString("0.###"), 9, "0");//12//Gross Weight C 9(6)v999 36//44//Weight of DG item 总重量 + tempstr += "N";//13//Marine Pollutant M X(1) 45//45//Y or N 海洋污染物 + tempstr += GetSpaceStr(bill.DPAGE, 10);//14//IMDG Page O X(10) 46//55// 危规页码 + tempstr += GetSpaceStr("", 4);//15//DOT Packaging Group O X(4) 56//59// 点包装集团 + tempstr += GetSpaceStr("", 10);//16//Filler M X(10) 60//69//Spaces 填料 + tempstr += GetSpaceStr("", 25);//17//Flashpoint O X(25) 70//94// 闪点 + tempstr += GetSpaceStr("", 3);//18//Packing Group O X(3) 95//97// 包装组 + tempstr += GetSpaceStr(ctn.KINDPKGS_EDI_CODE, 5);//19//Outer Package Code O X(5) 98//102//webCSM Package Code 外包装编码 + tempstr += GetSpaceStr(ctn.PKGS.ToString(), 9, "0");//20//Outer Quantity O 9(9) 103//111// 外量 + tempstr += GetSpaceStr("", 5);//21//Inner Package Code O X(5) 112//116//webCSM Package Code 内包装代码 + tempstr += GetSpaceStr("", 9);//22//Inner Quantity O 9(9) 117//125// 内部变量 + tempstr += GetSpaceStr("", 5);//23//Next Inner Package Code O X(5) 126//130//webCSM Package Code 下一个内部包代码 + tempstr += GetSpaceStr("", 9);//24//Next Inner Quantity O 9(9) 131//139// 下一个内部变量 + tempstr += GetSpaceStr("", 50);//25//Chemical Name O X(50) 140//189// 化学名称 + tempstr += GetSpaceStr("", 20);//26//Our Reference O X(20) 190//209// 我们的参考 + tempstr += GetSpaceStr("", 21);//28//Filler M X(21) 230//250//Spaces 填料 + r.WriteLine(GetSpaceStr(tempstr, 250)); + #endregion + } + } + #endregion + } + ctnline = ctnline + 1; + } + + #region 73 + /* + 2023-04-04 73B行韩工给提供了新的代码,替换原有逻辑 + */ + if (InttrEdi.filetype != "E") + { + tempstr = "73";//1 //RECORD_ID//M//9(2)//1 //2 //73 + tempstr += "B";//2 //Remarks_indicator//M//X(1)//3 //3 //O-Onhold, B-Booking, C-Customs, M-Manifest, X-Special, A-Additional, G-General, T-Transhipment, E-EDI //"73B,必填内容:1)SALES REP CODE;2)ACI HBL (1,2,3);加拿大线的HBL3) 货物混装描述 (S0C+C0C)"//分三行 + //3 //Remarks Text//O//X(120)//4 //123 //RemarksGetCustEdi(bill.YARD,120) + //4 //Filler//M//X(127)//124 //250 //Spaces + r.WriteLine(GetSpaceStr(tempstr, 250)); + + + if (!string.IsNullOrWhiteSpace(bill.ACIHBL)) + { + tempstr = "73";//1 //RECORD_ID//M//9(2)//1 //2 //73 + tempstr += "B";//2 //Remarks_indicator//M//X(1)//3 //3 //O-Onhold, B-Booking, C-Customs, M-Manifest, X-Special, A-Additional, G-General, T-Transhipment, E-EDI //"73B,必填内容:1)SALES REP CODE;2)ACI HBL (1,2,3);加拿大线的HBL3) 货物混装描述 (S0C+C0C)"//分三行 + tempstr += GetSpaceStr(bill.ACIHBL, 120);//3 //Remarks Text//O//X(120)//4 //123 //RemarksGetCustEdi(bill.YARD,120) + //4 //Filler//M//X(127)//124 //250 //Spaces + r.WriteLine(GetSpaceStr(tempstr, 250)); + } + + if (!string.IsNullOrWhiteSpace(bill.S0CC0C)) + { + tempstr = "73";//1 //RECORD_ID//M//9(2)//1 //2 //73 + tempstr += "B";//2 //Remarks_indicator//M//X(1)//3 //3 //O-Onhold, B-Booking, C-Customs, M-Manifest, X-Special, A-Additional, G-General, T-Transhipment, E-EDI //"73B,必填内容:1)SALES REP CODE;2)ACI HBL (1,2,3);加拿大线的HBL3) 货物混装描述 (S0C+C0C)"//分三行 + tempstr += GetSpaceStr(bill.S0CC0C, 120);//3 //Remarks Text//O//X(120)//4 //123 //RemarksGetCustEdi(bill.YARD,120) + //4 //Filler//M//X(127)//124 //250 //Spaces + r.WriteLine(GetSpaceStr(tempstr, 250)); + } + } + + if (InttrEdi.filetype == "E") + { + //2023-02-23 韩工提供新的截单写入集装箱的信息 + if (bill.CTNLIST != null && bill.CTNLIST.Count > 0) + { + foreach (var ctndetail in bill.CTNLIST) + { + tempstr = "73";//1 //RECORD_ID//M//9(2)//1 //2 //73 + tempstr += "B";//2 //Remarks_indicator//M//X(1)//3 //3 //O-Onhold, B-Booking, C-Customs, M-Manifest, X-Special, A-Additional, G-General, T-Transhipment, E-EDI //"73B,必填内容:1)SALES REP CODE;2)ACI HBL (1,2,3);加拿大线的HBL3) 货物混装描述 (S0C+C0C)"//分三行 + tempstr += GetSpaceStr(ctndetail.CNTRNO, 120);//3 //Remarks Text//O//X(120)//4 //123 //RemarksGetCustEdi(bill.YARD,120) + //4 //Filler//M//X(127)//124 //250 //Spaces + r.WriteLine(GetSpaceStr(tempstr, 250)); + } + } + + //欧盟港口、伊朗港口、KHI + if (!string.IsNullOrWhiteSpace(bill.cKHI)) + { + Shipping = bill.cKHI; + List ShippingListLs = formatlengthStr(Shipping, 120); + for (var i = 0; i < ShippingListLs.Count; i++) + { + tempstr = "73";//1 //RECORD_ID//M//9(2)//1 //2 //73 + tempstr += "C";//2 //Remarks_indicator//M//X(1)//3 //3 //O-Onhold, B-Booking, C-Customs, M-Manifest, X-Special, A-Additional, G-General, T-Transhipment, E-EDI //"73B,必填内容:1)SALES REP CODE;2)ACI HBL (1,2,3);加拿大线的HBL3) 货物混装描述 (S0C+C0C)"//分三行 + tempstr += GetSpaceStr(ShippingListLs[i], 120);//3 //Remarks Text//O//X(120)//4 //123 //RemarksGetCustEdi(bill.YARD,120) + //4 //Filler//M//X(127)//124 //250 //Spaces + r.WriteLine(GetSpaceStr(tempstr, 250)); + } + } + + //南美东 + if (!string.IsNullOrWhiteSpace(bill.cNCM)) + { + Shipping = bill.cNCM; + List ShippingListLs = formatlengthStr(Shipping, 120); + for (var i = 0; i < ShippingListLs.Count; i++) + { + tempstr = "73";//1 //RECORD_ID//M//9(2)//1 //2 //73 + tempstr += "C";//2 //Remarks_indicator//M//X(1)//3 //3 //O-Onhold, B-Booking, C-Customs, M-Manifest, X-Special, A-Additional, G-General, T-Transhipment, E-EDI //"73B,必填内容:1)SALES REP CODE;2)ACI HBL (1,2,3);加拿大线的HBL3) 货物混装描述 (S0C+C0C)"//分三行 + tempstr += GetSpaceStr(ShippingListLs[i], 120);//3 //Remarks Text//O//X(120)//4 //123 //RemarksGetCustEdi(bill.YARD,120) + //4 //Filler//M//X(127)//124 //250 //Spaces + r.WriteLine(GetSpaceStr(tempstr, 250)); + } + } + + //巴西线的木质包装情况 + if (!string.IsNullOrWhiteSpace(bill.wNCM)) + { + Shipping = bill.wNCM; + List ShippingListLs = formatlengthStr(Shipping, 120); + for (var i = 0; i < ShippingListLs.Count; i++) + { + tempstr = "73";//1 //RECORD_ID//M//9(2)//1 //2 //73 + tempstr += "W";//2 //Remarks_indicator//M//X(1)//3 //3 //O-Onhold, B-Booking, C-Customs, M-Manifest, X-Special, A-Additional, G-General, T-Transhipment, E-EDI //"73B,必填内容:1)SALES REP CODE;2)ACI HBL (1,2,3);加拿大线的HBL3) 货物混装描述 (S0C+C0C)"//分三行 + tempstr += GetSpaceStr(ShippingListLs[i], 120);//3 //Remarks Text//O//X(120)//4 //123 //RemarksGetCustEdi(bill.YARD,120) + //4 //Filler//M//X(127)//124 //250 //Spaces + r.WriteLine(GetSpaceStr(tempstr, 250)); + } + } + } + + #endregion + + #region 74 + tempstr = "74";//1//RECORD-ID//M//9(2)//1//2//74// + tempstr += GetSpaceStr("", 3);//2//Filler//O//X(3)//3//5//Spaces// + tempstr += GetSpaceStr(bill.ISSUEPLACEID, 5);//3//Place of BL issue//M//X(5)//6//10//webCSM Port code (Port of BL Issuance)//提单签发地//webcsm港口代码(BL发行端口) + if (string.IsNullOrWhiteSpace(bill.ISSUEDATE)) + { + tempstr += GetSpaceStr("", 8);//4//Date of BL issue//M//X(8)//11//18//YYYYMMDD//提单签发日期//年月日 + } + else + { + tempstr += GetDateStr(bill.ISSUEDATE, "yyyyMMdd");//4//Date of BL issue//M//X(8)//11//18//YYYYMMDD//提单签发日期//年月日 + } + tempstr += GetSpaceStr("", 4);//5//Department Code//M//X(4)//19//22//webCSM Department Code (eg SG00) (out from webCSM only)//部门代码//webcsm部门代码(如sg00)(从webcsm只) + tempstr += GetSpaceStr("", 3);//6//Booking Agent Code//M//X(3)//23//25//webCSM Booking Agent Code (eg SIN)//订舱代理代码//webcsm订舱代理代码(如犯罪) + if (bill.ISSUETYPE?.Trim().ToUpper() == "WAYBILL" || bill.ISSUETYPE?.Trim().ToUpper() == "SEAWAY BILL") + { + tempstr += GetSpaceStr("W", 1);//7//BOL Type//M//X(1)//26//26//N-Nominal, G-Negotiable, S-Switch, W-Waybill, M-Memo//公司类型//n-nominal,g-negotiable,S-开关,w-waybill,m-memo + } + else + { + tempstr += GetSpaceStr("N", 1);//7//BOL Type//M//X(1)//26//26//N-Nominal, G-Negotiable, S-Switch, W-Waybill, M-Memo//公司类型//n-nominal,g-negotiable,S-开关,w-waybill,m-memo + } + //tempstr += GetSpaceStr(GetBillNum(bill.NOBILL.ToString().Trim()), 2, "0");//8//No. of Original BLs//O//9(2)//27//28//号原BLS// + //tempstr += GetSpaceStr(GetBillNum(bill.COPYNOBILL.ToString().Trim()), 2, "0");//9//No. of Copy BLs//O//9(2)//29//30//不复制BLS// + tempstr += GetSpaceStr("", 2);//8//No. of Original BLs//O//9(2)//27//28//号原BLS//太平要求去掉 + tempstr += GetSpaceStr("", 2);//9//No. of Copy BLs//O//9(2)//29//30//不复制BLS//太平要求去掉 + if (bill.BYCOUNTRY == "USA") + { + tempstr += GetSpaceStr(bill.CONTRACTNO, 10);//10//Service Contract #//C//X(10)//31//40//Applicable to US shipments only//"mandtory for US shpts---Service Contract Nbr/TAA Nbr"//美国线的S/C,TAA//服务合同#//只适用于美国装运 + } + else + { + tempstr += GetSpaceStr("", 10);//10//Service Contract #//C//X(10)//31//40//Applicable to US shipments only//"mandtory for US shpts---Service Contract Nbr/TAA Nbr"//美国线的S/C,TAA//服务合同#//只适用于美国装运 + } + tempstr += GetSpaceStr("", 5);//11//Prepaid at (Port code)//M//X(5)//41//45//Ocean Freight Payment Location//预付(港码)//海运付款地点 + tempstr += GetSpaceStr("", 5);//12//Payable at (Port Code)//M//X(5)//46//50//1st Collect Charge Payment Location//按(港口代码)支付//第一收取缴费地点 + tempstr += GetSpaceStr(bill.PKGS.ToString().Trim(), 8, "0");//13//BL's total No of Packages//O//9(8)//51//58//提单总包数// + tempstr += GetSpaceStr(bill.KINDPKGS_EDI_CODE, 8);//14//BL's Packages_type in total//O//X(8)//59//66//Default as 'PACKAGE'//BL的packages_type总//默认为“包” + + + tempstr += GetSpaceStr("", 12);//15//Filler//M//X(12)//67//78//Spaces//填料//空间 + tempstr += GetSpaceStr("", 1);//16//Roundtrip Indicator//O//X(1)//79//79//Y:Round trip, else leave Blank//往返指示器//往返,否则留下空白 + tempstr += GetSpaceStr("", 1);//17//Received for Shipment//O//X(1)//80//80//Y:Received for Shipment, else leave Blank//收到的货物//收到装运,否则留空 + tempstr += GetSpaceStr("", 8);//18//Shipped on Board Date//O//X(8)//81//88//YYYYMMDD (SOB Date)//装船日期//YYYYMMDD(SOB日期) + tempstr += GetSpaceStr("", 8);//19//Date of Surrender//O//X(8)//89//96//YYYYMMDD (Surrender Date)//日投降//YYYYMMDD(投降日) + tempstr += GetSpaceStr("", 5);//20//Point of BL Surrender//O//X(5)//97//101//webCSM Port code (Point of BL Surrender)//提单退保点//webcsm港口代码(BL屈服点) + tempstr += GetSpaceStr("", 5);//21//Point of BL Switch//O//X(5)//102//106//webCSM Port code (Point of BL Switch)//BL开关点//webcsm港口代码(BL开关点) + tempstr += GetSpaceStr("", 8);//22//Date of Switch Issuance//O//X(8)//107//114//YYYYMMDD (Switch Issuance Date)//开关签发日期//YYYYMMDD(开关发行日期) + tempstr += GetSpaceStr("", 5);//23//Point of BL Switch Issuance//O//X(5)//115//119//webCSM Port code (Point of BL Switch Issuance)//提单开关点//webcsm港口代码(BL开关发行点) + tempstr += GetSpaceStr("", 5);//24//Final Delivered Point//O//X(5)//120//124//webCSM Port code (Final Released Point of cargo)//最后交付点//webcsm港口代码(最终发布点的货物) + tempstr += GetSpaceStr("", 126);//25//Filler//M//X(126)//125//250//Spaces + r.WriteLine(GetSpaceStr(tempstr, 250)); + #endregion + } + + #region 99 + tempstr = "99";//1 RECORD-ID M 9(2) 1 2 99 + tempstr += GetSpaceStr("", 3);//2 Filler M X(3) 3 5 Spaces + tempstr += GetSpaceStr(icount.ToString(), 6, "0");//3 Total No of B/Ls M 9(6) 6 11 Total number of b/ls generated in EDI file + //4 Filler M X(239) 12 250 Spaces + r.WriteLine(GetSpaceStr(tempstr, 250)); + #endregion + + r.Close(); + f.Close(); + result. Succeeded= true; + result.ExtraData1 = filename; + result.ExtraData2 = GetEmailTopic(InttrEdi); + return result; + } + #endregion + + /// + /// 获取邮件主题 + /// + /// + /// + public static string GetEmailTopic(EDIBaseModel inttrEdi) + { + if (inttrEdi.filetype.Equals("B", StringComparison.OrdinalIgnoreCase)) + { + //return inttrEdi.BSLIST.FirstOrDefault().VOYNO?.Trim() + " " + inttrEdi.BSLIST.FirstOrDefault().MBLNO?.Trim() + " IBOOKING"; + //2023-05-31 查看东胜7的PIL EDI最后改成这个主题 + return inttrEdi.BSLIST.FirstOrDefault().MBLNO?.Trim() + " " + "EDI"; + } + else if (inttrEdi.filetype.Equals("E", StringComparison.OrdinalIgnoreCase)) + { + return inttrEdi.BSLIST.FirstOrDefault().MBLNO?.Trim() + " " + "ESI"; + } + + return string.Empty; + } + + } +} diff --git a/ds-wms-service/DS.WMS.Core/Op/EDI/TSLEdiHelper.cs b/ds-wms-service/DS.WMS.Core/Op/EDI/TSLEdiHelper.cs new file mode 100644 index 00000000..08a9bde5 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Op/EDI/TSLEdiHelper.cs @@ -0,0 +1,2157 @@ +using DS.Module.Core; +using DS.WMS.Core.Op.Dtos; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace DS.WMS.Core.Op.EDI +{ + public class TSLEdiHelper + { + + public TSLEdiHelper() + { + } + + #region 基本函数 + public static string GetCarrierName(string str) + { + if (str == "MAEU") return "MAERSK LINE"; + if (str == "MCCQ") return "MCC TRANSPORT SINGAPORE"; + if (str == "ANNU") return "ANL CONTAINER LINE"; + if (str == "CMDU") return "CMA CGM"; + if (str == "CHNL") return "CNC"; + if (str == "HLCU") return "HAPAG-LLOYD"; + if (str == "SUDU") return "HAMBURG"; + if (str == "MSCU") return "MSC"; + if (str == "DAAE") return "DELMAS"; + if (str == "UASC") return "UASC"; + if (str == "COSU") return "COSCO"; + else return ""; + } + public static string GetBillNum(string str) + { + if (str == "ZERO") return "0"; + if (str == "ONE") return "1"; + if (str == "TWO") return "2"; + if (str == "THREE") return "3"; + if (str == "FOUR") return "4"; + if (str == "FIVE") return "5"; + if (str == "SIX") return "6"; + if (str == "SERVEN") return "7"; + if (str == "EIGHT") return "8"; + if (str == "NINE") return "9"; + if (str == "TEN") return "10"; + else return ""; + } + public static string GetBillNum2(string str) + { + if (str == "ZERO") return "00"; + if (str == "ONE") return "01"; + if (str == "TWO") return "02"; + if (str == "THREE") return "03"; + if (str == "FOUR") return "04"; + if (str == "FIVE") return "05"; + if (str == "SIX") return "06"; + if (str == "SERVEN") return "07"; + if (str == "EIGHT") return "08"; + if (str == "NINE") return "09"; + if (str == "TEN") return "10"; + else return ""; + } + + #region 判断中文字符 + public static bool IsChinese(char c) + { + return (int)c > 0x80; + } + public static bool StringIsChinese(string str) + { + var result = false; + for (int i = 1; i < str.Length; i++) + { + if (IsChinese(str[i])) + { + result = true; + return result; + } + } + for (int i = 0; i < str.Length; i++) + { + string stemp = str.Substring(i, 1); + int ilen = System.Text.Encoding.Default.GetByteCount(stemp); + if (ilen == 2) + { + result = true; + return result; + } + + } + + return result; + } + + #endregion + + #region 文本字段判断每行是否符合 + /// + /// edi 文本格式处理判断(例如:1行35个字符不超过5行) + /// + /// 文件类型(例如:txt、xml) + /// 要处理的数据 + /// 每行长度 + /// 主提单号 + /// 数据类型(例如:发货人内容、货描等) + /// 限制录入的行数(“0”代表不限制) + /// 限录后多出的放到货描中的数据的连接符(例如:“*”发货人内容、“**”收件人等) + /// + public static System.String formatlengthError(string fileType, string str, int length, string sMBLNO, string sType, int rowNum, string sSymbol, bool isHuoMiao) + { + string error = ""; + string Shipping = str; + if (fileType == "txt") + { + Shipping = formatEdiStr("txt", str); + } + else if (fileType == "xml") + { + Shipping = formatEdiStr("txt", str); + } + string[] argAGENT = Shipping.Split(new string[] { "\r\n" }, StringSplitOptions.None); + if (argAGENT.Length > 0) + { + if (argAGENT.Length == 1) + { + argAGENT = Shipping.Split(new string[] { "\n" }, StringSplitOptions.None); + if (argAGENT.Length > 0) + { + if (argAGENT.Length > rowNum && rowNum != 0) + { + if (isHuoMiao) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据!"; + } + else + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据,多余信息请手动以“" + sSymbol + "”号开头放到货物描述中!(例如:“货描内容" + sSymbol + "超出部分”)"; + } + } + for (int j = 0; j < argAGENT.Length; j++) + { + //List AgentList = formatlengthStr(argAGENT[j].ToString(), 35); + if (argAGENT[j].ToString().Length > length) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 第" + (j + 1) + "行超过" + length + "个字符"; + } + } + } + } + else + { + if (argAGENT.Length > rowNum && rowNum != 0) + { + if (isHuoMiao) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据!"; + } + else + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据,多余信息请手动以“" + sSymbol + "”号开头放到货物描述中!(例如:“货描内容" + sSymbol + "超出部分”)"; + } + } + for (int j = 0; j < argAGENT.Length; j++) + { + //List AgentList = formatlengthStr(argAGENT[j].ToString(), 35); + if (argAGENT[j].ToString().Length > length) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 第" + (j + 1) + "行超过" + length + "个字符"; + } + } + } + } + return error; + } + #endregion + + #region 字符转义 + /// + /// 各种文本转义字符 + /// + /// 文件类型(例如:txt、xml) + /// 文本字符串 + /// + public static string formatEdiStr(string fileType, string str) + { + if (str == null) + str = string.Empty; + + if (fileType == "txt") + { + return str.Replace("?", "??").Replace(":", "?:").Replace("+", "?+").Replace("'", "?'"); + } + else if (fileType == "xml") + { + return str.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace("\"", """).Replace("'", "'"); + } + else if (fileType == "sitc") + { + return str.Replace("?", "??").Replace(":", "?:").Replace("'", "?'"); + } + else + { + return str; + } + } + #endregion + #region 格式化每行 + public static List formatlengthStr(string str, int length, bool formatstr = false, bool nodelsp = false) + { + str = str.Replace("\r\n", "\\"); + str = str.Replace("\n", "\\"); + str = str.Replace("\r", " "); + string[] StrList = str.Split('\\'); + var strtemp = ""; + var strnewline = ""; + var strtempnewline = ""; + char[] spstring = { ' ', ';', ',', '.', ':', '/', '(', ')', '?', '+', '-' }; + List DestList = new List(); + for (var i = 0; i <= StrList.Length - 1; i++) + { + if (StrList[i].Length <= length) + { + if (formatstr) + DestList.Add(formatEdiStr("txt", StrList[i])); + else + DestList.Add(StrList[i]); + + } + else + { + strtemp = StrList[i] + " "; + strtempnewline = ""; + strnewline = ""; + for (var j = 0; j < strtemp.Length; j++) + { + strtempnewline = strtempnewline + strtemp[j]; + if (strtemp[j] == ' ' || strtemp[j] == ':' || strtemp[j] == ',' || strtemp[j] == '.' || strtemp[j] == ':' || strtemp[j] == '/' + || strtemp[j] == '?' || strtemp[j] == ')' || strtemp[j] == '}' || strtemp[j] == '+' || strtemp[j] == '-') + { + if ((strnewline.Length + strtempnewline.Length) <= length) + strnewline = strnewline + strtempnewline; + else + { + if (formatstr) + DestList.Add(formatEdiStr("txt", strnewline)); + else + DestList.Add(strnewline); + strnewline = strtempnewline; + + } + strtempnewline = ""; + } + } + if (nodelsp) + { + if (formatstr) + DestList.Add(formatEdiStr("txt", strnewline)); + else DestList.Add(strnewline); + } + else if (strnewline.Trim() != "") + { + if (formatstr) + DestList.Add(formatEdiStr("txt", strnewline)); + else DestList.Add(strnewline); + } + } + + } + + return DestList; + } + #endregion + #endregion + + #region 检查 + public static string IsCreateTSL(EDIBaseModel InttrEdi) + { + var error = ""; + + if (string.IsNullOrEmpty(InttrEdi.SENDCODE)) + { error = error + "
发送方代码不能为空"; } + + if (string.IsNullOrEmpty(InttrEdi.SENDNAME)) + { error = error + "
发送方名称不能为空"; } + + if (string.IsNullOrEmpty(InttrEdi.RECEIVECODE)) + { error = error + "
接收方代码不能为空"; } + + if (InttrEdi.filetype == "B") + { + if (InttrEdi.UseForWarderCode) + { + if (string.IsNullOrEmpty(InttrEdi.ForWarderCode)) + { error = error + "
货代代码不能为空"; } + + if (string.IsNullOrEmpty(InttrEdi.ForWarderName)) + { error = error + "
货代称呼不能为空"; } + } + } + + + foreach (var headData in InttrEdi.BSLIST) + { + + if (InttrEdi.filetype == "B") + { + if (InttrEdi.UseForWarderCode) + { + if (string.IsNullOrEmpty(headData.ORDERNO)) + { error = error + "
订舱编号不能为空"; } + } + } + + if (string.IsNullOrEmpty(headData.OpEName)) + { error = error + "
操作的英文名不能为空"; } + + if (string.IsNullOrEmpty(headData.OpTel)) + { error = error + "
操作的电话不能为空"; } + + if (string.IsNullOrEmpty(headData.OpEmail)) + { error = error + "
操作的邮箱不能为空"; } + + //2023-05-19 只有截单时才要求主提单号必填 + if (InttrEdi.filetype == "E") + { + if (string.IsNullOrEmpty(headData.MBLNO)) + { error = error + "
主提单号不能为空"; } + } + + if (string.IsNullOrEmpty(headData.BLFRT)) + { error = error + "
提单号:" + headData.MBLNO + " 付费方式不能为空"; } + + if (string.IsNullOrEmpty(headData.SERVICE)) + { error = error + "
提单号:" + headData.MBLNO + " 运输条款不能为空"; } + + //if (string.IsNullOrEmpty(headData.CONTRACTNO)) + //{ error = error + "
提单号:" + headData.MBLNO + " 运费协议号不能为空"; } + if (string.IsNullOrEmpty(headData.CARGOID)) + { error = error + "
提单号:" + headData.MBLNO + " 货物标识不能为空"; } + + + if (headData.CARGOID == "D" || headData.SERVICE == "DOOR-DOOR" || headData.SERVICE == "DOOR-CY" || headData.SERVICE == "CY-DOOR") + { + if (headData.CARRIER != "YML") + { + if (string.IsNullOrEmpty(headData.EDIATTN)) + { error = error + "
EDI信息联系人不能为空"; } + + if (string.IsNullOrEmpty(headData.EDIATTNTEL)) + { error = error + "
EDI信息联系人电话不能为空"; } + + if (string.IsNullOrEmpty(headData.EDIATTNEMAIL)) + { error = error + "
EDI信息联系人邮箱不能为空"; } + } + } + + + if (InttrEdi.filetype == "E") + { + if (string.IsNullOrEmpty(headData.VESSEL)) + { error = error + "
提单号:" + headData.MBLNO + " 船名不能为空"; } + + if (string.IsNullOrEmpty(headData.VOYNO)) + { error = error + "
提单号:" + headData.MBLNO + " 航次不能为空"; } + } + if (InttrEdi.filetype == "E") + { + if (headData.SIREMARK.IndexOf("PLEASE BOOK OCEAN CARRIER") > -1 || headData.SIREMARK.ToString().Trim() == "") + { + if (headData.CARRIER == "COSU") + { + error = error + "
提单号:" + headData.MBLNO + " 请在SI备注中输入:COSCO 销售的营销代码(此代码船公司会直接提供)"; + } + else + { + //if (carrier != "YML") + //error = error + "
提单号:" + bill.MBLNO + " EDI备注中不能为空"; + } + } + else + { + + if (StringIsChinese(headData.SIREMARK)) + { + error = error + "
提单号:" + headData.MBLNO + " SI备注中含有中文或双字节字符"; + } + + } + } + else + { + if (headData.EDIREMARK.IndexOf("PLEASE BOOK OCEAN CARRIER") > -1 || headData.EDIREMARK.ToString().Trim() == "") + { + if (headData.CARRIEREDICODE == "COSU") + { + error = error + "
提单号:" + headData.MBLNO + " 请在EDI备注中输入:COSCO 销售的营销代码(此代码船公司会直接提供)"; + } + else + { + //if (carrier != "YML") + //error = error + "
提单号:" + bill.MBLNO + " EDI备注中不能为空"; + } + } + else + { + /* + 2023-04-03 经过确认德翔需要能导出带中文的EDIREMARK,这里校验去掉 + if (StringIsChinese(headData.EDIREMARK)) + { + error = error + "
提单号:" + headData.MBLNO + " EDI备注中含有中文或双字节字符"; + } + */ + } + } + //if (string.IsNullOrEmpty(headData.CARRIER)) + //{ error = error + "
提单号:" + headData.MBLNO + " 船公司不能为空"; } + + if (string.IsNullOrEmpty(headData.CARRIEREDICODE)) + { error = error + "
提单号:" + headData.MBLNO + " 船公司EDI代码不能为空"; } + + + if (string.IsNullOrEmpty(headData.SHIPPER)) + { + error = error + "
提单号:" + headData.MBLNO + " 发货人不能为空"; + } + else + { + if (StringIsChinese(headData.SHIPPER)) + { + error = error + "
提单号:" + headData.MBLNO + " 发货人含有中文或双字节字符"; + } + else + { + if (headData.CARRIEREDICODE == "HLCU") + { + error += formatlengthError("txt", headData.SHIPPER, 35, headData.MBLNO, "发货人", 6, "-", false); + } + else + { + //2023-03-02 测试发现与东胜的限制行数不同,东胜是8行,跟韩工确认限制从6改为8 + //2023-06-19 合川操作提出收、发、通需要能录超过最大8行,查看TSL报文,允许最大10行,将最大8行改为10行 + error += formatlengthError("txt", headData.SHIPPER, 35, headData.MBLNO, "发货人", 10, "*", false); + } + } + } + //} + + + + if (string.IsNullOrEmpty(headData.CONSIGNEE)) + { + error = error + "
提单号:" + headData.MBLNO + " 收货人不能为空"; + } + else + { + if (StringIsChinese(headData.CONSIGNEE)) + { + error = error + "
提单号:" + headData.MBLNO + " 收货人含有中文或双字节字符"; + } + else + { + if (headData.CARRIEREDICODE == "HLCU") + { + error += formatlengthError("txt", headData.CONSIGNEE, 35, headData.MBLNO, "收货人", 6, "--", false); + } + else + { + //2023-03-02 测试发现与东胜的限制行数不同,东胜是8行,跟韩工确认限制从6改为8 + //2023-06-19 合川操作提出收、发、通需要能录超过最大8行,查看TSL报文,允许最大10行,将最大8行改为10行 + error += formatlengthError("txt", headData.CONSIGNEE, 35, headData.MBLNO, "收货人", 10, "**", false); + } + } + } + + + if (headData.SERVICE == "CY-DOOR") + { + if (string.IsNullOrEmpty(headData.CONSIGNEEDOORADDR)) + { + error = error + "
提单号:" + headData.MBLNO + " 运输条款为:CY-DOOR,EDI信息中的DOOR地址不能为空"; + } + else + { + if (StringIsChinese(headData.CONSIGNEEDOORADDR)) + { + error = error + "
提单号:" + headData.MBLNO + " DOOR地址含有中文或双字节字符"; + } + } + } + if (headData.SERVICE == "DOOR-CY") + { + if (string.IsNullOrEmpty(headData.SHIPPERDOORADDR)) + { + error = error + "
提单号:" + headData.MBLNO + " 运输条款为:DOOR-CY,EDI信息中的联系人地址不能为空"; + } + else + { + if (StringIsChinese(headData.SHIPPERDOORADDR)) + { + error = error + "
提单号:" + headData.MBLNO + " 联系人地址含有中文或双字节字符"; + } + } + } + + + if (string.IsNullOrEmpty(headData.NOTIFYPARTY)) + { + error = error + "
提单号:" + headData.MBLNO + " 通知人不能为空"; + } + else + { + if (StringIsChinese(headData.NOTIFYPARTY)) + { + error = error + "
提单号:" + headData.MBLNO + " 通知人含有中文或双字节字符"; + } + else + { + if (headData.CARRIEREDICODE == "HLCU") + { + error += formatlengthError("txt", headData.NOTIFYPARTY, 35, headData.MBLNO, "通知人", 6, "---", false); + } + else + { + //2023-03-02 测试发现与东胜的限制行数不同,东胜是8行,跟韩工确认限制从6改为8 + //2023-06-19 合川操作提出收、发、通需要能录超过最大8行,查看TSL报文,允许最大10行,将最大8行改为10行 + error += formatlengthError("txt", headData.NOTIFYPARTY, 35, headData.MBLNO, "通知人", 10, "***", false); + } + } + } + + if (!string.IsNullOrEmpty(headData.NOTIFYPARTY2)) + { + error += formatlengthError("txt", headData.NOTIFYPARTY2, 35, headData.MBLNO, "第二通知人", 5, "", false); + } + + if (string.IsNullOrEmpty(headData.MARKS)) + { + error = error + "
提单号:" + headData.MBLNO + " 唛头不能为空"; + } + else + { + if (StringIsChinese(headData.MARKS)) + { + error = error + "
提单号:" + headData.MBLNO + " 唛头含有中文或双字节字符"; + } + else + { + error += formatlengthError("txt", headData.MARKS, 35, headData.MBLNO, "唛头", 0, "", false); + } + } + + if (string.IsNullOrEmpty(headData.DESCRIPTION)) + { + error = error + "
提单号:" + headData.MBLNO + " 货物描述不能为空"; + } + else + { + if (StringIsChinese(headData.DESCRIPTION)) + { + error = error + "
提单号:" + headData.MBLNO + " 货物描述含有中文或双字节字符"; + } + else + { + //error += formatlengthError("txt", bill.DESCRIPTION, 35, bill.MBLNO, "货物描述", 0, ""); + } + } + if (string.IsNullOrEmpty(headData.PORTLOADID) || headData.PORTLOADID.Length != 5) + { error = error + "
提单号:" + headData.MBLNO + " 装货港代码不能为空或录入不正确(必须是5位代码)"; } + + if (string.IsNullOrEmpty(headData.PORTLOAD)) + { error = error + "
提单号:" + headData.MBLNO + " 装货港不能为空"; } + + if (string.IsNullOrEmpty(headData.ETD)) + { + error = error + "
提单号:" + headData.MBLNO + " 开船日期不能为空"; + return error; + } + if (string.IsNullOrEmpty(headData.PORTDISCHARGEID) || headData.PORTDISCHARGEID.Length != 5) + { error = error + "
提单号:" + headData.MBLNO + " 卸货港代码不能为空或录入不正确(必须是5位代码)"; } + if (string.IsNullOrEmpty(headData.PORTDISCHARGE)) + { error = error + "
提单号:" + headData.MBLNO + " 卸货港不能为空"; } + if (string.IsNullOrEmpty(headData.DESTINATION)) + { + if (string.IsNullOrEmpty(headData.DESTINATIONID) || headData.DESTINATIONID.Length != 5) + { error = error + "
提单号:" + headData.MBLNO + " 目的地代码不能为空或录入不正确(必须是5位代码)"; } + } + if (string.IsNullOrEmpty(headData.KINDPKGS_EDI_CODE)) + { error = error + "
提单号:" + headData.MBLNO + " 包装EDI代码不能为空"; } + if (headData.PKGS == 0) + { error = error + "
提单号:" + headData.MBLNO + " 件数不能为0"; } + if (headData.KGS == 0) + { error = error + "
提单号:" + headData.MBLNO + " 毛重不能为0"; } + if (headData.CBM == 0) + { error = error + "
提单号:" + headData.MBLNO + " 尺码不能为0"; } + + if (headData.CARGOID == "D") + { + if (string.IsNullOrEmpty(headData.DCLASS)) + { error = error + "
提单号:" + headData.MBLNO + " 危险品分类不能为空"; } + + if (string.IsNullOrEmpty(headData.DUNNO)) + { error = error + "
提单号:" + headData.MBLNO + " 危险品编号不能为空"; } + } + if (headData.CARGOID == "R") + { + if (headData.TEMPSET == null || headData.TEMPSET == "") + { error = error + "
提单号:" + headData.MBLNO + " 设置温度不能为空"; } + if (headData.REEFERF == null || headData.REEFERF == "") + { error = error + "
提单号:" + headData.MBLNO + " 通风度不能为空"; } + } + + if (headData.BLFRT != null && headData.BLFRT.IndexOf("PREPAID") >= 0) + { + if (string.IsNullOrEmpty(headData.PREPARDAT)) + { error = error + "
提单号:" + headData.MBLNO + " 预付地点不能为空"; } + if (string.IsNullOrEmpty(headData.PREPARDATID)) + { error = error + "
提单号:" + headData.MBLNO + " 预付地点EDI代码不能为空"; } + } + else if (headData.BLFRT != null && headData.BLFRT.IndexOf("COLLECT") >= 0) + { + if (string.IsNullOrEmpty(headData.PAYABLEAT)) + { error = error + "
提单号:" + headData.MBLNO + " 到付地点不能为空"; } + if (string.IsNullOrEmpty(headData.PAYABLEATID)) + { error = error + "
提单号:" + headData.MBLNO + " 到付地点EDI代码不能为空"; } + } + + if (InttrEdi.filetype == "E") + { + if (string.IsNullOrEmpty(headData.ISSUEPLACEID)) + { error = error + "
提单号:" + headData.MBLNO + " 签单地点或到签单地点EDI代码不能为空"; } + } + var ctnlist = headData.CTNLIST; + if (ctnlist.Count == 0) { error = error + "
提单号:" + headData.MBLNO + " 集装箱信息不能为空"; }; + + if (InttrEdi.filetype == "E") + { + #region 集装箱判断检查 + if (ctnlist.Count != 0) + { + Decimal dlPKGS = 0; + Decimal dlKGS = 0; + Decimal dlCBM = 0; + foreach (var ctn in ctnlist) + { + if (string.IsNullOrEmpty(ctn.CTNALLCODE)) + { error = error + "
提单号:" + headData.MBLNO + " 集装箱箱型EDI代码不能为空"; } + if (string.IsNullOrEmpty(ctn.CNTRNO)) + { error = error + "
提单号:" + headData.MBLNO + " 箱号不能为空"; } + if (string.IsNullOrEmpty(ctn.SEALNO)) + { error = error + "
提单号:" + headData.MBLNO + " 封号不能为空"; } + if (headData.BYCOUNTRY == "BRAZIL") + { + if (ctn.TAREWEIGHT == 0) + { error = error + "
提单号:" + headData.MBLNO + " 箱皮重不能为空"; } + } + if (ctn.KINDPKGS != headData.KINDPKGS) + { error = error + "
提单号:" + headData.MBLNO + " 中的包装类型与集装箱的包装类型不同"; } + dlPKGS += Convert.ToDecimal(ctn.PKGS); + dlKGS += Convert.ToDecimal(ctn.KGS); + dlCBM += Convert.ToDecimal(ctn.CBM); + } + + if (dlPKGS != Convert.ToDecimal(headData.PKGS)) + { error = error + "
提单号:" + headData.MBLNO + " 集装箱件数合计数必须等于委托单总件数"; } + if (dlKGS != Convert.ToDecimal(headData.KGS)) + { error = error + "
提单号:" + headData.MBLNO + " 集装箱重量合计数必须等于委托单总重量数"; } + if (dlCBM != Convert.ToDecimal(headData.CBM)) + { error = error + "
提单号:" + headData.MBLNO + " 集装箱尺码合计数必须等于委托单总尺码数"; } + } + if (headData.CTNGOODSLIST != null && headData.CTNGOODSLIST.Count > 0) + { + foreach (var ctn in ctnlist) + { + var isfind = false; + Int32 ctngoodssumpkgs = 0; + decimal ctngoodssumkgs = 0; + decimal ctngoodssumcbm = 0; + headData.CTNGOODSLIST.ForEach(i => + { + if (i.CNTRNO == ctn.CNTRNO) + { + isfind = true; + ctngoodssumpkgs = ctngoodssumpkgs + i.PKGS; + ctngoodssumkgs = ctngoodssumkgs + i.KGS; + ctngoodssumcbm = ctngoodssumcbm + i.CBM; + } + }); + if (!isfind) + { + error = error + "
提单号:" + headData.MBLNO + "的“" + ctn.CNTRNO + "”未添加分箱明细!"; + } + else + { + if (ctngoodssumpkgs != Convert.ToDecimal(ctn.PKGS)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctn.CNTRNO + " 分箱明细件数合计数不等于集装箱件数"; } + if (ctngoodssumkgs != Convert.ToDecimal(ctn.KGS)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctn.CNTRNO + " 分箱明细毛重合计数不等于集装箱毛重"; } + if (ctngoodssumcbm != Convert.ToDecimal(ctn.CBM)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctn.CNTRNO + " 分箱明细尺码合计数不等于集装箱毛重"; } + + } + + } + + foreach (var ctngood in headData.CTNGOODSLIST) + { + if (string.IsNullOrEmpty(ctngood.KINDPKGS)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱明细包装类型不能为空"; } + if (string.IsNullOrEmpty(ctngood.DESCRIPTION)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱货物描述不能为空"; } + else + { + error += formatlengthError("txt", ctngood.DESCRIPTION, 70, headData.MBLNO, "的“" + ctngood.CNTRNO + "”箱号的分箱货物描述", 0, "", false); + } + //if (string.IsNullOrEmpty(ctngood.HSCODE)) + //{ error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱HS编码不能为空"; } + if (string.IsNullOrEmpty(ctngood.KINDPKGS_EDI_CODE)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱明细包装类型代码不能为空"; } + + } + + } + + #endregion + + + } + + } + return error; + } + #endregion + + #region 订舱 + public static EdiDataResult CreateEdiTSL(EDIBaseModel InttrEdi) + { + var result = new EdiDataResult { Succeeded = false }; + + string bno = InttrEdi.BSLIST[0].MBLNO; + + if (string.IsNullOrWhiteSpace(bno)) + bno = InttrEdi.BSLIST[0].ORDERNO; + + string filename = InttrEdi.filerpath + "\\" + bno + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt"; + + //如果是部署linux需要修改路径 + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + filename = filename.Replace("\\", "/"); + + //if (System.IO.File.Exists(filename)) + //{ + // System.IO.File.Delete(filename); + //} + FileStream f = new FileStream(filename, FileMode.Create); + StreamWriter r = new StreamWriter(f, Encoding.Default); + var icount = 0; + var bsno = ""; + + //2023-05-04 多次现取当前日期改完生成一下,公用一个日期 + DateTime nowDate = DateTime.Now; + foreach (var bill in InttrEdi.BSLIST) + { + bsno = bill.ORDERNO; + r.WriteLine("UNB+UNOC:2+" + InttrEdi.SENDCODE + "SO:ZZZ+" + InttrEdi.RECEIVECODE + ":UN+" + nowDate.ToString("yyMMdd:HHmm") + "+" + bill.ORDERNO + "'"); + /* + * 2023-03-02 这里对比了和川的报文,UNH后面取的是提单号,经过韩工确认这里改为取提单号 + 原代码 r.WriteLine("UNH+" + bill.ORDERNO + "+IFTMBF:D:99B:UN'"); + + * 2023-05-19 董怡含反馈主提单号订舱时不填,考虑实际情况,变更为填写bill.ORDERNO + */ + r.WriteLine("UNH+" + bill.ORDERNO + "+IFTMBF:D:99B:UN'"); + icount = icount + 2; + + if (InttrEdi.filerole == "9") + r.WriteLine("BGM+335+" + bill.ORDERNO + "+9'"); + else if (InttrEdi.filerole == "1") + r.WriteLine("BGM+335+" + bill.ORDERNO + "+1'"); + else + r.WriteLine("BGM+335+" + bill.ORDERNO + "+5'"); + + + r.WriteLine("DTM+137:" + nowDate.ToString("yyyyMMddHHmm") + ":203'"); + icount = icount + 2; + + var Shipping = ""; + Shipping = formatEdiStr("txt", bill.EDIREMARK); + Shipping = Shipping.Replace("\n", "\\"); + Shipping = Shipping.Replace("\r", " "); + string[] EdiRemarkList = Shipping.Split('\\'); + if (EdiRemarkList.Length != 0) + { + + for (var i = 0; i < EdiRemarkList.Length; i++) + { + r.WriteLine("FTX+AAI+++" + EdiRemarkList[i] + "'"); + icount = icount + 1; + + } + } + r.WriteLine("RFF+FF:" + bill.ORDERNO.Trim() + "'"); + icount = icount + 1; + if (!string.IsNullOrEmpty(bill.CONTRACTNO)) + { + r.WriteLine("RFF+CT:" + bill.CONTRACTNO.Trim() + "'"); + icount = icount + 1; + } + + /*件重尺*/ + r.WriteLine("CNT+7:" + Math.Round(Convert.ToDecimal(bill.KGS), 3) + ":KGM'");//按照四舍五入的国际标准 + r.WriteLine("CNT+11:" + bill.PKGS.ToString() + "'"); + r.WriteLine("CNT+15:" + Math.Round(Convert.ToDecimal(bill.CBM), 3) + ":MTQ'"); + + icount = icount + 3; + + /* 2023-03-01 跟韩工确认,去掉这个UASC的判断,默认应该要显示CNT+16的信息 + if (bill.CARRIEREDICODE == "UASC") + { + if (bill.CTNLIST.Count > 0) + { + var ctnnum = 0; + foreach (var ctn in bill.CTNLIST) + { + ctnnum = ctnnum + ctn.CTNNUM; + } + r.WriteLine("CNT+16:" + ctnnum.ToString() + "'"); + icount = icount + 1; + } + + } + */ + + //2023-03-01 跟韩工确认,去掉这个UASC的判断,默认应该要显示CNT+16的信息,以下是新修改 + if (bill.CTNLIST.Count > 0) + { + var ctnnum = 0; + foreach (var ctn in bill.CTNLIST) + { + ctnnum = ctnnum + ctn.CTNNUM; + } + r.WriteLine("CNT+16:" + ctnnum.ToString() + "'"); + icount = icount + 1; + } + + if (bill.SERVICE.ToUpper() == "DOOR-DOOR") + { + r.WriteLine("TSR+27+2'"); + } + else if (bill.SERVICE.ToUpper() == "DOOR-CY") + { + r.WriteLine("TSR+28+2'"); + } + else if (bill.SERVICE.ToUpper() == "CY-DOOR") + { + r.WriteLine("TSR+29+2'"); + } + else + { + r.WriteLine("TSR+30+2'"); + } + + icount = icount + 1; + + var copynum = GetBillNum(bill.COPYNOBILL); + + //2023-03-02 测试这里有问题,签单方式用的中文,要改成英文正本-ORIGINAL 电放-TELEX + //if (bill.ISSUETYPE == "正本") + if (bill.ISSUETYPE == "ORIGINAL") + { + r.WriteLine("DOC+706+:26++" + GetBillNum(bill.NOBILL) + "'"); + icount = icount + 1; + if (!string.IsNullOrWhiteSpace(copynum)) + { + r.WriteLine("DOC+707+:26++" + copynum + "'"); + icount = icount + 1; + } + + } + else if (bill.ISSUETYPE == "海运单" || bill.ISSUETYPE.ToUpper() == "SEAWAY" || bill.ISSUETYPE.ToUpper() == "SEAWAY BILL" || bill.ISSUETYPE.ToUpper() == "WAYBILL" || bill.ISSUETYPE.ToUpper() == "SWB正本" || bill.ISSUETYPE.ToUpper() == "SWB无正本") + { + r.WriteLine("DOC+710+:26++" + GetBillNum(bill.NOBILL) + "'"); + icount = icount + 1; + + } + //else if (bill.ISSUETYPE.ToUpper() == "BILL COPY" || bill.ISSUETYPE == "电放") + else if (bill.ISSUETYPE.ToUpper() == "BILL COPY" || bill.ISSUETYPE == "TELEX") + { + r.WriteLine("DOC+706+:26++" + GetBillNum(bill.NOBILL) + "'"); + icount = icount + 1; + if (!string.IsNullOrWhiteSpace(copynum)) + { + r.WriteLine("DOC+707+:26++" + copynum + "'"); + icount = icount + 1; + } + + } + else if (bill.ISSUETYPE == "正副本") + { + r.WriteLine("DOC+706+:26++" + GetBillNum(bill.NOBILL) + "'"); + icount = icount + 1; + if (!string.IsNullOrWhiteSpace(copynum)) + { + r.WriteLine("DOC+707+:26++" + copynum + "'"); + icount = icount + 1; + } + + } + else if (bill.ISSUETYPE.ToUpper() == "HOUSE BILL") + { + r.WriteLine("DOC+714+:26++" + GetBillNum(bill.NOBILL) + "'"); + icount = icount + 1; + + } + + if (bill.BLFRT.ToUpper().IndexOf("PREPAID") > 0) + { + r.WriteLine("CPI+4++P'"); + icount = icount + 1; + } + else if (bill.BLFRT.ToUpper().IndexOf("COLLECT") > 0) + { + r.WriteLine("CPI+4++C'"); + icount = icount + 1; + } + else + { + r.WriteLine("CPI+4++B'"); + icount = icount + 1; + + } + + + + if (bill.BLFRT == "FREIGHT COLLECT") + { + if (!string.IsNullOrWhiteSpace(bill.PAYABLEAT)) + { + r.WriteLine("LOC+57+" + bill.PAYABLEATID + "::6:" + bill.PAYABLEAT + "'"); + icount = icount + 1; + } + } + else + { + r.WriteLine("LOC+57+" + bill.PREPARDATID + "::6:" + bill.PREPARDAT + "'"); + icount = icount + 1; + + } + + var voyno = ""; + if (!string.IsNullOrEmpty(bill.NVOYNO)) voyno = bill.NVOYNO; else voyno = bill.VOYNO; + + if (voyno.IndexOf(".") >= 0) + voyno = voyno.Substring(voyno.IndexOf(".") + 1, voyno.Length - voyno.IndexOf(".") - 1); + + + r.WriteLine("TDT+20+" + voyno + "+1++" + bill.CARRIEREDICODE + ":172+++:::" + bill.VESSEL + "'"); + r.WriteLine("DTM+133:" + Convert.ToDateTime(bill.ETD).ToString("yyyyMMdd") + ":102'");//yyyyMMddHHmm + r.WriteLine("LOC+88+" + bill.PORTLOADID + "::6:" + bill.PORTLOAD + "+'"); + r.WriteLine("LOC+9+" + bill.PORTLOADID + "::6:" + bill.PORTLOAD + "+'"); + r.WriteLine("LOC+11+" + bill.PORTDISCHARGEID + "::6:" + bill.PORTDISCHARGE + "+'"); + icount = icount + 5; + + if (!string.IsNullOrWhiteSpace(bill.DESTINATION)) + { + r.WriteLine("LOC+7+" + bill.DESTINATIONID + "::6:" + bill.DESTINATION + "+'"); + icount = icount + 1; + } + r.WriteLine("NAD+CA+" + bill.CARRIEREDICODE + ":160:86++" + GetCarrierName(bill.CARRIEREDICODE) + "'"); + icount = icount + 1; + + if (InttrEdi.SENDNAME.Length > 35) + r.WriteLine("NAD+HI+" + InttrEdi.SENDCODE + ":160:86++" + formatEdiStr("txt", InttrEdi.SENDNAME.Substring(0, 35)) + "+" + formatEdiStr("txt", InttrEdi.SENDNAME.Substring(35)) + "'"); + else + r.WriteLine("NAD+HI+" + InttrEdi.SENDCODE + ":160:86++" + formatEdiStr("txt", InttrEdi.SENDNAME) + "'"); + + //r.WriteLine("CTA+IC+:" +billams.ATTN+ "'"); + //r.WriteLine("COM+" +billams.ATTNTEL+ ":TE'"); + //r.WriteLine("COM+" + billams.ATTNEMAIL + ":EM'"); + + + r.WriteLine("CTA+IC+:" + bill.OpEName + "'"); + r.WriteLine("COM+" + bill.OpTel + ":TE'"); + r.WriteLine("COM+" + bill.OpEmail + ":EM'"); + + //2023-03-01 跟韩工确认这里FX不处理了,东胜还有。 + + r.WriteLine("NAD+MR+++" + formatEdiStr("txt", InttrEdi.SENDNAME) + "'"); + //r.WriteLine("CTA+NT+:" +billams.ATTN+ "'"); + //r.WriteLine("COM+" + billams.ATTNEMAIL + ":EM'"); + r.WriteLine("CTA+NT+:" + bill.OpEName + "'"); + r.WriteLine("COM+" + bill.OpEmail + ":EM'"); + + icount = icount + 7; + + if (!string.IsNullOrWhiteSpace(bill.WEITUO)) + { + if (bill.WEITUO.Length > 35) + r.WriteLine("NAD+FW+++" + formatEdiStr("txt", bill.WEITUO.Substring(0, 35)) + "+" + formatEdiStr("txt", bill.WEITUO.Substring(35)) + "'"); + else + r.WriteLine("NAD+FW+++" + formatEdiStr("txt", bill.WEITUO) + "'"); + icount = icount + 1; + + } + else + { + + if (InttrEdi.UseForWarderCode) + { + r.WriteLine("NAD+FW+" + InttrEdi.ForWarderCode + ":160:86++" + InttrEdi.ForWarderName + "'"); + icount++; + } + else + { + if (InttrEdi.SENDNAME.Length > 35) + r.WriteLine("NAD+FW+" + InttrEdi.SENDCODE + ":160:86++" + formatEdiStr("txt", InttrEdi.SENDNAME.Substring(0, 35)) + "+" + formatEdiStr("txt", InttrEdi.SENDNAME.Substring(35)) + "'"); + else + r.WriteLine("NAD+FW+" + InttrEdi.SENDCODE + ":160:86++" + formatEdiStr("txt", InttrEdi.SENDNAME) + "'"); + icount = icount + 1; + + } + } + + if (InttrEdi.UseForWarderCode) + { + r.WriteLine("NAD+BA+" + InttrEdi.ForWarderCode + ":160:86++" + InttrEdi.ForWarderName + "'"); + icount++; + r.WriteLine("CTA+IC+:" + bill.OpEName + "'"); + r.WriteLine("COM+" + bill.OpTel + ":TE'"); + r.WriteLine("COM+" + bill.OpEmail + ":EM'"); + icount = icount + 3; + } + + + + + Shipping = ""; + var DescriptionShipper = ""; + Shipping = formatEdiStr("txt", bill.SHIPPER); + + List ShippingList = formatlengthStr(Shipping, 35); + + //2023-03-16 测试比对德翔有固定发货方代码,从FTP配置读取 + string sendShipperCode = string.Empty; + + if (!string.IsNullOrWhiteSpace(InttrEdi.SENDSHIPPERCODE)) + { + sendShipperCode = InttrEdi.SENDSHIPPERCODE?.Trim(); + } + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + for (var i = 0; i < ShippingList.Count; i++) + { + if (i == 0) Shipping = "NAD+CZ+" + sendShipperCode + "++" + ShippingList[0] + "+"; + if (i == 1) Shipping = Shipping + ShippingList[i]; + if (i == 2 || i == 3) Shipping = Shipping + ":" + ShippingList[i]; + if (i >= 4 && ShippingList.Count > 5) + { + if (i == 4) + { + if (ShippingList[i].Length > 34) + { + Shipping = Shipping + ":" + ShippingList[i].Substring(0, 34); + DescriptionShipper = ShippingList[i].Substring(34); + } + else + Shipping = Shipping + ":" + ShippingList[i]; + if (bill.CARRIEREDICODE == "HLCU") + { + Shipping = Shipping + "-"; + DescriptionShipper = "-" + DescriptionShipper; + } + else + { + Shipping = Shipping + "*"; + DescriptionShipper = "*" + DescriptionShipper; + } + + } + else if (i > 4) + { + + DescriptionShipper = DescriptionShipper + " " + ShippingList[i]; + } + + } + else + if (i == 4) Shipping = Shipping + ":" + ShippingList[i]; + } + } + + r.WriteLine(Shipping + "'"); + icount = icount + 1; + + Shipping = formatEdiStr("txt", bill.CONSIGNEE); + ShippingList = formatlengthStr(Shipping, 35); + + var DescriptionConsignee = ""; + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + + for (var i = 0; i < ShippingList.Count; i++) + { + if (i == 0) Shipping = "NAD+CN+++" + ShippingList[0] + "+"; + if (i == 1) Shipping = Shipping + ShippingList[i]; + if (i == 2 || i == 3) Shipping = Shipping + ":" + ShippingList[i]; + if (i >= 4 && ShippingList.Count > 5) + { + if (i == 4) + { + if (ShippingList[i].Length > 33) + { + Shipping = Shipping + ":" + ShippingList[i].Substring(0, 33); + DescriptionConsignee = ShippingList[i].Substring(33); + } + else + Shipping = Shipping + ":" + ShippingList[i]; + if (bill.CARRIEREDICODE == "HLCU") + { + Shipping = Shipping + "--"; + DescriptionConsignee = "--" + DescriptionConsignee; + } + else + { + Shipping = Shipping + "**"; + DescriptionConsignee = "**" + DescriptionConsignee; + } + + } + else if (i > 4) + { + + DescriptionConsignee = DescriptionConsignee + " " + ShippingList[i]; + } + + } + else + if (i == 4) Shipping = Shipping + ":" + ShippingList[i]; + } + } + + if (bill.BYCOUNTRY == "USA") + { + Shipping = Shipping + "+++" + bill.CONSIGNEEPOSTCODE; + r.WriteLine(Shipping + "'"); + } + else if (bill.BYCOUNTRY == "CANADA") + { + Shipping = Shipping + "+++" + bill.CONSIGNEEPOSTCODE + "+CA"; + r.WriteLine(Shipping + "'"); + } + else if (bill.BYCOUNTRY == "BRAZIL") + { + Shipping = Shipping + "++++" + bill.CONSIGNEECOUNTRY; + r.WriteLine(Shipping + "'"); + r.WriteLine("RFF+GN:" + bill.CONSIGNEETAXNO + "'"); + icount = icount + 1; + + } + else r.WriteLine(Shipping + "'"); + + icount = icount + 1; + + Shipping = formatEdiStr("txt", bill.NOTIFYPARTY); + ShippingList = formatlengthStr(Shipping, 35); + + var DescriptionNotifyparty = ""; + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + + for (var i = 0; i < ShippingList.Count; i++) + { + if (i == 0) Shipping = "NAD+NI+++" + ShippingList[0] + "+"; + if (i == 1) Shipping = Shipping + ShippingList[i]; + if (i == 2 || i == 3) Shipping = Shipping + ":" + ShippingList[i]; + if (i >= 4 && ShippingList.Count > 5) + { + if (i == 4) + { + if (ShippingList[i].Length > 32) + { + Shipping = Shipping + ":" + ShippingList[i].Substring(0, 32); + DescriptionNotifyparty = ShippingList[i].Substring(32); + } + else + Shipping = Shipping + ":" + ShippingList[i]; + if (bill.CARRIEREDICODE == "HLCU") + { + Shipping = Shipping + "---"; + DescriptionNotifyparty = "---" + DescriptionNotifyparty; + } + else + { + Shipping = Shipping + "***"; + DescriptionNotifyparty = "***" + DescriptionNotifyparty; + } + + } + else if (i > 4) + { + + DescriptionNotifyparty = DescriptionNotifyparty + " " + ShippingList[i]; + } + + } + else + if (i == 4) Shipping = Shipping + ":" + ShippingList[i]; + } + } + + if (bill.BYCOUNTRY == "USA") + { + Shipping = Shipping + "+++" + bill.NOTIFYPARTYPOSTCODE; + r.WriteLine(Shipping + "'"); + } + else if (bill.BYCOUNTRY == "BRAZIL") + { + if (bill.NOTIFYPARTYCOUNTRY != "") + Shipping = Shipping + "++++" + bill.NOTIFYPARTYCOUNTRY; + r.WriteLine(Shipping + "'"); + if (bill.NOTIFYPARTYTAXNO != "") + { + r.WriteLine("RFF+GN:" + bill.NOTIFYPARTYTAXNO + "'"); + icount = icount + 1; + + } + } + else r.WriteLine(Shipping + "'"); + icount = icount + 1; + + + + + r.WriteLine("GID+1+" + bill.PKGS.ToString() + ":" + bill.KINDPKGS_EDI_CODE + "::6:" + bill.KINDPKGS + "'"); + + icount = icount + 1; + if (bill.CARGOID == "R") + { + r.WriteLine("GDS+14'"); + icount = icount + 1; + } + else if (bill.CARGOID == "D") + { + r.WriteLine("GDS+11'"); + icount = icount + 1; + + } + else if (bill.CARGOID == "O") + { + r.WriteLine("GDS+5'"); + icount = icount + 1; + + } + + + if (!string.IsNullOrWhiteSpace(bill.HSCODE)) + { + r.WriteLine("PIA+5+" + bill.HSCODE + ":HS'"); + icount = icount + 1; + + } + Shipping = formatEdiStr("txt", bill.DESCRIPTION); + Shipping = Shipping.Replace("\n", "\\"); + Shipping = Shipping.Replace("\r", " "); + string[] DescriptionList = Shipping.Split('\\'); + if (DescriptionList.Length != 0) + { + + for (var i = 0; i < DescriptionList.Length; i++) + { + r.WriteLine("FTX+AAA+++" + DescriptionList[i] + "'"); + icount = icount + 1; + + } + } + if (!string.IsNullOrWhiteSpace(DescriptionShipper)) + { + r.WriteLine("FTX+AAA+++" + DescriptionShipper + "'"); + icount = icount + 1; + + } + if (!string.IsNullOrWhiteSpace(DescriptionConsignee)) + { + r.WriteLine("FTX+AAA+++" + DescriptionConsignee + "'"); + icount = icount + 1; + + } + if (!string.IsNullOrWhiteSpace(DescriptionNotifyparty)) + { + r.WriteLine("FTX+AAA+++" + DescriptionNotifyparty + "'"); + icount = icount + 1; + + } + + r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(Convert.ToDecimal(bill.KGS), 3) + "'"); + r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(Convert.ToDecimal(bill.CBM), 3) + "'"); + icount = icount + 2; + + Shipping = formatEdiStr("txt", bill.MARKS); + + Shipping = Shipping.Replace("\n", "\\"); + Shipping = Shipping.Replace("\r", " "); + string[] MarksList = Shipping.Split('\\'); + if (MarksList.Length != 0) + { + + for (var i = 0; i < MarksList.Length; i++) + { + r.WriteLine("PCI++" + MarksList[i] + "'"); + icount = icount + 1; + + } + } + if (bill.CARGOID == "D") + { + r.WriteLine("DGS+IMD+" + bill.DCLASS + "+" + bill.DUNNO + "'"); + r.WriteLine("CTA+HG+:" + bill.EDIATTN + "'"); + r.WriteLine("COM+" + bill.EDIATTNTEL + ":TE'"); + icount = icount + 3; + } + + var ctnsumlist = new List(); + foreach (var ctn in bill.CTNLIST) + { + var isfind = false; + ctnsumlist.ForEach(i => + { + if (i.CTNALLCODE == ctn.CTNALLCODE) + { + i.CTNNUM = i.CTNNUM + ctn.CTNNUM; + isfind = true; + } + }); + if (!isfind) + { + var ctnnum = new SeaExportCtnEDIBaseModel(); + ctnnum.CTNALLCODE = ctn.CTNALLCODE; + ctnnum.CTNNUM = ctn.CTNNUM; + ctnsumlist.Add(ctnnum); + } + } + foreach (var ctn in ctnsumlist) + { + if (bill.ISCONTAINERSOC) + r.WriteLine("EQD+CN++" + ctn.CTNALLCODE + "+1'"); + else + r.WriteLine("EQD+CN++" + ctn.CTNALLCODE + "+2'"); + + icount = icount + 1; + + if (bill.CARGOID == "R") + { + if (!string.IsNullOrWhiteSpace(bill.REEFERF)) + { + r.WriteLine("MEA+AAE+AAS+CBM:" + bill.REEFERF + "'"); + icount = icount + 1; + } + + if (!string.IsNullOrWhiteSpace(bill.HUMIDITY)) + { + r.WriteLine("MEA+AAE+AAO+HMD:" + bill.HUMIDITY + "'"); + icount = icount + 1; + } + } + + r.WriteLine("EQN+" + ctn.CTNNUM.ToString() + "'"); + icount = icount + 1; + + if (bill.CARGOID == "R") + { + r.WriteLine("TMP+2+" + bill.TEMPSET + ":CEL'"); + icount = icount + 1; + } + } + + } + r.WriteLine("UNT+" + icount.ToString() + "+" + bsno + "'"); + r.WriteLine("UNZ+" + InttrEdi.BSLIST.Count.ToString() + "+" + bsno + "'"); + r.Close(); + f.Close(); + + result.Succeeded = true; + result.ExtraData1 = filename; + return result; + } + #endregion + + #region 确认 + public static EdiDataResult CreateEdiTSLSI(EDIBaseModel InttrEdi) + { + var result = new EdiDataResult { Succeeded = false }; + + string filename = InttrEdi.filerpath + "\\" + InttrEdi.BSLIST[0].MBLNO + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt"; + + //if (System.IO.File.Exists(filename)) + //{ + // System.IO.File.Delete(filename); + //} + FileStream f = new FileStream(filename, FileMode.Create); + StreamWriter r = new StreamWriter(f, Encoding.Default); + + var icount = 0; + var bsno = ""; + foreach (var bill in InttrEdi.BSLIST) + { + bsno = bill.ORDERNO; + r.WriteLine("UNB+UNOC:2+" + InttrEdi.SENDCODE + ":ZZZ+" + InttrEdi.RECEIVECODE + ":UN+" + DateTime.Now.ToString("yyMMdd:HHmm") + "+" + bill.ORDERNO + "'"); + r.WriteLine("UNH+" + bill.ORDERNO + "+IFTMIN:D:99B:UN'"); + if (InttrEdi.filerole == "9") + r.WriteLine("BGM+340+" + bill.MBLNO + "+9'"); + else + r.WriteLine("BGM+340+" + bill.MBLNO + "+5'"); + + icount = icount + 3; + + var Shipping = ""; + Shipping = formatEdiStr("txt", bill.SIREMARK); + Shipping = Shipping.Replace("\n", "\\"); + Shipping = Shipping.Replace("\r", " "); + string[] EdiRemarkList = Shipping.Split('\\'); + if (EdiRemarkList.Length != 0) + { + + for (var i = 0; i < EdiRemarkList.Length; i++) + { + r.WriteLine("FTX+AAI+++" + EdiRemarkList[i] + "'"); + icount = icount + 1; + + } + } + + r.WriteLine("RFF+BN:" + bill.MBLNO + "'"); + icount = icount + 1; + + r.WriteLine("RFF+BM:" + bill.MBLNO + "'"); + icount = icount + 1; + r.WriteLine("RFF+SI:" + bill.MBLNO + "'"); + icount = icount + 1; + + if (!string.IsNullOrEmpty(bill.CONTRACTNO)) + { + r.WriteLine("RFF+CT:" + bill.CONTRACTNO + "'"); + icount = icount + 1; + } + + r.WriteLine("CNT+7:" + Math.Round(Convert.ToDecimal(bill.KGS), 3) + ":KGM'"); + r.WriteLine("CNT+11:" + bill.PKGS.ToString() + "'"); + r.WriteLine("CNT+15:" + Math.Round(Convert.ToDecimal(bill.CBM), 3) + ":MTQ'"); + + icount = icount + 3; + + if (bill.CARRIEREDICODE == "UASC") + { + if (bill.CTNLIST.Count > 0) + { + var ctnnum = 0; + foreach (var ctn in bill.CTNLIST) + { + ctnnum = ctnnum + ctn.CTNNUM; + } + r.WriteLine("CNT+16:" + ctnnum.ToString() + "'"); + icount = icount + 1; + } + + } + + if (bill.SERVICE.ToUpper() == "DOOR-DOOR") + { + r.WriteLine("TSR+27+2'"); + } + else if (bill.SERVICE.ToUpper() == "DOOR-CY") + { + r.WriteLine("TSR+28+2'"); + } + else if (bill.SERVICE.ToUpper() == "CY-DOOR") + { + r.WriteLine("TSR+29+2'"); + } + else + { + r.WriteLine("TSR+30+2'"); + } + icount = icount + 1; + + var copynum = GetBillNum(bill.COPYNOBILL); + + //2023-03-02 测试这里有问题,签单方式用的中文,要改成英文正本-ORIGINAL 电放-TELEX + if (bill.ISSUETYPE == "ORIGINAL") + { + r.WriteLine("DOC+706+++" + GetBillNum(bill.NOBILL) + "'"); + icount = icount + 1; + if (copynum != "") + { + r.WriteLine("DOC+707+++" + copynum + "'"); + icount = icount + 1; + } + + } + else if (bill.ISSUETYPE == "海运单" || bill.ISSUETYPE.ToUpper() == "SEAWAY" || bill.ISSUETYPE.ToUpper() == "SEAWAY BILL" || bill.ISSUETYPE.ToUpper() == "WAYBILL" || bill.ISSUETYPE.ToUpper() == "SWB正本" || bill.ISSUETYPE.ToUpper() == "SWB无正本") + { + r.WriteLine("DOC+710+++" + GetBillNum(bill.NOBILL) + "'"); + icount = icount + 1; + + } + else if (bill.ISSUETYPE.ToUpper() == "BILL COPY" || bill.ISSUETYPE == "TELEX") + { + r.WriteLine("DOC+706+++" + GetBillNum(bill.NOBILL) + "'"); + icount = icount + 1; + if (copynum != "") + { + r.WriteLine("DOC+707+++" + copynum + "'"); + icount = icount + 1; + } + + } + else if (bill.ISSUETYPE == "正副本") + { + r.WriteLine("DOC+706+++" + GetBillNum(bill.NOBILL) + "'"); + icount = icount + 1; + if (copynum != "") + { + r.WriteLine("DOC+707+++" + copynum + "'"); + icount = icount + 1; + } + + } + else if (bill.ISSUETYPE.ToUpper() == "HOUSE BILL") + { + r.WriteLine("DOC+714+++" + GetBillNum(bill.NOBILL) + "'"); + icount = icount + 1; + + } + + if (bill.BLFRT.IndexOf("PREPAID") >= 0) + r.WriteLine("CPI+4++P'"); + else if (bill.BLFRT.IndexOf("COLLECT") >= 0) + r.WriteLine("CPI+4++C'"); + else + r.WriteLine("CPI+4++B'"); + icount = icount + 1; + + + if (bill.BLFRT == "FREIGHT COLLECT") + { + if (bill.PAYABLEAT != "") + { + r.WriteLine("LOC+57+" + bill.PREPARDATID + "::6:" + bill.PAYABLEAT + "'"); + icount = icount + 1; + } + } + else + { + r.WriteLine("LOC+57+" + bill.PREPARDATID + "::6:" + bill.PREPARDAT + "'"); + icount = icount + 1; + } + + r.WriteLine("LOC+73+" + bill.ISSUEPLACEID + "::6:" + bill.ISSUEPLACE + "'"); + icount = icount + 1; + + + + + //if (billams.ORDERNO != "") + // r.WriteLine("RFF+BN:" + billams.ORDERNO + "'"); + //else + + if (bill.BYCOUNTRY == "USA") + { + r.WriteLine("REF+TN:" + bill.ITNCODE + "'"); + icount = icount + 1; + + } + + + + var voyno = ""; + if (bill.VOYNO.IndexOf(".") >= 0) + { + voyno = bill.VOYNO.Substring(bill.VOYNO.IndexOf(".") + 1, bill.VOYNO.Length - bill.VOYNO.IndexOf(".") - 1); + } + else + { + voyno = bill.VOYNO; + } + r.WriteLine("TDT+20+" + voyno + "+1++" + bill.CARRIEREDICODE + "+++:::" + bill.VESSEL + "'"); + r.WriteLine("DTM+133:" + Convert.ToDateTime(bill.ETD).ToString("yyyyMMdd") + ":102'");//yyyyMMddHHmm + + r.WriteLine("LOC+88+" + bill.PORTLOADID + ":139:6:" + bill.PORTLOAD + "'"); + r.WriteLine("LOC+9+" + bill.PORTLOADID + ":139:6:" + bill.PORTLOAD + "'"); + r.WriteLine("LOC+11+" + bill.PORTDISCHARGEID + ":139:6:" + bill.PORTDISCHARGE + "'"); + icount = icount + 4; + + if (bill.DESTINATION != "") + { + r.WriteLine("LOC+7+" + bill.DESTINATIONID + ":139:6:" + bill.DESTINATION + "'"); + icount = icount + 1; + + } + r.WriteLine("NAD+CA+" + bill.CARRIEREDICODE + ":160:86++" + GetCarrierName(bill.CARRIEREDICODE) + "'"); + icount = icount + 1; + + if (InttrEdi.SENDNAME.Length > 35) + r.WriteLine("NAD+HI+" + InttrEdi.SENDCODE + ":160:86++" + formatEdiStr("txt", InttrEdi.SENDNAME.Substring(0, 35)) + "+" + formatEdiStr("txt", InttrEdi.SENDNAME.Substring(35)) + "'"); + else + r.WriteLine("NAD+HI+" + InttrEdi.SENDCODE + ":160:86++" + formatEdiStr("txt", InttrEdi.SENDNAME) + "'"); + + //r.WriteLine("CTA+IC+:" +billams.ATTN+ "'"); + //r.WriteLine("COM+" +billams.ATTNTEL+ ":TE'"); + //r.WriteLine("COM+" + billams.ATTNEMAIL + ":EM'"); + + + r.WriteLine("CTA+IC+:" + bill.OpEName + "'"); + r.WriteLine("COM+" + bill.OpTel + ":TE'"); + r.WriteLine("COM+" + bill.OpEmail + ":EM'"); + + r.WriteLine("NAD+MR+++" + formatEdiStr("txt", InttrEdi.SENDNAME) + "'"); + //r.WriteLine("CTA+NT+:" +billams.ATTN+ "'"); + //r.WriteLine("COM+" + billams.ATTNEMAIL + ":EM'"); + r.WriteLine("CTA+NT+:" + bill.OpEName + "'"); + r.WriteLine("COM+" + bill.OpEmail + ":EM'"); + + icount = icount + 7; + + + var DescriptionShipper = ""; + Shipping = formatEdiStr("txt", bill.SHIPPER); + + List ShippingList = formatlengthStr(Shipping, 35); + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + + for (var i = 0; i < ShippingList.Count; i++) + { + if (i == 0) Shipping = "NAD+CZ+++" + ShippingList[0] + "+"; + if (i == 1) Shipping = Shipping + ShippingList[i]; + if (i == 2 || i == 3) Shipping = Shipping + ":" + ShippingList[i]; + if (i >= 4 && ShippingList.Count > 5) + { + if (i == 4) + { + if (ShippingList[i].Length > 34) + { + Shipping = Shipping + ":" + ShippingList[i].Substring(0, 34); + DescriptionShipper = ShippingList[i].Substring(34); + } + else + Shipping = Shipping + ":" + ShippingList[i]; + if (bill.CARRIEREDICODE == "HLCU") + { + Shipping = Shipping + "-"; + DescriptionShipper = "-" + DescriptionShipper; + } + else + { + Shipping = Shipping + "*"; + DescriptionShipper = "*" + DescriptionShipper; + } + + } + else if (i > 4) + { + + DescriptionShipper = DescriptionShipper + " " + ShippingList[i]; + } + + } + else + if (i == 4) Shipping = Shipping + ":" + ShippingList[i]; + } + } + + r.WriteLine(Shipping + "'"); + icount = icount + 1; + Shipping = formatEdiStr("txt", bill.CONSIGNEE); + + ShippingList = formatlengthStr(Shipping, 35); + + var DescriptionConsignee = ""; + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + + for (var i = 0; i < ShippingList.Count; i++) + { + if (i == 0) Shipping = "NAD+CN+++" + ShippingList[0] + "+"; + if (i == 1) Shipping = Shipping + ShippingList[i]; + if (i == 2 || i == 3) Shipping = Shipping + ":" + ShippingList[i]; + if (i >= 4 && ShippingList.Count > 5) + { + if (i == 4) + { + if (ShippingList[i].Length > 33) + { + Shipping = Shipping + ":" + ShippingList[i].Substring(0, 33); + DescriptionConsignee = ShippingList[i].Substring(33); + } + else + Shipping = Shipping + ":" + ShippingList[i]; + if (bill.CARRIEREDICODE == "HLCU") + { + Shipping = Shipping + "--"; + DescriptionConsignee = "--" + DescriptionConsignee; + } + else + { + Shipping = Shipping + "**"; + DescriptionConsignee = "**" + DescriptionConsignee; + } + + } + else if (i > 4) + { + + DescriptionConsignee = DescriptionConsignee + " " + ShippingList[i]; + } + + } + else + if (i == 4) Shipping = Shipping + ":" + ShippingList[i]; + } + } + r.WriteLine(Shipping + "'"); + icount = icount + 1; + + + Shipping = formatEdiStr("txt", bill.NOTIFYPARTY); + + ShippingList = formatlengthStr(Shipping, 35); + + var DescriptionNotifyparty = ""; + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + + for (var i = 0; i < ShippingList.Count; i++) + { + if (i == 0) Shipping = "NAD+NI+++" + ShippingList[0] + "+"; + if (i == 1) Shipping = Shipping + ShippingList[i]; + if (i == 2 || i == 3) Shipping = Shipping + ":" + ShippingList[i]; + if (i >= 4 && ShippingList.Count > 5) + { + if (i == 4) + { + if (ShippingList[i].Length > 32) + { + Shipping = Shipping + ":" + ShippingList[i].Substring(0, 32); + DescriptionNotifyparty = ShippingList[i].Substring(32); + } + else + Shipping = Shipping + ":" + ShippingList[i]; + if (bill.CARRIEREDICODE == "HLCU") + { + Shipping = Shipping + "---"; + DescriptionNotifyparty = "---" + DescriptionNotifyparty; + } + else + { + Shipping = Shipping + "***"; + DescriptionNotifyparty = "***" + DescriptionNotifyparty; + } + + } + else if (i > 4) + { + + DescriptionNotifyparty = DescriptionNotifyparty + " " + ShippingList[i]; + } + + } + else + if (i == 4) Shipping = Shipping + ":" + ShippingList[i]; + } + } + + r.WriteLine(Shipping + "'"); + icount = icount + 1; + + Shipping = formatEdiStr("txt", bill.NOTIFYPARTY2); + ShippingList = formatlengthStr(Shipping, 35); + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + for (var i = 0; i < ShippingList.Count; i++) + { + if (i == 0) Shipping = "NAD+N1+++" + ShippingList[0] + "+"; + if (i == 1) Shipping = Shipping + ShippingList[i]; + if (i == 2 || i == 3) Shipping = Shipping + ":" + ShippingList[i]; + if (i == 4) Shipping = Shipping + ":" + ShippingList[i]; + } + r.WriteLine(Shipping + "'"); + } + + + //判断集装箱是否包含分箱明细 + + if (bill.CTNGOODSLIST == null || bill.CTNGOODSLIST.Count == 0) + { + #region 取委托单货描、唛头信息 + r.WriteLine("GID+1+" + bill.PKGS.ToString() + ":" + bill.KINDPKGS_EDI_CODE + "::6:" + bill.KINDPKGS + "'"); + + icount = icount + 1; + + if (bill.HSCODE != "") + { + r.WriteLine("PIA+5+" + bill.HSCODE + ":HS'"); + icount = icount + 1; + + } + + Shipping = formatEdiStr("txt", bill.DESCRIPTION); + + Shipping = Shipping.Replace("\n", "\\"); + Shipping = Shipping.Replace("\r", " "); + string[] DescriptionList = Shipping.Split('\\'); + if (DescriptionList.Length != 0) + { + + for (var i = 0; i < DescriptionList.Length; i++) + { + //if (DescriptionList[i] != "") + //{ + r.WriteLine("FTX+AAA+++" + DescriptionList[i] + "'"); + icount = icount + 1; + //} + + } + } + if (DescriptionShipper != "") + { + r.WriteLine("FTX+AAA+++" + DescriptionShipper + "'"); + icount = icount + 1; + + } + if (DescriptionConsignee != "") + { + r.WriteLine("FTX+AAA+++" + DescriptionConsignee + "'"); + icount = icount + 1; + + } + if (DescriptionNotifyparty != "") + { + r.WriteLine("FTX+AAA+++" + DescriptionNotifyparty + "'"); + icount = icount + 1; + + } + r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(Convert.ToDecimal(bill.KGS), 3) + "'"); + r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(Convert.ToDecimal(bill.CBM), 3) + "'"); + + icount = icount + 2; + + + if (!string.IsNullOrEmpty(bill.GOODSNCM)) + { + r.WriteLine("RFF+ABT:" + bill.GOODSNCM + "'"); + icount = icount + 1; + + } + Shipping = formatEdiStr("txt", bill.MARKS); + + Shipping = Shipping.Replace("\n", "\\"); + Shipping = Shipping.Replace("\r", " "); + string[] MarksList = Shipping.Split('\\'); + if (MarksList.Length != 0) + { + + for (var i = 0; i < MarksList.Length; i++) + { + + //if (MarksList[i] != "") + //{ + r.WriteLine("PCI++" + MarksList[i] + "'"); + icount = icount + 1; + //} + + } + } + + foreach (var ctn in bill.CTNLIST) + { + r.WriteLine("SGP+" + ctn.CNTRNO + "+" + ctn.PKGS.ToString() + "'"); + r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(Convert.ToDecimal(ctn.KGS), 3) + "'"); + r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(Convert.ToDecimal(ctn.CBM), 3) + "'"); + icount = icount + 3; + } + #endregion + } + else + { + + if (bill.CARRIEREDICODE == "UASC" || bill.CARRIEREDICODE == "HLCU" || bill.CARRIEREDICODE == "CMDU") + { + #region 取集装箱分箱_货描、唛头信息 + if (bill.CTNGOODSLIST != null) + { + if (bill.CTNGOODSLIST.Count > 0) + { + var i = 0; + foreach (var ctngood in bill.CTNGOODSLIST) + { + //GID+1+400:CT::6:CARTONS' + r.WriteLine("GID+" + (i + 1) + "+" + ctngood.PKGS.ToString() + ":" + ctngood.KINDPKGS_EDI_CODE + "::6:" + ctngood.KINDPKGS + "'"); + icount++; + //PIA+5+HS_CODE1:HS' + r.WriteLine("PIA+5+" + ctngood.HSCODE + ":HS'"); + icount++; + //FTX+AAA+++MATERIAL 1' + //FTX+AAA+++HS-NO 39023012' + Shipping = formatEdiStr("txt", ctngood.DESCRIPTION); + Shipping = Shipping.Replace("\n", "\\"); + Shipping = Shipping.Replace("\r", " "); + string[] DescriptionList = Shipping.Split('\\'); + if (DescriptionList.Length != 0) + { + for (var j = 0; j < DescriptionList.Length; j++) + { + r.WriteLine("FTX+AAA+++" + DescriptionList[j] + "'"); + icount++; + } + } + //MEA+AAE+WT+KGM:3000' + //MEA+AAE+AAW+MTQ:110.11' + r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(Convert.ToDecimal(ctngood.KGS), 3) + "'"); + icount++; + r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(Convert.ToDecimal(ctngood.CBM), 3) + "'"); + icount++; + //PCI++MARKS AND NUMBERS:FOR MATERIAL 1: OUR PONUMBER: PO_123456' + //if (isbill != 1) + //{ + // Shipping = formatEdiStr("txt", bill.MARKS); + //} + //else + //{ + Shipping = formatEdiStr("txt", ctngood.MARKS); + //} + if (string.IsNullOrEmpty(ctngood.MARKS)) Shipping = formatEdiStr("txt", bill.MARKS); + + Shipping = Shipping.Replace("\n", "\\"); + Shipping = Shipping.Replace("\r", " "); + string[] MarksList = Shipping.Split('\\'); + if (MarksList.Length != 0) + { + for (var j = 0; j < MarksList.Length; j++) + { + r.WriteLine("PCI++" + MarksList[j] + "'"); + icount++; + } + } + if (!string.IsNullOrEmpty(bill.GOODSNCM)) + { + r.WriteLine("RFF+ABT:" + bill.GOODSNCM + "'"); + icount++; + } + // + + //SGP+MSCU1234567+100' + r.WriteLine("SGP+" + ctngood.CNTRNO + "+" + ctngood.PKGS.ToString() + "'"); + //MEA+AAE+WT+KGM:1000' + r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(Convert.ToDecimal(ctngood.KGS), 3) + "'"); + //MEA+AAE+AAW+MTQ:50.11' + r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(Convert.ToDecimal(ctngood.CBM), 3) + "'"); + icount = icount + 3; + i = i + 1; + } + } + } + #endregion + + } + else + { + + #region 取集装箱分箱_货描、唛头信息 + + + var ctngoodssumlist = new List(); + foreach (var ctn in bill.CTNGOODSLIST) + { + var isfind = false; + ctngoodssumlist.ForEach(i => + { + if (i.HSCODE == ctn.HSCODE && i.KINDPKGS == ctn.KINDPKGS && i.DESCRIPTION == ctn.DESCRIPTION && i.MARKS == ctn.MARKS) + { + i.PKGS = i.PKGS + ctn.PKGS; + i.KGS = i.KGS + ctn.KGS; + i.CBM = i.CBM + ctn.CBM; + isfind = true; + } + }); + if (!isfind) + { + var ctnnum = new SeaExportCtnDetailEDIBaseModel(); + ctnnum.HSCODE = ctn.HSCODE; + ctnnum.KINDPKGS = ctn.KINDPKGS; + ctnnum.KINDPKGS_EDI_CODE = ctn.KINDPKGS_EDI_CODE; + ctnnum.DESCRIPTION = ctn.DESCRIPTION; + ctnnum.MARKS = ctn.MARKS; + ctnnum.PKGS = ctn.PKGS; + ctnnum.KGS = ctn.KGS; + ctnnum.CBM = ctn.CBM; + ctngoodssumlist.Add(ctnnum); + } + } + + if (ctngoodssumlist != null) + { + if (ctngoodssumlist.Count > 0) + { + var goodct = 0; + foreach (var ctngoodsum in ctngoodssumlist) + { + //GID+1+400:CT::6:CARTONS' + r.WriteLine("GID+" + (goodct + 1) + "+" + ctngoodsum.PKGS.ToString() + ":" + ctngoodsum.KINDPKGS_EDI_CODE + "::6:" + ctngoodsum.KINDPKGS + "'"); + icount++; + //PIA+5+HS_CODE1:HS' + r.WriteLine("PIA+5+" + ctngoodsum.HSCODE + ":HS'"); + icount++; + //FTX+AAA+++MATERIAL 1' + //FTX+AAA+++HS-NO 39023012' + Shipping = formatEdiStr("txt", ctngoodsum.DESCRIPTION); + Shipping = Shipping.Replace("\n", "\\"); + Shipping = Shipping.Replace("\r", " "); + string[] DescriptionList = Shipping.Split('\\'); + if (DescriptionList.Length != 0) + { + for (var j = 0; j < DescriptionList.Length; j++) + { + r.WriteLine("FTX+AAA+++" + DescriptionList[j] + "'"); + icount++; + } + } + //MEA+AAE+WT+KGM:3000' + //MEA+AAE+AAW+MTQ:110.11' + r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(Convert.ToDecimal(ctngoodsum.KGS), 3) + "'"); + icount++; + r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(Convert.ToDecimal(ctngoodsum.CBM), 3) + "'"); + icount++; + //PCI++MARKS AND NUMBERS:FOR MATERIAL 1: OUR PONUMBER: PO_123456' + //if (isbill != 1) + //{ + // Shipping = formatEdiStr("txt", bill.MARKS); + //} + //else + //{ + Shipping = formatEdiStr("txt", ctngoodsum.MARKS); + //} + + if (ctngoodsum.MARKS == "") Shipping = formatEdiStr("txt", bill.MARKS); + + + Shipping = Shipping.Replace("\n", "\\"); + Shipping = Shipping.Replace("\r", " "); + string[] MarksList = Shipping.Split('\\'); + if (MarksList.Length != 0) + { + for (var j = 0; j < MarksList.Length; j++) + { + r.WriteLine("PCI++" + MarksList[j] + "'"); + icount++; + } + } + if (!string.IsNullOrEmpty(bill.GOODSNCM)) + { + r.WriteLine("RFF+ABT:" + bill.GOODSNCM + "'"); + icount++; + } + goodct = goodct + 1; + bill.CTNGOODSLIST.ForEach(i => + { + if (i.HSCODE == ctngoodsum.HSCODE && i.KINDPKGS == ctngoodsum.KINDPKGS && i.DESCRIPTION == ctngoodsum.DESCRIPTION && i.MARKS == ctngoodsum.MARKS) + { + //SGP+MSCU1234567+100' + r.WriteLine("SGP+" + i.CNTRNO + "+" + i.PKGS.ToString() + "'"); + //MEA+AAE+WT+KGM:1000' + r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(Convert.ToDecimal(i.KGS), 3) + "'"); + //MEA+AAE+AAW+MTQ:50.11' + r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(Convert.ToDecimal(i.CBM), 3) + "'"); + icount = icount + 3; + } + }); + } + } + } + #endregion + } + + } + + if (bill.CARGOID == "D") + { + r.WriteLine("DGS+IMD+" + bill.DCLASS + "+" + bill.DUNNO + "'"); + r.WriteLine("CTA+HG+:" + bill.EDIATTN + "'"); + r.WriteLine("COM+" + bill.EDIATTNTEL + ":TE'"); + icount = icount + 3; + } + + #region 集装箱 主箱循环 + + foreach (var ctn in bill.CTNLIST) + { + if (bill.ISCONTAINERSOC) + r.WriteLine("EQD+CN+" + ctn.CNTRNO + "+" + ctn.CTNALLCODE + "+1'"); + else + r.WriteLine("EQD+CN+" + ctn.CNTRNO + "+" + ctn.CTNALLCODE + "+2'"); + r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(Convert.ToDecimal(ctn.KGS), 3) + "'"); + r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(Convert.ToDecimal(ctn.CBM), 3) + "'"); + icount = icount + 3; + + if (bill.CARGOID == "R") + { + if (bill.REEFERF != "") + { + r.WriteLine("MEA+AAE+AAS+CBM:" + bill.REEFERF + "'"); + icount = icount + 1; + } + } + r.WriteLine("SEL+" + ctn.SEALNO + "+CA'"); + icount = icount + 1; + + if (bill.CARGOID == "R") + { + r.WriteLine("TMP+2+" + bill.TEMPSET + ":CEL'"); + icount = icount + 1; + } + + } + #endregion + } + r.WriteLine("UNT+" + icount.ToString() + "+" + bsno + "'"); + r.WriteLine("UNZ+" + InttrEdi.BSLIST.Count.ToString() + "+" + bsno + "'"); + r.Close(); + f.Close(); + + result.Succeeded = true; + result.ExtraData1 = filename; + return result; + } + #endregion + + } + + /// + /// 订舱提单份数为空时,默认返回"0" + /// + public static class NoBillSOExts + { + public static string EmptyDefaultNum(this string s) + { + if (string.IsNullOrWhiteSpace(s)) + return "0"; + + return s; + } + } +} diff --git a/ds-wms-service/DS.WMS.Core/Op/EDI/VOLTAEdiHelper.cs b/ds-wms-service/DS.WMS.Core/Op/EDI/VOLTAEdiHelper.cs new file mode 100644 index 00000000..2d375769 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Op/EDI/VOLTAEdiHelper.cs @@ -0,0 +1,344 @@ +using DS.Module.Core; +using DS.WMS.Core.Op.Dtos; +using NPOI.SS.Formula.Functions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using Logger = NLog.Logger; +using NLog; +namespace DS.WMS.Core.Op.EDI +{ + /// + /// VOLTA EDI帮助类 + /// + public static class VOLTAEdiHelper + { + private static readonly Logger logger = LogManager.GetCurrentClassLogger(); + #region 生成VOLTA申报报文(截单) + /// + /// 生成VOLTA申报报文(截单) + /// + /// VOLTA申报详情 + /// 返回回执 + public static EdiDataResult CreateEdiVOLTA(VOLTAEDIBaseModel model) + { + var result = new EdiDataResult { Succeeded = false }; + + //日志 + //var logger = Log.CreateLogger(nameof(VOLTAEdiHelper)); + + try + { + ValidateInput(model); + + string bno = model.BookingId; + + string filePath = model.FilePath + "\\" + DateTime.Now.ToString("yyyyMMddHHmmssfff"); + + //预先创建目录 + if (!Directory.Exists(filePath)) + { + Directory.CreateDirectory(filePath); + } + + string filename = filePath + "\\" + bno + ".txt"; + + //如果是部署linux需要修改路径 + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + filename = filename.Replace("\\", "/"); + + FileStream f = new FileStream(filename, FileMode.Create); + StreamWriter r = new StreamWriter(f, Encoding.Default); + + DateTime nowDate = DateTime.Now; + + r.WriteLine("FROMSHIPPER"); + //订舱号 + r.WriteLine("" + model.BookingId + ""); + //发货人 + r.WriteLine("" + model.ShpperName + ""); + //发货人地址 + r.WriteLine(""); + r.WriteLine(model.ShpperAddr); + r.WriteLine(""); + //收货人 + r.WriteLine("" + model.ConsigneeName + ""); + //收货人地址 + r.WriteLine(""); + r.WriteLine(model.ConsigneeAddr); + r.WriteLine(""); + //通知人 + r.WriteLine("" + model.NotifyName + ""); + //通知人地址 + r.WriteLine(""); + r.WriteLine(model.NotifyAddr); + r.WriteLine(""); + //通知人1 + if (!string.IsNullOrWhiteSpace(model.NotifySecondName)) + { + r.WriteLine("" + model.NotifySecondName + ""); + } + else + { + r.WriteLine(""); + } + //通知人1地址 + if (!string.IsNullOrWhiteSpace(model.NotifySecondName)) + { + r.WriteLine(""); + r.WriteLine(model.ConsigneeAddr); + r.WriteLine(""); + } + else + { + r.WriteLine(""); + r.WriteLine(""); + r.WriteLine(""); + } + //发货地 + r.WriteLine("" + model.PlaceOfOrigin + ""); + //起运港 + r.WriteLine("" + model.LoadPort + ""); + //卸货港 + r.WriteLine("" + model.DischargePort + ""); + //最终目的港 + r.WriteLine("" + model.FinalDestination + ""); + //最终交货地 + r.WriteLine("" + model.PlaceOfDelivery + ""); + + //PlaceOfReceipt + r.WriteLine(""); + //提单正本份数默认3 + r.WriteLine("3"); + //提单状态(默认S) S-SHIPPED ON BOARD;R-RECEIVED FOR SHIPMENT;T-THRO BL + r.WriteLine("S"); + //重量单位(默认1) 1-KGS;2-TON;3-QUINTAL;4-MT;5-CENTIMETER;6-METER;7-INCH + r.WriteLine("1"); + //Payable At + r.WriteLine(""); + //Prepaid / Collect(默认P) P-PREPAID;C-COLLECT + r.WriteLine("P"); + //EDNumber + r.WriteLine(""); + //货描 + r.WriteLine(""); + r.WriteLine(model.CargoDescription); + r.WriteLine(""); + //唛头 + r.WriteLine(""); + r.WriteLine(model.Marks); + r.WriteLine(""); + //模板版本号 + r.WriteLine(""); + r.WriteLine(model.TemplateVersion); + r.WriteLine(""); + //箱明细 + r.WriteLine(""); + r.Write(GetContaInfo(model.ContaList)); + r.WriteLine(""); + + r.Close(); + f.Close(); + + result.Succeeded = true; + result.ExtraData1 = filename; + result.ExtraData2 = $"截单样本:{model.Vessel} {model.VoyNo} {model.BookingId}"; + + return result; + } + catch (Exception ex) + { + result.Succeeded = false; + result.Message = ex.Message; + return result; + } + + //return result; + } + #endregion + + #region 拼接箱明细报文 + /// + /// 拼接箱明细报文 + /// + /// 箱明细 + /// 返回拼接后字符 + private static string GetContaInfo(List contaList) + { + StringBuilder txtBuilder = new StringBuilder(); + + ////日志 + //var logger = Log.CreateLogger(nameof(VOLTAEdiHelper)); + + try + { + contaList.ForEach(ctn => + { + //箱拼接格式:序号~箱号~铅封号~Custom Seal No~毛重~净重~尺码~重量单位~~件数~~~包装 + txtBuilder.AppendLine($"{ctn.SNo}~{ctn.ContaNo}~{ctn.SealNo}~~{ctn.GWt.Value.ToString("0.###")}~{(ctn.NWt.HasValue ? ctn.NWt.Value.ToString("0.###") : "")}~{ctn.CBM.Value.ToString("0.###")}~{ctn.WTUnit}~~{ctn.Qty.Value.ToString("#.###")}~~~{ctn.EdiPkgs}"); + + }); + } + catch (Exception ex) + { + logger.Info("VOLTA拼接箱明细异常,原因:{0}", ex.Message); + + throw ex; + } + + return txtBuilder.ToString(); + } + #endregion + + #region 校验VOLTA请求参数s + /// + /// 校验VOLTA请求参数 + /// + /// VOLTA请求参数 + public static void ValidateInput(VOLTAEDIBaseModel model) + { + StringBuilder msgBuilder = new StringBuilder(); + + if (string.IsNullOrEmpty(model.BookingId)) + msgBuilder.AppendLine("提单号不能为空"); + + if (string.IsNullOrEmpty(model.ShpperName)) + msgBuilder.AppendLine("发货人名称不能为空"); + + if (string.IsNullOrEmpty(model.ShpperAddr)) + msgBuilder.AppendLine("发货人地址不能为空"); + + if (!string.IsNullOrEmpty(model.ShpperAddr)) + { + if (model.ShpperAddr.Length > 450) + msgBuilder.AppendLine("发货人地址不能大于450个字符"); + } + + if (string.IsNullOrEmpty(model.ConsigneeName)) + msgBuilder.AppendLine("收货人名称不能为空"); + + if (string.IsNullOrEmpty(model.ConsigneeAddr)) + msgBuilder.AppendLine("收货人地址不能为空"); + + if (!string.IsNullOrEmpty(model.ConsigneeAddr)) + { + if (model.ConsigneeAddr.Length > 450) + msgBuilder.AppendLine("收货人地址不能大于450个字符"); + } + + if (string.IsNullOrEmpty(model.NotifyName)) + msgBuilder.AppendLine("通知人名称不能为空"); + + if (string.IsNullOrEmpty(model.NotifyAddr)) + msgBuilder.AppendLine("通知人地址不能为空"); + + if (!string.IsNullOrEmpty(model.NotifyAddr)) + { + if (model.NotifyAddr.Length > 450) + msgBuilder.AppendLine("通知人地址不能大于450个字符"); + } + + if (!string.IsNullOrEmpty(model.NotifySecondName) && string.IsNullOrEmpty(model.NotifySecondAddr)) + msgBuilder.AppendLine("通知人1地址不能为空"); + + if (string.IsNullOrEmpty(model.NotifySecondName) && !string.IsNullOrEmpty(model.NotifySecondAddr)) + msgBuilder.AppendLine("通知人1名称不能为空"); + + if (!string.IsNullOrEmpty(model.NotifySecondAddr)) + { + if (model.NotifySecondAddr.Length > 450) + msgBuilder.AppendLine("通知人1地址不能大于450个字符"); + } + + if (string.IsNullOrEmpty(model.PlaceOfOrigin)) + msgBuilder.AppendLine("发货地不能为空"); + + if (string.IsNullOrEmpty(model.LoadPort)) + msgBuilder.AppendLine("起运港不能为空"); + + if (string.IsNullOrEmpty(model.DischargePort)) + msgBuilder.AppendLine("卸货港不能为空"); + + if (string.IsNullOrEmpty(model.FinalDestination)) + msgBuilder.AppendLine("最终目的港不能为空"); + + if (string.IsNullOrEmpty(model.PlaceOfDelivery)) + msgBuilder.AppendLine("最终交货地不能为空"); + + if (string.IsNullOrEmpty(model.CargoDescription)) + msgBuilder.AppendLine("品名不能为空"); + + if (!string.IsNullOrEmpty(model.CargoDescription)) + { + if (model.CargoDescription.Length > 3000) + msgBuilder.AppendLine("品名不能大于3000个字符"); + } + + if (string.IsNullOrEmpty(model.Marks)) + msgBuilder.AppendLine("唛头不能为空"); + + if (!string.IsNullOrEmpty(model.Marks)) + { + if (model.Marks.Length > 1000) + msgBuilder.AppendLine("唛头不能大于1000个字符"); + } + + if (model.ContaList == null || model.ContaList.Count == 0) + msgBuilder.AppendLine("箱明细不能为空"); + + model.ContaList.ForEach(ctn => + { + StringBuilder ctnMsgBuilder = new StringBuilder(); + + if (string.IsNullOrWhiteSpace(ctn.ContaNo)) + { + ctnMsgBuilder.Append("箱号不能为空;"); + } + else + { + if (ctn.ContaNo.Length > 11) + { + ctnMsgBuilder.Append("箱号长度不能大于11;"); + } + } + + if (string.IsNullOrWhiteSpace(ctn.SealNo)) + { + ctnMsgBuilder.Append("铅封号不能为空;"); + } + + if (!ctn.GWt.HasValue) + { + ctnMsgBuilder.Append("毛重不能为空;"); + } + + if (!ctn.CBM.HasValue) + { + ctnMsgBuilder.Append("尺寸不能为空;"); + } + + if (!ctn.Qty.HasValue) + { + ctnMsgBuilder.Append("件数不能为空;"); + } + + if (string.IsNullOrWhiteSpace(ctn.EdiPkgs)) + { + ctnMsgBuilder.Append("包装不能为空;"); + } + + if (ctnMsgBuilder.Length > 0) + { + msgBuilder.AppendLine($"箱【{ctn.SNo}】{ctnMsgBuilder.ToString()}"); + } + }); + + if (msgBuilder.Length > 0) + throw new Exception(msgBuilder.ToString()); + } + #endregion + } +} diff --git a/ds-wms-service/DS.WMS.Core/Op/EDI/WYEdiHelper.cs b/ds-wms-service/DS.WMS.Core/Op/EDI/WYEdiHelper.cs new file mode 100644 index 00000000..f0d0ea00 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Op/EDI/WYEdiHelper.cs @@ -0,0 +1,956 @@ +using DS.Module.Core; +using DS.WMS.Core.Op.Dtos; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace DS.WMS.Core.Op.EDI +{ + /// + /// + /// + public class WYEdiHelper + { + + public WYEdiHelper() + { + } + + #region 基本函数 + + public static string GetBillNum2(string str) + { + if (str == "ZERO") return "00"; + if (str == "ONE") return "01"; + if (str == "TWO") return "02"; + if (str == "THREE") return "03"; + if (str == "FOUR") return "04"; + if (str == "FIVE") return "05"; + if (str == "SIX") return "06"; + if (str == "SERVEN") return "07"; + if (str == "EIGHT") return "08"; + if (str == "NINE") return "09"; + if (str == "TEN") return "10"; + else return ""; + } + + + public static string GetDateStr(string datestr, string dateformat) + { + var result = ""; + + if (datestr == null || datestr == "") + { + result = ""; + } + else + { + result = Convert.ToDateTime(datestr).ToString(dateformat); + + } + + return result; + + } + + #region 判断中文字符 + public static bool IsChinese(char c) + { + return (int)c > 0x80; + } + public static bool StringIsChinese(string str) + { + var result = false; + for (int i = 1; i < str.Length; i++) + { + if (IsChinese(str[i])) + { + result = true; + return result; + } + } + for (int i = 0; i < str.Length; i++) + { + string stemp = str.Substring(i, 1); + int ilen = System.Text.Encoding.Default.GetByteCount(stemp); + if (ilen == 2) + { + result = true; + return result; + } + + } + + return result; + } + + #endregion + + public static string formatListStr(List DestList, int lineCount, bool isformat = false) + { + var result = ""; + for (var i = 0; i < lineCount; i++) + { + if (DestList.Count > i) + { + if (isformat) + result = result + formatEdiStr("txt", DestList[i]); + else + result = result + DestList[i]; + } + if (i != (lineCount - 1)) + result = result + ":"; + + + } + return result; + } + + + #region 文本字段判断每行是否符合 + /// + /// edi 文本格式处理判断(例如:1行35个字符不超过5行) + /// + /// 文件类型(例如:txt、xml) + /// 要处理的数据 + /// 每行长度 + /// 主提单号 + /// 数据类型(例如:发货人内容、货描等) + /// 限制录入的行数(“0”代表不限制) + /// 限录后多出的放到货描中的数据的连接符(例如:“*”发货人内容、“**”收件人等) + /// + public static System.String formatlengthError(string fileType, string str, int length, string sMBLNO, string sType, int rowNum, string sSymbol, bool isHuoMiao) + { + string error = ""; + string Shipping = str; + if (fileType == "txt") + { + Shipping = formatEdiStr("txt", str); + } + else if (fileType == "xml") + { + Shipping = formatEdiStr("txt", str); + } + string[] argAGENT = Shipping.Split(new string[] { "\r\n" }, StringSplitOptions.None); + if (argAGENT.Length > 0) + { + if (argAGENT.Length == 1) + { + argAGENT = Shipping.Split(new string[] { "\n" }, StringSplitOptions.None); + if (argAGENT.Length > 0) + { + if (argAGENT.Length > rowNum && rowNum != 0) + { + if (isHuoMiao) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据!"; + } + else + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据,多余信息请手动以“" + sSymbol + "”号开头放到货物描述中!(例如:“货描内容" + sSymbol + "超出部分”)"; + } + } + for (int j = 0; j < argAGENT.Length; j++) + { + //List AgentList = formatlengthStr(argAGENT[j].ToString(), 35); + if (argAGENT[j].ToString().Length > length) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 第" + (j + 1) + "行超过" + length + "个字符"; + } + } + } + } + else + { + if (argAGENT.Length > rowNum && rowNum != 0) + { + if (isHuoMiao) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据!"; + } + else + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据,多余信息请手动以“" + sSymbol + "”号开头放到货物描述中!(例如:“货描内容" + sSymbol + "超出部分”)"; + } + } + for (int j = 0; j < argAGENT.Length; j++) + { + //List AgentList = formatlengthStr(argAGENT[j].ToString(), 35); + if (argAGENT[j].ToString().Length > length) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 第" + (j + 1) + "行超过" + length + "个字符"; + } + } + } + } + return error; + } + #endregion + + #region 字符转义 + /// + /// 各种文本转义字符 + /// + /// 文件类型(例如:txt、xml) + /// 文本字符串 + /// + public static string formatEdiStr(string fileType, string str) + { + if (str == null) + str = string.Empty; + + if (fileType == "txt") + { + return str.Replace("?", "??").Replace(":", "?:").Replace("+", "?+").Replace("'", "?'"); + } + else if (fileType == "xml") + { + return str.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace("\"", """).Replace("'", "'"); + } + else if (fileType == "sitc") + { + return str.Replace("?", "??").Replace(":", "?:").Replace("'", "?'"); + } + else + { + return str; + } + } + #endregion + #region 格式化每行 + public static List formatlengthStr(string str, int length, bool formatstr = false, bool nodelsp = false) + { + str = str.Replace("\r\n", "\\"); + str = str.Replace("\n", "\\"); + str = str.Replace("\r", " "); + string[] StrList = str.Split('\\'); + var strtemp = ""; + var strnewline = ""; + var strtempnewline = ""; + char[] spstring = { ' ', ';', ',', '.', ':', '/', '(', ')', '?', '+', '-' }; + List DestList = new List(); + for (var i = 0; i <= StrList.Length - 1; i++) + { + if (StrList[i].Length <= length) + { + if (formatstr) + DestList.Add(formatEdiStr("txt", StrList[i])); + else + DestList.Add(StrList[i]); + + } + else + { + strtemp = StrList[i] + " "; + strtempnewline = ""; + strnewline = ""; + for (var j = 0; j < strtemp.Length; j++) + { + strtempnewline = strtempnewline + strtemp[j]; + if (strtemp[j] == ' ' || strtemp[j] == ':' || strtemp[j] == ',' || strtemp[j] == '.' || strtemp[j] == ':' || strtemp[j] == '/' + || strtemp[j] == '?' || strtemp[j] == ')' || strtemp[j] == '}' || strtemp[j] == '+' || strtemp[j] == '-') + { + if ((strnewline.Length + strtempnewline.Length) <= length) + strnewline = strnewline + strtempnewline; + else + { + if (formatstr) + DestList.Add(formatEdiStr("txt", strnewline)); + else + DestList.Add(strnewline); + strnewline = strtempnewline; + + } + strtempnewline = ""; + } + } + if (nodelsp) + { + if (formatstr) + DestList.Add(formatEdiStr("txt", strnewline)); + else DestList.Add(strnewline); + } + else if (strnewline.Trim() != "") + { + if (formatstr) + DestList.Add(formatEdiStr("txt", strnewline)); + else DestList.Add(strnewline); + } + } + + } + + return DestList; + } + #endregion + #endregion + + #region 检查 + public static string IsCreateWYEDI(EDIBaseModel InttrEdi) + { + var error = ""; + + if (string.IsNullOrEmpty(InttrEdi.SENDCODE)) + { error = error + "
发送方代码不能为空"; } + + if (string.IsNullOrEmpty(InttrEdi.SENDNAME)) + { error = error + "
发送方名称不能为空"; } + + if (string.IsNullOrEmpty(InttrEdi.RECEIVECODE)) + { error = error + "
接收方代码不能为空"; } + + //2023-03-03 确认需要增加货代名称不能为空,这里对比东胜是填的订舱代理名称,这里需要人工填写 + if (string.IsNullOrEmpty(InttrEdi.ForWarderName)) + { error = error + "
货代称呼不能为空"; } + + //if (InttrEdi.filetype == "B") + //{ + // if (InttrEdi.UseForWarderCode) + // { + // if (string.IsNullOrEmpty(InttrEdi.ForWarderCode)) + // { error = error + "
货代代码不能为空"; } + + // if (string.IsNullOrEmpty(InttrEdi.ForWarderName)) + // { error = error + "
货代称呼不能为空"; } + // } + //} + + + foreach (var headData in InttrEdi.BSLIST) + { + + if (string.IsNullOrEmpty(headData.MBLNO)) + { error = error + "
主提单号不能为空"; } + + if (string.IsNullOrEmpty(headData.BLFRT)) + { error = error + "
提单号:" + headData.MBLNO + " 付费方式不能为空"; } + + + + if (string.IsNullOrEmpty(headData.ETD)) + { + if (string.IsNullOrEmpty(headData.VESSEL)) + { error = error + "
提单号:" + headData.MBLNO + " 船名不能为空"; } + + if (string.IsNullOrEmpty(headData.VOYNO)) + { error = error + "
提单号:" + headData.MBLNO + " 航次不能为空"; } + + } + + + + + if (string.IsNullOrEmpty(headData.PORTLOADID) || headData.PORTLOADID.Length != 5) + { error = error + "
提单号:" + headData.MBLNO + " 装货港代码不能为空或录入不正确(必须是5位代码)"; } + + if (string.IsNullOrEmpty(headData.PORTLOAD)) + { error = error + "
提单号:" + headData.MBLNO + " 装货港不能为空"; } + + + if (string.IsNullOrEmpty(headData.PORTDISCHARGEID) || headData.PORTDISCHARGEID.Length != 5) + { error = error + "
提单号:" + headData.MBLNO + " 卸货港代码不能为空或录入不正确(必须是5位代码)"; } + if (string.IsNullOrEmpty(headData.PORTDISCHARGE)) + { error = error + "
提单号:" + headData.MBLNO + " 卸货港不能为空"; } + + if (string.IsNullOrEmpty(headData.PLACEDELIVERY) || headData.PLACEDELIVERYID.Length != 5) + { error = error + "
提单号:" + headData.MBLNO + " 交货地代码不能为空或录入不正确(必须是5位代码)"; } + if (string.IsNullOrEmpty(headData.PLACEDELIVERY)) + { error = error + "
提单号:" + headData.MBLNO + " 交货地不能为空"; } + + if (string.IsNullOrEmpty(headData.DESTINATION)) + { + if (string.IsNullOrEmpty(headData.DESTINATIONID) || headData.DESTINATIONID.Length != 5) + { error = error + "
提单号:" + headData.MBLNO + " 目的地代码不能为空或录入不正确(必须是5位代码)"; } + } + + if (string.IsNullOrEmpty(headData.KINDPKGS_EDI_CODE)) + { error = error + "
提单号:" + headData.MBLNO + " 包装EDI代码不能为空"; } + if (headData.PKGS == 0) + { error = error + "
提单号:" + headData.MBLNO + " 件数不能为0"; } + if (headData.KGS == 0) + { error = error + "
提单号:" + headData.MBLNO + " 毛重不能为0"; } + if (headData.CBM == 0) + { error = error + "
提单号:" + headData.MBLNO + " 尺码不能为0"; } + + if (string.IsNullOrEmpty(headData.CARGOID)) + { error = error + "
提单号:" + headData.MBLNO + " 货物标识不能为空"; } + + if (headData.CARGOID == "D") + { + if (string.IsNullOrEmpty(headData.DCLASS)) + { error = error + "
提单号:" + headData.MBLNO + " 危险品分类不能为空"; } + + if (string.IsNullOrEmpty(headData.DUNNO)) + { error = error + "
提单号:" + headData.MBLNO + " 危险品编号不能为空"; } + } + if (headData.CARGOID == "R") + { + if (headData.TEMPSET == null || headData.TEMPSET == "") + { error = error + "
提单号:" + headData.MBLNO + " 设置温度不能为空"; } + if (headData.REEFERF == null || headData.REEFERF == "") + { error = error + "
提单号:" + headData.MBLNO + " 通风度不能为空"; } + } + if (headData.ISSUEPLACE == null || headData.ISSUEPLACE == "") + { error = error + "
提单号:" + headData.MBLNO + "签单地点不能为空"; } + + if (headData.CARRIEREDICODE == "APL") + if (headData.ISSUETYPE == null || headData.ISSUETYPE == "") + { error = error + "
提单号:" + headData.MBLNO + "签单方式不能为空"; } + if (headData.SERVICE == "" || headData.SERVICE == null) + { error = error + "
提单号:" + headData.MBLNO + "运输条款不能为空"; } + + if (string.IsNullOrEmpty(headData.MARKS)) + { + error = error + "
提单号:" + headData.MBLNO + " 唛头不能为空"; + } + else + { + if (StringIsChinese(headData.MARKS)) + { + error = error + "
提单号:" + headData.MBLNO + " 唛头含有中文或双字节字符"; + } + else + { + error += formatlengthError("txt", headData.MARKS, 35, headData.MBLNO, "唛头", 0, "", false); + } + } + + if (string.IsNullOrEmpty(headData.DESCRIPTION)) + { + error = error + "
提单号:" + headData.MBLNO + " 货物描述不能为空"; + } + else + { + if (StringIsChinese(headData.DESCRIPTION)) + { + error = error + "
提单号:" + headData.MBLNO + " 货物描述含有中文或双字节字符"; + } + else + { + //error += formatlengthError("txt", bill.DESCRIPTION, 35, bill.MBLNO, "货物描述", 0, ""); + } + } + + + if (string.IsNullOrEmpty(headData.SHIPPER)) + { + error = error + "
提单号:" + headData.MBLNO + " 发货人不能为空"; + } + else + { + if (StringIsChinese(headData.SHIPPER)) + { + error = error + "
提单号:" + headData.MBLNO + " 发货人含有中文或双字节字符"; + } + else + { + if (headData.CARRIEREDICODE == "HLCU") + { + error += formatlengthError("txt", headData.SHIPPER, 35, headData.MBLNO, "发货人", 6, "-", false); + } + else + { + error += formatlengthError("txt", headData.SHIPPER, 35, headData.MBLNO, "发货人", 6, "*", false); + } + } + } + //} + + + + if (string.IsNullOrEmpty(headData.CONSIGNEE)) + { + error = error + "
提单号:" + headData.MBLNO + " 收货人不能为空"; + } + else + { + if (StringIsChinese(headData.CONSIGNEE)) + { + error = error + "
提单号:" + headData.MBLNO + " 收货人含有中文或双字节字符"; + } + else + { + if (headData.CARRIEREDICODE == "HLCU") + { + error += formatlengthError("txt", headData.CONSIGNEE, 35, headData.MBLNO, "收货人", 6, "--", false); + } + else + { + error += formatlengthError("txt", headData.CONSIGNEE, 35, headData.MBLNO, "收货人", 6, "**", false); + } + } + } + + + + + if (string.IsNullOrEmpty(headData.NOTIFYPARTY)) + { + error = error + "
提单号:" + headData.MBLNO + " 通知人不能为空"; + } + else + { + if (StringIsChinese(headData.NOTIFYPARTY)) + { + error = error + "
提单号:" + headData.MBLNO + " 通知人含有中文或双字节字符"; + } + else + { + if (headData.CARRIEREDICODE == "HLCU") + { + error += formatlengthError("txt", headData.NOTIFYPARTY, 35, headData.MBLNO, "通知人", 6, "---", false); + } + else + { + error += formatlengthError("txt", headData.NOTIFYPARTY, 35, headData.MBLNO, "通知人", 6, "***", false); + } + } + } + + if (!string.IsNullOrEmpty(headData.NOTIFYPARTY2)) + { + error += formatlengthError("txt", headData.NOTIFYPARTY2, 35, headData.MBLNO, "第二通知人", 5, "", false); + } + + var ctnlist = headData.CTNLIST; + if (ctnlist.Count == 0) { error = error + "
提单号:" + headData.MBLNO + " 集装箱信息不能为空"; }; + + #region 集装箱判断检查 + if (ctnlist.Count != 0) + { + Decimal dlPKGS = 0; + Decimal dlKGS = 0; + Decimal dlCBM = 0; + foreach (var ctn in ctnlist) + { + if (string.IsNullOrEmpty(ctn.CTNALLCODE)) + { error = error + "
提单号:" + headData.MBLNO + " 集装箱箱型EDI代码不能为空"; } + if ((ctn.CTNALLCODE.IndexOf("RH") > 0 || ctn.CTNALLCODE.IndexOf("RF") > 0) && (headData.CARGOID != "R")) + { + { error = error + "
提单号:" + headData.MBLNO + " 集装箱箱型为冻柜,货类代码请选择冻柜"; } + } + + if (InttrEdi.filetype == "E") + { + + if (string.IsNullOrEmpty(ctn.CNTRNO)) + { error = error + "
提单号:" + headData.MBLNO + " 箱号不能为空"; } + if (string.IsNullOrEmpty(ctn.SEALNO)) + { error = error + "
提单号:" + headData.MBLNO + " 封号不能为空"; } + + if (ctn.KINDPKGS != headData.KINDPKGS) + { error = error + "
提单号:" + headData.MBLNO + " 中的包装类型与集装箱的包装类型不同"; } + dlPKGS += Convert.ToDecimal(ctn.PKGS); + dlKGS += Convert.ToDecimal(ctn.KGS); + dlCBM += Convert.ToDecimal(ctn.CBM); + } + } + if (InttrEdi.filetype == "E") + { + if (dlPKGS != Convert.ToDecimal(headData.PKGS)) + { error = error + "
提单号:" + headData.MBLNO + " 集装箱件数合计数必须等于委托单总件数"; } + if (dlKGS != Convert.ToDecimal(headData.KGS)) + { error = error + "
提单号:" + headData.MBLNO + " 集装箱重量合计数必须等于委托单总重量数"; } + if (dlCBM != Convert.ToDecimal(headData.CBM)) + { error = error + "
提单号:" + headData.MBLNO + " 集装箱尺码合计数必须等于委托单总尺码数"; } + } + } + + if (InttrEdi.filetype == "E") + { + if (headData.CTNGOODSLIST != null && headData.CTNGOODSLIST.Count > 0) + { + foreach (var ctn in ctnlist) + { + var isfind = false; + Int32 ctngoodssumpkgs = 0; + decimal ctngoodssumkgs = 0; + decimal ctngoodssumcbm = 0; + headData.CTNGOODSLIST.ForEach(i => + { + if (i.CNTRNO == ctn.CNTRNO) + { + isfind = true; + ctngoodssumpkgs = ctngoodssumpkgs + i.PKGS; + ctngoodssumkgs = ctngoodssumkgs + i.KGS; + ctngoodssumcbm = ctngoodssumcbm + i.CBM; + } + }); + if (!isfind) + { + error = error + "
提单号:" + headData.MBLNO + "的“" + ctn.CNTRNO + "”未添加分箱明细!"; + } + else + { + if (ctngoodssumpkgs != Convert.ToDecimal(ctn.PKGS)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctn.CNTRNO + " 分箱明细件数合计数不等于集装箱件数"; } + if (ctngoodssumkgs != Convert.ToDecimal(ctn.KGS)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctn.CNTRNO + " 分箱明细毛重合计数不等于集装箱毛重"; } + if (ctngoodssumcbm != Convert.ToDecimal(ctn.CBM)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctn.CNTRNO + " 分箱明细尺码合计数不等于集装箱毛重"; } + + } + + } + + foreach (var ctngood in headData.CTNGOODSLIST) + { + if (string.IsNullOrEmpty(ctngood.KINDPKGS)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱明细包装类型不能为空"; } + if (string.IsNullOrEmpty(ctngood.DESCRIPTION)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱货物描述不能为空"; } + else + { + error += formatlengthError("txt", ctngood.DESCRIPTION, 70, headData.MBLNO, "的“" + ctngood.CNTRNO + "”箱号的分箱货物描述", 0, "", false); + } + //if (string.IsNullOrEmpty(ctngood.HSCODE)) + //{ error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱HS编码不能为空"; } + if (string.IsNullOrEmpty(ctngood.KINDPKGS_EDI_CODE)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱明细包装类型代码不能为空"; } + + } + + } + + #endregion + + + } + + //2023-03-03 经过测试东胜的EDI根据付费方式,区分 到付-需要填到付地点不能填预付地点,预付只能填预付地点不能填到付地点 + //跟韩工确认增加判断 + if (!string.IsNullOrWhiteSpace(headData.BLFRT) && headData.BLFRT.IndexOf("PREPAID") >= 0) + { + if (string.IsNullOrWhiteSpace(headData.PREPARDAT)) + { + error = error + "
提单号:" + headData.MBLNO + " 付费方式是预付,预付地点不能为空"; + } + + if (!string.IsNullOrWhiteSpace(headData.PAYABLEAT)) + { + error = error + "
提单号:" + headData.MBLNO + " 付费方式是预付,到付地点不能填写"; + } + } + else if (!string.IsNullOrWhiteSpace(headData.BLFRT) && headData.BLFRT.IndexOf("COLLECT") >= 0) + { + if (string.IsNullOrWhiteSpace(headData.PAYABLEAT)) + { + error = error + "
提单号:" + headData.MBLNO + " 付费方式是到付,到付地点不能为空"; + } + + if (!string.IsNullOrWhiteSpace(headData.PREPARDAT)) + { + error = error + "
提单号:" + headData.MBLNO + " 付费方式是到付,预付地点不能填写"; + } + } + + } + return error; + } + #endregion + + #region 生成报文(订舱(filetype=="B"),截单(filetype=="E")) + public static EdiDataResult CreateEdiWY(EDIBaseModel InttrEdi) + { + var result = new EdiDataResult { Succeeded = false }; + + var filetype = "IFTMBF"; + + string filename = InttrEdi.filerpath + "\\" + filetype + "_" + InttrEdi.BSLIST[0].MBLNO + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt"; + + //如果是部署linux需要修改路径 + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + filename = filename.Replace("\\", "/"); + + //if (System.IO.File.Exists(filename)) + //{ + // System.IO.File.Delete(filename); + //} + FileStream f = new FileStream(filename, FileMode.Create); + StreamWriter r = new StreamWriter(f, Encoding.Default); + var icount = 0; + var bsno = ""; + var isfirst = true; + foreach (var bill in InttrEdi.BSLIST) + { + if (isfirst) + { + if (InttrEdi.filetype == "E") + r.WriteLine("00:IFTMBF:SI:" + InttrEdi.filerole + ":" + InttrEdi.SENDCODE + ":" + InttrEdi.RECEIVECODE + ":" + DateTime.Now.ToString("yyyyMMddHHmm") + ":2.1'"); + else + r.WriteLine("00:IFTMBF:BK:" + InttrEdi.filerole + ":" + InttrEdi.SENDCODE + ":" + InttrEdi.RECEIVECODE + ":" + DateTime.Now.ToString("yyyyMMddHHmm") + ":2.1'"); + isfirst = false; + icount++; + + } + //2023-03-03 修改运输条款SERVICE改为EDI的映射值,经过韩工确认 + r.WriteLine("02" + + ":" + bill.ORDERNO//2 REFERENCE NO. 运编号 X(35) 一般为流水号 M + + ":" + bill.MBLNO//3 B\L NO. 提单号 X(20) 船公司的提单号 C + + ":" + bill.SERVICEEDICODE//4 DELIVERY TERM 交货条款 X(9) CY-CY(pier-pier/port):30CY-CFS(pier/port-door):29CFS-CY(door-pier/port):28CFS-CFS(door-door):27 M + + ":" + formatEdiStr("txt", InttrEdi.ForWarderName.Replace("\n", " ").Replace("\r", " "))//5 BOOKING PARTY 订舱人说明 X(70) 货代方企业名称或代码 C + + ":" + InttrEdi.RECEIVECODE//6 ISSUE PARTY CODE 签单人代码 X(13) 即接受订舱的人的代码 M + + ":"//7 ISSUE PARTY 签单人说明 X(35)   C + + ":"//8 APPLICANT 询价单位 X(13) 向船公司询价的单位代码 C + + ":"//9 FOB BK PARTY 国外订舱单位 X(13) 国外FOB货订舱单位的代码 C + + ":"//10 B/L TRANSHIP ID 转船标识 X(1) Y/N C + + ":"//11 BATCH ID 分批 X(1) Y/N C + + ":"//12 SHIPMENT DATE 装期 9(8) CCYYMMDD C + + ":"//13 EXPIRY DATE 效期 9(8) CCYYMMDD C + + ":" + bill.CONTRACTNO//14 QUOTATION NO. 运费协议号 X(30) MAERSK为必选 C + + ":"//15 CHARGE TYPE 费率本代码 X(1)   C + + ":" //16 S/C NO. 合约号 X(30)   C + + "'"); + + icount++; + + var ISSUETYPE = ""; + + //2023-03-02 测试这里有问题,签单方式用的中文,要改成英文正本-ORIGINAL 电放-TELEX + //if (bill.ISSUETYPE == "正本") + if (bill.ISSUETYPE == "ORIGINAL") + { + ISSUETYPE = "ORI"; + } + else if (bill.ISSUETYPE == "TELEX") + { + ISSUETYPE = "TER"; + } + 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++; + + + r.WriteLine("11:" + bill.VESSELID + ":" + bill.VESSEL + ":" + bill.VOYNO + "::" + bill.CARRIEREDICODE + ":" + bill.CARRIER + ":::::::'"); + icount++; + + var DESTINATIONID = bill.DESTINATIONID; + var DESTINATION = bill.DESTINATION; + if (bill.CARRIEREDICODE == "ONEY" || bill.CARRIEREDICODE == "ZIM") + { + DESTINATIONID = ""; + DESTINATION = ""; + } + + r.WriteLine("12" + + ":" + bill.PLACERECEIPTID//2 PLACE CODE OF RECEIPT 收货地代码 X(5) OOCL、HLC的订舱要求必选 O + + ":" + bill.PLACERECEIPT//3 PLACE OF RECEIPT 收货地 X(35)   C + + ":" + bill.PORTLOADID//4 LOAD PORT CODE 装货港代码 X(5) OOCL的订舱要求必选 O + + ":" + bill.PORTLOAD//5 LOAD PORT 装货港 X(35)   C + + ":" + bill.PORTDISCHARGEID//6 DISCHARGE PORT CODE 卸货港代码 X(5) OOCL的订舱要求必选 M + + ":" + bill.PORTDISCHARGE//7 DISCHARGE PORT 卸货港 X(35)   C + + ":" + bill.TRANSPORTID //8 TRANSFER PORT CODE 中转港代码 X(5)   C + + ":" + bill.TRANSPORT//9 TRANSFER PORT 中转港 X(35)   C + + ":" + bill.PLACEDELIVERYID//10 PLACE OF DELIVERY CODE 交货地代码 X(5) OOCL的订舱要求必选 O + + ":" + bill.PLACEDELIVERY//11 PLACE OF DELIVERY 交货地 X(35)   C + + ":" + DESTINATIONID//12 FINAL DESTINATION CODE 目的地代码 X(5)   C + + ":" + DESTINATION//13 FINAL DESTINATION CODE 目的地 X(35)   C + + ":" + bill.YARDEDICODE//14 FINAL DESTINATION CODE 目的地 X(35)   C + + "'"); + + icount = icount + 1; + + r.WriteLine("14:" + bill.BLFRTEDICODE + ":" + bill.BLFRT + "'"); + if (InttrEdi.filetype == "E") + r.WriteLine("15:::" + bill.BLFRTEDICODE + ":" + bill.PAYABLEATID + ":::::'"); + else + r.WriteLine("15:::" + bill.BLFRTEDICODE + "::::::'"); + icount = icount + 2; + + + var Shipping = ""; + if (InttrEdi.filetype == "E") + Shipping = formatEdiStr("txt", bill.SIREMARK); + else + Shipping = formatEdiStr("txt", bill.EDIREMARK); + + List ShippingList = formatlengthStr(Shipping, 70); + + if (Shipping != "") + { + r.WriteLine("17:" + formatListStr(ShippingList, 5) + "'"); + icount++; + } + + + + Shipping = formatEdiStr("txt", bill.SHIPPER); + ShippingList = formatlengthStr(Shipping, 35); + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + r.WriteLine("18::" + formatListStr(ShippingList, 6) + "'"); + icount = icount + 1; + + } + + + + Shipping = formatEdiStr("txt", bill.CONSIGNEE); + ShippingList = formatlengthStr(Shipping, 35); + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + r.WriteLine("19::" + formatListStr(ShippingList, 6) + "'"); + icount = icount + 1; + + } + + + Shipping = formatEdiStr("txt", bill.NOTIFYPARTY); + ShippingList = formatlengthStr(Shipping, 35); + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + r.WriteLine("20::" + formatListStr(ShippingList, 6) + "'"); + icount = icount + 1; + + } + + + Shipping = formatEdiStr("txt", InttrEdi.ForWarderName); + ShippingList = formatlengthStr(Shipping, 35); + + if (Shipping != "") + { + + r.WriteLine("23::" + formatListStr(ShippingList, 6) + "'"); + icount = icount + 1; + + + + } + + var ctnsumlist = new List(); + foreach (var ctn in bill.CTNLIST) + { + var isfind = false; + ctnsumlist.ForEach(i => + { + if (i.CTNALLCODE == ctn.CTNALLCODE) + { + i.CTNNUM = i.CTNNUM + ctn.CTNNUM; + isfind = true; + } + }); + if (!isfind) + { + var ctnnum = new SeaExportCtnEDIBaseModel(); + ctnnum.CTNALLCODE = ctn.CTNALLCODE; + ctnnum.CTNNUM = ctn.CTNNUM; + ctnsumlist.Add(ctnnum); + } + } + + foreach (var ctnsum in ctnsumlist) + { + r.WriteLine("40:" + ctnsum.CTNALLCODE + ":" + ctnsum.CTNNUM + ":F:::::N'"); + icount++; + } + + + var cargoid = bill.CARGOID; + if (cargoid == "" || cargoid == " ") cargoid = "S"; + + var kingweight = bill.KINGTAREWEIGHT; + if (kingweight == 0) + kingweight = 100; + + r.WriteLine("41:1:" + bill.HSCODE + ":" + cargoid + ":" + bill.PKGS.ToString() + ":" + bill.KINDPKGS_EDI_CODE + ":" + bill.KINDPKGS + ":" + kingweight.ToString("0.###") + ":" + + bill.CBM.ToString("0.###") + "::::::" + bill.KGS.ToString("0.###") + ":::'"); + + icount = icount + 1; + if (cargoid == "R") + r.WriteLine("43::::::::::" + bill.REEFERF + ":C:" + bill.TEMPSET + ":" + bill.TEMPMIN + ":" + bill.TEMPMAX + ":::::'"); + else if (cargoid == "D") + r.WriteLine("43:" + bill.DCLASS + ":" + bill.DPAGE + ":" + bill.DUNNO + ":" + bill.DLABEL + "::::::::::::'"); + + icount = icount + 1; + + + Shipping = formatEdiStr("txt", bill.MARKS); + ShippingList = formatlengthStr(Shipping, 35); + + for (var i = 0; i < Math.Ceiling(Convert.ToDecimal(Convert.ToDecimal(ShippingList.Count) / Convert.ToDecimal(10))); i++) + { + var tempstr = "44:"; + for (var z = 0; z < 10; z++) + { + if ((i * 10 + z) < ShippingList.Count) + tempstr = tempstr + ShippingList[i * 10 + z]; + if (z < 9) tempstr = tempstr + ":"; + } + if (tempstr != "44:") + { + r.WriteLine(tempstr + "'"); + icount++; + } + } + + Shipping = formatEdiStr("txt", bill.DESCRIPTION); + ShippingList = formatlengthStr(Shipping, 70); + + var m = 1; + var strtemp = ""; + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + + for (var i = 0; i < ShippingList.Count; i++) + { + if (ShippingList[i] != "") + { + if (m <= 5) + { + if (m == 1) strtemp = "47:" + ShippingList[i] + ":"; + else + { + if (m == 5) + strtemp = strtemp + ShippingList[i]; + else + strtemp = strtemp + ShippingList[i] + ":"; + } + } + else + { + m = 1; + r.WriteLine(strtemp + "'"); + strtemp = "47:" + ShippingList[i] + ":"; + icount = icount + 1; + } + m = m + 1; + } + } + } + if (strtemp != "") + { + r.WriteLine(strtemp + "'"); + icount = icount + 1; + } + + var ISSOC = "N"; + if (bill.ISCONTAINERSOC) ISSOC = "Y"; + foreach (var ctn in bill.CTNLIST) + { + r.WriteLine("51:" + ctn.CNTRNO + ":" + ctn.CTNALLCODE + ":" + ctn.SEALNO + ":::" + ctn.CTNSTATUS + ":" + ctn.PKGS.ToString() + ":" + ctn.KGS.ToString("0.###") + ":" + ctn.TAREWEIGHT.ToString("0.###") + ":" + ctn.CBM.ToString("0.###") + "'"); + icount = icount + 1; + } + } + icount = icount + 1; + r.WriteLine("99:" + icount.ToString() + "'"); + r.Close(); + f.Close(); + + result.Succeeded = true; + result.ExtraData1 = filename; + return result; + + } + #endregion + } +} diff --git a/ds-wms-service/DS.WMS.Core/Op/EDI/XiahuozhiHelpler.cs b/ds-wms-service/DS.WMS.Core/Op/EDI/XiahuozhiHelpler.cs new file mode 100644 index 00000000..bcf116f4 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Op/EDI/XiahuozhiHelpler.cs @@ -0,0 +1,1576 @@ +using DS.Module.Core.Helpers; +using DS.WMS.Core.Code.Entity; +using DS.WMS.Core.Map.Entity; +using DS.WMS.Core.Sys.Entity; +using Newtonsoft.Json.Linq; +using NPOI.HSSF.UserModel; +using NPOI.SS.Formula.Functions; +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace DS.WMS.Core.Op.EDI +{ + /// + /// 下货纸辅助类 + /// + public static class XiahuozhiHelpler + { + private static readonly string EdiFilePath = "XHZ"; + + private static readonly string TEMP_REGEX = "(TEMP\\b\\s?\\:.*?\\n)|(TEMP\\b\\s?\\:.*)|(TEMP\\b\\s?\\;.*?\\n)|(TEMP\\b\\s?\\;.*)|(TEMPERATURE\\b\\s?\\:.*?\\n)|(TEMPERATURE\\b\\s?\\:.*)|(TEMPERATURE\\b\\s?\\;.*?\\n)|(TEMPERATURE\\b\\s?\\;.*)|(TEMP\\b\\sSETTING\\sAT\\:.*)|(TEM\\b\\s?\\:.*)|(TEMPERATURE\\s+OF\\n.*)|(TEMP\\s+.*)"; + private static readonly string TEMP_TAKE_REGEX = "((?<=TEMP\\s\\:).*?(?=\\n))|((?<=TEMP\\s\\:).*)|((?<=TEMP\\:).*?(?=\\n))|((?<=TEMP\\:).*)|((?<=TEMP\\s\\;).*?(?=\\n))|((?<=TEMP\\s\\;).*?)|((?<=TEMP\\;).*?(?=\\n))|((?<=TEMP\\;).*)|((?<=TEMPERATURE\\s\\:).*?(?=\\n))|((?<=TEMPERATURE\\s\\:).*?)|((?<=TEMPERATURE\\:).*?(?=\\n))|((?<=TEMPERATURE\\:).*)|((?<=TEMPERATURE\\s\\;).*?(?=\\n))|((?<=TEMPERATURE\\s\\;).*?)|((?<=TEMPERATURE\\;).*?(?=\\n))|((?<=TEMPERATURE\\;).*)|((?<=TEMP\\s+SETTING\\s+AT\\:).*)|((?<=TEM\\:).*)|((?<=TEMPERATURE\\sOF\\n).*(?=DEGREES))|((?<=TEMP\\s\\:).*)|((?<=TEMP\\s+).*)"; + private static readonly string VENT_REGEX = "(VENT\\b\\s?\\:.*?\\n)|(VENT\\b\\s?\\:.*)|(VENT\\b\\s?\\;.*?\\n)|(VENT\\b\\s?\\;.*)|(VENTILATION\\s+HOLE\\b\\s?\\:.*)|(VENTILATION\\b\\s?\\:.*)|(VENT\\s+.*)"; + private static readonly string VENT_TAKE_REGEX = "((?<=VENT\\s\\:).*?(?=\\n))|((?<=VENT\\s\\:).*?)|((?<=VENT\\:).*?(?=\\n))|((?<=VENT\\:).*)|((?<=VENT\\s\\;).*?(?=\\n))|((?<=VENT\\s\\;).*?)|((?<=VENT\\;).*?(?=\\n))|((?<=VENT\\;).*)|((?<=VENTILATION\\s+HOLE\\:).*)|((?<=VENTILATION\\:).*)|((?<=VENT\\s+).*)"; + private static readonly string HUMI_REGEX = "(HUMI\\b\\s?\\:.*?\\n)|(HUMI\\b\\s?\\:.*)|(HUMI\\b\\s?\\;.*?\\n)|(HUMI\\b\\s?\\;.*)|(HDMI\\b\\s?\\:.*?\\n)|(HDMI\\b\\s?\\:.*)|(HDMI\\b\\s?\\;.*?\\n)|(HDMI\\b\\s?\\;.*)|(HDIM\\b\\s?\\:.*?\\n)|(HDIM\\b\\s?\\:.*)|(HDIM\\b\\s?\\;.*?\\n)|(HDIM\\b\\s?\\;.*)|(HUM\\b\\s?\\:.*?\\n)|(HUM\\b\\s?\\:.*)|(HUM\\b\\s?\\;.*?\\n)|(HUM\\b\\s?\\;.*)|(HUMIDITY\\b\\s?\\:.*)|(HUMD\\b\\:.*)"; + private static readonly string HUMI_TAKE_REGEX = "((?<=HUMI\\s\\:).*?(?=\\n))|((?<=HUMI\\s\\:).*?)|((?<=HUMI\\:).*?(?=\\n))|((?<=HUMI\\:).*)|((?<=HUMI\\s\\;).*?(?=\\n))|((?<=HUMI\\s\\;).*?)|((?<=HUMI\\;).*?(?=\\n))|((?<=HUMI\\;).*)|((?<=HDMI\\s\\:).*?(?=\\n))|((?<=HDMI\\s\\:).*?)|((?<=HDMI\\:).*?(?=\\n))|((?<=HDMI\\:).*)|((?<=HDMI\\s\\;).*?(?=\\n))|((?<=HDMI\\s\\;).*?)|((?<=HDMI\\;).*?(?=\\n))|((?<=HDMI\\;).*)|((?<=HDIM\\s\\:).*?(?=\\n))|((?<=HDIM\\s\\:).*?)|((?<=HDIM\\:).*?(?=\\n))|((?<=HDIM\\:).*)|((?<=HDIM\\s\\;).*?(?=\\n))|((?<=HDIM\\s\\;).*?)|((?<=HDIM\\;).*?(?=\\n))|((?<=HDIM\\;).*)|((?<=HUM\\s\\:).*?(?=\\n))|((?<=HUM\\s\\:).*?)|((?<=HUM\\:).*?(?=\\n))|((?<=HUM\\:).*)|((?<=HUM\\s\\;).*?(?=\\n))|((?<=HUM\\s\\;).*?)|((?<=HUM\\;).*?(?=\\n))|((?<=HUM\\;).*)|((?<=HUMIDITY\\:).*)|((?<=HUMD\\:).*)"; + + // public static async Task> Send( + // long bookingId, string filerole) + // { + // var repUser = App.GetService>(); + // var repOrder = App.GetService>(); + // var repCtn = App.GetService>(); + // var repBookingFile = App.GetService>(); + // var repUserMail = App.GetService>(); + + // var cacheService = App.GetService(); + + // var order = repOrder.FirstOrDefault(o => o.Id == bookingId); + // if (order == null) + // { + // return new KeyValuePair(false, "订舱信息未找到"); + // } + + // var checkRlt = XiahuozhiHelpler.CheckGoodsDescriptionWithInput(order); + + // if (!checkRlt.Key) + // { + // return checkRlt; + // } + + // var ctns = repCtn.Where(c => c.BILLID == bookingId).ToList(); + + // var dictData = await cacheService.GetAllDictData(); + // var yardCodeSetList = dictData.Where(x => x.TypeCode == "XiaHuoZhiYardCodeSet").ToList(); //所有支持下货纸的场站代码配置 + // var gljEdiCarrierSetList = dictData.Where(x => x.TypeCode == "XiaHuoZhiGLJEdiCarrierSet").ToList();//港联捷通过EDI发送下货纸船司配置 + // var gljExcelMailCarrierSetList = dictData.Where(x => x.TypeCode == "XiaHuoZhiGLJExcelMailCarrierSet").ToList();//港联捷通过邮件Excel下货纸船司配置 + + // var mappingCarrierAll = await cacheService.GetAllMappingCarrier(); + // var mappingCarrierLetterYard = mappingCarrierAll.Where(x => x.Module == "LetterYardCarrier").ToList(); //针对和川这种公共库不同的船司代码,需要匹配 + + // var yardArr = yardCodeSetList.Select(x => x.Value).ToArray(); + // if (!yardArr.Contains(order.YARDID)) + // { + // return new KeyValuePair(false, "不支持的场站"); + // } + + // if (string.IsNullOrEmpty(order.MBLNO)) + // { + // return new KeyValuePair(false, "主提单号不能为空"); + // } + + // if (string.IsNullOrEmpty(order.VESSEL)) + // { + // return new KeyValuePair(false, "船名不能为空"); + // } + + // if (string.IsNullOrEmpty(order.VOYNO)) + // { + // return new KeyValuePair(false, "海关航次不能为空"); + // } + + // if (order.CARGOID == "R") + // { + // //2023年10月11日,下货纸“货物标志”为“冻柜”时,对部分字段做校验 + // Regex regexSign = new Regex("^[-+]?([1-9][0-9]*|0)(\\.[0-9]+)?$"); + // if (!regexSign.IsMatch(order.TEMPSET)) + // { + // return new KeyValuePair(false, "冻柜的【设置温度】校验不通过,要求:必填、数字格式、可包含+或-"); + // } + // if (!string.IsNullOrEmpty(order.TEMPMIN) && !regexSign.IsMatch(order.TEMPMIN)) + // { + // return new KeyValuePair(false, "冻柜的【最低温度】校验不通过,要求:非必填、数字格式、可包含+或-"); + // } + // if (!string.IsNullOrEmpty(order.TEMPMAX) && !regexSign.IsMatch(order.TEMPMAX)) + // { + // return new KeyValuePair(false, "冻柜的【最高温度】校验不通过,要求:非必填、数字格式、可包含+或-"); + // } + + // Regex regex = new Regex("^([1-9][0-9]*|0)(\\.[0-9]+)?$"); + // if (!regex.IsMatch(order.HUMIDITY)) + // { + // return new KeyValuePair(false, "冻柜的【湿度】校验不通过,要求:必填(无要求可以填0)、数字格式、不能含有+或-"); + // } + // if (!regex.IsMatch(order.REEFERF)) + // { + // return new KeyValuePair(false, "冻柜的【冷藏通风量】校验不通过,要求:必填、数字格式、不能含有+或-"); + // } + + // //增加货描里的温度、湿度、通风与单个填写项的比对,必需一致才能提交 2024-04-17 JHQ + + // } + + // //2023年7月12日,下货纸为危险品时,需填写等级和编号 + // if (order.CARGOID == "D" && (string.IsNullOrEmpty(order.DUNNO) || string.IsNullOrEmpty(order.DCLASS))) + // { + // return new KeyValuePair(false, "危险品的等级和编号必须填写"); + // } + + // var fileOpt = App.GetOptions(); + // if (string.IsNullOrEmpty(fileOpt.basePath)) + // { + // fileOpt.basePath = App.WebHostEnvironment.WebRootPath; + // } + + // var yardCodeGLJ = yardCodeSetList.FirstOrDefault(x => x.Code == "YardGLJ"); + // if (yardCodeGLJ == null) + // { + // return new KeyValuePair(false, "港联捷场站代码未配置"); + // } + + // var yardCodeGJF = yardCodeSetList.FirstOrDefault(x => x.Code == "YardGJF"); + // if (yardCodeGJF == null) + // { + // return new KeyValuePair(false, "港捷丰场站代码未配置"); + // } + + // var yardCodeJieFeng = yardCodeSetList.FirstOrDefault(x => x.Code == "YardJieFeng"); + // if (yardCodeJieFeng == null) + // { + // return new KeyValuePair(false, "捷丰场站代码未配置"); + // } + + // var yardCodeGLX = yardCodeSetList.FirstOrDefault(x => x.Code == "YardGLX"); + // if (yardCodeGLX == null) + // { + // return new KeyValuePair(false, "港联欣站代码未配置"); + // } + + // var yardCodeZhongChuang = yardCodeSetList.FirstOrDefault(x => x.Code == "YardZhongChuang"); + // if (yardCodeZhongChuang == null) + // { + // return new KeyValuePair(false, "中创站代码未配置"); + // } + + + // //针对和川这种公共库不同的船司代码,需要匹配转换为当前的船司代码才能逻辑判断 + // var hlcCode = "HLC"; + // var mapCodeHLC = mappingCarrierLetterYard.FirstOrDefault(x => x.MapCode == "HLC"); + // if (mapCodeHLC != null) + // { + // hlcCode = mapCodeHLC.Code; + // } + + // #region 港联捷场站 + + // if (order.YARDID == yardCodeGLJ.Value) + // { + // var ediPathAbs = Path.Combine(fileOpt.basePath, fileOpt.relativePath, EdiFilePath); + // if (!Directory.Exists(ediPathAbs)) + // { + // Directory.CreateDirectory(ediPathAbs); + // } + + // //通过EDI发送下货纸的船司 + // if (gljEdiCarrierSetList.Select(x => x.Value).ToList().Contains(order.CARRIERID)) + // { + // //租户参数-港联捷下货纸代号 + // var paraXHZ = (await cacheService.GetAllTenantParam()).FirstOrDefault(p => p.TenantId == order.TenantId && p.ParaCode == "CODE_GLJ_XHZ"); + // if (paraXHZ == null || string.IsNullOrEmpty(paraXHZ.ItemCode)) + // { + // return new KeyValuePair(false, $"{order.TenantName} 港联捷场站 下货纸代号未找到或配置有误"); + // } + + // var ediFileName = $"{paraXHZ.ItemCode}_{order.MBLNO}_{DateTime.Now.Ticks}.txt"; + // var ediFileRela = Path.Combine(fileOpt.relativePath, EdiFilePath, ediFileName); + // var ediFileAbs = Path.Combine(ediPathAbs, ediFileName); + // var ediSettints = await cacheService.GetAllEdiSetting(); + // var dicData = await cacheService.GetAllDictData(); + // //港联捷所有用户使用一个ftp用户名和密码发送报文,使用文件名中的下货纸代号进行区分 + // var paraServer = dicData.FirstOrDefault(x => x.TypeCode == "booking_ftp_setting_glj" && x.Code == "ftp_server"); + // var paraUser = dicData.FirstOrDefault(x => x.TypeCode == "booking_ftp_setting_glj" && x.Code == "username"); + // var paraPwd = dicData.FirstOrDefault(x => x.TypeCode == "booking_ftp_setting_glj" && x.Code == "pwd"); + + // if (paraServer == null || paraUser == null || paraPwd == null) + // { + // return new KeyValuePair(false, $"港联捷下货纸FTP服务地址参数未配置"); + // } + + // StringBuilder sbData = new StringBuilder(); + // sbData.AppendLine($"01:{order.VESSEL}:{order.VOYNO}"); //船名 航次 + + // // 12:提单号:中转港:目的港:货代代码:船公司:HPL参考号:特殊说明 + // sbData.AppendLine($"12:{order.MBLNO}:{order.TRANSPORTID}:{GetMappingPortDischarge(order.PORTDISCHARGEID, "XHZ_GLJ")}:{paraXHZ.ItemCode}:{GetCarrierEDICode(order.CARRIERID, "XHZ_GLJ")}:{(order.CARRIERID == hlcCode ? order.CUSTNO : "")}:{ExchangeStr(order.YARDREMARK)}"); //主提单 中转港代码 目的港代码 货代代码 船公司 HPL参考号 备注 + // //2021-8-17,报文中不能体现英文字符①【:】②【,】,以空格代替 + // /* + // * 表象:QDAC064651 客户毛重28600 EDI进来28  + // 港联捷回复:是前面货名太长,后面内容截断了,每行不超过255字符就行 + // 解决方案:每行不超过255,品名只取前100就行 + // */ + // var despStr = ExchangeStr(order.DESCRIPTION.Replace(":", " ").Replace(",", " ")).Replace("\r\n", " ").Replace("\n", " "); + // if (despStr.Length > 100) + // { + // despStr = despStr.Substring(0, 100); + // } + + // //22:货名:件数:包装:重量:体积:危品标志:危品等级:危规号:副危品等级:副危规号:海污:温度:通风:湿度 + // sbData.AppendLine($"22:{despStr}:{order.PKGS}:{order.KINDPKGS}:{order.KGS}:{order.CBM}:{(order.CARGOID == "D" ? "Y" : "N")}:{order.DCLASS}:{order.DUNNO}::::{order.TEMPSET}:{order.REEFERF}:{order.HUMIDITY}");//货名 件数 包装代码 总重量 总体积 危品标志 危品等级 危规号 副危品等级 副危规号 温度 通风度 湿度 + + // var ctnCodes = (await GetAllCodeCtn()).Select(x => new { x.Code, x.Size }).ToList(); + // var ctnEdiList = (await GetAllMappingCtn()).AsQueryable().Where(x => x.Module == "XHZ_GLJ").ToList(); + + // foreach (var ctn in ctns) + // { + // var ctnFind = ctnCodes.FirstOrDefault(c => c.Code == ctn.CTNCODE); + // if (ctnFind == null) + // { + // return new KeyValuePair(false, $"未找到箱型 {ctn.CTNALL},请联系管理员"); + // } + + // var ctnEdi = ctnEdiList.FirstOrDefault(cc => cc.Code == ctn.CTNCODE); + // if (ctnEdi == null) + // { + // return new KeyValuePair(false, $"箱型({ctn.CTNALL})不匹配(EDI类型:XHZ_GLJ),无法发送下货纸,请联系管理员"); + // } + + // sbData.AppendLine($"13:{(order.ISCONTAINERSOC.HasValue && order.ISCONTAINERSOC.Value ? "SOC" : GetCtnForCarrier(order.CARRIERID, "XHZ_GLJ", dictData))}:{ctnFind.Size}:{ctnEdi.MapCode}:{ctn.CTNNUM}:{ExchangeStr(ctn.REMARK)}:N");//箱经营人代码 尺寸 箱型 箱数 备注 加重箱 + // } + + // Log.Information($"生成下货纸报文:{sbData.ToString()}"); + // File.WriteAllText(ediFileAbs, sbData.ToString()); + + // //挂载附件 + // var attFile = new BookingFile(); + // attFile.BookingId = order.Id; + // attFile.FileName = ediFileName; + // attFile.FilePath = ediFileRela; + // attFile.TypeCode = "xiahuozhi"; + // attFile.TypeName = "下货纸"; + // attFile.TenantName = order.TenantName; + // repBookingFile.Insert(attFile); + + // //发送ftp + // SplitFtpServerAndPort(paraServer.Value, out string server, out int port); + + // var ftpSpiderUrl = dicData.FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "booking_edi_ftp_server").Value; + // NameValueCollection par = new NameValueCollection(); + // par.Add("host", server); + // par.Add("port", port.ToString()); + // par.Add("username", paraUser.Value); + // par.Add("pwd", paraPwd.Value); + // par.Add("path", "/"); + + // Log.Information($"准备请求发送ftp:{ftpSpiderUrl} ,参数:{par.ToJsonString()},文件:{ediFileName}"); + // var res = FTPHelper.TransmitFtpFile(ftpSpiderUrl, par, new + // { + // file = "file", + // fileName = Path.GetFileName(ediFileName), + // fileBytes = Encoding.UTF8.GetBytes(sbData.ToString()) + // }); + // Log.Information($"发送ftp返回:{res}"); + // var jobjRetn = JObject.Parse(res); + // if (jobjRetn.GetStringValue("status") != "1") + // { + // return new KeyValuePair(false, $"ftp发送失败:{jobjRetn.GetStringValue("message")}"); + // } + + + // return new KeyValuePair(true, $"已发送"); + // } + // //通过邮件发送Excel的船司 + // else if (gljExcelMailCarrierSetList.Select(x => x.Value).ToList().Contains(order.CARRIERID)) + // { + // var ediFileName = $"{order.CARRIERID}_{order.VESSEL}_{order.VOYNO}_{DateTime.Now.Ticks}.xls"; + // var ediFileRela = Path.Combine(fileOpt.relativePath, EdiFilePath, ediFileName); + // var ediFileAbs = Path.Combine(ediPathAbs, ediFileName); + + // var templateFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "XhzGljTemplate.xls"); + // if (!File.Exists(templateFile)) + // { + // return new KeyValuePair(false, $"模板EXCEL文件未找到,请联系管理员"); + // } + + // if (string.IsNullOrEmpty(order.YARDCONTRACTEMAIL)) + // { + // return new KeyValuePair(false, $"场站联系人邮箱未填写"); + // } + + // var userMail = repUserMail.FirstOrDefault(x => x.CreatedUserId == order.CreatedUserId); + // if (userMail == null + // || string.IsNullOrEmpty(userMail.SmtpServer) + // || userMail.SmtpPort == 0) + // { + // return new KeyValuePair(false, $"发件邮箱未配置"); + // } + + // MemoryStream ms = new MemoryStream(File.ReadAllBytes(templateFile)); + // var workbook = new HSSFWorkbook(ms); + // var sheet = workbook.GetSheetAt(0); + + // //第一行标题 + // var title = $"下货纸清单-{order.LANENAME} SERVICE"; + // sheet.GetRow(0).GetCell(0).SetCellValue(title); + + // //船期B2 + // sheet.GetRow(1).GetCell(1).SetCellValue(order.ETD.HasValue ? order.ETD.Value.ToString("yyyy.MM.dd") : ""); + + // //船名B3 + // sheet.GetRow(2).GetCell(1).SetCellValue(order.VESSEL); + + // //航次F3 + // sheet.GetRow(2).GetCell(5).SetCellValue(order.VOYNO); + + // //代理B4 + // sheet.GetRow(3).GetCell(1).SetCellValue(order.TenantName); + + // //联系电话F4 + // var usr = repUser.AsQueryable().Filter(null, true).First(u => u.Id == order.CreatedUserId); + // if (!string.IsNullOrEmpty(usr.Tel)) + // { + // sheet.GetRow(3).GetCell(5).SetCellValue(usr.Tel); + // } + // else if (!string.IsNullOrEmpty(usr.Phone)) + // { + // sheet.GetRow(3).GetCell(5).SetCellValue(usr.Phone); + // } + // else + // { + // sheet.GetRow(3).GetCell(5).SetCellValue(""); + // } + + // //订舱号B7 + // sheet.GetRow(6).GetCell(1).SetCellValue(order.CUSTNO); + + // //目的港C7 + // sheet.GetRow(6).GetCell(2).SetCellValue(order.PORTDISCHARGE); + + // //中转港D7 + // sheet.GetRow(6).GetCell(3).SetCellValue(order.TRANSPORTID); + + // //货名E7 + // sheet.GetRow(6).GetCell(4).SetCellValue(order.DESCRIPTION); + + // //件数F7 + // sheet.GetRow(6).GetCell(5).SetCellValue(order.PKGS.Value.ToString()); + + // //重量G7 + // sheet.GetRow(6).GetCell(6).SetCellValue(Convert.ToDouble(order.KGS.Value).ToString()); + + // //尺码H7 + // sheet.GetRow(6).GetCell(7).SetCellValue(Convert.ToDouble(order.CBM.Value).ToString()); + + // //冻柜信息 温度C I7 + // if (order.CARGOID == "R") + // { + // sheet.GetRow(6).GetCell(8).SetCellValue(order.TEMPSET); + // } + // else + // { + // sheet.GetRow(6).GetCell(8).SetCellValue(""); + // } + + // //冻柜信息 通风CBM/H J7 + // if (order.CARGOID == "R") + // { + // sheet.GetRow(6).GetCell(9).SetCellValue(order.REEFERF); + // } + // else + // { + // sheet.GetRow(6).GetCell(9).SetCellValue(""); + // } + + // //冻柜信息 湿度% K7 + // if (order.CARGOID == "R") + // { + // sheet.GetRow(6).GetCell(10).SetCellValue(order.HUMIDITY); + // } + // else + // { + // sheet.GetRow(6).GetCell(10).SetCellValue(""); + // } + + // //整理箱型箱量 + // var groupList = ctns.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => new { CTNALL = g.Key.Replace("'", ""), CTNNUM = g.Sum(gg => gg.CTNNUM) }); + + // //箱量 20GP L7 + // var findCtn = groupList.FirstOrDefault(x => x.CTNALL == "20GP"); + // if (findCtn != null) + // { + // sheet.GetRow(6).GetCell(11).SetCellValue(findCtn.CTNNUM.Value.ToString()); + // } + // else + // { + // sheet.GetRow(6).GetCell(11).SetCellValue(""); + // } + + // //箱量 40GP M7 + // findCtn = groupList.FirstOrDefault(x => x.CTNALL == "40GP"); + // if (findCtn != null) + // { + // sheet.GetRow(6).GetCell(12).SetCellValue(findCtn.CTNNUM.Value.ToString()); + // } + // else + // { + // sheet.GetRow(6).GetCell(12).SetCellValue(""); + // } + + // //箱量 40HC N7 + // findCtn = groupList.FirstOrDefault(x => x.CTNALL == "40HC"); + // if (findCtn != null) + // { + // sheet.GetRow(6).GetCell(13).SetCellValue(findCtn.CTNNUM.Value.ToString()); + // } + // else + // { + // sheet.GetRow(6).GetCell(13).SetCellValue(""); + // } + + // //箱量 20RF O7 + // findCtn = groupList.FirstOrDefault(x => x.CTNALL == "20RF"); + // if (findCtn != null) + // { + // sheet.GetRow(6).GetCell(14).SetCellValue(findCtn.CTNNUM.Value.ToString()); + // } + // else + // { + // sheet.GetRow(6).GetCell(14).SetCellValue(""); + // } + + // //箱量 40RH P7 + // findCtn = groupList.FirstOrDefault(x => x.CTNALL == "40RH"); + // if (findCtn != null) + // { + // sheet.GetRow(6).GetCell(15).SetCellValue(findCtn.CTNNUM.Value.ToString()); + // } + // else + // { + // sheet.GetRow(6).GetCell(15).SetCellValue(""); + // } + + // //备注 场站/特殊要求 Q7 + // sheet.GetRow(6).GetCell(16).SetCellValue(order.YARDREMARK); + + // MemoryStream msResult = new MemoryStream(); + // workbook.Write(msResult); + + // File.WriteAllBytes(ediFileAbs, msResult.GetBuffer()); + + // //挂载附件 + // var attFile = new BookingFile(); + // attFile.BookingId = order.Id; + // attFile.FileName = ediFileName; + // attFile.FilePath = ediFileRela; + // attFile.TypeCode = "xiahuozhi"; + // attFile.TypeName = "下货纸"; + // attFile.TenantName = order.TenantName; + // repBookingFile.Insert(attFile); + + // //发送邮件 + // var sendResult = await MailSendHelper.SendMail(userMail, title, "", order.YARDCONTRACTEMAIL, new KeyValuePair(ediFileName, msResult.GetBuffer())); + // if (!sendResult.Key) + // { + // return new KeyValuePair(false, sendResult.Value); + // } + + // return new KeyValuePair(true, $"已发送"); + // } + // else + // { + // return new KeyValuePair(false, "该船司不支持发送港联捷下货纸"); + // } + + // } + // #endregion + + // #region 港捷丰场站 捷丰场站 NOTE:港捷丰场站和捷丰场站下货纸功能,根据东胜7同功能模块代码翻译而来 + + // else if (order.YARDID == yardCodeGJF.Value || order.YARDID == yardCodeJieFeng.Value) + // { + // if (!order.PKGS.HasValue || order.PKGS.Value == 0) + // { + // return new KeyValuePair(false, $"件数不能为空"); + // } + + // if (string.IsNullOrEmpty(order.KINDPKGS)) + // { + // return new KeyValuePair(false, $"件数包装不能为空"); + // } + + // if (!order.KGS.HasValue || order.KGS.Value == 0) + // { + // return new KeyValuePair(false, $"重量不能为空"); + // } + + // if (!order.CBM.HasValue || order.CBM.Value == 0) + // { + // return new KeyValuePair(false, $"尺码不能为空"); + // } + + // var ediFileName = $"{order.VESSEL}_{order.VOYNO}_{order.MBLNO}_{DateTime.Now.Ticks}.txt"; + // var ediFileRela = Path.Combine(fileOpt.relativePath, EdiFilePath, ediFileName); + // var ediPathAbs = Path.Combine(fileOpt.basePath, fileOpt.relativePath, EdiFilePath); + // var ediFileAbs = Path.Combine(ediPathAbs, ediFileName); + // if (!Directory.Exists(ediPathAbs)) + // { + // Directory.CreateDirectory(ediPathAbs); + // } + + // DjyEdiSetting ftpset = null; + // if (order.YARDID == yardCodeGJF.Value) + // { + // ftpset = (await cacheService.GetAllEdiSetting()).FirstOrDefault(f => f.EDICODE == "XHZ_GJF" && f.TenantId == order.TenantId); + // } + // else if (order.YARDID == yardCodeJieFeng.Value) + // { + // ftpset = (await cacheService.GetAllEdiSetting()).FirstOrDefault(f => f.EDICODE == "XHZ_JIEFENG" && f.TenantId == order.TenantId); + // } + + // if (ftpset == null) + // { + // return new KeyValuePair(false, $"ftp设置未找到"); + // } + + // var ediParaName = "XHZ_GJF"; + // if (order.YARDID == yardCodeJieFeng.Value) + // { + // ediParaName = "XHZ_JIEFENG"; + // } + + // List listJoinStr = new List(); + // listJoinStr.Add("00:IFCSUM:BK:" + filerole + ":" + ftpset.SENDCODE + ":" + ftpset.RECEIVECODE + ":" + DateTime.Now.ToString("yyyyMMddHHmm") + ":2.1'"); + + // //提单号 + // listJoinStr.Add("02:" + order.Id.ToString() + ":" + order.MBLNO.Trim() + ":" + order.SERVICE + ":" + ftpset.SENDNAME + ":" + ftpset.RECEIVECODE + "::::::::::" + order.CONTRACTNO + ":" + (order.CARRIERID == hlcCode ? order.CUSTNO : "") + ":'"); + + // //提单地址 + // var ISSUETYPE = ""; + // if (order.ISSUETYPE == "正本") + // { + // ISSUETYPE = "ORI"; + // } + // else + // { + // ISSUETYPE = "EXP"; + // } + // listJoinStr.Add("03:" + ISSUETYPE + ":" + order.ISSUEPLACEID + ":" + order.ISSUEPLACE + ":" + GetDateStr(order.ISSUEDATE, "yyyyMMdd") + ":" + GetBillNum2(order.NOBILL) + ":" + order.PORTLOADID + ":" + order.PREPARDAT + ":" + order.PAYABLEAT + "::'");//美国AMS标志、加拿大AMS标志 + + // //船 + // listJoinStr.Add("11:" + GetVesselEDICode(order.VESSEL, ediParaName) + ":" + order.VESSEL + ":" + order.VOYNO + ":::" + GetCarrierEDICode(order.CARRIERID, ediParaName) + "::" + GetDateStr(order.ETD, "yyyyMMdd") + "::::::" + order.YARDCONTRACT + ":" + formatEdiStr("txt", order.YARDREMARK) + ":'"); + + // //港口 + // listJoinStr.Add("12:" + order.PLACERECEIPTID + ":" + order.PLACERECEIPT + ":" + order.PORTLOADID + ":" + order.PORTLOAD + ":" + GetMappingPortDischarge(order.PORTDISCHARGEID, ediParaName) + ":" + order.PORTDISCHARGE + ":::" + order.PLACEDELIVERYID + ":" + order.PLACEDELIVERY + ":" + order.DESTINATIONID + ":" + order.DESTINATION + "'"); + + // //付费方式 + // var frtstr = GetFrtEDICode(order.BLFRT); + // if (frtstr != "") + // { + // listJoinStr.Add("14:" + frtstr + ":" + order.BLFRT + "'"); + // listJoinStr.Add("15:::" + frtstr + ":::::::'"); + // } + // else + // { + // listJoinStr.Add("14:P:" + order.BLFRT + "'"); + // listJoinStr.Add("15:::P:::::::'"); + // } + + // var Shipping = ""; + // List ShippingList = null; + + // //2021年9月1日修改,17行取消,放到11行原FAX位置(于斐) + // ////EDI备注 + // //if (!string.IsNullOrWhiteSpace(order.YardRemark)) + // //{ + // // Shipping = formatEdiStr("txt", order.YardRemark); + // // ShippingList = formatlengthStr(Shipping, 70); + // // if (Shipping != "") + // // { + // // listJoinStr.Add("17:" + formatListStr(ShippingList, 5) + "'"); + // // } + // //} + + // //发货人 + // Shipping = formatEdiStr("txt", order.SHIPPER); + // ShippingList = formatlengthStr(Shipping, 35); + // if (ShippingList.Count != 0 && Shipping.Length > 0) + // { + // listJoinStr.Add("18::" + formatListStr(ShippingList, 6) + "'"); + // } + + // //收货人 + // Shipping = formatEdiStr("txt", order.CONSIGNEE); + // ShippingList = formatlengthStr(Shipping, 35); + // if (ShippingList.Count != 0 && Shipping.Length > 0) + // { + // listJoinStr.Add("19::" + formatListStr(ShippingList, 6) + "'"); + // } + + // //通知人 + // Shipping = formatEdiStr("txt", order.NOTIFYPARTY); + // ShippingList = formatlengthStr(Shipping, 35); + // if (ShippingList.Count != 0 && Shipping.Length > 0) + // { + // listJoinStr.Add("20::" + formatListStr(ShippingList, 6) + "'"); + // } + + // //货物标识 + // var cargoid = order.CARGOID; + // if (string.IsNullOrWhiteSpace(cargoid)) + // { + // cargoid = "S"; + // } + + // listJoinStr.Add("41:1::" + cargoid + ":" + order.PKGS.ToString() + ":" + order.KINDPKGS + ":" + order.KINDPKGS + ":" + order.KGS.ToString() + ":" + order.CBM.ToString() + "::::::" + order.KGS.ToString() + ":::'");//bill.HSCODE + + // if (cargoid == "R") + // { + // listJoinStr.Add("43:::::::::::" + order.REEFERF + ":C:" + order.TEMPSET + ":" + order.TEMPMIN + ":" + order.TEMPMAX + "::::::" + order.HUMIDITY + "::::'"); + // } + // else if (cargoid == "D") + // { + // listJoinStr.Add("43:" + order.DCLASS + ":" + order.DPAGE + ":" + order.DUNNO + ":" + order.DLABEL + "::::::::::::::::::::'"); + // } + + // //唛头 + // Shipping = formatEdiStr("txt", order.MARKS); + // ShippingList = formatlengthStr(Shipping, 35); + // for (var i = 0; i < Math.Ceiling(Convert.ToDecimal(Convert.ToDecimal(ShippingList.Count) / Convert.ToDecimal(9))); i++) + // { + // var tempstr = "44:"; + // for (var z = 0; z < 9; z++) + // { + // if ((i * 9 + z) < ShippingList.Count) + // tempstr = tempstr + ShippingList[i * 9 + z]; + // if (z < 8) tempstr = tempstr + ":"; + // } + // if (tempstr != "44:") + // { + + // listJoinStr.Add(tempstr + "'"); + // } + // } + + // //货物描述 + // Shipping = formatEdiStr("txt", order.DESCRIPTION); + // ShippingList = formatlengthStr(Shipping, 70); + // var m = 1; + // var strtemp = ""; + // if (ShippingList.Count != 0 && Shipping.Length > 0) + // { + // for (var i = 0; i < ShippingList.Count; i++) + // { + // if (m <= 5) + // { + // if (m == 1) strtemp = "47:" + ShippingList[i] + ":"; + // else + // { + // if (m == 5) + // strtemp = strtemp + ShippingList[i]; + // else + // strtemp = strtemp + ShippingList[i] + ":"; + // } + // } + // else + // { + // m = 1; + // listJoinStr.Add(strtemp + "'"); + // strtemp = "47:" + ShippingList[i] + ":"; + // } + // m = m + 1; + // } + // } + + // if (strtemp != "") + // { + // listJoinStr.Add(strtemp + "'"); + // } + + // //集装箱 + // var groupList = ctns.Where(c => c.CTNNUM.HasValue).GroupBy(c => c.CTNCODE).Select(c => new { c.Key, CTNNUM = c.Sum(cc => cc.CTNNUM) }).ToList(); + // foreach (var g in groupList) + // { + // listJoinStr.Add("48:" + GetCtnEDICode(g.Key, ediParaName) + ":" + g.CTNNUM + $":F:::::{(order.ISCONTAINERSOC.HasValue && order.ISCONTAINERSOC.Value ? "Y" : "N")}'"); + // } + + // foreach (var ctn in ctns) + // { + // if (ctn.CNTRNO != "") + // { + // listJoinStr.Add("51:" + ctn.CNTRNO + ":" + GetCtnEDICode(ctn.CTNCODE, ediParaName) + ":" + ctn.SEALNO + ":M:CA:F:" + ctn.PKGS.ToString() + ":" + ctn.KGS.ToString() + "::" + ctn.CBM + "'"); + // } + // } + + // listJoinStr.Add("99:" + listJoinStr.Count + 1 + "'"); + + // var strJoin = string.Join(Environment.NewLine, listJoinStr); + // Log.Information($"生成下货纸报文:{strJoin}"); + // File.WriteAllText(ediFileAbs, strJoin, Encoding.Default); + + // //挂载附件 + // var attFile = new BookingFile(); + // attFile.BookingId = order.Id; + // attFile.FileName = ediFileName; + // attFile.FilePath = ediFileRela; + // attFile.TypeCode = "xiahuozhi"; + // attFile.TypeName = "下货纸"; + // attFile.TenantName = order.TenantName; + // await repBookingFile.InsertAsync(attFile); + + // //发送ftp + // SplitFtpServerAndPort(ftpset.SERVERIP, out string server, out int port); + + // var ftpSpiderUrl = (await cacheService.GetAllDictData()).FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "booking_edi_ftp_server").Value; + // NameValueCollection par = new NameValueCollection(); + // par.Add("host", server); + // par.Add("port", port.ToString()); + // par.Add("username", ftpset.USERNAME); + // par.Add("pwd", ftpset.PASSWORD); + // par.Add("path", ftpset.FOLDERNAME); + // par.Add("pasv", (!ftpset.FtpModeActive).ToString()); + + + // Log.Information($"准备请求发送ftp:{ftpSpiderUrl} ,参数:{par.ToJsonString()},文件:{ediFileName}"); + // var res = FTPHelper.TransmitFtpFile(ftpSpiderUrl, par, new + // { + // file = "file", + // fileName = Path.GetFileName(ediFileName), + // fileBytes = Encoding.UTF8.GetBytes(strJoin) + // }); + // Log.Information($"发送ftp返回:{res}"); + // var jobjRetn = JObject.Parse(res); + // if (jobjRetn.GetStringValue("status") != "1") + // { + // return new KeyValuePair(false, $"ftp发送失败:{jobjRetn.GetStringValue("message")}"); + // } + + + // return new KeyValuePair(true, $"完成"); + // } + // #endregion + + // #region 港联欣场站 + // else if (order.YARDID == yardCodeGLX.Value || order.YARDID == yardCodeZhongChuang.Value) + // { + // //2022年6月15日增加:港联欣场站若配置了通过港联捷EDI发送,则使用港联捷报文格式 + // var tenantParam = await cacheService.GetAllTenantParam(); + // var pGlxEdi = tenantParam.FirstOrDefault(p => p.TenantId == order.TenantId && p.ParaCode == "XIAHUOZHI_GLX_SEND_TYPE"); + // if (order.YARDID == yardCodeGLX.Value && pGlxEdi != null && pGlxEdi.ItemCode == "EDI_GLX") + // { + // var glxCarrierList = dictData.Where(x => x.TypeCode == "XiaHuoZhiGLXCarrierConfig").Select(x => x.Value).ToList();//港联欣支持的船司 + // if (!glxCarrierList.Contains(order.CARRIERID)) + // { + // return new KeyValuePair(false, $"港联欣下货纸当前不支持此船公司"); + // } + + // var ftpset = (await cacheService.GetAllEdiSetting()).FirstOrDefault(f => f.EDICODE == "XHZ_GLX" && f.TenantId == order.TenantId); + // if (ftpset == null) + // { + // return new KeyValuePair(false, $"港联欣下货纸ftp设置未找到"); + // } + + // var paraXHZ = tenantParam.FirstOrDefault(p => p.TenantId == order.TenantId && p.ParaCode == "CODE_GLX_XHZ"); + // if (paraXHZ == null || string.IsNullOrEmpty(paraXHZ.ItemCode)) + // { + // return new KeyValuePair(false, $"下货纸代号未找到或配置有误"); + // } + + // var ediFileName = $"{paraXHZ.ItemCode}_{order.MBLNO}_{DateTime.Now.Ticks}.txt"; + // var ediFileRela = Path.Combine(fileOpt.relativePath, EdiFilePath, ediFileName); + // var ediPathAbs = Path.Combine(fileOpt.basePath, fileOpt.relativePath, EdiFilePath); + // var ediFileAbs = Path.Combine(ediPathAbs, ediFileName); + // if (!Directory.Exists(ediPathAbs)) + // { + // Directory.CreateDirectory(ediPathAbs); + // } + + // StringBuilder sbData = new StringBuilder(); + // sbData.AppendLine($"01:{order.VESSEL}:{order.VOYNO}"); //船名 航次 + + // sbData.AppendLine($"12:{order.MBLNO}:{order.TRANSPORTID}:{GetMappingPortDischarge(order.PORTDISCHARGEID, "XHZ_GLX")}:{paraXHZ.ItemCode}:{GetCarrierEDICode(order.CARRIERID, "XHZ_GLX")}:{(order.CARRIERID == hlcCode ? order.CUSTNO : "")}:{order.PORTDISCHARGE}"); //主提单 中转港代码 目的港代码 货代代码 船公司 HPL参考号 备注 + // var despStr = ExchangeStr(order.DESCRIPTION.Replace(":", " ").Replace(",", " ")).Replace("\r\n", " ").Replace("\n", " "); + // if (despStr.Length > 100) + // { + // despStr = despStr.Substring(0, 100); + // } + + // /* + //“22” 2 字符 货物信息开始 + //货名 20 字符 必填 + //件数 10 字符 必填 + //包装代码 6 字符 必填 + //总重量 11 字符 公斤 必填 + //总体积 6 字符 立方米 必填 + //危品标志 1 字符 Y/N 必填 + //危品等级 5 字符 + //危规号 5 字符 + //副危品等级 5 字符 + //副危规号 5 字符 + //温度 5 字符 不带单位,默认C + //通风度 5 字符 不带单位,默认CBM/H + //湿度 5 字符 不带单位,默认% + //回车换行 2 ASC码 ASC码“0D”“0A” + // */ + // sbData.AppendLine($"22:{despStr}:{order.PKGS}:{order.KINDPKGS}:{order.KGS}:{order.CBM}:{(order.CARGOID == "D" ? "Y" : "N")}:{order.DCLASS}:{order.DUNNO}:::{order.TEMPSET}:{order.REEFERF}:{order.HUMIDITY}");//货名 件数 包装代码 总重量 总体积 危品标志 危品等级 危规号 副危品等级 副危规号 温度 通风度 湿度 + + // var ctnCodes = (await GetAllCodeCtn()).Select(x => new { x.Code, x.Size }).ToList(); + // var ctnEdiList = (await GetAllMappingCtn()).AsQueryable().Where(x => x.Module == "XHZ_GLX").ToList(); + // var groupList = ctns.GroupBy(x => new { x.CTNALL, x.CTNCODE }).Select(x => new { CTNCODE = x.Key.CTNCODE, CTNALL = x.Key.CTNALL, COUNT = x.Sum(y => y.CTNNUM) }).ToList(); + // foreach (var ctn in groupList) + // { + // var ctnFind = ctnCodes.FirstOrDefault(c => c.Code == ctn.CTNCODE); + // if (ctnFind == null) + // { + // return new KeyValuePair(false, $"未找到箱型 {ctn.CTNALL},请联系管理员"); + // } + + // var ctnEdi = ctnEdiList.FirstOrDefault(cc => cc.Code == ctn.CTNCODE); + // if (ctnEdi == null) + // { + // return new KeyValuePair(false, $"箱型({ctn.CTNALL})不匹配(EDI类型:XHZ_GLX),无法发送下货纸,请联系管理员"); + // } + + // sbData.AppendLine($"13:{(order.ISCONTAINERSOC.HasValue && order.ISCONTAINERSOC.Value ? "SOC" : GetCtnForCarrier(order.CARRIERID, "XHZ_GLJ", dictData))}:{ctnFind.Size}:{ctnEdi.MapCode}:{ctn.COUNT}::N");//箱经营人代码 尺寸 箱型 箱数 备注 加重箱 + // } + + // Log.Information($"生成下货纸报文:{sbData.ToString()}"); + // File.WriteAllText(ediFileAbs, sbData.ToString()); + + // //挂载附件 + // var attFile = new BookingFile(); + // attFile.BookingId = order.Id; + // attFile.FileName = ediFileName; + // attFile.FilePath = ediFileRela; + // attFile.TypeCode = "xiahuozhi"; + // attFile.TypeName = "下货纸"; + // attFile.TenantName = order.TenantName; + // repBookingFile.Insert(attFile); + + // //发送ftp + // SplitFtpServerAndPort(ftpset.SERVERIP, out string server, out int port); + + // var ftpSpiderUrl = (await cacheService.GetAllDictData()).FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "booking_edi_ftp_server").Value; + // NameValueCollection par = new NameValueCollection(); + // par.Add("host", server); + // par.Add("port", port.ToString()); + // par.Add("username", ftpset.USERNAME); + // par.Add("pwd", ftpset.PASSWORD); + // par.Add("path", ftpset.FOLDERNAME); + // par.Add("pasv", (!ftpset.FtpModeActive).ToString()); + + // Log.Information($"准备请求发送ftp:{ftpSpiderUrl} ,参数:{par.ToJsonString()},文件:{ediFileName}"); + // var res = FTPHelper.TransmitFtpFile(ftpSpiderUrl, par, new + // { + // file = "file", + // fileName = Path.GetFileName(ediFileName), + // fileBytes = Encoding.UTF8.GetBytes(sbData.ToString()) + // }); + // Log.Information($"发送ftp返回:{res}"); + // var jobjRetn = JObject.Parse(res); + // if (jobjRetn.GetStringValue("status") != "1") + // { + // return new KeyValuePair(false, $"ftp发送失败:{jobjRetn.GetStringValue("message")}"); + // } + + // } + // else //邮件方式 + // { + // if (string.IsNullOrEmpty(order.YARDCONTRACTEMAIL)) + // { + // return new KeyValuePair(false, $"场站联系人邮箱不能为空"); + // } + + // var userMail = repUserMail.FirstOrDefault(x => x.CreatedUserId == order.CreatedUserId); + // if (userMail == null + // || string.IsNullOrEmpty(userMail.SmtpServer) + // || userMail.SmtpPort == 0) + // { + // return new KeyValuePair(false, $"发件邮箱未配置"); + // } + + + // var userbase = repUser.FirstOrDefault(u => u.Id == order.CreatedUserId); + // var title = $"下货纸:{order.MBLNO}/{order.CARRIER}/{order.VESSEL}/{order.VOYNO}/{order.TenantName}"; + + // var bodyExt = string.Empty; + // if (order.CARGOID == "R") + // { + // bodyExt = $@"温度:{order.TEMPSET}{order.TEMPID}
+ // 通风:{order.REEFERF}
+ // 湿度:{order.HUMIDITY}
"; + // } + // else if (order.CARGOID == "D") + // { + // bodyExt = $@"危险品等级:{order.DCLASS}
+ // 危险品编号:{order.DUNNO}
+ // 危险品联系方式:{order.LINKMAN}
"; + // } + + // var body = $@"提单号:{order.MBLNO}
+ // 船名航次:{order.VESSEL}/{order.VOYNO}
+ // 起运港:{order.PORTLOAD},{order.PORTLOADID}
+ // 目的港:{order.PORTDISCHARGE},{GetMappingPortDischarge(order.PORTDISCHARGEID, "XHZ_GLX")}
+ // 目的地:{order.DESTINATION},{order.DESTINATIONID}
+ // 预计船期:{(order.ETD.HasValue ? order.ETD.Value.ToString("yyyy-MM-dd") : "")}
+ // 箱型箱量:{order.CNTRTOTAL}
+ // 件重尺:{order.PKGS} {order.KINDPKGS}/{order.KGS}KGS/{order.CBM}CBM
+ // 货物描述:{order.DESCRIPTION}
+ // {bodyExt} + // 备注:{order.YARDREMARK}
+ //
+ // 订舱代理:{order.TenantName}
+ // 联系人:{order.CreatedUserName}
+ // 电话:{userbase.Tel} 手机:{userbase.Phone}
+ // 邮箱:{userbase.Email}
+ // "; + + // var sendResult = await MailSendHelper.SendMail(userMail, title, body, order.YARDCONTRACTEMAIL); + // if (!sendResult.Key) + // { + // return new KeyValuePair(false, sendResult.Value); + // } + // } + // return new KeyValuePair(true, "已发送"); + // } + // #endregion + + // else + // { + // return new KeyValuePair(false, "不支持的场站"); + // } + + // } + + // //转义处理字符串中的特殊字符 + // private static string ExchangeStr(string str) + // { + // if (string.IsNullOrEmpty(str)) + // { + // return string.Empty; + // } + + // return str.Replace("?", "??").Replace("'", "?'").Replace("+", "?+").Replace(":", "?:"); + // } + + // //根据船名,获取船名edi代码(根据东胜7同功能模块代码翻译而成) + // public static string GetVesselEDICode(string vessel, string EDINAME) + // { + // string EDICODE = ""; + // vessel = vessel.Replace("'", "''"); + + // var codeVesselEdi = GetAllMappingVessel().Result.FirstOrDefault(v => v.Name == vessel && v.Module == EDINAME); + // if (codeVesselEdi != null) + // { + // EDICODE = codeVesselEdi.MapName.Trim(); + // } + + // if (string.IsNullOrEmpty(EDICODE)) + // { + // var codeVessel = GetAllCodeVessel().Result.FirstOrDefault(v => v.Name == vessel); + // if (codeVessel != null && !string.IsNullOrEmpty(codeVessel.EdiCode)) + // { + // EDICODE = codeVessel.EdiCode.Trim(); + // } + // else + // { + // EDICODE = vessel; + // } + // } + + // return EDICODE; + // } + + // //获取时间字符串 + // public static string GetDateStr(DateTime? dt, string dateformat) + // { + // var result = ""; + // if (!dt.HasValue) + // { + // result = ""; + // } + // else + // { + // result = dt.Value.ToString(dateformat); + // } + + // return result; + // } + + // //获取客户edi代码(根据东胜7同功能模块代码翻译而成) + // public static string GetCarrierEDICode(string carrierCode, string EDINAME) + // { + // string EDICODE = ""; + + // var custEdi = GetAllMappingCarrier().Result.FirstOrDefault(c => c.Code == carrierCode && c.Module == EDINAME); + // if (custEdi != null) + // { + // EDICODE = custEdi.MapCode.Trim(); + // } + + // if (string.IsNullOrEmpty(EDICODE)) + // { + // var infoclient = GetAllCodeCarrier().Result.FirstOrDefault(c => c.Code == carrierCode); + // if (infoclient != null) + // { + // EDICODE = infoclient.EdiCode.Trim(); + // } + // } + + // return EDICODE; + // } + + // /// + // /// 获取箱属船司代码 + // /// + // /// + // public static string GetCtnForCarrier(string carrid, string EDINAME, List dictData) + // { + // var xiaHuoZhiCarrierBelongMapping = dictData.Where(x => x.TypeCode == "XiaHuoZhiCarrierBelongMapping").ToList();//港联捷、港联欣下货纸的箱属映射配置 + // var map = xiaHuoZhiCarrierBelongMapping.FirstOrDefault(x => x.Code == carrid); + // if (map != null) + // { + // return map.Value; + // } + // else + // { + // return GetCarrierEDICode(carrid, EDINAME); + // } + // } + + + // //获取付费方式edi代码(根据东胜7同功能模块代码翻译而成) + // public static string GetFrtEDICode(string FRT) + // { + // string EDICODE = "P"; + + // var ediFRT = GetAllMappingFrt().Result.FirstOrDefault(c => c.Code == FRT); + // if (ediFRT != null) + // { + // EDICODE = ediFRT.MapCode.Trim(); + // } + + // return EDICODE; + + // } + + // //获取edi代码(根据东胜7同功能模块移植) + // public static string GetBillNum2(string str) + // { + // if (str == "ZERO") return "00"; + // if (str == "ONE") return "01"; + // if (str == "TWO") return "02"; + // if (str == "THREE") return "03"; + // if (str == "FOUR") return "04"; + // if (str == "FIVE") return "05"; + // if (str == "SIX") return "06"; + // if (str == "SERVEN") return "07"; + // if (str == "EIGHT") return "08"; + // if (str == "NINE") return "09"; + // if (str == "TEN") return "10"; + // else return ""; + // } + + + // /// + // /// 各种文本转义字符(东胜7移植) + // /// + // /// 文件类型(例如:txt、xml) + // /// 文本字符串 + // /// + // public static string formatEdiStr(string fileType, string str) + // { + // if (str == null) + // str = string.Empty; + + // if (str == null) + // { + // return string.Empty; + // } + + // if (fileType == "txt") + // { + // return str.Replace("?", "??").Replace(":", "?:").Replace("+", "?+").Replace("'", "?'"); + // } + // else if (fileType == "xml") + // { + // return str.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace("\"", """).Replace("'", "'"); + // } + // else if (fileType == "sitc") + // { + // return str.Replace("?", "??").Replace(":", "?:").Replace("'", "?'"); + // } + // else + // { + // return str; + // } + // } + + // //东胜7移植 + // public static List formatlengthStr(string str, int length, bool formatstr = false, bool nodelsp = false) + // { + // str = str.Replace("\r\n", "\\"); + // str = str.Replace("\n", "\\"); + // str = str.Replace("\r", " "); + + + // string[] StrList = str.Split('\\'); + + // //List StrListtmp = new List(); + // //for (var i = StrList.Length - 1; i >=0; i--) + // //{ + + + // //} + + // var strtemp = ""; + // var strnewline = ""; + // var strtempnewline = ""; + // char[] spstring = { ' ', ';', ',', '.', ':', '/', '(', ')', '?', '+', '-' }; + // List DestList = new List(); + // for (var i = 0; i <= StrList.Length - 1; i++) + // { + // if (StrList[i].Length <= length) + // { + // if (formatstr) + // DestList.Add(formatEdiStr("txt", StrList[i])); + // else + // DestList.Add(StrList[i]); + + // } + // else + // { + // strtemp = StrList[i] + " "; + // strtempnewline = ""; + // strnewline = ""; + // for (var j = 0; j < strtemp.Length; j++) + // { + // strtempnewline = strtempnewline + strtemp[j]; + // if (strtemp[j] == ' ' || strtemp[j] == ':' || strtemp[j] == ',' || strtemp[j] == '.' || strtemp[j] == ':' || strtemp[j] == '/' + // || strtemp[j] == '?' || strtemp[j] == ')' || strtemp[j] == '}' || strtemp[j] == '+' || strtemp[j] == '-') + // { + // if ((strnewline.Length + strtempnewline.Length) <= length) + // strnewline = strnewline + strtempnewline; + // else + // { + // if (formatstr) + // DestList.Add(formatEdiStr("txt", strnewline)); + // else + // DestList.Add(strnewline); + // strnewline = strtempnewline; + + // } + + // strtempnewline = ""; + + // } + + // } + // if (nodelsp) + // { + // if (formatstr) + // DestList.Add(formatEdiStr("txt", strnewline)); + // else DestList.Add(strnewline); + // } + // else if (strnewline.Trim() != "") + // { + // if (formatstr) + // DestList.Add(formatEdiStr("txt", strnewline)); + // else DestList.Add(strnewline); + // } + // } + + // } + + // return DestList; + // } + + // //东胜7移植 + // public static string formatListStr(List DestList, int lineCount) + // { + // var result = ""; + // for (var i = 0; i < lineCount; i++) + // { + // if (DestList.Count > i) + // { + // result = result + DestList[i]; + // } + // if (i != (lineCount - 1)) + // result = result + ":"; + + + // } + // return result; + // } + + // /// + // /// 获取箱型的EDI代码 + // /// + // /// + // /// + // /// + // public static string GetCtnEDICode(string ctnCode, string EDINAME) + // { + // string EDICODE = ""; + + // var ctnEdi = GetAllMappingCtn().Result.FirstOrDefault(c => c.Code == ctnCode && c.Module == EDINAME); + // if (ctnEdi != null) + // { + // EDICODE = ctnEdi.MapCode.Trim(); + // } + + // if (string.IsNullOrEmpty(EDICODE)) + // { + // var infoclient = GetAllCodeCtn().Result.FirstOrDefault(c => c.Code == ctnCode); + // if (infoclient != null) + // { + // EDICODE = infoclient.EdiCode.Trim(); + // } + // } + + // return EDICODE; + // } + + // /// + // /// 获取所有箱型(使用缓存) + // /// + // /// + // private static async Task> GetAllCodeCtn() + // { + // var cacheService = App.GetService(); + // var ctnList = await cacheService.GetAllCodeCtn(); + // if (ctnList == null || ctnList.Count == 0) + // { + // var rep = App.GetService>(); + // ctnList = await rep.ToListAsync(); + // await cacheService.SetAllCodeCtn(ctnList); + // } + + // return ctnList; + // } + + // /// + // /// 获取所有船司(使用缓存) + // /// + // /// + // private static async Task> GetAllCodeCarrier() + // { + // var cacheService = App.GetService(); + // var list = await cacheService.GetAllCodeCarrier(); + // if (list == null || list.Count == 0) + // { + // var rep = App.GetService>(); + // list = await rep.ToListAsync(); + // await cacheService.SetAllCodeCarrier(list); + // } + + // return list; + // } + + // /// + // /// 获取所有箱型映射(使用缓存) + // /// + // /// + // private static async Task> GetAllMappingCtn() + // { + // var cacheService = App.GetService(); + // var ctnList = await cacheService.GetAllMappingCtn(); + // if (ctnList == null || ctnList.Count == 0) + // { + // var rep = App.GetService>(); + // ctnList = await rep.ToListAsync(); + // await cacheService.SetAllMappingCtn(ctnList); + // } + + // return ctnList; + // } + + // /// + // /// 获取所有船司映射(使用缓存) + // /// + // /// + // private static async Task> GetAllMappingCarrier() + // { + // var cacheService = App.GetService(); + // var list = await cacheService.GetAllMappingCarrier(); + // if (list == null || list.Count == 0) + // { + // var rep = App.GetService>(); + // list = await rep.ToListAsync(); + // await cacheService.SetAllMappingCarrier(list); + // } + + // return list; + // } + + // /// + // /// 获取所有付费方式(使用缓存) + // /// + // /// + // private static async Task> GetAllCodeFrt() + // { + // var cacheService = App.GetService(); + // var list = await cacheService.GetAllCodeFrt(); + // if (list == null || list.Count == 0) + // { + // var rep = App.GetService>(); + // list = await rep.ToListAsync(); + // await cacheService.SetAllCodeFrt(list); + // } + + // return list; + // } + + // /// + // /// 获取所有付费方式映射(使用缓存) + // /// + // /// + // private static async Task> GetAllMappingFrt() + // { + // var cacheService = App.GetService(); + // var list = await cacheService.GetAllMappingFrt(); + // if (list == null || list.Count == 0) + // { + // var rep = App.GetService>(); + // list = await rep.ToListAsync(); + // await cacheService.SetAllMappingFrt(list); + // } + + // return list; + // } + + // ///// + // ///// 获取所有公司参数(使用缓存) + // ///// + // ///// + // //private static async Task> GetAllTenantParam() + // //{ + // // var cacheService = App.GetService(); + // // var list = await cacheService.GetAllTenantParam(); + // // if (list == null || list.Count == 0) + // // { + // // var rep = App.GetService>(); + // // list = await sugerClient.Queryable().ToListAsync(); + // // await cacheService.SetAllTenantParam(list); + // // } + + // // return list; + // //} + + // /// + // /// 获取所有船名(使用缓存) + // /// + // /// + // private static async Task> GetAllCodeVessel() + // { + // var cacheService = App.GetService(); + // var list = await cacheService.GetAllCodeVessel(); + // if (list == null || list.Count == 0) + // { + // var rep = App.GetService>(); + // list = await rep.ToListAsync(); + // await cacheService.SetAllCodeVessel(list); + // } + + // return list; + // } + + // /// + // /// 获取所有船名映射(使用缓存) + // /// + // /// + // private static async Task> GetAllMappingVessel() + // { + // var cacheService = App.GetService(); + // var list = await cacheService.GetAllMappingVessel(); + // if (list == null || list.Count == 0) + // { + // var rep = App.GetService>(); + // list = await rep.ToListAsync(); + // await cacheService.SetAllMappingVessel(list); + // } + + // return list; + // } + + // /// + // /// 分割ftp服务器地址和端口 + // /// + // /// + // private static void SplitFtpServerAndPort(string str, out string server, out int port) + // { + // if (str.IndexOf(':') > -1) + // { + // var arr = str.Split(':'); + // server = arr[0]; + // port = Convert.ToInt32(arr[1]); + // } + // else + // { + // server = str; + // port = 21; + // } + // } + + // /// + // /// 根据订舱中的卸货港代码查找映射代码 + // /// + // /// 2023年8月18日,董怡含: + // /// 因客户平台维护港口五字代码于场站下货纸识别的五字代码不一致, + // /// 可否给场站下货纸模块增加目的港映射,可以单独配置场站能取到的五字代码(目前通过映射 + // /// 配置,下货纸中港口五字代码仍是订舱页面选择的港口代码) + // /// + // /// 订舱中的卸货港五字码 + // /// 映射模块代码,例如XHZ_GLJ + // private static string GetMappingPortDischarge(string portDischargeEdiCode, string module) + // { + // var cacheService = App.GetService(); + // var portList = cacheService.GetAllCodePort().Result; + // var portMapping = cacheService.GetAllMappingPort().Result; + // var q = from p in portList + // join pm in portMapping on p.Code equals pm.Code + // where pm.Module == module && p.EdiCode == portDischargeEdiCode + // select pm; + + // var mapList = q.ToList(); + // if (mapList.Any()) + // { + // return mapList[0].MapCode; + // } + + // return portDischargeEdiCode; + // } + + // #region 校验货描里的温度、湿度、通风与单个填写项进行比对 + // /// + // /// 校验货描里的温度、湿度、通风与单个填写项进行比对 + // /// + // /// 订舱详情 + // public static KeyValuePair CheckGoodsDescriptionWithInput(BookingOrder order) + // { + // /* + // 1、先从货描提取温度、湿度、通风。 + // 2、判断录入框的温度、湿度、通风与货描提取的是否一致,不一致报错。 + // */ + + // //温度 + // string tempSet = string.Empty; + // //通风 + // string reeferf = string.Empty; + // //湿度 + // string humidity = string.Empty; + + // if (!string.IsNullOrWhiteSpace(order.DESCRIPTION)) + // { + // if (Regex.IsMatch(order.DESCRIPTION, TEMP_REGEX)) + // { + // var currStr = Regex.Match(order.DESCRIPTION, TEMP_TAKE_REGEX).Value; + + // if (!string.IsNullOrWhiteSpace(currStr)) + // currStr = Regex.Replace(currStr, "\\:", ""); + + // if (!string.IsNullOrWhiteSpace(currStr)) + // tempSet = currStr.Replace("#", ""); + // } + + // if (Regex.IsMatch(order.DESCRIPTION, VENT_REGEX)) + // { + // var currStr = Regex.Match(order.DESCRIPTION, VENT_TAKE_REGEX).Value; + + // if (!string.IsNullOrWhiteSpace(currStr)) + // { + // reeferf = currStr.Replace("#", ""); + // } + // } + + // if (Regex.IsMatch(order.DESCRIPTION, HUMI_REGEX)) + // { + // var currStr = Regex.Match(order.DESCRIPTION, HUMI_TAKE_REGEX).Value; + + // if (!string.IsNullOrWhiteSpace(currStr)) + // { + // if (Regex.IsMatch(currStr, "\\(NO\\s+SHOW\\)")) + // currStr = Regex.Replace(currStr, "\\(NO\\s+SHOW\\)", ""); + + // humidity = currStr.Replace("#", ""); + // } + // } + // } + + // if (!string.IsNullOrWhiteSpace(order.TEMPSET) && !string.IsNullOrWhiteSpace(tempSet)) + // { + // string strA = string.Empty; + // string strB = string.Empty; + + // strA = Regex.Match(order.TEMPSET, "(\\+|\\-)?\\s?[0-9]+(\\.[0-9]+)?").Value?.Trim(); + // if (Regex.IsMatch(tempSet, "(\\+|\\-)?\\s?[0-9]+(\\.[0-9]+)?.('C|'\\s+C|℃|ºC|C)?")) + // { + // strB = Regex.Match(tempSet, "(\\+|\\-)?\\s?[0-9]+(\\.[0-9]+)?(?=.('C|'\\s+C|℃|ºC|C)?)").Value?.Trim(); + // } + + // if (!Regex.IsMatch(strA, "^\\+") && Regex.IsMatch(strB, "^\\+")) + // { + // strB = Regex.Match(strB, "(?<=\\+).*").Value?.Trim(); + // } + + // if (!strA.Equals(strB)) + // { + // return new KeyValuePair(false, $"货描温度 {tempSet} 与请求设定温度 {order.TEMPSET} 不一致"); + // } + // } + + // if (!string.IsNullOrWhiteSpace(order.REEFERF) && !string.IsNullOrWhiteSpace(reeferf)) + // { + // string strA = string.Empty; + // string strB = string.Empty; + + // strA = Regex.Match(order.REEFERF, "[0-9]+(\\.[0-9]+)?").Value?.Trim(); + + // if (Regex.IsMatch(reeferf, "[0-9]+(\\.[0-9]+)?\\s?(CBM\\/H)?")) + // { + // strB = Regex.Match(reeferf, "[0-9]+(\\.[0-9]+)?\\s?(?=(CBM\\/HR|CBM\\/HOUR|CBM\\s+\\/\\s+H|CBM\\/H|CMH|CBMH)?)").Value?.Trim(); + // } + // else + // { + // strB = Regex.Match(reeferf, "[0-9]+(\\.[0-9]+)?").Value?.Trim(); + // } + + // if (!strA.Equals(strB)) + // { + // if (!(Regex.IsMatch(reeferf, "(CLOSE(D)?|OFF)") && Regex.IsMatch(order.REEFERF?.Trim(), "^0(\\.0)?"))) + // { + // //如果货描通风显示英文 CLOSE、CLOSED、OFF,并且录入通风是 0或者0.0可以认为一致 + // return new KeyValuePair(false, $"货描通风 {reeferf} 与请求冷藏通风量 {order.REEFERF} 不一致"); + // } + // } + // } + + // if (!string.IsNullOrWhiteSpace(order.HUMIDITY) && !string.IsNullOrWhiteSpace(humidity)) + // { + // string strA = Regex.Match(order.HUMIDITY, "[0-9]+(\\.[0-9]+)?(\\%)?").Value?.Trim(); + // string strB = Regex.Match(humidity, "[0-9]+(\\.[0-9]+)?(\\%)?").Value?.Trim(); + + // if (order.HUMIDITY.Contains("%") && !humidity.Contains("%")) + // { + // strA = Regex.Match(order.HUMIDITY, "[0-9]+(\\.[0-9]+)?").Value?.Trim(); + // } + + // if (!order.HUMIDITY.Contains("%") && humidity.Contains("%")) + // { + // strB = Regex.Match(humidity, "[0-9]+(\\.[0-9]+)?").Value?.Trim(); + // } + + + // if (!strA.Equals(strB)) + // { + // return new KeyValuePair(false, $"货描湿度 {humidity} 与请求湿度 {order.HUMIDITY} 不一致"); + // } + // } + + // return new KeyValuePair(true, "货描提取温度、湿度、通风校验通过"); + // } + // #endregion + } +} diff --git a/ds-wms-service/DS.WMS.Core/Op/EDI/YMLEdiHelper.cs b/ds-wms-service/DS.WMS.Core/Op/EDI/YMLEdiHelper.cs new file mode 100644 index 00000000..c94971c3 --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Op/EDI/YMLEdiHelper.cs @@ -0,0 +1,1874 @@ +using DS.Module.Core; +using DS.WMS.Core.Op.Dtos; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace DS.WMS.Core.Op.EDI +{ + public class YMLEdiHelper + { + + public YMLEdiHelper() + { + } + + #region 基本函数 + public static string GetBillNum(string str) + { + if (str == "ZERO") return "0"; + if (str == "ONE") return "1"; + if (str == "TWO") return "2"; + if (str == "THREE") return "3"; + if (str == "FOUR") return "4"; + if (str == "FIVE") return "5"; + if (str == "SIX") return "6"; + if (str == "SERVEN") return "7"; + if (str == "EIGHT") return "8"; + if (str == "NINE") return "9"; + if (str == "TEN") return "10"; + else return ""; + } + public static string GetBillNum2(string str) + { + if (str == "ZERO") return "00"; + if (str == "ONE") return "01"; + if (str == "TWO") return "02"; + if (str == "THREE") return "03"; + if (str == "FOUR") return "04"; + if (str == "FIVE") return "05"; + if (str == "SIX") return "06"; + if (str == "SERVEN") return "07"; + if (str == "EIGHT") return "08"; + if (str == "NINE") return "09"; + if (str == "TEN") return "10"; + else return ""; + } + + + public static string GetDateStr(string datestr, string dateformat) + { + var result = ""; + + if (datestr == null || datestr == "") + { + result = ""; + } + else + { + result = Convert.ToDateTime(datestr).ToString(dateformat); + + } + + return result; + + } + + #region 判断中文字符 + public static bool IsChinese(char c) + { + return (int)c > 0x80; + } + public static bool StringIsChinese(string str) + { + var result = false; + for (int i = 1; i < str.Length; i++) + { + if (IsChinese(str[i])) + { + result = true; + return result; + } + } + for (int i = 0; i < str.Length; i++) + { + string stemp = str.Substring(i, 1); + int ilen = System.Text.Encoding.Default.GetByteCount(stemp); + if (ilen == 2) + { + result = true; + return result; + } + + } + + return result; + } + + #endregion + + public static string formatListStr(List DestList, int lineCount, bool isformat = false) + { + var result = ""; + for (var i = 0; i < lineCount; i++) + { + if (DestList.Count > i) + { + if (isformat) + result = result + formatEdiStr("txt", DestList[i]); + else + result = result + DestList[i]; + } + if (i != (lineCount - 1)) + result = result + ":"; + + + } + return result; + } + + + #region 文本字段判断每行是否符合 + /// + /// edi 文本格式处理判断(例如:1行35个字符不超过5行) + /// + /// 文件类型(例如:txt、xml) + /// 要处理的数据 + /// 每行长度 + /// 主提单号 + /// 数据类型(例如:发货人内容、货描等) + /// 限制录入的行数(“0”代表不限制) + /// 限录后多出的放到货描中的数据的连接符(例如:“*”发货人内容、“**”收件人等) + /// + public static System.String formatlengthError(string fileType, string str, int length, string sMBLNO, string sType, int rowNum, string sSymbol, bool isHuoMiao) + { + string error = ""; + string Shipping = str; + if (fileType == "txt") + { + Shipping = formatEdiStr("txt", str); + } + else if (fileType == "xml") + { + Shipping = formatEdiStr("txt", str); + } + string[] argAGENT = Shipping.Split(new string[] { "\r\n" }, StringSplitOptions.None); + if (argAGENT.Length > 0) + { + if (argAGENT.Length == 1) + { + argAGENT = Shipping.Split(new string[] { "\n" }, StringSplitOptions.None); + if (argAGENT.Length > 0) + { + if (argAGENT.Length > rowNum && rowNum != 0) + { + if (isHuoMiao) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据!"; + } + else + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据,多余信息请手动以“" + sSymbol + "”号开头放到货物描述中!(例如:“货描内容" + sSymbol + "超出部分”)"; + } + } + for (int j = 0; j < argAGENT.Length; j++) + { + //List AgentList = formatlengthStr(argAGENT[j].ToString(), 35); + if (argAGENT[j].ToString().Length > length) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 第" + (j + 1) + "行超过" + length + "个字符"; + } + } + } + } + else + { + if (argAGENT.Length > rowNum && rowNum != 0) + { + if (isHuoMiao) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据!"; + } + else + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据,多余信息请手动以“" + sSymbol + "”号开头放到货物描述中!(例如:“货描内容" + sSymbol + "超出部分”)"; + } + } + for (int j = 0; j < argAGENT.Length; j++) + { + //List AgentList = formatlengthStr(argAGENT[j].ToString(), 35); + if (argAGENT[j].ToString().Length > length) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 第" + (j + 1) + "行超过" + length + "个字符"; + } + } + } + } + return error; + } + #endregion + + #region 字符转义 + /// + /// 各种文本转义字符 + /// + /// 文件类型(例如:txt、xml) + /// 文本字符串 + /// + public static string formatEdiStr(string fileType, string str) + { + if (str == null) + str = string.Empty; + + if (fileType == "txt") + { + return str.Replace("?", "??").Replace(":", "?:").Replace("+", "?+").Replace("'", "?'"); + } + else if (fileType == "xml") + { + return str.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace("\"", """).Replace("'", "'"); + } + else if (fileType == "sitc") + { + return str.Replace("?", "??").Replace(":", "?:").Replace("'", "?'"); + } + else + { + return str; + } + } + #endregion + #region 格式化每行 + public static List formatlengthStr(string str, int length, bool formatstr = false, bool nodelsp = false) + { + str = str.Replace("\r\n", "\\"); + str = str.Replace("\n", "\\"); + str = str.Replace("\r", " "); + string[] StrList = str.Split('\\'); + var strtemp = ""; + var strnewline = ""; + var strtempnewline = ""; + char[] spstring = { ' ', ';', ',', '.', ':', '/', '(', ')', '?', '+', '-' }; + List DestList = new List(); + for (var i = 0; i <= StrList.Length - 1; i++) + { + if (StrList[i].Length <= length) + { + if (formatstr) + DestList.Add(formatEdiStr("txt", StrList[i])); + else + DestList.Add(StrList[i]); + + } + else + { + strtemp = StrList[i] + " "; + strtempnewline = ""; + strnewline = ""; + for (var j = 0; j < strtemp.Length; j++) + { + strtempnewline = strtempnewline + strtemp[j]; + if (strtemp[j] == ' ' || strtemp[j] == ':' || strtemp[j] == ',' || strtemp[j] == '.' || strtemp[j] == ':' || strtemp[j] == '/' + || strtemp[j] == '?' || strtemp[j] == ')' || strtemp[j] == '}' || strtemp[j] == '+' || strtemp[j] == '-') + { + if ((strnewline.Length + strtempnewline.Length) <= length) + strnewline = strnewline + strtempnewline; + else + { + if (formatstr) + DestList.Add(formatEdiStr("txt", strnewline)); + else + DestList.Add(strnewline); + strnewline = strtempnewline; + + } + strtempnewline = ""; + } + } + if (nodelsp) + { + if (formatstr) + DestList.Add(formatEdiStr("txt", strnewline)); + else DestList.Add(strnewline); + } + else if (strnewline.Trim() != "") + { + if (formatstr) + DestList.Add(formatEdiStr("txt", strnewline)); + else DestList.Add(strnewline); + } + } + + } + + return DestList; + } + #endregion + #endregion + + #region 检查 + public static string IsCreateYMLEDI(EDIBaseModel InttrEdi) + { + var error = ""; + + if (string.IsNullOrEmpty(InttrEdi.SENDCODE)) + { error = error + "
发送方代码不能为空"; } + + if (string.IsNullOrEmpty(InttrEdi.SENDNAME)) + { error = error + "
发送方名称不能为空"; } + + if (string.IsNullOrEmpty(InttrEdi.RECEIVECODE)) + { error = error + "
接收方代码不能为空"; } + + //if (InttrEdi.filetype == "B") + //{ + // if (InttrEdi.UseForWarderCode) + // { + // if (string.IsNullOrEmpty(InttrEdi.ForWarderCode)) + // { error = error + "
货代代码不能为空"; } + + // if (string.IsNullOrEmpty(InttrEdi.ForWarderName)) + // { error = error + "
货代称呼不能为空"; } + // } + //} + + + foreach (var headData in InttrEdi.BSLIST) + { + if (InttrEdi.filetype != "B") + if (string.IsNullOrEmpty(headData.MBLNO)) + { error = error + "
主提单号不能为空"; } + + if (string.IsNullOrEmpty(headData.BLFRT)) + { error = error + "
提单号:" + headData.MBLNO + " 付费方式不能为空"; } + if (string.IsNullOrEmpty(headData.EDIATTN)) + { error = error + "
提单号:" + headData.MBLNO + " EDI联系人不能为空"; } + if (string.IsNullOrEmpty(headData.EDIATTNTEL)) + { error = error + "
提单号:" + headData.MBLNO + " EDI联系人电话不能为空"; } + if (string.IsNullOrEmpty(headData.EDIATTNEMAIL)) + { error = error + "
提单号:" + headData.MBLNO + " EDI联系人邮编不能为空"; } + + + if (InttrEdi.filetype == "E") + { + if (string.IsNullOrEmpty(headData.VESSELID)) + { error = error + "
提单号:" + headData.MBLNO + " 船舶呼号不能为空"; } + + + if (InttrEdi.filetype != "B" || headData.CARRIEREDICODE == "YML") + { + if (string.IsNullOrEmpty(headData.ETD)) + { + error = error + "
提单号:" + headData.MBLNO + " 开船日期不能为空"; + return error; + } + } + } + + if (string.IsNullOrEmpty(headData.PLACERECEIPTID) || headData.PLACERECEIPTID.Length != 5) + { error = error + "
提单号:" + headData.MBLNO + " 收货地代码不能为空或录入不正确(必须是5位代码)"; } + + if (string.IsNullOrEmpty(headData.PLACERECEIPT)) + { error = error + "
提单号:" + headData.MBLNO + " 收货地不能为空"; } + + + if (string.IsNullOrEmpty(headData.PORTLOADID) || headData.PORTLOADID.Length != 5) + { error = error + "
提单号:" + headData.MBLNO + " 装货港代码不能为空或录入不正确(必须是5位代码)"; } + + if (string.IsNullOrEmpty(headData.PORTLOAD)) + { error = error + "
提单号:" + headData.MBLNO + " 装货港不能为空"; } + + + if (string.IsNullOrEmpty(headData.PORTDISCHARGEID) || headData.PORTDISCHARGEID.Length != 5) + { error = error + "
提单号:" + headData.MBLNO + " 卸货港代码不能为空或录入不正确(必须是5位代码)"; } + if (string.IsNullOrEmpty(headData.PORTDISCHARGE)) + { error = error + "
提单号:" + headData.MBLNO + " 卸货港不能为空"; } + + if (string.IsNullOrEmpty(headData.PLACEDELIVERY) || headData.PLACEDELIVERYID.Length != 5) + { error = error + "
提单号:" + headData.MBLNO + " 交货地代码不能为空或录入不正确(必须是5位代码)"; } + if (string.IsNullOrEmpty(headData.PLACEDELIVERY)) + { error = error + "
提单号:" + headData.MBLNO + " 交货地不能为空"; } + + if (string.IsNullOrEmpty(headData.DESTINATION)) + { + if (string.IsNullOrEmpty(headData.DESTINATIONID) || headData.DESTINATIONID.Length != 5) + { error = error + "
提单号:" + headData.MBLNO + " 目的地代码不能为空或录入不正确(必须是5位代码)"; } + } + + if (string.IsNullOrEmpty(headData.KINDPKGS_EDI_CODE)) + { error = error + "
提单号:" + headData.MBLNO + " 包装EDI代码不能为空"; } + if (headData.PKGS == 0) + { error = error + "
提单号:" + headData.MBLNO + " 件数不能为0"; } + if (headData.KGS == 0) + { error = error + "
提单号:" + headData.MBLNO + " 毛重不能为0"; } + if (headData.CBM == 0) + { error = error + "
提单号:" + headData.MBLNO + " 尺码不能为0"; } + + if (string.IsNullOrEmpty(headData.CARGOID)) + { error = error + "
提单号:" + headData.MBLNO + " 货物标识不能为空"; } + + if (headData.CARGOID == "D") + { + if (string.IsNullOrEmpty(headData.DCLASS)) + { error = error + "
提单号:" + headData.MBLNO + " 危险品分类不能为空"; } + + if (string.IsNullOrEmpty(headData.DUNNO)) + { error = error + "
提单号:" + headData.MBLNO + " 危险品编号不能为空"; } + } + if (headData.CARGOID == "R") + { + if (headData.TEMPSET == null || headData.TEMPSET == "") + { error = error + "
提单号:" + headData.MBLNO + " 设置温度不能为空"; } + if (headData.REEFERF == null || headData.REEFERF == "") + { error = error + "
提单号:" + headData.MBLNO + " 通风度不能为空"; } + } + if (headData.ISSUEPLACE == null || headData.ISSUEPLACE == "") + { error = error + "
提单号:" + headData.MBLNO + "签单地点不能为空"; } + + if (headData.CARRIEREDICODE == "APL") + if (headData.ISSUETYPE == null || headData.ISSUETYPE == "") + { error = error + "
提单号:" + headData.MBLNO + "签单方式不能为空"; } + if (headData.SERVICE == "" || headData.SERVICE == null) + { error = error + "
提单号:" + headData.MBLNO + "运输条款不能为空"; } + + if (string.IsNullOrEmpty(headData.MARKS)) + { + error = error + "
提单号:" + headData.MBLNO + " 唛头不能为空"; + } + else + { + if (StringIsChinese(headData.MARKS)) + { + error = error + "
提单号:" + headData.MBLNO + " 唛头含有中文或双字节字符"; + } + else + { + error += formatlengthError("txt", headData.MARKS, 35, headData.MBLNO, "唛头", 0, "", false); + } + } + + if (string.IsNullOrEmpty(headData.DESCRIPTION)) + { + error = error + "
提单号:" + headData.MBLNO + " 货物描述不能为空"; + } + else + { + if (StringIsChinese(headData.DESCRIPTION)) + { + error = error + "
提单号:" + headData.MBLNO + " 货物描述含有中文或双字节字符"; + } + else + { + //error += formatlengthError("txt", bill.DESCRIPTION, 35, bill.MBLNO, "货物描述", 0, ""); + } + } + + + if (string.IsNullOrEmpty(headData.SHIPPER)) + { + error = error + "
提单号:" + headData.MBLNO + " 发货人不能为空"; + } + else + { + if (StringIsChinese(headData.SHIPPER)) + { + error = error + "
提单号:" + headData.MBLNO + " 发货人含有中文或双字节字符"; + } + else + { + if (headData.CARRIEREDICODE == "HLCU") + { + error += formatlengthError("txt", headData.SHIPPER, 35, headData.MBLNO, "发货人", 6, "-", false); + } + else + { + error += formatlengthError("txt", headData.SHIPPER, 35, headData.MBLNO, "发货人", 6, "*", false); + } + } + } + //} + + + + if (string.IsNullOrEmpty(headData.CONSIGNEE)) + { + error = error + "
提单号:" + headData.MBLNO + " 收货人不能为空"; + } + else + { + if (StringIsChinese(headData.CONSIGNEE)) + { + error = error + "
提单号:" + headData.MBLNO + " 收货人含有中文或双字节字符"; + } + else + { + if (headData.CARRIEREDICODE == "HLCU") + { + error += formatlengthError("txt", headData.CONSIGNEE, 35, headData.MBLNO, "收货人", 6, "--", false); + } + else + { + error += formatlengthError("txt", headData.CONSIGNEE, 35, headData.MBLNO, "收货人", 6, "**", false); + } + } + } + + + + + if (string.IsNullOrEmpty(headData.NOTIFYPARTY)) + { + error = error + "
提单号:" + headData.MBLNO + " 通知人不能为空"; + } + else + { + if (StringIsChinese(headData.NOTIFYPARTY)) + { + error = error + "
提单号:" + headData.MBLNO + " 通知人含有中文或双字节字符"; + } + else + { + if (headData.CARRIEREDICODE == "HLCU") + { + error += formatlengthError("txt", headData.NOTIFYPARTY, 35, headData.MBLNO, "通知人", 6, "---", false); + } + else + { + error += formatlengthError("txt", headData.NOTIFYPARTY, 35, headData.MBLNO, "通知人", 6, "***", false); + } + } + } + + if (!string.IsNullOrEmpty(headData.NOTIFYPARTY2)) + { + error += formatlengthError("txt", headData.NOTIFYPARTY2, 35, headData.MBLNO, "第二通知人", 5, "", false); + } + + var ctnlist = headData.CTNLIST; + if (ctnlist.Count == 0) { error = error + "
提单号:" + headData.MBLNO + " 集装箱信息不能为空"; }; + + #region 集装箱判断检查 + if (ctnlist.Count != 0) + { + Decimal dlPKGS = 0; + Decimal dlKGS = 0; + Decimal dlCBM = 0; + foreach (var ctn in ctnlist) + { + if (string.IsNullOrEmpty(ctn.CTNALLCODE)) + { error = error + "
提单号:" + headData.MBLNO + " 集装箱箱型EDI代码不能为空"; } + if ((ctn.CTNALLCODE.IndexOf("RH") > 0 || ctn.CTNALLCODE.IndexOf("RF") > 0) && (headData.CARGOID != "R")) + { + { error = error + "
提单号:" + headData.MBLNO + " 集装箱箱型为冻柜,货类代码请选择冻柜"; } + } + + if (InttrEdi.filetype == "E") + { + + if (string.IsNullOrEmpty(ctn.CNTRNO)) + { error = error + "
提单号:" + headData.MBLNO + " 箱号不能为空"; } + if (string.IsNullOrEmpty(ctn.SEALNO)) + { error = error + "
提单号:" + headData.MBLNO + " 封号不能为空"; } + + if (ctn.KINDPKGS != headData.KINDPKGS) + { error = error + "
提单号:" + headData.MBLNO + " 中的包装类型与集装箱的包装类型不同"; } + dlPKGS += Convert.ToDecimal(ctn.PKGS); + dlKGS += Convert.ToDecimal(ctn.KGS); + dlCBM += Convert.ToDecimal(ctn.CBM); + } + } + if (InttrEdi.filetype == "E") + { + if (dlPKGS != Convert.ToDecimal(headData.PKGS)) + { error = error + "
提单号:" + headData.MBLNO + " 集装箱件数合计数必须等于委托单总件数"; } + if (dlKGS != Convert.ToDecimal(headData.KGS)) + { error = error + "
提单号:" + headData.MBLNO + " 集装箱重量合计数必须等于委托单总重量数"; } + if (dlCBM != Convert.ToDecimal(headData.CBM)) + { error = error + "
提单号:" + headData.MBLNO + " 集装箱尺码合计数必须等于委托单总尺码数"; } + } + } + + if (InttrEdi.filetype == "E") + { + if (headData.CTNGOODSLIST != null && headData.CTNGOODSLIST.Count > 0) + { + foreach (var ctn in ctnlist) + { + var isfind = false; + Int32 ctngoodssumpkgs = 0; + decimal ctngoodssumkgs = 0; + decimal ctngoodssumcbm = 0; + headData.CTNGOODSLIST.ForEach(i => + { + if (i.CNTRNO == ctn.CNTRNO) + { + isfind = true; + ctngoodssumpkgs = ctngoodssumpkgs + i.PKGS; + ctngoodssumkgs = ctngoodssumkgs + i.KGS; + ctngoodssumcbm = ctngoodssumcbm + i.CBM; + } + }); + if (!isfind) + { + error = error + "
提单号:" + headData.MBLNO + "的“" + ctn.CNTRNO + "”未添加分箱明细!"; + } + else + { + if (ctngoodssumpkgs != Convert.ToDecimal(ctn.PKGS)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctn.CNTRNO + " 分箱明细件数合计数不等于集装箱件数"; } + if (ctngoodssumkgs != Convert.ToDecimal(ctn.KGS)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctn.CNTRNO + " 分箱明细毛重合计数不等于集装箱毛重"; } + if (ctngoodssumcbm != Convert.ToDecimal(ctn.CBM)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctn.CNTRNO + " 分箱明细尺码合计数不等于集装箱毛重"; } + + } + + } + + foreach (var ctngood in headData.CTNGOODSLIST) + { + if (string.IsNullOrEmpty(ctngood.KINDPKGS)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱明细包装类型不能为空"; } + if (string.IsNullOrEmpty(ctngood.DESCRIPTION)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱货物描述不能为空"; } + else + { + error += formatlengthError("txt", ctngood.DESCRIPTION, 70, headData.MBLNO, "的“" + ctngood.CNTRNO + "”箱号的分箱货物描述", 0, "", false); + } + //if (string.IsNullOrEmpty(ctngood.HSCODE)) + //{ error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱HS编码不能为空"; } + if (string.IsNullOrEmpty(ctngood.KINDPKGS_EDI_CODE)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱明细包装类型代码不能为空"; } + + } + + } + + #endregion + + + } + + //2023-03-03 经过测试东胜的EDI根据付费方式,区分 到付-需要填到付地点不能填预付地点,预付只能填预付地点不能填到付地点 + //跟韩工确认增加判断 + if (!string.IsNullOrWhiteSpace(headData.BLFRT) && headData.BLFRT.IndexOf("PREPAID") >= 0) + { + if (string.IsNullOrWhiteSpace(headData.PREPARDAT)) + { + error = error + "
提单号:" + headData.MBLNO + " 付费方式是预付,预付地点不能为空"; + } + + if (!string.IsNullOrWhiteSpace(headData.PAYABLEAT)) + { + error = error + "
提单号:" + headData.MBLNO + " 付费方式是预付,到付地点不能填写"; + } + } + else if (!string.IsNullOrWhiteSpace(headData.BLFRT) && headData.BLFRT.IndexOf("COLLECT") >= 0) + { + if (string.IsNullOrWhiteSpace(headData.PAYABLEAT)) + { + error = error + "
提单号:" + headData.MBLNO + " 付费方式是到付,到付地点不能为空"; + } + + if (!string.IsNullOrWhiteSpace(headData.PREPARDAT)) + { + error = error + "
提单号:" + headData.MBLNO + " 付费方式是到付,预付地点不能填写"; + } + } + } + return error; + } + #endregion + + #region 生成报文(订舱) + public static EdiDataResult CreateEdiYML(EDIBaseModel InttrEdi) + { + var result = new EdiDataResult { Succeeded = false }; + + var filetype = "IFTMBF"; + string filename = InttrEdi.filerpath + "\\" + filetype + "_" + InttrEdi.BSLIST[0].MBLNO + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt"; + + //如果是部署linux需要修改路径 + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + filename = filename.Replace("\\", "/"); + + //if (System.IO.File.Exists(filename)) + //{ + // System.IO.File.Delete(filename); + //} + FileStream f = new FileStream(filename, FileMode.Create); + StreamWriter r = new StreamWriter(f, Encoding.Default); + var icount = 0; + var bsno = ""; + var isfirst = true; + foreach (var bill in InttrEdi.BSLIST) + { + if (isfirst) + { + r.WriteLine("00:IFTMBF:BOOKING:" + InttrEdi.filerole + ":" + InttrEdi.SENDCODE + ":" + InttrEdi.RECEIVECODE + ":" + DateTime.Now.ToString("yyyyMMddHHmm") + "'"); + isfirst = false; + icount++; + + } + + //2023-03-03 修改运输条款SERVICE改为EDI的映射值,经过韩工确认 + r.WriteLine("02" + + ":" + bill.ORDERNO//2 REFERENCE NO. 运编号 X(35) 一般为流水号 M + + ":" + bill.MBLNO//3 B\L NO. 提单号 X(20) 船公司的提单号 C + + ":" + bill.SERVICEEDICODE//4 DELIVERY TERM 交货条款 X(9) CY-CY(pier-pier/port):30CY-CFS(pier/port-door):29CFS-CY(door-pier/port):28CFS-CFS(door-door):27 M + + ":" + InttrEdi.SENDNAME//5 BOOKING PARTY 订舱人说明 X(70) 货代方企业名称或代码 C + + ":" + InttrEdi.RECEIVECODE//6 ISSUE PARTY CODE 签单人代码 X(13) 即接受订舱的人的代码 M + + ":"//7 ISSUE PARTY 签单人说明 X(35)   C + + ":"//8 APPLICANT 询价单位 X(13) 向船公司询价的单位代码 C + + ":"//9 FOB BK PARTY 国外订舱单位 X(13) 国外FOB货订舱单位的代码 C + + ":"//10 B/L TRANSHIP ID 转船标识 X(1) Y/N C + + ":"//11 BATCH ID 分批 X(1) Y/N C + + ":"//12 SHIPMENT DATE 装期 9(8) CCYYMMDD C + + ":"//13 EXPIRY DATE 效期 9(8) CCYYMMDD C + + ":" + bill.CONTRACTNO//14 QUOTATION NO. 运费协议号 X(30) MAERSK为必选 C + + ":"//15 CHARGE TYPE 费率本代码 X(1)   C + + "'"); + + icount++; + + var ISSUETYPE = ""; + + //2023-03-02 测试这里有问题,签单方式用的中文,要改成英文正本-ORIGINAL 电放-TELEX + /* + if (bill.ISSUETYPE == "正本") + { + ISSUETYPE = "ORI"; + } + else if (bill.ISSUETYPE == "电放") + { + ISSUETYPE = "TER"; + } + else ISSUETYPE = "EXP"; + */ + if (bill.ISSUETYPE == "ORIGINAL") + { + ISSUETYPE = "ORI"; + } + else if (bill.ISSUETYPE == "TELEX") + { + ISSUETYPE = "TER"; + } + else ISSUETYPE = "EXP"; + + //2023-03-03 测试东胜到付会自动填,新的订舱确认只读取页面写入值,经韩工确认 + r.WriteLine("03:" + ISSUETYPE + ":" + bill.ISSUEPLACEID.Trim() + ":" + bill.ISSUEPLACE.Trim() + ":" + GetDateStr(bill.ISSUEDATE, "yyyyMMdd") + ":" + GetBillNum2(bill.NOBILL) + ":" + bill.PREPARDAT + ":" + bill.PAYABLEAT + "'"); + icount++; + + //2023-03-03 测试东胜这行缺了FTP配置接收人代码,经韩工确认加上 + //r.WriteLine("11:" + bill.VESSELID + ":" + bill.VESSEL + ":" + bill.VOYNO + ":::::" + GetDateStr(bill.ETD, "yyyyMMdd") + ":::::'"); + r.WriteLine("11:" + bill.VESSELID + ":" + bill.VESSEL + ":" + bill.VOYNO + ":::" + InttrEdi.RECEIVECODE + "::" + GetDateStr(bill.ETD, "yyyyMMdd") + ":::::'"); + icount++; + + var DESTINATIONID = bill.DESTINATIONID; + var DESTINATION = bill.DESTINATION; + + r.WriteLine("12" + + ":" + bill.PLACERECEIPTID//2 PLACE CODE OF RECEIPT 收货地代码 X(5) OOCL、HLC的订舱要求必选 O + + ":" + bill.PLACERECEIPT//3 PLACE OF RECEIPT 收货地 X(35)   C + + ":" + bill.PORTLOADID//4 LOAD PORT CODE 装货港代码 X(5) OOCL的订舱要求必选 O + + ":" + bill.PORTLOAD//5 LOAD PORT 装货港 X(35)   C + + ":" + bill.PORTDISCHARGEID//6 DISCHARGE PORT CODE 卸货港代码 X(5) OOCL的订舱要求必选 M + + ":" + bill.PORTDISCHARGE//7 DISCHARGE PORT 卸货港 X(35)   C + + ":" + bill.TRANSPORTID //8 TRANSFER PORT CODE 中转港代码 X(5)   C + + ":" + bill.TRANSPORT//9 TRANSFER PORT 中转港 X(35)   C + + ":" + bill.PLACEDELIVERYID//10 PLACE OF DELIVERY CODE 交货地代码 X(5) OOCL的订舱要求必选 O + + ":" + bill.PLACEDELIVERY//11 PLACE OF DELIVERY 交货地 X(35)   C + + ":" + DESTINATIONID//12 FINAL DESTINATION CODE 目的地代码 X(5)   C + + ":" + DESTINATION//13 FINAL DESTINATION CODE 目的地 X(35)   C + + "'"); + + icount = icount + 1; + + r.WriteLine("14:" + bill.BLFRTEDICODE + ":" + bill.BLFRT + "'"); + if (InttrEdi.filetype == "E") + r.WriteLine("15:::" + bill.BLFRTEDICODE + ":" + bill.PAYABLEATID + ":::::'"); + else + r.WriteLine("15:::" + bill.BLFRTEDICODE + "::::::'"); + icount = icount + 2; + + + var Shipping = ""; + Shipping = formatEdiStr("txt", bill.EDIREMARK); + + List ShippingList = formatlengthStr(Shipping, 70); + + if (Shipping != "") + { + r.WriteLine("17:" + formatListStr(ShippingList, 5) + "'"); + icount++; + } + + + Shipping = formatEdiStr("txt", bill.SHIPPER); + ShippingList = formatlengthStr(Shipping, 35); + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + if (!string.IsNullOrEmpty(bill.ERNCODE) || !string.IsNullOrEmpty(bill.VAECODE) || !string.IsNullOrEmpty(bill.FECCODE)) + { + r.WriteLine("20::" + formatListStr(ShippingList, 9) + ":" + bill.ERNCODE + ":" + bill.VAECODE + ":" + bill.FECCODE + "'"); + } + else + r.WriteLine("20::" + formatListStr(ShippingList, 9) + "'"); + icount = icount + 1; + + } + + + + Shipping = formatEdiStr("txt", bill.CONSIGNEE); + ShippingList = formatlengthStr(Shipping, 35); + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + if (!string.IsNullOrEmpty(bill.TACCODE)) + { + r.WriteLine("21::" + formatListStr(ShippingList, 9) + ":" + bill.TACCODE + "'"); + } + else + r.WriteLine("21::" + formatListStr(ShippingList, 9) + "'"); + icount = icount + 1; + + } + + + Shipping = formatEdiStr("txt", bill.NOTIFYPARTY); + ShippingList = formatlengthStr(Shipping, 35); + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + r.WriteLine("22::" + formatListStr(ShippingList, 6) + "'"); + icount = icount + 1; + + } + + + Shipping = formatEdiStr("txt", bill.NOTIFYPARTY2); + ShippingList = formatlengthStr(Shipping, 35); + + if (Shipping != "") + { + + r.WriteLine("23::" + formatListStr(ShippingList, 6) + "'"); + icount = icount + 1; + + + + } + //2023-03-01 跟韩工确认默认有这行 24: + r.WriteLine("24" + + ":" + bill.EDIATTN// 2 BOOKING ISSUER 訂艙聯絡人 X(60) C + + ":" + bill.EDIATTNEMAIL//3 EMAIL ADDRESS 訂艙聯絡人e-mail X(80) 若有給e-mail address, 在收到客戶 EDI 後, 系統會發回擲信給該 e-mail 做為確認. C + + ":" + bill.EDIATTNTEL//4 TEL NO 訂艙聯絡人電話 X(80) C + + "'"); + icount++; + + + var cargoid = bill.CARGOID; + if (cargoid == "" || cargoid == " ") cargoid = "S"; + + var kingweight = bill.KINGTAREWEIGHT; + if (kingweight == 0) + kingweight = 100; + + r.WriteLine("41:1:" + bill.HSCODE + ":" + cargoid + ":" + bill.PKGS.ToString() + ":" + bill.KINDPKGS_EDI_CODE + ":" + bill.KINDPKGS + ":" + kingweight.ToString("0.###") + ":" + + bill.CBM.ToString("0.###") + "::::::" + bill.KGS.ToString("0.###") + ":::'"); + + icount = icount + 1; + if (cargoid == "R") + r.WriteLine("43::::::::::" + bill.REEFERF + ":C:" + bill.TEMPSET + ":" + bill.TEMPMIN + ":" + bill.TEMPMAX + ":::::'"); + else if (cargoid == "D") + r.WriteLine("43:" + bill.DCLASS + ":" + bill.DPAGE + ":" + bill.DUNNO + ":" + bill.DLABEL + "::::::::::::'"); + + icount = icount + 1; + + + Shipping = formatEdiStr("txt", bill.MARKS); + ShippingList = formatlengthStr(Shipping, 35); + + for (var i = 0; i < Math.Ceiling(Convert.ToDecimal(Convert.ToDecimal(ShippingList.Count) / Convert.ToDecimal(10))); i++) + { + var tempstr = "44:"; + for (var z = 0; z < 10; z++) + { + if ((i * 10 + z) < ShippingList.Count) + tempstr = tempstr + ShippingList[i * 10 + z]; + if (z < 9) tempstr = tempstr + ":"; + } + if (tempstr != "44:") + { + r.WriteLine(tempstr + "'"); + icount++; + } + } + + Shipping = formatEdiStr("txt", bill.DESCRIPTION); + ShippingList = formatlengthStr(Shipping, 70); + + var m = 1; + var strtemp = ""; + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + + for (var i = 0; i < ShippingList.Count; i++) + { + if (ShippingList[i] != "") + { + if (m <= 5) + { + if (m == 1) strtemp = "47:" + ShippingList[i] + ":"; + else + { + if (m == 5) + strtemp = strtemp + ShippingList[i]; + else + strtemp = strtemp + ShippingList[i] + ":"; + } + } + else + { + m = 1; + r.WriteLine(strtemp + "'"); + strtemp = "47:" + ShippingList[i] + ":"; + icount = icount + 1; + } + m = m + 1; + } + } + } + if (strtemp != "") + { + r.WriteLine(strtemp + "'"); + icount = icount + 1; + } + + var ISSOC = "N"; + if (bill.ISCONTAINERSOC) ISSOC = "Y"; + + var ctnsumlist = new List(); + + foreach (var ctn in bill.CTNLIST) + { + var newctnsum = ctnsumlist.Find(x => x.CTNALLCODE == ctn.CTNALLCODE); + if (newctnsum == null) + { + var ctnsum = new SeaExportCtnEDIBaseModel(); + ctnsum.CTNALLCODE = ctn.CTNALLCODE; + ctnsum.CTNNUM = ctn.CTNNUM; + if (bill.ISCONTAINERSOC && !string.IsNullOrEmpty(ctn.CNTRNO)) + { + if (!string.IsNullOrEmpty(ctnsum.CNTRNO)) + { + ctnsum.CNTRNO = ctn.CNTRNO; + } + else + { + ctnsum.CNTRNO = ctnsum.CNTRNO + "," + ctn.CNTRNO; + + } + } + ctnsumlist.Add(ctnsum); + + } + else + { + newctnsum.CTNNUM = newctnsum.CTNNUM + ctn.CTNNUM; + if (bill.ISCONTAINERSOC && !string.IsNullOrEmpty(ctn.CNTRNO)) + { + if (!string.IsNullOrEmpty(newctnsum.CNTRNO)) + { + newctnsum.CNTRNO = ctn.CNTRNO; + } + else + { + newctnsum.CNTRNO = newctnsum.CNTRNO + "," + ctn.CNTRNO; + + } + } + + } + } + foreach (var ctnsum in ctnsumlist) + { + if (InttrEdi.filetype == "E") + { + r.WriteLine("48:" + ctnsum.CTNALLCODE + ":" + ctnsum.CTNNUM + ":F:::::" + ISSOC + "'"); + icount = icount + 1; + } + else + { + var cntrnostr = ""; + var isrstr = "N"; + if (cargoid == "R") isrstr = "Y"; + r.WriteLine("48:" + ctnsum.CTNALLCODE + ":" + ctnsum.CTNNUM + ":F:::::" + ISSOC + ":" + cntrnostr + ":::" + isrstr + "'"); + icount = icount + 1; + + } + + } + + + } + + icount = icount + 1; + r.WriteLine("99:" + icount.ToString() + "'"); + r.Close(); + f.Close(); + + result.Succeeded = true; + result.ExtraData1 = filename; + return result; + } + #endregion + + #region 生成报文(确认) + public static EdiDataResult CreateEdiYMLSI(EDIBaseModel InttrEdi) + { + var result = new EdiDataResult { Succeeded = false }; + + string filename = InttrEdi.filerpath + "\\" + InttrEdi.BSLIST[0].MBLNO + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt"; + + //如果是部署linux需要修改路径 + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + filename = filename.Replace("\\", "/"); + + //if (System.IO.File.Exists(filename)) + //{ + // System.IO.File.Delete(filename); + //} + FileStream f = new FileStream(filename, FileMode.Create); + StreamWriter r = new StreamWriter(f, Encoding.Default); + + var icount = 0; + var bsno = ""; + foreach (var bill in InttrEdi.BSLIST) + { + bsno = bill.ORDERNO; + r.WriteLine("UNB+UNOA:1+" + InttrEdi.SENDCODE + ":ZZZ+" + InttrEdi.RECEIVECODE + ":ZZZ+" + DateTime.Now.ToString("yyMMdd:HHmm") + "+" + bill.ORDERNO + "'"); + r.WriteLine("UNH+" + bill.ORDERNO + "+IFTMIN:D:99B:UN'"); + var BGMSTR = ""; + + //2023 - 03 - 02 测试这里有问题,签单方式用的中文,要改成英文正本 - ORIGINAL 电放 - TELEX + /* + if (bill.ISSUETYPE == "正本") + { + BGMSTR = "705"; + + } + else + { + BGMSTR = "712"; + + } + */ + if (bill.ISSUETYPE == "ORIGINAL") + { + BGMSTR = "705"; + + } + else + { + BGMSTR = "712"; + + } + + if (InttrEdi.filerole == "9") + r.WriteLine("BGM+" + BGMSTR + "+" + bill.MBLNO + "+9'"); + else + r.WriteLine("BGM+" + BGMSTR + "+" + bill.MBLNO + "+5'"); + if (bill.SERVICE.ToUpper() == "DOOR-DOOR") + { + r.WriteLine("TSR+27+2'"); + } + else if (bill.SERVICE.ToUpper() == "DOOR-CY") + { + r.WriteLine("TSR+28+2'"); + } + else if (bill.SERVICE.ToUpper() == "CY-DOOR") + { + r.WriteLine("TSR+29+2'"); + } + else + { + r.WriteLine("TSR+30+2'"); + } + + var str_pay = ""; + if (bill.BLFRT.IndexOf("PREPAID") >= 0) + str_pay = bill.PREPARDAT; + if (bill.BLFRT.IndexOf("COLLECT") >= 0) + str_pay = bill.PAYABLEAT; + //r.WriteLine("FTX+AAI+++" + bill.BLFRT + " Payable at " + str_pay + " " + bill.SERVICE + " " + // + bill.PKGS.ToString() + bill.KINDPKGS + "'"); + icount = icount + 4; + + var Shipping = ""; + Shipping = formatEdiStr("txt", bill.SIREMARK); + Shipping = Shipping.Replace("\n", "\\"); + Shipping = Shipping.Replace("\r", " "); + string[] EdiRemarkList = Shipping.Split('\\'); + if (EdiRemarkList.Length != 0) + { + + for (var i = 0; i < EdiRemarkList.Length; i++) + { + r.WriteLine("FTX+AAI+++" + EdiRemarkList[i] + "'"); + icount = icount + 1; + + } + } + + if (bill.BYCOUNTRY == "USA") + { + if (bill.SCACCODE != "") + r.WriteLine("FTX+CCI++MFS+1:US:" + bill.SCACCODE + "'"); + else + r.WriteLine("FTX+CCI++MFS+5:US'"); + icount = icount + 1; + + } + else if (bill.BYCOUNTRY == "CANADA") + { + if (bill.SCACCODE != "") + r.WriteLine("FTX+CCI++MFS+1:CA:" + bill.SCACCODE + "'"); + else + r.WriteLine("FTX+CCI++MFS+5:CA'"); + icount = icount + 1; + + } + r.WriteLine("CNT+7:" + Math.Round(Convert.ToDecimal(bill.KGS), 3) + ":KGM'"); + r.WriteLine("CNT+11:" + bill.PKGS.ToString() + "'"); + r.WriteLine("CNT+15:" + Math.Round(Convert.ToDecimal(bill.CBM), 3) + ":MTQ'"); + + icount = icount + 3; + + if (bill.CARRIEREDICODE == "UASC") + { + if (bill.CTNLIST.Count > 0) + { + var ctnnum = 0; + foreach (var ctn in bill.CTNLIST) + { + ctnnum = ctnnum + ctn.CTNNUM; + } + r.WriteLine("CNT+16:" + ctnnum.ToString() + "'"); + icount = icount + 1; + } + + } + + if (bill.BLFRT == "FREIGHT COLLECT") + { + if (bill.PAYABLEAT != "") + { + r.WriteLine("LOC+57+" + bill.PREPARDATID + "::6:" + bill.PAYABLEAT + "'"); + icount = icount + 1; + } + } + else + { + r.WriteLine("LOC+57+" + bill.PREPARDATID + "::6:" + bill.PREPARDAT + "'"); + icount = icount + 1; + } + + r.WriteLine("LOC+73+" + bill.ISSUEPLACEID + "::6:" + bill.ISSUEPLACE + "'"); + icount = icount + 1; + + + + r.WriteLine("RFF+BN:" + bill.MBLNO + "'"); + icount = icount + 1; + + r.WriteLine("RFF+BM:" + bill.MBLNO + "'"); + + + + + r.WriteLine("RFF+CT:" + bill.CONTRACTNO + "'"); + icount = icount + 2; + + + if (bill.CARRIEREDICODE == "UASC") + { + r.WriteLine("RFF+SI:" + bill.ORDERNO + "'"); + icount = icount + 1; + + } + if (bill.BYCOUNTRY == "USA") + { + r.WriteLine("REF+TN:" + bill.ITNCODE + "'"); + icount = icount + 1; + + } + + if (bill.BLFRT.IndexOf("PREPAID") >= 0) + r.WriteLine("CPI+4++P'"); + else if (bill.BLFRT.IndexOf("COLLECT") >= 0) + r.WriteLine("CPI+4++C'"); + else + r.WriteLine("CPI+4++B'"); + icount = icount + 1; + + var voyno = ""; + if (bill.VOYNO.IndexOf(".") >= 0) + { + voyno = bill.VOYNO.Substring(bill.VOYNO.IndexOf(".") + 1, bill.VOYNO.Length - bill.VOYNO.IndexOf(".") - 1); + } + else + { + voyno = bill.VOYNO; + } + r.WriteLine("TDT+20+" + voyno + "+1++" + bill.CARRIEREDICODE + "+++:::" + bill.VESSEL + "'"); + r.WriteLine("LOC+9+" + bill.PORTLOADID + ":139:6:" + bill.PORTLOAD + "'"); + + r.WriteLine("LOC+88+" + bill.PORTLOADID + ":139:6:" + bill.PORTLOAD + "'"); + r.WriteLine("LOC+11+" + bill.PORTDISCHARGEID + ":139:6:" + bill.PORTDISCHARGE + "'"); + icount = icount + 4; + + if (bill.DESTINATION != "") + { + r.WriteLine("LOC+7+" + bill.DESTINATIONID + ":139:6:" + bill.DESTINATION + "'"); + icount = icount + 1; + + } + + + + var DescriptionShipper = ""; + Shipping = formatEdiStr("txt", bill.SHIPPER); + + List ShippingList = formatlengthStr(Shipping, 35); + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + + for (var i = 0; i < ShippingList.Count; i++) + { + if (i == 0) Shipping = "NAD+CZ+++" + ShippingList[0] + "+"; + if (i == 1) Shipping = Shipping + ShippingList[i]; + if (i == 2 || i == 3) Shipping = Shipping + ":" + ShippingList[i]; + if (i >= 4 && ShippingList.Count > 5) + { + if (i == 4) + { + if (ShippingList[i].Length > 34) + { + Shipping = Shipping + ":" + ShippingList[i].Substring(0, 34); + DescriptionShipper = ShippingList[i].Substring(34); + } + else + Shipping = Shipping + ":" + ShippingList[i]; + if (bill.CARRIEREDICODE == "HLCU") + { + Shipping = Shipping + "-"; + DescriptionShipper = "-" + DescriptionShipper; + } + else + { + Shipping = Shipping + "*"; + DescriptionShipper = "*" + DescriptionShipper; + } + + } + else if (i > 4) + { + + DescriptionShipper = DescriptionShipper + " " + ShippingList[i]; + } + + } + else + if (i == 4) Shipping = Shipping + ":" + ShippingList[i]; + } + } + + r.WriteLine(Shipping + "'"); + icount = icount + 1; + Shipping = formatEdiStr("txt", bill.CONSIGNEE); + + ShippingList = formatlengthStr(Shipping, 35); + + var DescriptionConsignee = ""; + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + + for (var i = 0; i < ShippingList.Count; i++) + { + if (i == 0) Shipping = "NAD+CN+++" + ShippingList[0] + "+"; + if (i == 1) Shipping = Shipping + ShippingList[i]; + if (i == 2 || i == 3) Shipping = Shipping + ":" + ShippingList[i]; + if (i >= 4 && ShippingList.Count > 5) + { + if (i == 4) + { + if (ShippingList[i].Length > 33) + { + Shipping = Shipping + ":" + ShippingList[i].Substring(0, 33); + DescriptionConsignee = ShippingList[i].Substring(33); + } + else + Shipping = Shipping + ":" + ShippingList[i]; + if (bill.CARRIEREDICODE == "HLCU") + { + Shipping = Shipping + "--"; + DescriptionConsignee = "--" + DescriptionConsignee; + } + else + { + Shipping = Shipping + "**"; + DescriptionConsignee = "**" + DescriptionConsignee; + } + + } + else if (i > 4) + { + + DescriptionConsignee = DescriptionConsignee + " " + ShippingList[i]; + } + + } + else + if (i == 4) Shipping = Shipping + ":" + ShippingList[i]; + } + } + + if (bill.BYCOUNTRY == "USA") + { + Shipping = Shipping + "+++" + bill.CONSIGNEEPOSTCODE; + r.WriteLine(Shipping + "'"); + } + else if (bill.BYCOUNTRY == "CANADA") + { + Shipping = Shipping + "+++" + bill.CONSIGNEEPOSTCODE + "+CA"; + r.WriteLine(Shipping + "'"); + } + else if (bill.BYCOUNTRY == "BRAZIL") + { + Shipping = Shipping + "++++" + bill.CONSIGNEECOUNTRY; + r.WriteLine(Shipping + "'"); + r.WriteLine("RFF+GN:" + bill.CONSIGNEETAXNO + "'"); + icount = icount + 1; + + } + else r.WriteLine(Shipping + "'"); + icount = icount + 1; + + if (bill.WEITUO != "") + { + if (bill.WEITUO.Length > 35) + r.WriteLine("NAD+FW+++" + formatEdiStr("txt", bill.WEITUO.Substring(0, 35)) + "+" + formatEdiStr("txt", bill.WEITUO.Substring(35)) + "'"); + else + r.WriteLine("NAD+FW+++" + formatEdiStr("txt", bill.WEITUO) + "'"); + + } + else + { + + if (InttrEdi.UseForWarderCode) + { + r.WriteLine("NAD+FW+" + InttrEdi.ForWarderCode + ":160:86++" + InttrEdi.ForWarderName + "'"); + icount++; + } + else + { + if (InttrEdi.SENDNAME.Length > 35) + r.WriteLine("NAD+FW+" + InttrEdi.SENDCODE + ":160:86++" + InttrEdi.SENDNAME.Substring(0, 35) + "+" + InttrEdi.SENDNAME.Substring(35) + "'"); + else + r.WriteLine("NAD+FW+" + InttrEdi.SENDCODE + ":160:86++" + InttrEdi.SENDNAME + "'"); + } + } + + + + icount++; + + Shipping = formatEdiStr("txt", bill.NOTIFYPARTY); + + ShippingList = formatlengthStr(Shipping, 35); + + var DescriptionNotifyparty = ""; + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + + for (var i = 0; i < ShippingList.Count; i++) + { + if (i == 0) Shipping = "NAD+NI+++" + ShippingList[0] + "+"; + if (i == 1) Shipping = Shipping + ShippingList[i]; + if (i == 2 || i == 3) Shipping = Shipping + ":" + ShippingList[i]; + if (i >= 4 && ShippingList.Count > 5) + { + if (i == 4) + { + if (ShippingList[i].Length > 32) + { + Shipping = Shipping + ":" + ShippingList[i].Substring(0, 32); + DescriptionNotifyparty = ShippingList[i].Substring(32); + } + else + Shipping = Shipping + ":" + ShippingList[i]; + if (bill.CARRIEREDICODE == "HLCU") + { + Shipping = Shipping + "---"; + DescriptionNotifyparty = "---" + DescriptionNotifyparty; + } + else + { + Shipping = Shipping + "***"; + DescriptionNotifyparty = "***" + DescriptionNotifyparty; + } + + } + else if (i > 4) + { + + DescriptionNotifyparty = DescriptionNotifyparty + " " + ShippingList[i]; + } + + } + else + if (i == 4) Shipping = Shipping + ":" + ShippingList[i]; + } + } + + if (bill.BYCOUNTRY == "USA") + { + Shipping = Shipping + "+++" + bill.NOTIFYPARTYPOSTCODE; + r.WriteLine(Shipping + "'"); + } + else if (bill.BYCOUNTRY == "BRAZIL") + { + if (bill.NOTIFYPARTYCOUNTRY != "") + Shipping = Shipping + "++++" + bill.NOTIFYPARTYCOUNTRY; + r.WriteLine(Shipping + "'"); + if (bill.NOTIFYPARTYTAXNO != "") + { + r.WriteLine("RFF+GN:" + bill.NOTIFYPARTYTAXNO + "'"); + icount = icount + 1; + + } + } + else r.WriteLine(Shipping + "'"); + icount = icount + 1; + + Shipping = formatEdiStr("txt", bill.NOTIFYPARTY2); + ShippingList = formatlengthStr(Shipping, 35); + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + for (var i = 0; i < ShippingList.Count; i++) + { + if (i == 0) Shipping = "NAD+N1+++" + ShippingList[0] + "+"; + if (i == 1) Shipping = Shipping + ShippingList[i]; + if (i == 2 || i == 3) Shipping = Shipping + ":" + ShippingList[i]; + if (i == 4) Shipping = Shipping + ":" + ShippingList[i]; + } + r.WriteLine(Shipping + "'"); + } + + + r.WriteLine("NAD+CA+YMLU:160:86++YML'"); + + if (InttrEdi.SENDNAME.Length > 35) + r.WriteLine("NAD+HI+" + InttrEdi.SENDCODE + ":160:86++" + InttrEdi.SENDNAME.Substring(0, 35) + "+" + InttrEdi.SENDNAME.Substring(35) + "'"); + else + r.WriteLine("NAD+HI+" + InttrEdi.SENDCODE + ":160:86++" + InttrEdi.SENDNAME + "'"); + + r.WriteLine("CTA+IC+:" + bill.EDIATTN + "'"); + r.WriteLine("COM+" + bill.EDIATTNTEL + ":TE'"); + r.WriteLine("COM+" + bill.EDIATTNEMAIL + ":EM'"); + icount = icount + 5; + var copynum = GetBillNum(bill.COPYNOBILL); + + //2023-03-02 测试这里有问题,签单方式用的中文,要改成英文正本-ORIGINAL 电放-TELEX + if (bill.ISSUETYPE == "ORIGINAL") + { + r.WriteLine("DOC+706+++" + GetBillNum(bill.NOBILL) + "'"); + icount = icount + 1; + if (copynum != "") + { + r.WriteLine("DOC+707+++" + copynum + "'"); + icount = icount + 1; + } + + } + else if (bill.ISSUETYPE == "海运单" || bill.ISSUETYPE.ToUpper() == "SEAWAY" || bill.ISSUETYPE.ToUpper() == "SEAWAY BILL" || bill.ISSUETYPE.ToUpper() == "WAYBILL" || bill.ISSUETYPE.ToUpper() == "SWB正本" || bill.ISSUETYPE.ToUpper() == "SWB无正本") + { + r.WriteLine("DOC+710+++" + GetBillNum(bill.NOBILL) + "'"); + icount = icount + 1; + + } + else if (bill.ISSUETYPE.ToUpper() == "BILL COPY" || bill.ISSUETYPE == "TELEX") + { + r.WriteLine("DOC+706+++" + GetBillNum(bill.NOBILL) + "'"); + icount = icount + 1; + if (copynum != "") + { + r.WriteLine("DOC+707+++" + copynum + "'"); + icount = icount + 1; + } + + } + else if (bill.ISSUETYPE == "正副本") + { + r.WriteLine("DOC+706+++" + GetBillNum(bill.NOBILL) + "'"); + icount = icount + 1; + if (copynum != "") + { + r.WriteLine("DOC+707+++" + copynum + "'"); + icount = icount + 1; + } + + } + else if (bill.ISSUETYPE.ToUpper() == "HOUSE BILL") + { + r.WriteLine("DOC+714+++" + GetBillNum(bill.NOBILL) + "'"); + icount = icount + 1; + + } + + //判断集装箱是否包含分箱明细 + + if (bill.CTNGOODSLIST == null || bill.CTNGOODSLIST.Count == 0) + { + #region 取委托单货描、唛头信息 + r.WriteLine("GID+1+" + bill.PKGS.ToString() + ":" + bill.KINDPKGS_EDI_CODE + "::6:" + bill.KINDPKGS + "'"); + + icount = icount + 1; + + if (bill.HSCODE != "") + { + r.WriteLine("PIA+5+" + bill.HSCODE + ":HS'"); + icount = icount + 1; + + } + + Shipping = formatEdiStr("txt", bill.DESCRIPTION); + + Shipping = Shipping.Replace("\n", "\\"); + Shipping = Shipping.Replace("\r", " "); + string[] DescriptionList = Shipping.Split('\\'); + if (DescriptionList.Length != 0) + { + + for (var i = 0; i < DescriptionList.Length; i++) + { + //if (DescriptionList[i] != "") + //{ + r.WriteLine("FTX+AAA+++" + DescriptionList[i] + "'"); + icount = icount + 1; + //} + + } + } + if (DescriptionShipper != "") + { + r.WriteLine("FTX+AAA+++" + DescriptionShipper + "'"); + icount = icount + 1; + + } + if (DescriptionConsignee != "") + { + r.WriteLine("FTX+AAA+++" + DescriptionConsignee + "'"); + icount = icount + 1; + + } + if (DescriptionNotifyparty != "") + { + r.WriteLine("FTX+AAA+++" + DescriptionNotifyparty + "'"); + icount = icount + 1; + + } + r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(Convert.ToDecimal(bill.KGS), 3) + "'"); + r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(Convert.ToDecimal(bill.CBM), 3) + "'"); + + icount = icount + 2; + + + if (!string.IsNullOrEmpty(bill.GOODSNCM)) + { + r.WriteLine("RFF+ABT:" + bill.GOODSNCM + "'"); + icount = icount + 1; + + } + Shipping = formatEdiStr("txt", bill.MARKS); + + Shipping = Shipping.Replace("\n", "\\"); + Shipping = Shipping.Replace("\r", " "); + string[] MarksList = Shipping.Split('\\'); + if (MarksList.Length != 0) + { + + for (var i = 0; i < MarksList.Length; i++) + { + + //if (MarksList[i] != "") + //{ + r.WriteLine("PCI++" + MarksList[i] + "'"); + icount = icount + 1; + //} + + } + } + + foreach (var ctn in bill.CTNLIST) + { + r.WriteLine("SGP+" + ctn.CNTRNO + "+" + ctn.PKGS.ToString() + "'"); + r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(Convert.ToDecimal(ctn.KGS), 3) + "'"); + r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(Convert.ToDecimal(ctn.CBM), 3) + "'"); + icount = icount + 3; + } + #endregion + } + else + { + + if (bill.CARRIEREDICODE == "UASC" || bill.CARRIEREDICODE == "HLCU" || bill.CARRIEREDICODE == "CMDU") + { + #region 取集装箱分箱_货描、唛头信息 + if (bill.CTNGOODSLIST != null) + { + if (bill.CTNGOODSLIST.Count > 0) + { + var i = 0; + foreach (var ctngood in bill.CTNGOODSLIST) + { + //GID+1+400:CT::6:CARTONS' + r.WriteLine("GID+" + (i + 1) + "+" + ctngood.PKGS.ToString() + ":" + ctngood.KINDPKGS_EDI_CODE + "::6:" + ctngood.KINDPKGS + "'"); + icount++; + //PIA+5+HS_CODE1:HS' + r.WriteLine("PIA+5+" + ctngood.HSCODE + ":HS'"); + icount++; + //FTX+AAA+++MATERIAL 1' + //FTX+AAA+++HS-NO 39023012' + Shipping = formatEdiStr("txt", ctngood.DESCRIPTION); + Shipping = Shipping.Replace("\n", "\\"); + Shipping = Shipping.Replace("\r", " "); + string[] DescriptionList = Shipping.Split('\\'); + if (DescriptionList.Length != 0) + { + for (var j = 0; j < DescriptionList.Length; j++) + { + r.WriteLine("FTX+AAA+++" + DescriptionList[j] + "'"); + icount++; + } + } + //MEA+AAE+WT+KGM:3000' + //MEA+AAE+AAW+MTQ:110.11' + r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(Convert.ToDecimal(ctngood.KGS), 3) + "'"); + icount++; + r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(Convert.ToDecimal(ctngood.CBM), 3) + "'"); + icount++; + //PCI++MARKS AND NUMBERS:FOR MATERIAL 1: OUR PONUMBER: PO_123456' + //if (isbill != 1) + //{ + // Shipping = formatEdiStr("txt", bill.MARKS); + //} + //else + //{ + Shipping = formatEdiStr("txt", ctngood.MARKS); + //} + if (string.IsNullOrEmpty(ctngood.MARKS)) Shipping = formatEdiStr("txt", bill.MARKS); + + Shipping = Shipping.Replace("\n", "\\"); + Shipping = Shipping.Replace("\r", " "); + string[] MarksList = Shipping.Split('\\'); + if (MarksList.Length != 0) + { + for (var j = 0; j < MarksList.Length; j++) + { + r.WriteLine("PCI++" + MarksList[j] + "'"); + icount++; + } + } + if (!string.IsNullOrEmpty(bill.GOODSNCM)) + { + r.WriteLine("RFF+ABT:" + bill.GOODSNCM + "'"); + icount++; + } + // + + //SGP+MSCU1234567+100' + r.WriteLine("SGP+" + ctngood.CNTRNO + "+" + ctngood.PKGS.ToString() + "'"); + //MEA+AAE+WT+KGM:1000' + r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(Convert.ToDecimal(ctngood.KGS), 3) + "'"); + //MEA+AAE+AAW+MTQ:50.11' + r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(Convert.ToDecimal(ctngood.CBM), 3) + "'"); + icount = icount + 3; + i = i + 1; + } + } + } + #endregion + + } + else + { + + #region 取集装箱分箱_货描、唛头信息 + + + var ctngoodssumlist = new List(); + foreach (var ctn in bill.CTNGOODSLIST) + { + var isfind = false; + ctngoodssumlist.ForEach(i => + { + if (i.HSCODE == ctn.HSCODE && i.KINDPKGS == ctn.KINDPKGS && i.DESCRIPTION == ctn.DESCRIPTION && i.MARKS == ctn.MARKS) + { + i.PKGS = i.PKGS + ctn.PKGS; + i.KGS = i.KGS + ctn.KGS; + i.CBM = i.CBM + ctn.CBM; + isfind = true; + } + }); + if (!isfind) + { + var ctnnum = new SeaExportCtnDetailEDIBaseModel(); + ctnnum.HSCODE = ctn.HSCODE; + ctnnum.KINDPKGS = ctn.KINDPKGS; + ctnnum.KINDPKGS_EDI_CODE = ctn.KINDPKGS_EDI_CODE; + ctnnum.DESCRIPTION = ctn.DESCRIPTION; + ctnnum.MARKS = ctn.MARKS; + ctnnum.PKGS = ctn.PKGS; + ctnnum.KGS = ctn.KGS; + ctnnum.CBM = ctn.CBM; + ctngoodssumlist.Add(ctnnum); + } + } + + if (ctngoodssumlist != null) + { + if (ctngoodssumlist.Count > 0) + { + var goodct = 0; + foreach (var ctngoodsum in ctngoodssumlist) + { + //GID+1+400:CT::6:CARTONS' + r.WriteLine("GID+" + (goodct + 1) + "+" + ctngoodsum.PKGS.ToString() + ":" + ctngoodsum.KINDPKGS_EDI_CODE + "::6:" + ctngoodsum.KINDPKGS + "'"); + icount++; + //PIA+5+HS_CODE1:HS' + r.WriteLine("PIA+5+" + ctngoodsum.HSCODE + ":HS'"); + icount++; + //FTX+AAA+++MATERIAL 1' + //FTX+AAA+++HS-NO 39023012' + Shipping = formatEdiStr("txt", ctngoodsum.DESCRIPTION); + Shipping = Shipping.Replace("\n", "\\"); + Shipping = Shipping.Replace("\r", " "); + string[] DescriptionList = Shipping.Split('\\'); + if (DescriptionList.Length != 0) + { + for (var j = 0; j < DescriptionList.Length; j++) + { + r.WriteLine("FTX+AAA+++" + DescriptionList[j] + "'"); + icount++; + } + } + //MEA+AAE+WT+KGM:3000' + //MEA+AAE+AAW+MTQ:110.11' + r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(Convert.ToDecimal(ctngoodsum.KGS), 3) + "'"); + icount++; + r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(Convert.ToDecimal(ctngoodsum.CBM), 3) + "'"); + icount++; + //PCI++MARKS AND NUMBERS:FOR MATERIAL 1: OUR PONUMBER: PO_123456' + //if (isbill != 1) + //{ + // Shipping = formatEdiStr("txt", bill.MARKS); + //} + //else + //{ + Shipping = formatEdiStr("txt", ctngoodsum.MARKS); + //} + + if (ctngoodsum.MARKS == "") Shipping = formatEdiStr("txt", bill.MARKS); + + + Shipping = Shipping.Replace("\n", "\\"); + Shipping = Shipping.Replace("\r", " "); + string[] MarksList = Shipping.Split('\\'); + if (MarksList.Length != 0) + { + for (var j = 0; j < MarksList.Length; j++) + { + r.WriteLine("PCI++" + MarksList[j] + "'"); + icount++; + } + } + if (!string.IsNullOrEmpty(bill.GOODSNCM)) + { + r.WriteLine("RFF+ABT:" + bill.GOODSNCM + "'"); + icount++; + } + goodct = goodct + 1; + bill.CTNGOODSLIST.ForEach(i => + { + if (i.HSCODE == ctngoodsum.HSCODE && i.KINDPKGS == ctngoodsum.KINDPKGS && i.DESCRIPTION == ctngoodsum.DESCRIPTION && i.MARKS == ctngoodsum.MARKS) + { + //SGP+MSCU1234567+100' + r.WriteLine("SGP+" + i.CNTRNO + "+" + i.PKGS.ToString() + "'"); + //MEA+AAE+WT+KGM:1000' + r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(Convert.ToDecimal(i.KGS), 3) + "'"); + //MEA+AAE+AAW+MTQ:50.11' + r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(Convert.ToDecimal(i.CBM), 3) + "'"); + icount = icount + 3; + } + }); + } + } + } + #endregion + } + + } + + if (bill.CARGOID == "D") + { + r.WriteLine("DGS+IMD+" + bill.DCLASS + "+" + bill.DUNNO + "'"); + r.WriteLine("CTA+HG+:" + bill.EDIATTN + "'"); + r.WriteLine("COM+" + bill.EDIATTNTEL + ":TE'"); + icount = icount + 3; + } + + #region 集装箱 主箱循环 + + foreach (var ctn in bill.CTNLIST) + { + if (bill.ISCONTAINERSOC) + r.WriteLine("EQD+CN+" + ctn.CNTRNO + "+" + ctn.CTNALLCODE + "+1'"); + else + r.WriteLine("EQD+CN+" + ctn.CNTRNO + "+" + ctn.CTNALLCODE + "+2'"); + r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(Convert.ToDecimal(ctn.KGS), 3) + "'"); + r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(Convert.ToDecimal(ctn.CBM), 3) + "'"); + icount = icount + 3; + + if (bill.CARGOID == "R") + { + if (bill.REEFERF != "") + { + r.WriteLine("MEA+AAE+AAS+CBM:" + bill.REEFERF + "'"); + icount = icount + 1; + } + } + r.WriteLine("SEL+" + ctn.SEALNO + "+CA'"); + icount = icount + 1; + + if (bill.CARGOID == "R") + { + r.WriteLine("TMP+2+" + bill.TEMPSET + ":CEL'"); + icount = icount + 1; + } + + } + #endregion + } + r.WriteLine("UNT+" + icount.ToString() + "+" + bsno + "'"); + r.WriteLine("UNZ+" + InttrEdi.BSLIST.Count.ToString() + "+" + bsno + "'"); + r.Close(); + f.Close(); + + result.Succeeded = true; + result.ExtraData1 = filename; + return result; + } + #endregion + + } +} diff --git a/ds-wms-service/DS.WMS.Core/Op/EDI/YTEdiHelper.cs b/ds-wms-service/DS.WMS.Core/Op/EDI/YTEdiHelper.cs new file mode 100644 index 00000000..624ec52a --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Op/EDI/YTEdiHelper.cs @@ -0,0 +1,1205 @@ +using DS.Module.Core; +using DS.WMS.Core.Op.Dtos; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace DS.WMS.Core.Op.EDI +{ + public class YTEdiHelper + { + + public YTEdiHelper() + { + } + + #region 基本函数 + + public static string GetBillNum2(string str) + { + if (str == "ZERO") return "00"; + if (str == "ONE") return "01"; + if (str == "TWO") return "02"; + if (str == "THREE") return "03"; + if (str == "FOUR") return "04"; + if (str == "FIVE") return "05"; + if (str == "SIX") return "06"; + if (str == "SERVEN") return "07"; + if (str == "EIGHT") return "08"; + if (str == "NINE") return "09"; + if (str == "TEN") return "10"; + else return ""; + } + + + public static string GetDateStr(string datestr, string dateformat) + { + var result = ""; + + if (datestr == null || datestr == "") + { + result = ""; + } + else + { + result = Convert.ToDateTime(datestr).ToString(dateformat); + + } + + return result; + + } + + #region 判断中文字符 + public static bool IsChinese(char c) + { + return (int)c > 0x80; + } + public static bool StringIsChinese(string str) + { + var result = false; + for (int i = 1; i < str.Length; i++) + { + if (IsChinese(str[i])) + { + result = true; + return result; + } + } + for (int i = 0; i < str.Length; i++) + { + string stemp = str.Substring(i, 1); + int ilen = System.Text.Encoding.Default.GetByteCount(stemp); + if (ilen == 2) + { + result = true; + return result; + } + + } + + return result; + } + + #endregion + + public static string formatListStr(List DestList, int lineCount, bool isformat = false) + { + var result = ""; + for (var i = 0; i < lineCount; i++) + { + if (DestList.Count > i) + { + if (isformat) + result = result + formatEdiStr("txt", DestList[i]); + else + result = result + DestList[i]; + } + if (i != (lineCount - 1)) + result = result + ":"; + + + } + return result; + } + + + #region 文本字段判断每行是否符合 + /// + /// edi 文本格式处理判断(例如:1行35个字符不超过5行) + /// + /// 文件类型(例如:txt、xml) + /// 要处理的数据 + /// 每行长度 + /// 主提单号 + /// 数据类型(例如:发货人内容、货描等) + /// 限制录入的行数(“0”代表不限制) + /// 限录后多出的放到货描中的数据的连接符(例如:“*”发货人内容、“**”收件人等) + /// + public static System.String formatlengthError(string fileType, string str, int length, string sMBLNO, string sType, int rowNum, string sSymbol, bool isHuoMiao) + { + string error = ""; + string Shipping = str; + if (fileType == "txt") + { + Shipping = formatEdiStr("txt", str); + } + else if (fileType == "xml") + { + Shipping = formatEdiStr("txt", str); + } + string[] argAGENT = Shipping.Split(new string[] { "\r\n" }, StringSplitOptions.None); + if (argAGENT.Length > 0) + { + if (argAGENT.Length == 1) + { + argAGENT = Shipping.Split(new string[] { "\n" }, StringSplitOptions.None); + if (argAGENT.Length > 0) + { + if (argAGENT.Length > rowNum && rowNum != 0) + { + if (isHuoMiao) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据!"; + } + else + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据,多余信息请手动以“" + sSymbol + "”号开头放到货物描述中!(例如:“货描内容" + sSymbol + "超出部分”)"; + } + } + for (int j = 0; j < argAGENT.Length; j++) + { + //List AgentList = formatlengthStr(argAGENT[j].ToString(), 35); + if (argAGENT[j].ToString().Length > length) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 第" + (j + 1) + "行超过" + length + "个字符"; + } + } + } + } + else + { + if (argAGENT.Length > rowNum && rowNum != 0) + { + if (isHuoMiao) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据!"; + } + else + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 不允许录入超过" + rowNum + "行数据,多余信息请手动以“" + sSymbol + "”号开头放到货物描述中!(例如:“货描内容" + sSymbol + "超出部分”)"; + } + } + for (int j = 0; j < argAGENT.Length; j++) + { + //List AgentList = formatlengthStr(argAGENT[j].ToString(), 35); + if (argAGENT[j].ToString().Length > length) + { + error = error + "
提单号:" + sMBLNO + " " + sType + " 第" + (j + 1) + "行超过" + length + "个字符"; + } + } + } + } + return error; + } + #endregion + + #region 字符转义 + /// + /// 各种文本转义字符 + /// + /// 文件类型(例如:txt、xml) + /// 文本字符串 + /// + public static string formatEdiStr(string fileType, string str) + { + if (str == null) + str = string.Empty; + + if (fileType == "txt") + { + return str.Replace("?", "??").Replace(":", "?:").Replace("+", "?+").Replace("'", "?'"); + } + else if (fileType == "xml") + { + return str.Replace("&", "&").Replace("<", "<").Replace(">", ">").Replace("\"", """).Replace("'", "'"); + } + else if (fileType == "sitc") + { + return str.Replace("?", "??").Replace(":", "?:").Replace("'", "?'"); + } + else + { + return str; + } + } + #endregion + #region 格式化每行 + public static List formatlengthStr(string str, int length, bool formatstr = false, bool nodelsp = false) + { + //2022-12-28 JHQ 传的字段是null会导致报错,这里改为如果是NULL则默认赋空字符串。 + if (str == null) + str = ""; + + str = str.Replace("\r\n", "\\"); + str = str.Replace("\n", "\\"); + str = str.Replace("\r", " "); + string[] StrList = str.Split('\\'); + var strtemp = ""; + var strnewline = ""; + var strtempnewline = ""; + char[] spstring = { ' ', ';', ',', '.', ':', '/', '(', ')', '?', '+', '-' }; + List DestList = new List(); + for (var i = 0; i <= StrList.Length - 1; i++) + { + if (StrList[i].Length <= length) + { + if (formatstr) + DestList.Add(formatEdiStr("txt", StrList[i])); + else + DestList.Add(StrList[i]); + + } + else + { + strtemp = StrList[i] + " "; + strtempnewline = ""; + strnewline = ""; + for (var j = 0; j < strtemp.Length; j++) + { + strtempnewline = strtempnewline + strtemp[j]; + if (strtemp[j] == ' ' || strtemp[j] == ':' || strtemp[j] == ',' || strtemp[j] == '.' || strtemp[j] == ':' || strtemp[j] == '/' + || strtemp[j] == '?' || strtemp[j] == ')' || strtemp[j] == '}' || strtemp[j] == '+' || strtemp[j] == '-') + { + if ((strnewline.Length + strtempnewline.Length) <= length) + strnewline = strnewline + strtempnewline; + else + { + if (formatstr) + DestList.Add(formatEdiStr("txt", strnewline)); + else + DestList.Add(strnewline); + strnewline = strtempnewline; + + } + strtempnewline = ""; + } + } + if (nodelsp) + { + if (formatstr) + DestList.Add(formatEdiStr("txt", strnewline)); + else DestList.Add(strnewline); + } + else if (strnewline.Trim() != "") + { + if (formatstr) + DestList.Add(formatEdiStr("txt", strnewline)); + else DestList.Add(strnewline); + } + } + + } + + return DestList; + } + #endregion + #endregion + + #region 检查 + public static string IsCreateYTEDI(EDIBaseModel InttrEdi) + { + var error = ""; + + if (string.IsNullOrEmpty(InttrEdi.SENDCODE)) + { error = error + "
发送方代码不能为空"; } + + if (string.IsNullOrEmpty(InttrEdi.SENDNAME)) + { error = error + "
发送方名称不能为空"; } + + if (string.IsNullOrEmpty(InttrEdi.RECEIVECODE)) + { error = error + "
接收方代码不能为空"; } + + //if (InttrEdi.filetype == "B") + //{ + // if (InttrEdi.UseForWarderCode) + // { + // if (string.IsNullOrEmpty(InttrEdi.ForWarderCode)) + // { error = error + "
货代代码不能为空"; } + + // if (string.IsNullOrEmpty(InttrEdi.ForWarderName)) + // { error = error + "
货代称呼不能为空"; } + // } + //} + + + foreach (var headData in InttrEdi.BSLIST) + { + + if (string.IsNullOrEmpty(headData.MBLNO)) + { error = error + "
主提单号不能为空"; } + + if (string.IsNullOrEmpty(headData.BLFRT)) + { error = error + "
提单号:" + headData.MBLNO + " 付费方式不能为空"; } + + + + if (InttrEdi.filetype == "E") + { + if (string.IsNullOrEmpty(headData.VESSEL)) + { error = error + "
提单号:" + headData.MBLNO + " 船名不能为空"; } + + if (string.IsNullOrEmpty(headData.VOYNO)) + { error = error + "
提单号:" + headData.MBLNO + " 航次不能为空"; } + + if (InttrEdi.filetype != "B" || headData.CARRIEREDICODE == "YML") + { + if (string.IsNullOrEmpty(headData.ETD)) + { + error = error + "
提单号:" + headData.MBLNO + " 开船日期不能为空"; + return error; + } + } + } + + if (headData.CARRIEREDICODE != "ZIM") + { + if (string.IsNullOrEmpty(headData.PLACERECEIPTID) || headData.PLACERECEIPTID.Length != 5) + { error = error + "
提单号:" + headData.MBLNO + " 收货地代码不能为空或录入不正确(必须是5位代码)"; } + + if (string.IsNullOrEmpty(headData.PLACERECEIPT)) + { error = error + "
提单号:" + headData.MBLNO + " 收货地不能为空"; } + + } + + + if (string.IsNullOrEmpty(headData.PORTLOADID) || headData.PORTLOADID.Length != 5) + { error = error + "
提单号:" + headData.MBLNO + " 装货港代码不能为空或录入不正确(必须是5位代码)"; } + + if (string.IsNullOrEmpty(headData.PORTLOAD)) + { error = error + "
提单号:" + headData.MBLNO + " 装货港不能为空"; } + + + if (string.IsNullOrEmpty(headData.PORTDISCHARGEID) || headData.PORTDISCHARGEID.Length != 5) + { error = error + "
提单号:" + headData.MBLNO + " 卸货港代码不能为空或录入不正确(必须是5位代码)"; } + if (string.IsNullOrEmpty(headData.PORTDISCHARGE)) + { error = error + "
提单号:" + headData.MBLNO + " 卸货港不能为空"; } + + if (string.IsNullOrEmpty(headData.PLACEDELIVERY) || headData.PLACEDELIVERYID.Length != 5) + { error = error + "
提单号:" + headData.MBLNO + " 交货地代码不能为空或录入不正确(必须是5位代码)"; } + if (string.IsNullOrEmpty(headData.PLACEDELIVERY)) + { error = error + "
提单号:" + headData.MBLNO + " 交货地不能为空"; } + + if (string.IsNullOrEmpty(headData.DESTINATION)) + { + if (string.IsNullOrEmpty(headData.DESTINATIONID) || headData.DESTINATIONID.Length != 5) + { error = error + "
提单号:" + headData.MBLNO + " 目的地代码不能为空或录入不正确(必须是5位代码)"; } + } + + if (string.IsNullOrEmpty(headData.KINDPKGS_EDI_CODE)) + { error = error + "
提单号:" + headData.MBLNO + " 包装EDI代码不能为空"; } + if (headData.PKGS == 0) + { error = error + "
提单号:" + headData.MBLNO + " 件数不能为0"; } + if (headData.KGS == 0) + { error = error + "
提单号:" + headData.MBLNO + " 毛重不能为0"; } + if (headData.CBM == 0) + { error = error + "
提单号:" + headData.MBLNO + " 尺码不能为0"; } + + if (string.IsNullOrEmpty(headData.CARGOID)) + { error = error + "
提单号:" + headData.MBLNO + " 货物标识不能为空"; } + + if (headData.CARGOID == "D") + { + if (string.IsNullOrEmpty(headData.DCLASS)) + { error = error + "
提单号:" + headData.MBLNO + " 危险品分类不能为空"; } + + if (string.IsNullOrEmpty(headData.DUNNO)) + { error = error + "
提单号:" + headData.MBLNO + " 危险品编号不能为空"; } + } + if (headData.CARGOID == "R") + { + if (headData.TEMPSET == null || headData.TEMPSET == "") + { error = error + "
提单号:" + headData.MBLNO + " 设置温度不能为空"; } + if (headData.REEFERF == null || headData.REEFERF == "") + { error = error + "
提单号:" + headData.MBLNO + " 通风度不能为空"; } + } + if (headData.ISSUEPLACE == null || headData.ISSUEPLACE == "") + { error = error + "
提单号:" + headData.MBLNO + "签单地点不能为空"; } + + if (headData.CARRIEREDICODE == "APL") + if (headData.ISSUETYPE == null || headData.ISSUETYPE == "") + { error = error + "
提单号:" + headData.MBLNO + "签单方式不能为空"; } + if (headData.SERVICE == "" || headData.SERVICE == null) + { error = error + "
提单号:" + headData.MBLNO + "运输条款不能为空"; } + + if (string.IsNullOrEmpty(headData.MARKS)) + { + error = error + "
提单号:" + headData.MBLNO + " 唛头不能为空"; + } + else + { + if (StringIsChinese(headData.MARKS)) + { + error = error + "
提单号:" + headData.MBLNO + " 唛头含有中文或双字节字符"; + } + else + { + error += formatlengthError("txt", headData.MARKS, 35, headData.MBLNO, "唛头", 0, "", false); + } + } + + if (string.IsNullOrEmpty(headData.DESCRIPTION)) + { + error = error + "
提单号:" + headData.MBLNO + " 货物描述不能为空"; + } + else + { + if (StringIsChinese(headData.DESCRIPTION)) + { + error = error + "
提单号:" + headData.MBLNO + " 货物描述含有中文或双字节字符"; + } + else + { + //error += formatlengthError("txt", bill.DESCRIPTION, 35, bill.MBLNO, "货物描述", 0, ""); + } + } + + + if (string.IsNullOrEmpty(headData.SHIPPER)) + { + error = error + "
提单号:" + headData.MBLNO + " 发货人不能为空"; + } + else + { + if (StringIsChinese(headData.SHIPPER)) + { + error = error + "
提单号:" + headData.MBLNO + " 发货人含有中文或双字节字符"; + } + else + { + if (headData.CARRIEREDICODE == "HLCU") + { + error += formatlengthError("txt", headData.SHIPPER, 35, headData.MBLNO, "发货人", 6, "-", false); + } + else + { + error += formatlengthError("txt", headData.SHIPPER, 35, headData.MBLNO, "发货人", 6, "*", false); + } + } + } + //} + + + + if (string.IsNullOrEmpty(headData.CONSIGNEE)) + { + error = error + "
提单号:" + headData.MBLNO + " 收货人不能为空"; + } + else + { + if (StringIsChinese(headData.CONSIGNEE)) + { + error = error + "
提单号:" + headData.MBLNO + " 收货人含有中文或双字节字符"; + } + else + { + if (headData.CARRIEREDICODE == "HLCU") + { + error += formatlengthError("txt", headData.CONSIGNEE, 35, headData.MBLNO, "收货人", 6, "--", false); + } + else + { + error += formatlengthError("txt", headData.CONSIGNEE, 35, headData.MBLNO, "收货人", 6, "**", false); + } + } + } + + + + + if (string.IsNullOrEmpty(headData.NOTIFYPARTY)) + { + error = error + "
提单号:" + headData.MBLNO + " 通知人不能为空"; + } + else + { + if (StringIsChinese(headData.NOTIFYPARTY)) + { + error = error + "
提单号:" + headData.MBLNO + " 通知人含有中文或双字节字符"; + } + else + { + if (headData.CARRIEREDICODE == "HLCU") + { + error += formatlengthError("txt", headData.NOTIFYPARTY, 35, headData.MBLNO, "通知人", 6, "---", false); + } + else + { + error += formatlengthError("txt", headData.NOTIFYPARTY, 35, headData.MBLNO, "通知人", 6, "***", false); + } + } + } + + if (!string.IsNullOrEmpty(headData.NOTIFYPARTY2)) + { + error += formatlengthError("txt", headData.NOTIFYPARTY2, 35, headData.MBLNO, "第二通知人", 5, "", false); + } + + var ctnlist = headData.CTNLIST; + if (ctnlist.Count == 0) { error = error + "
提单号:" + headData.MBLNO + " 集装箱信息不能为空"; }; + + #region 集装箱判断检查 + if (ctnlist.Count != 0) + { + Decimal dlPKGS = 0; + Decimal dlKGS = 0; + Decimal dlCBM = 0; + foreach (var ctn in ctnlist) + { + if (string.IsNullOrEmpty(ctn.CTNALLCODE)) + { error = error + "
提单号:" + headData.MBLNO + " 集装箱箱型EDI代码不能为空"; } + if ((ctn.CTNALLCODE.IndexOf("RH") > 0 || ctn.CTNALLCODE.IndexOf("RF") > 0) && (headData.CARGOID != "R")) + { + { error = error + "
提单号:" + headData.MBLNO + " 集装箱箱型为冻柜,货类代码请选择冻柜"; } + } + + if (InttrEdi.filetype == "E") + { + + if (string.IsNullOrEmpty(ctn.CNTRNO)) + { error = error + "
提单号:" + headData.MBLNO + " 箱号不能为空"; } + if (string.IsNullOrEmpty(ctn.SEALNO)) + { error = error + "
提单号:" + headData.MBLNO + " 封号不能为空"; } + + if (ctn.KINDPKGS != headData.KINDPKGS) + { error = error + "
提单号:" + headData.MBLNO + " 中的包装类型与集装箱的包装类型不同"; } + dlPKGS += Convert.ToDecimal(ctn.PKGS); + dlKGS += Convert.ToDecimal(ctn.KGS); + dlCBM += Convert.ToDecimal(ctn.CBM); + } + } + if (InttrEdi.filetype == "E") + { + if (dlPKGS != Convert.ToDecimal(headData.PKGS)) + { error = error + "
提单号:" + headData.MBLNO + " 集装箱件数合计数必须等于委托单总件数"; } + if (dlKGS != Convert.ToDecimal(headData.KGS)) + { error = error + "
提单号:" + headData.MBLNO + " 集装箱重量合计数必须等于委托单总重量数"; } + if (dlCBM != Convert.ToDecimal(headData.CBM)) + { error = error + "
提单号:" + headData.MBLNO + " 集装箱尺码合计数必须等于委托单总尺码数"; } + } + } + + if (InttrEdi.filetype == "E") + { + if (headData.CTNGOODSLIST != null && headData.CTNGOODSLIST.Count > 0) + { + foreach (var ctn in ctnlist) + { + var isfind = false; + Int32 ctngoodssumpkgs = 0; + decimal ctngoodssumkgs = 0; + decimal ctngoodssumcbm = 0; + headData.CTNGOODSLIST.ForEach(i => + { + if (i.CNTRNO == ctn.CNTRNO) + { + isfind = true; + ctngoodssumpkgs = ctngoodssumpkgs + i.PKGS; + ctngoodssumkgs = ctngoodssumkgs + i.KGS; + ctngoodssumcbm = ctngoodssumcbm + i.CBM; + } + }); + if (!isfind) + { + error = error + "
提单号:" + headData.MBLNO + "的“" + ctn.CNTRNO + "”未添加分箱明细!"; + } + else + { + if (ctngoodssumpkgs != Convert.ToDecimal(ctn.PKGS)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctn.CNTRNO + " 分箱明细件数合计数不等于集装箱件数"; } + if (ctngoodssumkgs != Convert.ToDecimal(ctn.KGS)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctn.CNTRNO + " 分箱明细毛重合计数不等于集装箱毛重"; } + if (ctngoodssumcbm != Convert.ToDecimal(ctn.CBM)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctn.CNTRNO + " 分箱明细尺码合计数不等于集装箱毛重"; } + + } + + } + + foreach (var ctngood in headData.CTNGOODSLIST) + { + if (string.IsNullOrEmpty(ctngood.KINDPKGS)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱明细包装类型不能为空"; } + if (string.IsNullOrEmpty(ctngood.DESCRIPTION)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱货物描述不能为空"; } + else + { + error += formatlengthError("txt", ctngood.DESCRIPTION, 70, headData.MBLNO, "的“" + ctngood.CNTRNO + "”箱号的分箱货物描述", 0, "", false); + } + //if (string.IsNullOrEmpty(ctngood.HSCODE)) + //{ error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱HS编码不能为空"; } + if (string.IsNullOrEmpty(ctngood.KINDPKGS_EDI_CODE)) + { error = error + "
提单号:" + headData.MBLNO + ",箱号:" + ctngood.CNTRNO + " 中的分箱明细包装类型代码不能为空"; } + + } + + } + + #endregion + + + } + + //2023-03-03 经过测试东胜的EDI根据付费方式,区分 到付-需要填到付地点不能填预付地点,预付只能填预付地点不能填到付地点 + //跟韩工确认增加判断 + if (!string.IsNullOrWhiteSpace(headData.BLFRT) && headData.BLFRT.IndexOf("PREPAID") >= 0) + { + if (string.IsNullOrWhiteSpace(headData.PREPARDAT)) + { + error = error + "
提单号:" + headData.MBLNO + " 付费方式是预付,预付地点不能为空"; + } + + if (!string.IsNullOrWhiteSpace(headData.PAYABLEAT)) + { + error = error + "
提单号:" + headData.MBLNO + " 付费方式是预付,到付地点不能填写"; + } + } + else if (!string.IsNullOrWhiteSpace(headData.BLFRT) && headData.BLFRT.IndexOf("COLLECT") >= 0) + { + if (string.IsNullOrWhiteSpace(headData.PAYABLEAT)) + { + error = error + "
提单号:" + headData.MBLNO + " 付费方式是到付,到付地点不能为空"; + } + + if (!string.IsNullOrWhiteSpace(headData.PREPARDAT)) + { + error = error + "
提单号:" + headData.MBLNO + " 付费方式是到付,预付地点不能填写"; + } + } + + } + return error; + } + #endregion + + #region 生成报文(订舱(filetype=="B"),截单(filetype=="E")) + public static EdiDataResult CreateEdiYT(EDIBaseModel InttrEdi) + { + var result = new EdiDataResult { Succeeded = false }; + var filetype = "IFTMIN"; + if (InttrEdi.filetype != "E") filetype = "IFTMBF"; + + string filename = InttrEdi.filerpath + "\\" + filetype + "_" + InttrEdi.BSLIST[0].MBLNO + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".txt"; + + //如果是部署linux需要修改路径 + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + filename = filename.Replace("\\", "/"); + + //if (System.IO.File.Exists(filename)) + //{ + // System.IO.File.Delete(filename); + //} + FileStream f = new FileStream(filename, FileMode.Create); + StreamWriter r = new StreamWriter(f, Encoding.Default); + var icount = 0; + var bsno = ""; + var isfirst = true; + foreach (var bill in InttrEdi.BSLIST) + { + if (isfirst) + { + if (InttrEdi.filetype == "E") + r.WriteLine("00:IFTMIN:BOOKING:" + InttrEdi.filerole + ":" + InttrEdi.SENDCODE + ":" + InttrEdi.RECEIVECODE + ":" + DateTime.Now.ToString("yyyyMMddHHmm") + "'"); + else + r.WriteLine("00:IFTMBF:BOOKING:" + InttrEdi.filerole + ":" + InttrEdi.SENDCODE + ":" + InttrEdi.RECEIVECODE + ":" + DateTime.Now.ToString("yyyyMMddHHmm") + "'"); + isfirst = false; + icount++; + + } + + if (bill.CARRIEREDICODE == "ONEY") + { + var sendno = bill.EDIATTNEMAIL; + + if (filetype == "E") sendno = bill.AMSCODE; + var MBLNO = bill.MBLNO; + if (MBLNO.Substring(0, 4) == "ONEY") + { + MBLNO = MBLNO.Substring(4, MBLNO.Length - 4); + } + //2023-02-28 ONE的逻辑是去掉了提单号的前4位,跟韩工已确认,与东胜7相同 + //2023-03-03 韩工给提供了新的02行的处理SENDNAME改为读取FTP配置的 + /* + r.WriteLine("02" + + ":" + MBLNO//2 REFERENCE NO. 运编号 X(35) 一般为流水号 M + + ":" + MBLNO//3 B\L NO. 提单号 X(20) 船公司的提单号 C + + ":" + bill.SERVICE//4 DELIVERY TERM 交货条款 X(9) CY-CY(pier-pier/port):30CY-CFS(pier/port-door):29CFS-CY(door-pier/port):28CFS-CFS(door-door):27 M + + ":" + InttrEdi.SENDNAME//5 BOOKING PARTY 订舱人说明 X(70) 货代方企业名称或代码 C + + ":ONEY" //6 ISSUE PARTY CODE 签单人代码 X(13) 即接受订舱的人的代码 M + + ":"//7 ISSUE PARTY 签单人说明 X(35)   C + + ":"//8 APPLICANT 询价单位 X(13) 向船公司询价的单位代码 C + + ":"//9 FOB BK PARTY 国外订舱单位 X(13) 国外FOB货订舱单位的代码 C + + ":"//10 B/L TRANSHIP ID 转船标识 X(1) Y/N C + + ":"//11 BATCH ID 分批 X(1) Y/N C + + ":"//12 SHIPMENT DATE 装期 9(8) CCYYMMDD C + + ":"//13 EXPIRY DATE 效期 9(8) CCYYMMDD C + + ":" + bill.CONTRACTNO//14 QUOTATION NO. 运费协议号 X(30) MAERSK为必选 C + + ":"//15 CHARGE TYPE 费率本代码 X(1)   C + + ":" + bill.CONTRACTNO//16 S/C NO. 合约号 X(30)   C + + ":"//17 BOOKING NO. 船公司订舱编号 X(20) 船公司系统内部订舱编号 C + + ":"//18 SLOT CHARTER ID 舱位互用标识 X(1)   C + + ":" + sendno//19 AMS CODE AMS代码 X(15)   C + //注:QUOTATION NO.项填本票订舱货的运价是通过向中集询价后定下的特殊运价编号。 + + "'"); + */ + //2023-03-03 修改运输条款SERVICE改为EDI的映射值,经过韩工确认 + r.WriteLine("02" + + ":" + MBLNO//2 REFERENCE NO. 运编号 X(35) 一般为流水号 M + + ":" + MBLNO//3 B\L NO. 提单号 X(20) 船公司的提单号 C + + ":" + bill.SERVICEEDICODE//4 DELIVERY TERM 交货条款 X(9) CY-CY(pier-pier/port):30CY-CFS(pier/port-door):29CFS-CY(door-pier/port):28CFS-CFS(door-door):27 M + + ":" + formatEdiStr("txt", InttrEdi.SENDCOMPANYCODE) //5 BOOKING PARTY 订舱人说明 X(70) 货代方企业名称或代码 C + + ":ONEY" //6 ISSUE PARTY CODE 签单人代码 X(13) 即接受订舱的人的代码 M + + ":"//7 ISSUE PARTY 签单人说明 X(35)   C + + ":"//8 APPLICANT 询价单位 X(13) 向船公司询价的单位代码 C + + ":"//9 FOB BK PARTY 国外订舱单位 X(13) 国外FOB货订舱单位的代码 C + + ":"//10 B/L TRANSHIP ID 转船标识 X(1) Y/N C + + ":"//11 BATCH ID 分批 X(1) Y/N C + + ":"//12 SHIPMENT DATE 装期 9(8) CCYYMMDD C + + ":"//13 EXPIRY DATE 效期 9(8) CCYYMMDD C + + ":" + bill.CONTRACTNO//14 QUOTATION NO. 运费协议号 X(30) MAERSK为必选 C + + ":"//15 CHARGE TYPE 费率本代码 X(1)   C + + ":" + bill.CONTRACTNO//16 S/C NO. 合约号 X(30)   C + + ":"//17 BOOKING NO. 船公司订舱编号 X(20) 船公司系统内部订舱编号 C + + ":"//18 SLOT CHARTER ID 舱位互用标识 X(1)   C + + ":" + sendno//19 AMS CODE AMS代码 X(15)   C + //注:QUOTATION NO.项填本票订舱货的运价是通过向中集询价后定下的特殊运价编号。 + + "'"); + + } + else + if (InttrEdi.filetype == "E") + { + //2023-03-03 修改运输条款SERVICE改为EDI的映射值,经过韩工确认 + r.WriteLine("02" + + ":" + bill.ORDERNO//2 REFERENCE NO. 运编号 X(35) 一般为流水号 M + + ":" + bill.MBLNO//3 B\L NO. 提单号 X(20) 船公司的提单号 C + + ":" + bill.SERVICEEDICODE//4 DELIVERY TERM 交货条款 X(9) CY-CY(pier-pier/port):30CY-CFS(pier/port-door):29CFS-CY(door-pier/port):28CFS-CFS(door-door):27 M + + ":" + formatEdiStr("txt", !string.IsNullOrWhiteSpace(InttrEdi.ForWarderName) ? InttrEdi.ForWarderName.Replace("\n", " ").Replace("\r", " ") : "")//5 BOOKING PARTY 订舱人说明 X(70) 货代方企业名称或代码 C + + ":" + InttrEdi.RECEIVECODE//6 ISSUE PARTY CODE 签单人代码 X(13) 即接受订舱的人的代码 M + + ":"//7 ISSUE PARTY 签单人说明 X(35)   C + + ":"//8 APPLICANT 询价单位 X(13) 向船公司询价的单位代码 C + + ":"//9 FOB BK PARTY 国外订舱单位 X(13) 国外FOB货订舱单位的代码 C + + ":"//10 B/L TRANSHIP ID 转船标识 X(1) Y/N C + + ":"//11 BATCH ID 分批 X(1) Y/N C + + ":"//12 SHIPMENT DATE 装期 9(8) CCYYMMDD C + + ":"//13 EXPIRY DATE 效期 9(8) CCYYMMDD C + + ":" + bill.CONTRACTNO//14 QUOTATION NO. 运费协议号 X(30) MAERSK为必选 C + + ":"//15 CHARGE TYPE 费率本代码 X(1)   C + + ":" + bill.SERVICECONTRACTNO//16 S/C NO. 合约号 X(30)   C + + ":" + bill.ORDERNO//17 BOOKING NO. 船公司订舱编号 X(20) 船公司系统内部订舱编号 C + + ":::"//18 SLOT CHARTER ID 舱位互用标识 X(1)   C + + ":" + bill.EDIATTNEMAIL//21 AMS CODE AMS代码 X(15)   C + + ":" + bill.EDIATTN//22 AMS CODE AMS代码 X(15)   C + + ":" + bill.EDIATTNTEL//23 AMS CODE AMS代码 X(15)   C + //注:QUOTATION NO.项填本票订舱货的运价是通过向中集询价后定下的特殊运价编号。 + + "'"); + + } + else + { + //2023-03-03 修改运输条款SERVICE改为EDI的映射值,经过韩工确认 + r.WriteLine("02" + + ":" + bill.ORDERNO//2 REFERENCE NO. 运编号 X(35) 一般为流水号 M + + ":" + bill.MBLNO//3 B\L NO. 提单号 X(20) 船公司的提单号 C + + ":" + bill.SERVICEEDICODE//4 DELIVERY TERM 交货条款 X(9) CY-CY(pier-pier/port):30CY-CFS(pier/port-door):29CFS-CY(door-pier/port):28CFS-CFS(door-door):27 M + + ":" + formatEdiStr("txt", !string.IsNullOrWhiteSpace(InttrEdi.ForWarderName) ? InttrEdi.ForWarderName.Replace("\n", " ").Replace("\r", " ") : "")//5 BOOKING PARTY 订舱人说明 X(70) 货代方企业名称或代码 C + + ":" + InttrEdi.RECEIVECODE//6 ISSUE PARTY CODE 签单人代码 X(13) 即接受订舱的人的代码 M + + ":"//7 ISSUE PARTY 签单人说明 X(35)   C + + ":"//8 APPLICANT 询价单位 X(13) 向船公司询价的单位代码 C + + ":"//9 FOB BK PARTY 国外订舱单位 X(13) 国外FOB货订舱单位的代码 C + + ":"//10 B/L TRANSHIP ID 转船标识 X(1) Y/N C + + ":"//11 BATCH ID 分批 X(1) Y/N C + + ":"//12 SHIPMENT DATE 装期 9(8) CCYYMMDD C + + ":"//13 EXPIRY DATE 效期 9(8) CCYYMMDD C + + ":" + bill.CONTRACTNO//14 QUOTATION NO. 运费协议号 X(30) MAERSK为必选 C + + ":"//15 CHARGE TYPE 费率本代码 X(1)   C + + ":" + bill.SERVICECONTRACTNO//16 S/C NO. 合约号 X(30)   C + + ":" + bill.ORDERNO//17 BOOKING NO. 船公司订舱编号 X(20) 船公司系统内部订舱编号 C + + ":"//18 SLOT CHARTER ID 舱位互用标识 X(1)   C + + ":" + bill.EDIATTNEMAIL//21 AMS CODE AMS代码 X(15)   C + + ":" + bill.EDIATTN//22 AMS CODE AMS代码 X(15)   C + + ":" + bill.EDIATTNTEL//23 AMS CODE AMS代码 X(15)   C + //注:QUOTATION NO.项填本票订舱货的运价是通过向中集询价后定下的特殊运价编号。 + + "'"); + } + icount++; + + var ISSUETYPE = ""; + + //2023-03-02 测试这里有问题,签单方式用的中文,要改成英文正本-ORIGINAL 电放-TELEX + /* + if (bill.ISSUETYPE == "正本") + { + ISSUETYPE = "ORI"; + } + else if (bill.ISSUETYPE == "电放") + { + ISSUETYPE = "TER"; + } + else ISSUETYPE = "EXP"; + */ + if (bill.ISSUETYPE == "ORIGINAL") + { + ISSUETYPE = "ORI"; + } + else if (bill.ISSUETYPE == "TELEX") + { + ISSUETYPE = "TER"; + } + 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++; + + + r.WriteLine("11:" + bill.VESSELID + ":" + bill.VESSEL + ":" + bill.VOYNO + ":::::" + GetDateStr(bill.ETD, "yyyyMMdd") + ":::::'"); + icount++; + + var DESTINATIONID = bill.DESTINATIONID; + var DESTINATION = bill.DESTINATION; + if (bill.CARRIEREDICODE == "ONEY" || bill.CARRIEREDICODE == "ZIM") + { + DESTINATIONID = ""; + DESTINATION = ""; + } + + r.WriteLine("12" + + ":" + bill.PLACERECEIPTID//2 PLACE CODE OF RECEIPT 收货地代码 X(5) OOCL、HLC的订舱要求必选 O + + ":" + bill.PLACERECEIPT//3 PLACE OF RECEIPT 收货地 X(35)   C + + ":" + bill.PORTLOADID//4 LOAD PORT CODE 装货港代码 X(5) OOCL的订舱要求必选 O + + ":" + bill.PORTLOAD//5 LOAD PORT 装货港 X(35)   C + + ":" + bill.PORTDISCHARGEID//6 DISCHARGE PORT CODE 卸货港代码 X(5) OOCL的订舱要求必选 M + + ":" + bill.PORTDISCHARGE//7 DISCHARGE PORT 卸货港 X(35)   C + + ":" + bill.TRANSPORTID //8 TRANSFER PORT CODE 中转港代码 X(5)   C + + ":" + bill.TRANSPORT//9 TRANSFER PORT 中转港 X(35)   C + + ":" + bill.PLACEDELIVERYID//10 PLACE OF DELIVERY CODE 交货地代码 X(5) OOCL的订舱要求必选 O + + ":" + bill.PLACEDELIVERY//11 PLACE OF DELIVERY 交货地 X(35)   C + + ":" + DESTINATIONID//12 FINAL DESTINATION CODE 目的地代码 X(5)   C + + ":" + DESTINATION//13 FINAL DESTINATION CODE 目的地 X(35)   C + + "'"); + + icount = icount + 1; + + r.WriteLine("14:" + bill.BLFRTEDICODE + ":" + bill.BLFRT + "'"); + if (InttrEdi.filetype == "E") + r.WriteLine("15:::" + bill.BLFRTEDICODE + ":" + bill.PAYABLEATID + ":::::'"); + else + r.WriteLine("15:::" + bill.BLFRTEDICODE + "::::::'"); + icount = icount + 2; + + + var Shipping = ""; + if (InttrEdi.filetype == "E") + Shipping = formatEdiStr("txt", bill.SIREMARK); + else + Shipping = formatEdiStr("txt", bill.EDIREMARK); + + List ShippingList = formatlengthStr(Shipping, 70); + + if (!string.IsNullOrWhiteSpace(Shipping)) + { + r.WriteLine("17:" + formatListStr(ShippingList, 5) + "'"); + icount++; + } + + if (InttrEdi.filetype != "E" && !string.IsNullOrEmpty(bill.NVONO)) + { + r.WriteLine("18:NVO:" + bill.NVONO + "'"); + + } + + + Shipping = formatEdiStr("txt", bill.SHIPPER); + ShippingList = formatlengthStr(Shipping, 35); + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + r.WriteLine("20::" + formatListStr(ShippingList, 6) + "'"); + icount = icount + 1; + + } + + + + Shipping = formatEdiStr("txt", bill.CONSIGNEE); + ShippingList = formatlengthStr(Shipping, 35); + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + r.WriteLine("21::" + formatListStr(ShippingList, 6) + "'"); + icount = icount + 1; + + } + + + Shipping = formatEdiStr("txt", bill.NOTIFYPARTY); + ShippingList = formatlengthStr(Shipping, 35); + + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + r.WriteLine("22::" + formatListStr(ShippingList, 6) + "'"); + icount = icount + 1; + + } + + + Shipping = formatEdiStr("txt", !string.IsNullOrWhiteSpace(bill.NOTIFYPARTY2) ? bill.NOTIFYPARTY2 : ""); + ShippingList = formatlengthStr(Shipping, 35); + + if (!string.IsNullOrWhiteSpace(Shipping)) + { + + r.WriteLine("23::" + formatListStr(ShippingList, 6) + "'"); + icount = icount + 1; + + + + } + + Shipping = bill.AMSCONSIGNEE; + ShippingList = formatlengthStr(Shipping, 35); + + if (!string.IsNullOrWhiteSpace(Shipping)) + { + r.WriteLine("24::" + formatListStr(ShippingList, 6, true) + "'"); + icount = icount + 1; + + } + + + Shipping = bill.AMSNOTIFYPARTY; + ShippingList = formatlengthStr(Shipping, 35); + + if (!string.IsNullOrWhiteSpace(Shipping)) + { + r.WriteLine("25::" + formatListStr(ShippingList, 6, true) + "'"); + icount = icount + 1; + + } + + + + var cargoid = bill.CARGOID; + if (cargoid == "" || cargoid == " ") cargoid = "S"; + + var kingweight = bill.KINGTAREWEIGHT; + if (kingweight == 0) + kingweight = 100; + + r.WriteLine("41:1:" + bill.HSCODE + ":" + cargoid + ":" + bill.PKGS.ToString() + ":" + bill.KINDPKGS_EDI_CODE + ":" + bill.KINDPKGS + ":" + kingweight.ToString("0.###") + ":" + + bill.CBM.ToString("0.###") + "::::::" + bill.KGS.ToString("0.###") + ":::'"); + + icount = icount + 1; + if (cargoid == "R") + r.WriteLine("43::::::::::" + bill.REEFERF + ":C:" + bill.TEMPSET + ":" + bill.TEMPMIN + ":" + bill.TEMPMAX + ":::::'"); + else if (cargoid == "D") + r.WriteLine("43:" + bill.DCLASS + ":" + bill.DPAGE + ":" + bill.DUNNO + ":" + bill.DLABEL + "::::::::::::'"); + + icount = icount + 1; + + + Shipping = formatEdiStr("txt", bill.MARKS); + ShippingList = formatlengthStr(Shipping, 35); + + for (var i = 0; i < Math.Ceiling(Convert.ToDecimal(Convert.ToDecimal(ShippingList.Count) / Convert.ToDecimal(10))); i++) + { + var tempstr = "44:"; + for (var z = 0; z < 10; z++) + { + if ((i * 10 + z) < ShippingList.Count) + tempstr = tempstr + ShippingList[i * 10 + z]; + if (z < 9) tempstr = tempstr + ":"; + } + if (tempstr != "44:") + { + r.WriteLine(tempstr + "'"); + icount++; + } + } + + Shipping = formatEdiStr("txt", bill.DESCRIPTION); + ShippingList = formatlengthStr(Shipping, 70); + + var m = 1; + var strtemp = ""; + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + + for (var i = 0; i < ShippingList.Count; i++) + { + if (ShippingList[i] != "") + { + if (m <= 5) + { + if (m == 1) strtemp = "47:" + ShippingList[i] + ":"; + else + { + if (m == 5) + strtemp = strtemp + ShippingList[i]; + else + strtemp = strtemp + ShippingList[i] + ":"; + } + } + else + { + m = 1; + r.WriteLine(strtemp + "'"); + strtemp = "47:" + ShippingList[i] + ":"; + icount = icount + 1; + } + m = m + 1; + } + } + } + if (!string.IsNullOrWhiteSpace(strtemp)) + { + r.WriteLine(strtemp + "'"); + icount = icount + 1; + } + + var ISSOC = "N"; + if (bill.ISCONTAINERSOC) ISSOC = "Y"; + + var ctnsumlist = new List(); + + foreach (var ctn in bill.CTNLIST) + { + var newctnsum = ctnsumlist.Find(x => x.CTNALLCODE == ctn.CTNALLCODE); + if (newctnsum == null) + { + var ctnsum = new SeaExportCtnEDIBaseModel(); + ctnsum.CTNALLCODE = ctn.CTNALLCODE; + ctnsum.CTNNUM = ctn.CTNNUM; + if (bill.ISCONTAINERSOC && !string.IsNullOrEmpty(ctn.CNTRNO)) + { + if (!string.IsNullOrEmpty(ctnsum.CNTRNO)) + { + ctnsum.CNTRNO = ctn.CNTRNO; + } + else + { + ctnsum.CNTRNO = ctnsum.CNTRNO + "," + ctn.CNTRNO; + + } + } + ctnsumlist.Add(ctnsum); + + } + else + { + newctnsum.CTNNUM = newctnsum.CTNNUM + ctn.CTNNUM; + if (bill.ISCONTAINERSOC && !string.IsNullOrEmpty(ctn.CNTRNO)) + { + if (!string.IsNullOrEmpty(newctnsum.CNTRNO)) + { + newctnsum.CNTRNO = ctn.CNTRNO; + } + else + { + newctnsum.CNTRNO = newctnsum.CNTRNO + "," + ctn.CNTRNO; + + } + } + + } + } + foreach (var ctnsum in ctnsumlist) + { + if (InttrEdi.filetype == "E") + { + r.WriteLine("48:" + ctnsum.CTNALLCODE + ":" + ctnsum.CTNNUM + ":F:::::" + ISSOC + "'"); + icount = icount + 1; + } + else + { + var cntrnostr = ""; + var isrstr = "N"; + if (cargoid == "R") isrstr = "Y"; + r.WriteLine("48:" + ctnsum.CTNALLCODE + ":" + ctnsum.CTNNUM + ":F:::::" + ISSOC + ":" + cntrnostr + ":::" + isrstr + "'"); + icount = icount + 1; + + } + + } + + foreach (var ctn in bill.CTNLIST) + { + + if (InttrEdi.filetype == "E") + { + r.WriteLine("51:" + ctn.CNTRNO + ":" + ctn.CTNALLCODE + ":" + + ctn.SEALNO + ":" + ctn.PKGS.ToString() + ":" + ctn.KGS.ToString("0.###") + "::" + ctn.CBM.ToString("0.###") + ":" + bill.EDIATTNEMAIL + "'"); + icount = icount + 1; + + if (bill.CTNGOODSLIST != null && bill.CTNGOODSLIST.Count != 0) + { + foreach (var ctnhs in bill.CTNGOODSLIST) + { + r.WriteLine("53:" + ctnhs.HSCODE + ":" + ctnhs.PKGS.ToString() + ":" + + ctnhs.KGS.ToString("0.###") + ":" + ctnhs.CBM.ToString("0.###") + ":" + ctnhs.KINDPKGS_EDI_CODE + ":" + ctnhs.KINDPKGS + "'"); + icount = icount + 1; + Shipping = formatEdiStr("txt", ctnhs.DESCRIPTION); + ShippingList = formatlengthStr(Shipping, 70); + m = 1; + strtemp = ""; + if (ShippingList.Count != 0 && Shipping.Length > 0) + { + + for (var i = 0; i < ShippingList.Count; i++) + { + if (!string.IsNullOrWhiteSpace(ShippingList[i])) + { + if (m <= 5) + { + if (m == 1) strtemp = "54:" + ShippingList[i] + ":"; + else + { + if (m == 5) + strtemp = strtemp + ShippingList[i]; + else + strtemp = strtemp + ShippingList[i] + ":"; + } + } + else + { + m = 1; + r.WriteLine(strtemp + "'"); + strtemp = "54:" + ShippingList[i] + ":"; + icount = icount + 1; + } + m = m + 1; + } + } + } + if (!string.IsNullOrWhiteSpace(strtemp)) + { + r.WriteLine(strtemp + "'"); + icount = icount + 1; + } + + + } + } + } + else + { + if (!string.IsNullOrEmpty(ctn.CNTRNO)) + { + r.WriteLine("51:" + ctn.CNTRNO + ":" + ctn.CTNALLCODE + ":" + + ctn.SEALNO + ":" + ctn.PKGS.ToString() + ":" + ctn.KGS.ToString("0.###") + ":'"); + icount = icount + 1; + } + } + //} + } + + } + + icount = icount + 1; + r.WriteLine("99:" + icount.ToString() + "'"); + r.Close(); + f.Close(); + + result.Succeeded = true; + result.ExtraData1 = filename; + return result; + } + #endregion + + + + } +} diff --git a/ds-wms-service/DS.WMS.Core/Op/Entity/SeaExport.cs b/ds-wms-service/DS.WMS.Core/Op/Entity/SeaExport.cs index c7e5cc08..f9bf7058 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Entity/SeaExport.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Entity/SeaExport.cs @@ -103,7 +103,7 @@ public class SeaExport : BaseOrgModel /// /// 委托单位 t_info_client CUSTNAME /// - [SqlSugar.SugarColumn(ColumnDescription = "委托单位", IsNullable = true, Length = 20)] + [SqlSugar.SugarColumn(ColumnDescription = "委托单位", IsNullable = true, Length = 50)] public string CustomerName { get; set; } /// @@ -120,7 +120,7 @@ public class SeaExport : BaseOrgModel /// /// 发货人 t_info_client CUSTNAME /// - [SqlSugar.SugarColumn(ColumnDescription = "发货人", IsNullable = true)] + [SqlSugar.SugarColumn(ColumnDescription = "发货人", IsNullable = true, Length = 100)] public string Shipper { get; set; } /// /// 收货人 t_info_client CUSTNAME @@ -131,7 +131,7 @@ public class SeaExport : BaseOrgModel /// /// 收货人 t_info_client CUSTNAME /// - [SqlSugar.SugarColumn(ColumnDescription = "收货人", IsNullable = true)] + [SqlSugar.SugarColumn(ColumnDescription = "收货人", IsNullable = true, Length = 100)] public string Consignee { get; set; } /// /// 通知人 t_info_client CUSTNAME @@ -141,7 +141,7 @@ public class SeaExport : BaseOrgModel /// /// 通知人 t_info_client CUSTNAME /// - [SqlSugar.SugarColumn(ColumnDescription = "通知人", IsNullable = true)] + [SqlSugar.SugarColumn(ColumnDescription = "通知人", IsNullable = true, Length = 100)] public string NotifyParty { get; set; } /// /// 国外代理人Id t_info_client CUSTNAME @@ -151,30 +151,30 @@ public class SeaExport : BaseOrgModel /// /// 国外代理人 t_info_client CUSTNAME /// - [SqlSugar.SugarColumn(ColumnDescription = "国外代理人", IsNullable = true, Length = 600)] + [SqlSugar.SugarColumn(ColumnDescription = "国外代理人", IsNullable = true, Length = 100)] public string Agent { get; set; } /// /// 发货人内容 /// - [SqlSugar.SugarColumn(ColumnDescription = "发货人内容", IsNullable = true, Length = 600)] + [SqlSugar.SugarColumn(ColumnDescription = "发货人内容", IsNullable = true, ColumnDataType = StaticConfig.CodeFirst_BigString)] public string ShipperContent { get; set; } /// /// 收货人内容 /// - [SqlSugar.SugarColumn(ColumnDescription = "收货人内容", IsNullable = true, Length = 600)] + [SqlSugar.SugarColumn(ColumnDescription = "收货人内容", IsNullable = true, ColumnDataType = StaticConfig.CodeFirst_BigString)] public string ConsigneeContent { get; set; } /// /// 通知人内容 /// - [SqlSugar.SugarColumn(ColumnDescription = "通知人内容", IsNullable = true, Length = 600)] + [SqlSugar.SugarColumn(ColumnDescription = "通知人内容", IsNullable = true, ColumnDataType = StaticConfig.CodeFirst_BigString)] public string NotifyPartyContent { get; set; } /// /// 国外代理内容 /// - [SqlSugar.SugarColumn(ColumnDescription = "国外代理内容", IsNullable = true, Length = 600)] + [SqlSugar.SugarColumn(ColumnDescription = "国外代理内容", IsNullable = true, ColumnDataType = StaticConfig.CodeFirst_BigString)] public string AgentContent { get; set; } /// @@ -201,11 +201,30 @@ public class SeaExport : BaseOrgModel public long VesselId { get; set; } /// - /// 航次 + /// 海关航次 /// - [SqlSugar.SugarColumn(ColumnDescription = "航次", IsNullable = true, Length = 20)] + [SqlSugar.SugarColumn(ColumnDescription = "海关航次", IsNullable = true, Length = 20)] public string Voyno { get; set; } - + /// + /// 内部航次 + /// + [SqlSugar.SugarColumn(ColumnDescription = "内部航次", IsNullable = true, Length = 20)] + public string InnerVoyno { get; set; } + /// + /// 第二通知人Id t_info_client CUSTNAME + /// + [SqlSugar.SugarColumn(ColumnDescription = "第二通知人Id", IsNullable = true)] + public long? SecondNotifyPartyId { get; set; } + /// + /// 第二通知人 t_info_client CUSTNAME + /// + [SqlSugar.SugarColumn(ColumnDescription = "第二通知人", IsNullable = true,Length = 100)] + public string SecondNotifyParty { get; set; } + /// + /// 第二通知人内容 + /// + [SqlSugar.SugarColumn(ColumnDescription = "第二通知人内容", IsNullable = true, ColumnDataType = StaticConfig.CodeFirst_BigString)] + public string SecondNotifyPartyContent { get; set; } /// /// 开船日期 /// @@ -388,7 +407,11 @@ public class SeaExport : BaseOrgModel /// [SugarColumn(ColumnDescription = "货物描述", IsNullable = true, ColumnDataType=StaticConfig.CodeFirst_BigString)] public string Description { get; set; } - + /// + /// 品名Id + /// + [SugarColumn(ColumnDescription = "品名", IsNullable = true, DefaultValue ="0")] + public long? GoodsId { get; set; } /// /// 品名 t_code_goods /// @@ -398,13 +421,13 @@ public class SeaExport : BaseOrgModel /// /// 货物毛重 /// - [SugarColumn(ColumnDescription = "货物毛重", IsNullable = true, Length = 600)] + [SugarColumn(ColumnDescription = "货物毛重", IsNullable = true, ColumnDataType = StaticConfig.CodeFirst_BigString)] public string GrossWeight { get; set; } /// /// 货物尺码 /// - [SugarColumn(ColumnDescription = "货物尺码", IsNullable = true, Length = 600)] + [SugarColumn(ColumnDescription = "货物尺码", IsNullable = true, ColumnDataType = StaticConfig.CodeFirst_BigString)] public string Measurement { get; set; } /// @@ -440,7 +463,7 @@ public class SeaExport : BaseOrgModel /// /// 集装箱大写 /// - [SugarColumn(ColumnDescription = "集装箱大写", IsNullable = true, Length = 1000)] + [SugarColumn(ColumnDescription = "集装箱大写", IsNullable = true, ColumnDataType = StaticConfig.CodeFirst_BigString)] public string CntrNo { get; set; } /// @@ -518,7 +541,7 @@ public class SeaExport : BaseOrgModel /// /// 集装箱 /// - [SugarColumn(ColumnDescription = "集装箱", IsNullable = true, Length = 4000)] + [SugarColumn(ColumnDescription = "集装箱", IsNullable = true, ColumnDataType = StaticConfig.CodeFirst_BigString)] public string CntrTotal { get; set; } /// @@ -699,11 +722,11 @@ public class SeaExport : BaseOrgModel [SugarColumn(ColumnDescription = "订舱类型", IsNullable = true, Length = 50)] public string BookingType { get; set; } - ///// - ///// 订舱编号 - ///// - //[SugarColumn(ColumnDescription = "订舱编号", IsNullable = true, Length = 20)] - //public string BookingNo { get; set; } + /// + /// 订舱编号 + /// + [SugarColumn(ColumnDescription = "订舱编号", IsNullable = true, Length = 20)] + public string BookingNo { get; set; } /// /// Desc:保险人 @@ -1123,19 +1146,19 @@ public class SeaExport : BaseOrgModel /// /// Master收货人内容 /// - [SqlSugar.SugarColumn(ColumnDescription = "Master收货人内容", IsNullable = true, Length = 600)] + [SqlSugar.SugarColumn(ColumnDescription = "Master收货人内容", IsNullable = true, ColumnDataType = StaticConfig.CodeFirst_BigString)] public string MasterConsigneeContent { get; set; } /// /// Master通知人内容 /// - [SqlSugar.SugarColumn(ColumnDescription = "Master通知人内容", IsNullable = true, Length = 600)] + [SqlSugar.SugarColumn(ColumnDescription = "Master通知人内容", IsNullable = true, ColumnDataType = StaticConfig.CodeFirst_BigString)] public string MasterNotifyPartyContent { get; set; } /// /// Master发货人内容 /// - [SqlSugar.SugarColumn(ColumnDescription = "Master发货人内容", IsNullable = true, Length = 600)] + [SqlSugar.SugarColumn(ColumnDescription = "Master发货人内容", IsNullable = true, ColumnDataType = StaticConfig.CodeFirst_BigString)] public string MasterShipperContent { get; set; } /// @@ -1172,19 +1195,7 @@ public class SeaExport : BaseOrgModel /// 是否打印小票 /// [SugarColumn(ColumnDescription = "是否打印小票", DefaultValue = "0")] - public bool IsPrintReceipt { get; set; } - // /// - // /// 是否取消 - // /// - // [SugarColumn(ColumnDescription = "是否取消", DefaultValue = "0")] - // public bool IsCancel { get; set; } - // - // /// - // /// 是否TUI - // /// - // [SugarColumn(ColumnDescription = "是否TUI", DefaultValue = "0")] - // public bool IsTUI { get; set; } - + public bool IsPrintReceipt { get; set; } /// /// 船名 t_code_vessel /// @@ -1240,7 +1251,7 @@ public class SeaExport : BaseOrgModel /// /// 转运备注 /// - [SqlSugar.SugarColumn(ColumnDescription = "转运备注", IsNullable = true, Length = 600)] + [SqlSugar.SugarColumn(ColumnDescription = "转运备注", IsNullable = true, ColumnDataType = StaticConfig.CodeFirst_BigString)] public string TransRemark { get; set; } /// diff --git a/ds-wms-service/DS.WMS.Core/Op/Entity/SeaExportEdi.cs b/ds-wms-service/DS.WMS.Core/Op/Entity/SeaExportEdi.cs new file mode 100644 index 00000000..1ba3a94d --- /dev/null +++ b/ds-wms-service/DS.WMS.Core/Op/Entity/SeaExportEdi.cs @@ -0,0 +1,223 @@ +using DS.Module.Core.Data; +using SqlSugar; +using System.ComponentModel; + +namespace DS.WMS.Core.Op.Entity; + +/// +/// 海运出口Edi信息 +/// +[SqlSugar.SugarTable("op_sea_export_edi", "海运出口Edi信息")] +public class SeaExportEdi: BaseModel +{ + /// + /// 业务Id + /// + [SqlSugar.SugarColumn(ColumnDescription = "业务Id", IsNullable = false, Length = 100)] + public long BusinessId { get; set; } + + /// + /// 委托方 + /// + [Description("委托方")] + [SqlSugar.SugarColumn(ColumnDescription = "委托方", IsNullable = false, Length = 100)] + public string CustomerName { get; set; } + + /// + /// 发送方EDI代码 + /// + [SqlSugar.SugarColumn(ColumnDescription = "发送方EDI代码", IsNullable = false, Length = 50)] + public string SendCode { get; set; } + + /// + /// 接收方EDI代码 + /// + [SqlSugar.SugarColumn(ColumnDescription = "接收方EDI代码", IsNullable = false, Length = 50)] + public string ReceiveCode { get; set; } + + /// + /// 通知方EDI代码 + /// + [SqlSugar.SugarColumn(ColumnDescription = "通知方EDI代码", IsNullable = false, Length = 50)] + public string NotifyCdoe { get; set; } + + /// + /// 销售EDI代码 + /// + [SqlSugar.SugarColumn(ColumnDescription = "销售EDI代码", IsNullable = false, Length = 50)] + public string SalerCode { get; set; } + + /// + /// Master Bol Indicator + /// + [SqlSugar.SugarColumn(ColumnDescription = "Master Bol Indicator", IsNullable = false, Length = 50)] + public string MasterBolIndicator { get; set; } + + /// + /// EMANIFEST HBL + /// + [SqlSugar.SugarColumn(ColumnDescription = "EMANIFEST HBL", IsNullable = false, Length = 50)] + public string EmanifestHbl { get; set; } + + /// + /// 收货人EDI代码 + /// + [SqlSugar.SugarColumn(ColumnDescription = "收货人EDI代码", IsNullable = false, Length = 50)] + public string ConsigneeEdiCode { get; set; } + + /// + /// 发货人EDI代码 + /// + [SqlSugar.SugarColumn(ColumnDescription = "发货人EDI代码", IsNullable = false, Length = 50)] + public string ShipperEdiCode { get; set; } + + /// + /// EDI联系人名称 + /// + [SqlSugar.SugarColumn(ColumnDescription = "EDI联系人名称", IsNullable = false, Length = 100)] + public string EDIAttn { get; set; } + + /// + /// EDI联系人电话 + /// + [SqlSugar.SugarColumn(ColumnDescription = "EDI联系人电话", IsNullable = false, Length = 50)] + public string EDIAttnTel { get; set; } + + /// + /// EDI联系人邮箱 + /// + [SqlSugar.SugarColumn(ColumnDescription = "EDI联系人邮箱", IsNullable = false, Length = 50)] + public string EDIAttnMail { get; set; } + + /// + /// AMS收货人 + /// + [SqlSugar.SugarColumn(ColumnDescription = "AMS收货人", IsNullable = false, ColumnDataType = StaticConfig.CodeFirst_BigString)] + public string AMSConsignee { get; set; } + + /// + /// AMS通知人 + /// + [SqlSugar.SugarColumn(ColumnDescription = "AMS通知人", IsNullable = false, ColumnDataType = StaticConfig.CodeFirst_BigString)] + public string AMSNotifyParty { get; set; } + + /// + /// 操作英文名称 + /// + [SqlSugar.SugarColumn(ColumnDescription = "操作英文名称", IsNullable = false, Length = 50)] + public string OpEName { get; set; } + + /// + /// 操作电话 + /// + [SqlSugar.SugarColumn(ColumnDescription = "操作电话", IsNullable = false, Length = 50)] + public string OpTel { get; set; } + + /// + /// 操作邮箱 + /// + [SqlSugar.SugarColumn(ColumnDescription = "操作邮箱", IsNullable = false, Length = 50)] + public string OpEmail { get; set; } + + /// + /// ACI HBL + /// + [SqlSugar.SugarColumn(ColumnDescription = "ACI HBL", IsNullable = false, Length = 120)] + public string ACIHBL { get; set; } + /// + /// S0C C0C + /// + [SqlSugar.SugarColumn(ColumnDescription = "S0C C0C", IsNullable = false, Length = 120)] + public string S0CC0C { get; set; } + + /// + /// 商品名称 + /// + [SqlSugar.SugarColumn(ColumnDescription = "商品名称", IsNullable = false, Length = 100)] + public string GoodsName { get; set; } + + /// + /// Master Bol Indicator名称 + /// + [SqlSugar.SugarColumn(ColumnDescription = "Master Bol Indicator名称", IsNullable = false, Length = 50)] + public string MasterBolIndicatorName { get; set; } + + /// + /// 销售EDI名称 + /// + [SqlSugar.SugarColumn(ColumnDescription = "销售EDI名称", IsNullable = false, Length = 50)] + public string SalerCodeName { get; set; } + + /// + /// 欧盟港口、伊朗港口、KHI + /// + [SqlSugar.SugarColumn(ColumnDescription = "欧盟港口、伊朗港口、KHI", IsNullable = false, ColumnDataType = StaticConfig.CodeFirst_BigString)] + public string CKHI { get; set; } + + /// + /// 南美东 + /// + [SqlSugar.SugarColumn(ColumnDescription = "南美东", IsNullable = false, ColumnDataType = StaticConfig.CodeFirst_BigString)] + public string CNCM { get; set; } + + /// + /// 巴西线的木质包装情况 + /// + [SqlSugar.SugarColumn(ColumnDescription = "巴西线的木质包装情况", IsNullable = false, ColumnDataType = StaticConfig.CodeFirst_BigString)] + public string WNCM { get; set; } + + /// + /// 订舱人说明 + /// + [SqlSugar.SugarColumn(ColumnDescription = "订舱人说明", IsNullable = false, Length = 100)] + public string OrderRemark { get; set; } + + /// + /// 辅助字段1 + /// + [SqlSugar.SugarColumn(ColumnDescription = "辅助字段1", IsNullable = false, Length = 200)] + public string ExRemark1 { get; set; } + + /// + /// 辅助字段2 + /// + [SqlSugar.SugarColumn(ColumnDescription = "辅助字段2", IsNullable = false, Length = 200)] + public string ExRemark2 { get; set; } + + /// + /// 辅助字段3 + /// + [SqlSugar.SugarColumn(ColumnDescription = "辅助字段3", IsNullable = false, Length = 200)] + public string ExRemark3 { get; set; } + + /// + /// 辅助字段4 + /// + [SqlSugar.SugarColumn(ColumnDescription = "辅助字段4", IsNullable = false, Length = 200)] + public string ExRemark4 { get; set; } + + /// + /// 第一层包装皮重 + /// + [SqlSugar.SugarColumn(ColumnDescription = "第一层包装皮重", IsNullable = false, Length = 19, DecimalDigits = 2, DefaultValue = "0")] + public decimal? KingTareweight { get; set; } + + + /// + /// 箱满仓业务员 + /// + [SqlSugar.SugarColumn(ColumnDescription = "箱满仓业务员", IsNullable = false, Length = 50)] + public string XMCYWY { get; set; } + + /// + /// EMC Name accout + /// + [SqlSugar.SugarColumn(ColumnDescription = "EMC Name accout", IsNullable = false, Length = 50)] + public string EmcNameAccount { get; set; } + + /// + /// CNPTNo + /// + [SqlSugar.SugarColumn(ColumnDescription = "CNPTNo", IsNullable = false, Length = 50)] + public string CNPTNo { get; set; } +} \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.Core/Op/Interface/ISeaExportService.cs b/ds-wms-service/DS.WMS.Core/Op/Interface/ISeaExportService.cs index dc023b98..62252e16 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Interface/ISeaExportService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Interface/ISeaExportService.cs @@ -146,4 +146,10 @@ public interface ISeaExportService /// 返回回执 public DataResult CheckAndInitVOLTAEdi(BookingOrClosingEDIOrderReq req); + /// + /// 发送订舱、截单EDI + /// + /// 订舱、截单EDI请求 + /// 返回回执 + public Task> SendBookingOrClosingEDI(BookingOrClosingEDIOrderReq req); } \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/OpCtnDetailService.cs b/ds-wms-service/DS.WMS.Core/Op/Method/OpCtnDetailService.cs index c3bfbcf6..8477c095 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Method/OpCtnDetailService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Method/OpCtnDetailService.cs @@ -51,7 +51,7 @@ namespace DS.WMS.Core.Op.Method { if (item.Id == 0) { - var detail = item.Adapt(); + var detail = item.Adapt(); detail.CtnId = req.CtnId; tenantDb.Insertable(detail).ExecuteCommand(); } diff --git a/ds-wms-service/DS.WMS.Core/Op/Method/SeaExportService.cs b/ds-wms-service/DS.WMS.Core/Op/Method/SeaExportService.cs index 1eeca9c9..d4671a0a 100644 --- a/ds-wms-service/DS.WMS.Core/Op/Method/SeaExportService.cs +++ b/ds-wms-service/DS.WMS.Core/Op/Method/SeaExportService.cs @@ -1,3 +1,4 @@ +using Amazon.Runtime.Internal.Util; using AngleSharp.Dom; using DS.Module.Core; using DS.Module.Core.Data; @@ -16,6 +17,8 @@ using DS.WMS.Core.Sys.Entity; using DS.WMS.Core.Sys.Interface; using LanguageExt; using Mapster; +using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -25,6 +28,14 @@ using System.Collections.Specialized; using System.Text; using System.Text.RegularExpressions; using Logger = NLog.Logger; +using NPOI.HSSF.UserModel; +using NPOI.SS.UserModel; +using Org.BouncyCastle.Ocsp; +using Microsoft.AspNetCore.Hosting; +using NPOI.SS.Formula.Functions; +using System.Runtime.InteropServices; +using DS.WMS.Core.Op.EDI; +using DS.Module.PrintModule; namespace DS.WMS.Core.Op.Method; @@ -37,6 +48,20 @@ public class SeaExportService : ISeaExportService private readonly ICommonService commonService; private static readonly Logger _logger = LogManager.GetCurrentClassLogger(); private readonly ISeaExportCommonService seaComService; + private readonly IWebHostEnvironment _environment; + //private readonly IPrintService _printService; + + const string CONST_MAPPING_MODULE = "BOOK_OR_CLOSING"; + const string CONST_MAPPING_MODULE_ROUTE = "BOOK_OR_CLOSING_RT"; + const string CONST_MAPPING_MODULE_VOLTA = "BOOK_CLOSING_VOLTA"; + const string CONST_MAPPING_MODULE_INTTRA = "INTTRA_EDI"; + + private const string PrintRecentListTypeKey = "booking_print_recent_list"; + + const string CONST_TSL_EDI_URL = "tsl_edi_declare_url"; + const string CONST_TSL_TYPE_CODE = "TslWeb"; + const string CONST_ONE_SOFILE_CATE_CODE = "one_so_file_template"; + const string PRINT_DATASOURCE_KEY = "booking_order"; /// /// /// @@ -48,7 +73,21 @@ public class SeaExportService : ISeaExportService user = _serviceProvider.GetRequiredService(); saasService = _serviceProvider.GetRequiredService(); commonService = _serviceProvider.GetRequiredService(); - seaComService = _serviceProvider.GetRequiredService(); + seaComService = _serviceProvider.GetRequiredService(); + _environment = _serviceProvider.GetRequiredService(); + //_printService = _serviceProvider.GetRequiredService(); + // 设置对象映射 + TypeAdapterConfig + .NewConfig() + .Map(dto => dto.CNTRNO, poco => poco.Id) + .Map(dto => dto.HSCODE, poco => poco.HSCode) + .Map(dto => dto.MARKS, poco => poco.Marks) + .Map(dto => dto.DESCRIPTION, poco => poco.Description) + .Map(dto => dto.PKGS, poco => poco.PKGS) + .Map(dto => dto.KINDPKGS, poco => poco.KindPkgs) + .Map(dto => dto.KGS, poco => poco.KGS) + .Map(dto => dto.CBM, poco => poco.CBM) + .IgnoreNonMapped(true);//只映射Map指定的属性,其他属性都排除; } /// @@ -113,7 +152,13 @@ public class SeaExportService : ISeaExportService tenantDb.Insertable(ctn).ExecuteCommand(); } } - + if (req.EdiInfo.IsNotNull()) + { + var edi = req.EdiInfo.Adapt(); + edi.BusinessId = entity.Id; + tenantDb.Insertable(edi).ExecuteCommand(); + + } return DataResult.Successed("添加成功!", entity.Id, MultiLanguageConst.DataCreateSuccess); } else @@ -158,6 +203,13 @@ public class SeaExportService : ISeaExportService } } + if (req.EdiInfo.IsNotNull()) + { + var edi = tenantDb.Queryable().Where(x => x.BusinessId == req.Id).ToList(); + var ediInfo = req.EdiInfo.Adapt(edi); + tenantDb.Updateable(ediInfo).ExecuteCommand(); + + } return DataResult.Successed("更新成功!", MultiLanguageConst.DataUpdateSuccess); } @@ -173,6 +225,11 @@ public class SeaExportService : ISeaExportService var data = tenantDb.Queryable() .Where(a => a.Id == long.Parse(id)) .Select() + .Mapper(it => + { + it.EdiInfo = tenantDb.Queryable().Where(x => x.BusinessId == it.Id).Select().First(); + } + ) .First(); return DataResult.Success(data, MultiLanguageConst.DataQuerySuccess); } @@ -1676,177 +1733,2148 @@ public class SeaExportService : ISeaExportService return result; } #endregion - - - - #region 上传FTP + #region 订舱、截单EDI /// - /// 上传FTP + /// 发送订舱、截单EDI /// - /// EDI文件路径 - /// FTP配置 + /// 订舱、截单EDI请求 /// 返回回执 - private async Task> InnerSendBookingOrClosingEDIToFTP(string filePath, CodeEdiSet ediCfg) + public async Task> SendBookingOrClosingEDI(BookingOrClosingEDIOrderReq req) { - - - CancellationTokenSource cts = new CancellationTokenSource(); - - string host = string.Empty; - string port = string.Empty; - - if (ediCfg.ServerIp.IndexOf(":") >= 0) - { - host = ediCfg.ServerIp.Split(new char[] { ':' }).FirstOrDefault().Trim(); - port = ediCfg.ServerIp.Split(new char[] { ':' }).Last()?.Trim(); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); + var dictValue= db.Queryable() + .InnerJoin((a, b) => a.TypeId == b.Id).Where((a, b) => b.Code == "XiangManCang") + .Select((a, b) => new { Value = a.Value, Name = a.Name }).First(); + var order = tenantDb.Queryable().First(x => x.Id == req.Id); + var Forwarder = order.Forwarder; + if (!string.IsNullOrEmpty(Forwarder) && dictValue.Value == Forwarder) + { + return await XMCEXCEL(req.Id); } - - NameValueCollection par = new NameValueCollection(); - par.Add("host", host); - //这里如果配置没有指定端口号默认是21端口 - par.Add("port", string.IsNullOrWhiteSpace(port) ? "21" : port); - par.Add("username", ediCfg.UserName); - par.Add("pwd", ediCfg.Password); - par.Add("path", ediCfg.FOLDERNAME); - - var ftpSpiderUrl = db.Queryable().Filter(null, true).Where(x => x.Code == "booking_edi_ftp_server" && x.TenantId == 1288018625843826688).First(); - - if (ftpSpiderUrl.IsNull()) - return await Task.FromResult(DataResult.Failed("字典未配置 url_set->booking_edi_ftp_server 请联系管理员!")); - - //var fileInfo = new FileInfo(filePath); - - _logger.Info($"准备请求发送ftp:{ftpSpiderUrl.Value} ,参数:{JsonConvert.SerializeObject(par)},文件:{filePath}"); - - - System.IO.FileStream file = new System.IO.FileStream(filePath, FileMode.Open, FileAccess.Read); - int SplitSize = 5242880;//5M分片长度 - int index = 1; //序号 第几片 - long StartPosition = 5242880 * (index - 1); - long lastLens = file.Length - StartPosition;//真不知道怎么起命了,就这样吧 - if (lastLens < 5242880) + else { - SplitSize = (int)lastLens; + return await InnerBookingOrClosingEDI(req); } - byte[] heByte = new byte[SplitSize]; - file.Seek(StartPosition, SeekOrigin.Begin); - //第一个参数是 起始位置 - file.Read(heByte, 0, SplitSize); - //第三个参数是 读取长度(剩余长度) - file.Close(); - - string strJoin = System.IO.File.ReadAllText(filePath); - - DateTime bDate = DateTime.Now; - - _logger.Info("FTP 开始上传"); - var res = FTPHelper.TransmitFtpFile(ftpSpiderUrl.Value, par, new - { - file = "file", - fileName = Path.GetFileName(filePath), - fileBytes = heByte - }); - - DateTime eDate = DateTime.Now; - TimeSpan ts = eDate.Subtract(bDate); - var timeDiff = ts.TotalMilliseconds; - - _logger.Info($"FTP 上传完成 上传文件大小:{heByte.Length} 用时:{timeDiff}ms.,{strJoin}"); - - _logger.Info($"发送ftp返回:{res}"); - - var jobjRetn = JObject.Parse(res); - - if (jobjRetn.GetStringValue("status") != "1") - { - return await Task.FromResult(DataResult.Failed(jobjRetn.GetStringValue("message"))); - } - else - { - return await Task.FromResult(DataResult.Success("请求成功!")); - } } #endregion - /// - /// EDI发送POST请求 + /// 箱满仓生成excel文件 /// - /// 文件路径 - /// 请求URL - /// 配置账户 - /// 返回回执 - private async Task> InnerSendBookingOrClosingEDIToPOST(string filePath, string url, CodeThirdParty accountConfig) - { - - CancellationTokenSource cts = new CancellationTokenSource(); - var userKey = db.Queryable().Filter(null, true).Where(x => x.Code == "BCOrDraftUserKey" && x.TenantId == 1288018625843826688).First(); - var userPwd = db.Queryable().Filter(null, true).Where(x => x.Code == "BCOrDraftUserSecret" && x.TenantId == 1288018625843826688).First(); - if (userKey.IsNull()) - { - return await Task.FromResult(DataResult.Failed("请配置相关账号!")); - } - if (userPwd.IsNull()) - { - return await Task.FromResult(DataResult.Failed("请配置相关密钥!")); - } - NameValueCollection par = new NameValueCollection(); - //par.Add("user_key", App.Configuration["BCOrDraftUserKey"]); - //par.Add("user_secret", App.Configuration["BCOrDraftUserSecret"]); - par.Add("user_key", userKey.Value); - par.Add("user_secret", userPwd.Value); - par.Add("web_user", accountConfig.AppKey?.Trim()); - par.Add("web_psw", accountConfig.AppSecret?.Trim()); + /// + /// + /// + public async Task XMCEXCEL(long Id, bool flag = false) + { + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); + var order = tenantDb.Queryable().First(x => x.Id == Id); + + var edi = tenantDb.Queryable().First(x => x.BusinessId == Id); + var ctn = tenantDb.Queryable().Where(x => x.BSNO == order.Id.ToString()).ToList(); + + #region 箱满仓生成excel文件 + string fileName = String.Empty; + //var opt = App.GetOptions(); + var dirAbs = AppSetting.app(new string[] { "PrintTemplate", "BasePath" }); + var relativePath = AppSetting.app(new string[] { "PrintTemplate", "RelativePath" }); + if (string.IsNullOrEmpty(dirAbs)) + { + dirAbs = _environment.WebRootPath; + } + var fPath = "upload/printtemplate/箱满舱上传Excel模板.xls"; + var fileAbsPath = Path.Combine(dirAbs, fPath); + _logger.Info($"准备调用EXCEL"); + var file = new FileStream(fileAbsPath, FileMode.Open); + var excelwork = new HSSFWorkbook(file); + var sheet = excelwork.GetSheetAt(0); + for (int i = 0; i < sheet.LastRowNum; i++) + { + ////获取行 + var row = sheet.GetRow(i); + if (i == 0) + { + //委托编号 + ICell cell = row.GetCell(5); + if (cell != null) + { + row.Cells[5].SetCellValue(order.CustomerNo); + } + else + { + row.CreateCell(5).SetCellValue(order.CustomerNo); + } + } + if (i == 1) + { + //场站 + var yardid = order.Yard; + if (!string.IsNullOrEmpty(yardid)) + { + ICell cell = row.GetCell(5); + var yard = tenantDb.Queryable() + .Where(x => x.Status == StatusEnum.Enable && x.Module == "XiangManCangEDI" && x.Code == yardid) + .Select(x => x.MapCode).First(); + if (cell != null) + { + row.Cells[5].SetCellValue(yard); + } + else + { + row.CreateCell(5).SetCellValue(yard); + } - _logger.Info($"准备请求发送POST:{url} ,参数:{JsonConvert.SerializeObject(par)},文件:{filePath}"); + } - System.IO.FileStream file = new System.IO.FileStream(filePath, FileMode.Open, FileAccess.Read); - int SplitSize = 5242880;//5M分片长度 - int index = 1; //序号 第几片 - long StartPosition = 5242880 * (index - 1); - long lastLens = file.Length - StartPosition;//真不知道怎么起命了,就这样吧 - if (lastLens < 5242880) - { - SplitSize = (int)lastLens; - } - byte[] heByte = new byte[SplitSize]; - file.Seek(StartPosition, SeekOrigin.Begin); - //第一个参数是 起始位置 - file.Read(heByte, 0, SplitSize); - //第三个参数是 读取长度(剩余长度) - file.Close(); + } + if (i == 2) + { + //指定业务员 + ICell cell = row.GetCell(5); + if (cell != null) + { + row.Cells[5].SetCellValue(edi.XMCYWY); + } + else + { + row.CreateCell(5).SetCellValue(edi.XMCYWY); + } + } + if (i == 3) + { + //提单号 + ICell cell = row.GetCell(5); + if (cell != null) + { + if (string.IsNullOrEmpty(order.MBLNO)) + { - string strJoin = System.IO.File.ReadAllText(filePath); + row.Cells[5].SetCellValue(order.CustomerNo); + } + else + { - DateTime bDate = DateTime.Now; + row.Cells[5].SetCellValue(order.MBLNO); + } - _logger.Info("POST 开始上传"); + } + else + { + if (string.IsNullOrEmpty(order.MBLNO)) + { + row.CreateCell(5).SetCellValue(order.CustomerNo); + } + else + { + row.CreateCell(5).SetCellValue(order.MBLNO); + } + } + } + if (i == 8) + { + //发货人 + ICell cell = row.GetCell(1); + var shipper = tenantDb.Queryable() + .Where(x => x.Status == 0 && x.Id == order.ShipperId).First(); + if (cell != null) + { + row.Cells[1].SetCellValue(shipper.ShortName); + } + else + { + row.CreateCell(1).SetCellValue(shipper.ShortName); + } + } + if (i == 10) + { + //发货人代码 + ICell cell = row.GetCell(1); + if (cell != null) + { + row.Cells[1].SetCellValue(order.Shipper); + } + else + { + row.CreateCell(1).SetCellValue(order.Shipper); + } + } + if (i == 11) + { + //收货人 + ICell cell = row.GetCell(1); + if (cell != null) + { + row.Cells[1].SetCellValue(order.Consignee); + } + else + { + row.CreateCell(1).SetCellValue(order.Consignee); + } + } + if (i == 14) + { + //通知人 + ICell cell = row.GetCell(1); + if (cell != null) + { + row.Cells[1].SetCellValue(order.NotifyParty); + } + else + { + row.CreateCell(1).SetCellValue(order.NotifyParty); + } + } + if (i == 17) + { + //第二通知人 + ICell cell = row.GetCell(1); + if (cell != null) + { + row.Cells[1].SetCellValue(order.SecondNotifyParty); + } + else + { + row.CreateCell(1).SetCellValue(order.SecondNotifyParty); + } + } + if (i == 18) + { + //起运港国际五字代码 + ICell cell = row.GetCell(1); + if (cell != null) + { + row.Cells[1].SetCellValue(order.LoadPort); + } + else + { + row.CreateCell(1).SetCellValue(order.LoadPort); + } - var res = FTPHelper.TransmitFtpFile(url, par, new - { - file = "file", - fileName = Path.GetFileName(filePath), - fileBytes = heByte - }); + var service = order.Service; + //运输方式 + ICell cell5 = row.GetCell(5); + var serviceMap = tenantDb.Queryable() + .Where(x => x.Status == StatusEnum.Enable && x.Module == "XiangManCangEDI" && x.Code == service).Select(x => x.MapCode).First(); + + if (cell5 != null) + { + row.Cells[5].SetCellValue(serviceMap); + } + else + { + row.CreateCell(5).SetCellValue(serviceMap); + } + } + if (i == 19) + { + //卸货港国际五字代码 + ICell cell = row.GetCell(1); + if (cell != null) + { + row.Cells[1].SetCellValue(order.DischargePort); + } + else + { + row.CreateCell(1).SetCellValue(order.DischargePort); + } + } + if (i == 20) + { + //交货地国际五字代码 + ICell cell = row.GetCell(1); + if (cell != null) + { + row.Cells[1].SetCellValue(order.Destination); + } + else + { + row.CreateCell(1).SetCellValue(order.Destination); + } + } + if (i == 21) + { + //ETD - DateTime eDate = DateTime.Now; - TimeSpan ts = eDate.Subtract(bDate); - var timeDiff = ts.TotalMilliseconds; + if (order.ETD != null) + { - _logger.Info($"请求POST 上传完成 上传文件大小:{heByte.Length} 用时:{timeDiff}ms.,{strJoin}"); + ICell cell = row.GetCell(1); + if (cell != null) + { + row.Cells[1].SetCellValue(Convert.ToDateTime(order.ETD).ToString("yyyy-MM-dd")); + } + else + { + row.CreateCell(1).SetCellValue(Convert.ToDateTime(order.ETD).ToString("yyyy-MM-dd")); + } + } - _logger.Info($"发送POST返回:{res}"); - var jobjRetn = JObject.Parse(res); + //船名 + ICell cell4 = row.GetCell(4); + if (cell4 != null) + { + row.Cells[4].SetCellValue(order.Vessel); + } + else + { + row.CreateCell(4).SetCellValue(order.Vessel); + } - if (jobjRetn.GetStringValue("code") != "200") - { - return await Task.FromResult(DataResult.Failed(jobjRetn.GetStringValue("msg"))); - } - else - { - return await Task.FromResult(DataResult.Success("请求成功!")); - } - } + } + if (i == 22) + { + //客户协约号 + ICell cell = row.GetCell(1); + if (cell != null) + { + row.Cells[1].SetCellValue(order.ContractNo); + } + else + { + row.CreateCell(1).SetCellValue(order.ContractNo); + } + } + if (i == 23) + { + //航次 + ICell cell = row.GetCell(4); + if (cell != null) + { + row.Cells[4].SetCellValue(order.InnerVoyno); + } + else + { + row.CreateCell(4).SetCellValue(order.InnerVoyno); + } + } + if (i == 26) + { + //唛头 + ICell cell = row.GetCell(0); + if (cell != null) + { + row.Cells[0].SetCellValue(order.Marks); + } + else + { + row.CreateCell(0).SetCellValue(order.Marks); + } + + if (order.PKGS != null) + { + //件数 + ICell cell1 = row.GetCell(1); + if (cell1 != null) + { + row.Cells[1].SetCellValue(order.PKGS.ToString()); + } + else + { + row.CreateCell(1).SetCellValue(order.PKGS.ToString()); + } + + } + //包装 + ICell cell2 = row.GetCell(2); + if (cell2 != null) + { + row.Cells[2].SetCellValue(order.KindPkgs); + } + else + { + row.CreateCell(2).SetCellValue(order.KindPkgs); + } + //品名 + ICell cell3 = row.GetCell(3); + if (cell3 != null) + { + row.Cells[3].SetCellValue(order.Description); + } + else + { + row.CreateCell(3).SetCellValue(order.Description); + } + if (order.KGS != null) + { + //重量 + ICell cell4 = row.GetCell(4); + if (cell3 != null) + { + row.Cells[4].SetCellValue(order.KGS.ToString()); + } + else + { + row.CreateCell(4).SetCellValue(order.KGS.ToString()); + } + } + if (order.CBM != null) + { + //尺码 + ICell cell5 = row.GetCell(5); + if (cell5 != null) + { + row.Cells[5].SetCellValue(order.CBM.ToString()); + } + else + { + row.CreateCell(5).SetCellValue(order.CBM.ToString()); + } + } + } + if (i == 39) + { + var c = ctn.DistinctBy(x => x.CtnAll).ToList(); + var ctnAll = string.Empty; + foreach (var item in c) + { + var ctnMap = tenantDb.Queryable() + .Where(x => x.Status == StatusEnum.Enable && x.Module == "XiangManCangEDI" && x.Code == item.CtnCode).Select(x => x.MapCode).First(); + + ctnAll += $"{ctn.Where(x => x.CtnAll == item.CtnAll).Count()}*{ctnMap}+"; + } + ctnAll = ctnAll.Substring(0, ctnAll.Length - 1); + //箱型箱量 + ICell cell = row.GetCell(0); + if (cell != null) + { + row.Cells[0].SetCellValue(ctnAll); + } + else + { + row.CreateCell(0).SetCellValue(ctnAll); + } + } + if (i == 42) + { + //运费支付方式 + + var BLFRTCode = tenantDb.Queryable() + .Where(x => x.Status == StatusEnum.Enable && x.FrtName == order.MBLFrt).Select(x => x.EdiCode).First(); + var bl = string.Empty; + if (!string.IsNullOrEmpty(BLFRTCode)) + { + bl = tenantDb.Queryable() + .Where(x => x.Status == StatusEnum.Enable && x.Module == "XiangManCangEDI" && x.Code == BLFRTCode).Select(x => x.MapCode).First(); + + } + ICell cell = row.GetCell(0); + if (cell != null) + { + row.Cells[0].SetCellValue(bl); + } + else + { + row.CreateCell(0).SetCellValue(bl); + } + } + if (i == 43) + { + //hscode + ICell cell = row.GetCell(3); + if (cell != null) + { + row.Cells[3].SetCellValue(order.HSCode); + } + else + { + row.CreateCell(3).SetCellValue(order.HSCode); + } + } + if (i == 44) + { + var BLFRTCode = tenantDb.Queryable() + .Where(x => x.Status == StatusEnum.Enable && x.FrtName == order.MBLFrt).Select(x => x.EdiCode).First(); + var bl = string.Empty; + if (!string.IsNullOrEmpty(BLFRTCode)) + { + bl = tenantDb.Queryable() + .Where(x => x.Status == StatusEnum.Enable && x.Module == "XiangManCangEDI" && x.Code == BLFRTCode).Select(x => x.MapCode).First(); + + } + if (bl == "预付") + { + //预付地点 + ICell cell = row.GetCell(1); + if (cell != null) + { + row.Cells[1].SetCellValue(order.PrepareAt); + } + else + { + row.CreateCell(1).SetCellValue(order.PrepareAt); + } + + } + else if ((bl == "到付")) + { + + //预付地点 + ICell cell = row.GetCell(1); + if (cell != null) + { + row.Cells[1].SetCellValue(order.PayableAt); + } + else + { + row.CreateCell(1).SetCellValue(order.PayableAt); + } + + + } + + } + if (i == 45) + { + //Name accout + ICell cell = row.GetCell(1); + if (cell != null) + { + row.Cells[1].SetCellValue(edi.EmcNameAccount); + } + else + { + row.CreateCell(1).SetCellValue(edi.EmcNameAccount); + } + ICell _cell = row.GetCell(4); + if (_cell != null) + { + row.Cells[4].SetCellValue(edi.EmcNameAccount); + } + else + { + row.CreateCell(4).SetCellValue(edi.EmcNameAccount); + } + } + if (i == 47) + { + //Name accout + ICell cell = row.GetCell(1); + if (cell != null) + { + row.Cells[1].SetCellValue(order.TemperatureSet); + } + else + { + row.CreateCell(1).SetCellValue(order.TemperatureSet); + } + + + + //温度 + ICell cell2 = row.GetCell(2); + if (cell2 != null) + { + row.Cells[2].SetCellValue(order.ReeferQuantity); + } + else + { + row.CreateCell(2).SetCellValue(order.ReeferQuantity); + } + + + //湿度 + ICell cell3 = row.GetCell(3); + if (cell2 != null) + { + row.Cells[3].SetCellValue(order.Humidity); + } + else + { + row.CreateCell(3).SetCellValue(order.Humidity); + } + } + if (i == 49) + { + //危险品编号 + ICell cell = row.GetCell(1); + if (cell != null) + { + row.Cells[1].SetCellValue(order.DangerNo); + } + else + { + row.CreateCell(1).SetCellValue(order.DangerNo); + } + } + if (i == 50) + { + //订舱备注 + ICell cell = row.GetCell(1); + if (cell != null) + { + row.Cells[1].SetCellValue(order.BookingRemark); + } + else + { + row.CreateCell(1).SetCellValue(order.BookingRemark); + } + } + } + + var fileFullPath = Path.Combine(_environment.WebRootPath, AppSetting.app(new string[] { "TempFile", "Path" }));//服务器路径 + if (!Directory.Exists(fileFullPath)) + { + Directory.CreateDirectory(fileFullPath); + } + + //2023-4-3,根据合川操作要求,文件名只带提单号 + if (!string.IsNullOrEmpty(order.MBLNO)) + { + fileName = $"{DateTime.Now.Ticks}_{order.MBLNO}.xls";//名称 + } + else + { + fileName = $"{DateTime.Now.Ticks}_{order.MBLNO}.xls";//名称 + } + _logger.Info("导出excel:" + Path.Combine(fileFullPath, fileName)); + var filestream = new FileStream(Path.Combine(fileFullPath, fileName), FileMode.OpenOrCreate, FileAccess.ReadWrite); + excelwork.Write(filestream); + + #endregion + if (flag) + { + filestream.Close(); + filestream.Dispose(); + var fpath = Path.Combine(fileFullPath, fileName); + var fInfo = new FileInfo(fpath); + _logger.Info("箱满仓文件地址:" + fpath + " " + fInfo); + return new FileStreamResult(new FileStream(fpath, FileMode.Open), "application/octet-stream") { FileDownloadName = fInfo.Name }; + } + + #region 调用爬虫接口 + + var url = db.Queryable().Filter(null, true).Where(x => x.Code == "xiangManCangPostUrl" && x.TenantId == 1288018625843826688).Select(x => x.Value).First(); + if (string.IsNullOrEmpty(url)) + { + return await Task.FromResult(DataResult.Failed("未配置箱满仓请求地址,请联系管理员!")); + } + var account = tenantDb.Queryable().First(x => x.CustomerId == order.CarrierId && x.AccountType == "XiangManCang"); + if (account == null) + { + return await Task.FromResult(DataResult.Failed("未配置箱满仓账号!")); + } + + var key = db.Queryable().Filter(null, true).Where(x => x.Code == "billTraceNewUserKey" && x.TenantId == 1288018625843826688).Select(x => x.Value).First(); + + if (string.IsNullOrEmpty(key)) + { + return await Task.FromResult(DataResult.Failed("未获取到相关KEY,请联系管理员!")); + } + + var secret = db.Queryable().Filter(null, true).Where(x => x.Code == "billTraceNewUserSecret" && x.TenantId == 1288018625843826688).Select(x => x.Value).First(); + if (string.IsNullOrEmpty(secret)) + { + return await Task.FromResult(DataResult.Failed("未获取到相关SECRET,请联系管理员!")); + } + ////使用HttpClient方式上传文件 + var carrier_code = db.Queryable().Where(x => x.Module == "HeChuan" && x.MapCode == order.Carrier).Select(x => x.Code).First(); + string fn = string.Empty; + using (var httpClient = new HttpClient()) + { + using (var request = new HttpRequestMessage(new HttpMethod("Post"), url)) + { + //request.Headers.TryAddWithoutValidation("Content-Type", "application/x-www-form-urlencoded"); + var multipartContent = new MultipartFormDataContent(); + multipartContent.Add(new StringContent("user_key"), key); + multipartContent.Add(new StringContent("user_secret"), secret); + multipartContent.Add(new StringContent("web_user"), account.AppKey); + multipartContent.Add(new StringContent("web_psw"), account.AppSecret); + multipartContent.Add(new StringContent("carrier_code"), carrier_code); + multipartContent.Add(new StreamContent(filestream, (int)filestream.Length), "file", fileName); + request.Content = multipartContent; + var response = await httpClient.SendAsync(request); + if (response.IsSuccessStatusCode) + { + var strRtn = response.Content.ReadAsStringAsync().Result; + var jobj = strRtn.ToJObject(); + if (jobj.GetIntValue("code") == 200) + { + fn = jobj.GetStringValue("msg"); + + } + else + { + return await Task.FromResult(DataResult.Failed(jobj.GetStringValue("msg"))); + } + } + } + } + + //return fn; + return await Task.FromResult(DataResult.Success(fn)); + #endregion + } + + #region 根据船公司ID获取EDI的路由枚举 + /// + /// 根据船公司ID获取EDI的路由枚举 + /// + /// 船公司ID + /// + /// 返回适用的路由枚举 + private EDIRouteEnum GetEDIRoute(string carrierId, MappingCarrier ediRouteCfg) + { + EDIRouteEnum routeEnum = EDIRouteEnum.NULL; + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); + + //var ediRouteCfg = _cache.GetAllMappingCarrier().GetAwaiter().GetResult() + // .FirstOrDefault(t => t.Module.Equals("BOOK_OR_CLOSING_RT", StringComparison.OrdinalIgnoreCase) + // && t.Code.Equals(carrierId, StringComparison.OrdinalIgnoreCase)); + + if (ediRouteCfg != null && !string.IsNullOrWhiteSpace(ediRouteCfg.MapCode)) + routeEnum = (EDIRouteEnum)System.Enum.Parse(typeof(EDIRouteEnum), ediRouteCfg.MapCode); + + //switch (carrierId.ToUpper()) + //{ + // case "PIL": + // routeEnum = EDIRouteEnum.PIL; + // break; + // case "ONE": + // routeEnum = EDIRouteEnum.YT; + // break; + // case "TSL": + // routeEnum = EDIRouteEnum.TSL; + // break; + // case "YML": + // routeEnum = EDIRouteEnum.YML; + // break; + // case "WY": + // routeEnum = EDIRouteEnum.WY; + // break; + //} + + return routeEnum; + } + #endregion + public async Task> InnerBookingOrClosingEDI(BookingOrClosingEDIOrderReq req) + { + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); + + string batchNo = GuidHelper.NewGuidFormatN(); + + _logger.Info("批次={no}获取请求订舱、截单EDI {msg}", batchNo, JsonConvert.SerializeObject(req)); + /* + 发送订舱和截单EDI的流程 + 1、通过订单号获取订单信息。 + 2、检查订单的必填信息。 + 3、根据船公司ID获取对应的路由枚举。 + 4、获取EDI转换参数。(集装箱型号、包装方式) + 5、读取EDI的配置信息,获取船公司相关的EDI配置。 + 6、检查详细信息。 + 7、生成订舱或者截单EDI报文,并返回文件保存绝对路径。 + */ + if (req.Id == 0) + return DataResult.Failed($"订单Id不能为空"); + + var order = tenantDb.Queryable().First(x => x.Id == req.Id); + if (order == null) + return DataResult.Failed($"获取订单信息失败"); + if (order.ParentId == 0) + return DataResult.Failed($"获取当前订单为分单不能生成EDI信息"); + + _logger.Info("批次={no}提取订单信息完成", batchNo); + + var ediExtModel = tenantDb.Queryable().First(x => x.BusinessId == req.Id); + + if (ediExtModel == null) + return DataResult.Failed($"获取EDI信息失败"); + + _logger.Info("批次={no}提取订单EDI信息完成", batchNo); + + //箱信息 + var contaList = tenantDb.Queryable().Where(x => x.BSNO == order.Id.ToString()).ToList(); + + + var check= CheckBookingOrClosingEDI(order, contaList); + if (!check.Succeeded) + { + return DataResult.Failed(check.Message); + } + var carrMap= tenantDb.Queryable().Where(t => t.Module.Equals("BOOK_OR_CLOSING_RT", StringComparison.OrdinalIgnoreCase) + && t.LinkId == order.CarrierId) + .First(); + + EDIRouteEnum ediRouteEnum = GetEDIRoute(order.Carrier, carrMap); + + if (ediRouteEnum == EDIRouteEnum.YT) + { + if (string.IsNullOrWhiteSpace(order.NoBill)) + { + return DataResult.Failed($"当前船公司{order.Carrier} EDI={ediRouteEnum.ToString()} 提单份数必填"); + } + } + + //部分船公司EDI需要填写操作英文名称,这里预先预警,其他船公司如果也需要可以再此追加 + if (ediRouteEnum == EDIRouteEnum.TSL) + { + if (string.IsNullOrWhiteSpace(ediExtModel.OpEName)) + return DataResult.Failed($"未填写(EDI并补充信息)操作英文名称"); + } + + _logger.Info("批次={no} 获取EDI路由完成 路由={route}", batchNo, ediRouteEnum.ToString()); + + if (ediRouteEnum == EDIRouteEnum.NULL) + return DataResult.Failed($"当前船公司没有对应的请求路由配置"); + + //这里船公司VOL的单子不能走此通道发送 + if (ediRouteEnum == EDIRouteEnum.VOL) + return DataResult.Failed($"当前船公司VOL不能执行标准发送"); + + //集装箱型 + var ediCtnList = tenantDb.Queryable() + .Where(t => t.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase) + && t.CarrierId == order.CarrierId).ToList(); + + //包装 + var ediPkgsList = tenantDb.Queryable() + .Where(t => t.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase) + && t.CarrierId == order.CarrierId).ToList(); + + //包装基础数据 + var basePkgsList = tenantDb.Queryable().Where(x=>x.Status == StatusEnum.Enable).ToList(); + + //EDI SO\SI代码 + var ediSOSICfg = tenantDb.Queryable().First(t => t.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase) + && t.LinkId == order.CarrierId); + + if (ediSOSICfg == null || string.IsNullOrWhiteSpace(ediSOSICfg.MapCode)) + return DataResult.Failed($"CARRIERID={order.Carrier} 发送SO(SI)的船公司EDI代码未找到"); + + string postSpiderUrl = string.Empty; + CodeThirdParty userWebAccountConfig = null; + + if (ediRouteEnum == EDIRouteEnum.TSL && req.Send) + { + if (req.SendType.Equals("E", StringComparison.OrdinalIgnoreCase)) + return DataResult.Failed($"暂未提供TSL的截单发送"); + + postSpiderUrl = db.Queryable().Filter(null, true).Where(x => x.Code == CONST_TSL_EDI_URL && x.TenantId == 1288018625843826688).First().Value; + + if (string.IsNullOrWhiteSpace(postSpiderUrl)) + return DataResult.Failed($"字典未配置 url_set->{CONST_TSL_EDI_URL} 请联系管理员"); + + //获取个人对应的账户,这里GetAccountConfig逻辑优先取个人,个人没有配置取公司对应配置 + userWebAccountConfig = await tenantDb.Queryable().FirstAsync(x => x.AccountType == CONST_TSL_TYPE_CODE); + + + _logger.Info("批次={no} 获取获取网站的账户完成,result={Num}", batchNo,JsonConvert.SerializeObject(userWebAccountConfig)); + + if (userWebAccountConfig == null) + return DataResult.Failed($"未配置个人或公司网站账户,网站{CONST_TSL_TYPE_CODE}"); + } + + + var ediModel = new EDIBaseModel(); + + //2023-03-06 修改读取EDI配置方法,所有提取配置必须是已启用的EnableFlag=true,并且要根据SendType匹配发送类型,SendType=""表示使用订舱和截单,SO-订舱 SI-截单 + var ftpSet = tenantDb.Queryable() + .First(a => a.EdiTypeCode.Equals(ediRouteEnum.ToString(), StringComparison.OrdinalIgnoreCase) && a.CarrierId == order.CarrierId + && a.Status == StatusEnum.Enable + && (string.IsNullOrWhiteSpace(a.SendType) || + (!string.IsNullOrWhiteSpace(a.SendType) && ((req.SendType == "B" && a.SendType == "SO") || (req.SendType == "E" && a.SendType == "SI"))))); + + if (ftpSet == null) + return DataResult.Failed($"获取EDICODE={ediRouteEnum.ToString()}的EDI参数设置失败"); + + _logger.Info("批次={no} 获取EDI配置完成 路由={set}", batchNo, JsonConvert.SerializeObject(ftpSet)); + + ediModel.SENDCODE = ftpSet.SendCode; + ediModel.SENDNAME = ftpSet.SendName; + ediModel.RECEIVECODE = ftpSet.ReceiveCode; + ediModel.SENDCOMPANYCODE = ftpSet.SendCompanyCode; + ediModel.SENDSUBCOMPANYCODE = ftpSet.SendCompanyCode; + ediModel.ALIASSENDCODE = ftpSet.AliasSendCode; + ediModel.SENDSHIPPERCODE = ftpSet.SendShipperCode; + + ediModel.filetype = req.SendType; //订舱 + ediModel.filerole = req.FileRole; + + //读取文件配置 + //var fileCfg = App.GetOptions(); + var basePath = AppSetting.app(new string[] { "FileSettings", "BasePath" }); + string filePath = String.Empty; + string relativePath = string.Empty; + + if (!req.Send) + { + var opt = AppSetting.app(new string[] { "TempFile", "Path" }); + + filePath = $"{Path.Combine(_environment.WebRootPath, opt)}\\{order.CustomerNo}";//服务器路径 + } + else + { + var cfgPath = AppSetting.app(new string[] { "FileSettings", "RelativePath" }); + relativePath = $"{cfgPath}\\edifiles\\{order.CustomerNo}"; + + filePath = $"{(!string.IsNullOrWhiteSpace(basePath) ? basePath : _environment.WebRootPath)}\\{relativePath}"; + } + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + relativePath = relativePath.Replace("\\", "/"); + filePath = filePath.Replace("\\", "/"); + } + + + _logger.Info("批次={no} 生成文件保存路径完成 路由={filePath} 服务器系统={system}", batchNo, filePath, RuntimeInformation.OSDescription); + //预先创建目录 + if (!Directory.Exists(filePath)) + { + Directory.CreateDirectory(filePath); + } + + ediModel.filerpath = filePath; + + /* + * 2023-03-08 这里根据最新的要求,不通过前台读取了,直接从配置读取 + ediModel.UseForWarderCode = model.useForwarderCode; + ediModel.ForWarderCode = model.forwarderCode; + ediModel.ForWarderName = model.forwarderName; + */ + ediModel.ForWarderCode = ftpSet.SendCode; + ediModel.ForWarderName = ftpSet.SendName; + + ediModel.BSLIST = new List(); + + //TODO + var primaryModel = order.Adapt(); + + //航次取内部航次号 2023-04-03 合川操作确认这样调整 + primaryModel.VOYNO = order.InnerVoyno; + + //航线信息直接取的航司航线(ESL用) + primaryModel.ESLLINECODE = order.Lane; + + //起始港映射 + var ediLoadPortList = tenantDb.Queryable() + .Where(a => a.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase) && a.CarrierId == order.CarrierId).ToList(); + + //收货地 + if (!string.IsNullOrWhiteSpace(primaryModel.PLACERECEIPTID)) + { + var currPortInfo = ediLoadPortList.FirstOrDefault(a => + a.Code.Equals(primaryModel.PLACERECEIPTID, StringComparison.OrdinalIgnoreCase)); + + if (currPortInfo == null) + return DataResult.Failed($"收货地{primaryModel.PLACERECEIPTID}的EDI代码未找到"); + + primaryModel.PLACERECEIPTID = currPortInfo.MapCode?.Trim(); + } + + //装货港 + if (!string.IsNullOrWhiteSpace(primaryModel.PORTLOADID)) + { + var currPortInfo = ediLoadPortList.FirstOrDefault(a => + a.Code.Equals(primaryModel.PORTLOADID, StringComparison.OrdinalIgnoreCase)); + + if (currPortInfo == null) + return DataResult.Failed($"装货港{primaryModel.PORTLOADID}的EDI代码未找到"); + + primaryModel.PORTLOADID = currPortInfo.MapCode?.Trim(); + } + + //签单地点 + if (!string.IsNullOrWhiteSpace(primaryModel.ISSUEPLACEID)) + { + var currPortInfo = ediLoadPortList.FirstOrDefault(a => + a.Code.Equals(primaryModel.ISSUEPLACEID, StringComparison.OrdinalIgnoreCase)); + + if (currPortInfo == null) + return DataResult.Failed($"签单地点{primaryModel.ISSUEPLACEID}的EDI代码未找到"); + + primaryModel.ISSUEPLACEID = currPortInfo.MapCode?.Trim(); + } + + //预付地点 + if (!string.IsNullOrWhiteSpace(primaryModel.PREPARDATID)) + { + var currPortInfo = ediLoadPortList.FirstOrDefault(a => + a.Code.Equals(primaryModel.PREPARDATID, StringComparison.OrdinalIgnoreCase)); + + if (currPortInfo == null) + return DataResult.Failed($"预付地点{primaryModel.PREPARDATID}的EDI代码未找到"); + + primaryModel.PREPARDATID = currPortInfo.MapCode?.Trim(); + } + + //目的港基础 + var portList = tenantDb.Queryable().Where(x=>x.Status == StatusEnum.Enable).ToList(); + + //目的港映射 + var ediPortList = tenantDb.Queryable() + .Where(t => t.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase) && t.CarrierId == order.CarrierId).ToList(); + + //卸货港 + if (!string.IsNullOrWhiteSpace(primaryModel.PORTDISCHARGEID)) + { + var sameList = portList.Where(a => + !string.IsNullOrWhiteSpace(a.EdiCode) + && a.EdiCode.Equals(primaryModel.PORTDISCHARGEID, StringComparison.OrdinalIgnoreCase)) + .Select(a => a.PortName).ToList(); + + if (sameList == null || sameList.Count == 0) + return DataResult.Failed($"卸货港{primaryModel.PORTDISCHARGEID}基础港口代码未找到"); + + var currPortInfo = ediPortList.FirstOrDefault(a => + sameList.Contains(a.Code) && a.CarrierId == order.CarrierId); + + if (currPortInfo == null) + { + currPortInfo = ediPortList.FirstOrDefault(a => + sameList.Contains(a.Code)); + } + + if (currPortInfo == null) + return DataResult.Failed($"卸货港{primaryModel.PORTDISCHARGEID}的EDI代码未找到"); + + primaryModel.PORTDISCHARGEID = currPortInfo.MapCode?.Trim(); + } + + //中转港 + if (!string.IsNullOrWhiteSpace(primaryModel.TRANSPORTID)) + { + var sameList = portList.Where(a => + !string.IsNullOrWhiteSpace(a.EdiCode) + && a.EdiCode.Equals(primaryModel.TRANSPORTID, StringComparison.OrdinalIgnoreCase)) + .Select(a => a.PortName).ToList(); + + if (sameList == null || sameList.Count == 0) + return DataResult.Failed($"中转港{primaryModel.TRANSPORTID}基础港口代码未找到"); + + var currPortInfo = ediPortList.FirstOrDefault(a => + sameList.Contains(a.Code) && a.CarrierId == order.CarrierId); + + if (currPortInfo == null) + { + currPortInfo = ediPortList.FirstOrDefault(a => + sameList.Contains(a.Code)); + } + + if (currPortInfo == null) + return DataResult.Failed($"中转港{primaryModel.TRANSPORTID}的EDI代码未找到"); + + primaryModel.TRANSPORTID = currPortInfo.MapCode?.Trim(); + } + + //目的地 + if (!string.IsNullOrWhiteSpace(primaryModel.DESTINATIONID)) + { + var sameList = portList.Where(a => + !string.IsNullOrWhiteSpace(a.EdiCode) + && a.EdiCode.Equals(primaryModel.DESTINATIONID, StringComparison.OrdinalIgnoreCase)) + .Select(a => a.PortName?.Trim()).ToList(); + + if (sameList == null || sameList.Count == 0) + return DataResult.Failed($"目的地{primaryModel.DESTINATIONID}基础港口代码未找到"); + + var currPortInfo = ediPortList.FirstOrDefault(a => + sameList.Contains(a.Code) && a.CarrierId == order.CarrierId); + + if (currPortInfo == null) + { + currPortInfo = ediPortList.FirstOrDefault(a => + sameList.Contains(a.Code)); + } + + if (currPortInfo == null) + return DataResult.Failed($"目的地{primaryModel.DESTINATIONID}的EDI代码未找到"); + primaryModel.DESTINATIONID = currPortInfo.MapCode?.Trim(); + } + + //交货地 + if (!string.IsNullOrWhiteSpace(primaryModel.PLACEDELIVERYID)) + { + var sameList = portList.Where(a => + !string.IsNullOrWhiteSpace(a.EdiCode) + && a.EdiCode.Equals(primaryModel.PLACEDELIVERYID, StringComparison.OrdinalIgnoreCase)) + .Select(a => a.PortName).ToList(); + + if (sameList == null || sameList.Count == 0) + return DataResult.Failed($"交货地{primaryModel.PLACEDELIVERYID}基础港口代码未找到"); + + var currPortInfo = ediPortList.FirstOrDefault(a => + sameList.Contains(a.Code) && a.CarrierId == order.CarrierId); + + if (currPortInfo == null) + { + currPortInfo = ediPortList.FirstOrDefault(a => + sameList.Contains(a.Code)); + } + + if (currPortInfo == null) + return DataResult.Failed($"交货地{primaryModel.PLACEDELIVERYID}的EDI代码未找到"); + + primaryModel.PLACEDELIVERYID = currPortInfo.MapCode?.Trim(); + } + + //到付地点 + if (!string.IsNullOrWhiteSpace(primaryModel.PAYABLEATID)) + { + var sameList = portList.Where(a => + !string.IsNullOrWhiteSpace(a.EdiCode) + && a.EdiCode.Equals(primaryModel.PAYABLEATID, StringComparison.OrdinalIgnoreCase)) + .Select(a => a.PortName).ToList(); + + if (sameList == null || sameList.Count == 0) + return DataResult.Failed($"到付地点{primaryModel.PAYABLEATID}基础港口代码未找到"); + + var currPortInfo = ediPortList.FirstOrDefault(a => + sameList.Contains(a.Code) && a.CarrierId == order.CarrierId); + + if (currPortInfo == null) + { + currPortInfo = ediPortList.FirstOrDefault(a => + sameList.Contains(a.Code)); + } + + if (currPortInfo == null) + return DataResult.Failed($"到付地点{primaryModel.PAYABLEATID}的EDI代码未找到"); + + primaryModel.PAYABLEATID = currPortInfo.MapCode?.Trim(); + } + + //起运港是CNTAO并且船公司是太平需要判断场站EDI + if (ediRouteEnum == EDIRouteEnum.WY) + { + //场站 + var ediYardList = tenantDb.Queryable() + .Where(t => t.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase)).ToList(); + + if (!string.IsNullOrWhiteSpace(order.Yard)) + { + var currYardInfo = ediYardList.FirstOrDefault(t => t.Code.Equals(order.Yard, StringComparison.OrdinalIgnoreCase)); + + if (currYardInfo == null) + return DataResult.Failed($"场站{order.Yard}的EDI代码未找到"); + + primaryModel.YARDEDICODE = currYardInfo.MapCode?.Trim(); + primaryModel.YARD = currYardInfo.MapName?.Trim(); + } + } + + //ESL、PIL、WY、YML、YT 需要付费方式映射EDI代码 + if (ediRouteEnum == EDIRouteEnum.ESL || ediRouteEnum == EDIRouteEnum.PIL || ediRouteEnum == EDIRouteEnum.WY + || ediRouteEnum == EDIRouteEnum.YML || ediRouteEnum == EDIRouteEnum.YT || ediRouteEnum == EDIRouteEnum.INTTRA) + { + //付费方式基础数据 + var baseFrtList = tenantDb.Queryable().Where(x=>x.Status == StatusEnum.Enable).ToList(); + + var baseFrtInfo = baseFrtList.FirstOrDefault(t => + t.EdiCode.Equals(order.MBLFrt, StringComparison.OrdinalIgnoreCase)); + + if (baseFrtInfo == null) + return DataResult.Failed($"付费方式{order.MBLFrt}的基础代码未找到"); + + //付费方式映射 + var ediFrtList = tenantDb.Queryable() + .Where(t => t.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase) && t.CarrierId == order.CarrierId).ToList(); + + if (!string.IsNullOrWhiteSpace(order.MBLFrt)) + { + var currFrtInfo = ediFrtList.FirstOrDefault(t => t.Code.Equals(baseFrtInfo.EdiCode, StringComparison.OrdinalIgnoreCase)); + + if (currFrtInfo == null) + return DataResult.Failed($"付费方式{order.MBLFrt}的EDI代码未找到"); + + primaryModel.BLFRTEDICODE = currFrtInfo.MapCode?.Trim(); + } + } + + if (!string.IsNullOrWhiteSpace(order.Service)) + { + //运输条款EDI + var baseServiceList = tenantDb.Queryable().Where(x => x.Status == StatusEnum.Enable).ToList(); + + var baseServiceInfo = baseServiceList.FirstOrDefault(t => + t.EdiCode.Equals(order.Service, StringComparison.OrdinalIgnoreCase)); + + if (baseServiceInfo == null) + return DataResult.Failed($"运输条款{order.Service}的基础代码未找到"); + + //运输条款映射 + var ediServiceList = tenantDb.Queryable() + .Where(t => t.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase) && t.CarrierId == order.CarrierId).ToList(); + + var currServiceInfo = ediServiceList.FirstOrDefault(t => t.Code.Equals(baseServiceInfo.EdiCode, StringComparison.OrdinalIgnoreCase)); + + if (currServiceInfo == null) + return DataResult.Failed($"运输条款{order.Service}的EDI代码未找到"); + + primaryModel.SERVICEEDICODE = currServiceInfo.MapCode?.Trim(); + } + + + if (!string.IsNullOrWhiteSpace(order.IssueType)) + { + //签单方式EDI + var baseIssueTypeList = tenantDb.Queryable().Where(x => x.Status == StatusEnum.Enable).ToList(); + + var baseIssueTypeInfo = baseIssueTypeList.FirstOrDefault(t => + t.EnName.Equals(order.IssueType, StringComparison.OrdinalIgnoreCase)); + + if (baseIssueTypeInfo == null) + return DataResult.Failed($"签单方式{order.IssueType}的基础代码未找到"); + + //签单方式映射 + var ediIssueTypeList = tenantDb.Queryable() + .Where(t => t.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase) + ).ToList(); + + var currIssueTypeInfo = ediIssueTypeList.FirstOrDefault(t => t.CarrierId == order.CarrierId + && t.Code.Equals(baseIssueTypeInfo.EdiCode, StringComparison.OrdinalIgnoreCase)); + + if (currIssueTypeInfo == null) + { + //如果没有对应的船司记录,则取默认的第一个代码对应的记录 + currIssueTypeInfo = ediIssueTypeList.FirstOrDefault(t => t.Code.Equals(baseIssueTypeInfo.EdiCode, StringComparison.OrdinalIgnoreCase)); + } + + if (currIssueTypeInfo == null) + return DataResult.Failed($"签单方式{order.IssueType}的EDI代码未找到"); + + primaryModel.ISSUETYPE = currIssueTypeInfo.MapCode?.Trim().ToUpper(); + } + + primaryModel.CARRIEREDICODE = ediSOSICfg.MapCode; + + //这里除了TSL,订舱编号默认都对应到业务编号(订舱保存时自动生成) + if (ediRouteEnum == EDIRouteEnum.TSL) + { + if (string.IsNullOrWhiteSpace(order.CustomerNo)) + return DataResult.Failed($"船公司是{order.CustomerNo} 订舱编号不能为空"); + primaryModel.ORDERNO = order.CustomerNo; + } + else + { + primaryModel.ORDERNO = order.BookingNo; + } + + //2023-06-15 按照沟通要求,如果主提单号为空,并且订舱编号不为空,可以去订舱编号填入主提单号 + if (string.IsNullOrWhiteSpace(primaryModel.MBLNO)) + { + if (!string.IsNullOrWhiteSpace(order.CustomerNo)) + { + _logger.Info("批次={no} 主题单号为空 MBLNO={mblno} 取订舱编号补到主提单号 custno={custno}", batchNo, primaryModel.MBLNO, order.CustomerNo); + + if (req.SendType.Equals("B", StringComparison.OrdinalIgnoreCase)) + { + primaryModel.MBLNO = order.CustomerNo; + } + } + } + + var curBasePkgs = basePkgsList.FirstOrDefault(p => p.PackageName.Equals(order.KindPkgs, StringComparison.OrdinalIgnoreCase)); + + if (curBasePkgs == null) + return DataResult.Failed($"包装{order.KindPkgs}的基础数据代码未找到"); + + var ediPkgs = ediPkgsList.FirstOrDefault(x => x.Code.Equals(curBasePkgs.EdiCode, StringComparison.OrdinalIgnoreCase)); + + if (ediPkgs == null || string.IsNullOrWhiteSpace(ediPkgs.MapCode)) + return DataResult.Failed($"包装{order.KindPkgs}的EDI代码未找到"); + + primaryModel.KINDPKGS_EDI_CODE = ediPkgs.MapCode?.Trim(); + + //这里是订舱时,默认取SOREMARK赋值到EDIREMARK + if (req.SendType == "B") + { + primaryModel.EDIREMARK = order.EdiRemark; + } + + primaryModel.S0CC0C = ediExtModel.S0CC0C; + primaryModel.ACIHBL = ediExtModel.ACIHBL; + + primaryModel.MasterBOLIndicator = ediExtModel.MasterBolIndicator; + primaryModel.ConsigneeEdiCode = ediExtModel.ConsigneeEdiCode; + primaryModel.ShipperEdiCode = ediExtModel.ShipperEdiCode; + primaryModel.SalesRepCode = ediExtModel.SalerCode; + primaryModel.CNPTNo = ediExtModel.CNPTNo; + + //优先取订舱的EDI附属信息,为空取FTP配置 + primaryModel.EDIATTN = ediExtModel.EDIAttn; + + if (string.IsNullOrWhiteSpace(primaryModel.EDIATTN)) + { + primaryModel.EDIATTN = ftpSet.SendAttn; + } + primaryModel.EDIATTNTEL = ediExtModel.EDIAttnTel; + + if (string.IsNullOrWhiteSpace(primaryModel.EDIATTNTEL)) + { + primaryModel.EDIATTNTEL = ftpSet.SendTel; + } + + primaryModel.EDIATTNEMAIL = ediExtModel.EDIAttnMail; + + if (string.IsNullOrWhiteSpace(primaryModel.EDIATTNEMAIL)) + { + primaryModel.EDIATTNEMAIL = ftpSet.SendEmail; + } + + primaryModel.AMSCONSIGNEE = ediExtModel.AMSConsignee; + primaryModel.AMSNOTIFYPARTY = ediExtModel.AMSNotifyParty; + + primaryModel.OpEName = ediExtModel.OpEName; + primaryModel.OpTel = ediExtModel.OpTel; + primaryModel.OpEmail = ediExtModel.OpEmail; + + /* + 2023-04-14 确认东胜流程后,这里调整商品名称取值,不从EDI扩展信息取,改为从主表的GOODS_CODE取代码经过品名翻译英文填写 + 注:仅限PIL + //primaryModel.GOODSNAME = ediExtModel.GoodsName; + */ + + if (ediRouteEnum == EDIRouteEnum.PIL) + { + if (req.SendType.Equals("E", StringComparison.OrdinalIgnoreCase)) + { + if (!string.IsNullOrWhiteSpace(order.GoodsName)) + { + if (order.GoodsId == 0) + { + return DataResult.Failed($"海运出口商品Id未回填!"); + } + var pGoods = tenantDb.Queryable().First(x => x.Id == order.GoodsId); + if (pGoods == null) + { + _logger.Info("批次={no} 提取商品名称失败 GoodsName={code}", batchNo, order.GoodsName); + + return DataResult.Failed($"商品Id对应商品名称未找到!"); + } + else + { + primaryModel.GOODSNAME = pGoods.EnName; + + _logger.Info("批次={no} 提取商品名称失败 name={name}", batchNo, pGoods.GoodName); + } + } + } + else if (req.SendType.Equals("B", StringComparison.OrdinalIgnoreCase)) + { + //2023-05-17 PIL订舱时不提供GOODSNAME,这里默认赋空 + primaryModel.GOODSNAME = string.Empty; + } + } + + primaryModel.cKHI = ediExtModel.CKHI; + primaryModel.cNCM = ediExtModel.CNCM; + primaryModel.wNCM = ediExtModel.WNCM; + primaryModel.ORDERREMARK = ediExtModel.OrderRemark; + + //2023-05-10 (PIL)订舱的预抵日期不提供输入框,按照和川操作要求取开船日期填写到预抵日期 + if (string.IsNullOrWhiteSpace(primaryModel.ETA) && !string.IsNullOrWhiteSpace(primaryModel.ETD) && + ediRouteEnum == EDIRouteEnum.PIL) + { + primaryModel.ETA = primaryModel.ETD; + } + + primaryModel.KINGTAREWEIGHT = ediExtModel.KingTareweight.HasValue ? ediExtModel.KingTareweight.Value : 0; + + _logger.Info("批次={no} 提取箱完成 数量={total}", batchNo, contaList.Count); + + primaryModel.CTNLIST = new List(); + + + //集装箱 + foreach (var conta in contaList) + { + //TODO 转换 + var contaModel = conta.Adapt(); + + //EDI箱型 + var currConta = ediCtnList.FirstOrDefault(x => x.Code.Equals(conta.CtnCode, StringComparison.OrdinalIgnoreCase)); + + if (currConta == null) + return DataResult.Failed($"箱型{conta.CtnCode}的EDI代码未找到!"); + + contaModel.CTNALLCODE = currConta.MapCode; + + if (string.IsNullOrWhiteSpace(conta.KindPkgs)) + return DataResult.Failed($"集装箱包装不能为空!"); + + var curContaBasePkgs = basePkgsList.FirstOrDefault(p => p.PackageName.Equals(conta.KindPkgs, StringComparison.OrdinalIgnoreCase)); + + if (curContaBasePkgs == null) + return DataResult.Failed($"包装{conta.KindPkgs}的基础数据代码未找到!"); + + //EDI包装 + var ediContaPkgs = ediPkgsList.FirstOrDefault(x => x.Code.Equals(curContaBasePkgs.EdiCode, StringComparison.OrdinalIgnoreCase)); + + if (currConta == null) + return DataResult.Failed($"包装{conta.KindPkgs}的EDI代码未找到!"); + + contaModel.KINDPKGS_EDI_CODE = ediContaPkgs.MapCode?.Trim(); + + primaryModel.CTNLIST.Add(contaModel); + } + + //多品名 + var cargoList = tenantDb.Queryable().Where(t => contaList.Select(a => a.Id).ToArray().Contains(t.CtnId)).ToList(); + + _logger.Info("批次={no} 提取多品名完成 数量={total}", batchNo, cargoList.Count); + + primaryModel.CTNGOODSLIST = new List(); + + foreach (var cargo in cargoList) + { + //TODO 映射 + var cargoModel = cargo.Adapt(); + + cargoModel.CNTRNO = contaList.FirstOrDefault(a => a.Id == cargo.CtnId).CntrNo; + + if (string.IsNullOrWhiteSpace(cargo.KindPkgs)) + return DataResult.Failed($"多品名包装不能为空!"); + + var curCargoBasePkgs = basePkgsList.FirstOrDefault(p => p.PackageName.Equals(cargo.KindPkgs, StringComparison.OrdinalIgnoreCase)); + + if (curCargoBasePkgs == null) + return DataResult.Failed($"包装{cargo.KindPkgs}的基础数据代码未找到"); + + var ediDetailPkgs = ediPkgsList.FirstOrDefault(x => x.Code.Equals(curCargoBasePkgs.EdiCode, StringComparison.OrdinalIgnoreCase)); + + if (ediDetailPkgs == null) + return DataResult.Failed($"货明细的包装{cargo.KindPkgs}的EDI代码未找到"); + + cargoModel.KINDPKGS_EDI_CODE = ediDetailPkgs.MapCode?.Trim(); + + primaryModel.CTNGOODSLIST.Add(cargoModel); + } + + ediModel.BSLIST.Add(primaryModel); + + var result = await InnerSendBookingOrClosingEDI(req, ediModel, ediRouteEnum); + + _logger.Info("批次={no} 生成EDI文件完成 结果={result}", batchNo, JsonConvert.SerializeObject(result)); + + if (!result.Succeeded) + { + return DataResult.Failed(result.Message); + } + + if (order.Carrier.Equals("ONE", StringComparison.OrdinalIgnoreCase)) + { + //await PrintCarrierOneSOFileAsync(order); + } + + if (req.Send) + { + /* + 2023-05-24 这里新增TSL的判断,如果是走TSL则默认走吴广的外挂,需要提供个人账户 + */ + + string currFilePath = string.Empty; + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + currFilePath = System.Text.RegularExpressions.Regex.Match(result.ExtraData1.ToString(), relativePath.Replace("/", "\\/") + ".*").Value; + } + else + { + currFilePath = System.Text.RegularExpressions.Regex.Match(result.ExtraData1.ToString(), relativePath.Replace("\\", "\\\\") + ".*").Value; + } + + string fileTypeCode = "edi"; + string fileTypeName = "EDI文件"; + + if (req.SendType.Equals("E", StringComparison.OrdinalIgnoreCase)) + { + fileTypeCode = "esi"; + fileTypeName = "ESI文件"; + } + + //这里先写入附件表 + await SaveEDIFile(req.Id, currFilePath, new System.IO.FileInfo(currFilePath).Name, fileTypeCode, fileTypeName); + + _logger.Info("批次={no} 直接发送FTP 文件访问地址={filepath}", batchNo, result.ExtraData1.ToString()); + + DateTime bDate = DateTime.Now; + + //是否发送邮件,EDI这里主要分2种通道发送 默认是FTP,如果配置里指定了接收接收邮箱,就需要推送邮件 + bool isSendEmail = false; + + //上传FTP + EdiDataResult sendStatus = null; + + //TSL单独走接口 + if (ediRouteEnum == EDIRouteEnum.TSL) + { + sendStatus = await InnerSendBookingOrClosingEDIToPOST(result.ExtraData1.ToString(), postSpiderUrl, userWebAccountConfig); + } + else + { + //是订舱并且FTP配置了订舱接收邮箱则触发邮箱发送 + if (ftpSet.SendType.Equals("SO", StringComparison.OrdinalIgnoreCase) + && req.SendType.Equals("B", StringComparison.OrdinalIgnoreCase) + && !string.IsNullOrWhiteSpace(ftpSet.ReceiveEmail)) + { + isSendEmail = true; + } + else if (ftpSet.SendType.Equals("SI", StringComparison.OrdinalIgnoreCase) + && req.SendType.Equals("E", StringComparison.OrdinalIgnoreCase) + && !string.IsNullOrWhiteSpace(ftpSet.ReceiveEmail)) + { + isSendEmail = true; + } + else if (string.IsNullOrWhiteSpace(ftpSet.SendType) + && !string.IsNullOrWhiteSpace(ftpSet.ReceiveEmail)) + { + isSendEmail = true; + } + + if (isSendEmail) + { + //推送订舱邮件 + sendStatus = await InnerSendBookingOrClosingEDIToEmail(order, result.ExtraData1.ToString(), req.SendType, result.ExtraData2.ToString(), ftpSet); + } + else + { + sendStatus = await InnerSendBookingOrClosingEDIToFTP(result.ExtraData1.ToString(), ftpSet); + } + } + + DateTime eDate = DateTime.Now; + TimeSpan ts = eDate.Subtract(bDate); + var timeDiff = ts.TotalMilliseconds; + + _logger.Info("批次={no} 发送完成,耗时:{timeDiff}ms. 结果{msg}", batchNo, timeDiff, sendStatus.Succeeded ? "成功" : "失败"); + + //var logId = await _bookinglog.InsertReturnSnowflakeIdAsync(new BookingLog + //{ + // Type = "Trace", + // BookingId = model.Id, + // TenantId = Convert.ToInt64(UserManager.TENANT_ID), + // CreatedTime = DateTime.Now, + // CreatedUserId = UserManager.UserId, + // CreatedUserName = UserManager.Name + //}); + + string sendTypeName = "FTP"; + + if (isSendEmail) + { + sendTypeName = "邮件"; + } + else if (ediRouteEnum == EDIRouteEnum.TSL) + { + sendTypeName = "POST"; + } + + //await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail + //{ + // PId = logId, + // Field = String.Empty, + // OldValue = String.Empty, + // NewValue = $"发送 {order.CARRIERID} EDI 类型={model.sendType} 通过{sendTypeName} {(sendStatus.succ ? "成功" : "失败")}", + //}); + + if (!sendStatus.Succeeded) + { + return DataResult.Failed($"发送失败,原因:{sendStatus.Message}"); + } + + //截单 + if (req.SendType.Equals("E", StringComparison.OrdinalIgnoreCase)) + { + //如果是截单需最后推送货物状态 + await seaComService.SetGoodsStatus("JD", req.Id); + //await SendBookingOrder(new long[] { req.Id }); + } + + } + + return await Task.FromResult(DataResult.Success(result.ExtraData1.ToString())); + //return result.ExtraData1.ToString(); + } + + + private async Task SaveEDIFile(long boookId, string FilePath, string fileName, string fileTypeCode = "edi", string fileTypeName = "EDI文件") + { + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); + /* + 直接将附件信息写入附件表 + */ + //EDI文件 + var bookFile = new OpFile + { + FileName = fileName, + FilePath = FilePath, + TypeCode = fileTypeCode, + TypeName = fileTypeName, + LinkId = boookId, + }; + + await tenantDb.Insertable(bookFile).ExecuteCommandAsync(); + } + + #region 检查订舱、截单EDI订单信息 + /// + /// 检查订舱、截单EDI订单信息 + /// + /// + /// + private DataResult CheckBookingOrClosingEDI(SeaExport order, List ctnList) + { + if (string.IsNullOrWhiteSpace(order.Carrier)) + return DataResult.Failed("船公司必须填写!"); + + //if (string.IsNullOrWhiteSpace(order.OPID)) + // throw Oops.Bah("未填写操作人"); + + if (string.IsNullOrWhiteSpace(order.KindPkgs)) + return DataResult.Failed("包装种类未填写!"); + + //增加箱包装和主信息的包装是否一致校验 + if (ctnList.Any(a => a.KindPkgs != order.KindPkgs)) + { + return DataResult.Failed("集装箱包装和订舱包装不一致,请修改!"); + } + + //如果合同协议号不为空需要判断是否字符前、后有空格,不允许字符前后有空格,需要提示修改 + if (!string.IsNullOrWhiteSpace(order.ContractNo)) + { + if (order.ContractNo.StartsWith(" ")) + return DataResult.Failed("运费协议号前含有空格,请修改!"); + + if (order.ContractNo.EndsWith(" ")) + return DataResult.Failed("运费协议号后含有空格,请修改!"); + } + + //增加件、重、尺比对 + if (ctnList != null && ctnList.Count > 0) + { + if (ctnList.Sum(a => a.PKGS.HasValue ? a.PKGS.Value : 0) != (order.PKGS.HasValue ? order.PKGS.Value : 0)) + { + return DataResult.Failed("集装箱件数合计和订舱件数不一致,请修改!"); + } + + if (ctnList.Sum(a => a.KGS.HasValue ? a.KGS.Value : 0) != (order.KGS.HasValue ? order.KGS.Value : 0)) + { + return DataResult.Failed("集装箱重量合计和订舱重量不一致,请修改!"); + } + + if (ctnList.Sum(a => a.CBM.HasValue ? a.CBM.Value : 0) != (order.CBM.HasValue ? order.CBM.Value : 0)) + { + return DataResult.Failed("集装箱尺码合计和订舱尺码不一致,请修改!"); + } + } + return DataResult.Success("验证成功!"); + } + #endregion + #region 上传邮件 + /// + /// 上传邮件 + /// + /// 订舱详情 + /// 文件路径 + /// 请求类型 + /// EDI配置 + /// 返回回执 + private async Task InnerSendBookingOrClosingEDIToEmail(SeaExport bookingOrder, string filePath, + string sendType, string emailTopic, CodeEdiSet ediCfg) + { + var result = new EdiDataResult { Succeeded = true }; + + var emailUrl = db.Queryable().Filter(null, true).Where(x => x.Code == "email_api_url" && x.TenantId == 1288018625843826688).First().Value; + //var emailUrl = _cache.GetAllDictData().GetAwaiter().GetResult() + // .FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "email_api_url")?.Value; + + if (emailUrl == null) + { + result.Succeeded = false; + result.Message = "系统参数配置email_api_url 请联系管理员"; + return await Task.FromResult(result); + } + + List emailList = new List(); + + EmailApiDto emailApiDto = new EmailApiDto + { + SendTo = ediCfg.ReceiveEmail, + Title = emailTopic, + Attaches = new List(), + Body = emailTopic, + }; + + System.IO.FileStream file = new System.IO.FileStream(filePath, FileMode.Open, FileAccess.Read); + int SplitSize = 5242880;//5M分片长度 + int index = 1; //序号 第几片 + long StartPosition = 5242880 * (index - 1); + long lastLens = file.Length - StartPosition;//真不知道怎么起命了,就这样吧 + if (lastLens < 5242880) + { + SplitSize = (int)lastLens; + } + byte[] heByte = new byte[SplitSize]; + file.Seek(StartPosition, SeekOrigin.Begin); + //第一个参数是 起始位置 + file.Read(heByte, 0, SplitSize); + //第三个参数是 读取长度(剩余长度) + file.Close(); + + string base64Str = Convert.ToBase64String(heByte); + + emailApiDto.Attaches.Add(new AttachesInfo + { + AttachName = Path.GetFileName(filePath), + AttachContent = base64Str + }); + + emailList.Add(emailApiDto); + + string strJoin = System.IO.File.ReadAllText(filePath); + + DateTime bDate = DateTime.Now; + + string res = null; + + try + { + res = RequestHelper.Post(JsonConvert.SerializeObject(emailList), emailUrl); + //res = await emailUrl.SetBody(emailList, "application/json").PostAsync(); + } + catch (Exception ex) + { + _logger.Info($"发送邮件异常:{ex.Message}"); + } + + DateTime eDate = DateTime.Now; + TimeSpan ts = eDate.Subtract(bDate); + var timeDiff = ts.TotalMilliseconds; + + _logger.Info($"邮件上传完成 上传文件大小:{heByte.Length} 用时:{timeDiff}ms.,{strJoin}"); + + _logger.Info($"发送邮件返回:{JsonConvert.SerializeObject(res)}"); + + //if (res != null && res.StatusCode == System.Net.HttpStatusCode.OK) + //{ + // var userResult = await res.Content.ReadAsStringAsync(); + + // var respObj = JsonConvert.DeserializeAnonymousType(userResult, new + // { + // Success = false, + // Message = string.Empty, + // Code = -9999, + // }); + + // result.Succeeded = respObj.Success; + // result.Message = respObj.Message; + //} + if (res != null) + { + var respObj = JsonConvert.DeserializeAnonymousType(res, new + { + Success = false, + Message = string.Empty, + Code = -9999, + }); + + result.Succeeded = respObj.Success; + result.Message = respObj.Message; + } + return await Task.FromResult(result); + //return result; + } + #endregion + #region 上传FTP + /// + /// 上传FTP + /// + /// EDI文件路径 + /// FTP配置 + /// 返回回执 + private async Task InnerSendBookingOrClosingEDIToFTP(string filePath, CodeEdiSet ediCfg) + { + EdiDataResult result = new EdiDataResult { Succeeded = true }; + + CancellationTokenSource cts = new CancellationTokenSource(); + + string host = string.Empty; + string port = string.Empty; + + if (ediCfg.ServerIp.IndexOf(":") >= 0) + { + host = ediCfg.ServerIp.Split(new char[] { ':' }).FirstOrDefault().Trim(); + port = ediCfg.ServerIp.Split(new char[] { ':' }).Last()?.Trim(); + } + + NameValueCollection par = new NameValueCollection(); + par.Add("host", host); + //这里如果配置没有指定端口号默认是21端口 + par.Add("port", string.IsNullOrWhiteSpace(port) ? "21" : port); + par.Add("username", ediCfg.UserName); + par.Add("pwd", ediCfg.Password); + par.Add("path", ediCfg.FolderName); + + var ftpSpiderUrl = db.Queryable().Filter(null, true).Where(x => x.Code == "booking_edi_ftp_server" && x.TenantId == 1288018625843826688).First().Value; + if (ftpSpiderUrl == null) + return await Task.FromResult(EdiDataResult.Failed("系统未配置booking_edi_ftp_server 请联系管理员!")); + + //var fileInfo = new FileInfo(filePath); + + _logger.Info($"准备请求发送ftp:{ftpSpiderUrl} ,参数:{JsonConvert.SerializeObject(par)},文件:{filePath}"); + + + System.IO.FileStream file = new System.IO.FileStream(filePath, FileMode.Open, FileAccess.Read); + int SplitSize = 5242880;//5M分片长度 + int index = 1; //序号 第几片 + long StartPosition = 5242880 * (index - 1); + long lastLens = file.Length - StartPosition;//真不知道怎么起命了,就这样吧 + if (lastLens < 5242880) + { + SplitSize = (int)lastLens; + } + byte[] heByte = new byte[SplitSize]; + file.Seek(StartPosition, SeekOrigin.Begin); + //第一个参数是 起始位置 + file.Read(heByte, 0, SplitSize); + //第三个参数是 读取长度(剩余长度) + file.Close(); + + string strJoin = System.IO.File.ReadAllText(filePath); + + DateTime bDate = DateTime.Now; + + _logger.Info("FTP 开始上传"); + + var res = FTPHelper.TransmitFtpFile(ftpSpiderUrl, par, new + { + file = "file", + fileName = Path.GetFileName(filePath), + fileBytes = heByte + }); + + DateTime eDate = DateTime.Now; + TimeSpan ts = eDate.Subtract(bDate); + var timeDiff = ts.TotalMilliseconds; + + _logger.Info($"FTP 上传完成 上传文件大小:{heByte.Length} 用时:{timeDiff}ms.,{strJoin}"); + + _logger.Info($"发送ftp返回:{res}"); + + var jobjRetn = JObject.Parse(res); + + if (jobjRetn.GetStringValue("status") != "1") + { + result.Succeeded = false; + result.Message = jobjRetn.GetStringValue("message"); + } + return await Task.FromResult(result); + //return result; + } + #endregion + /// + /// EDI发送POST请求 + /// + /// 文件路径 + /// 请求URL + /// 配置账户 + /// 返回回执 + private async Task InnerSendBookingOrClosingEDIToPOST(string filePath, string url, CodeThirdParty accountConfig) + { + + CancellationTokenSource cts = new CancellationTokenSource(); + var userKey = db.Queryable().Filter(null, true).Where(x => x.Code == "BCOrDraftUserKey" && x.TenantId == 1288018625843826688).First(); + var userPwd = db.Queryable().Filter(null, true).Where(x => x.Code == "BCOrDraftUserSecret" && x.TenantId == 1288018625843826688).First(); + if (userKey.IsNull()) + { + return await Task.FromResult(EdiDataResult.Failed("请配置相关账号!")); + } + if (userPwd.IsNull()) + { + return await Task.FromResult(EdiDataResult.Failed("请配置相关密钥!")); + } + NameValueCollection par = new NameValueCollection(); + //par.Add("user_key", App.Configuration["BCOrDraftUserKey"]); + //par.Add("user_secret", App.Configuration["BCOrDraftUserSecret"]); + par.Add("user_key", userKey.Value); + par.Add("user_secret", userPwd.Value); + par.Add("web_user", accountConfig.AppKey?.Trim()); + par.Add("web_psw", accountConfig.AppSecret?.Trim()); + + _logger.Info($"准备请求发送POST:{url} ,参数:{JsonConvert.SerializeObject(par)},文件:{filePath}"); + + System.IO.FileStream file = new System.IO.FileStream(filePath, FileMode.Open, FileAccess.Read); + int SplitSize = 5242880;//5M分片长度 + int index = 1; //序号 第几片 + long StartPosition = 5242880 * (index - 1); + long lastLens = file.Length - StartPosition;//真不知道怎么起命了,就这样吧 + if (lastLens < 5242880) + { + SplitSize = (int)lastLens; + } + byte[] heByte = new byte[SplitSize]; + file.Seek(StartPosition, SeekOrigin.Begin); + //第一个参数是 起始位置 + file.Read(heByte, 0, SplitSize); + //第三个参数是 读取长度(剩余长度) + file.Close(); + + string strJoin = System.IO.File.ReadAllText(filePath); + + DateTime bDate = DateTime.Now; + + _logger.Info("POST 开始上传"); + + var res = FTPHelper.TransmitFtpFile(url, par, new + { + file = "file", + fileName = Path.GetFileName(filePath), + fileBytes = heByte + }); + + DateTime eDate = DateTime.Now; + TimeSpan ts = eDate.Subtract(bDate); + var timeDiff = ts.TotalMilliseconds; + + _logger.Info($"请求POST 上传完成 上传文件大小:{heByte.Length} 用时:{timeDiff}ms.,{strJoin}"); + + _logger.Info($"发送POST返回:{res}"); + + var jobjRetn = JObject.Parse(res); + + if (jobjRetn.GetStringValue("code") != "200") + { + return await Task.FromResult(EdiDataResult.Failed(jobjRetn.GetStringValue("msg"))); + } + else + { + return await Task.FromResult(EdiDataResult.Failed("请求成功!")); + } + } + + #region 触发订舱 + /// + /// 触发订舱 + /// + /// + /// + /// + /// + private async Task InnerSendBookingOrClosingEDI(BookingOrClosingEDIOrderReq req, EDIBaseModel ediModel, EDIRouteEnum ediRouteEnum) + { + var result = new EdiDataResult(); + var tenantDb = saasService.GetBizDbScopeById(user.TenantId); + try + { + if (ediRouteEnum == EDIRouteEnum.PIL) + { + #region PIL + string strCheck = PILEdiHelper.IsCreatePILEDI(ediModel); + + _logger.Info($"调用SO(SI),校验:{strCheck},数据对象:{JsonConvert.SerializeObject(ediModel)}"); + + if (!string.IsNullOrWhiteSpace(strCheck)) + { + if (Regex.IsMatch(strCheck, "\\")) + { + strCheck = Regex.Replace(strCheck, "\\", "\n"); + } + throw new Exception($"发送{EDIRouteEnum.PIL.ToString()}校验失败,{strCheck}"); + } + + + var currRlt = PILEdiHelper.CreateEdiPIL(ediModel); + #endregion + result.Succeeded = currRlt.Succeeded; + result.ExtraData1 = currRlt.Succeeded ? currRlt.ExtraData1.ToString() : ""; + result.ExtraData2 = currRlt.Succeeded ? currRlt.ExtraData2.ToString() : ""; + //return await Task.FromResult(currRlt); + } + else if (ediRouteEnum == EDIRouteEnum.TSL) + { + #region TSL + string strCheck = TSLEdiHelper.IsCreateTSL(ediModel); + + _logger.Info($"调用SO(SI),校验:{strCheck},数据对象:{JsonConvert.SerializeObject(ediModel)}"); + + if (!string.IsNullOrWhiteSpace(strCheck)) + { + if (Regex.IsMatch(strCheck, "\\")) + { + strCheck = Regex.Replace(strCheck, "\\", "\n"); + } + throw new Exception($"发送{EDIRouteEnum.TSL.ToString()}校验失败,{strCheck}"); + } + + var currRlt = new EdiDataResult(); + + if (req.SendType == "B") + { + currRlt = TSLEdiHelper.CreateEdiTSL(ediModel); + } + else if (req.SendType == "E") + { + currRlt = TSLEdiHelper.CreateEdiTSLSI(ediModel); + } + #endregion + result.Succeeded = currRlt.Succeeded; + result.ExtraData1 = currRlt.Succeeded ? currRlt.ExtraData1.ToString() : ""; + + } + else if (ediRouteEnum == EDIRouteEnum.WY) + { + #region WY + string strCheck = WYEdiHelper.IsCreateWYEDI(ediModel); + + _logger.Info($"调用SO(SI),校验:{strCheck},数据对象:{JsonConvert.SerializeObject(ediModel)}"); + + if (!string.IsNullOrWhiteSpace(strCheck)) + { + if (Regex.IsMatch(strCheck, "\\")) + { + strCheck = Regex.Replace(strCheck, "\\", "\n"); + } + throw new Exception($"发送{EDIRouteEnum.WY.ToString()}校验失败,{strCheck}"); + } + + var currRlt = WYEdiHelper.CreateEdiWY(ediModel); + #endregion + result.Succeeded = currRlt.Succeeded; + result.ExtraData1 = currRlt.Succeeded ? currRlt.ExtraData1.ToString() : ""; + } + else if (ediRouteEnum == EDIRouteEnum.YML) + { + #region YML + string strCheck = YMLEdiHelper.IsCreateYMLEDI(ediModel); + + _logger.Info($"调用SO(SI),校验:{strCheck},数据对象:{JsonConvert.SerializeObject(ediModel)}"); + + if (!string.IsNullOrWhiteSpace(strCheck)) + { + if (Regex.IsMatch(strCheck, "\\")) + { + strCheck = Regex.Replace(strCheck, "\\", "\n"); + } + throw new Exception($"发送{EDIRouteEnum.YML.ToString()}校验失败,{strCheck}"); + } + + var currRlt = new EdiDataResult(); + if (req.SendType == "B") + { + currRlt= YMLEdiHelper.CreateEdiYML(ediModel); + } + else if (req.SendType == "E") + { + currRlt = YMLEdiHelper.CreateEdiYMLSI(ediModel); + } + #endregion + result.Succeeded = currRlt.Succeeded; + result.ExtraData1 = currRlt.Succeeded ? currRlt.ExtraData1.ToString() : ""; + } + else if (ediRouteEnum == EDIRouteEnum.YT) + { + #region YT + string strCheck = YTEdiHelper.IsCreateYTEDI(ediModel); + + _logger.Info($"调用SO(SI),校验:{strCheck},数据对象:{JsonConvert.SerializeObject(ediModel)}"); + + if (!string.IsNullOrWhiteSpace(strCheck)) + { + if (Regex.IsMatch(strCheck, "\\")) + { + strCheck = Regex.Replace(strCheck, "\\", "\n"); + } + throw new Exception($"发送{EDIRouteEnum.YT.ToString()}校验失败,{strCheck}"); + } + + + var currRlt = YTEdiHelper.CreateEdiYT(ediModel); + #endregion + result.Succeeded = currRlt.Succeeded; + result.ExtraData1 = currRlt.Succeeded ? currRlt.ExtraData1.ToString() : ""; + } + else if (ediRouteEnum == EDIRouteEnum.ESL) + { + #region ESL + string strCheck = ESLEdiHelper.IsCreateESLEDI(ediModel); + + _logger.Info($"调用SO(SI),校验:{strCheck},数据对象:{JsonConvert.SerializeObject(ediModel)}"); + + if (!string.IsNullOrWhiteSpace(strCheck)) + { + if (Regex.IsMatch(strCheck, "\\")) + { + strCheck = Regex.Replace(strCheck, "\\", "\n"); + } + throw new Exception($"发送{EDIRouteEnum.ESL.ToString()}校验失败,{strCheck}"); + } + + + var currRlt = ESLEdiHelper.CreateEdiESL(ediModel); + #endregion + result.Succeeded = currRlt.Succeeded; + result.ExtraData1 = currRlt.Succeeded ? currRlt.ExtraData1.ToString() : ""; + } + else if (ediRouteEnum == EDIRouteEnum.MELL) + { + #region MELL + string strCheck = MellEdiHelper.IsCreatePILMELL(ediModel); + + _logger.Info($"调用SO(SI),校验:{strCheck},数据对象:{JsonConvert.SerializeObject(ediModel)}"); + + if (!string.IsNullOrWhiteSpace(strCheck)) + { + if (Regex.IsMatch(strCheck, "\\")) + { + strCheck = Regex.Replace(strCheck, "\\", "\n"); + } + throw new Exception($"发送{EDIRouteEnum.MELL.ToString()}校验失败,{strCheck}"); + } + + + var currRlt = MellEdiHelper.CreateEdiPILMELL(ediModel); + + #endregion + result.Succeeded = currRlt.Succeeded; + result.ExtraData1 = currRlt.Succeeded ? currRlt.ExtraData1.ToString() : ""; + result.ExtraData2 = currRlt.Succeeded ? currRlt.ExtraData2.ToString() : ""; + } + else if (ediRouteEnum == EDIRouteEnum.INTTRA) + { + //这里INTTRA单独取了船公司 + var ediSOSICfg = tenantDb.Queryable().First(t => t.Module.Equals(CONST_MAPPING_MODULE_INTTRA, StringComparison.OrdinalIgnoreCase) + && t.Code == ediModel.BSLIST.FirstOrDefault().CARRIERID); + + if (ediSOSICfg == null || string.IsNullOrWhiteSpace(ediSOSICfg.MapCode)) + throw new Exception($"CARRIERID={ediModel.BSLIST.FirstOrDefault().CARRIERID} INTTRA EDI订舱和截单 的船公司EDI代码未找到"); + + ediModel.BSLIST.FirstOrDefault().CARRIEREDICODE = ediSOSICfg.MapCode; + + #region INTTRA + string strCheck = InttraEdiHelper.IsCreateINTTR(ediModel); + + _logger.Info($"调用SO(SI),校验:{strCheck},数据对象:{JsonConvert.SerializeObject(ediModel)}"); + + if (!string.IsNullOrWhiteSpace(strCheck)) + { + if (Regex.IsMatch(strCheck, "\\")) + { + strCheck = Regex.Replace(strCheck, "\\", "\n"); + } + throw new Exception($"发送{EDIRouteEnum.INTTRA.ToString()}校验失败,{strCheck}"); + } + var currRlt = new EdiDataResult(); + if (req.SendType == "B") + { + currRlt = InttraEdiHelper.CreateEdiINTTR(ediModel); + } + else if (req.SendType == "E") + { + currRlt = InttraEdiHelper.CreateEdiINTTRSI(ediModel); + } + + #endregion + result.Succeeded = currRlt.Succeeded; + result.ExtraData1 = currRlt.Succeeded ? currRlt.ExtraData1.ToString() : ""; + } + } + catch (Exception ex) + { + result.Succeeded = false; + result.Message = ex.Message; + } + return result; + } + #endregion } \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.MainApi/Controllers/MappingFrtController.cs b/ds-wms-service/DS.WMS.MainApi/Controllers/MappingFrtController.cs new file mode 100644 index 00000000..20f77c9d --- /dev/null +++ b/ds-wms-service/DS.WMS.MainApi/Controllers/MappingFrtController.cs @@ -0,0 +1,92 @@ +using DS.Module.Core; +using DS.Module.Core.Data; +using DS.WMS.Core.Code.Dtos; +using DS.WMS.Core.Code.Interface; +using DS.WMS.Core.Map.Dtos; +using DS.WMS.Core.Map.Interface; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; + +namespace DS.WMS.MainApi.Controllers +{ + /// + /// 付款方式映射信息 模块 + /// + public class MappingFrtController : ApiController + { + private readonly IMappingFrtService _invokeService; + + /// + /// 构造函数 + /// + /// + public MappingFrtController(IMappingFrtService invokeService) + { + _invokeService = invokeService; + } + /// + /// 列表 + /// + /// + /// + [HttpPost] + [Route("GetMappingFrtList")] + public DataResult> GetMappingFrtList([FromBody] PageRequest request) + { + var res = _invokeService.GetListByPage(request); + return res; + } + + /// + /// 编辑 + /// + /// + /// + [HttpPost] + [Route("EditMappingFrt")] + public DataResult EditMappingFrt([FromBody] MappingFrtReq req) + { + var res = _invokeService.EditMappingFrt(req); + return res; + } + + /// + /// 详情 + /// + /// Id + /// + [HttpGet] + [Route("GetMappingFrtInfo")] + public DataResult GetMappingFrtInfo([FromQuery] string id) + { + var res = _invokeService.GetMappingFrtInfo(id); + return res; + } + + /// + /// 删除 + /// + /// Id + /// + [HttpPost] + [Route("DelMappingFrt")] + public DataResult DelMappingFrt([FromBody] IdModel req) + { + var res = _invokeService.DelMappingFrt(req); + return res; + } + + /// + ///批量删除 + /// + /// Id + /// + [HttpPost] + [Route("BatchDelMappingFrt")] + public DataResult BatchDelMappingFrt([FromBody] IdModel req) + { + var res = _invokeService.BatchDelMappingFrt(req); + return res; + } + } +} diff --git a/ds-wms-service/DS.WMS.OpApi/Controllers/SeaExportController.cs b/ds-wms-service/DS.WMS.OpApi/Controllers/SeaExportController.cs index bacc676c..cd50ec5d 100644 --- a/ds-wms-service/DS.WMS.OpApi/Controllers/SeaExportController.cs +++ b/ds-wms-service/DS.WMS.OpApi/Controllers/SeaExportController.cs @@ -221,4 +221,16 @@ public class SeaExportController : ApiController { return _invokeService.CheckAndInitVOLTAEdi(req); } + + /// + /// 发送订舱、截单EDI + /// + /// 订舱、截单EDI请求 + /// 返回回执 + [HttpPost] + [Route("SendBookingOrClosingEDI")] + public async Task> SendBookingOrClosingEDI([FromBody] BookingOrClosingEDIOrderReq req) + { + return await _invokeService.SendBookingOrClosingEDI(req); + } } \ No newline at end of file diff --git a/ds-wms-service/DS.WMS.OpApi/Logs/internal-nlog.txt b/ds-wms-service/DS.WMS.OpApi/Logs/internal-nlog.txt index 5376dc10..71b9c4de 100644 --- a/ds-wms-service/DS.WMS.OpApi/Logs/internal-nlog.txt +++ b/ds-wms-service/DS.WMS.OpApi/Logs/internal-nlog.txt @@ -68,3 +68,31 @@ 2024-05-15 13:39:29.2837 Info Validating config: TargetNames=console, ownFile-web, ConfigItems=54, FilePath=D:\Code\DS\ds8-solution\ds-wms-service\DS.WMS.OpApi\bin\Debug\net8.0\nlog.config 2024-05-15 13:39:29.3013 Warn Unused target detected. Add a rule for this target to the configuration. TargetName: allfile 2024-05-15 13:39:29.3325 Info Configuration initialized. +2024-05-20 15:30:34.8145 Info Registered target NLog.Targets.FileTarget(Name=allfile) +2024-05-20 15:30:34.8416 Info Registered target NLog.Targets.FileTarget(Name=ownFile-web) +2024-05-20 15:30:34.8416 Info Registered target NLog.Targets.ColoredConsoleTarget(Name=console) +2024-05-20 15:30:34.8774 Info NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 5.2.8.2366. Product version: 5.2.8+f586f1341c46fa38aaaff4c641e7f0fa7e813943. GlobalAssemblyCache: False +2024-05-20 15:30:34.9017 Info Validating config: TargetNames=console, ownFile-web, ConfigItems=54, FilePath=D:\Code\DS\ds8-solution\ds-wms-service\DS.WMS.OpApi\bin\Debug\net8.0\nlog.config +2024-05-20 15:30:34.9119 Warn Unused target detected. Add a rule for this target to the configuration. TargetName: allfile +2024-05-20 15:30:34.9317 Info Configuration initialized. +2024-05-20 15:33:36.4001 Info Registered target NLog.Targets.FileTarget(Name=allfile) +2024-05-20 15:33:36.4444 Info Registered target NLog.Targets.FileTarget(Name=ownFile-web) +2024-05-20 15:33:36.4618 Info Registered target NLog.Targets.ColoredConsoleTarget(Name=console) +2024-05-20 15:33:36.5052 Info NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 5.2.8.2366. Product version: 5.2.8+f586f1341c46fa38aaaff4c641e7f0fa7e813943. GlobalAssemblyCache: False +2024-05-20 15:33:36.5294 Info Validating config: TargetNames=console, ownFile-web, ConfigItems=54, FilePath=D:\Code\DS\ds8-solution\ds-wms-service\DS.WMS.OpApi\bin\Debug\net8.0\nlog.config +2024-05-20 15:33:36.5294 Warn Unused target detected. Add a rule for this target to the configuration. TargetName: allfile +2024-05-20 15:33:36.5646 Info Configuration initialized. +2024-05-20 16:18:02.4625 Info Registered target NLog.Targets.FileTarget(Name=allfile) +2024-05-20 16:18:02.5478 Info Registered target NLog.Targets.FileTarget(Name=ownFile-web) +2024-05-20 16:18:02.5914 Info Registered target NLog.Targets.ColoredConsoleTarget(Name=console) +2024-05-20 16:18:02.7548 Info NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 5.2.8.2366. Product version: 5.2.8+f586f1341c46fa38aaaff4c641e7f0fa7e813943. GlobalAssemblyCache: False +2024-05-20 16:18:02.8232 Info Validating config: TargetNames=console, ownFile-web, ConfigItems=54, FilePath=D:\Code\DS\ds8-solution\ds-wms-service\DS.WMS.OpApi\bin\Debug\net8.0\nlog.config +2024-05-20 16:18:02.8417 Warn Unused target detected. Add a rule for this target to the configuration. TargetName: allfile +2024-05-20 16:18:02.8731 Info Configuration initialized. +2024-05-20 16:20:35.0280 Info Registered target NLog.Targets.FileTarget(Name=allfile) +2024-05-20 16:20:35.0938 Info Registered target NLog.Targets.FileTarget(Name=ownFile-web) +2024-05-20 16:20:35.1176 Info Registered target NLog.Targets.ColoredConsoleTarget(Name=console) +2024-05-20 16:20:35.1620 Info NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c. File version: 5.2.8.2366. Product version: 5.2.8+f586f1341c46fa38aaaff4c641e7f0fa7e813943. GlobalAssemblyCache: False +2024-05-20 16:20:35.1879 Info Validating config: TargetNames=console, ownFile-web, ConfigItems=54, FilePath=D:\Code\DS\ds8-solution\ds-wms-service\DS.WMS.OpApi\bin\Debug\net8.0\nlog.config +2024-05-20 16:20:35.2035 Warn Unused target detected. Add a rule for this target to the configuration. TargetName: allfile +2024-05-20 16:20:35.2289 Info Configuration initialized. diff --git a/ds-wms-service/DS.WMS.OpApi/appsettings.json b/ds-wms-service/DS.WMS.OpApi/appsettings.json index 64504991..c612db62 100644 --- a/ds-wms-service/DS.WMS.OpApi/appsettings.json +++ b/ds-wms-service/DS.WMS.OpApi/appsettings.json @@ -49,6 +49,16 @@ "RelativePath": "LinkAttach", "FileType": [ ".xls", ".xlsx", ".pdf", ".txt", ".pms" ] }, + //打印模板 + "PrintTemplate": { + "BasePath": "", //基础路径,不配置则使用当前系统目录 + "RelativePath": "Upload/PrintTemplate", + "FileType": [ ".frx", ".xls" ] + }, + "TempFile": { + "Path": "TempFiles", + "RemainHours": 2 + }, "PrintService": { "IP": "60.209.125.238", "Port": "3009", diff --git a/ds-wms-service/DS.WMS.Test/SaasTest.cs b/ds-wms-service/DS.WMS.Test/SaasTest.cs index f05572c1..9dcb6354 100644 --- a/ds-wms-service/DS.WMS.Test/SaasTest.cs +++ b/ds-wms-service/DS.WMS.Test/SaasTest.cs @@ -32,11 +32,15 @@ public class SaasTest [Fact] public void SaasTest1() { + //Type[] types = Assembly + // .LoadFrom("DS.WMS.Core.dll")//如果 .dll报错,可以换成 xxx.exe 有些生成的是exe + // .GetTypes().Where(it => it.FullName.Contains("DS.WMS.Core.Code.Entity.") || it.FullName.Contains("DS.WMS.Core.Info.Entity.") || it.FullName.Contains("DS.WMS.Core.Op.Entity.") + // || it.FullName.Contains("DS.WMS.Core.Fee.Entity.") || it.FullName.Contains("DS.WMS.Core.Map.Entity."))//命名空间过滤,当然你也可以写其他条件过滤 + // .ToArray(); Type[] types = Assembly - .LoadFrom("DS.WMS.Core.dll")//如果 .dll报错,可以换成 xxx.exe 有些生成的是exe - .GetTypes().Where(it => it.FullName.Contains("DS.WMS.Core.Code.Entity.") || it.FullName.Contains("DS.WMS.Core.Info.Entity.") || it.FullName.Contains("DS.WMS.Core.Op.Entity.") - || it.FullName.Contains("DS.WMS.Core.Fee.Entity.") || it.FullName.Contains("DS.WMS.Core.Map.Entity."))//命名空间过滤,当然你也可以写其他条件过滤 - .ToArray(); + .LoadFrom("DS.WMS.Core.dll")//如果 .dll报错,可以换成 xxx.exe 有些生成的是exe + .GetTypes().Where(it => it.FullName.Contains("DS.WMS.Core.Op.Entity."))//命名空间过滤,当然你也可以写其他条件过滤 + .ToArray(); var tenantDb = saasService.GetBizDbScopeById("1750335377144680448"); // var temp = tenantDb.CodeFirst.GetDifferenceTables(types); // var diffString= tenantDb.CodeFirst.GetDifferenceTables(types).ToDiffString();