예제 #1
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);
            }
        }
예제 #2
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);
     }
 }
예제 #3
0
        public List <FreeBotItemVo> GetShouyeBubbleList(string user_id, string kid, string projectId)
        {
            //  var queryl = new QueryDocument { { "UId", new ObjectId(user_id) }, { "taskId", new ObjectId(kid) } };

            var builder  = Builders <FreeShopTimeline> .Filter;
            var filter   = builder.Eq(x => x.UId, new ObjectId(user_id)) & builder.Eq(x => x.ProjectId, new ObjectId(projectId));
            var strList2 = kid.Split(';').Select(x => new ObjectId(x)).ToList();

            var groupBuilder = Builders <FreeKeywordGroup> .Filter;
            //获取所给节点ID下关键词ID
            var keywordFilter = groupBuilder.In(x => x.CommendCategoryId, strList2) & groupBuilder.Eq(x => x.IsDel, false);
            var keywordList   = MongoDBHelper.Instance.GetFreeKeywordGroup().Find(keywordFilter).Project(x => x.BaiduCommendId).ToList();//.Select(x => x.ToString()).ToList();

            List <ObjectId> commendIds = new List <ObjectId>();

            if (!string.IsNullOrEmpty(kid))
            {
                var keyIds = GetIdListFromStr(kid);
                if (keyIds.Count > 0)
                {
                    commendIds.AddRange(keyIds);
                }
            }

            if (commendIds.Count > 0)
            {
                filter &= builder.In(x => x.taskId, keywordList);
            }

            //var col = MongoDBHelper.Instance.GetIW2S_SG_level1links();
            //var query = col.Find(filter)
            //   var queryl = new QueryDocument { { "UId", new ObjectId(user_id) }, { "taskId", new ObjectId(kid) } };
            var colFS = MongoDBHelper.Instance.Get_FreeShopTimeline();
            var aryl  = colFS.Find(filter).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))
                {
                    //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
                {
                    var strList = kid.Split(';').Select(x => new ObjectId(x)).ToList();

                    //MongoDBClass<FreeBotItem> helper = new MongoDBClass<FreeBotItem>();
                    //var queryTask = new QueryDocument { { "UId", new ObjectId(user_id) }, { "ProjectId", new ObjectId(projectId) } };
                    //queryTask.Add(MongoDB.Driver.Builders.Query.In("taskId", strList) as QueryDocument);// MongoDB.Driver.Builders.Query.In("_id", strList);
                    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();

                    var             builder3    = Builders <FreeBotItem> .Filter;
                    var             filter3     = builder3.Eq(x => x.UId, new ObjectId(user_id)) & builder3.Eq(x => x.ProjectId, new ObjectId(projectId));
                    List <ObjectId> commendIds3 = new List <ObjectId>();
                    if (!string.IsNullOrEmpty(kid))
                    {
                        var keyIds = GetIdListFromStr(kid);
                        if (keyIds.Count > 0)
                        {
                            commendIds3.AddRange(keyIds);
                        }
                    }
                    if (commendIds3.Count > 0)
                    {
                        filter3 &= builder3.In(x => x.taskId, keywordList);
                    }
                    var colFS3   = MongoDBHelper.Instance.Get_FreeBotItem();
                    var TaskList = colFS3.Find(filter3).SortByDescending(x => x.Recent30DaysSoldNum).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.taskId              = item.taskId.ToString();
                        v.taskName            = item.taskName;
                        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, t.taskId, t.taskName } 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,
                        taskId              = g.Key.taskId,
                        taskName            = g.Key.taskName
                    };
                    List <FreeBotItemVo> am = new List <FreeBotItemVo>();
                    foreach (var item in ary.GroupBy(x => x.CreatedAt2))
                    {
                        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);
                }
            }
        }
예제 #4
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);
                }
            }
        }
예제 #5
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);
            }
        }