AppPageController.cs 10 KB

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