private void UpdateProductLastUpdateAndValid(Product product, DBProductsTableAdapters.ProductTableAdapter productAdapter) { while (_isRunning) { try { if (productAdapter.Connection.State == ConnectionState.Closed) { productAdapter.Connection.Open(); } productAdapter.UpdateLastUpdateAndValid( product.Name, product.IDCategories, product.Price, product.Warranty, product.ImageUrl, product.IDCongTy, DateTime.Now, product.DetailUrl, product.Promotion, product.Summary, product.ProductContent, Common.UnicodeToKoDauFulltext(product.Name + " " + product.Domain), true, false, product.ShortDescription, product.IsDeal, product.OriginPrice, (int)product.Instock, (short)product.Status, product.PromotionInfo, product.ID); break; } catch (Exception ex) { Log.Error(string.Format("ProductId {0} : Update LastUpdate And Valid error.", product.ID), ex); Thread.Sleep(60000); } } }
private void InsertProductToSql(Product product, DBProductsTableAdapters.ProductTableAdapter productAdapter) { while (_isRunning) { try { productAdapter.InsertProduct( product.ID, product.Name, product.IDCategories, product.Price, product.Warranty, (short)product.Status, product.ImageUrl, product.IDCongTy, DateTime.Now, product.DetailUrl, 0, product.Promotion, product.Summary, product.ProductContent, Common.UnicodeToKoDauFulltext(product.Name + " " + product.Domain), true, DateTime.Now, true, product.HashName, 0, product.AddPosition, product.VATInfo, product.PromotionInfo, product.DeliveryInfo, product.OriginPrice, product.ShortDescription, product.IsDeal, (int)product.Instock); break; } catch (Exception ex) { Log.Error(string.Format("ProductId {0} : Insert error.", product.ID), ex); Thread.Sleep(60000); } } }
private void UpdateSingleProduct(Product product, JobClient updateProductJobClient, JobClient downloadImageProductJobClient) { #region Check Price //if (_isPriceBySku) //{ // if (_priceWithSku.ContainsKey(product.MerchantSku)) // { // product.Price = _priceWithSku[product.MerchantSku]; // } //} #endregion #region Check Promotion switch (_isPromotion) { //Không có Promotion case 0: product.PromotionInfo = ""; break; //Promotion theo Category case 1: try { product.PromotionInfo = _promotionLazadaWithCategory.ContainsKey(product.Categories[1]) ? _promotionLazadaWithCategory[product.Categories[1]] : _promotionLazadaWithCategory["Default"]; } catch (Exception exception) { Log.Error("Error check contain key " + exception.Message); } break; //Promotion theo SKU case 2: try { if (_promotionLazadaWithSku.ContainsKey(product.MerchantSku)) { product.PromotionInfo = _promotionLazadaWithSku[product.MerchantSku]; Log.Info("Promotion: " + product.ID + " --- " + _promotionLazadaWithSku[product.MerchantSku]); } else { product.PromotionInfo = ""; } } catch (Exception exception) { Log.Error("Error check contain key " + exception.Message); } break; } #endregion var productAdapter = new DBProductsTableAdapters.ProductTableAdapter(); productAdapter.Connection.ConnectionString = _connectionString; var productTable = new DBProducts.ProductDataTable(); while (_isRunning) { try { productAdapter.FillBy_ID(productTable, product.ID); break; } catch (Exception ex) { Log.Error(string.Format("ProductId {0} : Fill by ID error.", product.ID), ex); Thread.Sleep(60000); } } //InsertProduct if (productTable.Rows.Count == 0) { CheckClassificationInSql(product); InsertProductToSql(product, productAdapter); //Insert Price Log InsertPriceLog(product.ID, DateTime.Now, product.Price, 0); //Insert LogAddsProduct InsertLogAddProduct(product.IDCongTy, product.ID, product.Name, product.DetailUrl); SendMessageDownloadImageProduct(product, downloadImageProductJobClient, true); Log.Info(string.Format("CompanyId = {0} :Insert ProductId = {1} . Name = {2} . DetailUrl = {3}", product.IDCongTy, product.ID, product.Name, product.DetailUrl)); } else //UpdateProduct { var oldPrice = Common.Obj2Int(productTable.Rows[0]["Price"].ToString()); if (product.Price != oldPrice) { UpdateProductPriceChangeAndValid(product, productAdapter, oldPrice); //Insert Price Log InsertPriceLog(product.ID, DateTime.Now, product.Price, oldPrice); } else { UpdateProductLastUpdateAndValid(product, productAdapter); } if (productTable.Rows[0]["ImageId"] == DBNull.Value || string.IsNullOrEmpty(productTable.Rows[0]["ImageId"].ToString())) { SendMessageDownloadImageProduct(product, downloadImageProductJobClient, false); } Log.Info(string.Format("CompanyId = {0} :Update ProductId = {1} . Name = {2} . DetailUrl = {3}", product.IDCongTy, product.ID, product.Name, product.DetailUrl)); } productAdapter.Connection.Close(); var hashProductInfo = ProductEntity.GetHashChangeInfo((int)product.Instock, true, product.Price, product.Name, product.ImageUrl, product.IDCategories, product.ShortDescription, product.OriginPrice); if (RedisCacheProductDatafeed.CheckChangeInfoProduct(product.ID, hashProductInfo)) { SendMessageUpdateProductSolrAndRedisService(product, updateProductJobClient); } }