|
|
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
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 根据收货地港口英文名解析出起始港对象
|
|
|
/// </summary>
|
|
|
/// <param name="portEnName">收货地港口英文名</param>
|
|
|
/// <param name="cachePortLoad">起始港缓存</param>
|
|
|
/// <param name="cacheMapPortLoadFunc">起始港缓存映射</param>
|
|
|
/// <returns>起始港对象</returns>
|
|
|
public static async Task<CodePortLoad> PlaceReceiptToPortload(string portEnName, List<CodePortLoad> cachePortLoad, Func<Task<List<MappingPortLoad>>> 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;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 根据交货地港口英文名解析出目的港对象
|
|
|
/// </summary>
|
|
|
/// <param name="portEnName">交货地港口英文名</param>
|
|
|
/// <param name="cachePort">目的港缓存</param>
|
|
|
/// <param name="cacheMapPortFunc">目的港缓存映射</param>
|
|
|
/// <returns>目的港对象</returns>
|
|
|
public static async Task<CodePort> PlaceDeliveryToPort(string portEnName, List<CodePort> cachePort, Func<Task<List<MappingPort>>> 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;
|
|
|
}
|
|
|
}
|
|
|
}
|