AppChannelService.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. /// <summary>
  87. /// 查询
  88. /// </summary>
  89. /// <returns></returns>
  90. public async Task<IEnumerable<AppChannelResult>> GetAllAsync(AppChannelConst channelTypeValue)
  91. {
  92. var result = await appChannelRepository.GetAllAsync(channelTypeValue);
  93. foreach (var item in result)
  94. {
  95. if (item.TypeValue != 1)
  96. item.MediaIds = await channelCategoryMediaRepository.GetAllAsync(item.Id, false);
  97. }
  98. return result;
  99. }
  100. }
  101. }