using GxPress.Service.Interface.AppHomePage;
using GxPress.Repository.Interface;
using GxPress.Repository.Interface.Media;
using GxPress.Request.ArticleGroup;
using System.Threading.Tasks;
using System.Collections.Generic;
using GxPress.Result.SystemLabel;
using GxPress.Result.Media;
using GxPress.Repository.Interface.SystemLabel;
using GxPress.Repository.Interface.Navigation;
using GxPress.Result.MiddleLable;
using AutoMapper;
using System.Linq;
using GxPress.Common.Tools;
using GxPress.Common.Page;
using GxPress.Request.Media;
namespace GxPress.Service.Implement.AppHomePage
{
public class AppHomePageService : IAppHomePageService
{
private readonly IArticleGroupRepository articleGroupRepository;
private readonly IMediaRepository mediaRepository;
private readonly IMapper _mapper;
private readonly IMiddleLableRepository _middleLableRepository;
private readonly ISystemLabelRepository _systemLabelRepository;
private readonly IMediaLableRepository _mediaLableRepository;
private readonly IMiddleLableNexusRepository middleLableNexusRepository;
public AppHomePageService(IArticleGroupRepository articleGroupRepository, IMediaRepository mediaRepository, IMiddleLableRepository _middleLableRepository, ISystemLabelRepository _systemLabelRepository, IMiddleLableNexusRepository middleLableNexusRepository, IMediaLableRepository _mediaLableRepository, IMapper _mapper)
{
this.articleGroupRepository = articleGroupRepository;
this.mediaRepository = mediaRepository;
this._middleLableRepository = _middleLableRepository;
this._systemLabelRepository = _systemLabelRepository;
this.middleLableNexusRepository = middleLableNexusRepository;
this._mediaLableRepository = _mediaLableRepository;
this._mapper = _mapper;
}
///
/// 大咖讲座
///
///
///
public async Task>> GetMediasByTeacherAsync(ArticleGroupRequest request)
{
var results = new List>();
//大师讲座
if (request.StyleCss == "Cathedra")
{
request.Sort = "recommend";
var items = await mediaRepository.GetMediasByTeacherAsync(request);
results.Add(new AppLabelResult() { LabelName = "今日推荐", IsPage = false, ResourceType = 40, Method = "", Items = items });
request.Sort = "";
items = await mediaRepository.GetMediasByTeacherAsync(request);
results.Add(new AppLabelResult() { LabelName = "更多精彩", IsPage = true, ResourceType = 40, Method = "post", Items = items, ActionUrl = "api/app/page/cathedra-page" });
foreach (var item in results)
{
foreach (var model in item.Items)
model.Duration = "02:19:20";
}
}
//会员特供
if (request.StyleCss == "VipSupply")
{
return await GetVipSupplyAsync(request);
}
//每日好书
if (request.StyleCss == "DayGoodBook")
{
return await GetDayGoodBookAsync(request);
}
return results;
}
///
/// 每日好书
///
///
///
public async Task>> GetDayGoodBookAsync(ArticleGroupRequest request)
{
request.ActionUrl = "api/app/page/lable";
return await GetVipSupplyAsync(request);
}
///
/// 每日好文
///
///
///
public async Task> GetDayGoodTextAsync(MediaSearchRequest request)
{
var result = new PagedList();
var model = await mediaRepository.GetAllAsync(request);
var list = new List();
foreach (var item in model.Items)
{
var mediaCathedraResult = new MediaCathedraResult();
mediaCathedraResult.Author = item.Author;
mediaCathedraResult.CollectCount = item.CollectCount;
mediaCathedraResult.CreatedDate = item.CreatedDate;
mediaCathedraResult.Id = item.Id;
mediaCathedraResult.ImageUrls = item.ImageUrls;
mediaCathedraResult.MediaType = item.MediaType;
mediaCathedraResult.ReadCount = item.ReadCount;
mediaCathedraResult.Title = item.Title;
list.Add(mediaCathedraResult);
}
result.Total = model.Total;
result.Items = list;
return result;
}
///
/// 会员特供
///
///
///
public async Task>> GetVipSupplyAsync(ArticleGroupRequest request)
{
var result = new List>();
//根据样式查找导航数据
var articleGroup = await articleGroupRepository.GetArticleGroupAsync(request.StyleCss);
if (articleGroup.IsMiddleLable)
{
//获取中间页面
var middleLable = await _middleLableRepository.GetAsync(articleGroup.MiddleLableId);
//获取中间页标签
var middleLableNexusIds = await middleLableNexusRepository.GetAllTaskAsync(middleLable.Id);
//获取标签
var systemLabels = await _systemLabelRepository.GetAllAsync(middleLableNexusIds.Select(n => n.LableId).ToList());
foreach (var item in systemLabels)
{
//获取媒体标签
var mediaIds = await _mediaLableRepository.GetMediaIdsAysnc(item.Id);
var medias = await mediaRepository.GetNavigationMediaResults(mediaIds, item.PageSize);
var list = new List();
foreach (var mediaModel in medias)
{
list.Add(new MediaCathedraResult { Id = mediaModel.Id, Title = mediaModel.Title, ImageUrls = StringUtils.AddDomain(mediaModel.ImageUrls), Author = mediaModel.Author, ReadCount = mediaModel.ReadCount, CreatedDate = mediaModel.CreatedDate, CollectCount = mediaModel.CollectCount, MediaType = mediaModel.MediaType });
}
//获取常规数据
var mediaCathedraResult = new AppLabelResult()
{
IsPage = item.IsPage,
Id = item.Id,
LabelName = item.LabelName,
ResourceType = 40,
Items = list,
Method = item.IsPage ? "post" : "",
ActionUrl = item.IsPage ? request.ActionUrl : ""
};
result.Add(mediaCathedraResult);
}
}
return result;
}
///
/// 大咖讲座
///
///
public async Task> MediaCathedraResult(ArticleGroupRequest request)
{
var result = new PagedList();
result.Items = await mediaRepository.GetMediasByTeacherAsync(request);
foreach (var item in result.Items)
{
item.ImageUrls = Common.Tools.StringUtils.AddDomain(item.ImageUrls);
}
result.Total = await mediaRepository.GetMediasByTeacherCountAsync(request);
return result;
}
///
/// 根据IDs
///
///
public async Task> GetMediaByLableIdsAsync(MediaIdsRequest request)
{
var ids = await _mediaLableRepository.GetMediaIdsAysnc(request.LableId);
request.Ids = ids.ToList();
return await mediaRepository.GetMediaByLableIdsAsync(request);
}
}
}