From 48f00ebb059660cc11c12c74b1bd59490bc040b9 Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Mon, 8 Apr 2024 22:41:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=B0=E5=A2=9EINTTRA?= =?UTF-8?q?=E8=AE=A2=E8=88=B1=EF=BC=88MSK=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Myshipping.Application/EDI/InttraEdiHelper.cs | 147 ++- .../Entities/TaskBCEntity.cs | 37 + .../Entities/TaskFileEntities.cs | 47 + ServiceProjectSyncWin/Program.cs | 901 +++++++++++++++++- ServiceProjectSyncWin/appsettings.json | 2 +- 5 files changed, 1089 insertions(+), 45 deletions(-) create mode 100644 ServiceProjectSyncWin/Entities/TaskFileEntities.cs diff --git a/Myshipping.Application/EDI/InttraEdiHelper.cs b/Myshipping.Application/EDI/InttraEdiHelper.cs index de24c7ab..18f0e6dc 100644 --- a/Myshipping.Application/EDI/InttraEdiHelper.cs +++ b/Myshipping.Application/EDI/InttraEdiHelper.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text; +using System.Threading; using System.Threading.Tasks; namespace Myshipping.Application.EDI @@ -31,6 +32,7 @@ namespace Myshipping.Application.EDI 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) @@ -186,6 +188,9 @@ namespace Myshipping.Application.EDI /// public static string formatEdiStr(string fileType, string str) { + if (str == null) + str = string.Empty; + if (fileType == "txt") { return str.Replace("?", "??").Replace(":", "?:").Replace("+", "?+").Replace("'", "?'"); @@ -340,7 +345,7 @@ namespace Myshipping.Application.EDI if (headData.CARGOID == "D" || headData.SERVICE == "DOOR-DOOR" || headData.SERVICE == "DOOR-CY" || headData.SERVICE == "CY-DOOR") { - if (headData.CARRIER != "YML") + if (headData.CARRIERID != "YML") { if (string.IsNullOrEmpty(headData.EDIATTN)) { error = error + "
EDI信息联系人不能为空"; } @@ -771,7 +776,7 @@ namespace Myshipping.Application.EDI r.WriteLine("UNH+" + bill.ORDERNO + "+IFTMBF:D:99B:UN'"); icount = icount + 2; - if (bill.CARRIEREDICODE == "HLCU") + if (bill.CARRIERID == "HLCU") { if (InttrEdi.filerole == "9") r.WriteLine("BGM+335+" + bill.ORDERNO + "SO+9'"); @@ -795,15 +800,15 @@ namespace Myshipping.Application.EDI r.WriteLine("DTM+137:" + DateTime.Now.ToString("yyyyMMddHHmm") + ":203'"); icount = icount + 2; - if (bill.SERVICE.ToUpper() == "DOOR-DOOR") + if (bill.SERVICEEDICODE.ToUpper() == "DOOR-DOOR") { r.WriteLine("TSR+27+2'"); } - else if (bill.SERVICE.ToUpper() == "DOOR-CY") + else if (bill.SERVICEEDICODE.ToUpper() == "DOOR-CY") { r.WriteLine("TSR+28+2'"); } - else if (bill.SERVICE.ToUpper() == "CY-DOOR") + else if (bill.SERVICEEDICODE.ToUpper() == "CY-DOOR") { r.WriteLine("TSR+29+2'"); } @@ -818,7 +823,7 @@ namespace Myshipping.Application.EDI 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 + " " @@ -834,17 +839,34 @@ namespace Myshipping.Application.EDI 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(Convert.ToDecimal(bill.KGS), 3) + ":KGM'");//按照四舍五入的国际标准 + r.WriteLine("CNT+7:" + bill.KGS.ToString("0.###") + ":KGM'");//按照四舍五入的国际标准 r.WriteLine("CNT+11:" + bill.PKGS.ToString() + "'"); - r.WriteLine("CNT+15:" + Math.Round(Convert.ToDecimal(bill.CBM), 3) + ":MTQ'"); + r.WriteLine("CNT+15:" + bill.CBM.ToString("0.###") + ":MTQ'"); icount = icount + 3; - - if (bill.CARRIEREDICODE == "UASC") + //2024-04-08 这里看2.0文档显示不使用 CNT + if (bill.CARRIERID == "UASC") { if (bill.CTNLIST.Count > 0) { @@ -861,7 +883,7 @@ namespace Myshipping.Application.EDI if (bill.BLFRT == "FREIGHT COLLECT") { - if (bill.PAYABLEAT != "") + if (!string.IsNullOrWhiteSpace(bill.PAYABLEAT)) { r.WriteLine("LOC+57+" + bill.PREPARDATID + "::6:" + bill.PAYABLEAT + "'"); icount = icount + 1; @@ -924,17 +946,25 @@ namespace Myshipping.Application.EDI 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 - r.WriteLine("LOC+88+" + bill.PORTLOADID + ":139:6:" + bill.PORTLOAD + "'"); + + 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 (bill.DESTINATION != "") + if (!string.IsNullOrWhiteSpace(bill.DESTINATIONID)) { r.WriteLine("LOC+7+" + bill.DESTINATIONID + ":139:6:" + bill.DESTINATION + "'"); icount = icount + 1; } - var Shipping = ""; - var DescriptionShipper = ""; + + //处理发货人 + Shipping = string.Empty; + var DescriptionShipper = string.Empty; + Shipping = formatEdiStr("txt", bill.SHIPPER); List ShippingList = formatlengthStr(Shipping, 35); @@ -957,6 +987,7 @@ namespace Myshipping.Application.EDI } else Shipping = Shipping + ":" + ShippingList[i]; + if (bill.CARRIEREDICODE == "HLCU") { Shipping = Shipping + "-"; @@ -1008,6 +1039,7 @@ namespace Myshipping.Application.EDI } else Shipping = Shipping + ":" + ShippingList[i]; + if (bill.CARRIEREDICODE == "HLCU") { Shipping = Shipping + "--"; @@ -1061,7 +1093,6 @@ namespace Myshipping.Application.EDI if (ShippingList.Count != 0 && Shipping.Length > 0) { - for (var i = 0; i < ShippingList.Count; i++) { if (i == 0) Shipping = "NAD+NI+++" + ShippingList[0] + "+"; @@ -1109,10 +1140,10 @@ namespace Myshipping.Application.EDI } else if (bill.BYCOUNTRY == "BRAZIL") { - if (bill.NOTIFYPARTYCOUNTRY != "") + if (!string.IsNullOrWhiteSpace(bill.NOTIFYPARTYCOUNTRY)) Shipping = Shipping + "++++" + bill.NOTIFYPARTYCOUNTRY; r.WriteLine(Shipping + "'"); - if (bill.NOTIFYPARTYTAXNO != "") + if (!string.IsNullOrWhiteSpace(bill.NOTIFYPARTYTAXNO)) { r.WriteLine("RFF+GN:" + bill.NOTIFYPARTYTAXNO + "'"); icount = icount + 1; @@ -1125,7 +1156,7 @@ namespace Myshipping.Application.EDI r.WriteLine("NAD+CA+" + bill.CARRIEREDICODE + ":160:86++" + GetCarrierName(bill.CARRIEREDICODE) + "'"); icount = icount + 1; - if (bill.SERVICE == "DOOR-DOOR") + if (bill.SERVICEEDICODE == "DOOR-DOOR") { Shipping = formatEdiStr("txt", bill.SHIPPER); ShippingList = formatlengthStr(Shipping, 35); @@ -1208,7 +1239,7 @@ namespace Myshipping.Application.EDI } - if (bill.WEITUO != "") + 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)) + "'"); @@ -1258,7 +1289,7 @@ namespace Myshipping.Application.EDI icount = icount + 8; - if (bill.HSCODE != "") + if (!string.IsNullOrWhiteSpace(bill.HSCODE)) { r.WriteLine("PIA+5+" + bill.HSCODE + ":HS'"); icount = icount + 1; @@ -1278,27 +1309,27 @@ namespace Myshipping.Application.EDI } } - if (DescriptionShipper != "") + if (!string.IsNullOrWhiteSpace(DescriptionShipper)) { r.WriteLine("FTX+AAA+++" + DescriptionShipper + "'"); icount = icount + 1; } - if (DescriptionConsignee != "") + if (!string.IsNullOrWhiteSpace(DescriptionConsignee)) { r.WriteLine("FTX+AAA+++" + DescriptionConsignee + "'"); icount = icount + 1; } - if (DescriptionNotifyparty != "") + 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) + "'"); + r.WriteLine("MEA+AAE+WT+KGM:" + bill.KGS.ToString("0.###") + "'"); + r.WriteLine("MEA+AAE+AAW+MTQ:" + bill.CBM.ToString("0.###") + "'"); icount = icount + 2; Shipping = formatEdiStr("txt", bill.MARKS); @@ -1316,6 +1347,7 @@ namespace Myshipping.Application.EDI } } + //危险品 if (bill.CARGOID == "D") { r.WriteLine("DGS+IMD+" + bill.DCLASS + "+" + bill.DUNNO + "'"); @@ -1336,6 +1368,7 @@ namespace Myshipping.Application.EDI isfind = true; } }); + if (!isfind) { var ctnnum = new MsOpSeaeCtnEDIBaseModel(); @@ -1350,16 +1383,41 @@ namespace Myshipping.Application.EDI 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 != "") + if (!string.IsNullOrWhiteSpace(bill.REEFERF)) r.WriteLine("MEA+AAE+AAS+CBM:" + bill.REEFERF + "'"); - if (bill.HUMIDITY != "") + if (!string.IsNullOrWhiteSpace(bill.HUMIDITY)) r.WriteLine("MEA+AAE+AAO+HMD:" + bill.HUMIDITY + "'"); - r.WriteLine("TMP+2+" + bill.TEMPSET + ":CEL'"); + + //温度这里如果是带小数点的值,会导致错误,这里需要慎重 + 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; @@ -1405,15 +1463,15 @@ namespace Myshipping.Application.EDI - if (bill.SERVICE.ToUpper() == "DOOR-DOOR") + if (bill.SERVICEEDICODE.ToUpper() == "DOOR-DOOR") { r.WriteLine("TSR+27+2'"); } - else if (bill.SERVICE.ToUpper() == "DOOR-CY") + else if (bill.SERVICEEDICODE.ToUpper() == "DOOR-CY") { r.WriteLine("TSR+28+2'"); } - else if (bill.SERVICE.ToUpper() == "CY-DOOR") + else if (bill.SERVICEEDICODE.ToUpper() == "CY-DOOR") { r.WriteLine("TSR+29+2'"); } @@ -1423,11 +1481,11 @@ namespace Myshipping.Application.EDI } var str_pay = ""; - if (bill.BLFRT.IndexOf("PREPAID") >= 0) + if (bill.BLFRTEDICODE.IndexOf("PREPAID") >= 0) str_pay = bill.PREPARDAT; - if (bill.BLFRT.IndexOf("COLLECT") >= 0) + if (bill.BLFRTEDICODE.IndexOf("COLLECT") >= 0) str_pay = bill.PAYABLEAT; - r.WriteLine("FTX+AAI+++" + bill.BLFRT + " Payable at " + str_pay + " " + bill.SERVICE + " " + r.WriteLine("FTX+AAI+++" + bill.BLFRTEDICODE + " Payable at " + str_pay + " " + bill.SERVICEEDICODE + " " + bill.PKGS.ToString() + bill.KINDPKGS + "'"); icount = icount + 5; @@ -1593,8 +1651,6 @@ namespace Myshipping.Application.EDI } - - var DescriptionShipper = ""; Shipping = formatEdiStr("txt", bill.SHIPPER); @@ -1715,6 +1771,7 @@ namespace Myshipping.Application.EDI else r.WriteLine(Shipping + "'"); icount = icount + 1; + /*2024-04-08 JHQ 看文档2.0应该没有这段代码了 if (!string.IsNullOrEmpty(bill.WEITUO)) { if (bill.WEITUO.Length > 35) @@ -1739,10 +1796,11 @@ namespace Myshipping.Application.EDI r.WriteLine("NAD+FW+" + InttrEdi.SENDCODE + ":160:86++" + InttrEdi.SENDNAME + "'"); } } + icount++; + */ - icount++; Shipping = formatEdiStr("txt", bill.NOTIFYPARTY); @@ -1813,6 +1871,7 @@ namespace Myshipping.Application.EDI 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) @@ -1826,10 +1885,11 @@ namespace Myshipping.Application.EDI } 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) + "'"); @@ -1853,7 +1913,8 @@ namespace Myshipping.Application.EDI } } - 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无正本") + 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; @@ -2016,9 +2077,9 @@ namespace Myshipping.Application.EDI } //MEA+AAE+WT+KGM:3000' //MEA+AAE+AAW+MTQ:110.11' - r.WriteLine("MEA+AAE+WT+KGM:" + Math.Round(Convert.ToDecimal(ctngood.KGS), 3) + "'"); + r.WriteLine("MEA+AAE+WT+KGM:" + ctngood.KGS.ToString("0.###") + "'"); icount++; - r.WriteLine("MEA+AAE+AAW+MTQ:" + Math.Round(Convert.ToDecimal(ctngood.CBM), 3) + "'"); + r.WriteLine("MEA+AAE+AAW+MTQ:" + ctngood.CBM.ToString("0.###") + "'"); icount++; //PCI++MARKS AND NUMBERS:FOR MATERIAL 1: OUR PONUMBER: PO_123456' //if (isbill != 1) diff --git a/ServiceProjectSyncWin/Entities/TaskBCEntity.cs b/ServiceProjectSyncWin/Entities/TaskBCEntity.cs index f5f9d635..24473c07 100644 --- a/ServiceProjectSyncWin/Entities/TaskBCEntity.cs +++ b/ServiceProjectSyncWin/Entities/TaskBCEntity.cs @@ -26,12 +26,49 @@ namespace ServiceProjectSyncWin.Entities public Nullable SI_CUT_DATE { get; set; } + /// + /// 截关时间 + /// + public Nullable CLOSING_DATE { get; set; } + public Nullable ETD { get; set; } public Nullable ETA { get; set; } public Nullable VGM_CUTOFF_TIME { get; set; } + /// + /// 截单时间 + /// + public Nullable CUT_SINGLE_TIME { get; set; } + + /// + /// 舱单截止时间 + /// + public Nullable MANIFEST_CUT_DATE { get; set; } + + /// + /// MDGF提交截止时间 + /// + public Nullable MDGF_CUT_DATE { get; set; } + + /// + /// 截港时间 + /// + public Nullable CY_CUTOFF_TIME { get; set; } + public string TASK_ID { get; set; } + + public bool IsDeleted { get; set; } + + /// + /// 租户id + /// + public long? TenantId { get; set; } + + /// + /// 创建时间 + /// + public DateTime CreatedTime { get; set; } } } diff --git a/ServiceProjectSyncWin/Entities/TaskFileEntities.cs b/ServiceProjectSyncWin/Entities/TaskFileEntities.cs new file mode 100644 index 00000000..5d28ef66 --- /dev/null +++ b/ServiceProjectSyncWin/Entities/TaskFileEntities.cs @@ -0,0 +1,47 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ServiceProjectSyncWin.Entities +{ + [Tenant("db_master")] + [SugarTable("task_file")] + public class TaskFileEntities + { + /// + /// 主键 + /// + [SugarColumn(ColumnDescription = "主键", IsPrimaryKey = true)] + public string PK_ID { get; set; } + + /// + /// 任务主键(父主键) + /// + public string TASK_PKID { get; set; } + /// + /// 文件路径 + /// + public string FILE_PATH { get; set; } + /// + /// 文件类型 + /// + public string FILE_TYPE { get; set; } + /// + /// 文件名 + /// + public string FILE_NAME { get; set; } + + /// + /// 附件类型代码 BC-Booking Confirmation + /// + public string FILE_CATEGORY { get; set; } + + /// + /// 附件类型名称 BC-Booking Confirmation + /// + public string FILE_CATEGORY_NAME { get; set; } + } +} diff --git a/ServiceProjectSyncWin/Program.cs b/ServiceProjectSyncWin/Program.cs index 058d3f80..95ef2ff2 100644 --- a/ServiceProjectSyncWin/Program.cs +++ b/ServiceProjectSyncWin/Program.cs @@ -5,13 +5,18 @@ using Furion.DistributedIDGenerator; using Furion.FriendlyException; using Furion.JsonSerialization; using Furion.RemoteRequest.Extensions; +using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using ServiceProjectSyncWin; using ServiceProjectSyncWin.Entities; using SqlSugar; +using System.Collections.Specialized; +using System.ComponentModel.DataAnnotations; +using System.Net.Http.Headers; using System.Text; using System.Text.RegularExpressions; +using System.Web; using static System.Net.Mime.MediaTypeNames; Serve.RunGeneric(additional: services => @@ -426,9 +431,903 @@ public class SyncHisRecord: ISyncHisRecord,ITransient 1、更新任务台 2、更新舱位的截止时间记录 */ - //_db.Queryable().Max(a => a.ORG_STATUS_ID); + var taskList = _db.Queryable().Where(a => (a.BUSI_TYPE == "BookingConfirmation" || a.BUSI_TYPE == "BookingAmendment") && a.TASK_ID == "08dc56ae-e1bd-4650-818e-85447143df67") + .OrderBy(t=>t.CreatedTime) + .ToList(); + + string batchNo = Guid.NewGuid().ToString(); + + _logger.LogInformation($"批次={batchNo} 提取待处理任务 num={taskList.Count}"); + + string bcReadUrl = "http://localhost:5110/api/TaskBCParser/ExcuteBCFileRead"; + string amendReadUrl = "http://localhost:5110/api/TaskBookingAmendmentParser/ExcuteBookingAmendmentRead"; + + //foreach (var task in taskList) + for(int i=0;i().Where(a => a.TASK_PKID == task.TASK_ID && a.FILE_CATEGORY == "BC").First(); + + if (fileInfo != null) + { + _logger.LogInformation($"批次={batchNo} 提取待处理任务 MBLNO={task.MBL_NO} 取到文件"); + + string bcFileFullPath = $"D:\\djy\\backend\\wwwroot\\{fileInfo.FILE_PATH}"; + + var bcFileName = Path.GetFileName(bcFileFullPath); + + TaskBCInfoReadDto BCReadInfo = GetBCReaderInfo(bcFileFullPath, bcFileName, task.TenantId.Value, task.TASK_ID, bcReadUrl).GetAwaiter().GetResult(); + + _logger.LogInformation($"批次={batchNo} 提取待处理任务 MBLNO={task.MBL_NO} 识别完文件 BCReadInfo={JSON.Serialize(BCReadInfo)}"); + + if (BCReadInfo != null) + { + //SI_CUT_DATE + if (BCReadInfo.SICutDate.HasValue) + { + if (task.SI_CUT_DATE.HasValue && task.SI_CUT_DATE.Value == BCReadInfo.SICutDate.Value) + { + + } + task.SI_CUT_DATE = BCReadInfo.SICutDate.Value; + } + else + { + task.SI_CUT_DATE = null; + } + //VGM_CUTOFF_TIME + if (BCReadInfo.VGMCutoffTime.HasValue) + { + task.VGM_CUTOFF_TIME = BCReadInfo.VGMCutoffTime.Value; + } + else + { + task.VGM_CUTOFF_TIME = null; + } + //MANIFEST_CUT_DATE + if (BCReadInfo.ManifestCutDate.HasValue) + { + task.MANIFEST_CUT_DATE = BCReadInfo.ManifestCutDate.Value; + } + else + { + task.MANIFEST_CUT_DATE = null; + } + //CY_CUTOFF_TIME + if (BCReadInfo.CYCutoffTime.HasValue) + { + task.CY_CUTOFF_TIME = BCReadInfo.CYCutoffTime.Value; + } + else + { + task.CY_CUTOFF_TIME = null; + } + //MDGF_CUT_DATE + if (BCReadInfo.MDGFCutDate.HasValue) + { + task.MDGF_CUT_DATE = BCReadInfo.MDGFCutDate.Value; + } + else + { + task.MDGF_CUT_DATE = null; + } + //CLOSING_DATE + if (BCReadInfo.ClosingDate.HasValue) + { + task.CLOSING_DATE = BCReadInfo.ClosingDate.Value; + } + else + { + task.CLOSING_DATE = null; + } + + _db.Updateable(task).UpdateColumns(it => new + { + it.SI_CUT_DATE, + it.VGM_CUTOFF_TIME, + it.MANIFEST_CUT_DATE, + it.CY_CUTOFF_TIME, + it.MDGF_CUT_DATE, + it.CLOSING_DATE + }).ExecuteCommand(); + } + + } + } + else if (task.BUSI_TYPE == "BookingAmendment") + { + var fileInfo = _db.Queryable().Where(a => a.TASK_PKID == task.TASK_ID && a.FILE_CATEGORY == "BC_MODIFY").First(); + + if (fileInfo != null) + { + string bcFileFullPath = $"D:\\djy\\backend\\wwwroot\\{fileInfo.FILE_PATH}"; + + var bcFileName = Path.GetFileName(bcFileFullPath); + + TaskBCInfoReadDto BCReadInfo = GetBCReaderInfo(bcFileFullPath, bcFileName, task.TenantId.Value, task.TASK_ID, amendReadUrl).GetAwaiter().GetResult(); + + if (BCReadInfo != null) + { + //SI_CUT_DATE + if (BCReadInfo.SICutDate.HasValue) + { + task.SI_CUT_DATE = BCReadInfo.SICutDate.Value; + } + else + { + task.SI_CUT_DATE = null; + } + //VGM_CUTOFF_TIME + if (BCReadInfo.VGMCutoffTime.HasValue) + { + task.VGM_CUTOFF_TIME = BCReadInfo.VGMCutoffTime.Value; + } + else + { + task.VGM_CUTOFF_TIME = null; + } + //MANIFEST_CUT_DATE + if (BCReadInfo.ManifestCutDate.HasValue) + { + task.MANIFEST_CUT_DATE = BCReadInfo.ManifestCutDate.Value; + } + else + { + task.MANIFEST_CUT_DATE = null; + } + //CY_CUTOFF_TIME + if (BCReadInfo.CYCutoffTime.HasValue) + { + task.CY_CUTOFF_TIME = BCReadInfo.CYCutoffTime.Value; + } + else + { + task.CY_CUTOFF_TIME = null; + } + //MDGF_CUT_DATE + if (BCReadInfo.MDGFCutDate.HasValue) + { + task.MDGF_CUT_DATE = BCReadInfo.MDGFCutDate.Value; + } + else + { + task.MDGF_CUT_DATE = null; + } + //CLOSING_DATE + if (BCReadInfo.ClosingDate.HasValue) + { + task.CLOSING_DATE = BCReadInfo.ClosingDate.Value; + } + else + { + task.CLOSING_DATE = null; + } + + _db.Updateable(task).UpdateColumns(it => new + { + it.SI_CUT_DATE, + it.VGM_CUTOFF_TIME, + it.MANIFEST_CUT_DATE, + it.CY_CUTOFF_TIME, + it.MDGF_CUT_DATE, + it.CLOSING_DATE + }).ExecuteCommand(); + } + } + } + + + Thread.Sleep(500); + } + + } + + #region 读BC详情详情 + /// + /// 读BC详情详情 + /// + /// 文件完整路径 + /// 文件名称 + /// 所属租户 + /// 任务ID + /// 请求URL + /// + private async Task GetBCReaderInfo(string attachFullName, string fileName, long tenantId, string taskPKId, string url) + { + TaskBCInfoReadDto taskBCInfoReadDto = null; + + try + { + DateTime nowDate = DateTime.Now; + + EmailBCReadMessageInfo messageInfo = new EmailBCReadMessageInfo + { + Head = new TaskMessageHead + { + GID = IDGen.NextID().ToString(), + MessageType = "BOOKING_AMENDMENT", + SenderId = "DJY", + SenderName = "新大简云", + ReceiverId = "RulesEngine", + ReceiverName = "大简云规则引擎", + Version = "1.0", + RequestDate = nowDate.ToString("yyyy-MM-dd HH:mm:ss"), + RequestAction = "ReadFile", + }, + Main = new EmailBCReadMessageMainInfo + { + TenantId = tenantId > 0 ? tenantId.ToString() : "" + } + }; + + NameValueCollection par = new NameValueCollection(); + par.Add("jsonData", JSON.Serialize(messageInfo)); + + //解析BookingAmendment + var compareRlt = await ExcuteReadFile(par, url, new + { + file = "file", + fileName = fileName, + fileBytes = File.ReadAllBytes(attachFullName) + }); + + _logger.LogInformation($"读取BC附件详情 taskPKId={taskPKId},compareRlt={JSON.Serialize(compareRlt)}"); + + if (compareRlt.succ) + { + taskBCInfoReadDto = JSON.Deserialize(JSON.Serialize(compareRlt.extra)); + } + } + catch (Exception ex) + { + _logger.LogError($"读取BC附件详情异常,原因:{ex.Message}"); + } + + return taskBCInfoReadDto; + } + #endregion + + #region 请求BookingAmendment解析 + /// + /// 请求BookingAmendment解析 + /// + /// 请求参数 + /// 请求url + /// 文件 + /// 请求类型 + /// 返回回执 + [NonAction] + private async Task ExcuteReadFile(NameValueCollection nameValueCollection, string url, dynamic fileInfo, + string contentType = "application/json") + { + ParserReaderExcuteResultDto model = null; + var result = string.Empty; + + using (var httpClient = new HttpClient()) + { + try + { + using (var reduceAttach = new MultipartFormDataContent()) + { + string[] allKeys = nameValueCollection.AllKeys; + foreach (string key in allKeys) + { + var dataContent = new ByteArrayContent(Encoding.UTF8.GetBytes(nameValueCollection[key])); + + dataContent.Headers.ContentDisposition = new ContentDispositionHeaderValue($"form-data") + { + Name = key + }; + + reduceAttach.Add(dataContent); + } + + #region 文件参数 + if (fileInfo != null) + { + var Content = new ByteArrayContent(fileInfo.fileBytes); + + //Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data") + //{ + // Name = fileInfo.file.ToString(), + // FileName = fileInfo.fileName.ToString(), + + //}; + + Content.Headers.Add("Content-Type", contentType); + + reduceAttach.Add(Content, fileInfo.file.ToString(), HttpUtility.UrlEncode(fileInfo.fileName.ToString())); + } + #endregion + + //httpClient.DefaultRequestHeaders.Add("USER_KEY", App.Configuration["ApiUserKey"]); + //httpClient.DefaultRequestHeaders.Add("USER_SECRET", App.Configuration["ApiUserSecret"]); + //请求 + var response = httpClient.PostAsync(url, reduceAttach).Result; + result = response.Content.ReadAsStringAsync().Result; + + model = JSON.Deserialize(result); + } + } + catch (Exception ex) + { + _logger.LogInformation("请求读取BC附件详情读取详情异常,原因:{error}", ex.Message); + + throw Oops.Oh($"请求读取BC附件详情读取详情异常,原因:{ex.Message}"); + + } + + } + return model; + } + #endregion + + public class EmailBCReadMessageInfo + { + /// + /// 表头 + /// + public TaskMessageHead Head { get; set; } + + /// + /// 表体 + /// + public EmailBCReadMessageMainInfo Main { get; set; } + } + + public class EmailBCReadMessageMainInfo + { + /// + /// 所属租户ID + /// + public string TenantId { get; set; } + } + + public class TaskMessageHead : WebAPIHeadBase + { } + public class WebAPIHeadBase + { + /// + /// 报文惟一主键 + /// + /// 08dab66c-96a1-4f90-8606-2626e06202ad + [Required(ErrorMessage = "必填")] + public string GID { get; set; } + + /// + /// 报文类型 BUSI_RULE-业务规则校验 + /// + /// BUSI_RULE + [Required(ErrorMessage = "必填")] + public string MessageType { get; set; } + + /// + /// 发送方代码 + /// + /// CUSTOMER1 + [Required(ErrorMessage = "必填")] + public string SenderId { get; set; } + + /// + /// 发送方名称 + /// + /// 企业A + [Required(ErrorMessage = "必填")] + public string SenderName { get; set; } + + /// + /// 接收方代码 + /// + /// RulesEngine + [Required(ErrorMessage = "必填")] + public string ReceiverId { get; set; } + + /// + /// 接收方名称 + /// + /// 大简云规则引擎 + [Required(ErrorMessage = "必填")] + public string ReceiverName { get; set; } + + /// + /// 请求方登录TOKEN(可以是真实的登录人TOKEN或者是服务模拟登录人TOKEN) + /// + /// eyJhbGciOiJSUzI1NiIsImtpZCI6IkQ1RTkxMDI5OUU0RURFNUZEM0EwNTJBMEFDRDUzMUQzIiwidHlwIjoiYXQrand0In0 + public string Token { get; set; } + + /// + /// 版本号 默认1.0 + /// + /// 1.0 + [Required(ErrorMessage = "必填")] + public string Version { get; set; } = "1.0"; + + /// + /// 请求时间 + /// + /// 2022-10-10 10:00:00 + public string RequestDate { get; set; } + + /// + /// 请求操作类型 + /// + /// Add + [Required(ErrorMessage = "必填")] + public string RequestAction { get; set; } = "Add"; + } +} + +public class ParserReaderExcuteResultDto +{ + /// + /// 是否成功 true=成功 false=失败 + /// + public bool succ { get; set; } = false; + + /// + /// 状态 0-成功 + /// + public int status { get; set; } = 0; + + /// + /// 返回消息 + /// + public string msg { get; set; } + + /// + /// 总记录数 + /// + public int total { get; set; } + + /// + /// 当前页列表数据 + /// + public object rows { get; set; } + + /// + /// 合计信息 + /// + public object summary { get; set; } + + /// + /// 扩展信息 + /// + public object extra { get; set; } + + /// + /// 扩展信息2 + /// + public object extra2 { get; set; } + + /// + /// 扩展信息场站统计 + /// + public object yardStatInfo { get; set; } + + /// + /// 是否异常 + /// + public bool exceptionflag { get; set; } + + /// + /// 生成HTML + /// + public string ResultHtml { get; set; } +} +/// +/// +/// +public class TaskBCInfoReadDto +{ + /// + /// 订舱单位 + /// + public string BookingParty { get; set; } + + /// + /// 发货人 + /// + public string Shipper { get; set; } + + /// + /// 收货人 + /// + public string Consignee { get; set; } + + /// + /// 通知人 + /// + public string NotifyParty { get; set; } + + /// + /// BC更新次数 + /// + public Nullable BCModifyTimes { get; set; } + + /// + /// BC更新时间 + /// + public Nullable BCModifyDate { get; set; } + + /// + /// 主单号 + /// + public string MBLNo { get; set; } + + /// + /// 船名 + /// + public string Vessel { get; set; } + + /// + /// 航次 + /// + public string VoyNo { get; set; } + + /// + /// 船公司 + /// + public string Carrier { get; set; } + + /// + /// 收货地 + /// + public string PlaceReceipt { get; set; } + + /// + /// 装货港 + /// + public string Portload { get; set; } + + /// + /// 截关时间 + /// + public Nullable ClosingDate { get; set; } + + /// + /// 截VGM时间 + /// + public Nullable VGMCutoffTime { get; set; } + + /// + /// ETA(预计到港时间) + /// + public Nullable ETA { get; set; } + + /// + /// ETD(预计离港时间) + /// + public Nullable ETD { get; set; } + + /// + /// 目的港ETA + /// + public Nullable PODETA { get; set; } + + /// + /// 截单时间 + /// + public Nullable CutSingleTime { get; set; } + + /// + /// 卸货港 + /// + public string PortDischarge { get; set; } + + /// + /// 交货地 + /// + public string PlaceDelivery { get; set; } + + /// + /// 装运方式 + /// + public string ShippingMethod { get; set; } + + /// + /// 运输条款 + /// + public string Service { get; set; } + + /// + /// 港前运输形态 + /// + public string PreTransMode { get; set; } + + /// + /// 品名 + /// + public string Description { get; set; } + + /// + /// 签单地点 + /// + public string IssuePlace { get; set; } + + /// + /// 集港码头 + /// + public string CollectionTerminal { get; set; } + + /// + /// 约号 + /// + public string ContractNo { get; set; } + + /// + /// 预付地点 + /// + public string PrepardAT { get; set; } + + /// + /// 船代 + /// + public string ShipAgent { get; set; } + + /// + /// 场站 + /// + public string Yard { get; set; } + + /// + /// 场站联系人 + /// + public string YardContactUserName { get; set; } + + /// + /// 场站联系电话 + /// + public string YardContactTel { get; set; } + + /// + /// 一代客服姓名 + /// + public string FstCustomerSerUserName { get; set; } + + /// + /// 一代客服电话 + /// + public string FstCustomerSerUserTel { get; set; } + + /// + /// 一代客服邮箱 + /// + public string FstCustomerSerUserEmail { get; set; } + + /// + /// 备注1 + /// + public string Remark1 { get; set; } + + /// + /// 截港时间 + /// + public Nullable CYCutoffTime { get; set; } + + /// + /// 状态 TEMP-暂存 SUCC-已对应 ERROR-异常 + /// + public string Status { get; set; } + + /// + /// 文件MD5 + /// + public string FileMD5 { get; set; } + + /// + /// 最后对应时间,最后关联到订舱日期 + /// + public Nullable LastToBookingDate { get; set; } + + /// + /// 来源邮箱 + /// + public string FromEmail { get; set; } + + /// + /// 接收邮箱 + /// + public string RecvEmail { get; set; } + + /// + /// 订舱ID,对应成功后,订舱ID写入 + /// + public Nullable BookingOrderId { get; set; } + + /// + /// 集装箱列表 + /// + public List CtnList { get; set; } + + /// + /// 顺序号 + /// + public int Indx { get; set; } + + /// + /// 对应订舱序号 + /// + public int BKOrderIndx { get; set; } + + /// + /// 舱位主键 + /// + public Nullable BookingSlotId { get; set; } + + /// + /// 船公司代号 + /// + public string CarrierId { get; set; } + + /// + /// 航线代码(船公司) + /// + public string LaneCode { get; set; } + + /// + /// 航线名称(船公司) + /// + public string LaneName { get; set; } + + /// + /// 承运方式 DIRECT_SHIP-直达;TRANSFER_SHIP-中转 + /// + public string CarriageType { get; set; } + + /// + /// 承运方式名称 DIRECT_SHIP-直达;TRANSFER_SHIP-中转 + /// + public string CarriageTypeName { get; set; } + + /// + /// 订舱方式 CONTRACT_ORDER-合约订舱;SPOT_ORDER-SPOT订舱 + /// + public string BookingSlotType { get; set; } + + /// + /// 订舱方式名称 CONTRACT_ORDER-合约订舱;SPOT_ORDER-SPOT订舱 + /// + public string BookingSlotTypeName { get; set; } + + /// + /// 箱型箱量 + /// + public string CtnStat { get; set; } + + /// + /// 所在周数 + /// + public string WeekAt { get; set; } + + /// + /// 箱使天数 + /// + public int DetensionFreeDays { get; set; } + + /// + /// 样单截止日期 + /// + public Nullable SICutDate { get; set; } + + + /// + /// 舱单截止时间 + /// + public Nullable ManifestCutDate { get; set; } + + /// + /// MDGF提交截止时间 + /// + public Nullable MDGFCutDate { get; set; } + + /// + /// 中转港1 + /// + public string TransferPort1 { get; set; } + + /// + /// 中转港2 + /// + public string TransferPort2 { get; set; } + + + /// + /// 二程船名 + /// + public string SecondVessel { get; set; } + + /// + /// 二程航次 + /// + public string SecondVoyno { get; set; } + + /// + /// 二程ETD + /// + public Nullable SecondETD { get; set; } + + /// + /// 二程ETA + /// + public Nullable SecondETA { get; set; } + + /// + /// 订舱确认时间 + /// + public Nullable BookingConfirmDate { get; set; } +} +/// +/// 任务BC集装箱 +/// +public class TaskBCInfoReadCtnDto +{ + /// + /// 箱型代码 + /// + public string CtnCode { get; set; } + + /// + /// 箱型 + /// + public string CtnALL { get; set; } + + /// + /// 箱量 + /// + public Nullable CTNNUM { get; set; } + + /// + /// 件数 + /// + public Nullable PKGS { get; set; } + + /// + /// 尺码 + /// + public Nullable CBM { get; set; } + + /// + /// 毛重 + /// + public Nullable KGS { get; set; } + + /// + /// 皮重 + /// + public Nullable TareWeight { get; set; } + + /// + /// 危品票标示 + /// + public string IODGT { get; set; } + + /// + /// 特殊装载需求 + /// + public string SpecialLoadingRequire { get; set; } + + /// + /// 提箱场站 + /// + public string TakeCTNYard { get; set; } + + /// + /// 提箱时间 + /// + public Nullable TakeCTNTime { get; set; } + + /// + /// 还箱场站 + /// + public string ReturnCTNYard { get; set; } } \ No newline at end of file diff --git a/ServiceProjectSyncWin/appsettings.json b/ServiceProjectSyncWin/appsettings.json index c3787421..a663635f 100644 --- a/ServiceProjectSyncWin/appsettings.json +++ b/ServiceProjectSyncWin/appsettings.json @@ -1,6 +1,6 @@ { "ConnectionStrings": { - "db_master": "Data Source=rm-m5e0s0o35bo87087b3o.mysql.rds.aliyuncs.com;Database=booking_hechuan;User ID=hechuan;Password=HcDjy@123;pooling=true;port=3306;sslmode=none;CharSet=utf8mb4;Convert Zero Datetime=True;Allow Zero Datetime=True;" + "db_master": "Data Source=rm-m5e06xxqpa68a68ry5o.mysql.rds.aliyuncs.com;Database=booking_data;User ID=rulesengine_admin;Password=Rule1qaz2wsx!QAZ;pooling=true;port=3306;sslmode=none;CharSet=utf8;" }, "ServiceStatusPushUrl": "http://47.104.85.216:12345/api/ServiceWorkFlowManage/PushStatus" } \ No newline at end of file