AppPageController.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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>() { { AllTypeConst.Book.GetHashCode(), "热书榜" }, { AllTypeConst.Curriculum.GetHashCode(), "课程榜" }, { AllTypeConst.Article.GetHashCode(), "文献头条" }, { AllTypeConst.Audio.GetHashCode(), "视听榜" } };
  220. var result = new List<MediaRankingResult>();
  221. foreach (var item in dictionary)
  222. {
  223. var mediaRankingResult = new MediaRankingResult();
  224. var request = new RankingListRequest();
  225. request.DataTypeValue = item.Key;
  226. mediaRankingResult.Name = item.Value;
  227. mediaRankingResult.Items = await mediaRepository.GetRankingListResults(request);
  228. foreach (var dic in dictionaryMedia)
  229. {
  230. if (dic.Value.Equals(item.Value))
  231. mediaRankingResult.MediaType = dic.Key;
  232. }
  233. result.Add(mediaRankingResult);
  234. }
  235. return result;
  236. }
  237. /// <summary>
  238. /// 排行榜分页 1 热搜 2热书榜 3 课程榜 4Top 100 新书 5文献头条 6试听榜 7大众热评 8Top 100 专著
  239. /// </summary>
  240. /// <param name="request"></param>
  241. /// <returns></returns>
  242. [HttpPost("ranking-page")]
  243. [AllowAnonymous]
  244. public async Task<PagedList<RankingListResult>> GetRankingPageListResults(RankingListRequest request)
  245. {
  246. return await mediaRepository.GetRankingPageListResults(request);
  247. }
  248. /// <summary>
  249. /// 明栏
  250. /// </summary>
  251. /// <returns></returns>
  252. [HttpGet("star")]
  253. [AllowAnonymous]
  254. public async Task<IEnumerable<MediaStarLableResult>> GetMediaStarLableResultAysnc()
  255. {
  256. return await mediaService.GetMediaStarLableResultAysnc();
  257. }
  258. /// <summary>
  259. /// 明栏分页
  260. /// </summary>
  261. /// <returns></returns>
  262. [HttpPost("star-page")]
  263. [AllowAnonymous]
  264. public async Task<PagedList<MediaCathedraResult>> GetStarLablePageAsync(MediaStarLableRequest request)
  265. {
  266. return await mediaService.GetStarLablePageAsync(request);
  267. }
  268. /// <summary>
  269. /// 获取搜索内容
  270. /// </summary>
  271. /// <param name="request"></param>
  272. /// <returns></returns>
  273. [HttpPost("navigation-search")]
  274. [AllowAnonymous]
  275. public async Task<NavigationSearchResult> GetNavigationSearchResultAsync(NavigationSearchRequest request)
  276. {
  277. return await appHomePageService.GetNavigationSearchResultAsync(request);
  278. }
  279. /// <summary>
  280. /// 获取App频道
  281. /// </summary>
  282. /// <returns></returns>
  283. [HttpGet("channel")]
  284. [AllowAnonymous]
  285. public async Task<IEnumerable<AppChannelModelResult>> GetAppChannelsAsync()
  286. {
  287. return await appChannelService.GetAppChannelsAsync();
  288. }
  289. /// <summary>
  290. /// 查询 获取频道分类
  291. /// </summary>
  292. /// <returns></returns>
  293. [HttpGet("channel-category/{appChannelId}")]
  294. [AllowAnonymous]
  295. public async Task<IEnumerable<ChannelCategoryResult>> GetAllAsync(int appChannelId)
  296. {
  297. return await appChannelService.GetAllAsync(appChannelId);
  298. }
  299. /// <summary>
  300. /// 根据频道分类ID获取分页数据
  301. /// </summary>
  302. /// <returns></returns>
  303. [HttpPost("channel-category-media")]
  304. [AllowAnonymous]
  305. public async Task<PagedList<MediaChannelCategoryResult>> GetChannelCategoryMediaPageAsync(AppChannelSearchRequest request)
  306. {
  307. var result = new PagedList<MediaChannelCategoryResult>();
  308. if (request.CategoryId > 0)
  309. {
  310. if (await appChannelService.IsChildrenAsync(request.CategoryId))
  311. {
  312. var categroys = await appChannelService.GetAllByParentIdAsync(request);
  313. result.Total = categroys.Total;
  314. var list = new List<MediaChannelCategoryResult>();
  315. foreach (var item in categroys.Items)
  316. {
  317. list.Add(new MediaChannelCategoryResult { Id = item.Id, Name = item.Name, ExpandName = item.ExpandName, IsCategory = true });
  318. }
  319. result.Items = list;
  320. return result;
  321. }
  322. return await appChannelService.GetChannelCategoryMediaPageAsync(request);
  323. }
  324. return await appChannelService.GetChannelCategoryMediaPageAsync(request);
  325. }
  326. /// <summary>
  327. /// 书籍SKU
  328. /// </summary>
  329. /// <returns></returns>
  330. [HttpGet("sku")]
  331. [AllowAnonymous]
  332. public async Task<SkuResult> SkuResultAsync()
  333. {
  334. return await appHomePageService.SkuResultAsync();
  335. }
  336. }
  337. }