NavigationService.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. };
  81. // 特殊 130,示范课堂140,品牌专区1(150),品牌专区2(160)
  82. var specialInts = systemLabels.Where(n => n.ResourceType >= 130).Select(n => n.ResourceType);
  83. if (specialInts.Contains(item.ResourceType))
  84. {
  85. //获取特殊
  86. navigationLabelMediaResult.IsSpecial = true;
  87. navigationLabelMediaResult.SpecialLabelResults = await specialLabelRepository.GetAllAsync(item.ResourceType);
  88. foreach (var specialLabelResult in navigationLabelMediaResult.SpecialLabelResults)
  89. specialLabelResult.ImageUrls = StringUtils.AddDomain(specialLabelResult.ImageUrls);
  90. result.NavigationLabelMediaResults.Add(navigationLabelMediaResult);
  91. continue;
  92. }
  93. //获取媒体标签
  94. var lableInts = new List<int> { item.Id };
  95. var medias = await _mediaRepository.GetNavigationMediaResults(lableInts);
  96. navigationLabelMediaResult.MediaResults = medias.ToList();
  97. foreach (var itemMedia in navigationLabelMediaResult.MediaResults)
  98. itemMedia.ImageUrls = StringUtils.AddDomain(itemMedia.ImageUrls);
  99. result.NavigationLabelMediaResults.Add(navigationLabelMediaResult);
  100. }
  101. }
  102. return result;
  103. }
  104. }
  105. }