AppChannelService.cs 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. using GxPress.EnumConst;
  5. using GxPress.Repository.Interface.AppChannel;
  6. using GxPress.Result.AppChannel;
  7. using GxPress.Service.Interface.AppChannel;
  8. using GxPress.Common.Tools;
  9. using GxPress.Result.Media;
  10. using GxPress.Request.AppChannel;
  11. using GxPress.Repository.Interface.Media;
  12. using System.Linq;
  13. using GxPress.Common.Page;
  14. namespace GxPress.Service.Implement.AppChannel
  15. {
  16. /// <summary>
  17. /// app频道
  18. /// </summary>
  19. public class AppChannelService : IAppChannelService
  20. {
  21. private readonly IChannelCategoryMediaRepository channelCategoryMediaRepository;
  22. private readonly IChannelCategoryRepository channelCategoryRepository;
  23. private readonly IAppChannelRepository appChannelRepository;
  24. private readonly IMediaRepository mediaRepository;
  25. public AppChannelService(IChannelCategoryMediaRepository channelCategoryMediaRepository, IChannelCategoryRepository channelCategoryRepository, IAppChannelRepository appChannelRepository, IMediaRepository mediaRepository)
  26. {
  27. this.channelCategoryMediaRepository = channelCategoryMediaRepository;
  28. this.channelCategoryRepository = channelCategoryRepository;
  29. this.appChannelRepository = appChannelRepository;
  30. this.mediaRepository = mediaRepository;
  31. }
  32. /// <summary>
  33. /// 获取App频道
  34. /// </summary>
  35. /// <returns></returns>
  36. public async Task<IEnumerable<AppChannelModelResult>> GetAppChannelsAsync()
  37. {
  38. var result = new List<AppChannelModelResult>();
  39. //递归频道
  40. foreach (int v in Enum.GetValues(typeof(AppChannelConst)))
  41. {
  42. var constEnum = (AppChannelConst)v;
  43. var appChannelModelResult = new AppChannelModelResult()
  44. {
  45. Name = constEnum.GetDescriptionOriginal(),
  46. Id = constEnum,
  47. Items = await appChannelRepository.GetAllAsync(constEnum)
  48. };
  49. result.Add(appChannelModelResult);
  50. }
  51. return result;
  52. }
  53. /// <summary>
  54. /// 查询 获取频道分类
  55. /// </summary>
  56. /// <returns></returns>
  57. public async Task<IEnumerable<ChannelCategoryResult>> GetAllAsync(int appChannelId)
  58. {
  59. var result = await channelCategoryRepository.GetAllAsync(appChannelId);
  60. foreach (var item in result)
  61. {
  62. if (!item.IsChildren)
  63. item.MediaIds = await channelCategoryMediaRepository.GetAllAsync(item.Id);
  64. if (item.IsChildren)
  65. {
  66. foreach (var category in item.Children)
  67. {
  68. if (!category.IsChildren)
  69. category.MediaIds = await channelCategoryMediaRepository.GetAllAsync(category.Id);
  70. }
  71. }
  72. }
  73. return result;
  74. }
  75. /// <summary>
  76. /// 根据app频道分类id获取媒体分页数据
  77. /// </summary>
  78. /// <returns></returns>
  79. public async Task<PagedList<MediaCathedraResult>> GetChannelCategoryMediaPageAsync(AppChannelSearchRequest request)
  80. {
  81. //获取标签
  82. var ids = await channelCategoryMediaRepository.GetAllAsync(request.CategoryId);
  83. request.Ids = ids.ToList();
  84. return await mediaRepository.GetAppChannelsAsync(request);
  85. }
  86. }
  87. }