public static IPageOfList<ArticleInfo> List(ArticleSearchSetting setting) { return ArticleManage.List(setting); }
/// <summary> /// 带有分页的文章列表 /// </summary> /// <param name="searchSetting"></param> /// <returns></returns> public static IPageOfList<ArticleInfo> List(ArticleSearchSetting searchSetting) { FastPaging fp = new FastPaging(); fp.OverOrderBy = " A.PublishDateTime DESC"; fp.PageIndex = searchSetting.PageIndex; fp.PageSize = searchSetting.PageSize; fp.QueryFields = "*"; fp.TableName = "Articles"; fp.PrimaryKey = "Id"; fp.TableReName = "A"; fp.WithOptions = " WITH(NOLOCK)"; StringBuilder sbSQL = new StringBuilder(); if (searchSetting.ColumnIds != null && searchSetting.ColumnIds.Length > 0) { //过滤栏目分类 //跳过为0的值 string temp = Enumerable.Range(0, searchSetting.ColumnIds.Length).Select(i => { if (searchSetting.ColumnIds[i] > 0) { return string.Format(" A.CategoryId = {0} ", searchSetting.ColumnIds[i]); } return string.Empty; }).Aggregate((a, b) => a + " OR " + b); if(!string.IsNullOrEmpty(temp)){ sbSQL.AppendFormat(" AND ( {0} )",temp ); } } if (searchSetting.TechIds != null && searchSetting.TechIds.Length > 0) { //过滤技术分类 string temp = Enumerable.Range(0, searchSetting.TechIds.Length).Select(i => { if (searchSetting.TechIds[i] > 0) { return string.Format(" A2C.CategoryId = {0} ", searchSetting.TechIds[i]); } return string.Empty; }).Aggregate((a, b) => a + " OR " + b); if (!string.IsNullOrEmpty(temp)) { sbSQL.Append(" AND EXISTS("); sbSQL.Append(" SELECT * FROM dbo.Article2Category AS A2C WITH(NOLOCK)"); sbSQL.Append(" WHERE A2C.[Type] = 'tech'"); sbSQL.Append(" AND A.Id = A2C.ArticleId"); sbSQL.AppendFormat(" AND ( {0} )", temp); sbSQL.Append(" )"); } } if (searchSetting.IndustryIds != null && searchSetting.IndustryIds.Length > 0) { //过滤行业分类 string temp = Enumerable.Range(0, searchSetting.IndustryIds.Length).Select(i => { if (searchSetting.IndustryIds[i] > 0) { return string.Format(" A2C.CategoryId = {0} ", searchSetting.IndustryIds[i]); } return string.Empty; }).Aggregate((a, b) => a + " OR " + b); if (!string.IsNullOrEmpty(temp)) { sbSQL.Append(" AND EXISTS("); sbSQL.Append(" SELECT * FROM dbo.Article2Category AS A2C WITH(NOLOCK)"); sbSQL.Append(" WHERE A2C.[Type] = 'industry'"); sbSQL.Append(" AND A.Id = A2C.ArticleId"); sbSQL.AppendFormat(" AND ( {0} )", temp); sbSQL.Append(" )"); } } if(!searchSetting.IsDeleted){ sbSQL.Append(" AND IsDeleted = 0"); } fp.Condition = " 1 = 1 " + sbSQL.ToString(); //throw new Exception(fp.Build2005()); IList<ArticleInfo> list = new List<ArticleInfo>(); ArticleInfo model = null; DataTable dt = SQLPlus.ExecuteDataTable(CommandType.Text, fp.Build2005()); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { model = GetByDataRow(dr); if (model != null) { list.Add(model); } } } int count = Convert.ToInt32(SQLPlus.ExecuteScalar(CommandType.Text,fp.BuildCountSQL())); return new PageOfList<ArticleInfo>(list, searchSetting.PageIndex, searchSetting.PageSize, count); }