using Myshipping.Core; using Myshipping.Core.Entity; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Myshipping.Application.Helper { public static class PlaceToPortHelper { public static async Task PlaceReceiptToPortload(string portEnName, List cachePortLoad, Func>> cacheMapPortLoadFunc) { if (string.IsNullOrEmpty(portEnName)) { return null; } // 匹配方式1:精准匹配 var portInfo = cachePortLoad.FirstOrDefault(x => x.EnName.Equals(portEnName, StringComparison.OrdinalIgnoreCase)); if (portInfo != null) return portInfo; // 匹配方式2:起始模糊匹配 portInfo = cachePortLoad.FirstOrDefault(x => x.EnName.StartsWith(portEnName, StringComparison.OrdinalIgnoreCase)); if (portInfo != null) return portInfo; // 匹配方式3:完整模糊匹配 portInfo = cachePortLoad.FirstOrDefault(x => x.EnName.Contains(portEnName, StringComparison.OrdinalIgnoreCase)); if (portInfo != null) return portInfo; // 匹配方式4:精准映射匹配 var mapCachePortLoad = await cacheMapPortLoadFunc(); var map = mapCachePortLoad.FirstOrDefault(x => x.Module == CommonConst.RECEIPT_TO_PORTLOAD && x.MapName.Equals(portEnName, StringComparison.OrdinalIgnoreCase)); if (map != null) { portInfo = cachePortLoad.FirstOrDefault(x => x.Code == map.Code); if (portInfo != null) return portInfo; } return null; } public static async Task PlaceDeliveryToPort(string portEnName, List cachePort, Func>> cacheMapPortFunc) { if (string.IsNullOrEmpty(portEnName)) { return null; } // 匹配方式1:精准匹配 var portInfo = cachePort.FirstOrDefault(x => x.EnName.Equals(portEnName, StringComparison.OrdinalIgnoreCase)); if (portInfo != null) return portInfo; // 匹配方式2:起始模糊匹配 portInfo = cachePort.FirstOrDefault(x => x.EnName.StartsWith(portEnName, StringComparison.OrdinalIgnoreCase)); if (portInfo != null) return portInfo; // 匹配方式3:完整模糊匹配 portInfo = cachePort.FirstOrDefault(x => x.EnName.Contains(portEnName, StringComparison.OrdinalIgnoreCase)); if (portInfo != null) return portInfo; // 匹配方式4:精准映射匹配 var mapCachePort = await cacheMapPortFunc(); var map = mapCachePort.FirstOrDefault(x => x.Module == CommonConst.DELIVERY_TO_PORT && x.MapName.Equals(portEnName, StringComparison.OrdinalIgnoreCase)); if (map != null) { portInfo = cachePort.FirstOrDefault(x => x.Code == map.Code); if (portInfo != null) return portInfo; } return null; } } }