You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
BookingHeChuan/Myshipping.Application/Helper/PlaceToPortHelper.cs

93 lines
4.0 KiB
C#

6 months ago
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
{
6 months ago
/// <summary>
/// 根据收货地港口英文名解析出起始港对象
/// </summary>
/// <param name="portEnName">收货地港口英文名</param>
/// <param name="cachePortLoad">起始港缓存</param>
/// <param name="cacheMapPortLoadFunc">起始港缓存映射</param>
/// <returns>起始港对象</returns>
6 months ago
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;
}
6 months ago
/// <summary>
/// 根据交货地港口英文名解析出目的港对象
/// </summary>
/// <param name="portEnName">交货地港口英文名</param>
/// <param name="cachePort">目的港缓存</param>
/// <param name="cacheMapPortFunc">目的港缓存映射</param>
/// <returns>目的港对象</returns>
6 months ago
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;
}
}
}