|
|
@ -111,19 +111,26 @@ namespace BBWYB.Server.Business.Sync |
|
|
|
State = p.State, |
|
|
|
SyncTime = DateTime.Now, |
|
|
|
UpdateTime = DateTime.Now, |
|
|
|
UpperTime = p.CreateTime |
|
|
|
UpperTime = p.CreateTime, |
|
|
|
CategoryId = p.CategoryId, |
|
|
|
CategoryName = p.CategoryName |
|
|
|
})); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 找出变化的产品 (状态,标题)
|
|
|
|
var stateChangeProductList = productList.Where(p => dbProductList.Any(dp => dp.Id == p.Id && (dp.State != p.State || dp.ProductName != p.Title))).ToList(); |
|
|
|
var stateChangeProductList = productList.Where(p => dbProductList.Any(dp => dp.Id == p.Id && |
|
|
|
(dp.State != p.State || |
|
|
|
dp.ProductName != p.Title || |
|
|
|
dp.CategoryId != p.CategoryId))).ToList(); |
|
|
|
if (stateChangeProductList.Count() > 0) |
|
|
|
{ |
|
|
|
foreach (var product in stateChangeProductList) |
|
|
|
{ |
|
|
|
var update = fsql.Update<Product>(product.Id).Set(p => p.State, product.State) |
|
|
|
.Set(p => p.ProductName, product.Title); |
|
|
|
.Set(p => p.ProductName, product.Title) |
|
|
|
.Set(p => p.CategoryId, product.CategoryId) |
|
|
|
.Set(p => p.CategoryName, product.CategoryName); |
|
|
|
updateProductList.Add(update); |
|
|
|
} |
|
|
|
} |
|
|
@ -154,13 +161,20 @@ namespace BBWYB.Server.Business.Sync |
|
|
|
State = ps.State, |
|
|
|
SyncTime = DateTime.Now, |
|
|
|
UpdateTime = DateTime.Now, |
|
|
|
UpperTime = ps.CreateTime |
|
|
|
UpperTime = ps.CreateTime, |
|
|
|
CategoryId = ps.CategoryId, |
|
|
|
CategoryName = ps.CategoryName |
|
|
|
})); |
|
|
|
} |
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region 找出状态变化的SKU
|
|
|
|
var stateChangeProductSkuList = productSkuList.Where(ps => dbProductSkuList.Any(dps => dps.Id == ps.Id && (dps.State != ps.State || dps.SkuName != ps.Title || dps.Price != ps.Price || dps.Logo != ps.Logo))).ToList(); |
|
|
|
var stateChangeProductSkuList = productSkuList.Where(ps => dbProductSkuList.Any(dps => dps.Id == ps.Id && |
|
|
|
(dps.State != ps.State || |
|
|
|
dps.SkuName != ps.Title || |
|
|
|
dps.Price != ps.Price || |
|
|
|
dps.Logo != ps.Logo || |
|
|
|
dps.CategoryId != ps.CategoryId))).ToList(); |
|
|
|
if (stateChangeProductSkuList.Count() > 0) |
|
|
|
{ |
|
|
|
foreach (var productSku in stateChangeProductSkuList) |
|
|
@ -168,7 +182,9 @@ namespace BBWYB.Server.Business.Sync |
|
|
|
var update = fsql.Update<ProductSku>(productSku.Id).Set(p => p.State, productSku.State) |
|
|
|
.Set(p => p.SkuName, 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.CategoryId) |
|
|
|
.Set(p => p.CategoryName, productSku.CategoryName); |
|
|
|
updateProductSkuList.Add(update); |
|
|
|
} |
|
|
|
} |
|
|
@ -191,19 +207,68 @@ namespace BBWYB.Server.Business.Sync |
|
|
|
fsql.Insert(insertProductList).ExecuteAffrows(); |
|
|
|
if (insertProductSkuList.Count() > 0) |
|
|
|
fsql.Insert(insertProductSkuList).ExecuteAffrows(); |
|
|
|
}); |
|
|
|
|
|
|
|
{ |
|
|
|
var tempUpdateList = new List<IUpdate<Product>>(); |
|
|
|
if (updateProductList.Count() > 0) |
|
|
|
{ |
|
|
|
foreach (var update in updateProductList) |
|
|
|
update.ExecuteAffrows(); |
|
|
|
for (var i = 0; i < updateProductList.Count(); i++) |
|
|
|
{ |
|
|
|
tempUpdateList.Add(updateProductList[i]); |
|
|
|
if (tempUpdateList.Count() == 20) |
|
|
|
{ |
|
|
|
fsql.Transaction(() => |
|
|
|
{ |
|
|
|
foreach (var update in tempUpdateList) |
|
|
|
update.ExecuteAffrows(); |
|
|
|
}); |
|
|
|
tempUpdateList.Clear(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (tempUpdateList.Count() > 0) |
|
|
|
{ |
|
|
|
fsql.Transaction(() => |
|
|
|
{ |
|
|
|
foreach (var update in tempUpdateList) |
|
|
|
update.ExecuteAffrows(); |
|
|
|
}); |
|
|
|
tempUpdateList.Clear(); |
|
|
|
updateProductList.Clear(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
{ |
|
|
|
var tempUpdateList = new List<IUpdate<ProductSku>>(); |
|
|
|
if (updateProductSkuList.Count() > 0) |
|
|
|
{ |
|
|
|
foreach (var update in updateProductSkuList) |
|
|
|
update.ExecuteAffrows(); |
|
|
|
for (var i = 0; i < updateProductSkuList.Count(); i++) |
|
|
|
{ |
|
|
|
tempUpdateList.Add(updateProductSkuList[i]); |
|
|
|
if (tempUpdateList.Count() == 20) |
|
|
|
{ |
|
|
|
fsql.Transaction(() => |
|
|
|
{ |
|
|
|
foreach (var update in tempUpdateList) |
|
|
|
update.ExecuteAffrows(); |
|
|
|
}); |
|
|
|
tempUpdateList.Clear(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (tempUpdateList.Count() > 0) |
|
|
|
{ |
|
|
|
fsql.Transaction(() => |
|
|
|
{ |
|
|
|
foreach (var update in tempUpdateList) |
|
|
|
update.ExecuteAffrows(); |
|
|
|
}); |
|
|
|
tempUpdateList.Clear(); |
|
|
|
updateProductSkuList.Clear(); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Console.WriteLine($"{shop.ShopName}同步完毕,新增spu{insertProductList.Count()}个,新增sku{insertProductSkuList.Count()}个,更新spu{updateProductList.Count()}个,更新sku{updateProductSkuList.Count()}个"); |
|
|
|
} |
|
|
|