/// <summary> /// 根据问题id获取回答实体列表 /// </summary> /// <remarks> /// 缓存周期:对象集合 /// </remarks> /// <param name="questionId">问题id</param> /// <param name="sortBy">排序条件</param> /// <param name="pageSize">分页大小</param> /// <param name="pageIndex">页码</param> /// <returns>回答分页列表</returns> public Tunynet.PagingDataSet <AskAnswer> GetAnswersByQuestionId(long questionId, SortBy_AskAnswer sortBy, int pageSize, int pageIndex) { return(GetPagingEntities(pageSize, pageIndex, CachingExpirationType.ObjectCollection, () => { StringBuilder cacheKey = new StringBuilder(); cacheKey.Append(RealTimeCacheHelper.GetListCacheKeyPrefix(CacheVersionType.AreaVersion, "QuestionId", questionId)); cacheKey.AppendFormat("GetAnswersByQuestionId::sortBy-{0}", sortBy); return cacheKey.ToString(); }, () => { var sql = Sql.Builder.Select("spb_AskAnswers.*").From("spb_AskAnswers"); var whereSql = Sql.Builder.Where("spb_AskAnswers.QuestionId=@0", questionId); var orderSql = Sql.Builder; //过滤审核状态 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; } switch (sortBy) { case SortBy_AskAnswer.SupportCount: sql.LeftJoin("tn_Attitudes").On("spb_AskAnswers.AnswerId = tn_Attitudes.ObjectId"); whereSql.Where("(tn_Attitudes.TenantTypeId=@0 or tn_Attitudes.TenantTypeId is null)", TenantTypeIds.Instance().AskAnswer()); orderSql.OrderBy("spb_AskAnswers.IsBest desc") .OrderBy("tn_Attitudes.SupportCount desc") .OrderBy("spb_AskAnswers.AnswerId desc"); break; default: orderSql.OrderBy("spb_AskAnswers.IsBest desc") .OrderBy("spb_AskAnswers.AnswerId desc"); break; } return sql.Append(whereSql).Append(orderSql); })); }
/// <summary> /// 根据问题id获取回答实体列表 /// </summary> /// <remarks> /// 缓存周期:对象集合 /// </remarks> /// <param name="questionId">问题id</param> /// <param name="sortBy">排序条件</param> /// <param name="pageSize">分页大小</param> /// <param name="pageIndex">页码</param> /// <returns>回答分页列表</returns> public PagingDataSet <AskAnswer> GetAnswersByQuestionId(long questionId, SortBy_AskAnswer sortBy, int pageSize, int pageIndex) { return(askAnswerRepository.GetAnswersByQuestionId(questionId, sortBy, pageSize, pageIndex)); }