/// <summary> /// 获取群组贴吧的排行数据 /// </summary> /// <param name="tenantTypeId">租户类型Id</param> /// <param name="topNumber">前多少条</param> /// <param name="sortBy">主题帖排序依据</param> /// <returns></returns> public IEnumerable <BarThread> GetTopsThreadOfGroup(string tenantTypeId, int topNumber, bool?isEssential, SortBy_BarThread sortBy) { //只获取可对外显示审核状态的主题帖 //缓存周期:常用对象集合,不用维护即时性 return(GetTopEntities(topNumber, CachingExpirationType.UsualObjectCollection, () => { StringBuilder cacheKey = new StringBuilder(); cacheKey.AppendFormat("BarThreadRanks::TenantTypeId-{0}:SortBy-{1}:isEssential-{2}:isPublic-{3}", tenantTypeId, sortBy, isEssential, 1); return cacheKey.ToString(); } , () => { var sql = Sql.Builder; var whereSql = Sql.Builder; var orderSql = Sql.Builder; sql.Select("spb_BarThreads.*") .From("spb_BarThreads") .InnerJoin("spb_Groups") .On("spb_BarThreads.SectionId=spb_Groups.GroupId"); whereSql.Where("spb_BarThreads.TenantTypeId = @0", tenantTypeId); whereSql.Where("spb_Groups.IsPublic=@0", 1); if (isEssential.HasValue) { whereSql.Where("spb_BarThreads.IsEssential = @0", isEssential.Value); } switch (this.PubliclyAuditStatus) { case PubliclyAuditStatus.Again: case PubliclyAuditStatus.Fail: case PubliclyAuditStatus.Pending: case PubliclyAuditStatus.Success: whereSql.Where("spb_BarThreads.AuditStatus=@0", this.PubliclyAuditStatus); break; case PubliclyAuditStatus.Again_GreaterThanOrEqual: case PubliclyAuditStatus.Pending_GreaterThanOrEqual: whereSql.Where("spb_BarThreads.AuditStatus>@0", this.PubliclyAuditStatus); break; default: break; } CountService countService = new CountService(TenantTypeIds.Instance().BarThread()); string countTableName = countService.GetTableName_Counts(); switch (sortBy) { case SortBy_BarThread.DateCreated_Desc: orderSql.OrderBy("spb_BarThreads.ThreadId desc"); break; case SortBy_BarThread.LastModified_Desc: orderSql.OrderBy("spb_BarThreads.LastModified desc"); break; case SortBy_BarThread.HitTimes: sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, CountTypes.Instance().HitTimes())) .On("spb_BarThreads.ThreadId = c.ObjectId"); orderSql.OrderBy("c.StatisticsCount desc"); break; case SortBy_BarThread.StageHitTimes: StageCountTypeManager stageCountTypeManager = StageCountTypeManager.Instance(TenantTypeIds.Instance().BarThread()); int stageCountDays = stageCountTypeManager.GetMaxDayCount(CountTypes.Instance().HitTimes()); string stageCountType = stageCountTypeManager.GetStageCountType(CountTypes.Instance().HitTimes(), stageCountDays); sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, stageCountType)) .On("spb_BarThreads.ThreadId = c.ObjectId"); orderSql.OrderBy("c.StatisticsCount desc"); break; case SortBy_BarThread.PostCount: orderSql.OrderBy("spb_BarThreads.PostCount desc"); break; default: orderSql.OrderBy("spb_BarThreads.ThreadId desc"); break; } sql.Append(whereSql).Append(orderSql); return sql; })); }
/// <summary> /// 获取Sql语句 /// </summary> /// <param name="nameKeyword">商品名称关键字</param> /// <param name="categoryId">类别ID</param> /// <param name="isEnabled">是否上架</param> /// <param name="maxPrice">最大单价</param> /// <param name="minPrice">最小单价</param> /// <param name="sortBy">排序依据</param> /// <param name="topNumber">取出所需条数</param> /// <returns></returns> private Sql GetSql_GetPointGifts(string nameKeyword, long?categoryId, bool?isEnabled, int maxPrice, int minPrice, SortBy_PointGift sortBy, int topNumber) { Sql sql = Sql.Builder; Sql sql_Where = Sql.Builder; Sql sql_Orderby = Sql.Builder; sql.Select("spb_PointGifts.*") .From("spb_PointGifts"); if (!string.IsNullOrEmpty(nameKeyword)) { sql_Where.Where("spb_PointGifts.Name like @0", "%" + StringUtility.StripSQLInjection(nameKeyword) + "%"); } if (categoryId.HasValue) { if (categoryId != 0) { IEnumerable <Category> categories = new CategoryService().GetDescendants(categoryId.Value); List <long> categoryIds = new List <long> { categoryId.Value }; if (categories != null && categories.Count() > 0) { categoryIds.AddRange(categories.Select(n => n.CategoryId)); } sql.LeftJoin(string.Format("(select tn_ItemsInCategories.*,tn_Categories.CategoryName from tn_ItemsInCategories left join tn_Categories on tn_ItemsInCategories.CategoryId=tn_Categories.CategoryId where tn_ItemsInCategories.CategoryId in({0})) tn_ItemsInCategories", string.Join(",", categoryIds))) .On("spb_PointGifts.GiftId=tn_ItemsInCategories.ItemId"); sql_Where.Where("tn_ItemsInCategories.CategoryId in (@categoryIds)", new { categoryIds = categoryIds }); } } if (isEnabled.HasValue) { sql_Where.Where("spb_PointGifts.IsEnabled = @0", isEnabled); } if (maxPrice != 0 && minPrice != 0) { sql_Where.Where("spb_PointGifts.Price>= @0 and spb_PointGifts.Price<=@1", minPrice, maxPrice); } if (minPrice != 0 && maxPrice == 0) { sql_Where.Where("spb_PointGifts.Price>= @0", minPrice); } if (minPrice == 0 && maxPrice != 0) { sql_Where.Where("spb_PointGifts.Price>= 0 and spb_PointGifts.Price<=@0", maxPrice); } CountService countService = new CountService(TenantTypeIds.Instance().PointGift()); string countTableName = countService.GetTableName_Counts(); switch (sortBy) { case SortBy_PointGift.DateCreated_Desc: sql_Orderby.OrderBy("spb_PointGifts.LastModified desc"); break; case SortBy_PointGift.HitTimes_Desc: sql.LeftJoin(countTableName).On("spb_PointGifts.GiftId = " + countTableName + ".ObjectId"); sql_Where.Where(countTableName + ".CountType = @0 or " + countTableName + ".CountType is null", CountTypes.Instance().HitTimes()); sql_Orderby.OrderBy(countTableName + ".StatisticsCount desc"); break; case SortBy_PointGift.Price_Asc: sql_Orderby.OrderBy("spb_PointGifts.Price"); break; case SortBy_PointGift.Price_Desc: sql_Orderby.OrderBy("spb_PointGifts.Price desc"); break; case SortBy_PointGift.Sales_Desc: sql_Orderby.OrderBy("spb_PointGifts.ExchangedCount desc"); break; } sql.Append(sql_Where) .Append(sql_Orderby); return(sql); }
public CountHub(CountService countService) { this._countService = countService; }
public CountHub(CountService countService) { _countService = countService; }
/// <summary> /// 创建帖吧 /// </summary> /// <param name="section">帖吧</param> /// <param name="userId">当前操作人</param> /// <param name="managerIds">管理员用户Id</param> /// <param name="logoFile">帖吧标识图</param> /// <returns>是否创建成功</returns> public bool Create(BarSection section, long userId, IEnumerable <long> managerIds, Stream logoFile) { EventBus <BarSection> .Instance().OnBefore(section, new CommonEventArgs(EventOperationType.Instance().Create())); //设置审核状态 auditService.ChangeAuditStatusForCreate(userId, section); if (!(section.SectionId > 0)) { section.SectionId = IdGenerator.Next(); } long id = 0; long.TryParse(barSectionRepository.Insert(section).ToString(), out id); if (id > 0) { if (managerIds != null && managerIds.Count() > 0) { List <long> mangagerIds_list = managerIds.ToList(); mangagerIds_list.Remove(section.UserId); managerIds = mangagerIds_list; barSectionRepository.UpdateManagerIds(id, managerIds); } if (section.TenantTypeId == TenantTypeIds.Instance().Bar()) { //帖吧主、吧管理员自动关注本帖吧 SubscribeService subscribeService = new SubscribeService(TenantTypeIds.Instance().BarSection()); int followedCount = 0; bool result = subscribeService.Subscribe(section.SectionId, section.UserId); if (result) { followedCount++; } if (managerIds != null && managerIds.Count() > 0) { foreach (var managerId in managerIds) { result = subscribeService.Subscribe(section.SectionId, managerId); if (result) { followedCount++; } } } //增加帖吧的被关注数 CountService countService = new CountService(TenantTypeIds.Instance().BarSection()); countService.ChangeCount(CountTypes.Instance().FollowedCount(), section.SectionId, section.UserId, followedCount, true); } //上传Logo if (logoFile != null) { LogoService logoService = new LogoService(TenantTypeIds.Instance().BarSection()); section.LogoImage = logoService.UploadLogo(section.SectionId, logoFile); barSectionRepository.Update(section); } EventBus <BarSection> .Instance().OnAfter(section, new CommonEventArgs(EventOperationType.Instance().Create())); EventBus <BarSection, AuditEventArgs> .Instance().OnAfter(section, new AuditEventArgs(section.AuditStatus, null)); } return(id > 0); }
/// <summary> /// 根据排序条件分页显示用户 /// </summary> /// <param name="sortBy">排序条件</param> /// <param name="pageIndex">当前页码</param> /// <param name="pageSize">每页记录</param> /// <returns>根据排序条件倒排序分页显示用户</returns> public PagingDataSet <User> GetPagingUsers(SortBy_User?sortBy, int pageIndex, int pageSize) { PagingDataSet <User> users = GetPagingEntities(pageSize, pageIndex, Tunynet.Caching.CachingExpirationType.ObjectCollection, () => { StringBuilder cacheKey = new StringBuilder("PagingTopUsers:"); cacheKey.AppendFormat("SortBy-{0}", sortBy); return(cacheKey.ToString()); }, () => { var sql = PetaPoco.Sql.Builder; var whereSql = Sql.Builder; var orderSql = Sql.Builder; whereSql.Where("IsActivated =1 and IsBanned = 0"); CountService countService = new CountService(TenantTypeIds.Instance().User()); StageCountTypeManager stageCountTypeManager = StageCountTypeManager.Instance(TenantTypeIds.Instance().User()); string countTableName = countService.GetTableName_Counts(); int stageCountDays; string stageCountType; if (sortBy.HasValue) { switch (sortBy) { case SortBy_User.FollowerCount: orderSql.OrderBy("FollowerCount desc"); break; case SortBy_User.Rank: orderSql.OrderBy("Rank desc"); break; case SortBy_User.ReputationPoints: orderSql.OrderBy("ReputationPoints desc"); break; case SortBy_User.TradePoints: orderSql.OrderBy("TradePoints desc"); break; case SortBy_User.DateCreated: orderSql.OrderBy("UserId desc"); break; case SortBy_User.PreWeekHitTimes: stageCountDays = 7; stageCountType = stageCountTypeManager.GetStageCountType(CountTypes.Instance().HitTimes(), stageCountDays); sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, stageCountType)) .On("UserId = c.ObjectId"); orderSql.OrderBy("c.StatisticsCount desc"); break; case SortBy_User.HitTimes: sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, CountTypes.Instance().HitTimes())) .On("UserId = c.ObjectId"); orderSql.OrderBy("c.StatisticsCount desc"); break; case SortBy_User.PreWeekReputationPoints: stageCountDays = 7; stageCountType = stageCountTypeManager.GetStageCountType(CountTypes.Instance().ReputationPointsCounts(), stageCountDays); sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, stageCountType)) .On("UserId = c.ObjectId"); orderSql.OrderBy("c.StatisticsCount desc"); break; default: orderSql.OrderBy("UserId desc"); break; } } return(sql.Append(whereSql).Append(orderSql)); }); return(users); }
public CountWebService() { _countService = new CountService(); }
/// <summary> /// 根据不同条件分页获取问题列表(用于前台) /// </summary> /// <param name="tenantTypeId">租户类型id</param> /// <param name="tagName">标签</param> /// <param name="status">问题状态</param> /// <param name="isEssential">是否精华</param> /// <param name="sortBy">排序条件</param> /// <param name="pageSize">分页大小</param> /// <param name="pageIndex">页码</param> /// <returns>问题分页列表</returns> public Tunynet.PagingDataSet <AskQuestion> GetQuestions(string tenantTypeId, string tagName, QuestionStatus?status, bool?isEssential, SortBy_AskQuestion sortBy, int pageSize, int pageIndex) { return(GetPagingEntities(pageSize, pageIndex, CachingExpirationType.UsualObjectCollection, () => { StringBuilder cacheKey = new StringBuilder(); cacheKey.AppendFormat("GetQuestions::tenantTypeId-{0}:tagName-{1}:status-{2}:isEssential-{3}:sortBy-{4}", tenantTypeId, tagName, status, isEssential, sortBy); return cacheKey.ToString(); }, () => { var sql = Sql.Builder.Select("spb_AskQuestions.*").From("spb_AskQuestions"); var whereSql = Sql.Builder.Where("spb_AskQuestions.Status<>@0", QuestionStatus.Canceled); var orderSql = Sql.Builder; //过滤审核条件 switch (this.PubliclyAuditStatus) { case PubliclyAuditStatus.Again: case PubliclyAuditStatus.Fail: case PubliclyAuditStatus.Pending: case PubliclyAuditStatus.Success: whereSql.Where("spb_AskQuestions.AuditStatus=@0", this.PubliclyAuditStatus); break; case PubliclyAuditStatus.Again_GreaterThanOrEqual: case PubliclyAuditStatus.Pending_GreaterThanOrEqual: whereSql.Where("spb_AskQuestions.AuditStatus>@0", this.PubliclyAuditStatus); break; default: break; } if (!string.IsNullOrEmpty(tenantTypeId)) { whereSql.Where("spb_AskQuestions.TenantTypeId=@0", tenantTypeId); } if (status.HasValue) { whereSql.Where("spb_AskQuestions.Status=@0", status.Value); } if (isEssential.HasValue) { whereSql.Where("spb_AskQuestions.IsEssential=@0", isEssential.Value); } if (!string.IsNullOrEmpty(tagName)) { sql.InnerJoin("tn_ItemsInTags").On("spb_AskQuestions.QuestionId = tn_ItemsInTags.ItemId"); whereSql.Where("tn_ItemsInTags.TenantTypeId = @0", TenantTypeIds.Instance().AskQuestion()) .Where("tn_ItemsInTags.TagName=@0", tagName); } switch (sortBy) { case SortBy_AskQuestion.AnswerCount: orderSql.OrderBy("spb_AskQuestions.AnswerCount desc"); break; case SortBy_AskQuestion.StageHitTimes: CountService countService = new CountService(TenantTypeIds.Instance().AskQuestion()); string countTableName = countService.GetTableName_Counts(); StageCountTypeManager stageCountTypeManager = StageCountTypeManager.Instance(TenantTypeIds.Instance().AskQuestion()); int stageCountDays = stageCountTypeManager.GetMaxDayCount(CountTypes.Instance().HitTimes()); string stageCountType = stageCountTypeManager.GetStageCountType(CountTypes.Instance().HitTimes(), stageCountDays); sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, stageCountType)) .On("QuestionId = c.ObjectId"); orderSql.OrderBy("c.StatisticsCount desc"); break; case SortBy_AskQuestion.Reward: whereSql.Where("spb_AskQuestions.Reward > 0"); orderSql.OrderBy("spb_AskQuestions.Reward desc"); break; default: orderSql.OrderBy("spb_AskQuestions.QuestionId desc"); break; } sql.Append(whereSql).Append(orderSql); return sql; })); }
/// <summary> /// 撰写日志/转载日志 /// </summary> /// <param name="blogThread">日志实体</param> public bool Create(BlogThread blogThread, string privacyStatus1 = null, string privacyStatus2 = null) { //设计要点 //1、使用AuditService设置审核状态; //2、注意调用AttachmentService转换临时附件; //3、需要触发的事件参见《设计说明书-日志》 //4、草稿的审核状态为待审核; //5、转载的日志还需要为原日志转载数+1(调用计数服务); EventBus <BlogThread> .Instance().OnBefore(blogThread, new CommonEventArgs(EventOperationType.Instance().Create())); //设置审核状态,草稿的审核状态为待审核 if (blogThread.IsDraft) { blogThread.AuditStatus = AuditStatus.Pending; } else { AuditService auditService = new AuditService(); auditService.ChangeAuditStatusForCreate(blogThread.UserId, blogThread); } long threadId = 0; long.TryParse(blogThreadRepository.Insert(blogThread).ToString(), out threadId); if (threadId > 0) { //转换临时附件 AttachmentService attachmentService = new AttachmentService(TenantTypeIds.Instance().BlogThread()); attachmentService.ToggleTemporaryAttachments(blogThread.OwnerId, TenantTypeIds.Instance().BlogThread(), blogThread.ThreadId); //原日志转载数+1 if (blogThread.IsReproduced) { CountService countService = new CountService(TenantTypeIds.Instance().BlogThread()); countService.ChangeCount(CountTypes.Instance().ReproduceCount(), blogThread.OriginalThreadId, blogThread.OwnerId, 1, true); } //用户内容计数+1 if (!blogThread.IsDraft) { OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User()); ownerDataService.Change(blogThread.UserId, OwnerDataKeys.Instance().ThreadCount(), 1); } AtUserService atUserService = new AtUserService(TenantTypeIds.Instance().BlogThread()); atUserService.ResolveBodyForEdit(blogThread.GetBody(), blogThread.UserId, blogThread.ThreadId); //设置隐私状态 UpdatePrivacySettings(blogThread, privacyStatus1, privacyStatus2); EventBus <BlogThread> .Instance().OnAfter(blogThread, new CommonEventArgs(EventOperationType.Instance().Create())); EventBus <BlogThread, AuditEventArgs> .Instance().OnAfter(blogThread, new AuditEventArgs(null, blogThread.AuditStatus)); return(true); } return(false); }
/// <summary> /// 日志详细页 /// </summary> public ActionResult Detail(string spaceKey, long threadId) { BlogThread blogThread = blogService.Get(threadId); if (blogThread == null) { return HttpNotFound(); } if (!authorizer.BlogThread_View(blogThread)) { return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "没有权限", Body = "由于空间主人的权限设置,您无法浏览当前内容。", StatusMessageType = StatusMessageType.Hint })); } long currentSpaceUserId = UserIdToUserNameDictionary.GetUserId(spaceKey); if (!authorizer.IsAdministrator(BlogConfig.Instance().ApplicationId) && blogThread.UserId != currentSpaceUserId && (int)blogThread.AuditStatus < (int)(new AuditService().GetPubliclyAuditStatus(BlogConfig.Instance().ApplicationId))) return Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "尚未通过审核", Body = "由于当前日志尚未通过审核,您无法浏览当前内容。", StatusMessageType = StatusMessageType.Hint })); //附件信息 IEnumerable<Attachment> attachments = attachmentService.GetsByAssociateId(threadId); if (attachments != null && attachments.Count() > 0) { ViewData["attachments"] = attachments.Where(n => n.MediaType == MediaType.Other); } //更新浏览计数 CountService countService = new CountService(TenantTypeIds.Instance().BlogThread()); countService.ChangeCount(CountTypes.Instance().HitTimes(), blogThread.ThreadId, blogThread.UserId, 1, false); //设置SEO信息 pageResourceManager.InsertTitlePart(blogThread.Author); pageResourceManager.InsertTitlePart(blogThread.ResolvedSubject); List<string> keywords = new List<string>(); keywords.AddRange(blogThread.TagNames); keywords.AddRange(blogThread.OwnerCategoryNames); string keyword = string.Join(" ", keywords.Distinct()); if (!string.IsNullOrEmpty(blogThread.Keywords)) { keyword += " " + blogThread.Keywords; } pageResourceManager.SetMetaOfKeywords(keyword); if (!string.IsNullOrEmpty(blogThread.Summary)) { pageResourceManager.SetMetaOfDescription(HtmlUtility.StripHtml(blogThread.Summary, true, false)); } return View(blogThread); }
public override void ProcessRequest(HttpContext context) { long attachmentId = context.Request.QueryString.Get <long>("attachmentId", 0); if (attachmentId <= 0) { WebUtility.Return404(context); return; } string tenantTypeId = context.Request.QueryString.Get <string>("tenantTypeId", null); if (string.IsNullOrEmpty(tenantTypeId)) { WebUtility.Return404(context); return; } AttachmentService <Attachment> attachmentService = new AttachmentService <Attachment>(tenantTypeId); Attachment attachment = attachmentService.Get(attachmentId); if (attachment == null) { WebUtility.Return404(context); return; } IUser currentUser = UserContext.CurrentUser; //判断是否有附件的购买权限或下载权限,有下载权限肯定有购买权限,目前只有未登录或积分不够时才判定为没有权限 if (!DIContainer.Resolve <Authorizer>().Attachment_Buy(attachment)) { WebUtility.Return403(context); return; } //如果还没有下载权限,则说明积分可以支付附件售价,但是还未购买,则先进行积分交易 if (!DIContainer.Resolve <Authorizer>().Attachment_Download(attachment)) { //积分交易 PointService pointService = new PointService(); pointService.Trade(currentUser.UserId, attachment.UserId, attachment.Price, string.Format("购买附件{0}", attachment.FriendlyFileName), true); } //创建下载记录 AttachmentDownloadService attachmentDownloadService = new AttachmentDownloadService(); attachmentDownloadService.Create(currentUser == null ? 0 : currentUser.UserId, attachment.AttachmentId); //下载计数 CountService countService = new CountService(TenantTypeIds.Instance().Attachment()); countService.ChangeCount(CountTypes.Instance().DownloadCount(), attachment.AttachmentId, attachment.UserId, 1, false); bool enableCaching = context.Request.QueryString.GetBool("enableCaching", true); context.Response.Status = "302 Object Moved"; context.Response.StatusCode = 302; LinktimelinessSettings linktimelinessSettings = DIContainer.Resolve <ISettingsManager <LinktimelinessSettings> >().Get(); string token = Utility.EncryptTokenForAttachmentDownload(linktimelinessSettings.Highlinktimeliness, attachmentId); context.Response.Redirect(SiteUrls.Instance().AttachmentTempUrl(attachment.AttachmentId, tenantTypeId, token, enableCaching), true); context.Response.Flush(); context.Response.End(); }
public ActionResult Detail(string spaceKey, long threadId, int pageIndex = 1, bool onlyLandlord = false, SortBy_BarPost sortBy = SortBy_BarPost.DateCreated, long?postId = null, long?childPostIndex = null) { BarThread barThread = barThreadService.Get(threadId); if (barThread == null) { return(HttpNotFound()); } TopicEntity topic = topicService.Get(spaceKey); if (topic == null) { return(HttpNotFound()); } BarSection section = barSectionService.Get(barThread.SectionId); if (section == null || section.TenantTypeId != TenantTypeIds.Instance().Topic()) { return(HttpNotFound()); } //验证是否通过审核 long currentSpaceUserId = UserIdToUserNameDictionary.GetUserId(spaceKey); if (!authorizer.IsAdministrator(BarConfig.Instance().ApplicationId) && barThread.UserId != currentSpaceUserId && (int)barThread.AuditStatus < (int)(new AuditService().GetPubliclyAuditStatus(BarConfig.Instance().ApplicationId))) { return(Redirect(SiteUrls.Instance().SystemMessage(TempData, new SystemMessageViewModel { Title = "尚未通过审核", Body = "由于当前帖子尚未通过审核,您无法浏览当前内容。", StatusMessageType = StatusMessageType.Hint }))); } pageResourceManager.InsertTitlePart(section.Name); pageResourceManager.InsertTitlePart(barThread.Subject); Category category = categoryService.Get(barThread.CategoryId ?? 0); string keyWords = string.Join(",", barThread.TagNames); pageResourceManager.SetMetaOfKeywords(category != null ? category.CategoryName + "," + keyWords : keyWords); //设置Keyords类型的Meta pageResourceManager.SetMetaOfDescription(HtmlUtility.TrimHtml(barThread.GetResolvedBody(), 120)); //设置Description类型的Meta ViewData["EnableRating"] = barSettings.EnableRating; //更新浏览计数 CountService countService = new CountService(TenantTypeIds.Instance().BarThread()); countService.ChangeCount(CountTypes.Instance().HitTimes(), barThread.ThreadId, barThread.UserId, 1, false); PagingDataSet <BarPost> barPosts = barPostService.Gets(threadId, onlyLandlord, sortBy, pageIndex); if (pageIndex > barPosts.PageCount && pageIndex > 1) { return(Detail(spaceKey, threadId, barPosts.PageCount)); } if (Request.IsAjaxRequest()) { return(PartialView("~/Applications/Bar/Views/Bar/_ListPost.cshtml", barPosts)); } ViewData["barThread"] = barThread; ViewData["topic"] = topic; return(View(barPosts)); }
public CountController(CountService countService, ChildCountService childCountService) { _countService = countService; _childCountService = childCountService; }
/// <summary> /// 删除主题帖 /// </summary> /// <param name="threadId">主题帖Id</param> public void Delete(long threadId) { BarThread thread = barThreadRepository.Get(threadId); if (thread == null) { return; } EventBus <BarThread> .Instance().OnBefore(thread, new CommonEventArgs(EventOperationType.Instance().Delete())); BarSectionService barSectionService = new BarSectionService(); BarSection barSection = barSectionService.Get(thread.SectionId); if (barSection != null) { //帖子标签 TagService tagService = new TagService(TenantTypeIds.Instance().BarThread()); tagService.ClearTagsFromItem(threadId, barSection.SectionId); //帖子分类 CategoryService categoryService = new CategoryService(); categoryService.ClearCategoriesFromItem(threadId, barSection.SectionId, TenantTypeIds.Instance().BarThread()); } //删除回帖 BarPostService barPostService = new BarPostService(); barPostService.DeletesByThreadId(threadId); //删除推荐记录 RecommendService recommendService = new RecommendService(); recommendService.Delete(threadId, TenantTypeIds.Instance().BarThread()); int affectCount = barThreadRepository.Delete(thread); if (affectCount > 0) { //更新帖吧的计数 CountService countService = new CountService(TenantTypeIds.Instance().BarSection()); countService.ChangeCount(CountTypes.Instance().ThreadCount(), barSection.SectionId, barSection.UserId, -1, true); countService.ChangeCount(CountTypes.Instance().ThreadAndPostCount(), barSection.SectionId, barSection.UserId, -1, true); if (thread.TenantTypeId == TenantTypeIds.Instance().Group()) { //群组内容计数-1 OwnerDataService groupOwnerDataService = new OwnerDataService(TenantTypeIds.Instance().Group()); groupOwnerDataService.Change(thread.SectionId, OwnerDataKeys.Instance().ThreadCount(), -1); } else if (thread.TenantTypeId == TenantTypeIds.Instance().Bar()) { //用户内容计数-1 OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User()); ownerDataService.Change(thread.UserId, OwnerDataKeys.Instance().ThreadCount(), -1); } EventBus <BarThread> .Instance().OnAfter(thread, new CommonEventArgs(EventOperationType.Instance().Delete())); EventBus <BarThread, AuditEventArgs> .Instance().OnAfter(thread, new AuditEventArgs(thread.AuditStatus, null)); } //BarThread删除可能影响的: //1、附件 (看到了) //2、BarPost(看到了) //3、BarRating(看到了) //4、相关计数对象(看到了) //5、用户在应用中的数据(看到了) //6、@用户(看到了) }
/// <summary> /// 根据帖吧获取主题帖分页集合 /// </summary> /// <param name="tenantTypeId">租户类型Id</param> /// <param name="sectionId">帖吧Id</param> /// <param name="categoryId">帖吧分类Id</param> /// <param name="isEssential">是否为精华帖</param> /// <param name="sortBy">帖子排序依据</param> /// <param name="pageIndex">页码</param> /// <returns>主题帖列表</returns> public PagingDataSet <BarThread> Gets(long sectionId, long?categoryId, bool?isEssential, SortBy_BarThread sortBy, int pageIndex) { //只获取可对外显示审核状态的主题帖 //缓存周期:对象集合,需要维护即时性 return(GetPagingEntities(pageSize, pageIndex, CachingExpirationType.ObjectCollection, () => { StringBuilder cacheKey = new StringBuilder(); cacheKey.Append(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "SectionId", sectionId)); cacheKey.AppendFormat("BarThreadsOfSectionId::CategoryId-{0}:IsEssential-{1}:SortBy-{2}", categoryId, isEssential, sortBy); return cacheKey.ToString(); } , () => { var sql = Sql.Builder; var whereSql = Sql.Builder; var orderSql = Sql.Builder; sql.Select("spb_BarThreads.*") .From("spb_BarThreads"); whereSql.Where("SectionId = @0", sectionId); if (categoryId.HasValue && categoryId.Value > 0) { sql.InnerJoin("tn_ItemsInCategories") .On("ThreadId = tn_ItemsInCategories.ItemId"); whereSql.Where("tn_ItemsInCategories.CategoryId=@0", categoryId.Value); } if (isEssential.HasValue) { whereSql.Where("IsEssential = @0", isEssential.Value); } switch (this.PubliclyAuditStatus) { case PubliclyAuditStatus.Again: case PubliclyAuditStatus.Fail: case PubliclyAuditStatus.Pending: case PubliclyAuditStatus.Success: whereSql.Where("AuditStatus=@0", this.PubliclyAuditStatus); break; case PubliclyAuditStatus.Again_GreaterThanOrEqual: case PubliclyAuditStatus.Pending_GreaterThanOrEqual: whereSql.Where("AuditStatus>@0", this.PubliclyAuditStatus); break; default: break; } CountService countService = new CountService(TenantTypeIds.Instance().BarThread()); string countTableName = countService.GetTableName_Counts(); switch (sortBy) { case SortBy_BarThread.DateCreated_Desc: orderSql.OrderBy("ThreadId desc"); break; case SortBy_BarThread.LastModified_Desc: orderSql.OrderBy("IsSticky desc,LastModified desc"); break; case SortBy_BarThread.HitTimes: sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, CountTypes.Instance().HitTimes())) .On("ThreadId = c.ObjectId"); orderSql.OrderBy("c.StatisticsCount desc"); break; case SortBy_BarThread.StageHitTimes: StageCountTypeManager stageCountTypeManager = StageCountTypeManager.Instance(TenantTypeIds.Instance().BarThread()); int stageCountDays = stageCountTypeManager.GetMaxDayCount(CountTypes.Instance().HitTimes()); string stageCountType = stageCountTypeManager.GetStageCountType(CountTypes.Instance().HitTimes(), stageCountDays); sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, stageCountType)) .On("ThreadId = c.ObjectId"); orderSql.OrderBy("c.StatisticsCount desc"); break; case SortBy_BarThread.PostCount: orderSql.OrderBy("PostCount desc"); break; default: orderSql.OrderBy("ThreadId desc"); break; } sql.Append(whereSql).Append(orderSql); return sql; })); }
/// <summary> /// 获取前N个标签 /// </summary> /// <remarks>智能提示时也使用该方法获取数据</remarks> ///<param name="tenantTypeId">租户类型Id</param> ///<param name="topNumber">前N条数据</param> ///<param name="isFeatured">是否为特色标签</param> ///<param name="sortBy">标签排序字段</param> ///<param name="isTagCloud">为true时则不启用缓存</param> public IEnumerable <T> GetTopTags(string tenantTypeId, int topNumber, bool?isFeatured, SortBy_Tag?sortBy, bool isTagCloud = false) { IEnumerable <T> topTags = new List <T>(); if (!isTagCloud) { topTags = GetTopEntities(topNumber, CachingExpirationType.ObjectCollection, () => { //获取缓存 StringBuilder cacheKey = new StringBuilder(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "TenantTypeId", tenantTypeId)); //cacheKey.AppendFormat("TopNumber-{0}", topNumber); if (sortBy.HasValue) { cacheKey.AppendFormat(":SortBy-{0}", (int)sortBy); } if (isFeatured.HasValue) { cacheKey.AppendFormat(":IsFeatured-{0}", isFeatured); } return(cacheKey.ToString()); }, () => { var sql = Sql.Builder; var whereSql = Sql.Builder; var orderSql = Sql.Builder; sql.Select("tn_Tags.*") .From("tn_Tags"); if (!string.IsNullOrEmpty(tenantTypeId)) { whereSql.Where("TenantTypeId = @0", tenantTypeId); } if (isFeatured.HasValue) { whereSql.Where("IsFeatured = @0", isFeatured); } PubliclyAuditStatus publiclyAuditStatus = new AuditService().GetPubliclyAuditStatus(0); whereSql.Where("AuditStatus >= @0", publiclyAuditStatus); CountService countService = new CountService(TenantTypeIds.Instance().Tag()); string countTableName = countService.GetTableName_Counts(); StageCountTypeManager stageCountTypeManager = StageCountTypeManager.Instance(TenantTypeIds.Instance().Tag()); switch (sortBy) { case SortBy_Tag.OwnerCountDesc: orderSql.OrderBy("OwnerCount desc"); break; case SortBy_Tag.ItemCountDesc: orderSql.OrderBy("ItemCount desc"); break; case SortBy_Tag.PreDayItemCountDesc: string preDayCountType = stageCountTypeManager.GetStageCountTypes(CountTypes.Instance().ItemCounts()).Min(); sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, preDayCountType)) .On("TagId = c.ObjectId"); orderSql.OrderBy("c.StatisticsCount desc"); break; case SortBy_Tag.PreWeekItemCountDesc: string preWeekCountType = stageCountTypeManager.GetStageCountTypes(CountTypes.Instance().ItemCounts()).Max(); sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, preWeekCountType)) .On("TagId = c.ObjectId"); orderSql.OrderBy("c.StatisticsCount desc"); break; default: orderSql.OrderBy("TagId desc"); break; } sql.Append(whereSql).Append(orderSql); return(sql); }); } else { var sql = Sql.Builder; var whereSql = Sql.Builder; var orderSql = Sql.Builder; sql.Select("tn_Tags.*") .From("tn_Tags"); if (!string.IsNullOrEmpty(tenantTypeId)) { whereSql.Where("TenantTypeId = @0", tenantTypeId); } if (isFeatured.HasValue) { whereSql.Where("IsFeatured = @0", isFeatured); } PubliclyAuditStatus publiclyAuditStatus = new AuditService().GetPubliclyAuditStatus(0); whereSql.Where("AuditStatus >= @0", publiclyAuditStatus); CountService countService = new CountService(TenantTypeIds.Instance().Tag()); string countTableName = countService.GetTableName_Counts(); StageCountTypeManager stageCountTypeManager = StageCountTypeManager.Instance(TenantTypeIds.Instance().Tag()); switch (sortBy) { case SortBy_Tag.OwnerCountDesc: orderSql.OrderBy("OwnerCount desc"); break; case SortBy_Tag.ItemCountDesc: orderSql.OrderBy("ItemCount desc"); break; case SortBy_Tag.PreDayItemCountDesc: string preDayCountType = stageCountTypeManager.GetStageCountTypes(CountTypes.Instance().ItemCounts()).Min(); sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, preDayCountType)) .On("TagId = c.ObjectId"); orderSql.OrderBy("c.StatisticsCount desc"); break; case SortBy_Tag.PreWeekItemCountDesc: string preWeekCountType = stageCountTypeManager.GetStageCountTypes(CountTypes.Instance().ItemCounts()).Max(); sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, preWeekCountType)) .On("TagId = c.ObjectId"); orderSql.OrderBy("c.StatisticsCount desc"); break; default: orderSql.OrderBy("TagId desc"); break; } sql.Append(whereSql).Append(orderSql); IEnumerable <object> ids = CreateDAO().FetchTopPrimaryKeys <T>(topNumber, sql); topTags = PopulateEntitiesByEntityIds(ids); } return(topTags); }
/// <summary> /// 获取前N个用户 /// </summary> /// <param name="topNumber">获取用户数</param> /// <param name="sortBy">排序字段</param> /// <returns></returns> public IEnumerable <User> GetTopUsers(int topNumber, SortBy_User sortBy) { IEnumerable <User> topUsers = null; topUsers = GetTopEntities(topNumber, CachingExpirationType.ObjectCollection, () => { //获取缓存 StringBuilder cacheKey = new StringBuilder("TopUsers:"); cacheKey.AppendFormat("SortBy-{0}", (int)sortBy); return(cacheKey.ToString()); }, () => { var sql = PetaPoco.Sql.Builder; var whereSql = Sql.Builder; var orderSql = Sql.Builder; whereSql.Where("IsActivated =1 and IsBanned = 0"); CountService countService = new CountService(TenantTypeIds.Instance().User()); StageCountTypeManager stageCountTypeManager = StageCountTypeManager.Instance(TenantTypeIds.Instance().User()); string countTableName = countService.GetTableName_Counts(); int stageCountDays; string stageCountType; switch (sortBy) { case SortBy_User.FollowerCount: orderSql.OrderBy("FollowerCount desc"); break; case SortBy_User.ReputationPoints: orderSql.OrderBy("ReputationPoints desc"); break; case SortBy_User.DateCreated: orderSql.OrderBy("UserId desc"); break; case SortBy_User.PreWeekHitTimes: stageCountDays = 7; stageCountType = stageCountTypeManager.GetStageCountType(CountTypes.Instance().HitTimes(), stageCountDays); sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, stageCountType)) .On("UserId = c.ObjectId"); orderSql.OrderBy("c.StatisticsCount desc"); break; case SortBy_User.HitTimes: sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, CountTypes.Instance().HitTimes())) .On("UserId = c.ObjectId"); orderSql.OrderBy("c.StatisticsCount desc"); break; case SortBy_User.PreWeekReputationPoints: stageCountDays = 7; stageCountType = stageCountTypeManager.GetStageCountType(CountTypes.Instance().ReputationPointsCounts(), stageCountDays); sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, stageCountType)) .On("UserId = c.ObjectId"); orderSql.OrderBy("c.StatisticsCount desc"); break; default: orderSql.OrderBy("FollowerCount desc"); break; } return(sql.Append(whereSql).Append(orderSql)); }); return(topUsers); }
/// <summary> /// Gets和GetTops的sql语句 /// </summary> private Sql Getsqls(string areaCode, long?categoryId, string keyword, SortBy_Group sortBy) { Sql sql = Sql.Builder; var whereSql = Sql.Builder; var orderSql = Sql.Builder; sql.Select("spb_Groups.*").From("spb_Groups"); if (categoryId != null && categoryId.Value > 0) { CategoryService categoryService = new CategoryService(); IEnumerable <Category> categories = categoryService.GetDescendants(categoryId.Value); List <long> categoryIds = new List <long> { categoryId.Value }; if (categories != null && categories.Count() > 0) { categoryIds.AddRange(categories.Select(n => n.CategoryId)); } sql.InnerJoin("tn_ItemsInCategories") .On("spb_Groups.GroupId = tn_ItemsInCategories.ItemId"); whereSql.Where("tn_ItemsInCategories.CategoryId in(@categoryIds)", new { categoryIds = categoryIds }); } if (!string.IsNullOrEmpty(areaCode)) { if (areaCode.Equals("A1560000", StringComparison.CurrentCultureIgnoreCase)) { //已修改 whereSql.Where("AreaCode like '1%' or AreaCode like '2%' or AreaCode like '3%' or AreaCode like '4%' or AreaCode like '5%' or AreaCode like '6%' or AreaCode like '7%' or AreaCode like '8%' or AreaCode like '9%' "); } else { areaCode = areaCode.TrimEnd('0'); if (areaCode.Length % 2 == 1) { areaCode = areaCode + "0"; } whereSql.Where("AreaCode like @0 ", areaCode + "%"); } } if (!string.IsNullOrEmpty(keyword)) { whereSql.Where("GroupName like @0", keyword + "%"); } whereSql.Where("spb_Groups.IsPublic = 1"); //已修改 switch (this.PubliclyAuditStatus) { case PubliclyAuditStatus.Again: case PubliclyAuditStatus.Fail: case PubliclyAuditStatus.Pending: case PubliclyAuditStatus.Success: whereSql.Where("AuditStatus=@0", this.PubliclyAuditStatus); break; case PubliclyAuditStatus.Again_GreaterThanOrEqual: case PubliclyAuditStatus.Pending_GreaterThanOrEqual: whereSql.Where("AuditStatus>@0", this.PubliclyAuditStatus); break; default: break; } CountService countService = new CountService(TenantTypeIds.Instance().Group()); string countTableName = countService.GetTableName_Counts(); switch (sortBy) { case SortBy_Group.DateCreated_Desc: orderSql.OrderBy("DateCreated desc"); break; case SortBy_Group.GrowthValue_Desc: orderSql.OrderBy("GrowthValue desc"); break; case SortBy_Group.MemberCount_Desc: orderSql.OrderBy("MemberCount desc"); break; case SortBy_Group.HitTimes: sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, CountTypes.Instance().HitTimes())) .On("GroupId = c.ObjectId"); orderSql.OrderBy("c.StatisticsCount desc"); break; case SortBy_Group.StageHitTimes: StageCountTypeManager stageCountTypeManager = StageCountTypeManager.Instance(TenantTypeIds.Instance().Group()); int stageCountDays = stageCountTypeManager.GetMaxDayCount(CountTypes.Instance().HitTimes()); string stageCountType = stageCountTypeManager.GetStageCountType(CountTypes.Instance().HitTimes(), stageCountDays); sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, stageCountType)) .On("GroupId = c.ObjectId"); orderSql.OrderBy("c.StatisticsCount desc"); break; default: orderSql.OrderBy("DateCreated desc"); break; } sql.Append(whereSql).Append(orderSql); return(sql); }
/// <summary> /// 获取日志的排行数据 /// </summary> /// <param name="tenantTypeId">租户类型Id</param> /// <param name="topNumber">前多少条</param> /// <param name="categoryId">类别Id</param> /// <param name="isEssential">是否精华</param> /// <param name="sortBy">日志排序依据</param> /// <returns>日志列表</returns> public IEnumerable <BlogThread> GetTops(string tenantTypeId, int topNumber, long?categoryId, bool?isEssential, SortBy_BlogThread sortBy) { return(GetTopEntities(topNumber, CachingExpirationType.UsualObjectCollection, () => { StringBuilder cacheKey = new StringBuilder(); cacheKey.AppendFormat("BlogTops::TenantTypeId-{0}:CategoryId-{1}:IsEssential-{2}:SortBy-{3}", tenantTypeId, categoryId, isEssential, sortBy); return cacheKey.ToString(); }, () => { var sql = Sql.Builder.Select("spb_BlogThreads.*") .From("spb_BlogThreads"); var whereSql = Sql.Builder.Where("spb_BlogThreads.PrivacyStatus<>@0", PrivacyStatus.Private) .Where("spb_BlogThreads.IsDraft=0"); if (!string.IsNullOrEmpty(tenantTypeId)) { whereSql.Where("spb_BlogThreads.TenantTypeId=@0", tenantTypeId); } if (categoryId.HasValue && categoryId > 0) { sql.InnerJoin("tn_ItemsInCategories").On("spb_BlogThreads.ThreadId=tn_ItemsInCategories.ItemId"); whereSql.Where("tn_ItemsInCategories.CategoryId=@0", categoryId.Value); } switch (this.PubliclyAuditStatus) { case PubliclyAuditStatus.Again: case PubliclyAuditStatus.Fail: case PubliclyAuditStatus.Pending: case PubliclyAuditStatus.Success: whereSql.Where("spb_BlogThreads.AuditStatus=@0", this.PubliclyAuditStatus); break; case PubliclyAuditStatus.Again_GreaterThanOrEqual: case PubliclyAuditStatus.Pending_GreaterThanOrEqual: whereSql.Where("spb_BlogThreads.AuditStatus>@0", this.PubliclyAuditStatus); break; default: break; } if (isEssential.HasValue) { whereSql.Where("spb_BlogThreads.IsEssential=@0", isEssential); } var orderSql = Sql.Builder; CountService countService = new CountService(TenantTypeIds.Instance().BlogThread()); string countTableName = countService.GetTableName_Counts(); switch (sortBy) { case SortBy_BlogThread.DateCreated_Desc: orderSql.OrderBy("spb_BlogThreads.ThreadId desc"); break; case SortBy_BlogThread.CommentCount: sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, CountTypes.Instance().CommentCount())) .On("ThreadId = c.ObjectId"); orderSql.OrderBy("c.StatisticsCount desc"); break; case SortBy_BlogThread.StageHitTimes: StageCountTypeManager stageCountTypeManager = StageCountTypeManager.Instance(TenantTypeIds.Instance().BlogThread()); int stageCountDays = stageCountTypeManager.GetMaxDayCount(CountTypes.Instance().HitTimes()); string stageCountType = stageCountTypeManager.GetStageCountType(CountTypes.Instance().HitTimes(), stageCountDays); sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, stageCountType)) .On("ThreadId = c.ObjectId"); orderSql.OrderBy("c.StatisticsCount desc"); break; default: orderSql.OrderBy("spb_BlogThreads.ThreadId desc"); break; } return sql.Append(whereSql).Append(orderSql); })); }
/// <summary> /// 获取词条排行分页集合 /// </summary> /// <param name="tenantTypeId">租户类型Id</param> /// <param name="ignoreAudit">是否忽略审核状态</param> /// <param name="ownerId">所有者id</param> /// <param name="categoryId">类别Id</param> /// <param name="tagName">标签名称</param> /// <param name="isEssential">是否精华</param> /// <param name="sortBy">帖子排序依据</param> /// <param name="pageSize">分页大小</param> /// <param name="pageIndex">页码</param> /// <returns>词条分页列表</returns> public PagingDataSet <WikiPage> Gets(string keyWord, string tenantTypeId, long?ownerId, bool ignoreAudit, long?categoryId, string tagName, bool?isEssential, SortBy_WikiPage sortBy = SortBy_WikiPage.DateCreated_Desc, int pageSize = 20, int pageIndex = 1) { var sql = Sql.Builder.Select("spb_WikiPages.*").From("spb_WikiPages"); var whereSql = Sql.Builder.Where("spb_WikiPages.IsLogicalDelete=0"); var orderSql = Sql.Builder; if (!string.IsNullOrEmpty(tenantTypeId)) { whereSql.Where("spb_WikiPages.TenantTypeId=@0", tenantTypeId); } if (!string.IsNullOrEmpty(keyWord)) { whereSql.Where("spb_WikiPages.Title like @0", "%" + keyWord + "%"); } if (ownerId.HasValue) { whereSql.Where("spb_WikiPages.OwnerId=@0", ownerId.Value); } if (categoryId.HasValue && categoryId > 0) { sql.InnerJoin("tn_ItemsInCategories").On("spb_WikiPages.PageId=tn_ItemsInCategories.ItemId"); whereSql.Where("tn_ItemsInCategories.CategoryId=@0", categoryId.Value); } if (!string.IsNullOrEmpty(tagName)) { whereSql.Where("spb_WikiPages.PageId in ( select ItemId from tn_ItemsInTags where tn_ItemsInTags.TenantTypeId = @0 and tn_ItemsInTags.TagName=@1 )", TenantTypeIds.Instance().WikiPage(), tagName); } if (!ignoreAudit) { switch (this.PubliclyAuditStatus) { case PubliclyAuditStatus.Again: case PubliclyAuditStatus.Fail: case PubliclyAuditStatus.Pending: case PubliclyAuditStatus.Success: whereSql.Where("spb_WikiPages.AuditStatus=@0", this.PubliclyAuditStatus); break; case PubliclyAuditStatus.Again_GreaterThanOrEqual: case PubliclyAuditStatus.Pending_GreaterThanOrEqual: whereSql.Where("spb_WikiPages.AuditStatus>@0", this.PubliclyAuditStatus); break; default: break; } } if (isEssential.HasValue) { whereSql.Where("spb_WikiPages.IsEssential=@0", isEssential.Value); } CountService countService = new CountService(TenantTypeIds.Instance().WikiPage()); string countTableName = countService.GetTableName_Counts(); switch (sortBy) { case SortBy_WikiPage.DateCreated_Desc: orderSql.OrderBy("spb_WikiPages.PageId desc"); break; case SortBy_WikiPage.StageHitTimes: StageCountTypeManager stageCountTypeManager = StageCountTypeManager.Instance(TenantTypeIds.Instance().WikiPage()); int stageCountDays = stageCountTypeManager.GetMaxDayCount(CountTypes.Instance().HitTimes()); string stageCountType = stageCountTypeManager.GetStageCountType(CountTypes.Instance().HitTimes(), stageCountDays); sql.LeftJoin(string.Format("(select * from {0} WHERE ({0}.CountType = '{1}')) c", countTableName, stageCountType)) .On("PageId = c.ObjectId"); orderSql.OrderBy("c.StatisticsCount desc"); break; default: orderSql.OrderBy("spb_WikiPages.PageId desc"); break; } sql.Append(whereSql).Append(orderSql); return(GetPagingEntities(pageSize, pageIndex, sql)); }