李昊 4 years ago
parent
commit
5a62027bc0

+ 25 - 1
gx_api/GxPress/Api/GxPress.Api/AppControllers/AppPageController.cs

@@ -15,6 +15,7 @@ using GxPress.EnumConst;
 using GxPress.Common.Tools;
 using GxPress.Result.Category;
 using GxPress.Repository.Interface.Category;
+using GxPress.Service.Interface.Media;
 
 namespace GxPress.Api.AppControllers
 {
@@ -28,12 +29,14 @@ namespace GxPress.Api.AppControllers
     {
         private readonly IAppHomePageService appHomePageService;
         private readonly IMediaRepository mediaRepository;
+        private readonly IMediaService mediaService;
         private readonly ICategoryRepository categoryRepository;
-        public AppPageController(IAppHomePageService appHomePageService, IMediaRepository mediaRepository, ICategoryRepository categoryRepository)
+        public AppPageController(IAppHomePageService appHomePageService, IMediaRepository mediaRepository, ICategoryRepository categoryRepository, IMediaService mediaService)
         {
             this.appHomePageService = appHomePageService;
             this.mediaRepository = mediaRepository;
             this.categoryRepository = categoryRepository;
+            this.mediaService = mediaService;
         }
 
         /// <summary>
@@ -241,5 +244,26 @@ namespace GxPress.Api.AppControllers
         {
             return await mediaRepository.GetRankingPageListResults(request);
         }
+
+        /// <summary>
+        /// 明栏
+        /// </summary>
+        /// <returns></returns>
+        [HttpGet("star")]
+        [AllowAnonymous]
+        public async Task<IEnumerable<MediaStarLableResult>> GetMediaStarLableResultAysnc()
+        {
+            return await mediaService.GetMediaStarLableResultAysnc();
+        }
+        /// <summary>
+        /// 明栏分页
+        /// </summary>
+        /// <returns></returns>
+        [HttpPost("star-page")]
+        [AllowAnonymous]
+        public async Task<PagedList<MediaCathedraResult>> GetStarLablePageAsync(MediaStarLableRequest request)
+        {
+            return await mediaService.GetStarLablePageAsync(request);
+        }
     }
 }

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

@@ -307,5 +307,22 @@ namespace GxPress.Request.Media
         /// <value></value>
         public List<int> MediaIds { get; set; }
     }
+
+    /// <summary>
+    /// 明栏
+    /// </summary>
+    public class MediaStarLableRequest : Common.Page.PageParameter
+    {
+        /// <summary>
+        /// 明栏ID
+        /// </summary>
+        /// <value></value>
+        public int AttachId { get; set; }
+        /// <summary>
+        /// 关键字
+        /// </summary>
+        /// <value></value>
+        public string KeyWord { get; set; }
+    }
 }
 

+ 21 - 0
gx_api/GxPress/Model/GxPress.Result/Media/MediaResult.cs

@@ -585,4 +585,25 @@ namespace GxPress.Result.Media
         /// <value></value>
         public IEnumerable<RankingListResult> Items { get; set; }
     }
+    /// <summary>
+    /// 明栏
+    /// </summary>
+    public class MediaStarLableResult
+    {
+        /// <summary>
+        /// 名栏目ID
+        /// </summary>
+        /// <value></value>
+        public int Id { get; set; }
+        /// <summary>
+        /// 明栏名称
+        /// </summary>
+        /// <value></value>
+        public string Name { get; set; }
+        /// <summary>
+        /// 明栏数据
+        /// </summary>
+        /// <value></value>
+        public IEnumerable<MediaCathedraResult> Item { get; set; }
+    }
 }

+ 13 - 1
gx_api/GxPress/Repository/GxPress.Repository.Implement/Attach/AttachRepository.cs

@@ -102,6 +102,18 @@ namespace GxPress.Repository.Implement.Attach
             note.CategoryId = categoryId;
             return await _repository.UpdateAsync(note);
         }
