/// <summary>
        /// 关注的用户菜单控件
        /// </summary>
        /// <returns></returns>
        public ActionResult _TopFollowedUsers(string spaceKey, int topNumber)
        {
            Dictionary <long, bool> isFollowesUser = new Dictionary <long, bool>();

            long userId        = UserIdToUserNameDictionary.GetUserId(spaceKey);
            long currentUserId = UserContext.CurrentUser.UserId;

            FollowService      followService = new FollowService();
            IEnumerable <long> ids           = followService.GetTopFollowedUserIds(userId, topNumber);

            foreach (var id in ids)
            {
                isFollowesUser[id] = followService.IsFollowed(currentUserId, id);
            }

            ViewData["isFollowesUser"] = isFollowesUser;

            if (currentUserId == userId)
            {
                ViewData["isSameUser"] = true;
            }

            ViewData["gender"] = (userService.GetUser(spaceKey) as User).Profile.Gender;
            IEnumerable <User> users = userService.GetFullUsers(ids);

            return(View(users));
        }
Example #2
0
        /// <summary>
        /// 可能感兴趣的人
        /// </summary>
        /// <returns></returns>
        public ActionResult Interested()
        {
            IUser CurrentUser = UserContext.CurrentUser;

            if (CurrentUser == null)
            {
                return(Redirect(SiteUrls.Instance().Login()));
            }

            // 没有感兴趣的人时,推荐人气用户,需去除已关注用户和自己
            //根据点击数取热门用户
            IEnumerable <IUser> topUsers = userService.GetTopUsers(100, SortBy_User.HitTimes);

            //已关注用户
            IEnumerable <long> followedUserIds = followService.GetTopFollowedUserIds(CurrentUser.UserId, 1000);

            //黑名单用户
            IEnumerable <long> stopUserIds = new PrivacyService().GetStopedUsers(CurrentUser.UserId).Select(n => n.Key);

            //去除已关注用户和加黑名单用户
            IEnumerable <IUser> hotUsers = topUsers.Where(n => !followedUserIds.Contains(n.UserId) && n.UserId != CurrentUser.UserId && !stopUserIds.Contains(n.UserId)).Take(Math.Min(8, topUsers.Count()));

            //设置当前登录用户对当前页用户的关注情况
            Dictionary <long, bool> isCurrentUserFollowDic = new Dictionary <long, bool>();

            foreach (var user in hotUsers)
            {
                //如果当前登录用户关注了该用户
                if (followService.IsFollowed(CurrentUser.UserId, user.UserId))
                {
                    isCurrentUserFollowDic.Add(user.UserId, true);
                }
                else
                {
                    isCurrentUserFollowDic.Add(user.UserId, false);
                }
            }
            ViewData["isCurrentUserFollowDic"] = isCurrentUserFollowDic;
            ViewData["userName"] = CurrentUser.UserName;
            pageResourceManager.InsertTitlePart("可能感兴趣的人");

            return(View(hotUsers));
        }
Example #3
0
        /// <summary>
        /// 关注的用户菜单控件
        /// </summary>
        /// <returns></returns>
        public ActionResult _TopFollowedUsers(string spaceKey, int topNumber)
        {
            Dictionary<long, bool> isFollowesUser = new Dictionary<long, bool>();

            long userId = UserIdToUserNameDictionary.GetUserId(spaceKey);
            long currentUserId = UserContext.CurrentUser.UserId;

            FollowService followService = new FollowService();
            IEnumerable<long> ids = followService.GetTopFollowedUserIds(userId, topNumber);

            foreach (var id in ids)
            {
                isFollowesUser[id] = followService.IsFollowed(currentUserId, id);
            }

            ViewData["isFollowesUser"] = isFollowesUser;

            if (currentUserId == userId)
            {
                ViewData["isSameUser"] = true;
            }

            ViewData["gender"] = (userService.GetUser(spaceKey) as User).Profile.Gender;
            IEnumerable<User> users = userService.GetFullUsers(ids);

            return View(users);
        }
