AppHomePageService.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 AutoMapper;
  12. using System.Linq;
  13. using GxPress.Common.Tools;
  14. using GxPress.Common.Page;
  15. using GxPress.Request.Media;
  16. using GxPress.Repository.Interface.Teacher;
  17. using GxPress.Request.TeacherRequest;
  18. using GxPress.Result.Teacher;
  19. namespace GxPress.Service.Implement.AppHomePage
  20. {
  21. public class AppHomePageService : IAppHomePageService
  22. {
  23. private readonly IArticleGroupRepository articleGroupRepository;
  24. private readonly IMediaRepository mediaRepository;
  25. private readonly IMapper _mapper;
  26. private readonly IMiddleLableRepository _middleLableRepository;
  27. private readonly ISystemLabelRepository _systemLabelRepository;
  28. private readonly IMediaLableRepository _mediaLableRepository;
  29. private readonly IMiddleLableNexusRepository middleLableNexusRepository;
  30. private readonly ITeacherRepository teacherRepository;
  31. public AppHomePageService(IArticleGroupRepository articleGroupRepository, IMediaRepository mediaRepository, IMiddleLableRepository _middleLableRepository, ISystemLabelRepository _systemLabelRepository, IMiddleLableNexusRepository middleLableNexusRepository, IMediaLableRepository _mediaLableRepository, IMapper _mapper, ITeacherRepository teacherRepository)
  32. {
  33. this.articleGroupRepository = articleGroupRepository;
  34. this.mediaRepository = mediaRepository;
  35. this._middleLableRepository = _middleLableRepository;
  36. this._systemLabelRepository = _systemLabelRepository;
  37. this.middleLableNexusRepository = middleLableNexusRepository;
  38. this._mediaLableRepository = _mediaLableRepository;
  39. this._mapper = _mapper;
  40. this.teacherRepository = teacherRepository;
  41. }
  42. /// <summary>
  43. /// 大咖讲座
  44. /// </summary>
  45. /// <param name="request"></param>
  46. /// <returns></returns>
  47. public async Task<List<AppLabelResult<MediaCathedraResult>>> GetMediasByTeacherAsync(ArticleGroupRequest request)
  48. {
  49. var results = new List<AppLabelResult<MediaCathedraResult>>();
  50. //大师讲座
  51. if (request.StyleCss == "Cathedra")
  52. {
  53. request.Sort = "recommend";
  54. var items = await mediaRepository.GetMediasByTeacherAsync(request);
  55. results.Add(new AppLabelResult<MediaCathedraResult>() { LabelName = "今日推荐", IsPage = false, ResourceType = 40, Method = "", Items = items });
  56. request.Sort = "";
  57. items = await mediaRepository.GetMediasByTeacherAsync(request);
  58. results.Add(new AppLabelResult<MediaCathedraResult>() { LabelName = "更多精彩", IsPage = true, ResourceType = 40, Method = "post", Items = items, ActionUrl = "api/app/page/cathedra-page" });
  59. foreach (var item in results)
  60. {
  61. foreach (var model in item.Items)
  62. {
  63. model.Duration = "02:19:20";
  64. model.ImageUrls = Common.Tools.StringUtils.AddDomain(model.ImageUrls);
  65. }
  66. }
  67. }
  68. //会员特供
  69. if (request.StyleCss == "VipSupply")
  70. {
  71. return await GetVipSupplyAsync(request);
  72. }
  73. //每日好书
  74. if (request.StyleCss == "DayGoodBook")
  75. {
  76. return await GetDayGoodBookAsync(request);
  77. }
  78. return results;
  79. }
  80. /// <summary>
  81. /// 每日好书
  82. /// </summary>
  83. /// <param name="request"></param>
  84. /// <returns></returns>
  85. public async Task<List<AppLabelResult<MediaCathedraResult>>> GetDayGoodBookAsync(ArticleGroupRequest request)
  86. {
  87. request.ActionUrl = "api/app/page/lable";
  88. return await GetVipSupplyAsync(request);
  89. }
  90. /// <summary>
  91. /// 每日好文
  92. /// </summary>
  93. /// <param name="request"></param>
  94. /// <returns></returns>
  95. public async Task<PagedList<MediaCathedraResult>> GetDayGoodTextAsync(MediaSearchRequest request)
  96. {
  97. var result = new PagedList<MediaCathedraResult>();
  98. var model = await mediaRepository.GetAllAsync(request);
  99. var list = new List<MediaCathedraResult>();
  100. foreach (var item in model.Items)
  101. {
  102. var mediaCathedraResult = new MediaCathedraResult();
  103. mediaCathedraResult.Author = item.Author;
  104. mediaCathedraResult.CollectCount = item.CollectCount;
  105. mediaCathedraResult.CreatedDate = item.CreatedDate;
  106. mediaCathedraResult.Id = item.Id;
  107. mediaCathedraResult.ImageUrls = item.ImageUrls;
  108. mediaCathedraResult.MediaType = item.MediaType;
  109. mediaCathedraResult.ReadCount = item.ReadCount;
  110. mediaCathedraResult.Title = item.Title;
  111. mediaCathedraResult.Summary = item.Summary;
  112. mediaCathedraResult.Press = item.Press;
  113. list.Add(mediaCathedraResult);
  114. }
  115. result.Total = model.Total;
  116. foreach (var item in list)
  117. {
  118. item.ImageUrls = StringUtils.AddDomain(item.ImageUrls);
  119. }
  120. result.Items = list;
  121. return result;
  122. }
  123. /// <summary>
  124. /// 会员特供
  125. /// </summary>
  126. /// <param name="request"></param>
  127. /// <returns></returns>
  128. public async Task<List<AppLabelResult<MediaCathedraResult>>> GetVipSupplyAsync(ArticleGroupRequest request)
  129. {
  130. var result = new List<AppLabelResult<MediaCathedraResult>>();
  131. //根据样式查找导航数据
  132. var articleGroup = await articleGroupRepository.GetArticleGroupAsync(request.StyleCss);
  133. if (articleGroup.IsMiddleLable)
  134. {
  135. //获取中间页面
  136. var middleLable = await _middleLableRepository.GetAsync(articleGroup.MiddleLableId);
  137. //获取中间页标签
  138. var middleLableNexusIds = await middleLableNexusRepository.GetAllTaskAsync(middleLable.Id);
  139. //获取标签
  140. var systemLabels = await _systemLabelRepository.GetAllAsync(middleLableNexusIds.Select(n => n.LableId).ToList());
  141. foreach (var item in systemLabels)
  142. {
  143. //获取媒体标签
  144. var mediaIds = await _mediaLableRepository.GetMediaIdsAysnc(item.Id);
  145. var medias = await mediaRepository.GetNavigationMediaResults(mediaIds, item.PageSize);
  146. var list = new List<MediaCathedraResult>();
  147. foreach (var mediaModel in medias)
  148. {
  149. 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 });
  150. }
  151. //获取常规数据
  152. var mediaCathedraResult = new AppLabelResult<MediaCathedraResult>()
  153. {
  154. IsPage = item.IsPage,
  155. Id = item.Id,
  156. LabelName = item.LabelName,
  157. ResourceType = 40,
  158. Items = list,
  159. Method = item.IsPage ? "post" : "",
  160. ActionUrl = item.IsPage ? request.ActionUrl : ""
  161. };
  162. result.Add(mediaCathedraResult);
  163. }
  164. }
  165. return result;
  166. }
  167. /// <summary>
  168. /// 大咖讲座
  169. /// </summary>
  170. /// <returns></returns>
  171. public async Task<PagedList<MediaCathedraResult>> MediaCathedraResult(ArticleGroupRequest request)
  172. {
  173. var result = new PagedList<MediaCathedraResult>();
  174. result.Items = await mediaRepository.GetMediasByTeacherAsync(request);
  175. foreach (var item in result.Items)
  176. {
  177. item.ImageUrls = Common.Tools.StringUtils.AddDomain(item.ImageUrls);
  178. }
  179. result.Total = await mediaRepository.GetMediasByTeacherCountAsync(request);
  180. return result;
  181. }
  182. /// <summary>
  183. /// 根据IDs
  184. /// </summary>
  185. /// <returns></returns>
  186. public async Task<IEnumerable<MediaCathedraResult>> GetMediaByLableIdsAsync(MediaIdsRequest request)
  187. {
  188. //获取标签
  189. var systemLabel = await _systemLabelRepository.GetAsync(request.LableId);
  190. if (systemLabel == null)
  191. return null;
  192. var ids = await _mediaLableRepository.GetMediaIdsAysnc(request.LableId);
  193. request.Ids = ids.ToList();
  194. request.Limit = systemLabel.PageSize;
  195. return await mediaRepository.GetMediaByLableIdsAsync(request);
  196. }
  197. /// <summary>
  198. /// 根据IDs
  199. /// </summary>
  200. /// <returns></returns>
  201. public async Task<PagedList<MediaCathedraResult>> GetMediaByLableIdAsync(MediaLableIdRequest request)
  202. {
  203. //获取标签
  204. var systemLabel = await _systemLabelRepository.GetAsync(request.LableId);
  205. if (systemLabel == null)
  206. return null;
  207. var ids = await _mediaLableRepository.GetMediaIdsAysnc(request.LableId);
  208. request.Ids = ids.ToList();
  209. return await mediaRepository.GetMediaByLableIdAsync(request);
  210. }
  211. /// <summary>
  212. /// 名师
  213. /// </summary>
  214. /// <param name="request"></param>
  215. /// <returns></returns>
  216. public async Task<PagedList<TeacherResult>> GetTeacherAsync(TeacherRequest request)
  217. {
  218. var teachers = await teacherRepository.GetTeacherResult(request);
  219. return teachers;
  220. }
  221. /// <summary>
  222. /// 书城
  223. /// </summary>
  224. /// <param name="request"></param>
  225. /// <returns></returns>
  226. public async Task<List<AppLabelResult<MediaCathedraResult>>> GetBookCityAsync(ArticleGroupRequest request)
  227. {
  228. var result = new List<AppLabelResult<MediaCathedraResult>>();
  229. //获取中间页面
  230. var middleLable = await _middleLableRepository.GetAsync("书城");
  231. //获取中间页标签
  232. var middleLableNexusIds = await middleLableNexusRepository.GetAllTaskAsync(middleLable.Id);
  233. //获取标签
  234. var systemLabels = await _systemLabelRepository.GetAllAsync(middleLableNexusIds.Select(n => n.LableId).ToList());
  235. foreach (var item in systemLabels)
  236. {
  237. //获取媒体标签
  238. var mediaIds = await _mediaLableRepository.GetMediaIdsAysnc(item.Id);
  239. var medias = await mediaRepository.GetNavigationMediaResults(mediaIds, item.PageSize);
  240. var list = new List<MediaCathedraResult>();
  241. foreach (var mediaModel in medias)
  242. {
  243. 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 });
  244. }
  245. //获取常规数据
  246. var mediaCathedraResult = new AppLabelResult<MediaCathedraResult>()
  247. {
  248. IsPage = item.IsPage,
  249. Id = item.Id,
  250. LabelName = item.LabelName,
  251. ResourceType = 40,
  252. Items = list,
  253. Method = item.IsPage ? "post" : "",
  254. ActionUrl = item.IsPage ? request.ActionUrl : ""
  255. };
  256. result.Add(mediaCathedraResult);
  257. }
  258. return result;
  259. }
  260. }
  261. }