public void SaveListingsData(List <T_Am_ListingData> lds) { AmazonDataAccess dataAccess = new AmazonDataAccess(); try { //先删除该店类所有产品 dataAccess.deleteAmazonListingData(lds[0].pid.ToString()); //DbHelper.Insert("T_Am_ListingData", lds); } catch (Exception EX) { Log.ErrorFormat("初始化数据失败:{0}", EX); } //List<string> lstEle = new List<string>(); ////SalaryDetailModel model = new SalaryDetailModel(); //foreach (PropertyInfo prop in typeof(T_Am_ListingData).GetProperties()) //{ // if (prop.Name.ToLower() == "id") continue; // lstEle.Add(prop.Name); //} //lds = lds.Take(100).ToList(); //try //{ // var result = SqlServerRepo.ExecuteInsertOrUpdateSqlTran(lds, "T_Am_ListingData", sqlConnectionString, new string[] { "pid", "listing_id", "product_id" }, // //lstEle.ToArray(), lstEle.ToArray(), // null, null, // 50, 10); //} //catch (Exception ex) //{ //} //return; List <T_Am_ListingData> existsList = new List <T_Am_ListingData>(); List <T_Am_ListingData> notExistsList = new List <T_Am_ListingData>(); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); doBusiness(lds, ref existsList, ref notExistsList, dataAccess); stopwatch.Stop(); Log.Info("查询产品是否存在花费时间:" + (Int32)stopwatch.ElapsedMilliseconds / 1000 + "秒!"); DbHelper.Insert("T_Am_ListingData", notExistsList); //lds[0].item_name = lds[0].item_name + " 查询条件 exec('select top 1 * from T_Am_ListingData')"; DbHelper.Insert("T_Am_ListingDataInsert", lds); StringBuilder sb = new StringBuilder(); sb.AppendFormat(@" UPDATE T_Am_ListingData SET item_name = tbInsert.item_name , item_description = tbInsert.Item_description , seller_sku = tbInsert.seller_sku , price = tbInsert.price , quantity = tbInsert.quantity , open_date = tbInsert.open_date , image_url = tbInsert.image_url , item_is_marketplace = tbInsert.item_is_marketplace , product_id_type = tbInsert.product_id_type , zshop_shipping_fee = tbInsert.zshop_shipping_fee , item_note = tbInsert.item_note , item_condition = tbInsert.item_condition , zshop_category1 = tbInsert.zshop_category1 , zshop_browse_path = tbInsert.zshop_browse_path , zshop_storefront_feature = tbInsert.zshop_storefront_feature , asin1 = tbInsert.asin1 , asin2 = tbInsert.asin2 , asin3 = tbInsert.asin3 , will_ship_internationally = tbInsert.will_ship_internationally , expedited_shipping = tbInsert.expedited_shipping , zshop_boldface = tbInsert.zshop_boldface , bid_for_featured_placement = tbInsert.bid_for_featured_placement , add_delete = tbInsert.add_delete , pending_quantity = tbInsert.pending_quantity , fulfillment_channel = tbInsert.fulfillment_channel , UpdateDateTime = tbInsert.UpdateDateTime , IsDel = tbInsert.IsDel FROM T_Am_ListingDataInsert tbInsert WHERE T_Am_ListingData.listing_id = tbInsert.listing_id AND T_Am_ListingData.product_id = tbInsert.listing_id AND T_Am_ListingData.pid = tbInsert.listing_id "); try { stopwatch.Restart(); //更新产品数据 dataAccess.updateAmazonListingData(lds[0].pid.ToString().ToString()); stopwatch.Stop(); Log.Info("更新产品数据花费时间:" + (Int32)stopwatch.ElapsedMilliseconds / 1000 + "秒!"); } catch (Exception EX) { Log.ErrorFormat("更新产品失败:{0}", EX); } //foreach (var ld in lds) //{ // try // { // int i = dataAccess.AddOrUpdateListingsData(ld); // if (count % 1000 == 0) // { // Log.InfoFormat("第:{0}条更新成功", i); // } // count++; // } // catch (Exception ex) // { // Log.ErrorFormat("保存:{0}发生错误{1}", ld.seller_sku, ex); // } //} }
void doBusiness(List <T_Am_ListingData> lds, ref List <T_Am_ListingData> existsList, ref List <T_Am_ListingData> notExistsList, AmazonDataAccess dataAccess) { DataTable dataTableExists = new DataTable(); try { int count = 1000; while (lds.Count > 0) { count = count > lds.Count ? lds.Count : count; List <T_Am_ListingData> list = lds.Take(count).ToList(); dataTableExists = dataAccess.queryAmazonListingData(list); if (dataTableExists != null && dataTableExists.Rows.Count > 0) { bool isExists; foreach (var entity in list) { isExists = false; foreach (DataRow row in dataTableExists.Rows) { if (row["pid"].ToString() == entity.pid.ToString() && row["listing_id"].ToString() == entity.listing_id && row["product_id"].ToString() == entity.product_id) { isExists = true; } } if (isExists) { existsList.Add(entity); } else { notExistsList.Add(entity); } } ; } else { notExistsList.AddRange(list); } SqlCommand command = new SqlCommand(); //command.Transaction = new SqlTransaction() //DbHelper.ExecuteNonQuery(tr) //lds = lds.Skip(count).ToList(); } } catch (Exception ex) { Log.Info("转换失败:" + ex); } }