/// <summary> /// 获取类别的内容项集合 /// </summary> /// <param name="categoryId">分类的Id集合</param> /// <param name="pageSize">页面大小</param> /// <param name="pageIndex">当前页码</param> /// <param name="totalRecords">输出参数:总记录数</param> /// <returns>当页内容项的ID集合</returns> public IEnumerable <long> GetItemIds(long categoryId, IEnumerable <long> categorieIds, int pageSize, int pageIndex, out long totalRecords) { //根据条件获取内容项同分类的对应实体集合 PagingDataSet <ItemInCategory> itemInCategories = GetPagingEntities(pageSize, pageIndex, Caching.CachingExpirationType.UsualObjectCollection, () => { StringBuilder categoriesIdsStringBuilder = new StringBuilder(); foreach (long id in categorieIds) { categoriesIdsStringBuilder.AppendFormat("-{0}", id); } //获取缓存 StringBuilder cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "CategoryId", categoryId)); cacheKey.AppendFormat("allCategoryIds-{0}", categoriesIdsStringBuilder.ToString()); return(cacheKey.ToString()); }, () => { //组装获取实体的sql语句 var sql = PetaPoco.Sql.Builder; sql.Where(" CategoryId in (@ids)", new { ids = categorieIds }); return(sql); } ); totalRecords = itemInCategories.TotalRecords; //返回CategoryId集合 return(itemInCategories.Where(n => n != null).Select(n => n.ItemId).ToList()); }
/// <summary> /// 微博图片模式数据页 /// </summary> /// <param name="pageIndex"></param> /// <param name="tenantTypeId"></param> /// <param name="mediaType"></param> /// <param name="isOriginal"></param> /// <param name="sortBy"></param> /// <returns></returns> public ActionResult _Waterfall(int pageIndex = 1, string tenantTypeId = "", MediaType?mediaType = null, bool?isOriginal = null, SortBy_Microblog sortBy = SortBy_Microblog.DateCreated) { //获取微博分页数据 PagingDataSet <MicroblogEntity> MicroblogEntities = microblogService.GetPagings(pageIndex, tenantTypeId: TenantTypeIds.Instance().User(), mediaType: mediaType, sortBy: sortBy); //获取微博图片 AttachmentService <Attachment> attachementService = new AttachmentService <Attachment>(TenantTypeIds.Instance().Microblog()); foreach (var MicroblogEntity in MicroblogEntities.Where(n => n.HasPhoto)) { IEnumerable <Attachment> attachments = attachementService.GetsByAssociateId(MicroblogEntity.MicroblogId); if (attachments != null && attachments.Count <Attachment>() > 0) { MicroblogEntity.ImageWidth = attachments.First().Width; MicroblogEntity.ImageUrl = SiteUrls.Instance().ImageUrl(attachments.First(), TenantTypeIds.Instance().Microblog(), ImageSizeTypeKeys.Instance().Big()); } } //设置当前登录用户对当前页用户的关注情况 //如果当前登录用户关注了该用户 return(View(MicroblogEntities.AsEnumerable <MicroblogEntity>())); }
/// <summary> /// 微博图片模式数据页 /// </summary> /// <param name="pageIndex"></param> /// <param name="tenantTypeId"></param> /// <param name="mediaType"></param> /// <param name="isOriginal"></param> /// <param name="sortBy"></param> /// <returns></returns> public ActionResult _Waterfall(int pageIndex = 1, string tenantTypeId = "", MediaType?mediaType = null, bool?isOriginal = null, SortBy_Microblog sortBy = SortBy_Microblog.DateCreated) { //获取微博分页数据 PagingDataSet <MicroblogEntity> MicroblogEntities = microblogService.GetPagings(pageIndex, tenantTypeId: TenantTypeIds.Instance().User(), mediaType: mediaType, sortBy: sortBy); //获取微博图片 AttachmentService <Attachment> attachementService = new AttachmentService <Attachment>(TenantTypeIds.Instance().Microblog()); foreach (var MicroblogEntity in MicroblogEntities.Where(n => n.HasPhoto)) { IEnumerable <Attachment> attachments = attachementService.GetsByAssociateId(MicroblogEntity.MicroblogId); if (attachments != null && attachments.Count <Attachment>() > 0) { MicroblogEntity.ImageWidth = attachments.First().Width; MicroblogEntity.ImageUrl = SiteUrls.Instance().ImageUrl(attachments.First(), TenantTypeIds.Instance().Microblog(), ImageSizeTypeKeys.Instance().Big()); } } IUser CurrentUser = UserContext.CurrentUser; if (CurrentUser != null) { //设置当前登录用户对当前页用户的关注情况 Dictionary <long, bool> isCurrentUserFollowDic = new Dictionary <long, bool>(); foreach (var user in MicroblogEntities.Select(m => m.User)) { if (user == null) { continue; } //如果当前登录用户关注了该用户 if (followService.IsFollowed(CurrentUser.UserId, user.UserId)) { if (!isCurrentUserFollowDic.ContainsKey(user.UserId)) { isCurrentUserFollowDic.Add(user.UserId, true); } } else { if (!isCurrentUserFollowDic.ContainsKey(user.UserId)) { isCurrentUserFollowDic.Add(user.UserId, false); } } } ViewData["isCurrentUserFollowDic"] = isCurrentUserFollowDic; } return(View(MicroblogEntities.AsEnumerable <MicroblogEntity>())); }