李昊 4 years ago
parent
commit
cab67a659b

+ 5 - 5
gx_api/GxPress/Api/GxPress.Api/AppControllers/AppPageController.cs

@@ -28,7 +28,7 @@ namespace GxPress.Api.AppControllers
         }
 
         /// <summary>
-        /// 大咖讲座 
+        /// 大咖讲座  每日好书 
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
@@ -80,12 +80,12 @@ namespace GxPress.Api.AppControllers
         }
 
         /// <summary>
-        /// 根据标签ID获取每日好书
+        /// 根据标签ID获取每日好书 分页换一批
         /// </summary>
         /// <returns></returns>
         [HttpPost("lable")]
-         [AllowAnonymous]
-        public async Task<PagedList<MediaCathedraResult>> GetMediaByLableIdsAsync(MediaIdsRequest request)
+        [AllowAnonymous]
+        public async Task<IEnumerable<MediaCathedraResult>> GetMediaByLableIdsAsync(MediaIdsRequest request)
         {
             return await appHomePageService.GetMediaByLableIdsAsync(request);
         }
@@ -95,7 +95,7 @@ namespace GxPress.Api.AppControllers
         /// <param name="request"></param>
         /// <returns></returns>
         [HttpPost("teacher")]
-         [AllowAnonymous]
+        [AllowAnonymous]
         public async Task<PagedList<TeacherResult>> GetTeacherAsync(TeacherRequest request)
         {
             return await appHomePageService.GetTeacherAsync(request);

+ 3 - 1
gx_api/GxPress/Model/GxPress.Request/Media/MediaRequest.cs

@@ -254,10 +254,12 @@ namespace GxPress.Request.Media
     /// <summary>
     /// 
     /// </summary>
-    public class MediaIdsRequest : Common.Page.PageParameter
+    public class MediaIdsRequest
     {
         public int LableId { get; set; }
         public List<int> Ids { get; set; }
+
+        public int Limit { get; set; }
     }
 
 

+ 20 - 20
gx_api/GxPress/Repository/GxPress.Repository.Implement/Media/MediaRepository.cs

@@ -15,6 +15,7 @@ using GxPress.Request.Media;
 using System;
 using GxPress.EnumConst;
 using GxPress.Request.ArticleGroup;
+using Dapper;
 
 namespace GxPress.Repository.Implement.Media
 {
@@ -224,29 +225,28 @@ namespace GxPress.Repository.Implement.Media
         /// 根据IDs
         /// </summary>
         /// <returns></returns>
-        public async Task<PagedList<MediaCathedraResult>> GetMediaByLableIdsAsync(MediaIdsRequest request)
+        public async Task<IEnumerable<MediaCathedraResult>> GetMediaByLableIdsAsync(MediaIdsRequest request)
         {
-            var result = 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));
-            query.WhereIn(nameof(Entity.tede2.Media.Media.Id), request.Ids);
-            result.Total = await _repository.CountAsync(query);
-            if (!string.IsNullOrEmpty(request.Sort))
+            if (request.Ids.Count > 0)
             {
-                query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
-                query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsRecommend));
+                var str = "";
+                foreach (var item in request.Ids)
+                    str += item + ",";
+                str = str.Remove(str.Length - 1, 1);
+                var sql = $@"SELECT 
+                            Id,ImageUrls,Title,Author,MediaType,ReadCount,CreatedDate
+                        FROM
+                            tede_media
+                        WHERE
+                            id IN ({str})
+                        ORDER BY RAND() LIMIT {request.Limit}";
+
+                var databaseType = _databaseTypestr.ToEnum<DatabaseType>(DatabaseType.MySql);
+                var database = new Database(databaseType, _connectionString);
+                var connection = database.GetConnection();
+                return await connection.QueryAsync<MediaCathedraResult>(sql);
             }
-            else
-                query.OrderByDesc(nameof(Entity.tede2.Media.Media.CreatedDate));
-            query.ForPage(request.Page, request.PerPage);
-            result.Items = await _repository.GetAllAsync<MediaCathedraResult>(query);
-            return result;
+            return null;
         }
 
         public async Task<bool> UpdateAsync(MediaResult result)

+ 1 - 1
gx_api/GxPress/Repository/GxPress.Repository.Interface/Media/IMediaRepository.cs

@@ -83,6 +83,6 @@ namespace GxPress.Repository.Interface.Media
         /// 根据IDs
         /// </summary>
         /// <returns></returns>
-       Task<PagedList<MediaCathedraResult>> GetMediaByLableIdsAsync(MediaIdsRequest request);
+      Task<IEnumerable<MediaCathedraResult>> GetMediaByLableIdsAsync(MediaIdsRequest request);
     }
 }

+ 4 - 2
gx_api/GxPress/Service/GxPress.Service.Implement/AppHomePage/AppHomePageService.cs

@@ -8,7 +8,6 @@ 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;
@@ -185,10 +184,13 @@ namespace GxPress.Service.Implement.AppHomePage
         /// 根据IDs
         /// </summary>
         /// <returns></returns>
-        public async Task<PagedList<MediaCathedraResult>> GetMediaByLableIdsAsync(MediaIdsRequest request)
+        public async Task<IEnumerable<MediaCathedraResult>> GetMediaByLableIdsAsync(MediaIdsRequest request)
         {
+            //获取标签
+            var systemLabel = await _systemLabelRepository.GetAsync(request.LableId);
             var ids = await _mediaLableRepository.GetMediaIdsAysnc(request.LableId);
             request.Ids = ids.ToList();
+            request.Limit = systemLabel.PageSize;
             return await mediaRepository.GetMediaByLableIdsAsync(request);
         }
         /// <summary>

+ 1 - 1
gx_api/GxPress/Service/GxPress.Service.Interface/AppHomePage/IAppHomePageService.cs

@@ -33,7 +33,7 @@ namespace GxPress.Service.Interface.AppHomePage
         /// 根据IDs
         /// </summary>
         /// <returns></returns>
-        Task<PagedList<MediaCathedraResult>> GetMediaByLableIdsAsync(MediaIdsRequest request);
+        Task<IEnumerable<MediaCathedraResult>> GetMediaByLableIdsAsync(MediaIdsRequest request);
         /// 名师
         /// </summary>
         /// <param name="request"></param>