From e719ba2027bcc9a37d09de3c554a271feb1eb3f7 Mon Sep 17 00:00:00 2001 From: shanj <18996038927@163.com> Date: Tue, 26 Dec 2023 17:02:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=A7=E5=93=81=E5=90=8C?= =?UTF-8?q?=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sync/ProductSyncBusiness.cs | 87 ++++++++++++++++--- BBWYB.Server.Model/Db/Product/Product.cs | 11 +++ BBWYB.Server.Model/Db/Product/ProductSku.cs | 14 ++- .../QuanTan_Supplier_ProductListResponse.cs | 6 ++ ...QuanTan_Supplier_ProductSkuListResponse.cs | 5 +- .../Client/Impl/OP_QuanTanClient.cs | 8 +- .../Response/Product/OP_ProductResponse.cs | 10 +++ .../Response/Product/OP_ProductSkuResponse.cs | 10 +++ 8 files changed, 136 insertions(+), 15 deletions(-) diff --git a/BBWYB.Server.Business/Sync/ProductSyncBusiness.cs b/BBWYB.Server.Business/Sync/ProductSyncBusiness.cs index feeee0d..b9a9e04 100644 --- a/BBWYB.Server.Business/Sync/ProductSyncBusiness.cs +++ b/BBWYB.Server.Business/Sync/ProductSyncBusiness.cs @@ -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.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.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>(); 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>(); 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()}个"); } diff --git a/BBWYB.Server.Model/Db/Product/Product.cs b/BBWYB.Server.Model/Db/Product/Product.cs index ee4f128..942d593 100644 --- a/BBWYB.Server.Model/Db/Product/Product.cs +++ b/BBWYB.Server.Model/Db/Product/Product.cs @@ -49,6 +49,17 @@ namespace BBWYB.Server.Model.Db [Column(DbType = "datetime")] public DateTime? UpperTime { get; set; } + /// + /// 分类Id + /// + [Column(DbType = "bigint")] + public long? CategoryId { get; set; } + + /// + /// 分类名称 + /// + [Column(StringLength = 50)] + public string CategoryName { get; set; } } } diff --git a/BBWYB.Server.Model/Db/Product/ProductSku.cs b/BBWYB.Server.Model/Db/Product/ProductSku.cs index 0a385ba..5a943c1 100644 --- a/BBWYB.Server.Model/Db/Product/ProductSku.cs +++ b/BBWYB.Server.Model/Db/Product/ProductSku.cs @@ -54,6 +54,18 @@ namespace BBWYB.Server.Model.Db [Column(DbType = "datetime")] public DateTime? UpperTime { get; set; } - } + /// + /// 分类Id + /// + [Column(DbType = "bigint")] + public long? CategoryId { get; set; } + + /// + /// 分类名称 + /// + [Column(StringLength = 50)] + public string CategoryName { get; set; } + + } } diff --git a/QuanTan.SDK/Models/Supplier/Response/Product/QuanTan_Supplier_ProductListResponse.cs b/QuanTan.SDK/Models/Supplier/Response/Product/QuanTan_Supplier_ProductListResponse.cs index 49f68d0..a0c9e7c 100644 --- a/QuanTan.SDK/Models/Supplier/Response/Product/QuanTan_Supplier_ProductListResponse.cs +++ b/QuanTan.SDK/Models/Supplier/Response/Product/QuanTan_Supplier_ProductListResponse.cs @@ -15,6 +15,12 @@ public int? Status { 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 diff --git a/QuanTan.SDK/Models/Supplier/Response/Product/QuanTan_Supplier_ProductSkuListResponse.cs b/QuanTan.SDK/Models/Supplier/Response/Product/QuanTan_Supplier_ProductSkuListResponse.cs index ec89b75..d3adf89 100644 --- a/QuanTan.SDK/Models/Supplier/Response/Product/QuanTan_Supplier_ProductSkuListResponse.cs +++ b/QuanTan.SDK/Models/Supplier/Response/Product/QuanTan_Supplier_ProductSkuListResponse.cs @@ -13,8 +13,11 @@ public string SkuImage { 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; } diff --git a/SDKAdapter/OperationPlatform/Client/Impl/OP_QuanTanClient.cs b/SDKAdapter/OperationPlatform/Client/Impl/OP_QuanTanClient.cs index df103e0..b513adc 100644 --- a/SDKAdapter/OperationPlatform/Client/Impl/OP_QuanTanClient.cs +++ b/SDKAdapter/OperationPlatform/Client/Impl/OP_QuanTanClient.cs @@ -46,7 +46,9 @@ namespace SDKAdapter.OperationPlatform.Client Logo = qtp.Image, ProductItemNum = string.Empty, State = qtp.IsShow == 1 && qtp.Status == 1 ? 1 : 0, - Title = qtp.ProductName + Title = qtp.ProductName, + CategoryId = qtp.CategoryId, + CategoryName = qtp.CategoryName }).ToList() }; } @@ -76,7 +78,9 @@ namespace SDKAdapter.OperationPlatform.Client Price = qtps.SkuPrice, ProductId = qtps.ProductId, State = qtps.IsShow == 1 && qtps.Status == 1 ? 1 : 0, - Title = qtps.SkuName + Title = qtps.SkuName, + CategoryId = qtps.CategoryId, + CategoryName = qtps.CategoryName }).ToList() }; } diff --git a/SDKAdapter/OperationPlatform/Models/Response/Product/OP_ProductResponse.cs b/SDKAdapter/OperationPlatform/Models/Response/Product/OP_ProductResponse.cs index 4f6b3b9..5dc1a8a 100644 --- a/SDKAdapter/OperationPlatform/Models/Response/Product/OP_ProductResponse.cs +++ b/SDKAdapter/OperationPlatform/Models/Response/Product/OP_ProductResponse.cs @@ -32,6 +32,16 @@ /// 商品品牌名称 /// public string BrandName { get; set; } + + /// + /// 分类Id + /// + public long? CategoryId { get; set; } + + /// + /// 分类名称 + /// + public string CategoryName { get; set; } } } diff --git a/SDKAdapter/OperationPlatform/Models/Response/Product/OP_ProductSkuResponse.cs b/SDKAdapter/OperationPlatform/Models/Response/Product/OP_ProductSkuResponse.cs index 3d39a54..bf72943 100644 --- a/SDKAdapter/OperationPlatform/Models/Response/Product/OP_ProductSkuResponse.cs +++ b/SDKAdapter/OperationPlatform/Models/Response/Product/OP_ProductSkuResponse.cs @@ -29,5 +29,15 @@ public DateTime? CreateTime { get; set; } //public JToken Source { get; set; } + + /// + /// 分类Id + /// + public long? CategoryId { get; set; } + + /// + /// 分类名称 + /// + public string CategoryName { get; set; } } }