NavigationService.cs 10 KB

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