From 08649dd9f8969fdf77ff947389fa1d27bc8c1fc5 Mon Sep 17 00:00:00 2001 From: sanji Date: Tue, 30 Jan 2024 18:22:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=A7=E5=93=81=E5=90=8C=E6=AD=A5=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=B1=BB=E7=9B=AE=E6=9B=B4=E6=96=B0=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/ProductSyncController.cs | 6 +++++ .../Sync/ProductSyncBusiness.cs | 24 +++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/BBWY.Server.API/Controllers/ProductSyncController.cs b/BBWY.Server.API/Controllers/ProductSyncController.cs index 87256174..9c94ec7a 100644 --- a/BBWY.Server.API/Controllers/ProductSyncController.cs +++ b/BBWY.Server.API/Controllers/ProductSyncController.cs @@ -30,5 +30,11 @@ namespace BBWY.Server.API.Controllers { productSyncBusiness.SyncAllShopAllProduct(); } + + [HttpPost("{shopId}")] + public void SyncOneShopProduct([FromRoute]long shopId) + { + productSyncBusiness.SyncOneShopProduct(shopId); + } } } diff --git a/BBWY.Server.Business/Sync/ProductSyncBusiness.cs b/BBWY.Server.Business/Sync/ProductSyncBusiness.cs index 00bcf8ff..9ac8291f 100644 --- a/BBWY.Server.Business/Sync/ProductSyncBusiness.cs +++ b/BBWY.Server.Business/Sync/ProductSyncBusiness.cs @@ -165,15 +165,22 @@ namespace BBWY.Server.Business.Sync #endregion #region 找出状态变化的SKU - var stateChangeProductSkuList = productSkuList.Where(p => dbProductSkuList.Any(dp => dp.Id == p.Id && (dp.State != p.State || dp.Title != p.Title || dp.Price != p.Price || dp.Logo != p.Logo))).ToList(); + var stateChangeProductSkuList = productSkuList.Where(p => dbProductSkuList.Any(dp => dp.Id == p.Id && (dp.State != p.State || + dp.Title != p.Title || + dp.Price != p.Price || + dp.Logo != p.Logo || + dp.CategoryId != p.Source.Value("categoryId")))).ToList(); if (stateChangeProductSkuList.Count() > 0) { foreach (var productSku in stateChangeProductSkuList) { + var categoryName = GetCategoryName(shop, productSku.Source.Value("categoryId")); var update = fsql.Update(productSku.Id).Set(p => p.State, productSku.State) .Set(p => p.Title, productSku.Title) .Set(p => p.Price, productSku.Price) - .Set(p => p.Logo, productSku.Logo); + .Set(p => p.Logo, productSku.Logo) + .Set(p => p.CategoryId, productSku.Source.Value("categoryId")) + .Set(p => p.CategoryName, categoryName); updateProductSkuList.Add(update); } } @@ -256,6 +263,19 @@ namespace BBWY.Server.Business.Sync } } + /// + /// 同步所有店铺的全部产品 + /// + public void SyncOneShopProduct(long shopId) + { + var shopList = venderBusiness.GetShopList(shopId, platform: Enums.Platform.京东); + //SyncProduct(shopList.FirstOrDefault(s => s.ShopId == "11482739"), true); + foreach (var shop in shopList) + { + Task.Factory.StartNew(() => SyncProduct(shop, true), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.ProductSyncTaskScheduler); + } + } + private string GetCategoryName(ShopResponse shop, string categoryId) { if (categoryCache.TryGetValue(categoryId, out string name))