Files
KJD/Work/Business/ProductMappingBLL/MappingVDianTitleSearchBLL.cs
T

278 lines
14 KiB
C#

using AllBase;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Work.Business.ProductMappingBLL
{
public class MappingVDianTitleSearchBLL
{
public static List<Tuple<string, int, int,string>> GetTupleListData(string title,string weidianGetTitleResult)
{
var result = new List<Tuple<string, int, int,string>>();
if (weidianGetTitleResult == null)
return result;
if (weidianGetTitleResult.Contains("\\\"message\\\":\\\"OK\\\""))
{
Newtonsoft.Json.Linq.JObject jObj = Newtonsoft.Json.Linq.JObject.Parse(weidianGetTitleResult);
weidianGetTitleResult = jObj["data"].ToString();
}
Newtonsoft.Json.Linq.JArray jArr = new Newtonsoft.Json.Linq.JArray();
if (weidianGetTitleResult.Contains("\"message\":\"OK\""))
{
Newtonsoft.Json.Linq.JObject jObj = Newtonsoft.Json.Linq.JObject.Parse(weidianGetTitleResult);
jArr = jObj["result"]["viewContainer"] as Newtonsoft.Json.Linq.JArray;
}
else if (weidianGetTitleResult.Contains("\"data\":["))
{
Newtonsoft.Json.Linq.JObject jObj = Newtonsoft.Json.Linq.JObject.Parse(weidianGetTitleResult);
jArr = jObj["data"] as Newtonsoft.Json.Linq.JArray;
}
foreach (var item in jArr)
{
var str = item.ToString();
var id = BaseRegex.GetStringJson(ref str, "itemId");
var name = BaseRegex.GetStringJson(ref str, "itemName");
if (string.IsNullOrEmpty(name))
continue;
bool compare = CompareTitle(title, name);
if (!compare)
continue;
var price = BaseRegex.GetIntJson(ref str, "itemPrice");
if (!string.IsNullOrEmpty(id) && price > 0)
result.Add(new Tuple<string, int, int,string>(id, price, price, DateTime.Now.ToString("yyyy-MM-dd")));
}
return result;
}
public static List<Tuple<string, int, int,string>> GetTupleTaoBaoListData(string weidianGetTitleResult)
{
var result = new List<Tuple<string, int, int,string>>();
if (weidianGetTitleResult == null)
return result;
//if (weidianGetTitleResult.Contains("\\\"message\\\":\\\"OK\\\""))
//{
// Newtonsoft.Json.Linq.JObject jObj = Newtonsoft.Json.Linq.JObject.Parse(weidianGetTitleResult);
// weidianGetTitleResult = jObj["data"].ToString();
//}
Newtonsoft.Json.Linq.JArray jArr = new Newtonsoft.Json.Linq.JArray();
//if (weidianGetTitleResult.Contains("\"message\":\"OK\""))
//{
// Newtonsoft.Json.Linq.JObject jObj = Newtonsoft.Json.Linq.JObject.Parse(weidianGetTitleResult);
// jArr = jObj["result"]["viewContainer"] as Newtonsoft.Json.Linq.JArray;
//}
if (weidianGetTitleResult.Contains("mtopjsonp2("))
weidianGetTitleResult = BaseRegex.GetMatchRegexString(ref weidianGetTitleResult, @"mtopjsonp2\(({[\w\W]+?})\)");
if (weidianGetTitleResult.Contains("\"data\":{"))
{
Newtonsoft.Json.Linq.JObject jObj = Newtonsoft.Json.Linq.JObject.Parse(weidianGetTitleResult);
jArr = jObj["data"]?["recommend"]?["resultList"] as Newtonsoft.Json.Linq.JArray;
//var lst = jObj["data"]["resultList"].ToList();
//var ss = JArray.Parse(jObj["data"]?["recommend"]?["resultList"]?.ToString())?.ToObject<List<Object>>();
}
if (jArr == null)
return result;
foreach (var item in jArr)
{
var str = item.ToString();
var id = BaseRegex.GetStringJson(ref str, "itemId");
int price = 0;
var pricetemp = BaseRegex.GetDecimalJson(ref str, "promotionPrice");
price =(int)(pricetemp * 100);
if (!string.IsNullOrEmpty(id) && price > 0)
result.Add(new Tuple<string, int, int,string>("tb-"+id, price, price, DateTime.Now.ToString("yyyy-MM-dd")));
if (result.Count >= 10)
break;
}
return result;
}
public static List<Tuple<string, int, int,string>> GetTupleTaoBaoListV2Data(string title,string weidianGetTitleResult)
{
var result = new List<Tuple<string, int, int,string>>();
if (weidianGetTitleResult == null)
return result;
//if (weidianGetTitleResult.Contains("\\\"message\\\":\\\"OK\\\""))
//{
// Newtonsoft.Json.Linq.JObject jObj = Newtonsoft.Json.Linq.JObject.Parse(weidianGetTitleResult);
// weidianGetTitleResult = jObj["data"].ToString();
//}
Newtonsoft.Json.Linq.JArray jArr = new Newtonsoft.Json.Linq.JArray();
//if (weidianGetTitleResult.Contains("\"message\":\"OK\""))
//{
// Newtonsoft.Json.Linq.JObject jObj = Newtonsoft.Json.Linq.JObject.Parse(weidianGetTitleResult);
// jArr = jObj["result"]["viewContainer"] as Newtonsoft.Json.Linq.JArray;
//}
if (weidianGetTitleResult.Contains("mtopjsonp17("))
weidianGetTitleResult = BaseRegex.GetMatchRegexString(ref weidianGetTitleResult, @"mtopjsonp17\(({[\w\W]+?})\)");
if (weidianGetTitleResult.Contains("\"data\":{"))
{
Newtonsoft.Json.Linq.JObject jObj = Newtonsoft.Json.Linq.JObject.Parse(weidianGetTitleResult);
jArr = jObj["data"]?["itemsArray"] as Newtonsoft.Json.Linq.JArray;
//var lst = jObj["data"]["resultList"].ToList();
//var ss = JArray.Parse(jObj["data"]?["recommend"]?["resultList"]?.ToString())?.ToObject<List<Object>>();
}
if (jArr == null)
return result;
var resultx = new List<Tuple<string, int, int, double,string>>();
foreach (var item in jArr)
{
var str = item.ToString();
var id = BaseRegex.GetStringJson(ref str, "x_object_id");
if (id == null)
continue;
string name = BaseRegex.GetStringJson(ref str, "title");
double simu = BaseClass.GetSimularityBetween2Text(title, name);
if (simu < 0.8)
continue;
bool compare = CompareTitle(title, name);
if (!compare)
continue;
int price = 0;
var pricetemp = BaseRegex.GetDecimalJson(ref str, "item_price");
price = (int)(pricetemp * 100);
if (!string.IsNullOrEmpty(id) && price > 0)
resultx.Add(new Tuple<string, int, int, double,string>("tb-" + id, price, price,simu, DateTime.Now.ToString("yyyy-MM-dd")));
if (resultx.Count >= 10)
break;
}
resultx = resultx.OrderByDescending(o => o.Item4).ToList();
for (int i = 0; i < resultx.Count; i++)
{
var obj = resultx[i];
result.Add(new Tuple<string, int, int, string>(obj.Item1, obj.Item2, obj.Item3, obj.Item5));
}
//foreach (var item in jArr)
//{
// var str = item.ToString();
// var id = BaseRegex.GetStringJson(ref str, "x_object_id");
// if (id == null)
// continue;
// string name= BaseRegex.GetStringJson(ref str, "title");
// double simu= BaseClass.GetSimularityBetween2Text(title, name);
// if (simu < 0.85)
// continue;
// bool compare = CompareTitle(title, name);
// if (!compare)
// continue;
// int price = 0;
// var pricetemp = BaseRegex.GetDecimalJson(ref str, "item_price");
// price = (int)(pricetemp * 100);
// if (!string.IsNullOrEmpty(id) && price > 0)
// result.Add(new Tuple<string, int, int,string>("tb-" + id, price, price, DateTime.Now.ToString("yyyy-MM-dd")));
// if (result.Count >= 10)
// break;
//}
return result;
}
public static List<Tuple<string, int, int, string>> GetTuplejingxiListV2Data(string title, string weidianGetTitleResult)
{
var result = new List<Tuple<string, int, int, string>>();
if (weidianGetTitleResult == null)
return result;
Newtonsoft.Json.Linq.JArray jArr = new Newtonsoft.Json.Linq.JArray();
Newtonsoft.Json.Linq.JObject jObj = Newtonsoft.Json.Linq.JObject.Parse(weidianGetTitleResult);
jArr = jObj["wareInfo"] as Newtonsoft.Json.Linq.JArray;
if (jArr == null)
return result;
var resultx = new List<Tuple<string, int, int, double, string>>();
foreach (var item in jArr)
{
var str = item.ToString();
var id = BaseRegex.GetStringJson(ref str, "wareId");
if (id == null)
continue;
string name = BaseRegex.GetStringJson(ref str, "wname");
double simu = BaseClass.GetSimularityBetween2Text(title, name);
if (simu < 0.8)
continue;
//bool compare = CompareTitle(title, name);
//if (!compare)
// continue;
int price = 0;
var pricetemp = BaseRegex.GetDecimalJson(ref str, "jdPrice");
price = (int)(pricetemp * 100);
if (!string.IsNullOrEmpty(id) && price > 0)
resultx.Add(new Tuple<string, int, int,double,string>("jx-" + id, price, price,simu, DateTime.Now.ToString("yyyy-MM-dd")));
if (resultx.Count >= 10)
break;
}
resultx = resultx.OrderByDescending(o => o.Item4).ToList();
for (int i = 0; i < resultx.Count; i++)
{
var obj = resultx[i];
result.Add(new Tuple<string, int, int, string>(obj.Item1, obj.Item2, obj.Item3, obj.Item5));
}
return result;
}
public static List<Tuple<string, int, int,string>> GetTuple1688ListData(string title,string weidianGetTitleResult)
{
var result = new List<Tuple<string, int, int,string>>();
if (weidianGetTitleResult == null)
return result;
//if (weidianGetTitleResult.Contains("\\\"message\\\":\\\"OK\\\""))
//{
// Newtonsoft.Json.Linq.JObject jObj = Newtonsoft.Json.Linq.JObject.Parse(weidianGetTitleResult);
// weidianGetTitleResult = jObj["data"].ToString();
//}
Newtonsoft.Json.Linq.JArray jArr = new Newtonsoft.Json.Linq.JArray();
//if (weidianGetTitleResult.Contains("\"message\":\"OK\""))
//{
// Newtonsoft.Json.Linq.JObject jObj = Newtonsoft.Json.Linq.JObject.Parse(weidianGetTitleResult);
// jArr = jObj["result"]["viewContainer"] as Newtonsoft.Json.Linq.JArray;
//}
if (weidianGetTitleResult.Contains("mtopjsonp17("))
weidianGetTitleResult = BaseRegex.GetMatchRegexString(ref weidianGetTitleResult, @"mtopjsonp17\(({[\w\W]+?})\)");
if (weidianGetTitleResult.Contains("\"data\":{"))
{
Newtonsoft.Json.Linq.JObject jObj = Newtonsoft.Json.Linq.JObject.Parse(weidianGetTitleResult);
jArr = jObj["data"]?["offerList"] as Newtonsoft.Json.Linq.JArray;
//var lst = jObj["data"]["resultList"].ToList();
//var ss = JArray.Parse(jObj["data"]?["recommend"]?["resultList"]?.ToString())?.ToObject<List<Object>>();
}
if (jArr == null)
return result;
var resultx = new List<Tuple<string, int, int, double, string>>();
foreach (var item in jArr)
{
var str = item.ToString();
var id = BaseRegex.GetStringJson(ref str, "infoId");
string name = BaseRegex.GetStringJson(ref str, "simpleSubject");
double simu = BaseClass.GetSimularityBetween2Text(title, name);
if (simu < 0.5)
continue;
bool compare = CompareTitle(title, name);
if (!compare)
continue;
int price = 0;
var pricetemp = BaseRegex.GetDecimalJson(ref str, "price");
price = (int)(pricetemp * 100);
if (!string.IsNullOrEmpty(id) && price > 0)
resultx.Add(new Tuple<string, int, int,double,string>("al-" + id, price, price,simu,DateTime.Now.ToString("yyyy-MM-dd")));
if (resultx.Count >= 10)
break;
}
resultx = resultx.OrderByDescending(o => o.Item4).ToList();
for (int i = 0; i < resultx.Count; i++)
{
var obj = resultx[i];
result.Add(new Tuple<string, int, int, string>(obj.Item1, obj.Item2, obj.Item3, obj.Item5));
}
return result;
}
public static bool CompareTitle(string title,string name)
{
if ((name.Length < title.Length + 10) || name.Length <= 30)
{
return true;
}
return false;
}
}
}