AppHomePageService.cs 14 KB

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