From a94078f720c376d96c7c45ee87612e1ec76aeac2 Mon Sep 17 00:00:00 2001 From: shanj <18996038927@163.com> Date: Fri, 6 Jan 2023 17:34:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dsku=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PlatformSDK/JDBusiness.cs | 9 ++-- .../Sync/ProductSyncBusiness.cs | 14 ++++--- BBWY.Server.Business/TaskSchedulerManager.cs | 2 +- BBWY.Test/JDProductAPITest.cs | 41 ++++++++++++++++--- BBWY.Test/Program.cs | 2 +- 5 files changed, 51 insertions(+), 17 deletions(-) diff --git a/BBWY.Server.Business/PlatformSDK/JDBusiness.cs b/BBWY.Server.Business/PlatformSDK/JDBusiness.cs index b16e27bb..260381a4 100644 --- a/BBWY.Server.Business/PlatformSDK/JDBusiness.cs +++ b/BBWY.Server.Business/PlatformSDK/JDBusiness.cs @@ -129,13 +129,14 @@ namespace BBWY.Server.Business var skuList = new List(); IList 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++; } diff --git a/BBWY.Server.Business/Sync/ProductSyncBusiness.cs b/BBWY.Server.Business/Sync/ProductSyncBusiness.cs index e9c7420d..c44ba211 100644 --- a/BBWY.Server.Business/Sync/ProductSyncBusiness.cs +++ b/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); + } } } } diff --git a/BBWY.Server.Business/TaskSchedulerManager.cs b/BBWY.Server.Business/TaskSchedulerManager.cs index 1b8cd3d0..21b03fc6 100644 --- a/BBWY.Server.Business/TaskSchedulerManager.cs +++ b/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); diff --git a/BBWY.Test/JDProductAPITest.cs b/BBWY.Test/JDProductAPITest.cs index 34387d64..855c9c14 100644 --- a/BBWY.Test/JDProductAPITest.cs +++ b/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(); + IList 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("skuId"), + ProductId = s.Value("wareId"), + Price = s.Value("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("logo")}", + State = s.Value("status"), + CreateTime = s.Value("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)); diff --git a/BBWY.Test/Program.cs b/BBWY.Test/Program.cs index d723db95..8eea53ec 100644 --- a/BBWY.Test/Program.cs +++ b/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();