using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using HT.Cloud.Code; using HT.Cloud.DataBase; using HT.Cloud.Domain.ContentManage; namespace HT.Cloud.Service.ContentManage { /// /// 创 建:超级管理员 /// 日 期:2020-06-09 19:42 /// 描 述:新闻管理服务类 /// public class ArticleNewsService : BaseService, IDenpendency { public ArticleNewsService(ISqlSugarClient context) : base(context) { } #region 获取数据 public async Task> GetList(string keyword = "") { var query = repository.IQueryable(); if (!string.IsNullOrEmpty(keyword)) { query = query.Where(a => a.F_Title.Contains(keyword) || a.F_Tags.Contains(keyword)); } return await query.Where(a => a.F_DeleteMark == false).OrderBy(a => a.F_Id, OrderByType.Desc).ToListAsync(); } public async Task> GetLookList(SoulPage pagination, string keyword = "", string CategoryId = "") { //反格式化显示只能用"等于",其他不支持 Dictionary> dic = new Dictionary>(); Dictionary enabledTemp = new Dictionary(); enabledTemp.Add("1", "有效"); enabledTemp.Add("0", "无效"); dic.Add("F_EnabledMark", enabledTemp); Dictionary isTrue = new Dictionary(); isTrue.Add("1", "是"); isTrue.Add("0", "否"); dic.Add("F_IsTop", isTrue); dic.Add("F_IsHot", isTrue); pagination = ChangeSoulData(dic, pagination); //获取新闻列表 var query = repository.Db.Queryable((a, b) => new JoinQueryInfos( JoinType.Left, a.F_CategoryId == b.F_Id && b.F_EnabledMark == true )) .Select((a, b) => new ArticleNewsEntity { F_Id = a.F_Id.SelectAll(), F_CategoryName = b.F_FullName, }).MergeTable(); if (!string.IsNullOrEmpty(keyword)) { query = query.Where(a => a.F_Title.Contains(keyword)); } if (!string.IsNullOrEmpty(CategoryId)) { query = query.Where(a => a.F_CategoryId.Contains(CategoryId)); } query = query.Where(a => a.F_DeleteMark == false); //权限过滤 query = GetDataPrivilege("a", "", query); return await query.ToPageListAsync(pagination); } /// /// 获取新闻详情 /// /// 主键值 /// public async Task GetForm(string keyValue) { var query = repository.Db.Queryable((a, b) => new JoinQueryInfos( JoinType.Left, a.F_CategoryId == b.F_Id && b.F_EnabledMark == true )) .Select((a, b) => new ArticleNewsEntity { F_Id = a.F_Id.SelectAll(), F_CategoryName = b.F_FullName, }).MergeTable(); if (!string.IsNullOrEmpty(keyValue)) { query = query.Where(a => a.F_Id == keyValue); } //字段权限处理 return GetFieldsFilterData(await query.FirstAsync()); } #endregion 获取数据 #region 提交数据 public async Task SubmitForm(ArticleNewsEntity entity, string keyValue) { if (string.IsNullOrEmpty(entity.F_Zhaiyao)) { entity.F_Zhaiyao = TextHelper.GetSubString(WebHelper.NoHtml(entity.F_Description), 255); } if (string.IsNullOrEmpty(entity.F_SeoTitle)) { entity.F_SeoTitle = entity.F_Title; } if (string.IsNullOrEmpty(entity.F_SeoKeywords)) { entity.F_SeoKeywords = entity.F_Zhaiyao; } if (string.IsNullOrEmpty(entity.F_SeoDescription)) { entity.F_SeoDescription = entity.F_Zhaiyao; } if (string.IsNullOrEmpty(keyValue)) { entity.F_DeleteMark = false; //此处需修改 entity.Create(); await repository.Insert(entity); } else { //此处需修改 entity.Modify(keyValue); await repository.Update(entity); } } public async Task DeleteForm(string keyValue) { var ids = keyValue.Split(','); await repository.Delete(a => ids.Contains(a.F_Id)); } #endregion 提交数据 } }