AppPageController.cs 11 KB

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