123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- using System;
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using GxPress.EnumConst;
- using GxPress.Repository.Interface.AppChannel;
- using GxPress.Result.AppChannel;
- using GxPress.Service.Interface.AppChannel;
- using GxPress.Common.Tools;
- using GxPress.Result.Media;
- using GxPress.Request.AppChannel;
- using GxPress.Repository.Interface.Media;
- using System.Linq;
- using GxPress.Common.Page;
- namespace GxPress.Service.Implement.AppChannel
- {
- /// <summary>
- /// app频道
- /// </summary>
- public class AppChannelService : IAppChannelService
- {
- private readonly IChannelCategoryMediaRepository channelCategoryMediaRepository;
- private readonly IChannelCategoryRepository channelCategoryRepository;
- private readonly IAppChannelRepository appChannelRepository;
- private readonly IMediaRepository mediaRepository;
- public AppChannelService(IChannelCategoryMediaRepository channelCategoryMediaRepository, IChannelCategoryRepository channelCategoryRepository, IAppChannelRepository appChannelRepository, IMediaRepository mediaRepository)
- {
- this.channelCategoryMediaRepository = channelCategoryMediaRepository;
- this.channelCategoryRepository = channelCategoryRepository;
- this.appChannelRepository = appChannelRepository;
- this.mediaRepository = mediaRepository;
- }
- /// <summary>
- /// 获取App频道
- /// </summary>
- /// <returns></returns>
- public async Task<IEnumerable<AppChannelModelResult>> GetAppChannelsAsync()
- {
- var result = new List<AppChannelModelResult>();
- //递归频道
- foreach (int v in Enum.GetValues(typeof(AppChannelConst)))
- {
- var constEnum = (AppChannelConst)v;
- var appChannelModelResult = new AppChannelModelResult()
- {
- Name = constEnum.GetDescriptionOriginal(),
- Id = constEnum,
- Items = await appChannelRepository.GetAllAsync(constEnum)
- };
- result.Add(appChannelModelResult);
- }
- return result;
- }
- /// <summary>
- /// 查询 获取频道分类
- /// </summary>
- /// <returns></returns>
- public async Task<IEnumerable<ChannelCategoryResult>> GetAllAsync(int appChannelId)
- {
- var result = await channelCategoryRepository.GetAllAsync(appChannelId);
- foreach (var item in result)
- {
- if (!item.IsChildren)
- item.MediaIds = await channelCategoryMediaRepository.GetAllAsync(item.Id);
- if (item.IsChildren)
- {
- foreach (var category in item.Children)
- {
- if (!category.IsChildren)
- category.MediaIds = await channelCategoryMediaRepository.GetAllAsync(category.Id);
- }
- }
- }
- return result;
- }
- /// <summary>
- /// 根据app频道分类id获取媒体分页数据
- /// </summary>
- /// <returns></returns>
- public async Task<PagedList<MediaCathedraResult>> GetChannelCategoryMediaPageAsync(AppChannelSearchRequest request)
- {
- var appChannel = await appChannelRepository.GetAsync(request.ChannelId);
- //获取标签
- var ids = await channelCategoryMediaRepository.GetAllAsync(request.CategoryId == 0 ? appChannel.Id : request.CategoryId, appChannel.TypeValue == 1);
- request.Ids = ids.ToList();
- return await mediaRepository.GetAppChannelsAsync(request);
- }
- /// <summary>
- /// 查询
- /// </summary>
- /// <returns></returns>
- public async Task<IEnumerable<AppChannelResult>> GetAllAsync(AppChannelConst channelTypeValue)
- {
- var result = await appChannelRepository.GetAllAsync(channelTypeValue);
- foreach (var item in result)
- {
- if (item.TypeValue != 1)
- item.MediaIds = await channelCategoryMediaRepository.GetAllAsync(item.Id, false);
- }
- return result;
- }
- public async Task<bool> IsChildrenAsync(int id)
- {
- return await channelCategoryRepository.IsChildrenAsync(id);
- }
- /// <summary>
- /// 根据父级获取 获取频道分类
- /// </summary>
- /// <returns></returns>
- public async Task<PagedList<ChannelCategoryResult>> GetAllByParentIdAsync(AppChannelSearchRequest request)
- {
- return await channelCategoryRepository.GetAllByParentIdAsync(request);
- }
- }
- }
|