Exemple #1
0
        public List <string> Getimg(string user_id, string kid, string projectId)
        {
            MongoDBClass <FreeBotItem> helper = new MongoDBClass <FreeBotItem>();
            var queryTask = new QueryDocument {
                { "UId", new ObjectId(user_id) }, { "taskId", new ObjectId(kid) }, { "ProjectId", new ObjectId(projectId) }
            };
            FieldsDocument fd = new FieldsDocument();

            fd.Add("pic_url", 1);
            List <FreeBotItem>            list = new List <FreeBotItem>();
            MongoCollection <FreeBotItem> col  = new MongoDBClass <FreeBotItem>().GetMongoDB().GetCollection <FreeBotItem>("FreeBotItem");
            SortByDocument s = new SortByDocument();

            s.Add("Recent30DaysSoldNum", -1);//获取数据时进行排序,-1为降序
            var           TaskList = col.Find(queryTask).SetSortOrder(s).SetLimit(10).SetFields(fd);
            List <string> str      = new List <string>();

            foreach (var item in TaskList)
            {
                string v;
                v = "http:" + item.pic_url;
                str.Add(v);
            }
            return(str);
        }
Exemple #2
0
 public double?Get30VgePrice(string user_id, string kid, string projectId)
 {
     try
     {
         //var col = MongoDBHelper.Instance.Get_FreeBotItem();
         //var queryTask = new QueryDocument { { "UId", new ObjectId(user_id) }, { "taskId", new ObjectId(kid) } };
         //List<FreeBotItem> list = new List<FreeBotItem>();
         //FieldsDocument fd = new FieldsDocument();
         //fd.Add("Price", 1);
         //var TaskList = col.Find(queryTask).ToList();
         //double? matchSum = TaskList.Sum(x => x.Price);
         //double? vgePrice = matchSum / TaskList.Count();
         //return vgePrice;
         MongoDBClass <FreeBotItem> helper = new MongoDBClass <FreeBotItem>();
         var queryTask = new QueryDocument {
             { "UId", new ObjectId(user_id) }, { "taskId", new ObjectId(kid) }, { "ProjectId", new ObjectId(projectId) }
         };
         //var TaskList = helper.FindData("level1link", queryTask);
         List <FreeBotItem> list = new List <FreeBotItem>();
         FieldsDocument     fd   = new FieldsDocument();
         fd.Add("Price", 1);
         MongoCollection <FreeBotItem> col = new MongoDBClass <FreeBotItem>().GetMongoDB().GetCollection <FreeBotItem>("FreeBotItem");
         var    TaskList = col.Find(queryTask).SetFields(fd);
         double?matchSum = TaskList.Sum(x => x.Price);
         double?vgePrice = matchSum / TaskList.Count();
         return(vgePrice);
     }
     catch (Exception)
     {
         return(0);
     }
 }
Exemple #3
0
 public long?Get30SaleNum(string user_id, string kid, string projectId)
 {
     try
     {
         MongoDBClass <FreeBotItem> helper = new MongoDBClass <FreeBotItem>();
         //var TaskList = helper.FindData("level1link", queryTask);
         var queryTask = new QueryDocument {
             { "UId", new ObjectId(user_id) }, { "taskId", new ObjectId(kid) }, { "ProjectId", new ObjectId(projectId) }
         };
         List <FreeBotItem> list = new List <FreeBotItem>();
         FieldsDocument     fd   = new FieldsDocument();
         fd.Add("Recent30DaysSoldNum", 1);
         MongoCollection <FreeBotItem> col = new MongoDBClass <FreeBotItem>().GetMongoDB().GetCollection <FreeBotItem>("FreeBotItem");
         var TaskList = col.Find(queryTask).SetFields(fd);
         var matchSum = TaskList.Sum(x => x.Recent30DaysSoldNum);//计算该关键词30天内总销售量
         return(matchSum);
         //var col = MongoDBHelper.Instance.Get_FreeBotItem();
         //var queryTask = new QueryDocument { { "UId", new ObjectId(user_id) }, { "taskId", new ObjectId(kid) } };
         //List<FreeBotItem> list = new List<FreeBotItem>();
         //FieldsDocument fd = new FieldsDocument();
         //fd.Add("Recent30DaysSoldNum", 1);
         //var agreresult = col.Find(queryTask).ToList();
         //var matchSum = agreresult.Sum(x => x.Recent30DaysSoldNum);
         //return matchSum;
     }
     catch (Exception wc)
     {
         return(0);
     }
 }
