示例#1
0
 protected override void Do()
 {
     int count = 0;
     DoQuery(null,maps => count = maps.Count());
     int cursor = 0;
     const int pageSize = 200;
     var request = new DownItemRequest();
     while (cursor < count)
     {
         IEnumerable<string> maps = null;
         DoQuery(null,items => maps = items.OrderBy(t=>t.Id).Skip(cursor).Take(pageSize).Select(t=>t.ChannelProductId).ToList());
         request.Put(ParamName.Param_ItemList,string.Join("|",maps));
         request.Remove("sign");
         var rsp = Client.Execute<dynamic>(request);
         if (rsp.errorCode == 0)
         {
             Logger.Info(string.Format("共计下架商品({0})", maps.Count()));
         }
         else if (rsp.errorCode == 40005) //部分失败
         {
             string failList = rsp.failList;
             Logger.Error(failList);
         }
         else
         {
             Logger.Error(rsp.errorMessage);
         }
         cursor += pageSize;
     }
 }
        private void SyncOne(ProductEntity item)
        {
            int productId = item.Id;
            using (var db = DbContextHelper.GetDbContext())
            {
                var map =
                    db.Map4Products.FirstOrDefault(
                        m => m.ProductId == productId && m.Channel == ConstValue.WGW_CHANNEL_NAME);
                if (map == null)
                {
                    _failedCount += 1;
                    throw new WgwSyncException(string.Format("Unmapped product ID:({0})", item.Id));
                }
                var idList = new List<string>() {map.ChannelProductId};
                ISyncRequest reqeust = null;
                if (item.Is4Sale.HasValue && item.Is4Sale.Value && item.IsHasImage && item.Status == 1)
                {

                        reqeust = new UpItemRequest(idList);
                        var rsp = Client.Execute<dynamic>(reqeust);
                        if (rsp.errorCode == 0)
                        {
                            _succeedCount += 1;
                            map.Status = 1;
                            map.UpdateDate = DateTime.Now;
                            db.SaveChanges();
                            Logger.Error(string.Format("Succeed publish product {0}", item.Id));
                        }
                        else
                        {
                            _failedCount += 1;
                            Logger.Error(string.Format("Failed to publish product {0}", item.Id));
                        }
           
                }
                else
                {
                    reqeust = new DownItemRequest(idList);
                    var rsp = Client.Execute<dynamic>(reqeust);
                    if (rsp.errorCode == 0)
                    {
                        _succeedCount += 1;
                        map.Status = 0;
                        map.UpdateDate = DateTime.Now;
                        db.SaveChanges();
                        Logger.Error(string.Format("Succeed Down product {0}", item.Id));
                    }
                    else
                    {
                        _failedCount += 1;
                        Logger.Error(string.Format("Failed to Down product {0}", item.Id));
                    }
                }
            }
        }