AppPageController.cs 11 KB

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