From 5288fbfc899f194bcd37ffe6ece678e0652a1a89 Mon Sep 17 00:00:00 2001 From: jianghaiqing Date: Tue, 13 Dec 2022 11:35:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=B0=83=E5=8F=96=E8=A7=84?= =?UTF-8?q?=E5=88=99=E6=A0=A1=E9=AA=8C=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=9F=BA=E7=A1=80=E6=95=B0=E6=8D=AE=E7=9A=84=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E4=B8=BA=E7=A9=BA=E7=9A=84=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RulesEngine/RulesEngineClientService.cs | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/Myshipping.Application/Service/RulesEngine/RulesEngineClientService.cs b/Myshipping.Application/Service/RulesEngine/RulesEngineClientService.cs index 38d0901d..a5482ec0 100644 --- a/Myshipping.Application/Service/RulesEngine/RulesEngineClientService.cs +++ b/Myshipping.Application/Service/RulesEngine/RulesEngineClientService.cs @@ -304,17 +304,22 @@ namespace Myshipping.Application { 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)); + .FirstOrDefault(p => !string.IsNullOrWhiteSpace(mainInfo.CarrierId) && !string.IsNullOrWhiteSpace(p.CarrierCode) + && !string.IsNullOrWhiteSpace(p.PortCode) + && 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)); + laneInfo = laneList.FirstOrDefault(p => string.IsNullOrWhiteSpace(p.CarrierCode) + && !string.IsNullOrWhiteSpace(p.PortCode) + && p.PortCode.Equals(mainInfo.PortDischargeId, StringComparison.OrdinalIgnoreCase)); _logger.LogInformation("批次={no} 港口对应航线完成 port={port} msg={msg}", batchNo, mainInfo.PortDischargeId, JSON.Serialize(laneInfo)); if (laneInfo != null) { - var lineModel = _cache.GetAllCodeLane().GetAwaiter().GetResult().FirstOrDefault(t => t.Code.Equals(laneInfo.LaneCode, StringComparison.OrdinalIgnoreCase)); + var lineModel = _cache.GetAllCodeLane().GetAwaiter().GetResult().FirstOrDefault(t => + !string.IsNullOrWhiteSpace(t.Code) + && t.Code.Equals(laneInfo.LaneCode, StringComparison.OrdinalIgnoreCase)); _logger.LogInformation("批次={no} 检索航线完成 lane={lane} msg={msg}", batchNo, laneInfo.LaneCode, JSON.Serialize(lineModel)); @@ -325,14 +330,18 @@ namespace Myshipping.Application codePortList = _cache.GetAllCodePort().GetAwaiter().GetResult(); //翻译卸货港对应的国家 - var portInfo = codePortList.FirstOrDefault(t => t.Code.Equals(mainInfo.PortDischargeId, StringComparison.OrdinalIgnoreCase)); + var portInfo = codePortList.FirstOrDefault(t => + !string.IsNullOrWhiteSpace(t.Code) + && t.Code.Equals(mainInfo.PortDischargeId, StringComparison.OrdinalIgnoreCase)); _logger.LogInformation("批次={no} 检索港口完成 lane={lane} msg={msg}", batchNo, mainInfo.PortDischargeId, JSON.Serialize(portInfo)); if (portInfo == null || string.IsNullOrWhiteSpace(portInfo.CountryCode)) throw Oops.Oh($"卸货港口代码{mainInfo.PortDischargeId}获取港口基础数据失败"); - var countryInfo = _cache.GetAllCodeCountry().GetAwaiter().GetResult().FirstOrDefault(t => t.Code.Equals(portInfo.CountryCode, StringComparison.OrdinalIgnoreCase)); + var countryInfo = _cache.GetAllCodeCountry().GetAwaiter().GetResult().FirstOrDefault(t => + !string.IsNullOrWhiteSpace(t.Code) + && t.Code.Equals(portInfo.CountryCode, StringComparison.OrdinalIgnoreCase)); if (countryInfo == null || string.IsNullOrWhiteSpace(portInfo.EnName)) throw Oops.Oh($"国家代码{portInfo.CountryCode}获取国家基础数据失败"); @@ -352,14 +361,18 @@ namespace Myshipping.Application } //翻译中转港对应的国家 - var portInfo = codePortList.FirstOrDefault(t => t.Code.Equals(mainInfo.TransportId, StringComparison.OrdinalIgnoreCase)); + var portInfo = codePortList.FirstOrDefault(t => + !string.IsNullOrWhiteSpace(t.Code) + && t.Code.Equals(mainInfo.TransportId, StringComparison.OrdinalIgnoreCase)); _logger.LogInformation("批次={no} 检索港口完成 port={lane} msg={msg}", batchNo, mainInfo.TransportId, JSON.Serialize(portInfo)); if (portInfo == null || string.IsNullOrWhiteSpace(portInfo.CountryCode)) throw Oops.Oh($"中转港口代码{mainInfo.TransportId}获取港口基础数据失败"); - var countryInfo = _cache.GetAllCodeCountry().GetAwaiter().GetResult().FirstOrDefault(t => t.Code.Equals(portInfo.CountryCode, StringComparison.OrdinalIgnoreCase)); + var countryInfo = _cache.GetAllCodeCountry().GetAwaiter().GetResult().FirstOrDefault(t => + !string.IsNullOrWhiteSpace(t.Code) + && t.Code.Equals(portInfo.CountryCode, StringComparison.OrdinalIgnoreCase)); if (countryInfo == null || string.IsNullOrWhiteSpace(portInfo.EnName)) throw Oops.Oh($"国家代码{portInfo.CountryCode}获取国家基础数据失败"); @@ -372,7 +385,9 @@ namespace Myshipping.Application //对应签单方式 if (!string.IsNullOrWhiteSpace(mainInfo.IssueType)) { - var issueType = _cache.GetAllCodeIssueType().GetAwaiter().GetResult().FirstOrDefault(p => p.EnName.Equals(mainInfo.IssueType, StringComparison.OrdinalIgnoreCase)); + var issueType = _cache.GetAllCodeIssueType().GetAwaiter().GetResult().FirstOrDefault(p => + !string.IsNullOrWhiteSpace(p.EnName) + && p.EnName.Equals(mainInfo.IssueType, StringComparison.OrdinalIgnoreCase)); _logger.LogInformation("批次={no} 提取签单方式完成 IssueType={issue} msg={msg}", batchNo, mainInfo.IssueType, JSON.Serialize(issueType)); @@ -398,7 +413,9 @@ namespace Myshipping.Application { if (!string.IsNullOrWhiteSpace(t.ContaType)) { - var contaInfo = _cache.GetAllCodeCtn().GetAwaiter().GetResult().FirstOrDefault(p => p.Code.Equals(t.ContaType, StringComparison.OrdinalIgnoreCase)); + var contaInfo = _cache.GetAllCodeCtn().GetAwaiter().GetResult().FirstOrDefault(p => + !string.IsNullOrWhiteSpace(p.Code) + && p.Code.Equals(t.ContaType, StringComparison.OrdinalIgnoreCase)); if (contaInfo == null) throw Oops.Oh($"箱型{t.ContaType} 基础数据没有指定大小箱");