李昊 4 年之前
父节点
当前提交
cfe0138813

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

@@ -104,6 +104,16 @@ namespace GxPress.Api.AppControllers
             return await appHomePageService.GetMediaByLableIdsAsync(request);
         }
         /// <summary>
+        /// 根据标签ID获取分页数据
+        /// </summary>
+        /// <returns></returns>
+        [HttpPost("page-lable")]
+        [AllowAnonymous]
+        public async Task<PagedList<MediaCathedraResult>> GetMediaByLableIdAsync(MediaLableIdRequest request)
+        {
+            return await appHomePageService.GetMediaByLableIdAsync(request);
+        }
+        /// <summary>
         /// 名师
         /// </summary>
         /// <param name="request"></param>

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

@@ -261,6 +261,14 @@ namespace GxPress.Request.Media
 
         public int Limit { get; set; }
     }
+    /// <summary>
+    /// 
+    /// </summary>
+    public class MediaLableIdRequest : Common.Page.PageParameter
+    {
+        public int LableId { get; set; }
+        public List<int> Ids { get; set; }
+    }
 
 
 }

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

@@ -248,7 +248,36 @@ namespace GxPress.Repository.Implement.Media
             }
             return null;
         }
+        /// <summary>
+        /// 根据IDs
+        /// </summary>
+        /// <returns></returns>
+        public async Task<PagedList<MediaCathedraResult>> GetMediaByLableIdAsync(MediaLableIdRequest request)
+        {
+            var result = new PagedList<MediaCathedraResult>();
+            if (request.Ids.Count > 0)
+            {
+                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 CreatedDate desc  LIMIT {(request.Page - 1) * request.PerPage},{request.PerPage}";
 
+                var databaseType = _databaseTypestr.ToEnum<DatabaseType>(DatabaseType.MySql);
+                var database = new Database(databaseType, _connectionString);
+                var connection = database.GetConnection();
+                result.Items = await connection.QueryAsync<MediaCathedraResult>(sql);
+                sql = $@"SELECT  count(1) FROM tede_media WHERE id IN ({str})";
+                result.Total = await connection.ExecuteScalarAsync<int>(sql);
+            }
+            return null;
+        }
         public async Task<bool> UpdateAsync(MediaResult result)
         {
             //var model = _mapper.Map<Entity.tede2.Media.Media>(result);

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

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

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

@@ -196,6 +196,20 @@ namespace GxPress.Service.Implement.AppHomePage
             return await mediaRepository.GetMediaByLableIdsAsync(request);
         }
         /// <summary>
+        /// 根据IDs
+        /// </summary>
+        /// <returns></returns>
+        public async Task<PagedList<MediaCathedraResult>> GetMediaByLableIdAsync(MediaLableIdRequest request)
+        {
+            //获取标签
+            var systemLabel = await _systemLabelRepository.GetAsync(request.LableId);
+            if (systemLabel == null)
+                return null;
+            var ids = await _mediaLableRepository.GetMediaIdsAysnc(request.LableId);
+            request.Ids = ids.ToList();
+            return await mediaRepository.GetMediaByLableIdAsync(request);
+        }
+        /// <summary>
         /// 名师
         /// </summary>
         /// <param name="request"></param>

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

@@ -39,5 +39,10 @@ namespace GxPress.Service.Interface.AppHomePage
         /// <param name="request"></param>
         /// <returns></returns>
         Task<PagedList<TeacherResult>> GetTeacherAsync(TeacherRequest request);
+        /// <summary>
+        /// 根据IDs
+        /// </summary>
+        /// <returns></returns>
+        Task<PagedList<MediaCathedraResult>> GetMediaByLableIdAsync(MediaLableIdRequest request);
     }
 }