public static void InsertAllWebRootProductIntoCache(string productConnectionString, string userConnectionString, string searchEnginesServiceUrl) { var startTime = DateTime.Now; var products = WebRootProductBAL.GetAllWebRootProducts(productConnectionString, userConnectionString); var parts = products.Partition(100); foreach (var productPart in parts) { foreach (var product in productPart) { var rootProductMapping = RootProductMappingBAL.GetRootProductMappingFromCache(product.ID, 0, RootProductMappingSortType.PriceWithVAT, false); if (rootProductMapping == null) { RootProductMappingCacheTool.InsertRootProductMappingCache(product.ID, searchEnginesServiceUrl); rootProductMapping = RootProductMappingBAL.GetRootProductMappingFromCache(product.ID, 0, RootProductMappingSortType.PriceWithVAT, false); } if (rootProductMapping == null || rootProductMapping.NumMerchant == 0) { product.Price = 0; product.NumProduct = 0; } else { product.Price = rootProductMapping.MinPrice; product.NumProduct = rootProductMapping.NumMerchant; } } WebRootProductBAL.InsertWebRootProductsIntoCache(productPart); } var insertAllWebRootProductDuration = (DateTime.Now - startTime).TotalSeconds; Logger.InfoFormat("InsertAllWebRootProductIntoCache: {0} products. Duration: {1} s", products.Count, insertAllWebRootProductDuration); }
private void UpdateProductRootId(long rootId) { int rootIDtemp = 0; int.TryParse(rootId.ToString(), out rootIDtemp); if (rootIDtemp == 0) { Log.Error(string.Format("RootID = {0} vượt quá int =)) ", rootId)); return; } UpdateProductCategoryToZero((int)rootId); var rootProductMapping = RootProductMappingBAL.GetRootProductMappingFromCache(rootId, 0, RootProductMappingSortType.PriceWithVAT, true); if (rootProductMapping == null) { Log.WarnFormat("Get RootProductMapping return null! with ProductID = {0}", rootId); return; } if (rootProductMapping.ListMerchantProducts == null) { Log.WarnFormat("Root Product {0} have no product", rootId); return; } var dt = new DataTable(); dt.Columns.Add("ID", typeof(long)); dt.Columns.Add("ProductID", typeof(int)); dt.Columns.Add("CategoryID", typeof(int)); int categoryId = GetProductCategoryId(rootId); foreach (var productIdGroup in rootProductMapping.ListMerchantProducts) { foreach (var merchantProductId in productIdGroup.Value) { dt.Rows.Add(merchantProductId, rootId, categoryId); } } //Update ProductID và CategoryID các sản phẩm merchant theo nhận diện mới UpdateBulk(dt); Log.Info(string.Format("Update rootID for rootProduct {0} - {1} products", rootId, dt.Rows.Count)); }
public static bool InsertWebRootProductIntoCache(long productID, string productConnectionString, string userConnectionString, string searchEnginesServiceUrl) { var product = WebRootProductBAL.GetWebRootProduct(productID, productConnectionString, userConnectionString); if (product == null) { return(false); } var rootProductMapping = RootProductMappingBAL.GetRootProductMappingFromCache(product.ID, 0, RootProductMappingSortType.PriceWithVAT, false); if (rootProductMapping == null) { RootProductMappingCacheTool.InsertRootProductMappingCache(product.ID, searchEnginesServiceUrl); rootProductMapping = RootProductMappingBAL.GetRootProductMappingFromCache(product.ID, 0, RootProductMappingSortType.PriceWithVAT, false); if (rootProductMapping == null) { return(false); } } product.Price = rootProductMapping.MinPrice; product.NumProduct = rootProductMapping.NumMerchant; return(WebRootProductBAL.InsertWebRootProductsIntoCache(new[] { product })); }