李昊 4 years ago
parent
commit
c351675710

+ 23 - 2
gx_api/GxPress/Api/GxPress.Api/AppControllers/AppPageController.cs

@@ -10,7 +10,7 @@ using GxPress.Result.Teacher;
 using GxPress.Service.Interface.AppHomePage;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Mvc;
-
+using GxPress.Repository.Interface.Media;
 namespace GxPress.Api.AppControllers
 {
     /// <summary>
@@ -22,9 +22,11 @@ namespace GxPress.Api.AppControllers
     public class AppPageController : Controller
     {
         private readonly IAppHomePageService appHomePageService;
-        public AppPageController(IAppHomePageService appHomePageService)
+        private readonly IMediaRepository mediaRepository;
+        public AppPageController(IAppHomePageService appHomePageService, IMediaRepository mediaRepository)
         {
             this.appHomePageService = appHomePageService;
+            this.mediaRepository = mediaRepository;
         }
 
         /// <summary>
@@ -124,5 +126,24 @@ namespace GxPress.Api.AppControllers
         {
             return await appHomePageService.GetTeacherAsync(request);
         }
+        /// <summary>
+        /// 每日技能分页
+        /// </summary>
+        /// <returns></returns>
+        [HttpPost("day-skill")]
+        public async Task<PagedList<MediaCathedraResult>> GetDaySkillsAsync(Common.Page.PageParameter request)
+        {
+            return await mediaRepository.GetDaySkillsAsync(request);
+        }
+
+        /// <summary>
+        /// 随机每日技能
+        /// </summary>
+        /// <returns></returns>
+        [HttpGet("random-day-skill")]
+        public async Task<MediaCathedraResult> GetRandomDaySkillAsync()
+        {
+            return await mediaRepository.GetRandomDaySkillAsync();
+        }
     }
 }

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

@@ -618,5 +618,52 @@ namespace GxPress.Repository.Implement.Media
             query.Where(nameof(Entity.tede2.Media.Media.MediaType), GxPress.EnumConst.AllTypeConst.Video.GetHashCode());
             return await _repository.CountAsync(query);
         }
+
+        /// <summary>
+        /// 每日技能分页
+        /// </summary>
+        /// <returns></returns>
+        public async Task<PagedList<MediaCathedraResult>> GetDaySkillsAsync(Common.Page.PageParameter 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));
+            query.Where(nameof(Entity.tede2.Media.Media.IsExercises), true);
+            query.Where(nameof(Entity.tede2.Media.Media.MediaType), AllTypeConst.Article.GetHashCode());
+            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<MediaCathedraResult> GetRandomDaySkillAsync()
+        {
+            var sql = $@"SELECT 
+                            Id,ImageUrls,Title,Author,MediaType,ReadCount,CreatedDate
+                        FROM
+                            tede_media IsExercises=1 and MediaType={AllTypeConst.Article.GetHashCode()}
+                        ORDER BY RAND() LIMIT 1";
+            var databaseType = _databaseTypestr.ToEnum<DatabaseType>(DatabaseType.MySql);
+            var database = new Database(databaseType, _connectionString);
+            var connection = database.GetConnection();
+            return await connection.QueryFirstAsync<MediaCathedraResult>(sql);
+        }
     }
 }

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

@@ -89,5 +89,16 @@ namespace GxPress.Repository.Interface.Media
         /// </summary>
         /// <returns></returns>
         Task<PagedList<MediaCathedraResult>> GetMediaByLableIdAsync(MediaLableIdRequest request);
+        /// <summary>
+        /// 每日技能分页
+        /// </summary>
+        /// <returns></returns>
+        Task<PagedList<MediaCathedraResult>> GetDaySkillsAsync(Common.Page.PageParameter request);
+
+        /// <summary>
+        /// 每日技能
+        /// </summary>
+        /// <returns></returns>
+        Task<MediaCathedraResult> GetRandomDaySkillAsync();
     }
 }