MediaService.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. using GxPress.Service.Interface.Media;
  2. using GxPress.Repository.Interface.Category;
  3. using GxPress.Repository.Interface.Media;
  4. using System.Threading.Tasks;
  5. using GxPress.Result.Media;
  6. using AutoMapper;
  7. using System.Linq;
  8. using GxPress.Result.Category;
  9. using GxPress.Service.Interface.Epub;
  10. using GxPress.Request.Media;
  11. using System;
  12. using GxPress.Repository.Interface;
  13. using GxPress.Repository.Interface.Order;
  14. using GxPress.Repository.Interface.Attach;
  15. using GxPress.Repository.Interface.SystemLabel;
  16. using GxPress.Repository.Interface.Analyze;
  17. using Datory;
  18. using GxPress.Common.Tools;
  19. using GxPress.Service.Interface.Analyze;
  20. using GxPress.EnumConst;
  21. using System.IO;
  22. using GxPress.Request.Analyze;
  23. using GxPress.Service.Interface.VisitHistory;
  24. using GxPress.Common.Page;
  25. using System.Collections.Generic;
  26. using GxPress.Repository.Interface.Press;
  27. using GxPress.Repository.Interface.Teacher;
  28. using GxPress.Request.TeacherRequest;
  29. namespace GxPress.Service.Implement.Media
  30. {
  31. public partial class MediaService : IMediaService
  32. {
  33. private readonly ICategoryRepository categoryRepository;
  34. private readonly IMediaRepository mediaRepository;
  35. private readonly IMapper _mapper;
  36. private readonly IEpubService epubService;
  37. private readonly IMediaLibraryRepository mediaLibraryRepository;
  38. private readonly IUserRepository userRepository;
  39. private readonly IOrderRepository orderRepository;
  40. private readonly IAttachRepository attachRepository;
  41. private readonly ISystemLabelRepository systemLabelRepository;
  42. private readonly ISystemLableMediaRepository systemLableMediaRepository;
  43. private readonly IAnalyzeRepository analyzeRepository;
  44. private readonly IAnalyzeService _analyzeService;
  45. private readonly ICommentRepository _commentRepository;
  46. private readonly IVisitHistoryService visitHistoryService;
  47. private readonly IArticleRepository articleRepository;
  48. private readonly IPressRepository pressRepository;
  49. private readonly ITeacherRepository teacherRepository;
  50. public MediaService(ICategoryRepository categoryRepository,
  51. IMediaRepository mediaRepository, IMapper _mapper,
  52. IEpubService epubService, IMediaLibraryRepository mediaLibraryRepository,
  53. IUserRepository userRepository, IOrderRepository orderRepository,
  54. IAttachRepository attachRepository, ISystemLabelRepository systemLabelRepository,
  55. ISystemLableMediaRepository systemLableMediaRepository,
  56. IAnalyzeRepository analyzeRepository, IAnalyzeService _analyzeService,
  57. ICommentRepository _commentRepository, IVisitHistoryService visitHistoryService,
  58. IArticleRepository articleRepository, IPressRepository pressRepository,
  59. ITeacherRepository teacherRepository)
  60. {
  61. this.categoryRepository = categoryRepository;
  62. this.mediaRepository = mediaRepository;
  63. this._mapper = _mapper;
  64. this.epubService = epubService;
  65. this.mediaLibraryRepository = mediaLibraryRepository;
  66. this.userRepository = userRepository;
  67. this.orderRepository = orderRepository;
  68. this.attachRepository = attachRepository;
  69. this.systemLabelRepository = systemLabelRepository;
  70. this.systemLableMediaRepository = systemLableMediaRepository;
  71. this.analyzeRepository = analyzeRepository;
  72. this._analyzeService = _analyzeService;
  73. this._commentRepository = _commentRepository;
  74. this.visitHistoryService = visitHistoryService;
  75. this.articleRepository = articleRepository;
  76. this.pressRepository = pressRepository;
  77. this.teacherRepository = teacherRepository;
  78. }
  79. public async Task<bool> InsertAsync(MediaResult result)
  80. {
  81. // if (result.CategoryId > 0)
  82. // {
  83. // result.CategoryName = await categoryRepository.GetCategoryParentAsync(result.CategoryId, result.CategoryName);
  84. // }
  85. return await mediaRepository.InsertAsync(result);
  86. }
  87. public async Task<MediaResult> GetAsync(int id, int userId)
  88. {
  89. var result = new MediaResult();
  90. //获取媒体
  91. result = await mediaRepository.GetAsync(id);
  92. //获取类别
  93. var categoryAll = await categoryRepository.GetAllAsync(0);
  94. result.CategoryResults = categoryAll.Where(n => n.ParentId == 0).Select(n => _mapper.Map<CategoryResult>(n)).ToList();
  95. foreach (var item in result.CategoryResults)
  96. {
  97. item.IsChildren = categoryAll.Any(n => n.ParentId == item.Id);
  98. item.Children = categoryAll.Where(n => n.ParentId == item.Id).Select(n => _mapper.Map<CategoryResult>(n)).ToList();
  99. if (item.IsChildren)
  100. {
  101. foreach (var chidren in item.Children)
  102. {
  103. chidren.IsChildren = categoryAll.Any(n => n.ParentId == chidren.Id);
  104. chidren.Children = categoryAll.Where(n => n.ParentId == chidren.Id).Select(n => _mapper.Map<CategoryResult>(n)).ToList();
  105. }
  106. }
  107. }
  108. if (userId > 0)
  109. //获取用户历史记录
  110. await visitHistoryService.InsertAsync(userId, id, result.MediaType);
  111. var analyzeRequest = new Request.App.Analyze.AnalyzeRequest()
  112. {
  113. TypeValue = result.MediaType,
  114. AnalyzeType = 1,
  115. SourceId = id,
  116. UserId = userId
  117. };
  118. //点赞数量
  119. result.PraiseCount = await _analyzeService.CountAsync(analyzeRequest);
  120. //是否点赞
  121. result.IsPraise = await _analyzeService.ExistsAsync(analyzeRequest);
  122. //获取话题的评论数量
  123. var commentCount =
  124. await _commentRepository.CountAsync(Q.Where(nameof(Entity.Comment.ArticleId), id).Where(nameof(Entity.Comment.TypeValue), analyzeRequest.TypeValue).Where(nameof(Entity.Comment.Pid), 0));
  125. result.CommentCount = commentCount;
  126. //获取话题的转发数量
  127. analyzeRequest.AnalyzeType = 4;
  128. var retransmissionCount = await _analyzeService.CountAsync(analyzeRequest);
  129. result.RetransmissionCount = retransmissionCount;
  130. result.IsRetransmission = await _analyzeService.ExistsAsync(analyzeRequest);
  131. //获取话题的收藏数量
  132. analyzeRequest.AnalyzeType = 3;
  133. var collectCount = await _analyzeService.CountAsync(analyzeRequest);
  134. result.CollectCount = collectCount;
  135. //是否收藏
  136. result.IsCollect = await _analyzeService.ExistsAsync(analyzeRequest);
  137. //是否购买
  138. if (userId > 0 && result.FreeProportion == 0)
  139. result.IsBuy = true;
  140. else if (userId > 0)
  141. result.IsBuy = await orderRepository.GetExistsAsync(userId, id);
  142. //点赞数据
  143. var praisePageSearchRequest = new PraisePageSearchRequest { SourceId = id, TypeValue = analyzeRequest.TypeValue, Page = 1, PerPage = 3 };
  144. result.PraisePagedList = await _analyzeService.GetPraisePageAsync(praisePageSearchRequest);
  145. result.CommentScore = await _commentRepository.GetCommentScoreAsync(id, result.MediaType);
  146. return result;
  147. }
  148. /// <summary>
  149. /// 获取书籍详情
  150. /// </summary>
  151. /// <param name="id"></param>
  152. /// <param name="userId"></param>
  153. /// <returns></returns>
  154. public async Task<BookMediaResult> GetBookMediaResultAsync(int id, int userId)
  155. {
  156. var result = await mediaRepository.GetBookMediaResultAsync(id);
  157. if (result == null)
  158. throw new Common.Exceptions.BusinessException("不存在");
  159. if (result.MediaType != GxPress.EnumConst.ResourceTypeConst.Book.GetHashCode())
  160. throw new Common.Exceptions.BusinessException("非书籍");
  161. //获取用户历史记录
  162. await visitHistoryService.InsertAsync(userId, id, AllTypeConst.Book.GetHashCode());
  163. //获取书籍文件
  164. var mediaLibrary = await mediaLibraryRepository.GetTaskAsync(id);
  165. if (!mediaLibrary.FileUrl.Contains("epub"))
  166. throw new Common.Exceptions.BusinessException("书籍不存在epub文件");
  167. //书籍
  168. //获取media
  169. var media = await mediaRepository.GetAsync(id);
  170. if (userId > 0)
  171. {
  172. var user = await userRepository.GetAsync(userId);
  173. if (user.IsVip && user.EndTime > DateTime.Now)
  174. media.FreeProportion = 0;
  175. else
  176. {
  177. if (await orderRepository.GetExistsAsync(userId, id))
  178. media.FreeProportion = 0;
  179. }
  180. }
  181. var sectionValue = 0;
  182. result.BookCatalogResults = epubService.GetCatalog((Directory.GetCurrentDirectory() + "\\wwwroot" + StringUtils.RemoveDomain(mediaLibrary.FileUrl).Replace("/", "\\")));
  183. if (media.FreeProportion > 0)
  184. {
  185. var freeProportion = media.FreeProportion / 100;
  186. sectionValue = Convert.ToInt32(result.BookCatalogResults.Count * freeProportion);
  187. foreach (var item in result.BookCatalogResults)
  188. {
  189. if (item.Id <= sectionValue)
  190. item.IsRead = true;
  191. if (item.IsChildren)
  192. {
  193. foreach (var bookCatalogResult in item.Children)
  194. {
  195. if (bookCatalogResult.Id <= sectionValue)
  196. bookCatalogResult.IsRead = true;
  197. }
  198. }
  199. }
  200. }
  201. else
  202. {
  203. foreach (var item in result.BookCatalogResults)
  204. {
  205. item.IsRead = true;
  206. foreach (var bookCatalogResult in item.Children)
  207. bookCatalogResult.IsRead = true;
  208. }
  209. }
  210. //计算免费占比
  211. result.ImageUrls = StringUtils.AddDomain(result.ImageUrls);
  212. var analyzeRequest = new Request.App.Analyze.AnalyzeRequest()
  213. {
  214. TypeValue = result.MediaType,
  215. AnalyzeType = 1,
  216. SourceId = id,
  217. UserId = userId
  218. };
  219. //获取老师
  220. if (result.TeacherId > 0)
  221. {
  222. var teacher = await teacherRepository.GetAsync(result.TeacherId);
  223. result.Job = teacher != null ? teacher.Job : string.Empty;
  224. }
  225. //点赞数量
  226. result.PraiseCount = await _analyzeService.CountAsync(analyzeRequest);
  227. //是否点赞
  228. result.IsPraise = await _analyzeService.ExistsAsync(analyzeRequest);
  229. //获取话题的评论数量
  230. var commentCount =
  231. await _commentRepository.CountAsync(Q.Where(nameof(Entity.Comment.ArticleId), id).Where(nameof(Entity.Comment.TypeValue), analyzeRequest.TypeValue).Where(nameof(Entity.Comment.Pid), 0));
  232. result.CommentCount = commentCount;
  233. //获取话题的转发数量
  234. analyzeRequest.AnalyzeType = 4;
  235. var retransmissionCount = await _analyzeService.CountAsync(analyzeRequest);
  236. result.RetransmissionCount = retransmissionCount;
  237. result.IsRetransmission = await _analyzeService.ExistsAsync(analyzeRequest);
  238. //获取话题的收藏数量
  239. analyzeRequest.AnalyzeType = 3;
  240. var collectCount = await _analyzeService.CountAsync(analyzeRequest);
  241. result.CollectCount = collectCount;
  242. //是否收藏
  243. result.IsCollect = await _analyzeService.ExistsAsync(analyzeRequest);
  244. //是否购买
  245. if (userId > 0 && result.FreeProportion == 0)
  246. result.IsBuy = true;
  247. else if (userId > 0)
  248. result.IsBuy = await orderRepository.GetExistsAsync(userId, id);
  249. //点赞数据
  250. var praisePageSearchRequest = new PraisePageSearchRequest { SourceId = id, TypeValue = analyzeRequest.TypeValue, Page = 1, PerPage = 3 };
  251. result.PraisePagedList = await _analyzeService.GetPraisePageAsync(praisePageSearchRequest);
  252. //获取评分
  253. result.CommentScore = await _commentRepository.GetCommentScoreAsync(id, result.MediaType);
  254. return result;
  255. }
  256. /// <summary>
  257. /// 获取视频详情
  258. /// </summary>
  259. /// <param name="id"></param>
  260. /// <returns></returns>
  261. public async Task<VideoMediaResult> GetVideoMediaResultAsync(int id, int userId)
  262. {
  263. var result = await mediaRepository.GetVideoMediaResultAsync(id);
  264. if (result == null)
  265. throw new Common.Exceptions.BusinessException("不存在");
  266. if (result.MediaType != GxPress.EnumConst.ResourceTypeConst.Video.GetHashCode())
  267. throw new Common.Exceptions.BusinessException("非视频");
  268. //获取用户历史记录
  269. await visitHistoryService.InsertAsync(userId, id, AllTypeConst.Video.GetHashCode());
  270. //获取视频
  271. result.MediaLibraryResults = await mediaLibraryRepository.GetAllAsync(id);
  272. var analyzeRequest = new Request.App.Analyze.AnalyzeRequest();
  273. analyzeRequest.TypeValue = result.MediaType;
  274. analyzeRequest.AnalyzeType = 1;
  275. analyzeRequest.SourceId = id;
  276. analyzeRequest.UserId = userId;
  277. //点赞数量
  278. result.PraiseCount = await _analyzeService.CountAsync(analyzeRequest);
  279. //是否点赞
  280. result.IsPraise = await _analyzeService.ExistsAsync(analyzeRequest);
  281. //获取话题的评论数量
  282. var commentCount =
  283. await _commentRepository.CountAsync(Q.Where(nameof(Entity.Comment.ArticleId), id).Where(nameof(Entity.Comment.TypeValue), analyzeRequest.TypeValue).Where(nameof(Entity.Comment.Pid), 0));
  284. result.CommentCount = commentCount;
  285. //获取话题的转发数量
  286. analyzeRequest.AnalyzeType = 4;
  287. var retransmissionCount = await _analyzeService.CountAsync(analyzeRequest);
  288. result.RetransmissionCount = retransmissionCount;
  289. result.IsRetransmission = await _analyzeService.ExistsAsync(analyzeRequest);
  290. //获取话题的收藏数量
  291. analyzeRequest.AnalyzeType = 3;
  292. var collectCount = await _analyzeService.CountAsync(analyzeRequest);
  293. result.CollectCount = collectCount;
  294. //是否收藏
  295. result.IsCollect = await _analyzeService.ExistsAsync(analyzeRequest); //点赞数据
  296. var praisePageSearchRequest = new PraisePageSearchRequest { SourceId = id, TypeValue = analyzeRequest.TypeValue, Page = 1, PerPage = 3 };
  297. result.PraisePagedList = await _analyzeService.GetPraisePageAsync(praisePageSearchRequest);
  298. result.CommentScore = await _commentRepository.GetCommentScoreAsync(id, result.MediaType);
  299. return result;
  300. }
  301. /// <summary>
  302. /// 获取音频
  303. /// </summary>
  304. /// <param name="id"></param>
  305. /// <returns></returns>
  306. public async Task<AudioMediaResult> GetAudioMediaResultAsync(int id, int userId)
  307. {
  308. var result = await mediaRepository.GetAudioMediaResultAsync(id);
  309. if (result == null)
  310. throw new Common.Exceptions.BusinessException("不存在");
  311. if (result.MediaType != GxPress.EnumConst.ResourceTypeConst.Audio.GetHashCode())
  312. throw new Common.Exceptions.BusinessException("非音频");
  313. //获取用户历史记录
  314. await visitHistoryService.InsertAsync(userId, id, AllTypeConst.Audio.GetHashCode());
  315. //获取音频地址
  316. result.MediaLibraryResults = await mediaLibraryRepository.GetAudioTaskAsync(id);
  317. var query = Q.NewQuery();
  318. query.Where(nameof(Entity.Analyze.Analyze.TypeValue), GxPress.EnumConst.AllTypeConst.Book.GetHashCode());
  319. query.Where(nameof(Entity.Analyze.Analyze.AnalyzeType), 3);
  320. query.Where(nameof(Entity.Analyze.Analyze.SourceId), id);
  321. query.Where(nameof(Entity.Analyze.Analyze.UserId), userId);
  322. var analyzeRequest = new Request.App.Analyze.AnalyzeRequest();
  323. analyzeRequest.TypeValue = result.MediaType;
  324. analyzeRequest.AnalyzeType = 1;
  325. analyzeRequest.SourceId = id;
  326. analyzeRequest.UserId = userId;
  327. //点赞数量
  328. result.PraiseCount = await _analyzeService.CountAsync(analyzeRequest);
  329. //是否点赞
  330. result.IsPraise = await _analyzeService.ExistsAsync(analyzeRequest);
  331. //获取话题的评论数量
  332. var commentCount =
  333. await _commentRepository.CountAsync(Q.Where(nameof(Entity.Comment.ArticleId), id).Where(nameof(Entity.Comment.TypeValue), analyzeRequest.TypeValue).Where(nameof(Entity.Comment.Pid), 0));
  334. result.CommentCount = commentCount;
  335. //获取话题的转发数量
  336. analyzeRequest.AnalyzeType = 4;
  337. var retransmissionCount = await _analyzeService.CountAsync(analyzeRequest);
  338. result.RetransmissionCount = retransmissionCount;
  339. result.IsRetransmission = await _analyzeService.ExistsAsync(analyzeRequest);
  340. //获取话题的收藏数量
  341. analyzeRequest.AnalyzeType = 3;
  342. var collectCount = await _analyzeService.CountAsync(analyzeRequest);
  343. result.CollectCount = collectCount;
  344. //是否收藏
  345. result.IsCollect = await _analyzeService.ExistsAsync(analyzeRequest);
  346. //是否购买
  347. if (userId > 0 && result.FreeProportion == 0)
  348. result.IsBuy = true;
  349. else if (userId > 0)
  350. result.IsBuy = await orderRepository.GetExistsAsync(userId, id);
  351. //点赞数据
  352. var praisePageSearchRequest = new PraisePageSearchRequest { SourceId = id, TypeValue = analyzeRequest.TypeValue, Page = 1, PerPage = 3 };
  353. result.PraisePagedList = await _analyzeService.GetPraisePageAsync(praisePageSearchRequest);
  354. result.CommentScore = await _commentRepository.GetCommentScoreAsync(id, result.MediaType);
  355. return result;
  356. }
  357. /// <summary>
  358. /// 获取章节内容
  359. /// </summary>
  360. /// <param name="request"></param>
  361. /// <returns></returns>
  362. public async Task<string> GetBookMediaContentResultAsync(BookCatalogRequest request)
  363. {
  364. if (request.MediaId == 0)
  365. throw new Common.Exceptions.BusinessException("请检查参数");
  366. if (string.IsNullOrEmpty(request.CatalogNameg))
  367. throw new Common.Exceptions.BusinessException("请检查参数");
  368. if (string.IsNullOrEmpty(request.CatalogId))
  369. throw new Common.Exceptions.BusinessException("请检查参数");
  370. //获取书籍文件
  371. var mediaLibrary = await mediaLibraryRepository.GetTaskAsync(request.MediaId);
  372. if (!mediaLibrary.FileUrl.Contains("epub"))
  373. throw new Common.Exceptions.BusinessException("书籍不存在epub文件");
  374. request.Path = "wwwroot" + StringUtils.RemoveDomain(mediaLibrary.FileUrl);
  375. return await epubService.GetBookCatalogContent(request);
  376. }
  377. /// <summary>
  378. /// 根据labeId获取媒体
  379. /// </summary>
  380. /// <param name="mediaIds"></param>
  381. /// <returns></returns>
  382. public async Task<PagedList<MediaSearchResult>> GetMediaByLableIdAysnc(MediaLableIdRequest request)
  383. {
  384. var result = new PagedList<MediaSearchResult>();
  385. var systemLabel = await systemLabelRepository.GetAsync(request.LableId);
  386. if (systemLabel.ResourceType > 0)
  387. {
  388. if (systemLabel.ResourceType == AllTypeConst.Teacher.GetHashCode())
  389. {
  390. var teacherResults = await teacherRepository.GetTeacherResult(new TeacherRequest { KeyWord = request.KeyWord, Page = request.Page, PerPage = request.PerPage, UserId = request.UserId });
  391. var mediaSearchResults = new List<MediaSearchResult>();
  392. foreach (var teacher in teacherResults.Items)
  393. {
  394. mediaSearchResults.Add(new MediaSearchResult
  395. {
  396. Id = teacher.Id,
  397. Title = teacher.Name,
  398. ImageUrls = !string.IsNullOrEmpty(teacher.ImageUrl) ? StringUtils.AddDomain(teacher.ImageUrl) : "",
  399. Summary = teacher.Summary,
  400. Author = teacher.Name,
  401. CollectCount = teacher.CollectCount,
  402. MediaType = AllTypeConst.Teacher.GetHashCode()
  403. });
  404. }
  405. result.Items = mediaSearchResults;
  406. result.Total = teacherResults.Total;
  407. return result;
  408. }
  409. if (systemLabel.ResourceType == AllTypeConst.Article.GetHashCode())
  410. {
  411. var articleResult = await articleRepository.GetArticleResults(new PageParameter { Page = request.Page, PerPage = request.PerPage, KeyWord = request.KeyWord });
  412. var mediaSearchResults = new List<MediaSearchResult>();
  413. foreach (var article in articleResult.Items)
  414. {
  415. var jsonContent = article.ArticleContent;
  416. var textContent = string.Empty;
  417. //新版json
  418. if (jsonContent != null && jsonContent.type.Count() > 0)
  419. {
  420. foreach (var content in jsonContent.content)
  421. {
  422. foreach (var contentItem in content.content)
  423. {
  424. if (contentItem.type == "text")
  425. textContent += contentItem.text;
  426. }
  427. }
  428. }
  429. var imageUrl = article.ImageUrls != null ? article.ImageUrls.FirstOrDefault() : "";
  430. mediaSearchResults.Add(new MediaSearchResult
  431. {
  432. Id = article.Id,
  433. Title = article.Title,
  434. ImageUrls = !string.IsNullOrEmpty(imageUrl) ? StringUtils.AddDomain(imageUrl) : "",
  435. Summary = textContent,
  436. Author = article.Author,
  437. //Source = article.Source,
  438. CreatedDate = article.AddDate,
  439. //CollectCount = article.CollectCount,
  440. ReadCount = article.ReadCount,
  441. MediaType = AllTypeConst.Article.GetHashCode()
  442. });
  443. }
  444. result.Items = mediaSearchResults;
  445. result.Total = articleResult.Total;
  446. return result;
  447. }
  448. if (systemLabel.ResourceType == AllTypeConst.Press.GetHashCode())
  449. {
  450. var pressResults = await pressRepository.GetAllListAsync(new PageParameter { Page = request.Page, PerPage = request.PerPage, KeyWord = request.KeyWord });
  451. var mediaSearchResults = new List<MediaSearchResult>();
  452. foreach (var press in pressResults.Items)
  453. {
  454. mediaSearchResults.Add(new MediaSearchResult
  455. {
  456. Id = press.Id,
  457. Title = press.Name,
  458. Summary = press.Summary,
  459. ImageUrls = press.ImageUrl,
  460. MediaType = AllTypeConst.Press.GetHashCode()
  461. });
  462. }
  463. result.Items = mediaSearchResults;
  464. result.Total = pressResults.Total;
  465. return result;
  466. }
  467. }
  468. return await mediaRepository.GetMediaByLableIdAysnc(request);
  469. }
  470. /// <summary>
  471. /// 排行榜
  472. /// </summary>
  473. /// <param name="request"></param>
  474. /// <returns></returns>
  475. public async Task<AppRankingResult> GetRankingListResults()
  476. {
  477. var query = Q.NewQuery();
  478. query.Where(nameof(Entity.SystemLabel.SystemLabel.LableType), 2);
  479. query.Where(nameof(Entity.SystemLabel.SystemLabel.IsDisable), false);
  480. query.OrderByDesc(nameof(Entity.SystemLabel.SystemLabel.Sort));
  481. var systemLabels = await systemLabelRepository.GetAllAsync(query);
  482. var result = new AppRankingResult();
  483. result.Labels = systemLabels.Where(n => !n.IsRecommend);
  484. result.Items = new List<MediaRankingResult>();
  485. foreach (var item in systemLabels.Where(n => n.IsRecommend))
  486. {
  487. var data = await mediaRepository.SearchLableKeyWordAsync(new LableIdMediaRequest { LableId = item.Id, KeyWord = string.Empty, Page = 1, PerPage = item.PageSize });
  488. result.Items.Add(new MediaRankingResult
  489. {
  490. Id = item.Id,
  491. MediaType = item.ResourceType,
  492. Name = item.LabelName,
  493. Items = data.Items.ToList()
  494. });
  495. }
  496. return result;
  497. }
  498. /// <summary>
  499. /// 根据关键字搜索榜单
  500. /// </summary>
  501. /// <param name="keyWord"></param>
  502. /// <param name="lableId"></param>
  503. /// <returns></returns>
  504. public async Task<PagedList<MediaSearchResult>> SearchRankingAsync(Common.Page.PageParameter request)
  505. {
  506. return await mediaRepository.SearchRankingAsync(request);
  507. }
  508. }
  509. }