/*********************************************************************** * Project: baifenBinfa * ProjectName: 百分兵法管理系统 * Web: http://chuanyin.com * Author: * Email: * CreateTime: 202403/02 * Description: 暂无 ***********************************************************************/ using System; using System.Collections.Generic; using System.Linq.Expressions; using System.Threading.Tasks; using CoreCms.Net.IRepository; using CoreCms.Net.IRepository.UnitOfWork; using CoreCms.Net.Model.Entities; using CoreCms.Net.Model.ViewModels.Basics; using CoreCms.Net.Utility.Helper; using SqlSugar; namespace CoreCms.Net.Repository { /// /// 文章表 接口实现 /// public class CoreCmsArticleRepository : BaseRepository, ICoreCmsArticleRepository { public CoreCmsArticleRepository(IUnitOfWork unitOfWork) : base(unitOfWork) { } #region 获取指定id 的文章详情 /// /// 获取指定id 的文章详情 /// /// 序列 public async Task ArticleDetail(int id) { var article = await DbClient.Queryable().Where(p => p.id == id && p.isPub == true) .FirstAsync(); if (article == null) { return null; } article.contentBody = CommonHelper.ClearHtml(article.contentBody, new[] { "width", "height" }); article.contentBody = article.contentBody.Replace(" 0) { article.articleType = await DbClient.Queryable().InSingleAsync(article.typeId); } //上一篇 article.upArticle = await DbClient.Queryable().Where(p => p.id < article.id && p.isPub == true).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 }).FirstAsync(); //下一篇 article.downArticle = await DbClient.Queryable().Where(p => p.id > article.id && p.isPub == true).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 }).FirstAsync(); await DbClient.Updateable().SetColumns(p => p.pv == (p.pv + 1)).Where(p => p.id == article.id).ExecuteCommandAsync(); return article; } #endregion #region 重写根据条件查询分页数据 /// /// 重写根据条件查询分页数据 /// /// 判断集合 /// 排序方式 /// 当前页面索引 /// 分布大小 /// /// public async Task> QueryPageAsync(Expression> predicate, Expression> orderByExpression, OrderByType orderByType, int pageIndex = 1, int pageSize = 20) { RefAsync totalCount = 0; var page = 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 }).ToPageListAsync(pageIndex, pageSize, totalCount); var list = new PageList(page, pageIndex, pageSize, totalCount); return list; } #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 } }