AppPageController.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using GxPress.Common.Page;
  4. using GxPress.Request.ArticleGroup;
  5. using GxPress.Request.Media;
  6. using GxPress.Request.TeacherRequest;
  7. using GxPress.Result.Media;
  8. using GxPress.Result.SystemLabel;
  9. using GxPress.Result.Teacher;
  10. using GxPress.Service.Interface.AppHomePage;
  11. using Microsoft.AspNetCore.Authorization;
  12. using Microsoft.AspNetCore.Mvc;
  13. using GxPress.Repository.Interface.Media;
  14. using GxPress.EnumConst;
  15. using GxPress.Common.Tools;
  16. using GxPress.Result.Category;
  17. using GxPress.Repository.Interface.Category;
  18. namespace GxPress.Api.AppControllers
  19. {
  20. /// <summary>
  21. /// App首页数据
  22. /// </summary>
  23. [Route("api/app/page")]
  24. [ApiController]
  25. [Authorize]
  26. public class AppPageController : Controller
  27. {
  28. private readonly IAppHomePageService appHomePageService;
  29. private readonly IMediaRepository mediaRepository;
  30. private readonly ICategoryRepository categoryRepository;
  31. public AppPageController(IAppHomePageService appHomePageService, IMediaRepository mediaRepository, ICategoryRepository categoryRepository)
  32. {
  33. this.appHomePageService = appHomePageService;
  34. this.mediaRepository = mediaRepository;
  35. this.categoryRepository = categoryRepository;
  36. }
  37. /// <summary>
  38. /// 大咖讲座 每日好书
  39. /// </summary>
  40. /// <param name="request"></param>
  41. /// <returns></returns>
  42. [HttpPost("cathedra")]
  43. [AllowAnonymous]
  44. public async Task<List<AppLabelResult<MediaCathedraResult>>> GetMediasByTeacherAsync(ArticleGroupRequest request)
  45. {
  46. if (string.IsNullOrEmpty(request.StyleCss))
  47. throw new Common.Exceptions.BusinessException("样式未知!");
  48. return await appHomePageService.GetMediasByTeacherAsync(request);
  49. }
  50. /// <summary>
  51. /// 大咖讲座分页接口
  52. /// </summary>
  53. /// <returns></returns>
  54. [HttpPost("cathedra-page")]
  55. [AllowAnonymous]
  56. public async Task<PagedList<MediaCathedraResult>> MediaCathedraResult(ArticleGroupRequest request)
  57. {
  58. return await appHomePageService.MediaCathedraResult(request);
  59. }
  60. /// <summary>
  61. /// 每日好文
  62. /// </summary>
  63. /// <param name="request"></param>
  64. /// <returns></returns>
  65. [HttpPost("day-good-text")]
  66. [AllowAnonymous]
  67. public async Task<PagedList<MediaCathedraResult>> GetDayGoodTextAsync(MediaSearchRequest request)
  68. {
  69. request.MediaType = GxPress.EnumConst.AllTypeConst.Article.GetHashCode();
  70. request.IsDelete = 0;
  71. request.IsChecked = 1;
  72. return await appHomePageService.GetDayGoodTextAsync(request);
  73. }
  74. /// <summary>
  75. /// 每日微课
  76. /// </summary>
  77. /// <returns></returns>
  78. [HttpPost("day-we-book")]
  79. [AllowAnonymous]
  80. public async Task<PagedList<MediaCathedraResult>> GetDayWeBookAsync(MediaDayWeBookRequest request)
  81. {
  82. request.Name = "每日微课";
  83. return await appHomePageService.GetDayWeBookAsync(request);
  84. }
  85. /// <summary>
  86. /// 信源听说
  87. /// </summary>
  88. /// <param name="request"></param>
  89. /// <returns></returns>
  90. [HttpPost("chat-hear-speak")]
  91. [AllowAnonymous]
  92. public async Task<PagedList<MediaCathedraResult>> GetChatHearSpeak(MediaSearchRequest request)
  93. {
  94. request.MediaType = GxPress.EnumConst.AllTypeConst.Audio.GetHashCode();
  95. request.IsDelete = 0;
  96. request.IsChecked = 1;
  97. return await appHomePageService.GetDayGoodTextAsync(request);
  98. }
  99. /// <summary>
  100. /// 根据标签ID获取每日好书 分页换一批
  101. /// </summary>
  102. /// <returns></returns>
  103. [HttpPost("lable")]
  104. [AllowAnonymous]
  105. public async Task<IEnumerable<MediaCathedraResult>> GetMediaByLableIdsAsync(MediaIdsRequest request)
  106. {
  107. return await appHomePageService.GetMediaByLableIdsAsync(request);
  108. }
  109. /// <summary>
  110. /// 根据标签ID获取分页数据
  111. /// </summary>
  112. /// <returns></returns>
  113. [HttpPost("page-lable")]
  114. [AllowAnonymous]
  115. public async Task<PagedList<MediaCathedraResult>> GetMediaByLableIdAsync(MediaLableIdRequest request)
  116. {
  117. return await appHomePageService.GetMediaByLableIdAsync(request);
  118. }
  119. /// <summary>
  120. /// 名师
  121. /// </summary>
  122. /// <param name="request"></param>
  123. /// <returns></returns>
  124. [HttpPost("teacher")]
  125. [AllowAnonymous]
  126. public async Task<PagedList<TeacherResult>> GetTeacherAsync(TeacherRequest request)
  127. {
  128. return await appHomePageService.GetTeacherAsync(request);
  129. }
  130. /// <summary>
  131. /// 每日技能分页
  132. /// </summary>
  133. /// <returns></returns>
  134. [HttpPost("day-skill")]
  135. [AllowAnonymous]
  136. public async Task<PagedList<MediaCathedraResult>> GetDaySkillsAsync(MediaDayWeBookRequest request)
  137. {
  138. request.TypeValue = AllTypeConst.Article.GetHashCode();
  139. return await mediaRepository.GetDaySkillsAsync(request);
  140. }
  141. /// <summary>
  142. /// 随机每日技能
  143. /// </summary>
  144. /// <returns></returns>
  145. [HttpGet("random-day-skill")]
  146. [AllowAnonymous]
  147. public async Task<SkillInfo> GetRandomDaySkillAsync()
  148. {
  149. return await mediaRepository.GetRandomDaySkillAsync();
  150. }
  151. /// <summary>
  152. /// 书城
  153. /// </summary>
  154. /// <returns></returns>
  155. [HttpGet("book-city")]
  156. [AllowAnonymous]
  157. public async Task<List<AppLabelResult<MediaCathedraResult>>> GetBookCityAsync()
  158. {
  159. ArticleGroupRequest request = new ArticleGroupRequest();
  160. request.ActionUrl = "api/app/page/lable";
  161. return await appHomePageService.GetBookCityAsync(request);
  162. }
  163. /// <summary>
  164. /// 猜你喜欢
  165. /// </summary>
  166. /// <returns></returns>
  167. [HttpGet("user-like")]
  168. [AllowAnonymous]
  169. public async Task<IEnumerable<MediaCathedraResult>> GetUserLikeAsync()
  170. {
  171. var result = await mediaRepository.GetUserLikeAsync();
  172. foreach (var item in result)
  173. {
  174. item.ImageUrls = StringUtils.AddDomain(item.ImageUrls);
  175. }
  176. return result;
  177. }
  178. /// <summary>
  179. /// 导航内容分页
  180. /// </summary>
  181. /// <returns></returns>
  182. [HttpPost("content-navigation-list")]
  183. [AllowAnonymous]
  184. public async Task<PagedList<MediaCathedraResult>> GetContentNavigationAsync(MediaContentNavigationRequest request)
  185. {
  186. if (request.MediaIds == null)
  187. request.MediaIds = new List<int>();
  188. return await appHomePageService.GetContentNavigationAsync(request);
  189. }
  190. /// <summary>
  191. /// 内容导航分类
  192. /// </summary>
  193. /// <returns></returns>
  194. [HttpGet("category")]
  195. [AllowAnonymous]
  196. public async Task<IEnumerable<CategoryResult>> GetCategoryAllAsync()
  197. {
  198. return await categoryRepository.GetCategoryAllAsync(1);
  199. }
  200. /// <summary>
  201. /// 榜单
  202. /// </summary>
  203. /// <param name="request"></param>
  204. /// <returns></returns>
  205. [HttpGet("ranking")]
  206. [AllowAnonymous]
  207. public async Task<List<MediaRankingResult>> GetRankingListResults()
  208. {
  209. var dictionary = new Dictionary<int, string>();
  210. dictionary.Add(2, "热书榜");
  211. dictionary.Add(3, "课程榜");
  212. dictionary.Add(4, "文献头条");
  213. dictionary.Add(6, "试听榜");
  214. var dictionaryMedia = new Dictionary<int, string>();
  215. dictionaryMedia.Add(AllTypeConst.Book.GetHashCode(), "热书榜");
  216. dictionaryMedia.Add(AllTypeConst.Curriculum.GetHashCode(), "课程榜");
  217. dictionaryMedia.Add(AllTypeConst.Article.GetHashCode(), "文献头条");
  218. dictionaryMedia.Add(AllTypeConst.Audio.GetHashCode(), "试听榜");
  219. var result = new List<MediaRankingResult>();
  220. foreach (var item in dictionary)
  221. {
  222. var mediaRankingResult = new MediaRankingResult();
  223. var request = new RankingListRequest();
  224. request.DataTypeValue = item.Key;
  225. mediaRankingResult.Name = item.Value;
  226. mediaRankingResult.RankingListResults = await mediaRepository.GetRankingListResults(request);
  227. foreach (var dic in dictionaryMedia)
  228. {
  229. if (dic.Value.Equals(item.Value))
  230. mediaRankingResult.MediaType = dic.Key;
  231. }
  232. result.Add(mediaRankingResult);
  233. }
  234. return result;
  235. }
  236. /// <summary>
  237. /// 排行榜分页 1 热搜 2热书榜 3 课程榜 4Top 100 新书 5文献头条 6试听榜 7大众热评 8Top 100 专著
  238. /// </summary>
  239. /// <param name="request"></param>
  240. /// <returns></returns>
  241. [HttpPost("ranking-page")]
  242. [AllowAnonymous]
  243. public async Task<PagedList<RankingListResult>> GetRankingPageListResults(RankingListRequest request)
  244. {
  245. return await mediaRepository.GetRankingPageListResults(request);
  246. }
  247. }
  248. }