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
{
///
/// app频道
///
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;
}
///
/// 获取App频道
///
///
public async Task> GetAppChannelsAsync()
{
var result = new List();
//递归频道
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;
}
///
/// 查询 获取频道分类
///
///
public async Task> 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;
}
///
/// 根据app频道分类id获取媒体分页数据
///
///
public async Task> 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);
}
///
/// 查询
///
///
public async Task> 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 IsChildrenAsync(int id)
{
return await channelCategoryRepository.IsChildrenAsync(id);
}
///
/// 根据父级获取 获取频道分类
///
///
public async Task> GetAllByParentIdAsync(AppChannelSearchRequest request)
{
return await channelCategoryRepository.GetAllByParentIdAsync(request);
}
}
}