李昊 4 years ago
parent
commit
fe2f3ec8e8

+ 50 - 0
gx_api/GxPress/Api/GxPress.Api/AppControllers/AppPageController.cs

@@ -0,0 +1,50 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using GxPress.Request.ArticleGroup;
+using GxPress.Result.Media;
+using GxPress.Result.SystemLabel;
+using GxPress.Service.Interface.AppHomePage;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Mvc;
+
+namespace GxPress.Api.AppControllers
+{
+    /// <summary>
+    /// App首页数据
+    /// </summary>
+    [Route("api/app/page")]
+    [ApiController]
+    [Authorize]
+    public class AppPageController : Controller
+    {
+        private readonly IAppHomePageService appHomePageService;
+        public AppPageController(IAppHomePageService appHomePageService)
+        {
+            this.appHomePageService = appHomePageService;
+        }
+
+        /// <summary>
+        /// 大咖讲座
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("cathedra")]
+        [AllowAnonymous]
+        public async Task<List<AppLabelResult<MediaCathedraResult>>> GetMediasByTeacherAsync(ArticleGroupRequest request)
+        {
+            if (string.IsNullOrEmpty(request.StyleCss))
+                throw new Common.Exceptions.BusinessException("样式未知!");
+            return await appHomePageService.GetMediasByTeacherAsync(request);
+        }
+        /// <summary>
+        /// 大咖讲座分页接口
+        /// </summary>
+        /// <returns></returns>
+        [HttpPost("cathedra-page")]
+        [AllowAnonymous]
+        public async Task<IEnumerable<MediaCathedraResult>> MediaCathedraResult(ArticleGroupRequest request)
+        {
+            return await appHomePageService.MediaCathedraResult(request);
+        }
+    }
+}

+ 14 - 0
gx_api/GxPress/Model/GxPress.Request/ArticleGroup/ArticleGroupRequest.cs

@@ -0,0 +1,14 @@
+namespace GxPress.Request.ArticleGroup
+{
+    /// <summary>
+    /// 
+    /// </summary>
+    public class ArticleGroupRequest:Common.Page.PageParameter
+    {
+        /// <summary>
+        /// 样式
+        /// </summary>
+        /// <value></value>
+        public string StyleCss{get;set;}
+    }
+}

+ 2 - 0
gx_api/GxPress/Model/GxPress.Request/Media/MediaRequest.cs

@@ -251,4 +251,6 @@ namespace GxPress.Request.Media
         /// <value></value>
         public int DataTypeValue { get; set; }
     }
+
+    
 }

+ 47 - 1
gx_api/GxPress/Model/GxPress.Result/Media/MediaResult.cs

@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
 using GxPress.EnumConst;
 using GxPress.Result.Category;
 
@@ -444,4 +445,49 @@ namespace GxPress.Result.Media
 
         public string Author { get; set; }
     }
+
+    /// <summary>
+    /// 大咖讲座
+    /// </summary>
+    public class MediaCathedraResult
+    {
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <value></value>
+        public int Id { get; set; }
+        /// <summary>
+        /// 标题
+        /// </summary>
+
+        public string Title { get; set; }
+
+        /// <summary>
+        /// 标题图片
+        /// </summary>
+
+        public string ImageUrls { get; set; }
+
+
+        /// <summary>
+        /// 作者
+        /// </summary>
+
+        public string Author { get; set; }
+        /// <summary>
+        /// 阅读量
+        /// </summary>
+        /// <value></value>
+        public int ReadCount { get; set; }
+        /// <summary>
+        /// 创建时间
+        /// </summary>
+        /// <value></value>
+        public DateTime? CreatedDate { get; set; }
+        /// <summary>
+        /// 时长
+        /// </summary>
+        /// <value></value>
+        public string Duration { get; set; }
+    }
 }

+ 42 - 0
gx_api/GxPress/Model/GxPress.Result/SystemLabel/SystemLabelResult.cs

@@ -1,3 +1,5 @@
+using System.Collections.Generic;
+
 namespace GxPress.Result.SystemLabel
 {
     /// <summary>
@@ -99,4 +101,44 @@ namespace GxPress.Result.SystemLabel
         /// <value></value>
         public int ResourceCount { get; set; }
     }
+    /// <summary>
+    /// APP导航
+    /// </summary>
+    public class AppLabelResult<TItem>
+    {
+        /// <summary>
+        /// 显示数据
+        /// </summary>
+        /// <value></value>
+        public IEnumerable<TItem> Items { get; set; }
+        /// <summary>
+        /// 标签名称
+        /// </summary>
+        /// <value></value>
+
+        public string LabelName { get; set; }
+        /// <summary>
+        /// 资源类型 文章100书籍20,课程30,音频40,期刊50,视频60,名栏90,公众号110,刊期120,榜单130,示范课堂140,品牌专区1(150),品牌专区2(160)
+        /// </summary>
+        /// <value></value>
+
+        public int ResourceType { get; set; }
+        /// <summary>
+        /// 路径
+        /// </summary>
+        /// <value></value>
+
+        public string ActionUrl { get; set; }
+        /// <summary>
+        /// 是否分页
+        /// </summary>
+        /// <value></value>
+
+        public bool IsPage { get; set; }
+        /// <summary>
+        /// 请求类型
+        /// </summary>
+        /// <value></value>
+        public string Method { get; set; }
+    }
 }

+ 27 - 0
gx_api/GxPress/Repository/GxPress.Repository.Implement/Media/MediaRepository.cs

