Browse Source

修复sku查询问题

qianyi
shanji 2 years ago
parent
commit
a94078f720
  1. 9
      BBWY.Server.Business/PlatformSDK/JDBusiness.cs
  2. 14
      BBWY.Server.Business/Sync/ProductSyncBusiness.cs
  3. 2
      BBWY.Server.Business/TaskSchedulerManager.cs
  4. 41
      BBWY.Test/JDProductAPITest.cs
  5. 2
      BBWY.Test/Program.cs

9
BBWY.Server.Business/PlatformSDK/JDBusiness.cs

@ -129,13 +129,14 @@ namespace BBWY.Server.Business
var skuList = new List<ProductSkuResponse>();
IList<string> skuIdList = null;
var pageIndex = 1;
var pageSize = 0;
var pageSize = 20;
var totalPageSize = 1;
if (!string.IsNullOrEmpty(searchProductSkuRequest.Spu))
pageSize = 1;
totalPageSize = 1;
else if (!string.IsNullOrEmpty(searchProductSkuRequest.Sku))
{
skuIdList = searchProductSkuRequest.Sku.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
pageSize = (skuIdList.Count() - 1) / 20 + 1;
totalPageSize = (skuIdList.Count() - 1) / pageSize + 1;
}
while (true)
@ -164,7 +165,7 @@ namespace BBWY.Server.Business
if (currentList != null && currentList.Count() > 0)
skuList.AddRange(currentList);
if (pageIndex >= pageSize)
if (pageIndex >= totalPageSize)
break;
pageIndex++;
}

14
BBWY.Server.Business/Sync/ProductSyncBusiness.cs

@ -12,6 +12,7 @@ using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using FreeSql;
using System.Threading;
namespace BBWY.Server.Business.Sync
{
@ -74,8 +75,8 @@ namespace BBWY.Server.Business.Sync
foreach (var product in productList.Items)
{
Thread.Sleep(200);
currentProductId = product.Id;
#region 检查sku
var skuList = productBusiness.GetProductSkuList(new SearchProductSkuRequest()
{
@ -189,6 +190,7 @@ namespace BBWY.Server.Business.Sync
if (productList.Items.Count < 50 || !IsSyncAllProduct)
break;
request.PageIndex++;
Thread.Sleep(1000);
}
}
catch (Exception ex)
@ -217,11 +219,11 @@ namespace BBWY.Server.Business.Sync
public void SyncAllShopAllProduct()
{
var shopList = venderBusiness.GetShopList();
SyncProduct(shopList.FirstOrDefault(s => s.ShopName == "布莱特玩具专营店"), true);
//foreach (var shop in shopList)
//{
// Task.Factory.StartNew(() => SyncProduct(shop, true), System.Threading.CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.ProductSyncTaskScheduler);
//}
//SyncProduct(shopList.FirstOrDefault(s => s.ShopName == "奥德汽车用品专营店"), true);
foreach (var shop in shopList)
{
Task.Factory.StartNew(() => SyncProduct(shop, true), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.ProductSyncTaskScheduler);
}
}
}
}

2
BBWY.Server.Business/TaskSchedulerManager.cs

@ -28,7 +28,7 @@ namespace BBWY.Server.Business
SyncRefundOrderTaskScheduler = new LimitedConcurrencyLevelTaskScheduler(10);
SyncAfterOrderTaskScheduler = new LimitedConcurrencyLevelTaskScheduler(10);
PurchaseOrderCallbackTaskScheduler = new LimitedConcurrencyLevelTaskScheduler(10);
ProductSyncTaskScheduler = new LimitedConcurrencyLevelTaskScheduler(5);
ProductSyncTaskScheduler = new LimitedConcurrencyLevelTaskScheduler(2);
JDPopularizeTaskScheduler = new LimitedConcurrencyLevelTaskScheduler(10);
StoreHouseTaskScheduler = new LimitedConcurrencyLevelTaskScheduler(2);

41
BBWY.Test/JDProductAPITest.cs

@ -13,17 +13,48 @@ namespace BBWY.Test
{
public class JDProductAPITest
{
public void GetSkus(IJdClient client, string token, string spu)
public void GetSkus(IJdClient client, string token)
{
var req_skuList = new SkuReadSearchSkuListRequest()
{
pageSize = 50,//50
field = "logo,saleAttrs,status,created,barCode,categoryId,multiCateProps"
};
string sku = "10066603568725,10066603568724,10066603568728,10066603568727,10066603568726,10066603568722,10066603568729,10066603568723";
var skuList = new List<ProductSkuResponse>();
IList<string> skuIdList = null;
var pageIndex = 1;
var pageSize = 20;
var totalPageSize = 1;
skuIdList = sku.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
totalPageSize = (skuIdList.Count() - 1) / 20 + 1;
while (true)
{
req_skuList.skuId = string.Join(",", skuIdList.Skip((pageIndex - 1) * pageSize).Take(pageSize));
req_skuList.wareId = spu;
var response = client.Execute(req_skuList, token, DateTime.Now.ToLocalTime());
Console.WriteLine(JsonConvert.SerializeObject(response));
var rep_skuList = client.Execute(req_skuList, token, DateTime.Now.ToLocalTime());
var currentList = ((JArray)rep_skuList.Json["jingdong_sku_read_searchSkuList_responce"]["page"]["data"]).Select(s => new ProductSkuResponse()
{
Id = s.Value<string>("skuId"),
ProductId = s.Value<string>("wareId"),
Price = s.Value<decimal>("jdPrice"),
Title = s["saleAttrs"] != null ? string.Join("-", s["saleAttrs"].Select(a => a["attrValueAlias"][0].ToString())) : string.Empty,
Logo = $"https://img13.360buyimg.com/n9/s80x80_{s.Value<string>("logo")}",
State = s.Value<int>("status"),
CreateTime = s.Value<long>("created").StampToDateTime(),
Source = s
}).ToList();
if (currentList != null && currentList.Count() > 0)
skuList.AddRange(currentList);
if (pageIndex >= totalPageSize)
break;
pageIndex++;
}
Console.WriteLine(JsonConvert.SerializeObject(skuList));
}
public void GetSpu(IJdClient client, string token, string spu)
@ -37,7 +68,7 @@ namespace BBWY.Test
field = "created,logo,brandName"
};
req_productList.wareId = spu;
req_productList.wareId = spu;
var res = client.Execute(req_productList, token, DateTime.Now.ToLocalTime());
Console.WriteLine(JsonConvert.SerializeObject(res));

2
BBWY.Test/Program.cs

@ -39,7 +39,7 @@ namespace BBWY.Test
IJdClient client = GetJdClient(appkey, appSecret);
var test1 = new JDProductAPITest();
test1.GetSpu(client, token, "10023500913672");
test1.GetSkus(client, token);
Console.ReadKey();

Loading…
Cancel
Save