NavigationService.cs 11 KB

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