From c8e5caa70d4808fd71fd5247bc1525dbb64f4cde Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Wed, 30 Nov 2022 10:45:45 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9PIL=E5=8F=91=E9=80=81EDI?= =?UTF-8?q?=EF=BC=8C=E5=8E=BB=E6=8E=89=E6=94=B6=E3=80=81=E5=8F=91=E3=80=81?= =?UTF-8?q?=E9=80=9A=E7=9A=84=E7=89=B9=E6=AE=8A=E5=AD=97=E7=AC=A6=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=E3=80=82=20=E4=BF=AE=E6=94=B9=E8=B0=83=E5=8F=96?= =?UTF-8?q?=E8=A7=84=E5=88=99=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Myshipping.Application/EDI/PILEdiHelper.cs | 8 +- .../Myshipping.Application.xml | 9 +- .../BookingOrder/Dto/BookingEDIMapper.cs | 4 +- .../RulesEngine/RulesEngineClientService.cs | 211 +++++++++--------- 4 files changed, 114 insertions(+), 118 deletions(-) diff --git a/Myshipping.Application/EDI/PILEdiHelper.cs b/Myshipping.Application/EDI/PILEdiHelper.cs index 8d7db7b8..9ece3325 100644 --- a/Myshipping.Application/EDI/PILEdiHelper.cs +++ b/Myshipping.Application/EDI/PILEdiHelper.cs @@ -90,7 +90,7 @@ namespace Myshipping.Application.EDI.PIL string Shipping = str; if (fileType == "txt") { - Shipping = formatEdiStr("txt", str); + //Shipping = formatEdiStr("txt", str); } else if (fileType == "xml") { @@ -1648,7 +1648,7 @@ namespace Myshipping.Application.EDI.PIL //4 //Filler//M//X(127)//124 //250 //Spaces r.WriteLine(GetSpaceStr(tempstr, 250)); - if (bill.ACIHBL != "") + 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)"//分三行 @@ -1657,7 +1657,7 @@ namespace Myshipping.Application.EDI.PIL r.WriteLine(GetSpaceStr(tempstr, 250)); } - if (bill.S0CC0C != "") + 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)"//分三行 @@ -1720,7 +1720,7 @@ namespace Myshipping.Application.EDI.PIL 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 (bill.ISSUEDATE.ToString().Trim() == "") + if (string.IsNullOrWhiteSpace(bill.ISSUEDATE)) { tempstr += GetSpaceStr("", 8);//4//Date of BL issue//M//X(8)//11//18//YYYYMMDD//提单签发日期//年月日 } diff --git a/Myshipping.Application/Myshipping.Application.xml b/Myshipping.Application/Myshipping.Application.xml index 8cf1467d..4320f11c 100644 --- a/Myshipping.Application/Myshipping.Application.xml +++ b/Myshipping.Application/Myshipping.Application.xml @@ -8757,7 +8757,7 @@ 请求规则平台 - + @@ -8783,6 +8783,13 @@ 海运订舱报文类 返回回执 + + + 生成请求规则报文 + + 订舱主业务信息 + 返回请求报文类 + 请求规则平台 diff --git a/Myshipping.Application/Service/BookingOrder/Dto/BookingEDIMapper.cs b/Myshipping.Application/Service/BookingOrder/Dto/BookingEDIMapper.cs index d52022dd..e0d7f1e5 100644 --- a/Myshipping.Application/Service/BookingOrder/Dto/BookingEDIMapper.cs +++ b/Myshipping.Application/Service/BookingOrder/Dto/BookingEDIMapper.cs @@ -20,7 +20,7 @@ namespace Myshipping.Application .Map(dest => dest.BLFRT, src => src.BLFRT) .Map(dest => dest.VESSEL, src => src.VESSEL) .Map(dest => dest.VOYNO, src => src.VOYNO) - .Map(dest => dest.ETD, src => src.ETD.HasValue? src.ETD.Value.ToString("yyyy-MM-dd"):"") + .Map(dest => dest.ETD, src => src.ETD.HasValue ? src.ETD.Value.ToString("yyyy-MM-dd") : "") .Map(dest => dest.SIREMARK, src => src.SIREMARK) .Map(dest => dest.SHIPPER, src => src.SHIPPER) .Map(dest => dest.CONSIGNEE, src => src.CONSIGNEE) @@ -35,7 +35,7 @@ namespace Myshipping.Application .Map(dest => dest.PORTDISCHARGE, src => src.PORTDISCHARGE) .Map(dest => dest.DESTINATIONID, src => src.DESTINATIONID) .Map(dest => dest.DESTINATION, src => src.DESTINATION) - .Map(dest => dest.PKGS, src => src.PKGS.HasValue? src.PKGS.Value:0) + .Map(dest => dest.PKGS, src => src.PKGS.HasValue ? src.PKGS.Value : 0) .Map(dest => dest.KINDPKGS, src => src.KINDPKGS) .Map(dest => dest.KGS, src => src.KGS.HasValue ? src.KGS.Value : 0) .Map(dest => dest.CBM, src => src.CBM.HasValue ? src.CBM.Value : 0) diff --git a/Myshipping.Application/Service/RulesEngine/RulesEngineClientService.cs b/Myshipping.Application/Service/RulesEngine/RulesEngineClientService.cs index 8da78ac8..a0087542 100644 --- a/Myshipping.Application/Service/RulesEngine/RulesEngineClientService.cs +++ b/Myshipping.Application/Service/RulesEngine/RulesEngineClientService.cs @@ -34,6 +34,9 @@ namespace Myshipping.Application private readonly SqlSugarRepository _bookingOrderContaRepository; private readonly SqlSugarRepository _bookingOrderContaCargoRepository; private readonly ISysCacheService _cache; + private readonly SqlSugarRepository _relaPortCarrierLaneRep; + + const string CONST_MAPPING_MODULE = "BOOK_OR_CLOSING"; /// /// @@ -41,12 +44,14 @@ namespace Myshipping.Application public RulesEngineClientService(SqlSugarRepository bookingOrderRepository, SqlSugarRepository bookingOrderContaRepository, SqlSugarRepository bookingOrderContaCargoRepository, - ISysCacheService cache) + ISysCacheService cache, + SqlSugarRepository relaPortCarrierLaneRep) { _bookingOrderRepository = bookingOrderRepository; _bookingOrderContaRepository = bookingOrderContaRepository; _bookingOrderContaCargoRepository = bookingOrderContaCargoRepository; _cache = cache; + _relaPortCarrierLaneRep = relaPortCarrierLaneRep; } #region 海运订舱请求规则引擎校验 @@ -110,42 +115,22 @@ namespace Myshipping.Application if (model == null) throw Oops.Oh($"订舱主键{bookingId}无法获取业务信息"); - RulesEngineOrderBookingMessageInfo msgModel = new RulesEngineOrderBookingMessageInfo(); - - msgModel.Head = new RulesEngineWebAPIHeadBase - { - GID = IDGen.NextID().ToString(), - MessageType = "BUSI_RULE", - SenderId = App.Configuration["RulesEngineSender"], - SenderName = App.Configuration["RulesEngineSenderName"], - SenderKey = App.Configuration["RulesEngineAuthKey"], - ReceiverId = "RulesEngine", - ReceiverName = "大简云规则引擎", - Version = "1.0", - RequestDate = nowDate.ToString("yyyy-MM-dd HH:mm:ss"), - RequestAction = "CheckRule", - }; - - msgModel.Main = new RulesEngineOrderBookingMainInfo { - ProjectCode = App.Configuration["RulesEngineProjects"].Split(new char[] { ','}).ToArray(), - }; - - msgModel.Main.BusinessInfo = model.Adapt(); + var mainInfo = model.Adapt(); var contaList = await _bookingOrderContaRepository.AsQueryable().Where(x => x.BILLID == model.Id).ToListAsync(); if (contaList.Count > 0) { - msgModel.Main.BusinessInfo.ContaList = contaList.Adapt>(); + mainInfo.ContaList = contaList.Adapt>(); var ctnArg = contaList.Select(t => t.Id).ToArray(); - var cargoList = await _bookingOrderContaCargoRepository.AsQueryable() - .Where(x=> ctnArg.Contains(x.CTNID.Value)).ToListAsync(); + var cargoList = await _bookingOrderContaCargoRepository.AsQueryable() + .Where(x => ctnArg.Contains(x.CTNID.Value)).ToListAsync(); - if(cargoList.Count > 0) + if (cargoList.Count > 0) { - msgModel.Main.BusinessInfo.ContaList = contaList.GroupJoin(cargoList, l => l.Id, r => r.CTNID, (l, r) => { + mainInfo.ContaList = contaList.GroupJoin(cargoList, l => l.Id, r => r.CTNID, (l, r) => { var currList = r.ToList(); if (currList.Count > 0) @@ -162,11 +147,13 @@ namespace Myshipping.Application } else { - msgModel.Main.BusinessInfo.ContaList = contaList.Adapt>(); + mainInfo.ContaList = contaList.Adapt>(); } } + var msgModel = GetMessageInfo(mainInfo); + var ruleResult = await ExcuteRulesEngine(msgModel); if(ruleResult == null) @@ -218,91 +205,10 @@ namespace Myshipping.Application { DateTime nowDate = DateTime.Now; - //var model = - - //if() - // _bookingOrderRepository.AsQueryable().InSingle(bookingId); - - //if (model == null) - // throw Oops.Oh($"订舱主键{bookingId}无法获取业务信息"); - - RulesEngineOrderBookingMessageInfo msgModel = new RulesEngineOrderBookingMessageInfo(); - - msgModel.Head = new RulesEngineWebAPIHeadBase - { - GID = IDGen.NextID().ToString(), - MessageType = "BUSI_RULE", - SenderId = App.Configuration["RulesEngineSender"], - SenderName = App.Configuration["RulesEngineSenderName"], - SenderKey = App.Configuration["RulesEngineAuthKey"], - ReceiverId = "RulesEngine", - ReceiverName = "大简云规则引擎", - Version = "1.0", - RequestDate = nowDate.ToString("yyyy-MM-dd HH:mm:ss"), - RequestAction = "CheckRule", - }; - - msgModel.Main = new RulesEngineOrderBookingMainInfo - { - ProjectCode = App.Configuration["RulesEngineProjects"].Split(new char[] { ',' }).ToArray(), - }; - - msgModel.Main.BusinessInfo = model.Adapt(); - - //根据卸货港翻译航线信息 - if(!string.IsNullOrWhiteSpace(model.PORTDISCHARGEID)) - { - var laneList = _cache.GetAllRelaPortCarrierLane().GetAwaiter().GetResult(); - var laneInfo = laneList - .FirstOrDefault(p => !string.IsNullOrWhiteSpace(model.CARRIER) && !string.IsNullOrWhiteSpace(p.CarrierCode) && - p.CarrierCode.Equals(model.CARRIER, StringComparison.OrdinalIgnoreCase) && p.PortCode.Equals(model.PORTDISCHARGEID, StringComparison.OrdinalIgnoreCase)); + var mainInfo = model.Adapt(); - if(laneInfo == null) - laneInfo = laneList.FirstOrDefault(p => string.IsNullOrWhiteSpace(p.CarrierCode) && p.PortCode.Equals(model.PORTDISCHARGEID, StringComparison.OrdinalIgnoreCase)); + RulesEngineOrderBookingMessageInfo msgModel = GetMessageInfo(mainInfo); - if (laneInfo != null) - { - var lineModel = _cache.GetAllCodeLane().GetAwaiter().GetResult().FirstOrDefault(t => t.Code.Equals(laneInfo.LaneCode, StringComparison.OrdinalIgnoreCase)); - - msgModel.Main.BusinessInfo.LaneCode = laneInfo.LaneCode; - msgModel.Main.BusinessInfo.LaneName = lineModel?.CnName; - } - } - - - var contaList = await _bookingOrderContaRepository.AsQueryable().Where(x => x.BILLID == model.Id).ToListAsync(); - - if (contaList.Count > 0) - { - msgModel.Main.BusinessInfo.ContaList = contaList.Adapt>(); - - var cargoList = await _bookingOrderContaCargoRepository.AsQueryable() - .Where(x => contaList.Any(a => a.Id == x.CTNID)).ToListAsync(); - - if (cargoList.Count > 0) - { - msgModel.Main.BusinessInfo.ContaList = contaList.GroupJoin(cargoList, l => l.Id, r => r.CTNID, (l, r) => - { - var currList = r.ToList(); - - if (currList.Count > 0) - { - var info = l.Adapt(); - info.CargoList = currList.Adapt>(); - - return info; - } - - return l.Adapt(); - - }).ToList(); - } - else - { - msgModel.Main.BusinessInfo.ContaList = contaList.Adapt>(); - } - - } var ruleResult = await ExcuteRulesEngine(msgModel); if (ruleResult == null) @@ -330,12 +236,95 @@ namespace Myshipping.Application } #endregion + /// + /// 生成请求规则报文 + /// + /// 订舱主业务信息 + /// 返回请求报文类 + [NonAction] + private RulesEngineOrderBookingMessageInfo GetMessageInfo(RulesEngineOrderBookingMainBusinessInfo mainInfo) + { + DateTime nowDate = DateTime.Now; + + RulesEngineOrderBookingMessageInfo msgModel = new RulesEngineOrderBookingMessageInfo(); + + msgModel.Head = new RulesEngineWebAPIHeadBase + { + GID = IDGen.NextID().ToString(), + MessageType = "BUSI_RULE", + SenderId = App.Configuration["RulesEngineSender"], + SenderName = App.Configuration["RulesEngineSenderName"], + SenderKey = App.Configuration["RulesEngineAuthKey"], + ReceiverId = "RulesEngine", + ReceiverName = "大简云规则引擎", + Version = "1.0", + RequestDate = nowDate.ToString("yyyy-MM-dd HH:mm:ss"), + RequestAction = "CheckRule", + }; + + msgModel.Main = new RulesEngineOrderBookingMainInfo + { + ProjectCode = App.Configuration["RulesEngineProjects"].Split(new char[] { ',' }).ToArray(), + }; + + msgModel.Main.BusinessInfo = mainInfo; + + //根据卸货港翻译航线信息 + if (!string.IsNullOrWhiteSpace(mainInfo.PortDischargeId)) + { + var laneList = _cache.GetAllRelaPortCarrierLane().GetAwaiter().GetResult(); + var laneInfo = laneList + .FirstOrDefault(p => !string.IsNullOrWhiteSpace(mainInfo.CarrierId) && !string.IsNullOrWhiteSpace(p.CarrierCode) && + p.CarrierCode.Equals(mainInfo.CarrierId, StringComparison.OrdinalIgnoreCase) && p.PortCode.Equals(mainInfo.PortDischargeId, StringComparison.OrdinalIgnoreCase)); + + if (laneInfo == null) + laneInfo = laneList.FirstOrDefault(p => string.IsNullOrWhiteSpace(p.CarrierCode) && p.PortCode.Equals(mainInfo.PortDischargeId, StringComparison.OrdinalIgnoreCase)); + + if (laneInfo != null) + { + var lineModel = _cache.GetAllCodeLane().GetAwaiter().GetResult().FirstOrDefault(t => t.Code.Equals(laneInfo.LaneCode, StringComparison.OrdinalIgnoreCase)); + + msgModel.Main.BusinessInfo.LaneCode = laneInfo.LaneCode; + msgModel.Main.BusinessInfo.LaneName = lineModel?.CnName; + } + } + + //对应签单方式 + if (!string.IsNullOrWhiteSpace(mainInfo.IssueType)) + { + var issueType = _cache.GetAllCodeIssueType().GetAwaiter().GetResult().FirstOrDefault(p => p.EnName.Equals(mainInfo.IssueType, StringComparison.OrdinalIgnoreCase)); + + //这里规则约定用了签单方式的代码大写 + if (issueType != null) + msgModel.Main.BusinessInfo.IssueType = issueType.Code.ToUpper(); + } + + if (mainInfo.ContaList != null && mainInfo.ContaList.Count > 0) + { + var contaList = _cache.GetAllMappingCtn().GetAwaiter().GetResult(); + mainInfo.ContaList.ForEach(t => + { + var currContaType = contaList.FirstOrDefault(x => x.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase) + && x.Code.Equals(t.ContaType, StringComparison.OrdinalIgnoreCase)); + + if (currContaType != null) + { + t.ContaType = currContaType.MapCode?.ToUpper(); + } + }); + } + + return msgModel; + } + + #region 请求规则平台 /// /// 请求规则平台 /// /// /// + [NonAction] private async Task ExcuteRulesEngine(RulesEngineOrderBookingMessageInfo info) { RulesEngineWebApiResult model = null; From 8c371547eb41075bb860cb745c4676f20a2d40f3 Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Wed, 30 Nov 2022 11:05:37 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AE=A2=E8=88=B1EDI?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AD=97=E6=AE=B5=E7=9A=84=E5=AF=B9=E5=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BookingOrder/BookingOrderService.cs | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs index bdd86c4f..d1837c7c 100644 --- a/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs +++ b/Myshipping.Application/Service/BookingOrder/BookingOrderService.cs @@ -1983,6 +1983,9 @@ namespace Myshipping.Application if (ediExtModel == null) throw Oops.Bah($"获取EDI信息失败"); + if (string.IsNullOrWhiteSpace(ediExtModel.OpEName)) + throw Oops.Bah("未填写(EDI并补充信息)操作英文名称"); + CheckBookingOrClosingEDI(order); EDIRouteEnum ediRouteEnum = GetEDIRoute(order.CARRIERID); @@ -2006,6 +2009,9 @@ namespace Myshipping.Application if (ediSOSICfg == null || string.IsNullOrWhiteSpace(ediSOSICfg.MapCode)) throw Oops.Bah($"CARRIERID={order.CARRIERID} 发送SO(SI)的船公司EDI代码未找到"); + + + var ediModel = new EDIBaseModel(); var ftpSet = _cache.GetAllEdiSetting().GetAwaiter().GetResult() @@ -2024,7 +2030,7 @@ namespace Myshipping.Application //读取文件配置 var fileCfg = App.GetOptions(); - string filePath = $"{Path.Combine(!string.IsNullOrWhiteSpace(fileCfg.basePath) ? fileCfg.basePath : App.WebHostEnvironment.WebRootPath, fileCfg.relativePath)}/edifiles/{order.BSNO}"; + string filePath = $"{Path.Combine(!string.IsNullOrWhiteSpace(fileCfg.basePath) ? fileCfg.basePath : App.WebHostEnvironment.WebRootPath, fileCfg.relativePath)}\\edifiles\\{order.BSNO}"; if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) filePath = filePath.Replace("\\", "/"); @@ -2045,7 +2051,23 @@ namespace Myshipping.Application var primaryModel = order.Adapt(); + //场站 + var ediYardList = _cache.GetAllMappingYard().GetAwaiter().GetResult() + .Where(t => t.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase)).ToList(); + + if (!string.IsNullOrWhiteSpace(order.YARDID)) + { + var currYardInfo = ediYardList.FirstOrDefault(t => t.Code.Equals(order.YARDID, StringComparison.OrdinalIgnoreCase)); + + if (currYardInfo == null) + throw Oops.Bah($"场站{order.YARDID}的EDI代码未找到"); + + primaryModel.YARDEDICODE = currYardInfo.MapCode?.Trim(); + primaryModel.YARD = currYardInfo.MapName?.Trim(); + } + primaryModel.CARRIEREDICODE = ediSOSICfg.MapCode; + primaryModel.ORDERNO = order.BOOKINGNO; var ediPkgs = ediPkgsList.FirstOrDefault(x => x.Code.Equals(order.KINDPKGS, StringComparison.OrdinalIgnoreCase)); @@ -2073,6 +2095,8 @@ namespace Myshipping.Application primaryModel.AMSCONSIGNEE = ediExtModel.AMSConsignee; primaryModel.AMSNOTIFYPARTY = ediExtModel.AMSNotifyParty; + + primaryModel.OpEName = ediExtModel.OpEName; primaryModel.OpTel = ediExtModel.OpTel; primaryModel.OpEmail = ediExtModel.OpEmail; @@ -2104,7 +2128,7 @@ namespace Myshipping.Application if (currConta == null) throw Oops.Oh($"集装箱包装{conta.KINDPKGS}的EDI代码未找到"); - contaModel.KINDPKGS_EDI_CODE = ediContaPkgs.MapCode; + contaModel.KINDPKGS_EDI_CODE = ediContaPkgs.MapCode?.Trim(); primaryModel.CTNLIST.Add(contaModel); } @@ -2125,13 +2149,11 @@ namespace Myshipping.Application if (ediDetailPkgs == null) throw Oops.Oh($"货明细的包装{cargo.KINDPKGS}的EDI代码未找到"); - cargoModel.KINDPKGS_EDI_CODE = ediDetailPkgs.MapCode; + cargoModel.KINDPKGS_EDI_CODE = ediDetailPkgs.MapCode?.Trim(); primaryModel.CTNGOODSLIST.Add(cargoModel); } - - ediModel.BSLIST.Add(primaryModel); var result = await InnerSendBookingOrClosingEDI(model, ediModel, ediRouteEnum); @@ -2345,8 +2367,8 @@ namespace Myshipping.Application if (string.IsNullOrWhiteSpace(order.CARRIERID)) throw Oops.Bah("船公司必须填写"); - if (string.IsNullOrWhiteSpace(order.OPID)) - throw Oops.Bah("未填写操作人"); + //if (string.IsNullOrWhiteSpace(order.OPID)) + // throw Oops.Bah("未填写操作人"); if (string.IsNullOrWhiteSpace(order.KINDPKGS)) throw Oops.Bah("包装种类未填写");