Example #4
0
        /// <summary>
        /// 获取感兴趣的问题
        /// </summary>
        /// <param name="tenantTypeId">租户类型id</param>
        /// <param name="userId">用户id</param>
        /// <param name="topNumber">查询条数</param>
        /// <returns>问题列表</returns>
        public IEnumerable <AskQuestion> GetTopInterestedQuestions(string tenantTypeId, long userId, int topNumber)
        {
            StringBuilder cacheKey = new StringBuilder();

            cacheKey.Append(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "UserId", userId));
            cacheKey.AppendFormat("GetTopInterestedQuestions::tenantTypeId-{0}", tenantTypeId);

            //从缓存里取列表,如果缓存里没有就去数据库取
            List <AskQuestion> questions = cacheService.Get <List <AskQuestion> >(cacheKey.ToString());

            if (questions != null && questions.Count() > 0)
            {
                return(questions.Take(topNumber));
            }

            IEnumerable <object> questionIds = null;

            //先查询关注标签下的问题
            //查询用户关注的标签
            SubscribeService   subscribeService = new SubscribeService(TenantTypeIds.Instance().AskTag());
            IEnumerable <long> tagIds           = subscribeService.GetAllObjectIds(userId);

            if (tagIds != null && tagIds.Count() > 0)
            {
                Sql sql;
                Sql whereSql;
                Sql orderSql;
                BuildSqlForGetTopInterestedQuestions(tenantTypeId, out sql, out whereSql, out orderSql);
                sql.InnerJoin("tn_ItemsInTags").On("spb_AskQuestions.QuestionId = tn_ItemsInTags.ItemId")
                .Append(whereSql)
                .Where("tn_ItemsInTags.TenantTypeId = @0", TenantTypeIds.Instance().AskQuestion())
                .Where("tn_ItemsInTags.Id in (@tagIds)", new { tagIds = tagIds })
                .Append(orderSql);
                questionIds = CreateDAO().FetchTopPrimaryKeys <AskQuestion>(100, sql);
                questions   = this.PopulateEntitiesByEntityIds(questionIds).ToList();
                if (questions != null && questions.Count() >= topNumber)
                {
                    //加入缓存
                    cacheService.Add(cacheKey.ToString(), questions, CachingExpirationType.UsualObjectCollection);
                    return(questions.Take(topNumber));
                }
            }



            //如果查询结果不够topNumber,从关注用户的问题中查找
            //查询用户关注的用户
            FollowService      followService   = new FollowService();
            IEnumerable <long> followedUserIds = followService.GetTopFollowedUserIds(userId, 100, null, Follow_SortBy.FollowerCount_Desc);

            if (followedUserIds != null && followedUserIds.Count() > 0)
            {
                Sql sql;
                Sql whereSql;
                Sql orderSql;
                BuildSqlForGetTopInterestedQuestions(tenantTypeId, out sql, out whereSql, out orderSql);
                sql.Append(whereSql)
                .Where("spb_AskQuestions.UserId in (@followedUserIds)", new { followedUserIds = followedUserIds })
                .Append(orderSql);
                questionIds = CreateDAO().FetchTopPrimaryKeys <AskQuestion>(100, sql);
                IEnumerable <AskQuestion> questionsFollow = this.PopulateEntitiesByEntityIds(questionIds);
                if (questionsFollow != null && questionsFollow.Count() > 0)
                {
                    if (questions == null)
                    {
                        questions = new List <AskQuestion>();
                    }
                    questions.AddRange(questionsFollow);
                    questions = questions.Distinct <AskQuestion>().ToList();
                }
                if (questions != null && questions.Count() >= topNumber)
                {
                    //加入缓存
                    cacheService.Add(cacheKey.ToString(), questions, CachingExpirationType.UsualObjectCollection);
                    return(questions.Take(topNumber));
                }
            }

            //如果查询结果还不够topNumber,从最新问题中查找
            Sql sqlNew;
            Sql whereSqlNew;
            Sql orderSqlNew;

            BuildSqlForGetTopInterestedQuestions(tenantTypeId, out sqlNew, out whereSqlNew, out orderSqlNew);
            sqlNew.Append(whereSqlNew).Append(orderSqlNew);
            questionIds = CreateDAO().FetchTopPrimaryKeys <AskQuestion>(100, sqlNew);
            IEnumerable <AskQuestion> questionsNew = this.PopulateEntitiesByEntityIds(questionIds);

            if (questionsNew != null && questionsNew.Count() > 0)
            {
                if (questions == null)
                {
                    questions = new List <AskQuestion>();
                }
                questions.AddRange(questionsNew);
                questions = questions.Distinct().ToList();
            }
            if (questions != null)
            {
                //加入缓存
                cacheService.Add(cacheKey.ToString(), questions, CachingExpirationType.UsualObjectCollection);
                return(questions.Take(topNumber));
            }

            return(questions);
        }