Browse Source

更新产品同步

liangku_skuoptimazation
shanji 1 year ago
parent
commit
e719ba2027
  1. 87
      BBWYB.Server.Business/Sync/ProductSyncBusiness.cs
  2. 11
      BBWYB.Server.Model/Db/Product/Product.cs
  3. 14
      BBWYB.Server.Model/Db/Product/ProductSku.cs
  4. 6
      QuanTan.SDK/Models/Supplier/Response/Product/QuanTan_Supplier_ProductListResponse.cs
  5. 5
      QuanTan.SDK/Models/Supplier/Response/Product/QuanTan_Supplier_ProductSkuListResponse.cs
  6. 8
      SDKAdapter/OperationPlatform/Client/Impl/OP_QuanTanClient.cs
  7. 10
      SDKAdapter/OperationPlatform/Models/Response/Product/OP_ProductResponse.cs
  8. 10
      SDKAdapter/OperationPlatform/Models/Response/Product/OP_ProductSkuResponse.cs

87
BBWYB.Server.Business/Sync/ProductSyncBusiness.cs

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

11
BBWYB.Server.Model/Db/Product/Product.cs

@ -49,6 +49,17 @@ namespace BBWYB.Server.Model.Db
[Column(DbType = "datetime")] [Column(DbType = "datetime")]
public DateTime? UpperTime { get; set; } public DateTime? UpperTime { get; set; }
/// <summary>
/// 分类Id
/// </summary>
[Column(DbType = "bigint")]
public long? CategoryId { get; set; }
/// <summary>
/// 分类名称
/// </summary>
[Column(StringLength = 50)]
public string CategoryName { get; set; }
} }
} }

14
BBWYB.Server.Model/Db/Product/ProductSku.cs

@ -54,6 +54,18 @@ namespace BBWYB.Server.Model.Db
[Column(DbType = "datetime")] [Column(DbType = "datetime")]
public DateTime? UpperTime { get; set; } public DateTime? UpperTime { get; set; }
} /// <summary>
/// 分类Id
/// </summary>
[Column(DbType = "bigint")]
public long? CategoryId { get; set; }
/// <summary>
/// 分类名称
/// </summary>
[Column(StringLength = 50)]
public string CategoryName { get; set; }
}
} }

6
QuanTan.SDK/Models/Supplier/Response/Product/QuanTan_Supplier_ProductListResponse.cs

@ -15,6 +15,12 @@
public int? Status { get; set; } public int? Status { get; set; }
public DateTime? UpperTime { get; set; } public DateTime? UpperTime { get; set; }
public long? CategoryId { get; set; }
public string CategoryName { get; set; }
public string CategoryPath { get; set; }
} }
public class QuanTan_Supplier_ProductListResponse : QuanTanListResponse<QuanTan_Supplier_Product> public class QuanTan_Supplier_ProductListResponse : QuanTanListResponse<QuanTan_Supplier_Product>

5
QuanTan.SDK/Models/Supplier/Response/Product/QuanTan_Supplier_ProductSkuListResponse.cs

@ -13,8 +13,11 @@
public string SkuImage { get; set; } public string SkuImage { get; set; }
public decimal SkuPrice { get; set; } public decimal SkuPrice { get; set; }
public long? CategoryId { get; set; }
public string CategoryId { get; set; } public string CategoryName { get; set; }
public string CategoryPath { get; set; }
public string StoreId { get; set; } public string StoreId { get; set; }

8
SDKAdapter/OperationPlatform/Client/Impl/OP_QuanTanClient.cs

@ -46,7 +46,9 @@ namespace SDKAdapter.OperationPlatform.Client
Logo = qtp.Image, Logo = qtp.Image,
ProductItemNum = string.Empty, ProductItemNum = string.Empty,
State = qtp.IsShow == 1 && qtp.Status == 1 ? 1 : 0, State = qtp.IsShow == 1 && qtp.Status == 1 ? 1 : 0,
Title = qtp.ProductName Title = qtp.ProductName,
CategoryId = qtp.CategoryId,
CategoryName = qtp.CategoryName
}).ToList() }).ToList()
}; };
} }
@ -76,7 +78,9 @@ namespace SDKAdapter.OperationPlatform.Client
Price = qtps.SkuPrice, Price = qtps.SkuPrice,
ProductId = qtps.ProductId, ProductId = qtps.ProductId,
State = qtps.IsShow == 1 && qtps.Status == 1 ? 1 : 0, State = qtps.IsShow == 1 && qtps.Status == 1 ? 1 : 0,
Title = qtps.SkuName Title = qtps.SkuName,
CategoryId = qtps.CategoryId,
CategoryName = qtps.CategoryName
}).ToList() }).ToList()
}; };
} }

10
SDKAdapter/OperationPlatform/Models/Response/Product/OP_ProductResponse.cs

@ -32,6 +32,16 @@
/// 商品品牌名称 /// 商品品牌名称
/// </summary> /// </summary>
public string BrandName { get; set; } public string BrandName { get; set; }
/// <summary>
/// 分类Id
/// </summary>
public long? CategoryId { get; set; }
/// <summary>
/// 分类名称
/// </summary>
public string CategoryName { get; set; }
} }
} }

10
SDKAdapter/OperationPlatform/Models/Response/Product/OP_ProductSkuResponse.cs

@ -29,5 +29,15 @@
public DateTime? CreateTime { get; set; } public DateTime? CreateTime { get; set; }
//public JToken Source { get; set; } //public JToken Source { get; set; }
/// <summary>
/// 分类Id
/// </summary>
public long? CategoryId { get; set; }
/// <summary>
/// 分类名称
/// </summary>
public string CategoryName { get; set; }
} }
} }

Loading…
Cancel
Save