/// <summary> /// 获取最新微博 /// </summary> ///<param name="lastMicroblogId">用户当前浏览的最新一条微博Id</param> ///<param name="tenantTypeId">租户类型Id</param> /// <returns></returns> public int GetNewerCount(long lastMicroblogId, string tenantTypeId) { ICacheService cacheService = DIContainer.Resolve <ICacheService>(); string cacheKey = GetCackeKey_PagingMicroblogs(tenantTypeId, null, null, SortBy_Microblog.DateCreated); PagingEntityIdCollection peic = cacheService.Get <PagingEntityIdCollection>(cacheKey); if (peic == null) { Sql sql = GenerateSql_Paging_Top(0, tenantTypeId, null, null, SortBy_Microblog.DateCreated); peic = CreateDAO().FetchPagingPrimaryKeys <MicroblogEntity>(PrimaryMaxRecords, pageSize * CacheablePageCount, 1, sql); peic.IsContainsMultiplePages = true; cacheService.Add(cacheKey, peic, Tunynet.Caching.CachingExpirationType.ObjectCollection); } IEnumerable <long> ids = peic.GetTopEntityIds(1000).Cast <long>(); int count = 0; if (ids != null && ids.Count() > 0 && ids.Contains(lastMicroblogId)) { count = ids.ToList().IndexOf(lastMicroblogId); } return(count); }
public int GetPageIndexForCommentInParentCommens(long commentId, long parentId, SortBy_Comment sortBy) { int pageIndex = 1; string cacheKey = GetCacheKey_GetChildren(parentId, sortBy); PagingEntityIdCollection peic = cacheService.Get <PagingEntityIdCollection>(cacheKey); if (peic == null) { peic = CreateDAO().FetchPagingPrimaryKeys <Comment>(PrimaryMaxRecords, PageSize * CacheablePageCount, 1, GetSql_CommentPageIndexInParentComments(parentId, sortBy)); peic.IsContainsMultiplePages = true; cacheService.Add(cacheKey, peic, CachingExpirationType.ObjectCollection); } if (peic != null) { IList <long> commentIds = peic.GetTopEntityIds(peic.Count).Cast <long>().ToList(); int commentIndex = commentIds.IndexOf(commentId); if (commentIndex > 0) { pageIndex = commentIndex / ChildPageSize + 1; } else { PetaPoco.Sql sql = PetaPoco.Sql.Builder .Select("Count(Id)") .From("tn_Comments") .Where("ParentId=@0", parentId); switch (sortBy) { case SortBy_Comment.DateCreated: sql.Where("Id<@0", commentId); break; case SortBy_Comment.DateCreatedDesc: sql.Where("Id>@0", commentId); break; default: sql.Where("Id<@0", commentId); break; } commentIndex = CreateDAO().FirstOrDefault <int>(sql); if (commentIndex > 0) { pageIndex = commentIndex / ChildPageSize + 1; } } } return(pageIndex); }
/// <summary> /// 计算子级回帖在子回帖的第几页 /// </summary> /// <param name="parentId"></param> /// <param name="postId"></param> /// <returns></returns> public int GetPageIndexForChildrenPost(long parentId, long postId) { int pageIndex = 1; //和实际获取的时候使用一个缓存 string cacheKey = GetCacheKey_GetChildren(SortBy_BarPost.DateCreated_Desc, parentId); PagingEntityIdCollection peic = cacheService.Get <PagingEntityIdCollection>(cacheKey); if (peic == null) { var sql = Sql.Builder; sql.Select("PostId") .From("spb_BarPosts") .Where("ParentId = @0", parentId) .OrderBy("PostId desc"); peic = CreateDAO().FetchPagingPrimaryKeys <BarPost>(PrimaryMaxRecords, childrenPageSize * CacheablePageCount, 1, sql); peic.IsContainsMultiplePages = true; cacheService.Set(cacheKey, peic, CachingExpirationType.ObjectCollection); } if (peic != null) { IList <long> postIds = peic.GetTopEntityIds(peic.Count).Cast <long>().ToList(); int postIndex = postIds.IndexOf(postId); if (postIndex > 0) { pageIndex = postIndex / childrenPageSize + 1; } else { Sql sql = Sql.Builder; sql.Select("count(PostId)") .From("spb_BarPosts") .Where("ParentId = @0", parentId) .Where("PostId>@0", postId); postIndex = CreateDAO().FirstOrDefault <int>(sql); if (postIndex > 0) { pageIndex = postIndex / childrenPageSize + 1; } } } return(pageIndex); }
/// <summary> /// 计算回帖在帖子的哪一页 /// </summary> /// <param name="threadId"></param> /// <param name="postId"></param> /// <returns></returns> public int GetPageIndexForPostInThread(long threadId, long postId) { int pageIndex = 1; string cacheKey = GetCacheKey_PostIdsOfThread(threadId, false, SortBy_BarPost.DateCreated); PagingEntityIdCollection peic = cacheService.Get <PagingEntityIdCollection>(cacheKey); if (peic == null) { peic = CreateDAO().FetchPagingPrimaryKeys <BarPost>(PrimaryMaxRecords, pageSize * CacheablePageCount, 1, GetSql_Posts(threadId, false, 0, SortBy_BarPost.DateCreated)); peic.IsContainsMultiplePages = true; cacheService.Add(cacheKey, peic, CachingExpirationType.ObjectCollection); } if (peic != null) { IList <long> postIds = peic.GetTopEntityIds(peic.Count).Cast <long>().ToList(); int postIndex = postIds.IndexOf(postId); if (postIndex > 0) { pageIndex = postIndex / pageSize + 1; } else { Sql sql = Sql.Builder .Select("count(PostId)") .From("spb_BarPosts") .Where("ParentId=0") .Where("ThreadId=@0", threadId) .Where("PostId<@0", postId); postIndex = CreateDAO().FirstOrDefault <int>(sql); if (postIndex > 0) { pageIndex = postIndex / pageSize + 1; } } } return(pageIndex); }