MediaRepository.cs 28 KB

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