-
+        /// <summary>
+        /// 获取明栏
+        /// </summary>
+        /// <returns></returns>
+        public async Task<IEnumerable<(int, string)>> GetStarLablesAsync()
+        {
+            var query = Q.NewQuery();
+            query.Where(nameof(Entity.tede2.Attach.Attach.AttachType), GxPress.EnumConst.AttachTypeConst.StarColumn.GetHashCode());
+            query.OrderByDesc(nameof(Entity.tede2.Attach.Attach.CreatedDate));
+            query.Select(nameof(Entity.tede2.Attach.Attach.Id));
+            query.Select(nameof(Entity.tede2.Attach.Attach.Name));
+            return await _repository.GetAllAsync<(int, string)>(query);
+        }
     }
 }

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

@@ -276,6 +276,10 @@ namespace GxPress.Repository.Implement.Media
                 sql = $@"SELECT  count(1) FROM tede_media WHERE id IN ({str})";
                 result.Total = await connection.ExecuteScalarAsync<int>(sql);
             }
+            foreach (var item in result.Items)
+            {
+                item.ImageUrls = StringUtils.AddDomain(item.ImageUrls);
+            }
             return result;
         }
         public async Task<bool> UpdateAsync(MediaResult result)
@@ -794,5 +798,63 @@ namespace GxPress.Repository.Implement.Media
             resut.Items = await _repository.GetAllAsync<MediaCathedraResult>(query);
             return resut;
         }
+
+        /// <summary>
+        /// 明栏分页
+        /// </summary>
+        /// <returns></returns>
+        public async Task<PagedList<MediaCathedraResult>> GetStarLablePageAsync(MediaStarLableRequest request)
+        {
+            var resut = new PagedList<MediaCathedraResult>();
+            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));
+            if (!string.IsNullOrEmpty(request.KeyWord))
+                query.WhereLike(nameof(Entity.tede2.Media.Media.Title), $"%{request.KeyWord}%");
+            query.Where(nameof(Entity.tede2.Media.Media.AttachId), request.AttachId);
+            resut.Total = await _repository.CountAsync(query);
+            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);
+            resut.Items = await _repository.GetAllAsync<MediaCathedraResult>(query);
+            return resut;
+        }
+        /// <summary>
+        /// 明栏分页
+        /// </summary>
+        /// <returns></returns>
+        public async Task<IEnumerable<MediaCathedraResult>> GetStarLablesAsync(MediaStarLableRequest 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));
+            if (!string.IsNullOrEmpty(request.KeyWord))
+                query.WhereLike(nameof(Entity.tede2.Media.Media.Title), $"%{request.KeyWord}%");
+            query.Where(nameof(Entity.tede2.Media.Media.AttachId), request.AttachId);
+            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); ;
+        }
     }
 }

+ 5 - 0
gx_api/GxPress/Repository/GxPress.Repository.Interface/Attach/IAttachRepository.cs

@@ -17,5 +17,10 @@ namespace GxPress.Repository.Interface.Attach
         Task<int> InsertAsync(Entity.tede2.Attach.Attach note);
 
         Task<bool> UpdateAsync(Entity.tede2.Attach.Attach note);
+        /// <summary>
+        /// 获取明栏
+        /// </summary>
+        /// <returns></returns>
+        Task<IEnumerable<(int, string)>> GetStarLablesAsync();
     }
 }

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

@@ -116,5 +116,15 @@ namespace GxPress.Repository.Interface.Media
         /// <param name="request"></param>
         /// <returns></returns>
         Task<PagedList<RankingListResult>> GetRankingPageListResults(RankingListRequest request);
+        /// <summary>
+        /// 明栏分页
+        /// </summary>
+        /// <returns></returns>
+        Task<PagedList<MediaCathedraResult>> GetStarLablePageAsync(MediaStarLableRequest request);
+        /// <summary>
+        /// 明栏分页
+        /// </summary>
+        /// <returns></returns>
+        Task<IEnumerable<MediaCathedraResult>> GetStarLablesAsync(MediaStarLableRequest request);
     }
 }

+ 48 - 0
gx_api/GxPress/Service/GxPress.Service.Implement/Media/MediaService.StarLable.cs

