AppChannelService.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. var appChannel = await appChannelRepository.GetAsync(request.ChannelId);
  82. //获取标签
  83. var ids = await channelCategoryMediaRepository.GetAllAsync(request.CategoryId == 0 ? appChannel.Id : request.CategoryId, appChannel.TypeValue == 1);
  84. request.Ids = ids.ToList();
  85. return await mediaRepository.GetAppChannelsAsync(request);
  86. }
  87. /// <summary>
  88. /// 查询
  89. /// </summary>
  90. /// <returns></returns>
  91. public async Task<IEnumerable<AppChannelResult>> GetAllAsync(AppChannelConst channelTypeValue)
  92. {
  93. var result = await appChannelRepository.GetAllAsync(channelTypeValue);
  94. foreach (var item in result)
  95. {
  96. if (item.TypeValue != 1)
  97. item.MediaIds = await channelCategoryMediaRepository.GetAllAsync(item.Id, false);
  98. }
  99. return result;
  100. }
  101. public async Task<bool> IsChildrenAsync(int id)
  102. {
  103. return await channelCategoryRepository.IsChildrenAsync(id);
  104. }
  105. /// <summary>
  106. /// 根据父级获取 获取频道分类
  107. /// </summary>
  108. /// <returns></returns>
  109. public async Task<PagedList<ChannelCategoryResult>> GetAllByParentIdAsync(AppChannelSearchRequest request)
  110. {
  111. return await channelCategoryRepository.GetAllByParentIdAsync(request);
  112. }
  113. }
  114. }