You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
2.2 KiB
41 lines
2.2 KiB
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace BBWY.Test
|
|
{
|
|
internal class Program
|
|
{
|
|
|
|
|
|
static void Main(string[] args)
|
|
{
|
|
IDictionary<int, string> deliverySelfDic = new Dictionary<int, string>()
|
|
{
|
|
{2 , "1274"} //厂家自送
|
|
};
|
|
var wayBillNoResponse = JObject.Parse("{\"LogisticsCompanyId\":\"100\",\"LogisticsCompanyName\":\"申通快递(STO)\",\"WayBillNo\":\"773159209682541\"}");
|
|
var logisticsCompanyList = JArray.Parse("[{\"Id\":\"2087\",\"Name\":\"京东快递\"},{\"Id\":\"463\",\"Name\":\"圆通快递\"},{\"Id\":\"2170\",\"Name\":\"邮政快递包裹\"},{\"Id\":\"1327\",\"Name\":\"韵达快递\"},{\"Id\":\"680414\",\"Name\":\"中通快运\"},{\"Id\":\"467\",\"Name\":\"顺丰快递\"},{\"Id\":\"256122\",\"Name\":\"UPS\"},{\"Id\":\"1747\",\"Name\":\"优速快递\"},{\"Id\":\"3046\",\"Name\":\"德邦快递\"},{\"Id\":\"465\",\"Name\":\"邮政EMS\"},{\"Id\":\"1665004\",\"Name\":\"云仓速递\"},{\"Id\":\"4832\",\"Name\":\"安能物流\"},{\"Id\":\"1499\",\"Name\":\"中通速递\"}]");
|
|
|
|
var companyId = ConvertLogisticsCompanyId(wayBillNoResponse.Value<string>("LogisticsCompanyName"), logisticsCompanyList, 2, deliverySelfDic);
|
|
Console.WriteLine(companyId);
|
|
Console.ReadKey();
|
|
}
|
|
|
|
|
|
private static string ConvertLogisticsCompanyId(string sourceLogisticsCompanyName, IList<JToken> targetLogisticsList, int tagetLogisticsPlatform, IDictionary<int, string> deliverySelfDic)
|
|
{
|
|
var match = Regex.Match(sourceLogisticsCompanyName, "(中通|圆通|申通|顺丰|韵达|邮政快递包裹|平邮|EMS|德邦|百世|天天|优速)");
|
|
if (match.Success)
|
|
{
|
|
var sname = match.Groups[1].Value;
|
|
var targetLogistics = targetLogisticsList.FirstOrDefault(t => t.Value<string>("Name").Contains(sname));
|
|
if (targetLogistics != null)
|
|
return targetLogistics.Value<string>("Id");
|
|
}
|
|
return deliverySelfDic[tagetLogisticsPlatform];
|
|
}
|
|
}
|
|
}
|
|
|