Browse Source

Sku删除逻辑

AddValidOverTime
shanji 2 years ago
parent
commit
b2c06a9ba7
  1. 23
      BBWY.Server.Business/Sync/ProductSyncBusiness.cs

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

@ -68,6 +68,7 @@ namespace BBWY.Server.Business.Sync
List<ProductSku> inserSkuList = new List<ProductSku>(); List<ProductSku> inserSkuList = new List<ProductSku>();
List<IUpdate<ProductSku>> updateProductSkuList = new List<IUpdate<ProductSku>>(); List<IUpdate<ProductSku>> updateProductSkuList = new List<IUpdate<ProductSku>>();
List<string> deletedSkuIdList = new List<string>();
var productIds = productList.Items.Select(p => p.Id); var productIds = productList.Items.Select(p => p.Id);
var dbProducts = fsql.Select<Product>().Where(p => p.ShopId == shopId && productIds.Contains(p.Id)).ToList(); var dbProducts = fsql.Select<Product>().Where(p => p.ShopId == shopId && productIds.Contains(p.Id)).ToList();
@ -89,6 +90,13 @@ namespace BBWY.Server.Business.Sync
}); });
if (skuList == null || skuList.Count() == 0) if (skuList == null || skuList.Count() == 0)
continue; continue;
//排查已删除的sku
var currentDbSkus = dbProductSkus.Where(dbsku => dbsku.ProductId == product.Id).ToList();
var deletedSkuList = currentDbSkus.Where(dbsku => skuList.Count(s => s.Id == dbsku.Id) == 0).ToList();
if (deletedSkuList.Count() > 0)
deletedSkuIdList.AddRange(deletedSkuList.Select(dbsku => dbsku.Id));
foreach (var sku in skuList) foreach (var sku in skuList)
{ {
var categoryId = sku.Source.Value<int>("categoryId"); var categoryId = sku.Source.Value<int>("categoryId");
@ -159,6 +167,8 @@ namespace BBWY.Server.Business.Sync
if (updateProductSkuList.Count > 0) if (updateProductSkuList.Count > 0)
foreach (var update in updateProductSkuList) foreach (var update in updateProductSkuList)
update.ExecuteAffrows(); update.ExecuteAffrows();
if (deletedSkuIdList.Count() > 0)
fsql.Delete<ProductSku>(deletedSkuIdList).ExecuteAffrows();
}); });
} }
@ -179,7 +189,8 @@ namespace BBWY.Server.Business.Sync
AppKey = shop.AppKey, AppKey = shop.AppKey,
AppSecret = shop.AppSecret, AppSecret = shop.AppSecret,
AppToken = shop.AppToken, AppToken = shop.AppToken,
Platform = shop.PlatformId Platform = shop.PlatformId,
Spu = "10021182557318"
}; };
while (true) while (true)
{ {
@ -219,11 +230,11 @@ namespace BBWY.Server.Business.Sync
public void SyncAllShopAllProduct() public void SyncAllShopAllProduct()
{ {
var shopList = venderBusiness.GetShopList(); var shopList = venderBusiness.GetShopList();
//SyncProduct(shopList.FirstOrDefault(s => s.ShopName == "奥德汽车用品专营店"), true); SyncProduct(shopList.FirstOrDefault(s => s.ShopName == "趣弈手机配件专营店"), true);
foreach (var shop in shopList) //foreach (var shop in shopList)
{ //{
Task.Factory.StartNew(() => SyncProduct(shop, true), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.ProductSyncTaskScheduler); // Task.Factory.StartNew(() => SyncProduct(shop, true), CancellationToken.None, TaskCreationOptions.LongRunning, taskSchedulerManager.ProductSyncTaskScheduler);
} //}
} }
} }
} }

Loading…
Cancel
Save