NavigationService.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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.Select(n => n.LableId).ToList());
  70. foreach (var middleLableNexus in middleLableNexusIds)
  71. {
  72. foreach (var item in systemLabels)
  73. {
  74. if (middleLableNexus.LableId != item.Id)
  75. continue;
  76. //获取常规数据
  77. var navigationLabelMediaResult = new NavigationLabelMediaResult()
  78. {
  79. Id = item.Id,
  80. Sort = item.Sort,
  81. StyleType = item.StyleType,
  82. ActionUrl = item.ActionUrl,
  83. ControllerUrl = item.ControllerUrl,
  84. IsPage = item.IsPage,
  85. IsSkip = item.IsSkip,
  86. LabelName = item.LabelName,
  87. ResourceType = item.ResourceType,
  88. LabelNameDescribe = item.LabelNameDescribe,
  89. Remark = item.Remark,
  90. IsShowLabelName = item.IsShowLabelName
  91. };
  92. // 特殊 130,示范课堂140,品牌专区1(150),品牌专区2(160),170 直播 180 名师
  93. var specialInts = systemLabels.Where(n => n.ResourceType >= 130).Select(n => n.ResourceType);
  94. if (specialInts.Contains(item.ResourceType))
  95. {
  96. //获取特殊
  97. navigationLabelMediaResult.IsSpecial = true;
  98. //名师
  99. if (item.ResourceType == SpecialConst.Teacher.GetHashCode())
  100. {
  101. navigationLabelMediaResult.IsTeacher = true;
  102. navigationLabelMediaResult.TeacherResults = await teacherRepository.GetTeacherResult();
  103. result.NavigationLabelMediaResults.Add(navigationLabelMediaResult);
  104. continue;
  105. }
  106. navigationLabelMediaResult.SpecialLabelResults = await specialLabelRepository.GetAllAsync(item.ResourceType);
  107. foreach (var specialLabelResult in navigationLabelMediaResult.SpecialLabelResults)
  108. specialLabelResult.ImageUrls = StringUtils.AddDomain(specialLabelResult.ImageUrls);
  109. result.NavigationLabelMediaResults.Add(navigationLabelMediaResult);
  110. continue;
  111. }
  112. //获取媒体标签
  113. var mediaIds = await _mediaLableRepository.GetMediaIdsAysnc(item.Id);
  114. var medias = await _mediaRepository.GetNavigationMediaResults(mediaIds);
  115. navigationLabelMediaResult.MediaResults = medias.ToList();
  116. foreach (var itemMedia in navigationLabelMediaResult.MediaResults)
  117. itemMedia.ImageUrls = StringUtils.AddDomain(itemMedia.ImageUrls);
  118. result.NavigationLabelMediaResults.Add(navigationLabelMediaResult);
  119. }
  120. }
  121. }
  122. return result;
  123. }
  124. /// <summary>
  125. /// 获取中间页面数据
  126. /// </summary>
  127. /// <returns></returns>
  128. public async Task<MiddleLableResult> GetMiddleLableResults(int middleLableId)
  129. {
  130. var result = new MiddleLableResult();
  131. //获取中间页面
  132. var middleLable = await _middleLableRepository.GetAsync(middleLableId);
  133. //获取中间页标签
  134. var middleLableNexusIds = await middleLableNexusRepository.GetAllTaskAsync(middleLableId);
  135. result = _mapper.Map<MiddleLableResult>(middleLable);
  136. result.NavigationLabelMediaResults = new List<NavigationLabelMediaResult>();
  137. //获取轮播
  138. if (middleLable.IsSlide)
  139. {
  140. if (result.IsSlide)
  141. {
  142. result.Sildes = await slideRepository.GetListAsync(result.TypeId);
  143. foreach (var item in result.Sildes)
  144. item.ImageUrl = StringUtils.AddDomain(item.ImageUrl);
  145. }
  146. }
  147. //获取标签
  148. var systemLabels = await _systemLabelRepository.GetAllAsync(middleLableNexusIds.Select(n => n.LableId).ToList());
  149. foreach (var item in systemLabels)
  150. {
  151. //获取常规数据
  152. var navigationLabelMediaResult = new NavigationLabelMediaResult()
  153. {
  154. Id = item.Id,
  155. Sort = item.Sort,
  156. StyleType = item.StyleType,
  157. ActionUrl = item.ActionUrl,
  158. ControllerUrl = item.ControllerUrl,
  159. IsPage = item.IsPage,
  160. IsSkip = item.IsSkip,
  161. LabelName = item.LabelName,
  162. ResourceType = item.ResourceType,
  163. LabelNameDescribe = item.LabelNameDescribe,
  164. Remark = item.Remark
  165. };
  166. // 特殊 130,示范课堂140,品牌专区1(150),品牌专区2(160)
  167. var specialInts = systemLabels.Where(n => n.ResourceType >= 130).Select(n => n.ResourceType);
  168. if (specialInts.Contains(item.ResourceType))
  169. {
  170. //获取特殊
  171. navigationLabelMediaResult.IsSpecial = true;
  172. navigationLabelMediaResult.SpecialLabelResults = await specialLabelRepository.GetAllAsync(item.ResourceType);
  173. foreach (var specialLabelResult in navigationLabelMediaResult.SpecialLabelResults)
  174. specialLabelResult.ImageUrls = StringUtils.AddDomain(specialLabelResult.ImageUrls);
  175. result.NavigationLabelMediaResults.Add(navigationLabelMediaResult);
  176. continue;
  177. }
  178. //获取媒体标签
  179. var mediaIds = await _mediaLableRepository.GetMediaIdsAysnc(item.Id);
  180. var medias = await _mediaRepository.GetNavigationMediaResults(mediaIds);
  181. navigationLabelMediaResult.MediaResults = medias.ToList();
  182. foreach (var itemMedia in navigationLabelMediaResult.MediaResults)
  183. itemMedia.ImageUrls = StringUtils.AddDomain(itemMedia.ImageUrls);
  184. result.NavigationLabelMediaResults.Add(navigationLabelMediaResult);
  185. }
  186. return result;
  187. }
  188. /// <summary>
  189. /// 获取标签数据
  190. /// </summary>
  191. /// <param name="labelId"></param>
  192. /// <returns></returns>
  193. public async Task<LabelMediaResult> GetLabelMediaResult(int labelId)
  194. {
  195. var result = new LabelMediaResult();
  196. //获取媒体标签
  197. var mediaIds = await _mediaLableRepository.GetMediaIdsAysnc(labelId);
  198. result.LabelMediaResults = await _mediaRepository.GetNavigationMediaResults(mediaIds);
  199. result.LikeMediaResults = await _mediaRepository.GetlikeMediaResults();
  200. result.RecommendMediaResults = await _mediaRepository.GetRecommendMediaResults();
  201. return result;
  202. }
  203. }
  204. }