AppHomePageService.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. using GxPress.Service.Interface.AppHomePage;
  2. using GxPress.Repository.Interface;
  3. using GxPress.Repository.Interface.Media;
  4. using GxPress.Request.ArticleGroup;
  5. using System.Threading.Tasks;
  6. using System.Collections.Generic;
  7. using GxPress.Result.SystemLabel;
  8. using GxPress.Result.Media;
  9. using GxPress.Repository.Interface.SystemLabel;
  10. using GxPress.Repository.Interface.Navigation;
  11. using GxPress.Result.MiddleLable;
  12. using AutoMapper;
  13. using System.Linq;
  14. using GxPress.Common.Tools;
  15. using GxPress.Common.Page;
  16. using GxPress.Request.Media;
  17. namespace GxPress.Service.Implement.AppHomePage
  18. {
  19. public class AppHomePageService : IAppHomePageService
  20. {
  21. private readonly IArticleGroupRepository articleGroupRepository;
  22. private readonly IMediaRepository mediaRepository;
  23. private readonly IMapper _mapper;
  24. private readonly IMiddleLableRepository _middleLableRepository;
  25. private readonly ISystemLabelRepository _systemLabelRepository;
  26. private readonly IMediaLableRepository _mediaLableRepository;
  27. private readonly IMiddleLableNexusRepository middleLableNexusRepository;
  28. public AppHomePageService(IArticleGroupRepository articleGroupRepository, IMediaRepository mediaRepository, IMiddleLableRepository _middleLableRepository, ISystemLabelRepository _systemLabelRepository, IMiddleLableNexusRepository middleLableNexusRepository, IMediaLableRepository _mediaLableRepository, IMapper _mapper)
  29. {
  30. this.articleGroupRepository = articleGroupRepository;
  31. this.mediaRepository = mediaRepository;
  32. this._middleLableRepository = _middleLableRepository;
  33. this._systemLabelRepository = _systemLabelRepository;
  34. this.middleLableNexusRepository = middleLableNexusRepository;
  35. this._mediaLableRepository = _mediaLableRepository;
  36. this._mapper = _mapper;
  37. }
  38. /// <summary>
  39. /// 大咖讲座
  40. /// </summary>
  41. /// <param name="request"></param>
  42. /// <returns></returns>
  43. public async Task<List<AppLabelResult<MediaCathedraResult>>> GetMediasByTeacherAsync(ArticleGroupRequest request)
  44. {
  45. var results = new List<AppLabelResult<MediaCathedraResult>>();
  46. //大师讲座
  47. if (request.StyleCss == "Cathedra")
  48. {
  49. request.Sort = "recommend";
  50. var items = await mediaRepository.GetMediasByTeacherAsync(request);
  51. results.Add(new AppLabelResult<MediaCathedraResult>() { LabelName = "今日推荐", IsPage = false, ResourceType = 40, Method = "", Items = items });
  52. request.Sort = "";
  53. items = await mediaRepository.GetMediasByTeacherAsync(request);
  54. results.Add(new AppLabelResult<MediaCathedraResult>() { LabelName = "更多精彩", IsPage = true, ResourceType = 40, Method = "post", Items = items, ActionUrl = "api/app/page/cathedra-page" });
  55. foreach (var item in results)
  56. {
  57. foreach (var model in item.Items)
  58. model.Duration = "02:19:20";
  59. }
  60. }
  61. //会员特供
  62. if (request.StyleCss == "VipSupply")
  63. {
  64. return await GetVipSupplyAsync(request);
  65. }
  66. //每日好书
  67. if (request.StyleCss == "DayGoodBook")
  68. {
  69. return await GetDayGoodBookAsync(request);
  70. }
  71. return results;
  72. }
  73. /// <summary>
  74. /// 每日好书
  75. /// </summary>
  76. /// <param name="request"></param>
  77. /// <returns></returns>
  78. public async Task<List<AppLabelResult<MediaCathedraResult>>> GetDayGoodBookAsync(ArticleGroupRequest request)
  79. {
  80. request.ActionUrl = "api/app/page/lable";
  81. return await GetVipSupplyAsync(request);
  82. }
  83. /// <summary>
  84. /// 每日好文
  85. /// </summary>
  86. /// <param name="request"></param>
  87. /// <returns></returns>
  88. public async Task<PagedList<MediaCathedraResult>> GetDayGoodTextAsync(MediaSearchRequest request)
  89. {
  90. var result = new PagedList<MediaCathedraResult>();
  91. var model = await mediaRepository.GetAllAsync(request);
  92. var list = new List<MediaCathedraResult>();
  93. foreach (var item in model.Items)
  94. {
  95. var mediaCathedraResult = new MediaCathedraResult();
  96. mediaCathedraResult.Author = item.Author;
  97. mediaCathedraResult.CollectCount = item.CollectCount;
  98. mediaCathedraResult.CreatedDate = item.CreatedDate;
  99. mediaCathedraResult.Id = item.Id;
  100. mediaCathedraResult.ImageUrls = item.ImageUrls;
  101. mediaCathedraResult.MediaType = item.MediaType;
  102. mediaCathedraResult.ReadCount = item.ReadCount;
  103. mediaCathedraResult.Title = item.Title;
  104. list.Add(mediaCathedraResult);
  105. }
  106. result.Total = model.Total;
  107. result.Items = list;
  108. return result;
  109. }
  110. /// <summary>
  111. /// 会员特供
  112. /// </summary>
  113. /// <param name="request"></param>
  114. /// <returns></returns>
  115. public async Task<List<AppLabelResult<MediaCathedraResult>>> GetVipSupplyAsync(ArticleGroupRequest request)
  116. {
  117. var result = new List<AppLabelResult<MediaCathedraResult>>();
  118. //根据样式查找导航数据
  119. var articleGroup = await articleGroupRepository.GetArticleGroupAsync(request.StyleCss);
  120. if (articleGroup.IsMiddleLable)
  121. {
  122. //获取中间页面
  123. var middleLable = await _middleLableRepository.GetAsync(articleGroup.MiddleLableId);
  124. //获取中间页标签
  125. var middleLableNexusIds = await middleLableNexusRepository.GetAllTaskAsync(middleLable.Id);
  126. //获取标签
  127. var systemLabels = await _systemLabelRepository.GetAllAsync(middleLableNexusIds.Select(n => n.LableId).ToList());
  128. foreach (var item in systemLabels)
  129. {
  130. //获取媒体标签
  131. var mediaIds = await _mediaLableRepository.GetMediaIdsAysnc(item.Id);
  132. var medias = await mediaRepository.GetNavigationMediaResults(mediaIds, item.PageSize);
  133. var list = new List<MediaCathedraResult>();
  134. foreach (var mediaModel in medias)
  135. {
  136. list.Add(new MediaCathedraResult { Id = mediaModel.Id, Title = mediaModel.Title, ImageUrls = StringUtils.AddDomain(mediaModel.ImageUrls), Author = mediaModel.Author, ReadCount = mediaModel.ReadCount, CreatedDate = mediaModel.CreatedDate, CollectCount = mediaModel.CollectCount, MediaType = mediaModel.MediaType });
  137. }
  138. //获取常规数据
  139. var mediaCathedraResult = new AppLabelResult<MediaCathedraResult>()
  140. {
  141. IsPage = item.IsPage,
  142. Id = item.Id,
  143. LabelName = item.LabelName,
  144. ResourceType = 40,
  145. Items = list,
  146. Method = item.IsPage ? "post" : "",
  147. ActionUrl = item.IsPage ? request.ActionUrl : ""
  148. };
  149. result.Add(mediaCathedraResult);
  150. }
  151. }
  152. return result;
  153. }
  154. /// <summary>
  155. /// 大咖讲座
  156. /// </summary>
  157. /// <returns></returns>
  158. public async Task<PagedList<MediaCathedraResult>> MediaCathedraResult(ArticleGroupRequest request)
  159. {
  160. var result = new PagedList<MediaCathedraResult>();
  161. result.Items = await mediaRepository.GetMediasByTeacherAsync(request);
  162. foreach (var item in result.Items)
  163. {
  164. item.ImageUrls = Common.Tools.StringUtils.AddDomain(item.ImageUrls);
  165. }
  166. result.Total = await mediaRepository.GetMediasByTeacherCountAsync(request);
  167. return result;
  168. }
  169. /// <summary>
  170. /// 根据IDs
  171. /// </summary>
  172. /// <returns></returns>
  173. public async Task<PagedList<MediaCathedraResult>> GetMediaByLableIdsAsync(MediaIdsRequest request)
  174. {
  175. var ids = await _mediaLableRepository.GetMediaIdsAysnc(request.LableId);
  176. request.Ids = ids.ToList();
  177. return await mediaRepository.GetMediaByLableIdsAsync(request);
  178. }
  179. }
  180. }