@@ -14,6 +14,7 @@ using GxPress.Common.Page;
 using GxPress.Request.Media;
 using System;
 using GxPress.EnumConst;
+using GxPress.Request.ArticleGroup;
 
 namespace GxPress.Repository.Implement.Media
 {
@@ -517,5 +518,31 @@ namespace GxPress.Repository.Implement.Media
             query.ForPage(request.Page, request.PerPage);
             return await _repository.GetAllAsync<RankingListResult>(query);
         }
+        /// <summary>
+        /// 大咖讲座
+        /// </summary>
+        /// <returns></returns>
+        public async Task<IEnumerable<MediaCathedraResult>> GetMediasByTeacherAsync(ArticleGroupRequest request)
+        {
+            var query = Q.NewQuery();
+            query.Select(nameof(Entity.tede2.Media.Media.Id));
+            query.Select(nameof(Entity.tede2.Media.Media.ImageUrls));
+            query.Select(nameof(Entity.tede2.Media.Media.Title));
+            query.Select(nameof(Entity.tede2.Media.Media.Author));
+            query.Select(nameof(Entity.tede2.Media.Media.MediaType));
+            query.Select(nameof(Entity.tede2.Media.Media.ReadCount));
+            query.Select(nameof(Entity.tede2.Media.Media.CreatedDate));
+            query.Where(nameof(Entity.tede2.Media.Media.TeacherId), ">", 0);
+            query.Where(nameof(Entity.tede2.Media.Media.MediaType), GxPress.EnumConst.AllTypeConst.Video.GetHashCode());
+            if (!string.IsNullOrEmpty(request.Sort))
+            {
+                query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
+                query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsRecommend));
+            }
+            else
+                query.OrderByDesc(nameof(Entity.tede2.Media.Media.CreatedDate));
+            query.ForPage(request.Page, request.PerPage);
+            return await _repository.GetAllAsync<MediaCathedraResult>(query);
+        }
     }
 }

+ 6 - 0
gx_api/GxPress/Repository/GxPress.Repository.Interface/Media/IMediaRepository.cs

@@ -2,6 +2,7 @@
 using System.Threading.Tasks;
 using Datory;
 using GxPress.Common.Page;
+using GxPress.Request.ArticleGroup;
 using GxPress.Request.Media;
 using GxPress.Result.Media;
 
@@ -68,5 +69,10 @@ namespace GxPress.Repository.Interface.Media
         /// <param name="query"></param>
         /// <returns></returns>
         Task<MediaNoteResult> GetAsync(SqlKata.Query query);
+         /// <summary>
+        /// 大咖讲座
+        /// </summary>
+        /// <returns></returns>
+        Task<IEnumerable<MediaCathedraResult>> GetMediasByTeacherAsync(ArticleGroupRequest request);
     }
 }

+ 51 - 0
gx_api/GxPress/Service/GxPress.Service.Implement/AppHomePage/AppHomePageService.cs

@@ -0,0 +1,51 @@
+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;
+
+namespace GxPress.Service.Implement.AppHomePage
+{
+    public class AppHomePageService : IAppHomePageService
+    {
+        private readonly IArticleGroupRepository articleGroupRepository;
+        private readonly IMediaRepository mediaRepository;
+        public AppHomePageService(IArticleGroupRepository articleGroupRepository, IMediaRepository mediaRepository)
+        {
+            this.articleGroupRepository = articleGroupRepository;
+            this.mediaRepository = mediaRepository;
+        }
+        /// <summary>
+        /// 大咖讲座
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        public async Task<List<AppLabelResult<MediaCathedraResult>>> GetMediasByTeacherAsync(ArticleGroupRequest request)
+        {
+            var results = new List<AppLabelResult<MediaCathedraResult>>();
+            request.Sort = "recommend";
+            var items = await mediaRepository.GetMediasByTeacherAsync(request);
+            results.Add(new AppLabelResult<MediaCathedraResult>() { LabelName = "今日推荐", IsPage = false, ResourceType = 40, Method = "", Items = items });
+            request.Sort = "";
+            items = await mediaRepository.GetMediasByTeacherAsync(request);
+            results.Add(new AppLabelResult<MediaCathedraResult>() { 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";
+            }
+            return results;
+        }
+        /// <summary>
+        /// 大咖讲座
+        /// </summary>
+        /// <returns></returns>
+        public async Task<IEnumerable<MediaCathedraResult>> MediaCathedraResult(ArticleGroupRequest request)
+        {
+            return await mediaRepository.GetMediasByTeacherAsync(request);
+        }
+    }
+}

+ 23 - 0
gx_api/GxPress/Service/GxPress.Service.Interface/AppHomePage/IAppHomePageService.cs

@@ -0,0 +1,23 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using GxPress.Request.ArticleGroup;
+using GxPress.Result.Media;
+using GxPress.Result.SystemLabel;
+
+namespace GxPress.Service.Interface.AppHomePage
+{
+    public interface IAppHomePageService : IService
+    {
+        /// <summary>
+        /// 大咖讲座
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        Task<List<AppLabelResult<MediaCathedraResult>>> GetMediasByTeacherAsync(ArticleGroupRequest request);
+         /// <summary>
+        /// 大咖讲座分页
+        /// </summary>
+        /// <returns></returns>
+         Task<IEnumerable<MediaCathedraResult>> MediaCathedraResult(ArticleGroupRequest request);
+    }
+}