using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using AutoMapper; using GxPress.Common.Tools; using GxPress.EnumConst; using GxPress.Repository.Interface; using GxPress.Repository.Interface.Media; using GxPress.Repository.Interface.Navigation; using GxPress.Repository.Interface.SpecialLabel; using GxPress.Repository.Interface.SystemLabel; using GxPress.Repository.Interface.Teacher; using GxPress.Result.Navigation; using GxPress.Service.Interface.Navigation; namespace GxPress.Service.Implement.Navigation { public class NavigationService : INavigationService { private readonly INavigationRepository _navigationrepository; private readonly IMapper _mapper; private readonly IMiddleLableRepository _middleLableRepository; private readonly ISystemLabelRepository _systemLabelRepository; private readonly IMediaRepository _mediaRepository; private readonly IMediaLableRepository _mediaLableRepository; private readonly IMiddleLableNexusRepository middleLableNexusRepository; private readonly ISlideRepository slideRepository; private readonly ISpecialLabelRepository specialLabelRepository; private readonly ITeacherRepository teacherRepository; public NavigationService(INavigationRepository _repository, IMapper _mapper, IMiddleLableRepository _middleLableRepository, ISystemLabelRepository _systemLabelRepository, IMediaRepository _mediaRepository, IMediaLableRepository _mediaLableRepository, ISlideRepository slideRepository, ISpecialLabelRepository specialLabelRepository, ITeacherRepository teacherRepository, IMiddleLableNexusRepository middleLableNexusRepository) { this._navigationrepository = _repository; this._middleLableRepository = _middleLableRepository; this._systemLabelRepository = _systemLabelRepository; this._mediaRepository = _mediaRepository; this._mediaLableRepository = _mediaLableRepository; this.slideRepository = slideRepository; this._mapper = _mapper; this.specialLabelRepository = specialLabelRepository; this.teacherRepository = teacherRepository; this.middleLableNexusRepository = middleLableNexusRepository; } /// /// 获取导航栏数据 /// /// public async Task GetNavigationResults(int navigationId) { var result = new MiddleLableResult(); var navigation = await _navigationrepository.GetAsync(navigationId); if (navigation.MiddleLableId > 0) { //获取中间页面 var middleLable = await _middleLableRepository.GetAsync(navigation.MiddleLableId); result = _mapper.Map(middleLable); result.NavigationLabelMediaResults = new List(); //获取中间页标签 var middleLableNexusIds = await middleLableNexusRepository.GetAllTaskAsync(navigation.MiddleLableId); //获取轮播 if (middleLable.IsSlide) { if (result.IsSlide) { result.Sildes = await slideRepository.GetListAsync(result.TypeId); foreach (var item in result.Sildes) item.ImageUrl = StringUtils.AddDomain(item.ImageUrl); } } //获取标签 var systemLabels = await _systemLabelRepository.GetAllAsync(middleLableNexusIds.Select(n => n.LableId).ToList()); foreach (var middleLableNexus in middleLableNexusIds) { foreach (var item in systemLabels) { if (middleLableNexus.LableId != item.Id) continue; //获取常规数据 var navigationLabelMediaResult = new NavigationLabelMediaResult() { Id = item.Id, Sort = item.Sort, StyleType = item.StyleType, ActionUrl = item.ActionUrl, ControllerUrl = item.ControllerUrl, IsPage = item.IsPage, IsSkip = item.IsSkip, LabelName = item.LabelName, ResourceType = item.ResourceType, LabelNameDescribe = item.LabelNameDescribe, Remark = item.Remark, IsShowLabelName = item.IsShowLabelName }; // 特殊 130,示范课堂140,品牌专区1(150),品牌专区2(160),170 直播 180 名师 var specialInts = systemLabels.Where(n => n.ResourceType >= 130).Select(n => n.ResourceType); if (specialInts.Contains(item.ResourceType)) { //获取特殊 navigationLabelMediaResult.IsSpecial = true; //名师 if (item.ResourceType == SpecialConst.Teacher.GetHashCode()) { navigationLabelMediaResult.IsTeacher = true; navigationLabelMediaResult.TeacherResults = await teacherRepository.GetTeacherResult(); result.NavigationLabelMediaResults.Add(navigationLabelMediaResult); continue; } navigationLabelMediaResult.SpecialLabelResults = await specialLabelRepository.GetAllAsync(item.ResourceType); foreach (var specialLabelResult in navigationLabelMediaResult.SpecialLabelResults) specialLabelResult.ImageUrls = StringUtils.AddDomain(specialLabelResult.ImageUrls); result.NavigationLabelMediaResults.Add(navigationLabelMediaResult); continue; } //获取媒体标签 var mediaIds = await _mediaLableRepository.GetMediaIdsAysnc(item.Id); var medias = await _mediaRepository.GetNavigationMediaResults(mediaIds); navigationLabelMediaResult.MediaResults = medias.ToList(); foreach (var itemMedia in navigationLabelMediaResult.MediaResults) itemMedia.ImageUrls = StringUtils.AddDomain(itemMedia.ImageUrls); result.NavigationLabelMediaResults.Add(navigationLabelMediaResult); } } } return result; } /// /// 获取中间页面数据 /// /// public async Task GetMiddleLableResults(int middleLableId) { var result = new MiddleLableResult(); //获取中间页面 var middleLable = await _middleLableRepository.GetAsync(middleLableId); //获取中间页标签 var middleLableNexusIds = await middleLableNexusRepository.GetAllTaskAsync(middleLableId); result = _mapper.Map(middleLable); result.NavigationLabelMediaResults = new List(); //获取轮播 if (middleLable.IsSlide) { if (result.IsSlide) { result.Sildes = await slideRepository.GetListAsync(result.TypeId); foreach (var item in result.Sildes) item.ImageUrl = StringUtils.AddDomain(item.ImageUrl); } } //获取标签 var systemLabels = await _systemLabelRepository.GetAllAsync(middleLableNexusIds.Select(n => n.LableId).ToList()); foreach (var item in systemLabels) { //获取常规数据 var navigationLabelMediaResult = new NavigationLabelMediaResult() { Id = item.Id, Sort = item.Sort, StyleType = item.StyleType, ActionUrl = item.ActionUrl, ControllerUrl = item.ControllerUrl, IsPage = item.IsPage, IsSkip = item.IsSkip, LabelName = item.LabelName, ResourceType = item.ResourceType, LabelNameDescribe = item.LabelNameDescribe, Remark = item.Remark }; // 特殊 130,示范课堂140,品牌专区1(150),品牌专区2(160) var specialInts = systemLabels.Where(n => n.ResourceType >= 130).Select(n => n.ResourceType); if (specialInts.Contains(item.ResourceType)) { //获取特殊 navigationLabelMediaResult.IsSpecial = true; navigationLabelMediaResult.SpecialLabelResults = await specialLabelRepository.GetAllAsync(item.ResourceType); foreach (var specialLabelResult in navigationLabelMediaResult.SpecialLabelResults) specialLabelResult.ImageUrls = StringUtils.AddDomain(specialLabelResult.ImageUrls); result.NavigationLabelMediaResults.Add(navigationLabelMediaResult); continue; } //获取媒体标签 var mediaIds = await _mediaLableRepository.GetMediaIdsAysnc(item.Id); var medias = await _mediaRepository.GetNavigationMediaResults(mediaIds); navigationLabelMediaResult.MediaResults = medias.ToList(); foreach (var itemMedia in navigationLabelMediaResult.MediaResults) itemMedia.ImageUrls = StringUtils.AddDomain(itemMedia.ImageUrls); result.NavigationLabelMediaResults.Add(navigationLabelMediaResult); } return result; } /// /// 获取标签数据 /// /// /// public async Task GetLabelMediaResult(int labelId) { var result = new LabelMediaResult(); //获取媒体标签 var mediaIds = await _mediaLableRepository.GetMediaIdsAysnc(labelId); result.LabelMediaResults = await _mediaRepository.GetNavigationMediaResults(mediaIds); result.LikeMediaResults = await _mediaRepository.GetlikeMediaResults(); result.RecommendMediaResults = await _mediaRepository.GetRecommendMediaResults(); return result; } } }