123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
-
- using System.Collections.Generic;
- using CZFW.Framework.Logic;
- using System.Linq;
- using CZFW.Framework.Model.Entity;
- using CZKJ.GBRS2.Entity;
- using CZKJ.GBRS2.Interface;
- namespace CZKJ.GBRS2.Logic
- {
- public class ArticleLogic : LogicBase<ArticleEntity>, IArticle
- {
- public IList<ArticleEntity> GetList(int pageIndex, int pageSize, out int rowsCount, int? parentId, int? typeId, string keywords)
- {
- var queryable = Queryable;
- if (parentId.HasValue)
- {
- var idList = DbContext.Set<TypeEntity>().Where(x => x.ParentId == parentId).Select(x => x.Id).ToList();
- queryable = queryable.Where(x => idList.Contains(x.TypeId));
- }
- if (typeId.HasValue)
- {
- queryable = queryable.Where(x => x.TypeId == typeId);
- }
- if (!string.IsNullOrWhiteSpace(keywords))
- {
- queryable = queryable.Where(x => x.Title.Contains(keywords) || x.Summary.Contains(keywords) || x.Detail.Contains(keywords));
- }
- rowsCount = queryable.Count();
- var list = queryable.Join(DbContext.Set<TypeEntity>(), x => x.TypeId, y => y.Id, (x, y) => new { x, y.Name }).OrderByDescending(x => x.x.SortOrder).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
- return list.Select(x => new ArticleEntity
- {
- Id = x.x.Id,
- Image = x.x.Image,
- Title = x.x.Title,
- TypeName = x.Name,
- Summary = x.x.Summary,
- SortOrder = x.x.SortOrder,
- Source = x.x.Source,
- PublishTime = x.x.PublishTime
- }).ToList();
- }
- public IList<ArticleEntity> GetSelect(IList<int> idList, int? typeId, string keywords, int pageIndex, int pageSize, out int rowsCount)
- {
- var queryable = Queryable;
- if (idList != null && idList.Count > 0)
- {
- queryable = queryable.Where(x => !idList.Contains(x.Id));
- }
- if (typeId.HasValue)
- {
- var typeIdList = DbContext.Set<TypeEntity>().Where(x => x.ParentId == typeId).Select(x => x.Id).ToList();
- queryable = queryable.Where(x => typeIdList.Contains(x.TypeId));
- }
- if (!string.IsNullOrWhiteSpace(keywords))
- {
- queryable = queryable.Where(x => x.Title.Contains(keywords) || x.Summary.Contains(keywords) || x.Detail.Contains(keywords));
- }
- rowsCount = queryable.Count();
- var list = queryable.Join(DbContext.Set<TypeEntity>(), x => x.TypeId, y => y.Id, (x, y) => new { x, y.Name }).OrderByDescending(x => x.x.SortOrder).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
- return list.Select(x => new ArticleEntity
- {
- Id = x.x.Id,
- Image = x.x.Image,
- Title = x.x.Title,
- TypeName = x.Name,
- Summary = x.x.Summary,
- PublishTime = x.x.PublishTime
- }).ToList();
- }
- /// <summary>
- /// 根据类型集合获取文章列表(可选取几条)
- /// </summary>
- /// <param name="count"></param>
- /// <param name="typeIdList"></param>
- /// <returns></returns>
- public IList<ArticleEntity> GetList(int? count, params int[] typeIdList)
- {
- var articleList = new List<ArticleEntity>();
- if (count.HasValue)
- {
- foreach (var list in typeIdList.Select(item => DbContext.Set<ArticleEntity>().Where(x => x.TypeId == item).OrderByDescending(x => x.SortOrder).Take(count.Value).ToList()))
- {
- articleList.AddRange(list);
- }
- }
- else
- {
- articleList = DbContext.Set<ArticleEntity>().Where(x => typeIdList.Contains(x.TypeId)).ToList();
- }
- return articleList;
- }
- public IList<ArticleEntity> GetListCount(int? parentId, int? typeId, int count)
- {
- var queryable = Queryable;
- if (parentId.HasValue)
- {
- var idList = DbContext.Set<TypeEntity>().Where(x => x.ParentId == parentId).Select(x => x.Id).ToList();
- queryable = queryable.Where(x => idList.Contains(x.TypeId));
- }
- if (typeId.HasValue)
- {
- queryable = queryable.Where(x => x.TypeId == typeId);
- }
- var result = queryable.Join(DbContext.Set<TypeEntity>(), x => x.TypeId, y => y.Id, (x, y) => new { x, y.Name }).OrderByDescending(x => x.x.SortOrder).Take(count).ToList();
- return result.Select(x => new ArticleEntity
- {
- Id = x.x.Id,
- Image = x.x.Image,
- Title = x.x.Title,
- TypeName = x.Name,
- Summary = x.x.Summary,
- PublishTime = x.x.PublishTime
- }).ToList();
- }
- public IList<ArticleEntity> GetArticleList(int typeId, int pageIndex, int pageSize, out int rowsCount)
- {
- var queryable = Queryable.Where(x => x.TypeId == typeId);
- rowsCount = queryable.Count();
- return queryable.OrderByDescending(x => x.SortOrder).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
- }
- public IList<ArticleEntity> GetSearchResult(string keywords, int pageIndex, int pageSize, out int rowsCount)
- {
- var queryable = Queryable.Where(x => x.Title.Contains(keywords) || x.Summary.Contains(keywords) || x.Detail.Contains(keywords));
- rowsCount = queryable.Count();
- var result = queryable.Join(DbContext.Set<TypeEntity>(), x => x.TypeId, y => y.Id, (x, y) => new { x, y.Name }).Select(x => new { x.x.Title, x.x.PublishTime,x.x.SortOrder, TypeName = x.Name, x.x.Id }).OrderByDescending(x => x.SortOrder).Skip((pageIndex - 1) * pageSize).Take(pageSize);
- return result.ToList().Select(x => new ArticleEntity
- {
- Id = x.Id,
- Title = x.Title,
- PublishTime = x.PublishTime,
- TypeName = x.TypeName
- }).ToList();
- }
- }
- }
|