MediaRepository.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. using System.Linq;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. using AutoMapper;
  5. using Datory;
  6. using GxPress.Common.AppOptions;
  7. using GxPress.Common.Tools;
  8. using GxPress.Repository.Interface.Media;
  9. using GxPress.Result.Media;
  10. using Microsoft.Extensions.Options;
  11. using System.Transactions;
  12. using GxPress.Common.Exceptions;
  13. using GxPress.Common.Page;
  14. using GxPress.Request.Media;
  15. using System;
  16. using GxPress.EnumConst;
  17. namespace GxPress.Repository.Implement.Media
  18. {
  19. public class MediaRepository : IMediaRepository
  20. {
  21. private readonly Repository<Entity.tede2.Media.Media> _repository;
  22. private readonly Repository<Entity.tede2.Media.MediaLibrary> mediaLibraryRepository;
  23. private readonly Repository<Entity.tede2.Media.MediaLable> mediaLableRepository;
  24. private readonly IMapper _mapper;
  25. private readonly string _connectionString;
  26. private readonly string _databaseTypestr;
  27. public MediaRepository(IOptionsMonitor<DatabaseOptions> dbOptionsAccessor, IMapper mapper)
  28. {
  29. _databaseTypestr = dbOptionsAccessor.CurrentValue.DatabaseType;
  30. _connectionString = dbOptionsAccessor.CurrentValue.ConnectionString;
  31. var databaseType =
  32. StringUtils.ToEnum<DatabaseType>(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql);
  33. var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString);
  34. _repository = new Repository<Entity.tede2.Media.Media>(database);
  35. mediaLibraryRepository = new Repository<Entity.tede2.Media.MediaLibrary>(database);
  36. mediaLableRepository = new Repository<Entity.tede2.Media.MediaLable>(database);
  37. _mapper = mapper;
  38. }
  39. public IDatabase Database => _repository.Database;
  40. public string TableName => _repository.TableName;
  41. public List<TableColumn> TableColumns => _repository.TableColumns;
  42. public async Task<MediaResult> GetAsync(int id)
  43. {
  44. var result = new MediaResult();
  45. //获取媒体
  46. var media = await _repository.GetAsync(id);
  47. result = _mapper.Map<MediaResult>(media);
  48. result.ImageUrls = StringUtils.AddDomain(result.ImageUrls);
  49. result.CategoryId = StringUtils.StringCollectionToStringList(media.CategoryId).ToList();
  50. result.CategoryName = StringUtils.StringCollectionToStringList(media.CategoryName).ToList();
  51. result.FullCategoryId = StringUtils.StringCollectionToStringList(media.FullCategoryId).ToList();
  52. //获取媒体库资源
  53. var mediaLibrarys = await mediaLibraryRepository.GetAllAsync(Q.Where(nameof(Entity.tede2.Media.MediaLibrary.MediaId), id));
  54. result.MediaLibraryResults = mediaLibrarys.ToList().Select(n => _mapper.Map<MediaLibraryResult>(n)).ToList();
  55. foreach (var item in result.MediaLibraryResults)
  56. {
  57. item.FileUrl = StringUtils.AddDomain(item.FileUrl);
  58. }
  59. //获取媒体标签
  60. var mediaLables = await mediaLableRepository.GetAllAsync(Q.Where(nameof(Entity.tede2.Media.MediaLable.MediaId), id));
  61. result.MediaLableResults = mediaLables.Select(n => _mapper.Map<MediaLableResult>(n)).ToList();
  62. return result;
  63. }
  64. /// <summary>
  65. /// 删除媒体
  66. /// </summary>
  67. /// <param name="id"></param>
  68. /// <returns></returns>
  69. public async Task<bool> DeleteAsync(int id)
  70. {
  71. try
  72. {
  73. using (var transactionScope = new TransactionScope())
  74. {
  75. // //删除媒体库
  76. // await mediaLibraryRepository.DeleteAsync(Q.Where(nameof(Entity.tede2.Media.MediaLibrary.MediaId), id));
  77. // //删除媒体标签
  78. // await mediaLableRepository.DeleteAsync(Q.Where(nameof(Entity.tede2.Media.MediaLable.MediaId), id));
  79. await _repository.UpdateAsync(Q.Where(nameof(Entity.tede2.Media.Media.Id), id).Set(nameof(Entity.tede2.Media.Media.IsDelete), true));
  80. transactionScope.Complete();
  81. }
  82. }
  83. catch (System.Exception ex)
  84. {
  85. throw new BusinessException(ex.Message);
  86. }
  87. return true;
  88. }
  89. /// <summary>
  90. /// 添加媒体
  91. /// </summary>
  92. /// <param name="result"></param>
  93. /// <returns></returns>
  94. public async Task<bool> InsertAsync(MediaResult result)
  95. {
  96. var model = _mapper.Map<Entity.tede2.Media.Media>(result);
  97. model.ImageUrls = StringUtils.RemoveDomain(result.ImageUrls);
  98. try
  99. {
  100. using (var transactionScope = new TransactionScope())
  101. {
  102. model.AutoNumber = SnowflakeHelper.MakeSnowflake();
  103. var categoryId = "";
  104. foreach (var item in result.CategoryId)
  105. {
  106. categoryId += item.Split(",")[item.Split(",").Length - 1] + ",";
  107. }
  108. categoryId = categoryId.Remove(categoryId.Length - 1, 1);
  109. model.CategoryId = categoryId;
  110. model.FullCategoryId = StringUtils.ObjectCollectionToString(result.CategoryId);
  111. var categoryName = "";
  112. foreach (var item in result.CategoryName)
  113. {
  114. categoryName += item.Split(",")[item.Split(",").Length - 1] + ",";
  115. }
  116. categoryName = categoryName.Remove(categoryName.Length - 1, 1);
  117. model.CategoryName = categoryName;
  118. model.IsLibrary = result.MediaLibraryResults.Count > 0;
  119. var id = await _repository.InsertAsync(model);
  120. if (id > 0)
  121. {
  122. foreach (var item in result.MediaLibraryResults)
  123. {
  124. var mediaLibrary = _mapper.Map<Entity.tede2.Media.MediaLibrary>(item);
  125. mediaLibrary.MediaId = id;
  126. mediaLibrary.FileUrl = StringUtils.RemoveDomain(item.FileUrl);
  127. await mediaLibraryRepository.InsertAsync(mediaLibrary);
  128. }
  129. }
  130. //添加标签
  131. foreach (var item in result.MediaLableResults)
  132. {
  133. var mediaLable = _mapper.Map<Entity.tede2.Media.MediaLable>(item);
  134. mediaLable.MediaId = id;
  135. await mediaLableRepository.InsertAsync(mediaLable);
  136. }
  137. if (result.Id == 0 && result.TeacherId == 0 && !string.IsNullOrEmpty(result.Author))
  138. {
  139. //新增名师
  140. }
  141. //提交事务
  142. transactionScope.Complete();
  143. }
  144. }
  145. catch (System.Exception ex)
  146. {
  147. throw new Common.Exceptions.BusinessException(ex.Message);
  148. }
  149. return true;
  150. }
  151. public async Task<bool> UpdateAsync(Entity.tede2.Media.Media note)
  152. {
  153. return await _repository.UpdateAsync(note);
  154. }
  155. public async Task<bool> UpdateAsync(SqlKata.Query query)
  156. {
  157. return await _repository.UpdateAsync(query) > 0;
  158. }
  159. /// <summary>
  160. /// 查询
  161. /// </summary>
  162. /// <param name="request"></param>
  163. /// <returns></returns>
  164. public async Task<PagedList<Entity.tede2.Media.Media>> GetAllAsync(MediaSearchRequest request)
  165. {
  166. var result = new PagedList<Entity.tede2.Media.Media>();
  167. var query = Q.NewQuery();
  168. if (!string.IsNullOrEmpty(request.KeyWord))
  169. {
  170. query.OrWhereLike(nameof(Entity.tede2.Media.Media.Title), $"%{request.KeyWord}%");
  171. query.OrWhereLike(nameof(Entity.tede2.Media.Media.Creator), $"%{request.KeyWord}%");
  172. }
  173. if (request.IsDelete > 0)
  174. query.Where(nameof(Entity.tede2.Media.Media.IsDelete), request.IsDelete == 1);
  175. if (request.MediaType > 0)
  176. query.Where(nameof(Entity.tede2.Media.Media.MediaType), request.MediaType);
  177. if (request.LibraryType > 0)
  178. query.Where(nameof(Entity.tede2.Media.Media.IsLibrary), request.LibraryType == 1);
  179. if (!string.IsNullOrEmpty(request.BeginTime) && !string.IsNullOrEmpty(request.EndTime))
  180. {
  181. if (DateTime.TryParse(request.BeginTime, out var beginTime) && DateTime.TryParse(request.EndTime, out var endTime))
  182. {
  183. query.WhereDate(nameof(Entity.tede2.Media.Media.CreatedDate), ">=", beginTime);
  184. query.WhereDate(nameof(Entity.tede2.Media.Media.CreatedDate), "<=", endTime);
  185. }
  186. }
  187. if (request.IsChecked > 0)
  188. query.Where(nameof(Entity.tede2.Media.Media.IsChecked), request.IsChecked == 1);
  189. result.Total = await _repository.CountAsync(query);
  190. //排序
  191. if (string.IsNullOrEmpty(request.Sort))
  192. query.OrderByDesc(nameof(Entity.tede2.Media.Media.CreatedDate));
  193. else if (request.Sort.Equals("SellAmount"))
  194. query.OrderByDesc(nameof(Entity.tede2.Media.Media.SellAmount));
  195. else if (request.Sort.Equals("ReadCount"))
  196. query.OrderByDesc(nameof(Entity.tede2.Media.Media.ReadCount));
  197. var item = await _repository.GetAllAsync(query.ForPage(request.Page, request.PerPage));
  198. result.Items = item;
  199. return result;
  200. }
  201. public async Task<bool> UpdateAsync(MediaResult result)
  202. {
  203. //var model = _mapper.Map<Entity.tede2.Media.Media>(result);
  204. try
  205. {
  206. using (var transactionScope = new TransactionScope())
  207. {
  208. var model = await _repository.GetAsync(result.Id);
  209. if (result.CategoryId != null && result.CategoryId.Count > 0)
  210. {
  211. var categoryId = "";
  212. foreach (var item in result.CategoryId)
  213. categoryId += item.Split(",")[item.Split(",").Length - 1] + ",";
  214. categoryId = categoryId.Remove(categoryId.Length - 1, 1);
  215. model.CategoryId = categoryId;
  216. model.FullCategoryId = StringUtils.ObjectCollectionToString(result.CategoryId);
  217. }
  218. if (result.CategoryName != null && result.CategoryName.Count > 0)
  219. {
  220. var categoryName = "";
  221. foreach (var item in result.CategoryName)
  222. categoryName += item.Split(",")[item.Split(",").Length - 1] + ",";
  223. categoryName = categoryName.Remove(categoryName.Length - 1, 1);
  224. model.CategoryName = categoryName;
  225. }
  226. if (result.AdminId > 0)
  227. model.AdminId = result.AdminId;
  228. if (!string.IsNullOrEmpty(result.Creator))
  229. model.Creator = result.Creator;
  230. if (result.MediaType > 0)
  231. model.MediaType = result.MediaType;
  232. if (!string.IsNullOrEmpty(result.Title))
  233. model.Title = result.Title;
  234. if (!string.IsNullOrEmpty(result.ImageUrls))
  235. model.ImageUrls = result.ImageUrls;
  236. if (!string.IsNullOrEmpty(result.Summary))
  237. model.Summary = result.Summary;
  238. if (!string.IsNullOrEmpty(result.Author))
  239. model.Author = result.Author;
  240. if (result.TeacherId > 0)
  241. model.TeacherId = result.TeacherId;
  242. if (!string.IsNullOrEmpty(result.Source))
  243. model.Source = result.Source;
  244. if (!string.IsNullOrEmpty(result.Blocks))
  245. model.Blocks = result.Blocks;
  246. if (result.IsChecked > 0)
  247. model.IsChecked = result.IsChecked == 1;
  248. if (!string.IsNullOrEmpty(result.AddDate))
  249. model.AddDate = Convert.ToDateTime(result.AddDate);
  250. if (model.Sort > 0)
  251. model.Sort = result.Sort;
  252. if (model.ReadCount > 0)
  253. model.ReadCount = result.ReadCount;
  254. if (result.IsTop > 0)
  255. model.IsTop = result.IsTop == 1;
  256. if (result.LableId > 0)
  257. model.LableId = result.LableId;
  258. if (result.IsRecommend > 0)
  259. model.IsRecommend = result.IsRecommend == 1;
  260. if (!string.IsNullOrEmpty(result.Press))
  261. model.Press = result.Press;
  262. if (!string.IsNullOrEmpty(result.PublishTime))
  263. model.PublishTime = result.PublishTime;
  264. if (result.IosDiscountPrice > 0)
  265. model.IosDiscountPrice = result.IosDiscountPrice;
  266. if (result.IosPrice > 0)
  267. model.IosPrice = result.IosPrice;
  268. if (result.OtherDiscountPrice > 0)
  269. model.OtherDiscountPrice = result.OtherDiscountPrice;
  270. if (result.OtherPrice > 0)
  271. model.OtherPrice = result.OtherPrice;
  272. if (result.FreeProportion > 0)
  273. model.FreeProportion = result.FreeProportion;
  274. if (result.AttachType > 0)
  275. model.AttachType = result.AttachType;
  276. if (result.AttachId > 0)
  277. model.AttachId = result.AttachId;
  278. if (result.MediaId > 0)
  279. model.MediaId = result.MediaId;
  280. if (!string.IsNullOrEmpty(result.MediaTitle))
  281. model.MediaTitle = result.MediaTitle;
  282. if (!string.IsNullOrEmpty(result.JournalsYear))
  283. model.JournalsYear = result.JournalsYear;
  284. if (result.JournalsCategory > 0)
  285. model.JournalsCategory = result.JournalsCategory;
  286. await _repository.UpdateAsync(model);
  287. if (result.MediaLibraryResults != null && result.MediaLibraryResults.Count > 0)
  288. {
  289. model.IsLibrary = result.MediaLibraryResults.Count > 0;
  290. //删除媒体库
  291. await mediaLibraryRepository.DeleteAsync(Q.Where(nameof(Entity.tede2.Media.MediaLibrary.MediaId), result.Id));
  292. foreach (var item in result.MediaLibraryResults)
  293. {
  294. var mediaLibrary = _mapper.Map<Entity.tede2.Media.MediaLibrary>(item);
  295. mediaLibrary.MediaId = result.Id;
  296. mediaLibrary.FileUrl = StringUtils.RemoveDomain(mediaLibrary.FileUrl);
  297. await mediaLibraryRepository.InsertAsync(mediaLibrary);
  298. }
  299. }
  300. if (result.MediaLableResults != null && result.MediaLableResults.Count > 0)
  301. {
  302. //删除媒体标签
  303. await mediaLableRepository.DeleteAsync(Q.Where(nameof(Entity.tede2.Media.MediaLable.MediaId), result.Id));
  304. //添加标签
  305. foreach (var item in result.MediaLableResults)
  306. {
  307. var mediaLable = _mapper.Map<Entity.tede2.Media.MediaLable>(item);
  308. mediaLable.MediaId = result.Id;
  309. await mediaLableRepository.InsertAsync(mediaLable);
  310. }
  311. }
  312. //提交事务
  313. transactionScope.Complete();
  314. }
  315. }
  316. catch (System.Exception ex)
  317. {
  318. throw new Common.Exceptions.BusinessException(ex.Message);
  319. }
  320. return true;
  321. }
  322. public async Task<int> CountAsync(string beginTime, string endTime)
  323. {
  324. return await _repository.CountAsync(Q.WhereDate(nameof(Entity.tede2.Media.Media.CreatedDate), ">=", beginTime).WhereDate(nameof(Entity.tede2.Media.Media.CreatedDate), "<=", endTime));
  325. }
  326. public async Task<int> CountAsync(SqlKata.Query query)
  327. {
  328. return await _repository.CountAsync(query);
  329. }
  330. public async Task<Entity.tede2.Media.Media> GetAsync(string autoNumber)
  331. {
  332. return await _repository.GetAsync(Q.Where(nameof(Entity.tede2.Media.Media.AutoNumber), autoNumber));
  333. }
  334. /// <summary>
  335. /// 获取书籍
  336. /// </summary>
  337. /// <param name="mediaId"></param>
  338. /// <returns></returns>
  339. public async Task<BookMediaResult> GetBookMediaResultAsync(int mediaId)
  340. {
  341. var result = await _repository.GetAsync(Q.Where(nameof(Entity.tede2.Media.Media.Id), mediaId).Where(nameof(Entity.tede2.Media.Media.IsChecked), true).Where(nameof(Entity.tede2.Media.Media.IsDelete), false));
  342. return _mapper.Map<BookMediaResult>(result);
  343. }
  344. /// <summary>
  345. /// 获取视频
  346. /// </summary>
  347. /// <param name="mediaId"></param>
  348. /// <returns></returns>
  349. public async Task<VideoMediaResult> GetVideoMediaResultAsync(int mediaId)
  350. {
  351. var result = await _repository.GetAsync(Q.Where(nameof(Entity.tede2.Media.Media.Id), mediaId).Where(nameof(Entity.tede2.Media.Media.IsChecked), true).Where(nameof(Entity.tede2.Media.Media.IsDelete), false));
  352. return _mapper.Map<VideoMediaResult>(result);
  353. }
  354. /// <summary>
  355. /// 根据
  356. /// </summary>
  357. /// <param name="mediaIds"></param>
  358. /// <returns></returns>
  359. public async Task<IEnumerable<NavigationMediaResult>> GetNavigationMediaResults(IEnumerable<int> mediaIds)
  360. {
  361. //获取媒体
  362. var query = Q.NewQuery();
  363. query.Select(nameof(Entity.tede2.Media.Media.Id));
  364. query.Select(nameof(Entity.tede2.Media.Media.ImageUrls));
  365. query.Select(nameof(Entity.tede2.Media.Media.Title));
  366. query.Select(nameof(Entity.tede2.Media.Media.Summary));
  367. query.Select(nameof(Entity.tede2.Media.Media.TeacherId));
  368. query.Select(nameof(Entity.tede2.Media.Media.AutoNumber));
  369. query.Select(nameof(Entity.tede2.Media.Media.Author));
  370. query.Select(nameof(Entity.tede2.Media.Media.MediaType));
  371. query.WhereIn(nameof(Entity.tede2.Media.Media.Id), mediaIds);
  372. query.Where(nameof(Entity.tede2.Media.Media.IsChecked), true);
  373. query.Where(nameof(Entity.tede2.Media.Media.IsDelete), false);
  374. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
  375. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsRecommend));
  376. query.ForPage(1, 10);
  377. return await _repository.GetAllAsync<NavigationMediaResult>(query);
  378. }
  379. /// <summary>
  380. /// 猜你喜欢
  381. /// </summary>
  382. /// <param name="mediaIds"></param>
  383. /// <returns></returns>
  384. public async Task<IEnumerable<NavigationMediaResult>> GetlikeMediaResults()
  385. {
  386. //获取媒体
  387. var query = Q.NewQuery();
  388. query.Select(nameof(Entity.tede2.Media.Media.Id));
  389. query.Select(nameof(Entity.tede2.Media.Media.ImageUrls));
  390. query.Select(nameof(Entity.tede2.Media.Media.Title));
  391. query.Select(nameof(Entity.tede2.Media.Media.Summary));
  392. query.Select(nameof(Entity.tede2.Media.Media.TeacherId));
  393. query.Select(nameof(Entity.tede2.Media.Media.AutoNumber));
  394. query.Select(nameof(Entity.tede2.Media.Media.Author));
  395. query.Select(nameof(Entity.tede2.Media.Media.MediaType));
  396. query.Where(nameof(Entity.tede2.Media.Media.IsTop), true);
  397. query.Where(nameof(Entity.tede2.Media.Media.IsChecked), true);
  398. query.Where(nameof(Entity.tede2.Media.Media.IsDelete), false);
  399. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
  400. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsRecommend));
  401. query.ForPage(1, 10);
  402. return await _repository.GetAllAsync<NavigationMediaResult>(query);
  403. }
  404. /// <summary>
  405. /// 推荐
  406. /// </summary>
  407. /// <param name="mediaIds"></param>
  408. /// <returns></returns>
  409. public async Task<IEnumerable<NavigationMediaResult>> GetRecommendMediaResults()
  410. {
  411. //获取媒体
  412. var query = Q.NewQuery();
  413. query.Select(nameof(Entity.tede2.Media.Media.Id));
  414. query.Select(nameof(Entity.tede2.Media.Media.ImageUrls));
  415. query.Select(nameof(Entity.tede2.Media.Media.Title));
  416. query.Select(nameof(Entity.tede2.Media.Media.Summary));
  417. query.Select(nameof(Entity.tede2.Media.Media.TeacherId));
  418. query.Select(nameof(Entity.tede2.Media.Media.AutoNumber));
  419. query.Select(nameof(Entity.tede2.Media.Media.Author));
  420. query.Select(nameof(Entity.tede2.Media.Media.MediaType));
  421. query.Where(nameof(Entity.tede2.Media.Media.IsRecommend), true);
  422. query.Where(nameof(Entity.tede2.Media.Media.IsChecked), true);
  423. query.Where(nameof(Entity.tede2.Media.Media.IsDelete), false);
  424. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
  425. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsRecommend));
  426. query.ForPage(1, 10);
  427. return await _repository.GetAllAsync<NavigationMediaResult>(query);
  428. }
  429. /// <summary>
  430. /// 排行榜
  431. /// </summary>
  432. /// <param name="request"></param>
  433. /// <returns></returns>
  434. public async Task<IEnumerable<RankingListResult>> GetRankingListResults(RankingListRequest request)
  435. {
  436. //获取媒体
  437. var query = Q.NewQuery();
  438. query.Select(nameof(Entity.tede2.Media.Media.Id));
  439. query.Select(nameof(Entity.tede2.Media.Media.ImageUrls));
  440. query.Select(nameof(Entity.tede2.Media.Media.Title));
  441. query.Select(nameof(Entity.tede2.Media.Media.Summary));
  442. query.Select(nameof(Entity.tede2.Media.Media.TeacherId));
  443. query.Select(nameof(Entity.tede2.Media.Media.AutoNumber));
  444. query.Select(nameof(Entity.tede2.Media.Media.Author));
  445. query.Select(nameof(Entity.tede2.Media.Media.MediaType));
  446. query.Select(nameof(Entity.tede2.Media.Media.Summary));
  447. query.Select(nameof(Entity.tede2.Media.Media.CommentScore));
  448. //1 热搜 2热书榜 3 课程榜 4Top 100 新书 5文献头条 6试听榜 7大众热评 8Top 100 专著
  449. if (request.DataTypeValue > 0)
  450. {
  451. //1 热搜
  452. if (request.DataTypeValue == RankingListConst.HotSearch.GetHashCode())
  453. query.OrderByDesc(nameof(Entity.tede2.Media.Media.ReadCount));
  454. //2热书榜
  455. if (request.DataTypeValue == RankingListConst.ReadBook.GetHashCode())
  456. {
  457. query.Where(nameof(Entity.tede2.Media.Media.MediaType), ResourceTypeConst.Book.GetHashCode());
  458. query.OrderByDesc(nameof(Entity.tede2.Media.Media.ReadCount));
  459. }
  460. //3 课程榜
  461. if (request.DataTypeValue == RankingListConst.Article.GetHashCode())
  462. {
  463. query.Where(nameof(Entity.tede2.Media.Media.MediaType), ResourceTypeConst.Article.GetHashCode());
  464. query.OrderByDesc(nameof(Entity.tede2.Media.Media.ReadCount));
  465. }
  466. //Top 100 新书
  467. if (request.DataTypeValue == RankingListConst.NewBook.GetHashCode())
  468. {
  469. query.Where(nameof(Entity.tede2.Media.Media.MediaType), ResourceTypeConst.Book.GetHashCode());
  470. query.OrderByDesc(nameof(Entity.tede2.Media.Media.CreatedDate));
  471. }
  472. //文献头条
  473. if (request.DataTypeValue == RankingListConst.ArticleTop.GetHashCode())
  474. {
  475. query.Where(nameof(Entity.tede2.Media.Media.MediaType), ResourceTypeConst.Article.GetHashCode());
  476. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
  477. }
  478. if (request.DataTypeValue == RankingListConst.Audio.GetHashCode())
  479. {
  480. query.Where(nameof(Entity.tede2.Media.Media.MediaType), ResourceTypeConst.Audio.GetHashCode());
  481. query.OrderByDesc(nameof(Entity.tede2.Media.Media.ReadCount));
  482. }
  483. if (request.DataTypeValue == RankingListConst.HotComment.GetHashCode())
  484. query.OrderByDesc(nameof(Entity.tede2.Media.Media.CommentScore));
  485. if (request.DataTypeValue == RankingListConst.CollectionBook.GetHashCode())
  486. query.OrderByDesc(nameof(Entity.tede2.Media.Media.CollectCount));
  487. }
  488. query.Where(nameof(Entity.tede2.Media.Media.IsChecked), true);
  489. query.Where(nameof(Entity.tede2.Media.Media.IsDelete), false);
  490. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
  491. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsRecommend));
  492. query.ForPage(request.Page, request.PerPage);
  493. return await _repository.GetAllAsync<RankingListResult>(query);
  494. }
  495. }
  496. }