MediaRepository.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  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. /// <summary>
  152. /// 获取媒体
  153. /// </summary>
  154. /// <param name="query"></param>
  155. /// <returns></returns>
  156. public async Task<MediaNoteResult> GetAsync(SqlKata.Query query)
  157. {
  158. query.Select(nameof(Entity.tede2.Media.Media.Id));
  159. query.Select(nameof(Entity.tede2.Media.Media.Title));
  160. query.Select(nameof(Entity.tede2.Media.Media.Author));
  161. query.Select(nameof(Entity.tede2.Media.Media.ImageUrls));
  162. return await _repository.GetAsync<MediaNoteResult>(query);
  163. }
  164. public async Task<bool> UpdateAsync(Entity.tede2.Media.Media note)
  165. {
  166. return await _repository.UpdateAsync(note);
  167. }
  168. public async Task<bool> UpdateAsync(SqlKata.Query query)
  169. {
  170. return await _repository.UpdateAsync(query) > 0;
  171. }
  172. /// <summary>
  173. /// 查询
  174. /// </summary>
  175. /// <param name="request"></param>
  176. /// <returns></returns>
  177. public async Task<PagedList<Entity.tede2.Media.Media>> GetAllAsync(MediaSearchRequest request)
  178. {
  179. var result = new PagedList<Entity.tede2.Media.Media>();
  180. var query = Q.NewQuery();
  181. if (!string.IsNullOrEmpty(request.KeyWord))
  182. {
  183. query.OrWhereLike(nameof(Entity.tede2.Media.Media.Title), $"%{request.KeyWord}%");
  184. query.OrWhereLike(nameof(Entity.tede2.Media.Media.Creator), $"%{request.KeyWord}%");
  185. }
  186. if (request.IsDelete > 0)
  187. query.Where(nameof(Entity.tede2.Media.Media.IsDelete), request.IsDelete == 1);
  188. if (request.MediaType > 0)
  189. query.Where(nameof(Entity.tede2.Media.Media.MediaType), request.MediaType);
  190. if (request.LibraryType > 0)
  191. query.Where(nameof(Entity.tede2.Media.Media.IsLibrary), request.LibraryType == 1);
  192. if (!string.IsNullOrEmpty(request.BeginTime) && !string.IsNullOrEmpty(request.EndTime))
  193. {
  194. if (DateTime.TryParse(request.BeginTime, out var beginTime) && DateTime.TryParse(request.EndTime, out var endTime))
  195. {
  196. query.WhereDate(nameof(Entity.tede2.Media.Media.CreatedDate), ">=", beginTime);
  197. query.WhereDate(nameof(Entity.tede2.Media.Media.CreatedDate), "<=", endTime);
  198. }
  199. }
  200. if (request.IsChecked > 0)
  201. query.Where(nameof(Entity.tede2.Media.Media.IsChecked), request.IsChecked == 1);
  202. result.Total = await _repository.CountAsync(query);
  203. //排序
  204. if (string.IsNullOrEmpty(request.Sort))
  205. query.OrderByDesc(nameof(Entity.tede2.Media.Media.CreatedDate));
  206. else if (request.Sort.Equals("SellAmount"))
  207. query.OrderByDesc(nameof(Entity.tede2.Media.Media.SellAmount));
  208. else if (request.Sort.Equals("ReadCount"))
  209. query.OrderByDesc(nameof(Entity.tede2.Media.Media.ReadCount));
  210. var item = await _repository.GetAllAsync(query.ForPage(request.Page, request.PerPage));
  211. result.Items = item;
  212. return result;
  213. }
  214. public async Task<bool> UpdateAsync(MediaResult result)
  215. {
  216. //var model = _mapper.Map<Entity.tede2.Media.Media>(result);
  217. try
  218. {
  219. using (var transactionScope = new TransactionScope())
  220. {
  221. var model = await _repository.GetAsync(result.Id);
  222. if (result.CategoryId != null && result.CategoryId.Count > 0)
  223. {
  224. var categoryId = "";
  225. foreach (var item in result.CategoryId)
  226. categoryId += item.Split(",")[item.Split(",").Length - 1] + ",";
  227. categoryId = categoryId.Remove(categoryId.Length - 1, 1);
  228. model.CategoryId = categoryId;
  229. model.FullCategoryId = StringUtils.ObjectCollectionToString(result.CategoryId);
  230. }
  231. if (result.CategoryName != null && result.CategoryName.Count > 0)
  232. {
  233. var categoryName = "";
  234. foreach (var item in result.CategoryName)
  235. categoryName += item.Split(",")[item.Split(",").Length - 1] + ",";
  236. categoryName = categoryName.Remove(categoryName.Length - 1, 1);
  237. model.CategoryName = categoryName;
  238. }
  239. if (result.AdminId > 0)
  240. model.AdminId = result.AdminId;
  241. if (!string.IsNullOrEmpty(result.Creator))
  242. model.Creator = result.Creator;
  243. if (result.MediaType > 0)
  244. model.MediaType = result.MediaType;
  245. if (!string.IsNullOrEmpty(result.Title))
  246. model.Title = result.Title;
  247. if (!string.IsNullOrEmpty(result.ImageUrls))
  248. model.ImageUrls = result.ImageUrls;
  249. if (!string.IsNullOrEmpty(result.Summary))
  250. model.Summary = result.Summary;
  251. if (!string.IsNullOrEmpty(result.Author))
  252. model.Author = result.Author;
  253. if (result.TeacherId > 0)
  254. model.TeacherId = result.TeacherId;
  255. if (!string.IsNullOrEmpty(result.Source))
  256. model.Source = result.Source;
  257. if (!string.IsNullOrEmpty(result.Blocks))
  258. model.Blocks = result.Blocks;
  259. if (result.IsChecked > 0)
  260. model.IsChecked = result.IsChecked == 1;
  261. if (!string.IsNullOrEmpty(result.AddDate))
  262. model.AddDate = Convert.ToDateTime(result.AddDate);
  263. if (model.Sort > 0)
  264. model.Sort = result.Sort;
  265. if (model.ReadCount > 0)
  266. model.ReadCount = result.ReadCount;
  267. if (result.IsTop > 0)
  268. model.IsTop = result.IsTop == 1;
  269. if (result.LableId > 0)
  270. model.LableId = result.LableId;
  271. if (result.IsRecommend > 0)
  272. model.IsRecommend = result.IsRecommend == 1;
  273. if (!string.IsNullOrEmpty(result.Press))
  274. model.Press = result.Press;
  275. if (!string.IsNullOrEmpty(result.PublishTime))
  276. model.PublishTime = result.PublishTime;
  277. if (result.IosDiscountPrice > 0)
  278. model.IosDiscountPrice = result.IosDiscountPrice;
  279. if (result.IosPrice > 0)
  280. model.IosPrice = result.IosPrice;
  281. if (result.OtherDiscountPrice > 0)
  282. model.OtherDiscountPrice = result.OtherDiscountPrice;
  283. if (result.OtherPrice > 0)
  284. model.OtherPrice = result.OtherPrice;
  285. if (result.FreeProportion > 0)
  286. model.FreeProportion = result.FreeProportion;
  287. if (result.AttachType > 0)
  288. model.AttachType = result.AttachType;
  289. if (result.AttachId > 0)
  290. model.AttachId = result.AttachId;
  291. if (result.MediaId > 0)
  292. model.MediaId = result.MediaId;
  293. if (!string.IsNullOrEmpty(result.MediaTitle))
  294. model.MediaTitle = result.MediaTitle;
  295. if (!string.IsNullOrEmpty(result.JournalsYear))
  296. model.JournalsYear = result.JournalsYear;
  297. if (result.JournalsCategory > 0)
  298. model.JournalsCategory = result.JournalsCategory;
  299. await _repository.UpdateAsync(model);
  300. if (result.MediaLibraryResults != null && result.MediaLibraryResults.Count > 0)
  301. {
  302. model.IsLibrary = result.MediaLibraryResults.Count > 0;
  303. //删除媒体库
  304. await mediaLibraryRepository.DeleteAsync(Q.Where(nameof(Entity.tede2.Media.MediaLibrary.MediaId), result.Id));
  305. foreach (var item in result.MediaLibraryResults)
  306. {
  307. var mediaLibrary = _mapper.Map<Entity.tede2.Media.MediaLibrary>(item);
  308. mediaLibrary.MediaId = result.Id;
  309. mediaLibrary.FileUrl = StringUtils.RemoveDomain(mediaLibrary.FileUrl);
  310. await mediaLibraryRepository.InsertAsync(mediaLibrary);
  311. }
  312. }
  313. if (result.MediaLableResults != null && result.MediaLableResults.Count > 0)
  314. {
  315. //删除媒体标签
  316. await mediaLableRepository.DeleteAsync(Q.Where(nameof(Entity.tede2.Media.MediaLable.MediaId), result.Id));
  317. //添加标签
  318. foreach (var item in result.MediaLableResults)
  319. {
  320. var mediaLable = _mapper.Map<Entity.tede2.Media.MediaLable>(item);
  321. mediaLable.MediaId = result.Id;
  322. await mediaLableRepository.InsertAsync(mediaLable);
  323. }
  324. }
  325. //提交事务
  326. transactionScope.Complete();
  327. }
  328. }
  329. catch (System.Exception ex)
  330. {
  331. throw new Common.Exceptions.BusinessException(ex.Message);
  332. }
  333. return true;
  334. }
  335. public async Task<int> CountAsync(string beginTime, string endTime)
  336. {
  337. return await _repository.CountAsync(Q.WhereDate(nameof(Entity.tede2.Media.Media.CreatedDate), ">=", beginTime).WhereDate(nameof(Entity.tede2.Media.Media.CreatedDate), "<=", endTime));
  338. }
  339. public async Task<int> CountAsync(SqlKata.Query query)
  340. {
  341. return await _repository.CountAsync(query);
  342. }
  343. public async Task<Entity.tede2.Media.Media> GetAsync(string autoNumber)
  344. {
  345. return await _repository.GetAsync(Q.Where(nameof(Entity.tede2.Media.Media.AutoNumber), autoNumber));
  346. }
  347. /// <summary>
  348. /// 获取书籍
  349. /// </summary>
  350. /// <param name="mediaId"></param>
  351. /// <returns></returns>
  352. public async Task<BookMediaResult> GetBookMediaResultAsync(int mediaId)
  353. {
  354. 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));
  355. return _mapper.Map<BookMediaResult>(result);
  356. }
  357. /// <summary>
  358. /// 获取视频
  359. /// </summary>
  360. /// <param name="mediaId"></param>
  361. /// <returns></returns>
  362. public async Task<VideoMediaResult> GetVideoMediaResultAsync(int mediaId)
  363. {
  364. 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));
  365. return _mapper.Map<VideoMediaResult>(result);
  366. }
  367. /// <summary>
  368. /// 根据
  369. /// </summary>
  370. /// <param name="mediaIds"></param>
  371. /// <returns></returns>
  372. public async Task<IEnumerable<NavigationMediaResult>> GetNavigationMediaResults(IEnumerable<int> mediaIds, int pageSize = 10)
  373. {
  374. //获取媒体
  375. var query = Q.NewQuery();
  376. query.Select(nameof(Entity.tede2.Media.Media.Id));
  377. query.Select(nameof(Entity.tede2.Media.Media.ImageUrls));
  378. query.Select(nameof(Entity.tede2.Media.Media.Title));
  379. query.Select(nameof(Entity.tede2.Media.Media.Summary));
  380. query.Select(nameof(Entity.tede2.Media.Media.TeacherId));
  381. query.Select(nameof(Entity.tede2.Media.Media.AutoNumber));
  382. query.Select(nameof(Entity.tede2.Media.Media.Author));
  383. query.Select(nameof(Entity.tede2.Media.Media.MediaType));
  384. query.WhereIn(nameof(Entity.tede2.Media.Media.Id), mediaIds);
  385. query.Where(nameof(Entity.tede2.Media.Media.IsChecked), true);
  386. query.Where(nameof(Entity.tede2.Media.Media.IsDelete), false);
  387. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
  388. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsRecommend));
  389. query.OrderByDesc(nameof(Entity.tede2.Media.Media.LastModifiedDate));
  390. query.ForPage(1, pageSize);
  391. return await _repository.GetAllAsync<NavigationMediaResult>(query);
  392. }
  393. /// <summary>
  394. /// 猜你喜欢
  395. /// </summary>
  396. /// <param name="mediaIds"></param>
  397. /// <returns></returns>
  398. public async Task<IEnumerable<NavigationMediaResult>> GetlikeMediaResults()
  399. {
  400. //获取媒体
  401. var query = Q.NewQuery();
  402. query.Select(nameof(Entity.tede2.Media.Media.Id));
  403. query.Select(nameof(Entity.tede2.Media.Media.ImageUrls));
  404. query.Select(nameof(Entity.tede2.Media.Media.Title));
  405. query.Select(nameof(Entity.tede2.Media.Media.Summary));
  406. query.Select(nameof(Entity.tede2.Media.Media.TeacherId));
  407. query.Select(nameof(Entity.tede2.Media.Media.AutoNumber));
  408. query.Select(nameof(Entity.tede2.Media.Media.Author));
  409. query.Select(nameof(Entity.tede2.Media.Media.MediaType));
  410. query.Where(nameof(Entity.tede2.Media.Media.IsTop), true);
  411. query.Where(nameof(Entity.tede2.Media.Media.IsChecked), true);
  412. query.Where(nameof(Entity.tede2.Media.Media.IsDelete), false);
  413. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
  414. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsRecommend));
  415. query.ForPage(1, 10);
  416. return await _repository.GetAllAsync<NavigationMediaResult>(query);
  417. }
  418. /// <summary>
  419. /// 推荐
  420. /// </summary>
  421. /// <param name="mediaIds"></param>
  422. /// <returns></returns>
  423. public async Task<IEnumerable<NavigationMediaResult>> GetRecommendMediaResults()
  424. {
  425. //获取媒体
  426. var query = Q.NewQuery();
  427. query.Select(nameof(Entity.tede2.Media.Media.Id));
  428. query.Select(nameof(Entity.tede2.Media.Media.ImageUrls));
  429. query.Select(nameof(Entity.tede2.Media.Media.Title));
  430. query.Select(nameof(Entity.tede2.Media.Media.Summary));
  431. query.Select(nameof(Entity.tede2.Media.Media.TeacherId));
  432. query.Select(nameof(Entity.tede2.Media.Media.AutoNumber));
  433. query.Select(nameof(Entity.tede2.Media.Media.Author));
  434. query.Select(nameof(Entity.tede2.Media.Media.MediaType));
  435. query.Where(nameof(Entity.tede2.Media.Media.IsRecommend), true);
  436. query.Where(nameof(Entity.tede2.Media.Media.IsChecked), true);
  437. query.Where(nameof(Entity.tede2.Media.Media.IsDelete), false);
  438. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
  439. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsRecommend));
  440. query.ForPage(1, 10);
  441. return await _repository.GetAllAsync<NavigationMediaResult>(query);
  442. }
  443. /// <summary>
  444. /// 排行榜
  445. /// </summary>
  446. /// <param name="request"></param>
  447. /// <returns></returns>
  448. public async Task<IEnumerable<RankingListResult>> GetRankingListResults(RankingListRequest request)
  449. {
  450. //获取媒体
  451. var query = Q.NewQuery();
  452. query.Select(nameof(Entity.tede2.Media.Media.Id));
  453. query.Select(nameof(Entity.tede2.Media.Media.ImageUrls));
  454. query.Select(nameof(Entity.tede2.Media.Media.Title));
  455. query.Select(nameof(Entity.tede2.Media.Media.Summary));
  456. query.Select(nameof(Entity.tede2.Media.Media.TeacherId));
  457. query.Select(nameof(Entity.tede2.Media.Media.AutoNumber));
  458. query.Select(nameof(Entity.tede2.Media.Media.Author));
  459. query.Select(nameof(Entity.tede2.Media.Media.MediaType));
  460. query.Select(nameof(Entity.tede2.Media.Media.Summary));
  461. query.Select(nameof(Entity.tede2.Media.Media.CommentScore));
  462. //1 热搜 2热书榜 3 课程榜 4Top 100 新书 5文献头条 6试听榜 7大众热评 8Top 100 专著
  463. if (request.DataTypeValue > 0)
  464. {
  465. //1 热搜
  466. if (request.DataTypeValue == RankingListConst.HotSearch.GetHashCode())
  467. query.OrderByDesc(nameof(Entity.tede2.Media.Media.ReadCount));
  468. //2热书榜
  469. if (request.DataTypeValue == RankingListConst.ReadBook.GetHashCode())
  470. {
  471. query.Where(nameof(Entity.tede2.Media.Media.MediaType), ResourceTypeConst.Book.GetHashCode());
  472. query.OrderByDesc(nameof(Entity.tede2.Media.Media.ReadCount));
  473. }
  474. //3 课程榜
  475. if (request.DataTypeValue == RankingListConst.Article.GetHashCode())
  476. {
  477. query.Where(nameof(Entity.tede2.Media.Media.MediaType), ResourceTypeConst.Article.GetHashCode());
  478. query.OrderByDesc(nameof(Entity.tede2.Media.Media.ReadCount));
  479. }
  480. //Top 100 新书
  481. if (request.DataTypeValue == RankingListConst.NewBook.GetHashCode())
  482. {
  483. query.Where(nameof(Entity.tede2.Media.Media.MediaType), ResourceTypeConst.Book.GetHashCode());
  484. query.OrderByDesc(nameof(Entity.tede2.Media.Media.CreatedDate));
  485. }
  486. //文献头条
  487. if (request.DataTypeValue == RankingListConst.ArticleTop.GetHashCode())
  488. {
  489. query.Where(nameof(Entity.tede2.Media.Media.MediaType), ResourceTypeConst.Article.GetHashCode());
  490. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
  491. }
  492. if (request.DataTypeValue == RankingListConst.Audio.GetHashCode())
  493. {
  494. query.Where(nameof(Entity.tede2.Media.Media.MediaType), ResourceTypeConst.Audio.GetHashCode());
  495. query.OrderByDesc(nameof(Entity.tede2.Media.Media.ReadCount));
  496. }
  497. if (request.DataTypeValue == RankingListConst.HotComment.GetHashCode())
  498. query.OrderByDesc(nameof(Entity.tede2.Media.Media.CommentScore));
  499. if (request.DataTypeValue == RankingListConst.CollectionBook.GetHashCode())
  500. query.OrderByDesc(nameof(Entity.tede2.Media.Media.CollectCount));
  501. }
  502. query.Where(nameof(Entity.tede2.Media.Media.IsChecked), true);
  503. query.Where(nameof(Entity.tede2.Media.Media.IsDelete), false);
  504. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
  505. query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsRecommend));
  506. query.ForPage(request.Page, request.PerPage);
  507. return await _repository.GetAllAsync<RankingListResult>(query);
  508. }
  509. }
  510. }