Browse Source

同步全部产品

qianyi
shanji 3 years ago
parent
commit
74d3ecde2a
  1. 11
      BBWY.Server.API/Controllers/ProductSyncController.cs
  2. 59
      BBWY.Server.Business/Sync/ProductSyncBusiness.cs

11
BBWY.Server.API/Controllers/ProductSyncController.cs

@ -14,12 +14,21 @@ namespace BBWY.Server.API.Controllers
} }
/// <summary> /// <summary>
/// 全店同步产品 /// 全店同步产品(前50)
/// </summary> /// </summary>
[HttpPost] [HttpPost]
public void SyncAllShopProduct() public void SyncAllShopProduct()
{ {
productSyncBusiness.SyncAllShopProduct(); productSyncBusiness.SyncAllShopProduct();
} }
/// <summary>
/// 全店同步产品(全部产品)
/// </summary>
[HttpPost]
public void SyncAllShopAllProduct()
{
productSyncBusiness.SyncAllShopAllProduct();
}
} }
} }

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

@ -37,24 +37,9 @@ namespace BBWY.Server.Business.Sync
this.productBusiness = productBusiness; this.productBusiness = productBusiness;
} }
private void SyncProduct(ShopResponse shop) private void SyncProduct(ShopResponse shop, ProductListResponse productList)
{
try
{ {
var shopId = long.Parse(shop.ShopId); var shopId = long.Parse(shop.ShopId);
var productList = productBusiness.GetProductList(new SearchProductRequest()
{
PageSize = 50,
PageIndex = 1,
AppKey = shop.AppKey,
AppSecret = shop.AppSecret,
AppToken = shop.AppToken,
Platform = shop.PlatformId
});
if (productList == null || productList.Count == 0)
return;
List<Product> insertProductList = new List<Product>(); List<Product> insertProductList = new List<Product>();
List<IUpdate<Product>> updateProductList = new List<IUpdate<Product>>(); List<IUpdate<Product>> updateProductList = new List<IUpdate<Product>>();
@ -135,6 +120,31 @@ namespace BBWY.Server.Business.Sync
}); });
} }
private void SyncProduct(ShopResponse shop, bool IsSyncAllProduct = false)
{
try
{
var request = new SearchProductRequest()
{
PageSize = 50,
PageIndex = 1,
AppKey = shop.AppKey,
AppSecret = shop.AppSecret,
AppToken = shop.AppToken,
Platform = shop.PlatformId
};
while (true)
{
var productList = productBusiness.GetProductList(request);
if (productList == null || productList.Count == 0)
return;
SyncProduct(shop, productList);
if (productList.Items.Count < 50 || !IsSyncAllProduct)
break;
request.PageIndex++;
}
}
catch (Exception ex) catch (Exception ex)
{ {
var shopData = JsonConvert.SerializeObject(shop); var shopData = JsonConvert.SerializeObject(shop);
@ -143,17 +153,30 @@ namespace BBWY.Server.Business.Sync
} }
/// <summary> /// <summary>
/// 同步所有店铺的订单 /// 同步所有店铺的前50个产品
/// </summary> /// </summary>
public void SyncAllShopProduct() public void SyncAllShopProduct()
{ {
var shopList = venderBusiness.GetShopList(); var shopList = venderBusiness.GetShopList();
//SyncProduct(shopList[0]); //SyncProduct(shopList.FirstOrDefault(s => s.ShopId == "10388155"), true); //布莱特玩具专营店
foreach (var shop in shopList) foreach (var shop in shopList)
{ {
Task.Factory.StartNew(() => SyncProduct(shop), System.Threading.CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.ProductSyncTaskScheduler); Task.Factory.StartNew(() => SyncProduct(shop), System.Threading.CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.ProductSyncTaskScheduler);
} }
} }
/// <summary>
/// 同步所有店铺的全部产品
/// </summary>
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);
}
}
} }
} }

Loading…
Cancel
Save