/// <summary> /// 重建索引 /// </summary> public void RebuildIndex() { //pageSize参数决定了每次批量取多少条数据进行索引。要注意的是,如果是分布式搜索,客户端会将这部分数据通过WCF传递给服务器端,而WCF默认的最大传输数据量是65535B,pageSize较大时这个设置显然是不够用的,WCF会报400错误;系统现在将最大传输量放宽了,但仍要注意一次不要传输过多,如遇异常,可适当调小pageSize的值 int pageSize = 1000; int pageIndex = 1; long totalRecords = 0; bool isBeginning = true; bool isEndding = false; do { //分页获取专题列表 PagingDataSet <TopicEntity> groups = topicService.GetsForAdmin(null, null, null, null, null, null, null, null, pageSize, pageIndex); totalRecords = groups.TotalRecords; isEndding = (pageSize * pageIndex < totalRecords) ? false : true; //重建索引 List <TopicEntity> groupList = groups.ToList <TopicEntity>(); IEnumerable <Document> docs = TopicIndexDocument.Convert(groupList); searchEngine.RebuildIndex(docs, isBeginning, isEndding); isBeginning = false; pageIndex++; }while (!isEndding); }
/// <summary> /// 照片管理 /// </summary> /// <param name="descriptionKeyword">名称关键字</param> /// <param name="userId">作者Id</param> /// <param name="auditStatus">审核状态</param> /// <param name="isEssential">是否精华</param> /// <param name="pageSize">分页大小</param> /// <param name="pageIndex">页码</param> /// <returns></returns> public ActionResult ManagePhotos(string TenantTypeId, string descriptionKeyword, string userId, long?ownerId, AuditStatus?auditStatus, bool?isEssential, int?pageSize, int?pageIndex) { //处理用户选择器产生的userId long?photoUserId = null; if (!string.IsNullOrEmpty(userId)) { userId = userId.Trim(','); if (!string.IsNullOrEmpty(userId)) { photoUserId = long.Parse(userId); } } ViewData["userId"] = photoUserId; //组装是否加精 List <SelectListItem> items = new List <SelectListItem> { new SelectListItem { Text = "是", Value = true.ToString() }, new SelectListItem { Text = "否", Value = false.ToString() } }; ViewData["isEssential"] = new SelectList(items, "Value", "Text", isEssential); PagingDataSet <Photo> photos = photoService.GetPhotosForAdmin(TenantTypeId, descriptionKeyword, photoUserId, ownerId, isEssential, auditStatus, pageSize ?? 20, pageIndex ?? 1); return(View(photos)); }
/// <summary> /// 词条列表 /// </summary> /// <param name="menu"></param> /// <param name="pageSize"></param> /// <param name="pageIndex"></param> /// <returns></returns> public ActionResult _ListWikiPages(submenu menu = submenu.all, int pageSize = 10, int pageIndex = 1) { PagingDataSet <WikiPage> wikiPages = null; if (UserContext.CurrentUser != null) { if (menu == submenu.perfect) { wikiPages = wikiService.GetPerfectPages(TenantTypeIds.Instance().Wiki(), UserContext.CurrentUser.UserId, pageSize: pageSize, pageIndex: pageIndex); } else if (menu == submenu.mycreated) { wikiPages = wikiService.GetOwnerPages(TenantTypeIds.Instance().Wiki(), UserContext.CurrentUser.UserId, true, string.Empty, pageSize: pageSize, pageIndex: pageIndex); } else if (menu == submenu.myperfected) { wikiPages = wikiService.GetUserEditedPages(TenantTypeIds.Instance().Wiki(), UserContext.CurrentUser.UserId, true, pageSize: pageSize, pageIndex: pageIndex); } } if (wikiPages == null) { wikiPages = wikiService.Gets(TenantTypeIds.Instance().Wiki(), null, false, null, string.Empty, null, SortBy_WikiPage.DateCreated_Desc, pageSize, pageIndex); } return(View(wikiPages)); }
public ActionResult UserThreads(string spaceKey, bool isPosted = false, int pageIndex = 1) { IUser currentUser = UserContext.CurrentUser; long sectionId = GroupIdToGroupKeyDictionary.GetGroupId(spaceKey); //若当前用户是在浏览自己的帖子列表,或者是管理员,则忽略审核; bool ignoreAudit = currentUser != null && UserContext.CurrentUser.UserId == currentUser.UserId || new Authorizer().IsAdministrator(BarConfig.Instance().ApplicationId); PagingDataSet <BarThread> pds = barThreadService.GetUserThreads(TenantTypeIds.Instance().Group(), currentUser.UserId, ignoreAudit, isPosted, pageIndex, sectionId); if (Request.IsAjaxRequest()) { return(PartialView("~/Applications/Bar/Views/Bar/_List.cshtml", pds)); } var group = groupService.Get(spaceKey); pageResourceManager.InsertTitlePart(group.GroupName); string title = isPosted ? "我的回帖" : "我的帖子"; if (UserContext.CurrentUser != null && UserContext.CurrentUser.UserId != currentUser.UserId) { title = isPosted ? currentUser.DisplayName + "的回帖" : currentUser.DisplayName + "的帖子"; ViewData["isOwner"] = false; } pageResourceManager.InsertTitlePart(title); ViewData["userId"] = currentUser != null ? currentUser.UserId : 0; return(View(pds)); }
/// <summary> /// 相册管理 /// </summary> /// <param name="nameKeyword">名称关键字</param> /// <param name="userId">作者ID</param> /// <param name="ownerId">所有者ID</param> /// <param name="auditStatus">审核状态</param> /// <param name="pageSize">分页大小</param> /// <param name="pageIndex">页码</param> /// <returns></returns> public ActionResult ManageAlbums(string tenantId, string nameKeyword, string userId, string ownerId, AuditStatus?auditStatus, int pageSize = 20, int pageIndex = 1) { pageResourceManager.InsertTitlePart("相册管理"); long?_userId = null; if (!string.IsNullOrEmpty(userId)) { userId = userId.Trim(','); if (!string.IsNullOrEmpty(userId)) { _userId = long.Parse(userId); } } long?_ownerId = null; if (!string.IsNullOrEmpty(ownerId)) { ownerId = userId.Trim(','); if (!string.IsNullOrEmpty(ownerId)) { _ownerId = long.Parse(ownerId); } } ViewData["userId"] = _userId; ViewData["ownerId"] = _ownerId; PagingDataSet <Album> albums = photoService.GetAlbumsForAdmin(tenantId, nameKeyword, _userId, _ownerId, auditStatus, pageSize, pageIndex); return(View(albums)); }
/// <summary> /// 最新加入 /// </summary> /// <param name="spaceKey">群组标识</param> /// <param name="topNumber">前几条数据</param> /// <returns></returns> public ActionResult _ListMembers(string spaceKey, int topNumber) { long groupId = GroupIdToGroupKeyDictionary.GetGroupId(spaceKey); IUser currentUser = UserContext.CurrentUser; if (currentUser == null) { return(new EmptyResult()); } PagingDataSet <GroupMember> groupMembers = groupService.GetGroupMembers(groupId, false, SortBy_GroupMember.DateCreated_Desc); IEnumerable <GroupMember> members = groupMembers.Take(topNumber); //设置当前登录用户对当前页用户的关注情况 Dictionary <long, bool> isCurrentUserFollowDic = new Dictionary <long, bool>(); foreach (var member in members) { if (followService.IsFollowed(currentUser.UserId, member.UserId)) { isCurrentUserFollowDic[member.UserId] = true; } else { isCurrentUserFollowDic[member.UserId] = false; } } ViewData["isCurrentUserFollowDic"] = isCurrentUserFollowDic; return(View(members)); }
/// <summary> /// 获取分页查询数据(启用缓存) /// </summary> /// <param name="pageSize">每页记录数</param> /// <param name="pageIndex">当前页码(从1开始)</param> /// <param name="cachingExpirationTypes">缓存策略</param> /// <param name="getCacheKey">生成cacheKey的委托</param> /// <param name="generateSql">生成PetaPoco.Sql的委托</param> /// <returns></returns> protected virtual PagingDataSet <TEntity> GetPagingEntities(int pageSize, int pageIndex, CachingExpirationType cachingExpirationTypes, Func <string> getCacheKey, Func <PetaPoco.Sql> generateSql) { PagingEntityIdCollection peic = null; //modified by jiangshl:分页过大时缓存多页没有意义,所以加了pageSize <= SecondaryMaxRecords的限制 if (pageIndex < CacheablePageCount && pageSize <= SecondaryMaxRecords) { string cacheKey = getCacheKey(); peic = cacheService.Get <PagingEntityIdCollection>(cacheKey); if (peic == null) { peic = CreateDAO().FetchPagingPrimaryKeys <TEntity>(PrimaryMaxRecords, pageSize * CacheablePageCount, 1, generateSql()); peic.IsContainsMultiplePages = true; cacheService.Add(cacheKey, peic, cachingExpirationTypes); } } else { peic = CreateDAO().FetchPagingPrimaryKeys <TEntity>(PrimaryMaxRecords, pageSize, pageIndex, generateSql()); } IEnumerable <TEntity> entitiesOfPage = PopulateEntitiesByEntityIds(peic.GetPagingEntityIds(pageSize, pageIndex)); PagingDataSet <TEntity> pagingEntities = new PagingDataSet <TEntity>(entitiesOfPage) { PageIndex = pageIndex, PageSize = pageSize, TotalRecords = peic.TotalRecords }; return(pagingEntities); }
public ActionResult _Related(string spaceKey, long threadId) { BlogThread blogThread = blogService.Get(threadId); //获取标题、标签、用户分类组成的关键字集合 List <string> keywords = new List <string>(); IEnumerable <string> subjectKeywords = blogThread.Keywords.Split(' ', ',', '.', '、', '|', '-', '\\', '/', ':', ':', ';', ';').AsEnumerable(); if (subjectKeywords.Count() > 0) { keywords.AddRange(subjectKeywords); } keywords.AddRange(blogThread.TagNames); keywords.AddRange(blogThread.OwnerCategoryNames); //调用搜索器进行搜索10条相关日志 BlogFullTextQuery query = new BlogFullTextQuery(); query.PageSize = 10; query.IsRelationBlog = true; query.Keywords = keywords; query.CurrentThreadId = threadId; BlogSearcher blogSearcher = (BlogSearcher)SearcherFactory.GetSearcher(BlogSearcher.CODE); PagingDataSet <BlogThread> blogThreads = blogSearcher.Search(query); return(View(blogThreads)); }
public ActionResult ManageIdentifications(IdentificationQuery query, string userId, int pageSize = 20, int pageIndex = 1) { //标识类型下拉列表 IEnumerable <IdentificationType> identificationTypes = identificationService.GetIdentificationTypes(null); SelectList identificationTypeSelectList = new SelectList(identificationTypes.Select(n => new { text = n.Name, value = n.IdentificationTypeId }), "value", "text"); ViewData["typeSelectList"] = identificationTypeSelectList; //获得所有的认证标识 Dictionary <long, string> identificationTypesDic = identificationTypes.ToDictionary(n => n.IdentificationTypeId, n => n.Name); ViewData["identificationTypesDic"] = identificationTypesDic; //处理userid为query.UserId赋值 if (!string.IsNullOrEmpty(userId)) { if (!string.IsNullOrEmpty(userId.Trim(','))) { query.UserId = long.Parse(userId.Trim(',')); } } //用户选择器默认值 ViewData["userId"] = query.UserId; PagingDataSet <Identification> identifications = identificationService.GetIdentifications(query, pageIndex, pageSize); return(View(identifications)); }
/// <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> /// 我的日志/Ta的日志 /// </summary> public ActionResult Journals(string spaceKey, int pageIndex = 1) { PagingDataSet <long> journals = null; IUser currentUser = UserContext.CurrentUser; if (currentUser != null && currentUser.UserName == spaceKey) { //journals = journalsService.GetOwnerThreads(TenantTypeIds.Instance().User(), currentUser.UserId, true, false, null, null, true, 20, pageIndex); journals = favoriteService.GetPagingObjectIds(currentUser.UserId, pageIndex); //journals = journalsService.GetJournals(pds) as PagingDataSet<Journal>; pageResourceManager.InsertTitlePart("我的杂志"); return(View("My", journals)); } else { User user = userService.GetFullUser(spaceKey); if (user == null) { return(HttpNotFound()); } journals = favoriteService.GetPagingObjectIds(user.UserId, pageIndex); //journals = journalsService.GetJournalsByIds(pds) as PagingDataSet<Journal>; pageResourceManager.InsertTitlePart(user.DisplayName + "的日志"); return(View("Ta", journals)); } }
public ActionResult _ListActivities(string spaceKey, int?pageIndex, int?applicationId, MediaType?mediaType, bool?isOriginal, long?userId) { long groupId = GroupIdToGroupKeyDictionary.GetGroupId(spaceKey); GroupEntity group = groupService.Get(groupId); if (group == null) { return(new EmptyResult()); } IUser currentUser = UserContext.CurrentUser; if (currentUser == null) { return(new EmptyResult()); } PagingDataSet <Activity> activities = activityService.GetOwnerActivities(ActivityOwnerTypes.Instance().Group(), groupId, applicationId, mediaType, isOriginal, null, pageIndex ?? 1, userId); if (activities.FirstOrDefault() != null) { ViewData["lastActivityId"] = activities.FirstOrDefault().ActivityId; } bool isDynamic = groupService.IsDynamic(group.GroupId); bool isMember = groupService.IsMember(group.GroupId, currentUser.UserId); ViewData["pageIndex"] = pageIndex; ViewData["applicationId"] = applicationId; ViewData["mediaType"] = mediaType; ViewData["isOriginal"] = isOriginal; ViewData["userId"] = userId; ViewData["isMember"] = isMember; ViewData["isDynamic"] = isDynamic; return(View(activities)); }
public ActionResult _ListMyMicroblogs(string spaceKey, string type, int?pageIndex) { IUser owner = userService.GetUser(spaceKey); if (owner == null) { return(new EmptyResult()); } MediaType?mediaType = null; bool? isOriginal = null; if (!string.IsNullOrEmpty(type)) { if (type.Equals("original")) { isOriginal = true; } else { MediaType tempMediaType; Enum.TryParse(type, out tempMediaType); mediaType = tempMediaType; } } PagingDataSet <long> pds = microblogService.GetPaingIds(owner.UserId, mediaType, isOriginal, pageIndex ?? 1); return(View(pds)); }
/// <summary> /// 我关注的群组成员 /// </summary> /// <param name="spaceKey"></param> /// <param name="pageIndex"></param> /// <returns></returns> public ActionResult MyFollowedUsers(string spaceKey, int pageIndex = 1) { GroupEntity group = groupService.Get(spaceKey); if (group == null) { return(HttpNotFound()); } var currentUser = UserContext.CurrentUser; if (currentUser == null) { return(Redirect(SiteUrls.Instance().Login(true))); } pageResourceManager.InsertTitlePart(group.GroupName); pageResourceManager.InsertTitlePart("管理成员列表页"); long groupId = GroupIdToGroupKeyDictionary.GetGroupId(spaceKey); IEnumerable <GroupMember> groupMember = groupService.GetGroupMembersAlsoIsMyFollowedUser(groupId, currentUser.UserId); PagingDataSet <GroupMember> groupMembers = new PagingDataSet <GroupMember>(groupMember); if (currentUser.IsFollowed(group.User.UserId)) { ViewData["groupOwner"] = group.User; } return(View(groupMembers)); }
/// <summary> /// 删除用户时处理所有词条相关的数据(删除用户时使用) /// </summary> /// <param name="userId">用户Id</param> /// <param name="takeOverUserName">用于接管删除用户时不能删除的内容(例如:用户创建的群组)</param> /// <param name="takeOverAll">是否接管被删除用户的所有内容</param> /// <remarks>接管被删除用户的所有内容</remarks> public void DeleteUser(long userId, string takeOverUserName, bool takeOverAll) { //takeOverAll为true,指定其他用户接管数据 if (takeOverAll) { IUserService userService = DIContainer.Resolve <IUserService>(); User takeOverUser = userService.GetFullUser(takeOverUserName); wikiPageRepository.TakeOver(userId, takeOverUser); } //takeOverAll为false,调用Delete方法逐条删除用户的词条,积分、索引、动态等的删除由EventModule处理,评论、顶踩、附件等相关数据由系统自动删除 else { int pageSize = 100; //批量删除,每次删100条 int pageIndex = 1; int pageCount = 1; do { PagingDataSet <WikiPage> Wikis = GetOwnerPages(TenantTypeIds.Instance().User(), userId, true, null, pageSize, pageIndex); foreach (WikiPage Wiki in Wikis) { Delete(Wiki); } pageCount = Wikis.PageCount; pageIndex++; } while (pageIndex <= pageCount); } }
/// <summary> /// 资讯标签详情页 /// </summary> public ActionResult TagDetail(string tagName, int pageSize = 15, int pageIndex = 1) { //tagName = WebUtility.UrlDecode(tagName); var tag = tagService.Get(tagName); if (tag == null) { return(HttpNotFound()); } PagingDataSet <ContentItem> contentItems = contentItemService.GetContentItemsSortBy(ContentItemSortBy.ReleaseDate_Desc, null, null, false, tag.TagName, pageSize, pageIndex); if (Request.IsAjaxRequest()) { return(PartialView("_List", contentItems)); } //设置title和meta pageResourceManager.InsertTitlePart(tag.TagName); if (!string.IsNullOrEmpty(tag.Description)) { pageResourceManager.SetMetaOfDescription(HtmlUtility.TrimHtml(tag.Description, 100)); } ViewData["tag"] = tag; return(View(contentItems)); }
/// <summary> /// 标签显示帖子列表 /// </summary> /// <returns></returns> public ActionResult ListByTag(string spaceKey, string tagName, SortBy_BarThread?sortBy, bool?isEssential, int pageIndex = 1) { tagName = WebUtility.UrlDecode(tagName); PagingDataSet <BarThread> pds = barThreadService.Gets(TenantTypeIds.Instance().Group(), tagName, isEssential, sortBy ?? SortBy_BarThread.StageHitTimes, pageIndex); if (Request.IsAjaxRequest()) { return(PartialView("~/Applications/Bar/Views/Bar/_ListInGroup.cshtml", pds)); } var group = groupService.Get(spaceKey); if (group == null) { return(HttpNotFound()); } pageResourceManager.InsertTitlePart(group.GroupName); pageResourceManager.InsertTitlePart(tagName); ViewData["sortBy"] = sortBy; var tag = new TagService(TenantTypeIds.Instance().BarThread()).Get(tagName); if (tag == null) { return(HttpNotFound()); } ViewData["tag"] = tag; ViewData["SectionId"] = GroupIdToGroupKeyDictionary.GetGroupId(spaceKey); ViewData["group"] = group; return(View(pds)); }
public ActionResult Mine(string spaceKey, string type, int?pageIndex) { IUser owner = userService.GetUser(spaceKey); if (owner == null) { return(new EmptyResult()); } pageResourceManager.InsertTitlePart((UserContext.CurrentUser != null && UserContext.CurrentUser.UserId == owner.UserId ? "我" : owner.DisplayName) + "的微博"); MediaType?mediaType = null; bool? isOriginal = null; if (!string.IsNullOrEmpty(type)) { if (type.Equals("original")) { isOriginal = true; } else { MediaType tempMediaType; Enum.TryParse(type, out tempMediaType); mediaType = tempMediaType; } } PagingDataSet <long> pds = microblogService.GetPaingIds(owner.UserId, mediaType, isOriginal, pageIndex ?? 1); return(View(pds)); }
/// <summary> /// 删除用户时处理其相册内容 /// </summary> /// <remarks> /// 1.如果需要接管,直接执行Repository的方法更新数据库记录 /// 2.如果不需要接管,调用DeleteAlbum、DeletePhoto、DeleteLabel循环删除该用户下的所有相册、照片、圈人 /// </remarks> /// <param name="userId">用户ID</param> /// <param name="takeOverUserName">指定接管用户的用户名</param> /// <param name="isTakeOver">是否接管</param> public void DeleteUser(long userId, string takeOverUserName, bool isTakeOver) { if (isTakeOver) { IUserService userService = DIContainer.Resolve <IUserService>(); User takeOverUser = userService.GetFullUser(takeOverUserName); albumRepository.TakeOver(userId, takeOverUser); } else { //删除用户下相册 int pageCount = 1; int pageIndex = 1; do { PagingDataSet <Album> albums = this.GetUserAlbums(null, userId, true, SortBy_Album.DateCreated_Desc, 100, pageIndex); foreach (Album album in albums) { this.DeleteAlbum(album); } pageCount = albums.PageCount; pageIndex++; } while (pageIndex <= pageCount); } }
/// <summary> /// 排行榜 /// </summary> //[DonutOutputCache(CacheProfile = "Frequently")] public ActionResult Ranking(SortBy_User?sortBy = SortBy_User.PreWeekHitTimes, int pageIndex = 1) { PagingDataSet <User> users = userService.GetPagingUsers(sortBy, pageIndex, 20); IUser CurrentUser = UserContext.CurrentUser; ViewData["sortBy"] = sortBy; //查询用户标签 IEnumerable <long> itemInTagIds = tagService.GetItemInTagIdsByItemIds(users.Select(n => n.UserId)); IEnumerable <ItemInTag> itemInTags = tagService.GetItemInTags(itemInTagIds); Dictionary <long, List <string> > userTagNameDic = new Dictionary <long, List <string> >(); foreach (ItemInTag itemInTag in itemInTags) { if (userTagNameDic.ContainsKey(itemInTag.ItemId)) { List <string> tagNames = userTagNameDic[itemInTag.ItemId]; tagNames.Add(itemInTag.TagName); } else { List <string> tagNames = new List <string>(); tagNames.Add(itemInTag.TagName); userTagNameDic.Add(itemInTag.ItemId, tagNames); } } ViewData["userTagNameDic"] = userTagNameDic; pageResourceManager.InsertTitlePart("用户排行"); return(View(users)); }
/// <summary> /// 微博搜索 /// </summary> /// <param name="query"></param> /// <returns></returns> public ActionResult Search(MicroblogFullTextQuery query) { query.PageSize = 20;//每页记录数 //调用搜索器进行搜索 MicroblogSearcher microblogSearcher = (MicroblogSearcher)SearcherFactory.GetSearcher(MicroblogSearcher.CODE); PagingDataSet <MicroblogEntity> microblogEntities = microblogSearcher.Search(query); //添加到用户搜索历史 IUser CurrentUser = UserContext.CurrentUser; if (CurrentUser != null) { SearchHistoryService searchHistoryService = new SearchHistoryService(); searchHistoryService.SearchTerm(CurrentUser.UserId, MicroblogSearcher.CODE, query.Keyword); } //添加到热词 if (!string.IsNullOrWhiteSpace(query.Keyword)) { SearchedTermService searchedTermService = new SearchedTermService(); searchedTermService.SearchTerm(MicroblogSearcher.CODE, query.Keyword); } //设置页面Meta if (string.IsNullOrWhiteSpace(query.Keyword)) { pageResourceManager.InsertTitlePart("搜索");//设置页面Title } else { pageResourceManager.InsertTitlePart('“' + query.Keyword + '”' + "的相关微博");//设置页面Title } return(View(microblogEntities)); }
/// <summary> /// 我的日志/Ta的日志 /// </summary> public ActionResult Blog(string spaceKey, int pageIndex = 1) { PagingDataSet <BlogThread> blogs = null; IUser currentUser = UserContext.CurrentUser; if (currentUser != null && currentUser.UserName == spaceKey) { blogs = blogService.GetOwnerThreads(TenantTypeIds.Instance().User(), currentUser.UserId, true, false, null, null, true, 20, pageIndex); pageResourceManager.InsertTitlePart("我的日志"); return(View("My", blogs)); } else { User user = userService.GetFullUser(spaceKey); if (user == null) { return(HttpNotFound()); } blogs = blogService.GetOwnerThreads(TenantTypeIds.Instance().User(), user.UserId, false, true, null, null, true, 20, pageIndex); pageResourceManager.InsertTitlePart(user.DisplayName + "的日志"); return(View("Ta", blogs)); } }
/// <summary> /// 毕业于同一学校 /// </summary> /// <param name="pageIndex">分页页码</param> /// <returns></returns> public ActionResult _InterestedWithSchools(int pageIndex = 1, string view = null) { IUser CurrentUser = UserContext.CurrentUser; if (CurrentUser == null) { return(null); } Dictionary <long, IEnumerable <string> > schoolNameDic = null; UserSearcher searcher = (UserSearcher)SearcherFactory.GetSearcher(UserSearcher.CODE); PagingDataSet <User> users = searcher.SearchInterestedWithSchools(CurrentUser.UserId, pageIndex, pageSize, out schoolNameDic); ViewData["schoolNameDic"] = schoolNameDic; if (string.IsNullOrEmpty(view)) { return(View(users)); } else { return(View(view, users)); } }
public ActionResult _CreateBlogThread(long ActivityId) { Activity activity = activityService.Get(ActivityId); if (activity == null) { return(Content(string.Empty)); } BlogThread thread = blogService.Get(activity.SourceId); if (thread == null) { return(Content(string.Empty)); } PagingDataSet <Comment> comments = commentService.GetRootComments(TenantTypeIds.Instance().BlogThread(), thread.ThreadId, 1, SortBy_Comment.DateCreatedDesc); ViewData["Comments"] = comments.Take(3); //ViewData["Comments"] = commentService.GetTopComments(thread.ThreadId, TenantTypeIds.Instance().BlogThread(), 3, SortBy_Comment.DateCreatedDesc); IEnumerable <Attachment> attachments = attachementService.GetsByAssociateId(thread.ThreadId); if (attachments != null && attachments.Count() > 0) { IEnumerable <Attachment> attachmentImages = attachments.Where(n => n.MediaType == MediaType.Image); if (attachmentImages != null && attachmentImages.Count() > 0) { ViewData["Attachments"] = attachmentImages; } } ViewData["ActivityId"] = ActivityId; return(View(thread)); }
/// <summary> /// 日志排行页 /// </summary> /// <param name="rank">区分最新日志,热门日志,热评日志,精华日志</param> public ActionResult ListByRank(string rank, int pageIndex = 1) { PagingDataSet <BlogThread> blogs = null; //最新日志 if (rank == "new") { blogs = blogService.Gets(TenantTypeIds.Instance().User(), null, false, true, null, null, null, SortBy_BlogThread.DateCreated_Desc, 20, pageIndex); pageResourceManager.InsertTitlePart("最新日志"); } //热门日志 else if (rank == "hot") { blogs = blogService.Gets(TenantTypeIds.Instance().User(), null, false, true, null, null, null, SortBy_BlogThread.StageHitTimes, 20, pageIndex); pageResourceManager.InsertTitlePart("热门日志"); } //热评日志 else if (rank == "comment") { blogs = blogService.Gets(TenantTypeIds.Instance().User(), null, false, true, null, null, null, SortBy_BlogThread.CommentCount, 20, pageIndex); pageResourceManager.InsertTitlePart("热评日志"); } //精华日志 else { blogs = blogService.Gets(TenantTypeIds.Instance().User(), null, false, true, null, null, true, SortBy_BlogThread.DateCreated_Desc, 20, pageIndex); pageResourceManager.InsertTitlePart("精华日志"); } ViewData["rank"] = rank; return(View(blogs)); }
/// <summary> /// 删除相册 /// </summary> /// <remarks> /// 1.删除相册时同时删除相册下的所有照片以及照片的圈人; /// 2.注意需要删除动态,通过EventModule处理; /// 3.注意需要扣除新建相册时增加的积分,通过EventModule处理; /// 4.需要触发的事件:1)Delete的OnBefore、OnAfter;2)审核状态变更 /// </remarks> /// <param name="album">相册对象</param> public void DeleteAlbum(Album album) { //删除相册下相片 int pageCount = 1; int pageIndex = 1; do { PagingDataSet <Photo> photos = this.GetPhotosOfAlbum(null, album.AlbumId, true, SortBy_Photo.DateCreated_Desc, null, 100, pageIndex); foreach (Photo photo in photos) { this.DeletePhoto(photo); } pageCount = photos.PageCount; pageIndex++; } while (pageIndex <= pageCount); //删除相册的推荐 RecommendService recommendService = new RecommendService(); recommendService.Delete(album.AlbumId, TenantTypeIds.Instance().Album()); EventBus <Album> .Instance().OnBefore(album, new CommonEventArgs(EventOperationType.Instance().Delete())); albumRepository.Delete(album); EventBus <Album> .Instance().OnAfter(album, new CommonEventArgs(EventOperationType.Instance().Delete())); EventBus <Album, AuditEventArgs> .Instance().OnAfter(album, new AuditEventArgs(album.AuditStatus, null)); }
public ActionResult PhotoManage(string spaceKey, long albumId, int pageSize = 20, int pageIndex = 1) { Album album = photoService.GetAlbum(albumId); if (album == null) { return(HttpNotFound()); } if (!authorizer.Album_Edit(album)) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = "没有管理照片的权限", Title = "没有权限", StatusMessageType = StatusMessageType.Hint }))); } PagingDataSet <Photo> photos = photoService.GetPhotosOfAlbum(TenantTypeIds.Instance().User(), albumId, true, pageSize: pageSize, pageIndex: pageIndex); ViewData["album"] = album; pageResourceManager.InsertTitlePart("照片管理"); return(View(photos)); }
/// <summary> /// 空间首页瀑布流局部页(相册首页) /// </summary> public ActionResult _HomeWaterFall(string spaceKey, int pageIndex = 1) { IUser user = userService.GetUser(spaceKey); if (user == null) { return(HttpNotFound()); } var currentuser = UserContext.CurrentUser; if (currentuser == null) { return(Redirect(SiteUrls.Instance().Login(true))); } if (currentuser.UserName == spaceKey || authorizer.IsAdministrator(PhotoConfig.Instance().ApplicationId)) { PagingDataSet <Photo> photos = photoService.GetPhotosOfFollowedUsers(user.UserId, pageSize, pageIndex); return(View(photos)); } else { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = "没有查看首页照片的权限", Title = "没有权限", StatusMessageType = StatusMessageType.Hint }))); } }
/// <summary> /// 日志频道首页 /// </summary> public ActionResult Home(int pageIndex = 1) { PagingDataSet <BlogThread> blogs = blogService.Gets(TenantTypeIds.Instance().User(), null, false, true, null, null, null, SortBy_BlogThread.DateCreated_Desc, 15, pageIndex); if (Request.IsAjaxRequest()) { return(PartialView("_List", blogs)); } //获取推荐日志 //图片推荐(幻灯片) IEnumerable <RecommendItem> recommendPicItems = recommendService.GetTops(5, blogSettings.RecommendPicTypeId); int linkCount = recommendPicItems.Where(n => n.IsLink).Where(n => !string.IsNullOrEmpty(n.FeaturedImage)).Count(); int blogCount = blogService.GetBlogThreads(recommendPicItems.Where(n => !n.IsLink).Select(n => n.ItemId)).Where(n => !string.IsNullOrEmpty(n.FeaturedImage)).Count(); int count = recommendPicItems.Where(n => !n.IsLink).Where(n => !string.IsNullOrEmpty(n.FeaturedImage)).Count(); int recommendCount = System.Math.Max(count, blogCount) + linkCount; ViewData["recommendPicBlogs"] = recommendPicItems; //文字推荐(幻灯片右侧文字区) IEnumerable <RecommendItem> recommendWordItems = recommendService.GetTops(6, blogSettings.RecommendWordTypeId); IEnumerable <BlogThread> recommendWordBlogsAll = blogService.GetBlogThreads(recommendWordItems.Where(n => !n.IsLink).Select(n => n.ItemId)); ViewData["recommendCount"] = recommendCount; ViewData["recommendWordItems"] = recommendWordItems; pageResourceManager.InsertTitlePart("日志"); return(View(blogs)); }
/// <summary> /// 删除用户时处理其兑换申请 /// </summary> /// <remarks> /// 1.如果需要接管,直接执行Repository的方法更新数据库记录 /// 2.如果不需要接管,删除申请记录 /// </remarks> /// <param name="userId">用户ID</param> /// <param name="takeOverUserName">指定接管用户的用户名</param> /// <param name="isTakeOver">是否接管</param> public void DeleteUser(long userId, string takeOverUserName, bool isTakeOver) { if (isTakeOver) { IUserService userService = DIContainer.Resolve <IUserService>(); User takeOverUser = userService.GetFullUser(takeOverUserName); recordRepository.TakeOver(userId, takeOverUser); } else { //删除用户下申请 int pageCount = 1; int pageIndex = 1; do { PagingDataSet <PointGiftExchangeRecord> records = this.GetRecordsOfUser(userId, Convert.ToDateTime("2000-01-01"), DateTime.Now, null, 100, pageIndex); foreach (PointGiftExchangeRecord record in records) { recordRepository.Delete(record); //处理统计数据 OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User()); ownerDataService.Change(record.PayerUserId, OwnerDataKeys.Instance().PostCount(), -1); } pageCount = records.PageCount; pageIndex++; } while (pageIndex <= pageCount); } }
/// <summary> /// 日志分页搜索 /// </summary> /// <param name="journalQuery">搜索条件</param> /// <returns>符合搜索条件的分页集合</returns> public PagingDataSet<Journal> Search(JournalFullTextQuery journalQuery) { if (journalQuery.SiteCategoryId == 0 && journalQuery.LoginId == 0 && journalQuery.UserId == 0) { if (string.IsNullOrWhiteSpace(journalQuery.Keyword) && journalQuery.IsRelationJournal == false) { return new PagingDataSet<Journal>(new List<Journal>()); } } LuceneSearchBuilder searchBuilder = BuildLuceneSearchBuilder(journalQuery); //使用LuceneSearchBuilder构建Lucene需要Query、Filter、Sort Query query = null; Filter filter = null; Sort sort = null; searchBuilder.BuildQuery(out query, out filter, out sort); //调用SearchService.Search(),执行搜索 PagingDataSet<Document> searchResult = searchEngine.Search(query, filter, sort, journalQuery.PageIndex, journalQuery.PageSize); IEnumerable<Document> docs = searchResult.ToList<Document>(); //解析出搜索结果中的日志ID List<long> journalIds = new List<long>(); //获取索引中日志的标签 Dictionary<long, IEnumerable<string>> journalTags = new Dictionary<long, IEnumerable<string>>(); //获取索引中日志的用户分类名 Dictionary<long, IEnumerable<string>> journalOwnerCategoryNames = new Dictionary<long, IEnumerable<string>>(); foreach (Document doc in docs) { long journalid = long.Parse(doc.Get(JournalIndexDocument.id)); journalIds.Add(journalid); //journalTags[journalid] = doc.GetValues(JournalIndexDocument.Tag).ToList<string>(); //journalOwnerCategoryNames[journalid] = doc.GetValues(JournalIndexDocument.OwnerCategoryName).ToList<string>(); } //根据日志ID列表批量查询日志实例 IEnumerable<Journal> journalList = journalService.GetJournalsByIds(journalIds); /*foreach (var journal in journalList) { journal.Body = journal.GetBody(); if (blogTags.ContainsKey(journal.ThreadId)) { journal.TagNames = blogTags[journal.ThreadId]; } if (journalOwnerCategoryNames.ContainsKey(journal.ThreadId)) { journal.OwnerCategoryNames = journalOwnerCategoryNames[journal.ThreadId]; } } */ //组装分页对象 PagingDataSet<Journal> journals = new PagingDataSet<Journal>(journalList) { TotalRecords = searchResult.TotalRecords, PageSize = searchResult.PageSize, PageIndex = searchResult.PageIndex, QueryDuration = searchResult.QueryDuration }; return journals; }
/// <summary> /// 根据多个话题名称(标签)分页查询微博列表 /// </summary> /// <param name="tagNames">话题名称列表</param> /// <param name="pageSize">分页大小</param> /// <param name="pageIndex">页码</param> /// <returns></returns> public PagingDataSet<MicroblogEntity> GetMicroblogsByTagNames(IEnumerable<string> tagNames, int pageSize, int pageIndex) { PagingEntityIdCollection pec = tagService.GetItemIds(tagNames, null, pageSize, pageIndex); IEnumerable<MicroblogEntity> microblogEntitysList = microblogRepository.PopulateEntitiesByEntityIds(pec.GetPagingEntityIds(pageSize, pageIndex)); //组装分页对象 PagingDataSet<MicroblogEntity> microblogEntitysPage = new PagingDataSet<MicroblogEntity>(microblogEntitysList) { TotalRecords = pec.TotalRecords, PageSize = pageSize, PageIndex = pageIndex }; return microblogEntitysPage; }
public ActionResult ManageFollowedUsers(string spaceKey, int? pageIndex, long? groupId, int sortBy = 0) { //已修改 pageResourceManager.InsertTitlePart("我的关注"); IEnumerable<Category> userCategories = null; List<Category> categoriesShowList = null; List<Category> categoriesLeftList = null; IEnumerable<MenuItem> menuItem = null; Dictionary<long, string> noteNameDic = new Dictionary<long, string>(); Dictionary<long, bool> isMutualDic = new Dictionary<long, bool>(); Dictionary<long, bool> isFollowedDic = new Dictionary<long, bool>(); Dictionary<long, string> userCategoriesShowDic = new Dictionary<long, string>(); long userId = UserIdToUserNameDictionary.GetUserId(spaceKey); User user = userService.GetFullUser(userId); if (user != null) ViewData["followedCount"] = user.FollowedCount; ViewData["sortBy"] = (Follow_SortBy)sortBy; ViewData["userId"] = userId; string tenantTypeId = TenantTypeIds.Instance().User(); #region 分组栏设置 IEnumerable<Category> categories = categoryService.GetOwnerCategories(userId, tenantTypeId); if (categories != null) { //已修改 categoriesShowList = categories.Take(4).ToList(); if (groupId > 0 && !categories.Select(n => n.CategoryId).Contains(groupId ?? -99)) { groupId = null; ViewData["noGroupId"] = true; } if (categories.Count() > 4) { categoriesLeftList = categories.ToList().GetRange(4, categories.Count() - 4); if (groupId != null && groupId > 0 && !categoriesShowList.Select(n => n.CategoryId).Contains(groupId ?? -99)) { int index = categoriesLeftList.Select(n => n.CategoryId).ToList().IndexOf(groupId ?? -99); Category midCategory = categoriesShowList[3]; categoriesShowList[3] = categoriesLeftList[index]; categoriesLeftList[index] = midCategory; } } } ViewData["categoriesShow"] = categoriesShowList; if (categoriesLeftList != null) menuItem = categoriesLeftList.Select(n => new MenuItem { Text = n.CategoryName, Value = n.CategoryId.ToString(), Url = SiteUrls.Instance().ManageFollowedUsers(Url.SpaceKey(), n.CategoryId) }); #endregion ViewData["categoriesLeft"] = menuItem; ViewData["groupId"] = groupId; PagingDataSet<long> pds = followService.GetFollowedUserIds(userId, groupId, (Follow_SortBy)sortBy == null ? Follow_SortBy.DateCreated_Desc : (Follow_SortBy)sortBy, pageIndex ?? 1); IEnumerable<User> users = userService.GetFullUsers(pds); bool isFollowed; #region 字典 foreach (var id in pds) { string userCategoriesShowString = string.Empty; noteNameDic[id] = followService.GetNoteName(userId, id); isMutualDic[id] = followService.IsMutualFollowed(userId, id); followService.IsFollowed(userId, id, out isFollowed); isFollowedDic[id] = isFollowed; FollowEntity follow = followService.Get(userId, id); if (follow == null) continue; userCategories = categoryService.GetCategoriesOfItem(follow.Id, userId, tenantTypeId); if (userCategories != null && userCategories.Count() > 0) { for (int i = 0; i < (userCategories.Count() >= 2 ? 2 : userCategories.Count()); i++) { userCategoriesShowString = userCategories.ElementAt(userCategories.Count() - 1 - i).CategoryName + "," + userCategoriesShowString; } userCategoriesShowString = userCategoriesShowString.Remove(userCategoriesShowString.Count() - 1); } userCategoriesShowDic[id] = userCategoriesShowString; } ViewData["noteNameDic"] = noteNameDic; ViewData["isMutualDic"] = isMutualDic; ViewData["isFollowedDic"] = isFollowedDic; ViewData["userCategoriesShowDic"] = userCategoriesShowDic; #endregion PagingDataSet<User> pagingUsers = new PagingDataSet<User>(users); pagingUsers.PageSize = pds.PageSize; pagingUsers.PageIndex = pds.PageIndex; pagingUsers.TotalRecords = pds.TotalRecords; return View(pagingUsers); }
public ActionResult InviteFriend(string spaceKey, int pageIndex = 1) { if (userSettings.RegistrationMode == RegistrationMode.Disabled) { return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Body = "站点不允许注册,所以邀请好友功能被关闭", Title = "未启用的功能", StatusMessageType = StatusMessageType.Hint })); } pageResourceManager.InsertTitlePart("邀请好友"); InviteFriendSettings inviteFriendSettings = inviteFriendSettingsManager.Get(); long userId = UserIdToUserNameDictionary.GetUserId(spaceKey); PagingDataSet<InvitationCode> invitationCodes = null; if (inviteFriendSettings.AllowInvitationCodeUseOnce) { invitationCodes = inviteFriendService.GetMyInvitationCodes(userId, pageIndex); } else { List<InvitationCode> codes = new List<InvitationCode>(); string code = inviteFriendService.GetInvitationCode(userId); InvitationCode invitationCode = inviteFriendService.GetInvitationCodeEntity(code); codes.Add(invitationCode); invitationCodes = new PagingDataSet<InvitationCode>(codes); } InvitationCodeStatistic invitationCodeStatistic = inviteFriendService.GetUserInvitationCodeStatistic(userId); ViewData["CodeUnUsedCount"] = invitationCodeStatistic.CodeUnUsedCount; if (!Request.IsAjaxRequest()) return View("InviteFriend", invitationCodes); return PartialView("_InvitationCode", invitationCodes); }
public ActionResult ListFollowers(string spaceKey, int sortBy = 0, int pageIndex = 1) { long userId = UserIdToUserNameDictionary.GetUserId(spaceKey); long currentUserId = UserContext.CurrentUser == null ? 0 : UserContext.CurrentUser.UserId; if (currentUserId == userId) return RedirectToAction("ManageFollowers", new { spaceKey = spaceKey }); UserProfile currentUser = userProfileService.Get(userId); if (currentUser != null) { if (currentUser.Gender == GenderType.FeMale) pageResourceManager.InsertTitlePart("她的粉丝"); else pageResourceManager.InsertTitlePart("他的粉丝"); ViewData["Gender"] = currentUser.Gender; } PagingDataSet<long> followerUserIds = followService.GetFollowerUserIds(userId, (Follow_SortBy)sortBy, pageIndex); IEnumerable<User> listUsers = userService.GetFullUsers(followerUserIds.ToList()); PagingDataSet<User> followerUsers = new PagingDataSet<User>(listUsers); followerUsers.PageIndex = followerUserIds.PageIndex; followerUsers.PageSize = followerUserIds.PageSize; followerUsers.TotalRecords = followerUserIds.TotalRecords; ViewData["sortBy"] = (Follow_SortBy)sortBy; return View(followerUsers); }
public ActionResult ManageFollowers(string spaceKey, int sortBy = 0, int pageIndex = 1) { pageResourceManager.InsertTitlePart("我的粉丝"); long userId = UserIdToUserNameDictionary.GetUserId(spaceKey); PagingDataSet<long> followerUserIds = followService.GetFollowerUserIds(userId, (Follow_SortBy)sortBy, pageIndex); IEnumerable<User> listUsers = userService.GetFullUsers(followerUserIds); User user = userService.GetFullUser(userId); if (user != null) ViewData["followerCount"] = user.FollowerCount; PagingDataSet<User> followerUsers = new PagingDataSet<User>(listUsers); followerUsers.PageIndex = followerUserIds.PageIndex; followerUsers.PageSize = followerUserIds.PageSize; followerUsers.TotalRecords = followerUserIds.TotalRecords; followService.ClearNewFollowerCount(userId);//清除最新粉丝数 ViewData["sortBy"] = (Follow_SortBy)sortBy; return View(followerUsers); }
public IEnumerable<Journal> GetJournals(PagingDataSet<long> pdsObjectIds) { List<Journal> jlist = new List<Journal>(); foreach (long id in pdsObjectIds) { var j = Get(id); if(j!=null) { jlist.Add(j); } } return jlist; }
/// <summary> /// 搜索共同关注的人 /// </summary> /// <param name="userId">粉丝的用户ID</param> /// <param name="pageIndex">页码</param> /// <param name="pageSize">分页大小</param> /// <param name="followedUserIdDic">每个相同关注用户中共同关注的用户ID列表</param> /// <param name="followedUserDic">每个共同关注的用户的ID与User的映射</param> /// <returns>符合搜索条件的User分页集合</returns> public PagingDataSet<User> SearchInterestedWithFollows(long userId, int pageIndex, int pageSize, out Dictionary<long, IEnumerable<long>> followedUserIdDic, out Dictionary<long, User> followedUserDic) { followedUserIdDic = new Dictionary<long, IEnumerable<long>>(); followedUserDic = new Dictionary<long, User>(); if (userId <= 0) { return new PagingDataSet<User>(new List<User>()); } //先查询当前用户关注的人(包括“悄悄关注”的用户),此处需要调用数据库查询,因为索引中没有存储“是否悄悄关注”属性 IEnumerable<long> myFollowedUserIds = followService.GetPortionFollowedUserIds(userId); if (myFollowedUserIds != null && myFollowedUserIds.Count() == 0) { return new PagingDataSet<User>(new List<User>()); } //黑名单用户 IEnumerable<long> stopUserIds = new PrivacyService().GetStopedUsers(userId).Select(n => n.Key); //搜索“我”关注的人中包含“共同关注的人”的用户 //使用LuceneSearchBuilder构建Lucene需要Query、Filter、Sort Query query = null; Filter filter = null; Sort sort = null; LuceneSearchBuilder searchBuilder = new LuceneSearchBuilder(); searchBuilder.WithFields(FollowedUserIds, myFollowedUserIds.Select(n => n.ToString()), true) .NotWithField(UserId, userId.ToString())//排除掉当前用户 .NotWithFields(UserIndexDocument.UserId, myFollowedUserIds.Select(n => n.ToString()))//排除掉已关注用户 .NotWithFields(UserIndexDocument.UserId, stopUserIds.Select(n => n.ToString()));//排除掉黑名单用户 searchBuilder.BuildQuery(out query, out filter, out sort); PagingDataSet<Document> searchResult = searchEngine.Search(query, filter, sort, pageIndex, pageSize); IEnumerable<Document> docs = searchResult.ToList<Document>(); if (docs == null || docs.Count() == 0) { return new PagingDataSet<User>(new List<User>()); } List<long> sameFollowedUserIdList = new List<long>(); //解析出搜索结果中的用户ID List<long> followerUserIds = new List<long>(); foreach (Document doc in docs) { long followerUserId = long.Parse(doc.Get(UserId)); followerUserIds.Add(followerUserId); //“我”关注的人关注的人 string[] followedUserIds = doc.GetValues(FollowedUserIds); //比较获取“共同关注的人” IEnumerable<long> sameFollowedUserIds = myFollowedUserIds.Intersect<long>(followedUserIds.Select(n => Convert.ToInt64(n))); if (!followedUserIdDic.ContainsKey(followerUserId)) { followedUserIdDic.Add(followerUserId, sameFollowedUserIds); } sameFollowedUserIdList.AddRange(sameFollowedUserIds); } //批量查询“共同关注的用户”列表 IEnumerable<User> followerUserList = userService.GetFullUsers(followerUserIds).Where(n => n.IsCanbeFollow == true && n.IsActivated == true && n.IsBanned == false); //组装分页对象 PagingDataSet<User> users = new PagingDataSet<User>(followerUserList) { TotalRecords = searchResult.TotalRecords, PageSize = searchResult.PageSize, PageIndex = searchResult.PageIndex, QueryDuration = searchResult.QueryDuration }; //批量查询“共同关注的用户”关注的“共同关注用户”列表 IEnumerable<User> sameFollowedUserList = userService.GetFullUsers(sameFollowedUserIdList.Distinct()); followedUserDic = sameFollowedUserList.ToDictionary(n => n.UserId); return users; }
/// <summary> /// 我关注的专题成员 /// </summary> /// <param name="spaceKey"></param> /// <param name="pageIndex"></param> /// <returns></returns> public ActionResult MyFollowedUsers(string spaceKey, int pageIndex = 1) { TopicEntity topic = topicService.Get(spaceKey); if (topic == null) return HttpNotFound(); var currentUser = UserContext.CurrentUser; if (currentUser == null) return Redirect(SiteUrls.Instance().Login(true)); pageResourceManager.InsertTitlePart(topic.TopicName); pageResourceManager.InsertTitlePart("管理成员列表页"); long topicId = TopicIdToTopicKeyDictionary.GetTopicId(spaceKey); IEnumerable<TopicMember> topicMember = topicService.GetTopicMembersAlsoIsMyFollowedUser(topicId, currentUser.UserId); PagingDataSet<TopicMember> topicMembers = new PagingDataSet<TopicMember>(topicMember); if (currentUser.IsFollowed(topic.User.UserId)) { ViewData["topicOwner"] = topic.User; } return View(topicMembers); }
public ActionResult InvitedFriends(string spaceKey, int? pageIndex) { pageResourceManager.InsertTitlePart("我邀请过的好友"); long userId = UserIdToUserNameDictionary.GetUserId(spaceKey); List<InvitedFriendViewModel> invitedFriends = new List<InvitedFriendViewModel>(); PagingEntityIdCollection userIds = inviteFriendService.GetMyInviteFriendRecords(userId, pageIndex ?? 1); IEnumerable<object> itemIds = userIds.GetPagingEntityIds(12, pageIndex ?? 1); foreach (var item in itemIds) { long InvitedUserId = (long)item; User user = userService.GetFullUser(InvitedUserId); UserProfile userProfile = userProfileService.Get(InvitedUserId); if (user == null) continue; InvitedFriendViewModel invitedFriend = new InvitedFriendViewModel { UserId = InvitedUserId, MicroblogCount = 0, UserName = user.UserName, DisplayName = user.DisplayName, FollowedCount = user.FollowedCount, FollowerCount = user.FollowerCount }; invitedFriend.AreaName = userProfile != null && userProfile.NowAreaCode != null ? Formatter.FormatArea(userProfile.NowAreaCode, false) : ""; invitedFriend.GenderType = user.Profile != null ? user.Profile.Gender : GenderType.NotSet; invitedFriends.Add(invitedFriend); } PagingDataSet<InvitedFriendViewModel> pagingDataSetInvitedFriends = new PagingDataSet<InvitedFriendViewModel>(invitedFriends) { PageIndex = pageIndex ?? 1, PageSize = 12, TotalRecords = userIds.TotalRecords }; return View(pagingDataSetInvitedFriends); }
/// <summary> /// 展示帖子的局部分页 /// </summary> /// <param name="threads">要展示的实体</param> /// <returns>展示帖子的局部分页</returns> public ActionResult _PagingThreads(PagingDataSet<BarThread> threads, bool ShowSectionInfo = false) { ViewData["ShowSectionInfo"] = ShowSectionInfo; ViewData["BarThreads"] = threads; return View(); }
public ActionResult AtMeComments(string spaceKey, int? pageIndex, string tenantTypeId = "") { pageResourceManager.InsertTitlePart("@我的评论"); long userId = UserIdToUserNameDictionary.GetUserId(spaceKey); AtUserService service = new AtUserService(TenantTypeIds.Instance().Comment()); PagingDataSet<long> objectIds = service.GetPagingAssociateIds(userId, pageIndex ?? 1); IList<Comment> commentLists = new List<Comment>(); foreach (var commentId in objectIds) { Comment comment = commentService.Get(commentId); if (comment != null) { commentLists.Add(comment); } } if (!string.IsNullOrEmpty(tenantTypeId)) { commentLists = commentLists.Where(n => n.TenantTypeId == tenantTypeId).ToList(); } PagingDataSet<Comment> comments = new PagingDataSet<Comment>(commentLists) { PageIndex = pageIndex ?? 1, PageSize = objectIds.PageSize, TotalRecords = objectIds.TotalRecords }; Dictionary<long, TenantType> commentId_tenantType = new Dictionary<long, TenantType>(); Dictionary<long, CommentedObject> commentedObject = new Dictionary<long, CommentedObject>(); Dictionary<long, Comment> commentId_parentComment = new Dictionary<long, Comment>(); //排除掉被禁用的应用 var tenantTypes = tenantTypeService.Gets(MultiTenantServiceKeys.Instance().Comment()).Where(n => n.TenantTypeId != "101202" && n.TenantTypeId != "200101"); List<TenantType> tennatType_List = new List<TenantType>(); foreach (var item in tenantTypes) { if (applicationService.Get(item.ApplicationId).IsEnabled) { tennatType_List.Add(item); } } Dictionary<string, string> tenantTypeDic = tennatType_List.ToDictionary(k => k.TenantTypeId, v => v.Name); foreach (var comment in comments) { TenantType tenantType = tenantTypeService.Get(comment.TenantTypeId); if (comment.TenantTypeId != TenantTypeIds.Instance().Group()) { commentId_tenantType[comment.Id] = tenantType; } ICommentUrlGetter commentUrlGetter = CommentUrlGetterFactory.Get(comment.TenantTypeId); if (commentUrlGetter != null && comment.CommentedObjectId != 0) { CommentedObject comment_object = commentUrlGetter.GetCommentedObject(comment.CommentedObjectId); if (comment_object != null) { commentedObject[comment.Id] = comment_object; } } if (comment.ParentId != 0) { commentId_parentComment[comment.Id] = commentService.Get(comment.ParentId); } } ViewData["tenantTypeDic"] = tenantTypeDic; ViewData["commentId_tenantType"] = commentId_tenantType; ViewData["commentedObject"] = commentedObject; ViewData["commentId_parentComment"] = commentId_parentComment; return View(comments); }
public ActionResult _ListPost(long threadId, long parentId, int pageIndex = 1, bool showBeforPage = false) { BarThread barThread = barThreadService.Get(threadId); if (barThread == null) return Content(string.Empty); ViewData["BarThread"] = barThread; ViewData["parentId"] = parentId; PagingDataSet<BarPost> posts = barPostService.GetChildren(parentId, SortBy_BarPost.DateCreated_Desc, pageIndex); PagingDataSet<BarPost> postsReverse = new PagingDataSet<BarPost>(new List<BarPost>()); if (posts != null) { postsReverse = new PagingDataSet<BarPost>(posts.Reverse()); postsReverse.PageIndex = posts.PageIndex; postsReverse.PageSize = posts.PageSize; postsReverse.QueryDuration = posts.QueryDuration; postsReverse.TotalRecords = posts.TotalRecords; } return View(postsReverse); }
/// <summary> /// 微博分页搜索 /// </summary> /// <param name="query">搜索条件</param> /// <returns>符合搜索条件的分页集合</returns> public PagingDataSet<MicroblogEntity> Search(MicroblogFullTextQuery microBlogQuery) { if (microBlogQuery.Keywords == null && string.IsNullOrWhiteSpace(microBlogQuery.Keyword) && microBlogQuery.SearchTerm == MicroblogSearchTerm.ALL) { return new PagingDataSet<MicroblogEntity>(new List<MicroblogEntity>()); } LuceneSearchBuilder searchBuilder = BuildLuceneSearchBuilder(microBlogQuery); //使用LuceneSearchBuilder构建Lucene需要Query、Filter、Sort Query query = null; Filter filter = null; Sort sort = null; searchBuilder.BuildQuery(out query, out filter, out sort); //调用SearchService.Search(),执行搜索 PagingDataSet<Document> searchResult = searchEngine.Search(query, filter, sort, microBlogQuery.PageIndex, microBlogQuery.PageSize); IEnumerable<Document> docs = searchResult.ToList<Document>(); //解析出搜索结果中的微博ID List<long> microblogIds = new List<long>(); foreach (Document doc in docs) { long microblogId = long.Parse(doc.Get(MicroblogIndexDocument.MicroblogId)); microblogIds.Add(microblogId); } //根据微博ID列表批量查询微博实例 IEnumerable<MicroblogEntity> microblogList = microBlogService.GetMicroblogs(microblogIds); //组装分页对象 PagingDataSet<MicroblogEntity> microblogs = new PagingDataSet<MicroblogEntity>(microblogList) { TotalRecords = searchResult.TotalRecords, PageSize = searchResult.PageSize, PageIndex = searchResult.PageIndex, QueryDuration = searchResult.QueryDuration }; return microblogs; }
public ActionResult SectionMembers(long sectionId, int pageIndex = 1) { BarSection barSection = barSectionService.Get(sectionId); if (!authorizer.BarSection_View(barSection)) return Redirect(SiteUrls.Instance().SystemMessage(TempData, SystemMessageViewModel.NoCompetence())); pageResourceManager.InsertTitlePart(barSection.Name); pageResourceManager.InsertTitlePart("关注本吧的用户"); PagingDataSet<long> memberUserIds = subscribeService.GetPagingUserIdsOfObject(sectionId, pageIndex); PagingDataSet<User> members = new PagingDataSet<User>(userService.GetFullUsers(memberUserIds)); members.PageIndex = pageIndex; members.PageSize = 50; members.QueryDuration = memberUserIds.QueryDuration; members.TotalRecords = memberUserIds.TotalRecords; ViewData["barSection"] = barSection; return View(members); }
/// <summary> /// 日志分页搜索 /// </summary> /// <param name="blogQuery">搜索条件</param> /// <returns>符合搜索条件的分页集合</returns> public PagingDataSet<BlogThread> Search(BlogFullTextQuery blogQuery) { if (blogQuery.SiteCategoryId == 0 && blogQuery.LoginId == 0 && blogQuery.UserId == 0) { if (string.IsNullOrWhiteSpace(blogQuery.Keyword) && blogQuery.IsRelationBlog == false) { return new PagingDataSet<BlogThread>(new List<BlogThread>()); } } LuceneSearchBuilder searchBuilder = BuildLuceneSearchBuilder(blogQuery); //使用LuceneSearchBuilder构建Lucene需要Query、Filter、Sort Query query = null; Filter filter = null; Sort sort = null; searchBuilder.BuildQuery(out query, out filter, out sort); //调用SearchService.Search(),执行搜索 PagingDataSet<Document> searchResult = searchEngine.Search(query, filter, sort, blogQuery.PageIndex, blogQuery.PageSize); IEnumerable<Document> docs = searchResult.ToList<Document>(); //解析出搜索结果中的日志ID List<long> blogThreadIds = new List<long>(); //获取索引中日志的标签 Dictionary<long, IEnumerable<string>> blogTags = new Dictionary<long, IEnumerable<string>>(); //获取索引中日志的用户分类名 Dictionary<long, IEnumerable<string>> blogOwnerCategoryNames = new Dictionary<long, IEnumerable<string>>(); foreach (Document doc in docs) { long blogThreadId = long.Parse(doc.Get(BlogIndexDocument.ThreadId)); blogThreadIds.Add(blogThreadId); blogTags[blogThreadId] = doc.GetValues(BlogIndexDocument.Tag).ToList<string>(); blogOwnerCategoryNames[blogThreadId] = doc.GetValues(BlogIndexDocument.OwnerCategoryName).ToList<string>(); } //根据日志ID列表批量查询日志实例 IEnumerable<BlogThread> blogThreadList = blogThreadService.GetBlogThreads(blogThreadIds); foreach (var blogThread in blogThreadList) { blogThread.Body = blogThread.GetBody(); if (blogTags.ContainsKey(blogThread.ThreadId)) { blogThread.TagNames = blogTags[blogThread.ThreadId]; } if (blogOwnerCategoryNames.ContainsKey(blogThread.ThreadId)) { blogThread.OwnerCategoryNames = blogOwnerCategoryNames[blogThread.ThreadId]; } } //组装分页对象 PagingDataSet<BlogThread> blogThreads = new PagingDataSet<BlogThread>(blogThreadList) { TotalRecords = searchResult.TotalRecords, PageSize = searchResult.PageSize, PageIndex = searchResult.PageIndex, QueryDuration = searchResult.QueryDuration }; return blogThreads; }
public ActionResult OnlineUser(string viewName = "OnlineUser", bool ignoreAnonymousUsers = true, int topNumber = 0, int pageIndex = 1, int pageSize = 100) { Dictionary<string, OnlineUser> loggerUsers = onlineUserService.GetLoggedUsers(); IList<OnlineUser> anonymousUsers = onlineUserService.GetAnonymousUsers(); IEnumerable<OnlineUser> onlineUsers = Enumerable.Empty<OnlineUser>(); onlineUsers = onlineUsers.Union(loggerUsers.Values.ToList()); if (!ignoreAnonymousUsers) { onlineUsers = onlineUsers.Union(anonymousUsers); } if (topNumber != 0) { onlineUsers = onlineUsers.Take(topNumber); } PagingDataSet<OnlineUser> users = new PagingDataSet<OnlineUser>(onlineUsers) { TotalRecords = onlineUsers.Count(), PageIndex = pageIndex, PageSize = pageSize }; return View(viewName, users); }
/// <summary> /// 资讯分页搜索 /// </summary> /// <param name="cmsQuery">搜索条件</param> /// <returns>符合搜索条件的分页集合</returns> public PagingDataSet<ContentItem> Search(CmsFullTextQuery cmsQuery) { if (cmsQuery.ContentFolderId == 0) { if (string.IsNullOrWhiteSpace(cmsQuery.Keyword)) { return new PagingDataSet<ContentItem>(new List<ContentItem>()); } } LuceneSearchBuilder searchBuilder = BuildLuceneSearchBuilder(cmsQuery); //使用LuceneSearchBuilder构建Lucene需要Query、Filter、Sort Query query = null; Filter filter = null; Sort sort = null; searchBuilder.BuildQuery(out query, out filter, out sort); //调用SearchService.Search(),执行搜索 PagingDataSet<Document> searchResult = searchEngine.Search(query, filter, sort, cmsQuery.PageIndex, cmsQuery.PageSize); IEnumerable<Document> docs = searchResult.ToList<Document>(); //解析出搜索结果中的资讯ID List<long> cmsContentItemIds = new List<long>(); //获取索引中资讯的标签 Dictionary<long, IEnumerable<string>> cmsTags = new Dictionary<long, IEnumerable<string>>(); foreach (Document doc in docs) { long cmsContentItemId = long.Parse(doc.Get(CmsIndexDocument.ContentItemId)); cmsContentItemIds.Add(cmsContentItemId); cmsTags[cmsContentItemId] = doc.GetValues(CmsIndexDocument.Tag).ToList<string>(); } //根据资讯ID列表批量查询资讯实例 IEnumerable<ContentItem> contentItemList = contentItemService.GetContentItems(cmsContentItemIds); foreach (var contentItem in contentItemList) { if (cmsTags.ContainsKey(contentItem.ContentItemId)) { contentItem.TagNames = cmsTags[contentItem.ContentItemId]; } } //组装分页对象 PagingDataSet<ContentItem> contentItems = new PagingDataSet<ContentItem>(contentItemList) { TotalRecords = searchResult.TotalRecords, PageSize = searchResult.PageSize, PageIndex = searchResult.PageIndex, QueryDuration = searchResult.QueryDuration }; return contentItems; }
//fixed by wanf /// <summary> /// 群组分页搜索 /// </summary> /// <param name="groupQuery">搜索条件</param> /// <param name="interestGroup">是否是查询可能感兴趣的群组</param> /// <returns>符合搜索条件的分页集合</returns> public PagingDataSet<GroupEntity> Search(GroupFullTextQuery groupQuery, bool interestGroup = false) { if (!interestGroup) { if (string.IsNullOrWhiteSpace(groupQuery.Keyword) && !groupQuery.KeywordIsNull) { return new PagingDataSet<GroupEntity>(new List<GroupEntity>()); } } LuceneSearchBuilder searchBuilder = BuildLuceneSearchBuilder(groupQuery, interestGroup); //使用LuceneSearchBuilder构建Lucene需要Query、Filter、Sort Query query = null; Filter filter = null; Sort sort = null; searchBuilder.BuildQuery(out query, out filter, out sort); //调用SearchService.Search(),执行搜索 PagingDataSet<Document> searchResult = searchEngine.Search(query, filter, sort, groupQuery.PageIndex, groupQuery.PageSize); IEnumerable<Document> docs = searchResult.ToList<Document>(); //解析出搜索结果中的群组ID List<long> groupIds = new List<long>(); //获取索引中群组的标签 Dictionary<long, IEnumerable<string>> groupTags = new Dictionary<long, IEnumerable<string>>(); //获取索引中群组的分类名 Dictionary<long, string> categoryNames = new Dictionary<long, string>(); foreach (Document doc in docs) { long groupId = long.Parse(doc.Get(GroupIndexDocument.GroupId)); groupIds.Add(groupId); groupTags[groupId]=doc.GetValues(GroupIndexDocument.Tag).ToList<string>(); categoryNames[groupId]=doc.Get(GroupIndexDocument.CategoryName); } //根据群组ID列表批量查询群组实例 IEnumerable<GroupEntity> groupList = groupService.GetGroupEntitiesByIds(groupIds); foreach (var group in groupList) { if (groupTags.ContainsKey(group.GroupId)) { group.TagNames = groupTags[group.GroupId]; } if (categoryNames.ContainsKey(group.GroupId)) { group.CategoryName = categoryNames[group.GroupId]; } } //组装分页对象 PagingDataSet<GroupEntity> GroupEntitys = new PagingDataSet<GroupEntity>(groupList) { TotalRecords = searchResult.TotalRecords, PageSize = searchResult.PageSize, PageIndex = searchResult.PageIndex, QueryDuration = searchResult.QueryDuration }; return GroupEntitys; }
/// <summary> /// 供职于同一公司 /// </summary> /// <param name="pageIndex">分页页码</param> /// <returns></returns> public ActionResult _InterestedWithCompanys(int pageIndex = 1, string view = null) { IUser CurrentUser = UserContext.CurrentUser; if (CurrentUser == null) { return null; } Dictionary<long, IEnumerable<string>> companyNameDic = null; UserSearcher searcher = (UserSearcher)SearcherFactory.GetSearcher(UserSearcher.CODE); PagingDataSet<User> users = searcher.SearchInterestedWithCompanys(CurrentUser.UserId, pageIndex, pageSize, out companyNameDic); ViewData["companyNameDic"] = companyNameDic; List<User> userList = new List<User>(); foreach (var user in users) { if (companyNameDic.ContainsKey(user.UserId) && companyNameDic[user.UserId].Count() > 0) { userList.Add(user); } } int pageCount = users.PageCount; users = new PagingDataSet<User>(userList); ViewData["pageCount"] = pageCount; if (string.IsNullOrEmpty(view)) { return View(users); } else { return View(view, users); } }
public ActionResult ListFavorites(string spaceKey, int? pageIndex) { pageResourceManager.InsertTitlePart("我的收藏"); long userId = UserIdToUserNameDictionary.GetUserId(spaceKey); PagingDataSet<long> pdsObjectIds = favoriteService.GetPagingObjectIds(userId, pageIndex ?? 1); IEnumerable<MicroblogEntity> microblogs = microblogService.GetMicroblogs(pdsObjectIds); PagingDataSet<MicroblogEntity> pds = new PagingDataSet<MicroblogEntity>(microblogs) { TotalRecords = pdsObjectIds.TotalRecords, PageSize = pdsObjectIds.PageSize, PageIndex = pdsObjectIds.PageIndex, QueryDuration = pdsObjectIds.QueryDuration }; return View(pds); }
/// <summary> /// 我关注的群组成员 /// </summary> /// <param name="spaceKey"></param> /// <param name="pageIndex"></param> /// <returns></returns> public ActionResult MyFollowedUsers(string spaceKey, int pageIndex = 1) { GroupEntity group = groupService.Get(spaceKey); if (group == null) return HttpNotFound(); var currentUser = UserContext.CurrentUser; if (currentUser == null) return Redirect(SiteUrls.Instance().Login(true)); pageResourceManager.InsertTitlePart(group.GroupName); pageResourceManager.InsertTitlePart("管理成员列表页"); long groupId = GroupIdToGroupKeyDictionary.GetGroupId(spaceKey); IEnumerable<GroupMember> groupMember = groupService.GetGroupMembersAlsoIsMyFollowedUser(groupId, currentUser.UserId); PagingDataSet<GroupMember> groupMembers = new PagingDataSet<GroupMember>(groupMember); if (currentUser.IsFollowed(group.User.UserId)) { ViewData["groupOwner"] = group.User; } return View(groupMembers); }
/// <summary> /// 用户搜索 /// </summary> /// <param name="userQuery">搜索条件</param> /// <returns>符合搜索条件的User分页集合</returns> public PagingDataSet<User> Search(UserFullTextQuery userQuery) { LuceneSearchBuilder searchBuilder = BuildLuceneSearchBuilder(userQuery); //使用LuceneSearchBuilder构建Lucene需要Query、Filter、Sort Query query = null; Filter filter = null; Sort sort = null; searchBuilder.BuildQuery(out query, out filter, out sort); //调用SearchEngine.Search(),执行搜索 PagingDataSet<Document> searchResult = searchEngine.Search(query, filter, sort, userQuery.PageIndex, userQuery.PageSize); IEnumerable<Document> docs = searchResult.ToList<Document>(); //解析出搜索结果中的用户ID List<long> userIds = new List<long>(); foreach (Document doc in docs) { long userId = long.Parse(doc.Get(UserIndexDocument.UserId)); userIds.Add(userId); } //根据用户ID列表批量查询用户实例 IEnumerable<User> userList = userService.GetFullUsers(userIds); //根据用户ID列表批量查询UserProfile实例,利用Repository的自动缓存机制,减少页面加载时的关联数据库查询次数 //对于UserProfile的Tag、WorkExperience、EducationExperience,目前页面列表不显示,暂不处理 userProfileService.GetUserProfiles(userIds); //组装分页对象 PagingDataSet<User> users = new PagingDataSet<User>(userList) { TotalRecords = searchResult.TotalRecords, PageSize = searchResult.PageSize, PageIndex = searchResult.PageIndex, QueryDuration = searchResult.QueryDuration }; return users; }
/// <summary> /// 搜索“使用了相同标签”的用户 /// </summary> /// <param name="userId">当前用户的ID(浏览者)</param> /// <param name="pageIndex">分页页码</param> /// <param name="pageSize">分页大小</param> /// <param name="tagNameDic">存储用户ID到标签列表的映射,用于页面列表输出</param> /// <returns></returns> public PagingDataSet<User> SearchInterestedWithTags(long userId, int pageIndex, int pageSize, out Dictionary<long, IEnumerable<string>> tagNameDic) { //Dictionary,用于页面列表输出 tagNameDic = new Dictionary<long, IEnumerable<string>>(); //无效用户ID,直接返回空列表 if (userId <= 0) { return new PagingDataSet<User>(new List<User>()); } Query query = null; Filter filter = null; Sort sort = null; //先搜索出当前用户的标签 //使用LuceneSearchBuilder构建Lucene需要Query、Filter、Sort LuceneSearchBuilder searchBuilder = new LuceneSearchBuilder(); searchBuilder.WithField(UserIndexDocument.UserId, userId.ToString(), true); searchBuilder.BuildQuery(out query, out filter, out sort); IEnumerable<Document> docs = searchEngine.Search(query, filter, sort, 1); //索引中无此用户,直接返回空列表 if (docs == null || docs.Count<Document>() == 0) { return new PagingDataSet<User>(new List<User>()); } string[] myTagNames = docs.First<Document>().GetValues(UserIndexDocument.TagName); //当前用户无标签,直接返回空列表 if (myTagNames != null && myTagNames.Count() == 0) { return new PagingDataSet<User>(new List<User>()); } //查找有相同标签的用户 //先查询当前用户关注的人(包括“悄悄关注”的用户),此处需要调用数据库查询,因为索引中没有存储“是否悄悄关注”属性 IEnumerable<long> myFollowedUserIds = followService.GetPortionFollowedUserIds(userId); //黑名单用户 IEnumerable<long> stopUserIds = new PrivacyService().GetStopedUsers(userId).Select(n => n.Key); //使用LuceneSearchBuilder构建Lucene需要Query、Filter、Sort searchBuilder = new LuceneSearchBuilder(0); //搜索条件需要排除掉当前用户本身 searchBuilder.WithPhrases(UserIndexDocument.TagName, myTagNames.ToList<string>()) .NotWithField(UserIndexDocument.UserId, userId.ToString()) //排除掉当前用户 .NotWithFields(UserIndexDocument.UserId, myFollowedUserIds.Select(n => n.ToString()))//排除掉已关注用户 .NotWithFields(UserIndexDocument.UserId, stopUserIds.Select(n => n.ToString()));//排除掉黑名单用户 searchBuilder.BuildQuery(out query, out filter, out sort); PagingDataSet<Document> searchResult = searchEngine.Search(query, filter, sort, pageIndex, pageSize); docs = searchResult.ToList<Document>(); //如果没有使用相同标签的用户,直接返回空列表 if (docs == null || docs.Count<Document>() == 0) { return new PagingDataSet<User>(new List<User>()); } //“使用了相同标签”的用户ID列表 List<long> sameUserIds = new List<long>(); foreach (Document doc in docs) { long sameUserId = long.Parse(doc.Get(UserIndexDocument.UserId)); sameUserIds.Add(sameUserId); string[] tagNames = doc.GetValues(UserIndexDocument.TagName); //比较获取“相同的标签” IEnumerable<string> sameTagNames = myTagNames.Intersect<string>(tagNames); //加入Dictionary,用于页面列表输出 if (!tagNameDic.ContainsKey(sameUserId)) { tagNameDic.Add(sameUserId, sameTagNames); } } //批量查询“使用了相同标签”的用户列表 IEnumerable<User> sameUsers = userService.GetFullUsers(sameUserIds).Where(n => n.IsCanbeFollow == true && n.IsActivated == true && n.IsBanned == false); //组装分页对象 PagingDataSet<User> users = new PagingDataSet<User>(sameUsers) { TotalRecords = searchResult.TotalRecords, PageSize = searchResult.PageSize, PageIndex = searchResult.PageIndex, QueryDuration = searchResult.QueryDuration }; return users; }
/// <summary> /// 关注的文章 /// </summary> public ActionResult Subscribed(string spaceKey, int pageIndex = 1) { PagingDataSet<BlogThread> blogs = new PagingDataSet<BlogThread>(new List<BlogThread>()); pageResourceManager.InsertTitlePart("我的关注"); PagingDataSet<long> threadIds = subscribeService.GetPagingObjectIds(UserContext.CurrentUser.UserId, pageIndex); if (threadIds != null && threadIds.Count > 0) { IEnumerable<BlogThread> blogList = blogService.GetBlogThreads(threadIds.ToList()); blogs = new PagingDataSet<BlogThread>(blogList) { TotalRecords = threadIds.TotalRecords, PageSize = threadIds.PageSize, PageIndex = threadIds.PageIndex, QueryDuration = threadIds.QueryDuration }; } return View(blogs); }
/// <summary> /// 获取提到用户的微博分页集合 /// </summary> /// <param name="userName">被提到的用户Id</param> /// <param name="pageIndex">页码</param> /// <returns></returns> public PagingDataSet<MicroblogEntity> GetMicroblogsByReferredUser(long userId, int pageIndex) { AtUserService atUserService = new AtUserService(TenantTypeIds.Instance().Microblog()); PagingDataSet<long> pagingIds = atUserService.GetPagingAssociateIds(userId, pageIndex); if (pagingIds != null) { PagingDataSet<MicroblogEntity> pds = new PagingDataSet<MicroblogEntity>(microblogRepository.PopulateEntitiesByEntityIds(pagingIds)); pds.PageIndex = pagingIds.PageIndex; pds.PageSize = pagingIds.PageSize; pds.TotalRecords = pagingIds.TotalRecords; return pds; } return null; }