AppPageController.cs 13 KB

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