Browse Source

修复sku为空报错的问题

qianyi
shanji 3 years ago
parent
commit
1e95073740
  1. 9
      BBWY.Server.Business/PlatformSDK/JDBusiness.cs
  2. 26
      BBWY.Server.Business/Sync/ProductSyncBusiness.cs
  3. 10
      BBWY.Server.Business/Sync/RefundOrderSyncBusiness.cs
  4. 2
      BBWY.Test/Program.cs

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

@ -131,6 +131,15 @@ namespace BBWY.Server.Business
var rep_skuList = jdClient.Execute(req_skuList, searchProductSkuRequest.AppToken, DateTime.Now.ToLocalTime());
if (rep_skuList.IsError)
throw new BusinessException(string.IsNullOrEmpty(rep_skuList.ErrorMsg) ? rep_skuList.ErrMsg : rep_skuList.ErrorMsg);
if (rep_skuList.Json == null ||
!rep_skuList.Json.ContainsKey("jingdong_sku_read_searchSkuList_responce") ||
rep_skuList.Json["jingdong_sku_read_searchSkuList_responce"]["page"] == null ||
rep_skuList.Json["jingdong_sku_read_searchSkuList_responce"]["page"]["data"] == null)
{
return new ProductSkuResponse[0];
}
return ((JArray)rep_skuList.Json["jingdong_sku_read_searchSkuList_responce"]["page"]["data"]).Select(s => new ProductSkuResponse()
{
Id = s.Value<string>("skuId"),

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

@ -37,7 +37,10 @@ namespace BBWY.Server.Business.Sync
this.productBusiness = productBusiness;
}
private void SyncProduct(ShopResponse shop, ProductListResponse productList)
private void SyncProduct(ShopResponse shop, ProductListResponse productList, out string productId)
{
productId = "";
try
{
var shopId = long.Parse(shop.ShopId);
List<Product> insertProductList = new List<Product>();
@ -52,6 +55,7 @@ namespace BBWY.Server.Business.Sync
foreach (var product in productList.Items)
{
productId = product.Id;
var dbProduct = dbProducts.FirstOrDefault(dbp => dbp.Id == product.Id);
if (dbProduct == null)
{
@ -80,7 +84,8 @@ namespace BBWY.Server.Business.Sync
Platform = shop.PlatformId,
Spu = product.Id
});
if (skuList == null || skuList.Count() == 0)
continue;
foreach (var sku in skuList)
{
var dbSku = dbProductSkus.FirstOrDefault(s => s.Id == sku.Id);
@ -120,6 +125,11 @@ namespace BBWY.Server.Business.Sync
});
}
catch (Exception ex)
{
throw new Exception(productId, ex);
}
}
private void SyncProduct(ShopResponse shop, bool IsSyncAllProduct = false)
{
@ -139,7 +149,7 @@ namespace BBWY.Server.Business.Sync
var productList = productBusiness.GetProductList(request);
if (productList == null || productList.Count == 0)
return;
SyncProduct(shop, productList);
SyncProduct(shop, productList, out string productId);
if (productList.Items.Count < 50 || !IsSyncAllProduct)
break;
request.PageIndex++;
@ -171,11 +181,11 @@ namespace BBWY.Server.Business.Sync
public void SyncAllShopAllProduct()
{
var shopList = venderBusiness.GetShopList();
//SyncProduct(shopList.FirstOrDefault(s => s.ShopId == "10388155"), 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), System.Threading.CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.ProductSyncTaskScheduler);
//}
}
}
}

10
BBWY.Server.Business/Sync/RefundOrderSyncBusiness.cs

@ -156,11 +156,11 @@ namespace BBWY.Server.Business
public void SyncAllShopRefundOrder()
{
var shopList = venderBusiness.GetShopList();
SyncRefundOrder(shopList.FirstOrDefault(s => s.ShopName == "赟娅墨森专卖店"), string.Empty, isAuto: true);
//foreach (var shop in shopList)
//{
// Task.Factory.StartNew(() => SyncRefundOrder(shop, string.Empty, isAuto: true), System.Threading.CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.SyncRefundOrderTaskScheduler);
//}
//SyncRefundOrder(shopList.FirstOrDefault(s => s.ShopName == "赟娅墨森专卖店"), string.Empty, isAuto: true);
foreach (var shop in shopList)
{
Task.Factory.StartNew(() => SyncRefundOrder(shop, string.Empty, isAuto: true), System.Threading.CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.SyncRefundOrderTaskScheduler);
}
}
}
}

2
BBWY.Test/Program.cs

@ -2,6 +2,7 @@
using Jd.Api.Request;
using Jd.Api.Response;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
namespace BBWY.Test
{
@ -14,6 +15,7 @@ namespace BBWY.Test
static void Main(string[] args)
{
var appKey = "120EA9EC65AB017567D78CC1139EEEA5";
var appSecret = "866a9877f5f24b03b537483b4defe75d";
var token = "2ace3023200c4ea9aa682bbf8bffee18jztm";

Loading…
Cancel
Save