|
|
@ -13,6 +13,7 @@ using System.Collections.Generic; |
|
|
|
using Newtonsoft.Json; |
|
|
|
using FreeSql; |
|
|
|
using System.Threading; |
|
|
|
using System.Collections.Concurrent; |
|
|
|
|
|
|
|
namespace BBWY.Server.Business.Sync |
|
|
|
{ |
|
|
@ -20,6 +21,8 @@ namespace BBWY.Server.Business.Sync |
|
|
|
{ |
|
|
|
private ProductBusiness productBusiness; |
|
|
|
|
|
|
|
private ConcurrentDictionary<string, string> categoryCache; |
|
|
|
|
|
|
|
public ProductSyncBusiness(RestApiService restApiService, |
|
|
|
IOptions<GlobalConfig> options, |
|
|
|
NLogManager nLogManager, |
|
|
@ -38,6 +41,7 @@ namespace BBWY.Server.Business.Sync |
|
|
|
yunDingBusiness) |
|
|
|
{ |
|
|
|
this.productBusiness = productBusiness; |
|
|
|
this.categoryCache = new ConcurrentDictionary<string, string>(); |
|
|
|
} |
|
|
|
|
|
|
|
private string GetMainSkuId(IList<ProductSkuResponse> skuList) |
|
|
@ -292,7 +296,8 @@ namespace BBWY.Server.Business.Sync |
|
|
|
Logo = p.Logo, |
|
|
|
ProductId = p.ProductId, |
|
|
|
Price = p.Price, |
|
|
|
CategoryId = p.Source.Value<int>("categoryId") |
|
|
|
CategoryId = p.Source.Value<int>("categoryId"), |
|
|
|
CategoryName = GetCategoryName(shop, p.Source.Value<string>("categoryId")) |
|
|
|
})); |
|
|
|
} |
|
|
|
#endregion
|
|
|
@ -309,6 +314,19 @@ namespace BBWY.Server.Business.Sync |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 找出缺少类目的sku
|
|
|
|
var noCategoryProductList = productSkuList.Where(p => dbProductSkuList.Any(dp => dp.Id == p.Id && string.IsNullOrEmpty(dp.CategoryName))).ToList(); |
|
|
|
if (noCategoryProductList.Count() > 0) |
|
|
|
{ |
|
|
|
foreach (var productSku in noCategoryProductList) |
|
|
|
{ |
|
|
|
var categoryName = GetCategoryName(shop, productSku.Source.Value<string>("categoryId")); |
|
|
|
var update = fsql.Update<ProductSku>(productSku.Id).Set(p => p.CategoryName, categoryName); |
|
|
|
updateProductSkuList.Add(update); |
|
|
|
} |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 找出接口查不出的SKU
|
|
|
|
var goneProductSkuList = dbProductSkuList.Where(dp => !productSkuList.Any(p => p.Id == dp.Id)).ToList(); |
|
|
|
if (goneProductSkuList.Count() > 0) |
|
|
@ -366,12 +384,36 @@ namespace BBWY.Server.Business.Sync |
|
|
|
public void SyncAllShopAllProduct() |
|
|
|
{ |
|
|
|
var shopList = venderBusiness.GetShopList(platform: Enums.Platform.京东); |
|
|
|
//SyncProduct(shopList.FirstOrDefault(s => s.ShopName == "熊猴玩具专营店"), true);
|
|
|
|
//SyncProduct(shopList.FirstOrDefault(s => s.ShopName == "披风熊玩具专营店"), 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)) |
|
|
|
return name; |
|
|
|
try |
|
|
|
{ |
|
|
|
var res = productBusiness.GetCategoyrInfo(new JDQueryCategoryRequest() |
|
|
|
{ |
|
|
|
AppKey = shop.AppKey, |
|
|
|
CategoryId = categoryId, |
|
|
|
AppSecret = shop.AppSecret, |
|
|
|
AppToken = shop.AppToken, |
|
|
|
Platform = shop.PlatformId |
|
|
|
}); |
|
|
|
categoryCache.TryAdd(categoryId, res.Name); |
|
|
|
name = res.Name; |
|
|
|
} |
|
|
|
catch |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
return name; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|