diff --git a/CoreCms.Net.IRepository/Article/ICoreCmsArticleRepository.cs b/CoreCms.Net.IRepository/Article/ICoreCmsArticleRepository.cs index 23b0fb53..5e0d4ec6 100644 --- a/CoreCms.Net.IRepository/Article/ICoreCmsArticleRepository.cs +++ b/CoreCms.Net.IRepository/Article/ICoreCmsArticleRepository.cs @@ -10,6 +10,7 @@ using System; +using System.Collections.Generic; using System.Linq.Expressions; using System.Threading.Tasks; using CoreCms.Net.Model.Entities; @@ -42,5 +43,18 @@ namespace CoreCms.Net.IRepository Task> QueryPageAsync(Expression> predicate, Expression> orderByExpression, OrderByType orderByType, int pageIndex = 1, int pageSize = 20); + + + /// + /// 重写根据条件查询分页数据 + /// + /// 判断集合 + /// 排序方式 + /// + /// + /// + Task> QueryListAsync(Expression> predicate, + Expression> orderByExpression, OrderByType orderByType, int take); + } } \ No newline at end of file diff --git a/CoreCms.Net.IServices/Article/ICoreCmsArticleServices.cs b/CoreCms.Net.IServices/Article/ICoreCmsArticleServices.cs index 735fa0bc..8fbfd1ee 100644 --- a/CoreCms.Net.IServices/Article/ICoreCmsArticleServices.cs +++ b/CoreCms.Net.IServices/Article/ICoreCmsArticleServices.cs @@ -9,6 +9,7 @@ ***********************************************************************/ using System; +using System.Collections.Generic; using System.Linq.Expressions; using System.Threading.Tasks; using CoreCms.Net.Model.Entities; @@ -41,5 +42,18 @@ namespace CoreCms.Net.IServices Task> QueryPageAsync(Expression> predicate, Expression> orderByExpression, OrderByType orderByType, int pageIndex = 1, int pageSize = 20); + + + /// + /// 重写根据条件查询分页数据 + /// + /// 判断集合 + /// 排序方式 + /// + /// + /// + Task> QueryListAsync(Expression> predicate, + Expression> orderByExpression, OrderByType orderByType, int take); + } } \ No newline at end of file diff --git a/CoreCms.Net.Model/FromBody/FMArticle.cs b/CoreCms.Net.Model/FromBody/FMArticle.cs new file mode 100644 index 00000000..0e48ae98 --- /dev/null +++ b/CoreCms.Net.Model/FromBody/FMArticle.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CoreCms.Net.Model.FromBody +{ + /// + /// 获取新文章 + /// + public class FMGetNewArticle + { + public int num { set; get; } = 5; + public int typeId { set; get; } = 0; + } +} diff --git a/CoreCms.Net.Repository/Article/CoreCmsArticleRepository.cs b/CoreCms.Net.Repository/Article/CoreCmsArticleRepository.cs index 155755a5..094b39f8 100644 --- a/CoreCms.Net.Repository/Article/CoreCmsArticleRepository.cs +++ b/CoreCms.Net.Repository/Article/CoreCmsArticleRepository.cs @@ -10,6 +10,7 @@ using System; +using System.Collections.Generic; using System.Linq.Expressions; using System.Threading.Tasks; using CoreCms.Net.IRepository; @@ -128,5 +129,41 @@ namespace CoreCms.Net.Repository #endregion + + #region 重写根据条件查询分页数据 + + /// + /// 重写根据条件查询分页数据 + /// + /// 判断集合 + /// 排序方式 + /// + /// + /// + public async Task> QueryListAsync(Expression> predicate, + Expression> orderByExpression, OrderByType orderByType,int take) + { + var list = await DbClient.Queryable() + .OrderByIF(orderByExpression != null, orderByExpression, orderByType) + .WhereIF(predicate != null, predicate).Select(p => new CoreCmsArticle + { + id = p.id, + title = p.title, + brief = p.brief, + coverImage = p.coverImage, + typeId = p.typeId, + sort = p.sort, + isPub = p.isPub, + isDel = p.isDel, + pv = p.pv, + createTime = p.createTime, + updateTime = p.updateTime + }).Take(take).ToListAsync(); + return list; + } + + #endregion + + } } diff --git a/CoreCms.Net.Services/Article/CoreCmsArticleServices.cs b/CoreCms.Net.Services/Article/CoreCmsArticleServices.cs index e813f3ce..10a78d74 100644 --- a/CoreCms.Net.Services/Article/CoreCmsArticleServices.cs +++ b/CoreCms.Net.Services/Article/CoreCmsArticleServices.cs @@ -9,6 +9,7 @@ ***********************************************************************/ using System; +using System.Collections.Generic; using System.Linq.Expressions; using System.Threading.Tasks; using CoreCms.Net.IRepository; @@ -61,5 +62,19 @@ namespace CoreCms.Net.Services { return await _dal.QueryPageAsync(predicate, orderByExpression, orderByType, pageIndex, pageSize); } + + + /// + /// 重写根据条件查询分页数据 + /// + /// 判断集合 + /// 排序方式 + /// + /// + /// + public async Task> QueryListAsync(Expression> predicate, Expression> orderByExpression, OrderByType orderByType, int take) + { + return await _dal.QueryListAsync(predicate, orderByExpression, orderByType, take); + } } } \ No newline at end of file diff --git a/CoreCms.Net.Web.WebApi/Controllers/ArticleController.cs b/CoreCms.Net.Web.WebApi/Controllers/ArticleController.cs index 04fcf5a8..68fa040a 100644 --- a/CoreCms.Net.Web.WebApi/Controllers/ArticleController.cs +++ b/CoreCms.Net.Web.WebApi/Controllers/ArticleController.cs @@ -11,13 +11,11 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using CoreCms.Net.Auth.HttpContextUser; using CoreCms.Net.IServices; using CoreCms.Net.Model.Entities; using CoreCms.Net.Model.Entities.Expression; using CoreCms.Net.Model.FromBody; using CoreCms.Net.Model.ViewModels.UI; -using Essensoft.Paylink.Alipay.Domain; using Microsoft.AspNetCore.Mvc; using SqlSugar; @@ -30,26 +28,20 @@ namespace CoreCms.Net.Web.WebApi.Controllers [ApiController] public class ArticleController : ControllerBase { - - private IHttpContextUser _user; private readonly ICoreCmsArticleServices _articleServices; private readonly ICoreCmsArticleTypeServices _articleTypeServices; /// /// 构造函数 /// - /// /// /// - public ArticleController(IHttpContextUser user, ICoreCmsArticleServices articleServices, ICoreCmsArticleTypeServices articleTypeServices) + public ArticleController(ICoreCmsArticleServices articleServices, ICoreCmsArticleTypeServices articleTypeServices) { - _user = user; _articleServices = articleServices; _articleTypeServices = articleTypeServices; } - - #region 获取通知列表 /// /// 获取通知列表 @@ -70,6 +62,41 @@ namespace CoreCms.Net.Web.WebApi.Controllers #endregion + #region 获取文章栏目 + /// + /// 获取文章列表 + /// + /// + [HttpPost] + public async Task GetArticleClassify() + { + var jm = new WebApiCallBack + { + status = true, + data = await _articleTypeServices.QueryListByClauseAsync(p => p.id > 0, p => p.sort, OrderByType.Desc, true, true) + }; + return jm; + } + + #endregion + + #region 获取最新文章 + /// + /// 获取最新文章 + /// + /// + [HttpPost] + public async Task GetNewArticle([FromBody] FMGetNewArticle entity) + { + var jm = new WebApiCallBack + { + status = true, + data = await _articleServices.QueryListAsync(p => p.isPub == true, p => p.createTime, OrderByType.Desc, entity.num) + }; + return jm; + } + + #endregion #region 获取文章列表 /// @@ -81,10 +108,10 @@ namespace CoreCms.Net.Web.WebApi.Controllers { var jm = new WebApiCallBack(); - var articleType = await _articleTypeServices.QueryAsync(); + var articleType = await _articleTypeServices.QueryAsync(true, true); if (articleType.Any()) { - var where = PredicateBuilder.True(); + var where = PredicateBuilder.True(); if (entity.id > 0) { where = where.And(p => p.isDel == false && p.typeId == entity.id); @@ -99,7 +126,10 @@ namespace CoreCms.Net.Web.WebApi.Controllers { list, articleType, - count = list.TotalCount + count = list.TotalCount, + list.HasNextPage, + list.HasPreviousPage, + list.TotalPages }; } else @@ -117,7 +147,7 @@ namespace CoreCms.Net.Web.WebApi.Controllers #endregion - + #region 获取单个文章内容 /// /// 获取单个文章内容 /// @@ -138,6 +168,7 @@ namespace CoreCms.Net.Web.WebApi.Controllers jm.data = model; return jm; - } + } + #endregion } } diff --git a/CoreCms.Net.Web.WebApi/Controllers/GoodController.cs b/CoreCms.Net.Web.WebApi/Controllers/GoodController.cs index 9d126952..e4e6e0a5 100644 --- a/CoreCms.Net.Web.WebApi/Controllers/GoodController.cs +++ b/CoreCms.Net.Web.WebApi/Controllers/GoodController.cs @@ -210,11 +210,23 @@ namespace CoreCms.Net.Web.WebApi.Controllers } if (!string.IsNullOrWhiteSpace(obj.brandId)) { - var brandId = obj.brandId.ObjectToInt(0); - if (brandId > 0) + if (obj.brandId.Contains(",")) { - where = where.And(p => p.brandId == brandId); + var brandIdsIntArray = CommonHelper.StringToIntArray(obj.brandId); + if (brandIdsIntArray.Any()) + { + where = where.And(p => brandIdsIntArray.Contains(p.brandId)); + } } + else + { + var brandId = obj.brandId.ObjectToInt(0); + if (brandId > 0) + { + where = where.And(p => p.brandId == brandId); + } + } + } if (!string.IsNullOrWhiteSpace(obj.labelId)) {