@@ -0,0 +1,48 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using GxPress.Common.Page;
+using GxPress.Request.Media;
+using GxPress.Result.Media;
+
+namespace GxPress.Service.Implement.Media
+{
+    /// <summary>
+    /// 明栏
+    /// </summary>
+    public partial class MediaService
+    {
+        /// <summary>
+        /// 明栏
+        /// </summary>
+        /// <returns></returns>
+        public async Task<IEnumerable<MediaStarLableResult>> GetMediaStarLableResultAysnc()
+        {
+            var result = new List<MediaStarLableResult>();
+            //获取明栏
+            var starLable = await attachRepository.GetStarLablesAsync();
+            foreach (var item in starLable)
+            {
+                var request = new MediaStarLableRequest()
+                {
+                    AttachId = item.Item1
+                };
+                var mediaStarLableResult = new MediaStarLableResult()
+                {
+                    Id = item.Item1,
+                    Name = item.Item2,
+                    Item = await mediaRepository.GetStarLablesAsync(request)
+                };
+                result.Add(mediaStarLableResult);
+            }
+            return result;
+        }
+        /// <summary>
+        /// 明栏分页
+        /// </summary>
+        /// <returns></returns>
+        public async Task<PagedList<MediaCathedraResult>> GetStarLablePageAsync(MediaStarLableRequest request)
+        {
+            return await mediaRepository.GetStarLablePageAsync(request);
+        }
+    }
+}

+ 5 - 2
gx_api/GxPress/Service/GxPress.Service.Implement/Media/MediaService.cs

@@ -11,10 +11,11 @@ using GxPress.Request.Media;
 using System;
 using GxPress.Repository.Interface;
 using GxPress.Repository.Interface.Order;
+using GxPress.Repository.Interface.Attach;
 
 namespace GxPress.Service.Implement.Media
 {
-    public class MediaService : IMediaService
+    public partial class MediaService : IMediaService
     {
         private readonly ICategoryRepository categoryRepository;
         private readonly IMediaRepository mediaRepository;
@@ -23,7 +24,8 @@ namespace GxPress.Service.Implement.Media
         private readonly IMediaLibraryRepository mediaLibraryRepository;
         private readonly IUserRepository userRepository;
         private readonly IOrderRepository orderRepository;
-        public MediaService(ICategoryRepository categoryRepository, IMediaRepository mediaRepository, IMapper _mapper, IEpubService epubService, IMediaLibraryRepository mediaLibraryRepository, IUserRepository userRepository, IOrderRepository orderRepository)
+        private readonly IAttachRepository attachRepository;
+        public MediaService(ICategoryRepository categoryRepository, IMediaRepository mediaRepository, IMapper _mapper, IEpubService epubService, IMediaLibraryRepository mediaLibraryRepository, IUserRepository userRepository, IOrderRepository orderRepository,IAttachRepository attachRepository)
         {
             this.categoryRepository = categoryRepository;
             this.mediaRepository = mediaRepository;
@@ -32,6 +34,7 @@ namespace GxPress.Service.Implement.Media
             this.mediaLibraryRepository = mediaLibraryRepository;
             this.userRepository = userRepository;
             this.orderRepository = orderRepository;
+            this.attachRepository=attachRepository;
         }
         public async Task<bool> InsertAsync(MediaResult result)
         {

+ 12 - 0
gx_api/GxPress/Service/GxPress.Service.Interface/Media/IMediaService.cs

@@ -1,4 +1,6 @@
+using System.Collections.Generic;
 using System.Threading.Tasks;
+using GxPress.Common.Page;
 using GxPress.Request.Media;
 using GxPress.Result.Media;
 
@@ -27,5 +29,15 @@ namespace GxPress.Service.Interface.Media
         /// <param name="id"></param>
         /// <returns></returns>
         Task<VideoMediaResult> GetVideoMediaResultAsync(int id);
+        /// <summary>
+        /// 明栏
+        /// </summary>
+        /// <returns></returns>
+        Task<IEnumerable<MediaStarLableResult>> GetMediaStarLableResultAysnc();
+        /// <summary>
+        /// 明栏分页
+        /// </summary>
+        /// <returns></returns>
+        Task<PagedList<MediaCathedraResult>> GetStarLablePageAsync(MediaStarLableRequest request);
     }
 }