NavigationService.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using AutoMapper;
  5. using GxPress.Common.Tools;
  6. using GxPress.Repository.Interface;
  7. using GxPress.Repository.Interface.Media;
  8. using GxPress.Repository.Interface.Navigation;
  9. using GxPress.Repository.Interface.SpecialLabel;
  10. using GxPress.Repository.Interface.SystemLabel;
  11. using GxPress.Result.Navigation;
  12. using GxPress.Service.Interface.Navigation;
  13. namespace GxPress.Service.Implement.Navigation
  14. {
  15. public class NavigationService : INavigationService
  16. {
  17. private readonly INavigationRepository _navigationrepository;
  18. private readonly IMapper _mapper;
  19. private readonly IMiddleLableRepository _middleLableRepository;
  20. private readonly ISystemLabelRepository _systemLabelRepository;
  21. private readonly IMediaRepository _mediaRepository;
  22. private readonly IMediaLableRepository _mediaLableRepository;
  23. private readonly ISlideRepository slideRepository;
  24. private readonly ISpecialLabelRepository specialLabelRepository;
  25. public NavigationService(INavigationRepository _repository, IMapper _mapper, IMiddleLableRepository _middleLableRepository, ISystemLabelRepository _systemLabelRepository, IMediaRepository _mediaRepository, IMediaLableRepository _mediaLableRepository, ISlideRepository slideRepository, ISpecialLabelRepository specialLabelRepository)
  26. {
  27. this._navigationrepository = _repository;
  28. this._middleLableRepository = _middleLableRepository;
  29. this._systemLabelRepository = _systemLabelRepository;
  30. this._mediaRepository = _mediaRepository;
  31. this._mediaLableRepository = _mediaLableRepository;
  32. this.slideRepository = slideRepository;
  33. this._mapper = _mapper;
  34. this.specialLabelRepository = specialLabelRepository;
  35. }
  36. /// <summary>
  37. /// 获取导航栏数据
  38. /// </summary>
  39. /// <returns></returns>
  40. public async Task<MiddleLableResult> GetNavigationResults(int navigationId)
  41. {
  42. var result = new MiddleLableResult();
  43. var navigation = await _navigationrepository.GetAsync(navigationId);
  44. if (navigation.MiddleLableId > 0)
  45. {
  46. //获取中间页面
  47. var middleLable = await _middleLableRepository.GetAsync(navigation.MiddleLableId);
  48. if (string.IsNullOrEmpty(middleLable.LabelId))
  49. return result;
  50. result = _mapper.Map<MiddleLableResult>(middleLable);
  51. result.NavigationLabelMediaResults = new List<NavigationLabelMediaResult>();
  52. //获取轮播
  53. if (middleLable.IsSlide)
  54. {
  55. if (result.IsSlide)
  56. {
  57. result.Sildes = await slideRepository.GetListAsync(result.TypeId);
  58. foreach (var item in result.Sildes)
  59. item.ImageUrl = StringUtils.AddDomain(item.ImageUrl);
  60. }
  61. }
  62. //获取标签
  63. var systemLabels = await _systemLabelRepository.GetAllAsync(StringUtils.StringCollectionToIntList(middleLable.LabelId).ToList());
  64. foreach (var item in systemLabels)
  65. {
  66. //获取常规数据
  67. var navigationLabelMediaResult = new NavigationLabelMediaResult()
  68. {
  69. Id = item.Id,
  70. Sort = item.Sort,
  71. StyleType = item.StyleType,
  72. ActionUrl = item.ActionUrl,
  73. ControllerUrl = item.ControllerUrl,
  74. IsPage = item.IsPage,
  75. IsSkip = item.IsSkip,
  76. LabelName = item.LabelName,
  77. ResourceType = item.ResourceType,
  78. LabelNameDescribe = item.LabelNameDescribe,
  79. Remark = item.Remark,
  80. IsShowLabelName = item.IsShowLabelName
  81. };
  82. // 特殊 130,示范课堂140,品牌专区1(150),品牌专区2(160)
  83. var specialInts = systemLabels.Where(n => n.ResourceType >= 130).Select(n => n.ResourceType);
  84. if (specialInts.Contains(item.ResourceType))
  85. {
  86. //获取特殊
  87. navigationLabelMediaResult.IsSpecial = true;
  88. navigationLabelMediaResult.SpecialLabelResults = await specialLabelRepository.GetAllAsync(item.ResourceType);
  89. foreach (var specialLabelResult in navigationLabelMediaResult.SpecialLabelResults)
  90. specialLabelResult.ImageUrls = StringUtils.AddDomain(specialLabelResult.ImageUrls);
  91. result.NavigationLabelMediaResults.Add(navigationLabelMediaResult);
  92. continue;
  93. }
  94. //获取媒体标签
  95. var mediaIds = await _mediaLableRepository.GetMediaIdsAysnc(item.Id);
  96. var medias = await _mediaRepository.GetNavigationMediaResults(mediaIds);
  97. navigationLabelMediaResult.MediaResults = medias.ToList();
  98. foreach (var itemMedia in navigationLabelMediaResult.MediaResults)
  99. itemMedia.ImageUrls = StringUtils.AddDomain(itemMedia.ImageUrls);
  100. result.NavigationLabelMediaResults.Add(navigationLabelMediaResult);
  101. }
  102. }
  103. return result;
  104. }
  105. /// <summary>
  106. /// 获取中间页面数据
  107. /// </summary>
  108. /// <returns></returns>
  109. public async Task<MiddleLableResult> GetMiddleLableResults(int middleLableId)
  110. {
  111. var result = new MiddleLableResult();
  112. //获取中间页面
  113. var middleLable = await _middleLableRepository.GetAsync(middleLableId);
  114. if (string.IsNullOrEmpty(middleLable.LabelId))
  115. return result;
  116. result = _mapper.Map<MiddleLableResult>(middleLable);
  117. result.NavigationLabelMediaResults = new List<NavigationLabelMediaResult>();
  118. //获取轮播
  119. if (middleLable.IsSlide)
  120. {
  121. if (result.IsSlide)
  122. {
  123. result.Sildes = await slideRepository.GetListAsync(result.TypeId);
  124. foreach (var item in result.Sildes)
  125. item.ImageUrl = StringUtils.AddDomain(item.ImageUrl);
  126. }
  127. }
  128. //获取标签
  129. var systemLabels = await _systemLabelRepository.GetAllAsync(StringUtils.StringCollectionToIntList(middleLable.LabelId).ToList());
  130. foreach (var item in systemLabels)
  131. {
  132. //获取常规数据
  133. var navigationLabelMediaResult = new NavigationLabelMediaResult()
  134. {
  135. Id = item.Id,
  136. Sort = item.Sort,
  137. StyleType = item.StyleType,
  138. ActionUrl = item.ActionUrl,
  139. ControllerUrl = item.ControllerUrl,
  140. IsPage = item.IsPage,
  141. IsSkip = item.IsSkip,
  142. LabelName = item.LabelName,
  143. ResourceType = item.ResourceType,
  144. LabelNameDescribe = item.LabelNameDescribe,
  145. Remark = item.Remark
  146. };
  147. // 特殊 130,示范课堂140,品牌专区1(150),品牌专区2(160)
  148. var specialInts = systemLabels.Where(n => n.ResourceType >= 130).Select(n => n.ResourceType);
  149. if (specialInts.Contains(item.ResourceType))
  150. {
  151. //获取特殊
  152. navigationLabelMediaResult.IsSpecial = true;
  153. navigationLabelMediaResult.SpecialLabelResults = await specialLabelRepository.GetAllAsync(item.ResourceType);
  154. foreach (var specialLabelResult in navigationLabelMediaResult.SpecialLabelResults)
  155. specialLabelResult.ImageUrls = StringUtils.AddDomain(specialLabelResult.ImageUrls);
  156. result.NavigationLabelMediaResults.Add(navigationLabelMediaResult);
  157. continue;
  158. }
  159. //获取媒体标签
  160. var mediaIds = await _mediaLableRepository.GetMediaIdsAysnc(item.Id);
  161. var medias = await _mediaRepository.GetNavigationMediaResults(mediaIds);
  162. navigationLabelMediaResult.MediaResults = medias.ToList();
  163. foreach (var itemMedia in navigationLabelMediaResult.MediaResults)
  164. itemMedia.ImageUrls = StringUtils.AddDomain(itemMedia.ImageUrls);
  165. result.NavigationLabelMediaResults.Add(navigationLabelMediaResult);
  166. }
  167. return result;
  168. }
  169. /// <summary>
  170. /// 获取标签数据
  171. /// </summary>
  172. /// <param name="labelId"></param>
  173. /// <returns></returns>
  174. public async Task<LabelMediaResult> GetLabelMediaResult(int labelId)
  175. {
  176. var result = new LabelMediaResult();
  177. //获取媒体标签
  178. var mediaIds = await _mediaLableRepository.GetMediaIdsAysnc(labelId);
  179. result.LabelMediaResults = await _mediaRepository.GetNavigationMediaResults(mediaIds);
  180. result.LikeMediaResults = await _mediaRepository.GetlikeMediaResults();
  181. result.RecommendMediaResults = await _mediaRepository.GetRecommendMediaResults();
  182. return result;
  183. }
  184. }
  185. }