Exemple #4
0
        public List <FreeBotItemDto> GetItemList(string user_id, string kid, int?pagesize, string projectId)
        {
            try
            {
                MongoDBClass <FreeBotItem> helper = new MongoDBClass <FreeBotItem>();
                var queryTask = new QueryDocument {
                    { "UId", new ObjectId(user_id) }, { "taskId", new ObjectId(kid) }, { "ProjectId", new ObjectId(projectId) }
                };
                List <FreeBotItemDto> list = new List <FreeBotItemDto>();
                FieldsDocument        fd   = new FieldsDocument();
                fd.Add("Location", 1);
                fd.Add("Price", 1);
                fd.Add("Recent30DaysSoldNum", 1);
                MongoCollection <FreeBotItem> col = new MongoDBClass <FreeBotItem>().GetMongoDB().GetCollection <FreeBotItem>("FreeBotItem");
                var TaskList = col.Find(queryTask).SetFields(fd);
                foreach (var item in TaskList)
                {
                    if (!string.IsNullOrEmpty(item.Location))
                    {
                        FreeBotItemDto v   = new FreeBotItemDto();
                        var            str = item.Location.Split(' ');
                        if (str.Length > 1)
                        {
                            v.Location = str[1];
                        }
                        else
                        {
                            v.Location = str[0];
                        }
                        v.salesAmount = item.Price * item.Recent30DaysSoldNum;
                        list.Add(v);
                    }
                }

                List <FreeBotItemDto> am = new List <FreeBotItemDto>();
                var ary = from t in list
                          group t by new { t.Location } into g
                    select new FreeBotItemDto
                {
                    _id         = Guid.NewGuid().ToString(),
                    Location    = g.Key.Location,
                    salesAmount = g.Sum(p => p.salesAmount),
                    SalesVolume = Math.Round(Convert.ToDouble(g.Sum(p => p.salesAmount)), 2).ToString("C2", new CultureInfo("zh-CN"))          //C2为保留两位小数,new CultureInfo("zh-CN")为添加货币符号(中国)
                };
                if (pagesize.HasValue)
                {
                    return(ary.OrderByDescending(x => x.salesAmount).Take(Convert.ToInt16(pagesize)).ToList());
                }
                else
                {
                    return(ary.OrderByDescending(x => x.salesAmount).ToList());
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemple #5
0
 public List <FreeWebSite> GetWebSite(string user_id, string kid, string projectId)
 {
     try
     {
         MongoDBClass <FreeBotItem> helper = new MongoDBClass <FreeBotItem>();//多余语句
         // int user_id = WebSecurity.GetUserId(User.Identity.Name);
         var queryTask = new QueryDocument {
             { "UId", new ObjectId(user_id) }, { "projectId", new ObjectId(projectId) }
         };
         List <FreeBotItem> list = new List <FreeBotItem>();
         FieldsDocument     fd   = new FieldsDocument();//设置要提取的列,1表示同意提取
         fd.Add("SiteId", 1);
         fd.Add("SiteName", 1);
         MongoCollection <FreeBotItem> col = new MongoDBClass <FreeBotItem>().GetMongoDB().GetCollection <FreeBotItem>("FreeBotItem");//旧式MongoDB使用方法
         var TaskList          = col.Find(queryTask).SetFields(fd);
         List <FreeWebSite> am = new List <FreeWebSite>();
         var ary = from t in TaskList
                   group t by new { t.SiteId, t.SiteName } into g
             select new FreeWebSite
         {
             _id      = g.Key.SiteId.ToString(),
             SiteName = g.Key.SiteName
         };          //以siteId,SiteName列进行分组,key为当前所处组
         return(ary.ToList());
         //var builder = Builders<FreeBotItem>.Filter;
         //var filter = builder.Eq(x => x.UId, new ObjectId(user_id));
         //var TaskList = MongoDBHelper.Instance.Get_FreeBotItem().Find(filter).ToList();
         //List<FreeWebSite> am = new List<FreeWebSite>();
         //var ary = from t in TaskList
         //          group t by new { t.SiteId, t.SiteName } into g
         //          select new FreeWebSite
         //          {
         //              _id = g.Key.SiteId.ToString(),
         //              SiteName = g.Key.SiteName
         //          };
         //return ary.ToList();
     }
     catch (Exception)
     {
         return(null);
     }
 }
Exemple #6
0
 public List <FreeBotItemDto> GetBotResultList(string user_id, string kid, string projectId)
 {
     try
     {
         MongoDBClass <FreeBotItem> helper = new MongoDBClass <FreeBotItem>();
         var queryTask = new QueryDocument {
             { "UId", new ObjectId(user_id) }, { "taskId", new ObjectId(kid) }, { "ProjectId", new ObjectId(projectId) }
         };
         List <FreeBotItemDto> list = new List <FreeBotItemDto>();
         FieldsDocument        fd   = new FieldsDocument();
         fd.Add("_id", 1);
         fd.Add("ShopName", 1);
         fd.Add("Location", 1);
         fd.Add("Recent30DaysSoldNum", 1);
         fd.Add("ItemName", 1);
         fd.Add("Price", 1);
         fd.Add("CreatedAt", 1);
         MongoCollection <FreeBotItem> col = new MongoDBClass <FreeBotItem>().GetMongoDB().GetCollection <FreeBotItem>("FreeBotItem");
         SortByDocument so = new SortByDocument();
         so.Add("CreatedAt", -1);
         var TaskList = col.Find(queryTask).SetSortOrder(so).SetFields(fd);
         foreach (var item in TaskList)
         {
             FreeBotItemDto v = new FreeBotItemDto();
             v._id                 = item._id.ToString();
             v.ShopName            = item.ShopName;
             v.Location            = item.Location;
             v.ItemName            = item.ItemName;
             v.Price               = item.Price;
             v.Recent30DaysSoldNum = item.Recent30DaysSoldNum;
             list.Add(v);
         }
         return(list);
     }
     catch (Exception)
     {
         return(null);
     }
 }
Exemple #7
0
        public void save_level1_links(List <IW2S_level1link> links,
                                      IW2S_BaiduCommend tsk, List <IW2S_ExcludeKeyword> excludedKeywords)
        {
            links = prehandle_data(links, tsk, excludedKeywords);

            if (links == null || links.Count == 0)
            {
                log("SUCCESS saving 0 Level 1 Links for " + tsk.CommendKeyword);
                return;
            }

            int pagesize = 100;
            int count    = 0;
            var col      = MongoDBHelper.Instance.GetIW2S_level1links();
            var builder  = Builders <IW2S_level1link> .Filter;

            for (int page = 0; page *pagesize < links.Count; page++)
            {
                var list = links.Skip(page * pagesize).Take(pagesize).ToList();
                //list.ForEach(x => x._id = new MongoDB.Bson.ObjectId(IDHelper.GetGuid("{0}/&itemid={1}".FormatStr(x.Domain, x.LinkUrl)).ToString()));
                list = ListDistinctBy(list, x => x.BizId);

                // FieldsDocument fd = new FieldsDocument();

                List <Guid> BizId = list.Select(x => x.BizId).ToList();

                Guid sdsdsd = Guid.Parse(BizId[0].ToString());
                MongoDBClass <IW2S_level1link> helper = new MongoDBClass <IW2S_level1link>();
                var queryTask = new QueryDocument {
                    { "BizId", sdsdsd }
                };
                FieldsDocument fd = new FieldsDocument();
                fd.Add("BizId", 1);
                MongoCollection <IW2S_level1link> colww = new MongoDBClass <IW2S_level1link>().GetMongoDB().GetCollection <IW2S_level1link>("IW2S_level1link");
                var TaskList = colww.Find(queryTask).SetFields(fd);
                var sdsds    = TaskList.Count();
                if (sdsds > 0)
                {
                }
                else
                {
                    count += pagesize;

                    col.InsertMany(links);
                    log("SUCCESS saving " + links.Count + " Level 1 Links for " + tsk.CommendKeyword);
                }

                //         var exists_objs = col.Find(builder.Eq(x => x.BizId, sdsdsd)).Project(x => x.BizId).ToList();
                //List<Guid> exists_ids = new List<Guid>();
                //foreach (var result in exists_objs)
                //{
                //    exists_ids.Add(result);
                //}
                //if(exists_ids !=null && exists_ids.Count >0)
                //{
                //    list = list.Where(x => !exists_ids.Contains(x.BizId)).ToList();
                //}
                //if(list==null || list.Count ==0)
                //    continue ;
            }
        }
Exemple #8
0
        public List <FreeBotItemVo> GetBubbleList(string user_id, string kid, int?pagesize, string projectId)
        {
            var queryl = new QueryDocument {
                { "UId", new ObjectId(user_id) }, { "taskId", new ObjectId(kid) }
            };
            var colFS = MongoDBHelper.Instance.Get_FreeShopTimeline();
            var aryl  = colFS.Find(queryl).SortByDescending(x => x.Recent30DaysSoldNum).ToList();
            List <FreeBotItemDto> fst = new List <FreeBotItemDto>();

            if (aryl.Count > 0)
            {
                foreach (var item in aryl)
                {
                    FreeBotItemDto fstDto = new FreeBotItemDto()
                    {
                        _id                 = item._id.ToString(),
                        CreatedAt           = Convert.ToDateTime(item.CreatedAt),// item.CreatedAt,
                        CreatedAt2          = item.CreatedAt2,
                        Position            = item.Position,
                        Recent30DaysSoldNum = item.Recent30DaysSoldNum,
                        ShopName            = item.ShopName,
                        ItemId              = item.SId,
                        taskId              = item.taskId.ToString(),
                        TotalComments       = item.TotalComments,
                        UId                 = item.UId.ToString()
                    };

                    fst.Add(fstDto);
                }
                List <FreeBotItemVo> am = new List <FreeBotItemVo>();
                foreach (var item in fst.GroupBy(x => x.CreatedAt))
                {
                    if (pagesize.HasValue)
                    {
                        //TaskList = col.Find(queryTask).SetFields(fd).SetSortOrder(s).SetLimit(Convert.ToInt16(pagesize)).ToList();
                        FreeBotItemVo amm = new FreeBotItemVo();
                        amm.TimeKey         = item.Key.ToString();
                        amm.FreeBotItemList = item.OrderByDescending(x => x.Recent30DaysSoldNum).Take(Convert.ToInt16(pagesize)).ToList();
                        am.Add(amm);
                    }
                    else
                    {
                        //TaskList = col.Find(queryTask).SetFields(fd).SetSortOrder(s).ToList();
                        FreeBotItemVo amm = new FreeBotItemVo();
                        amm.TimeKey         = item.Key.ToString();
                        amm.FreeBotItemList = item.OrderByDescending(x => x.Recent30DaysSoldNum).ToList();
                        am.Add(amm);
                    }
                }
                return(am.OrderBy(x => x.TimeKey).ToList());
            }
            else
            {
                try
                {
                    MongoDBClass <FreeBotItem> helper = new MongoDBClass <FreeBotItem>();
                    var queryTask = new QueryDocument {
                        { "UId", new ObjectId(user_id) }, { "taskId", new ObjectId(kid) }, { "ProjectId", new ObjectId(projectId) }
                    };
                    List <FreeBotItemDto> list = new List <FreeBotItemDto>();
                    FieldsDocument        fd   = new FieldsDocument();
                    fd.Add("_id", 1);
                    fd.Add("Position", 1);
                    fd.Add("Location", 1);
                    fd.Add("Recent30DaysSoldNum", 1);
                    fd.Add("ItemName", 1);
                    fd.Add("ShopName", 1);
                    fd.Add("TotalComments", 1);
                    fd.Add("DetailUrl", 1);
                    fd.Add("CreatedAt", 1);
                    MongoCollection <FreeBotItem> col = new MongoDBClass <FreeBotItem>().GetMongoDB().GetCollection <FreeBotItem>("FreeBotItem");
                    var            TaskList           = new List <FreeBotItem>();
                    SortByDocument s = new SortByDocument();
                    s.Add("Recent30DaysSoldNum", -1);
                    TaskList = col.Find(queryTask).SetFields(fd).SetSortOrder(s).ToList();
                    foreach (var item in TaskList)
                    {
                        FreeBotItemDto v = new FreeBotItemDto();
                        v._id                 = item._id.ToString();
                        v.Position            = item.Position;
                        v.Location            = item.Location;
                        v.Recent30DaysSoldNum = item.Recent30DaysSoldNum;
                        v.ItemName            = item.ItemName;
                        v.ShopName            = item.ShopName;
                        v.TotalComments       = item.TotalComments;
                        v.DetailUrl           = item.DetailUrl;
                        v.CreatedAt2          = Convert.ToDateTime(item.CreatedAt).ToString("yyyy/MM/dd");
                        list.Add(v);
                    }
                    var ary = from t in list
                              group t by new { t.ShopName, t.CreatedAt2 } into g
                        select new FreeBotItemDto
                    {
                        _id                 = Guid.NewGuid().ToString(),
                        ShopName            = g.Key.ShopName,
                        Position            = Convert.ToInt32(g.Average(p => p.Position)),
                        TotalComments       = g.Sum(p => p.TotalComments),
                        Recent30DaysSoldNum = g.Sum(p => p.Recent30DaysSoldNum),
                        CreatedAt2          = g.Key.CreatedAt2
                    };
                    List <FreeBotItemVo> am = new List <FreeBotItemVo>();
                    foreach (var item in ary.GroupBy(x => x.CreatedAt2))
                    {
                        if (pagesize.HasValue)
                        {
                            FreeBotItemVo amm = new FreeBotItemVo();
                            amm.TimeKey         = item.Key;//key即为CreateAt2
                            amm.FreeBotItemList = item.Take(Convert.ToInt16(pagesize)).ToList();
                            am.Add(amm);
                        }
                        else
                        {
                            FreeBotItemVo amm = new FreeBotItemVo();
                            amm.TimeKey         = item.Key;
                            amm.FreeBotItemList = item.ToList();
                            am.Add(amm);
                        }
                    }
                    return(am.OrderBy(x => x.TimeKey).ToList());
                }
                catch (Exception)
                {
                    return(null);
                }
            }
        }
Exemple #9
0
        public List <FreeBotItemDto> GetShopList(string user_id, string kid, int?pagesize, string projectId)
        {
            try
            {
                MongoDBClass <FreeBotItem> helper = new MongoDBClass <FreeBotItem>();
                var queryTask = new QueryDocument {
                    { "UId", new ObjectId(user_id) }, { "taskId", new ObjectId(kid) }, { "ProjectId", new ObjectId(projectId) }
                };
                List <FreeBotItemDto> list = new List <FreeBotItemDto>();
                FieldsDocument        fd   = new FieldsDocument();
                fd.Add("_id", 1);
                fd.Add("ShopName", 1);

                fd.Add("Location", 1);
                fd.Add("Recent30DaysSoldNum", 1);
                fd.Add("ItemName", 1);
                fd.Add("Price", 1);
                fd.Add("ShopID", 1);
                fd.Add("DetailUrl", 1);
                MongoCollection <FreeBotItem> col = new MongoDBClass <FreeBotItem>().GetMongoDB().GetCollection <FreeBotItem>("FreeBotItem");
                var TaskList = col.Find(queryTask).SetFields(fd);
                var ary      = from t in TaskList
                               group t by new { t.ShopName, t.Location, t.Recent30DaysSoldNum, t.ItemName, t.Price, t.ShopID, t.DetailUrl } into g
                    select new FreeBotItemDto
                {
                    _id                 = Guid.NewGuid().ToString(),
                    ShopName            = g.Key.ShopName,
                    Location            = g.Key.Location,
                    Recent30DaysSoldNum = g.Key.Recent30DaysSoldNum,
                    ItemName            = g.Key.ItemName,
                    Price               = g.Key.Price,
                    ShopID              = g.Key.ShopID,
                    DetailUrl           = g.Key.DetailUrl
                };
                foreach (var item in ary)
                {
                    FreeBotItemDto v = new FreeBotItemDto();
                    v._id         = item._id;
                    v.ShopID      = item.ShopID;
                    v.ShopName    = item.ShopName;
                    v.Location    = item.Location;
                    v.ItemName    = item.ItemName;
                    v.Price       = item.Price;
                    v.salesAmount = item.Price * item.Recent30DaysSoldNum;
                    //Math.Round(Convert.ToDouble(io.Value), 2).ToString("C2", new CultureInfo("zh-CN"));
                    v.SalesVolume = Math.Round(Convert.ToDouble(item.Price * item.Recent30DaysSoldNum), 2).ToString("C2", new CultureInfo("zh-CN")); //double.Parse(String.Format("{0:N2}", item.Price * item.Recent30DaysSoldNum));
                    v.Price2      = Math.Round(Convert.ToDouble(item.Price), 2).ToString("C2", new CultureInfo("zh-CN"));
                    v.DetailUrl   = item.DetailUrl;
                    list.Add(v);
                }
                if (pagesize.HasValue)
                {
                    list = list.OrderByDescending(x => x.salesAmount).Take(Convert.ToInt16(pagesize)).ToList();
                    return(list);
                }
                else
                {
                    return(list.OrderByDescending(x => x.salesAmount).ToList());
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }