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} 基础数据没有指定大小箱");