李昊 il y a 4 ans
Parent
commit
537ce4dd25

+ 18 - 8
gx_api/GxPress/Api/GxPress.Api/AppControllers/AppPageController.cs

@@ -11,6 +11,8 @@ using GxPress.Service.Interface.AppHomePage;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Mvc;
 using GxPress.Repository.Interface.Media;
+using GxPress.EnumConst;
+
 namespace GxPress.Api.AppControllers
 {
     /// <summary>
@@ -66,20 +68,19 @@ namespace GxPress.Api.AppControllers
             request.IsChecked = 1;
             return await appHomePageService.GetDayGoodTextAsync(request);
         }
+
         /// <summary>
         /// 每日微课
         /// </summary>
-        /// <param name="request"></param>
         /// <returns></returns>
         [HttpPost("day-we-book")]
         [AllowAnonymous]
-        public async Task<PagedList<MediaCathedraResult>> GetDayWeBookAsync(MediaSearchRequest request)
+        public async Task<PagedList<MediaCathedraResult>> GetDayWeBookAsync(MediaDayWeBookRequest request)
         {
-            request.MediaType = GxPress.EnumConst.AllTypeConst.Curriculum.GetHashCode();
-            request.IsDelete = 0;
-            request.IsChecked = 1;
-            return await appHomePageService.GetDayGoodTextAsync(request);
+            request.Name = "每日微课";
+            return await appHomePageService.GetDayWeBookAsync(request);
         }
+
         /// <summary>
         /// 信源听说
         /// </summary>
@@ -132,8 +133,9 @@ namespace GxPress.Api.AppControllers
         /// <returns></returns>
         [HttpPost("day-skill")]
         [AllowAnonymous]
-        public async Task<PagedList<MediaCathedraResult>> GetDaySkillsAsync(Common.Page.PageParameter request)
+        public async Task<PagedList<MediaCathedraResult>> GetDaySkillsAsync(MediaDayWeBookRequest request)
         {
+            request.TypeValue = AllTypeConst.Article.GetHashCode();
             return await mediaRepository.GetDaySkillsAsync(request);
         }
 
@@ -159,6 +161,14 @@ namespace GxPress.Api.AppControllers
             request.ActionUrl = "api/app/page/lable";
             return await appHomePageService.GetBookCityAsync(request);
         }
-
+        /// <summary>
+        /// 猜你喜欢
+        /// </summary>
+        /// <returns></returns>
+        [HttpGet("user-like")]
+        public async Task<IEnumerable<MediaCathedraResult>> GetUserLikeAsync()
+        {
+            return await mediaRepository.GetUserLikeAsync();
+        }
     }
 }

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

@@ -270,5 +270,20 @@ namespace GxPress.Request.Media
         public List<int> Ids { get; set; }
     }
 
-
+    /// <summary>
+    /// 每日微课
+    /// </summary>
+    public class MediaDayWeBookRequest : Common.Page.PageParameter
+    {
+        /// <summary>
+        /// 名称
+        /// </summary>
+        /// <value></value>
+        public string Name { get; set; }
+        /// <summary>
+        /// 类型
+        /// </summary>
+        /// <value></value>
+        public int TypeValue { get; set; }
+    }
 }

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

@@ -443,7 +443,7 @@ namespace GxPress.Repository.Implement.Media
         /// </summary>
         /// <param name="mediaIds"></param>
         /// <returns></returns>
-        public async Task<IEnumerable<NavigationMediaResult>> GetNavigationMediaResults(IEnumerable<int> mediaIds, int pageSize = 10)
+        public async Task<IEnumerable<NavigationMediaResult>> GetNavigationMediaResults(IEnumerable<int> mediaIds, int page = 1, int pageSize = 10)
         {
             //获取媒体
             var query = Q.NewQuery();
@@ -464,7 +464,7 @@ namespace GxPress.Repository.Implement.Media
             query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsTop));
             query.OrderByDesc(nameof(Entity.tede2.Media.Media.IsRecommend));
             query.OrderByDesc(nameof(Entity.tede2.Media.Media.LastModifiedDate));
-            query.ForPage(1, pageSize);
+            query.ForPage(page, pageSize);
             return await _repository.GetAllAsync<NavigationMediaResult>(query);
         }
         /// <summary>
@@ -625,7 +625,7 @@ namespace GxPress.Repository.Implement.Media
         /// 每日技能分页
         /// </summary>
         /// <returns></returns>
-        public async Task<PagedList<MediaCathedraResult>> GetDaySkillsAsync(Common.Page.PageParameter request)
+        public async Task<PagedList<MediaCathedraResult>> GetDaySkillsAsync(MediaDayWeBookRequest request)
         {
             var resut = new PagedList<MediaCathedraResult>();
             var query = Q.NewQuery();
@@ -637,7 +637,7 @@ namespace GxPress.Repository.Implement.Media
             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());
+            query.Where(nameof(Entity.tede2.Media.Media.MediaType), request.TypeValue);
             resut.Total = await _repository.CountAsync(query);
             if (!string.IsNullOrEmpty(request.Sort))
             {
@@ -667,5 +667,21 @@ namespace GxPress.Repository.Implement.Media
             var connection = database.GetConnection();
             return await connection.QueryFirstOrDefaultAsync<SkillInfo>(sql);
         }
+        /// <summary>
+        /// 猜你喜欢
+        /// </summary>
+        /// <returns></returns>
+        public async Task<IEnumerable<MediaCathedraResult>> GetUserLikeAsync()
+        {
+            var sql = $@"SELECT 
+                            Id,ImageUrls,Title,Author,MediaType,ReadCount,CreatedDate
+                        FROM
+                            tede_media where IsExercises=1 and MediaType={AllTypeConst.Article.GetHashCode()}
+                        ORDER BY RAND() LIMIT 3";
+            var databaseType = _databaseTypestr.ToEnum<DatabaseType>(DatabaseType.MySql);
+            var database = new Database(databaseType, _connectionString);
+            var connection = database.GetConnection();
+            return await connection.QueryAsync<MediaCathedraResult>(sql);
+        }
     }
 }

+ 4 - 1
gx_api/GxPress/Repository/GxPress.Repository.Implement/SystemLabel/SystemLabelRepository.cs

@@ -39,7 +39,10 @@ namespace GxPress.Repository.Implement.SystemLabel
         {
             return await _repository.GetAsync(id);
         }
-
+        public async Task<Entity.SystemLabel.SystemLabel> GetByNameAsync(string name)
+        {
+            return await _repository.GetAsync(Q.WhereLike(nameof(Entity.SystemLabel.SystemLabel.LabelName), $"%{name}%"));
+        }
         public async Task<bool> DeleteAsync(int id)
         {
             return await _repository.DeleteAsync(id);

+ 7 - 2
gx_api/GxPress/Repository/GxPress.Repository.Interface/Media/IMediaRepository.cs

@@ -43,7 +43,7 @@ namespace GxPress.Repository.Interface.Media
         /// <param name="mediaId"></param>
         /// <returns></returns>
         Task<VideoMediaResult> GetVideoMediaResultAsync(int mediaId);
-        Task<IEnumerable<NavigationMediaResult>> GetNavigationMediaResults(IEnumerable<int> mediaLables, int pageSize = 10);
+        Task<IEnumerable<NavigationMediaResult>> GetNavigationMediaResults(IEnumerable<int> mediaLables,int page=1, int pageSize = 10);
         /// <summary>
         /// 猜你喜欢
         /// </summary>
@@ -93,12 +93,17 @@ namespace GxPress.Repository.Interface.Media
         /// 每日技能分页
         /// </summary>
         /// <returns></returns>
-        Task<PagedList<MediaCathedraResult>> GetDaySkillsAsync(Common.Page.PageParameter request);
+        Task<PagedList<MediaCathedraResult>> GetDaySkillsAsync(MediaDayWeBookRequest request);
 
         /// <summary>
         /// 每日技能
         /// </summary>
         /// <returns></returns>
         Task<SkillInfo> GetRandomDaySkillAsync();
+         /// <summary>
+        /// 猜你喜欢
+        /// </summary>
+        /// <returns></returns>
+        Task<IEnumerable<MediaCathedraResult>> GetUserLikeAsync();
     }
 }

+ 1 - 0
gx_api/GxPress/Repository/GxPress.Repository.Interface/SystemLabel/ISystemLabelRepository.cs

@@ -18,6 +18,7 @@ namespace GxPress.Repository.Interface.SystemLabel
         Task<bool> UpdateAsync(SystemLabelUpRequest note);
         Task<PagedList<SystemLabelResult>> GetAllAsync(Common.Page.PageParameter request);
         Task<IEnumerable<Entity.SystemLabel.SystemLabel>> GetAllAsync(List<int> ids);
+        Task<Entity.SystemLabel.SystemLabel> GetByNameAsync(string name);
 
     }
 }

+ 21 - 3
gx_api/GxPress/Service/GxPress.Service.Implement/AppHomePage/AppHomePageService.cs

@@ -28,8 +28,9 @@ namespace GxPress.Service.Implement.AppHomePage
         private readonly ISystemLabelRepository _systemLabelRepository;
         private readonly IMediaLableRepository _mediaLableRepository;
         private readonly IMiddleLableNexusRepository middleLableNexusRepository;
+        private readonly ISystemLableMediaRepository systemLableMediaRepository;
         private readonly ITeacherRepository teacherRepository;
-        public AppHomePageService(IArticleGroupRepository articleGroupRepository, IMediaRepository mediaRepository, IMiddleLableRepository _middleLableRepository, ISystemLabelRepository _systemLabelRepository, IMiddleLableNexusRepository middleLableNexusRepository, IMediaLableRepository _mediaLableRepository, IMapper _mapper, ITeacherRepository teacherRepository)
+        public AppHomePageService(IArticleGroupRepository articleGroupRepository, IMediaRepository mediaRepository, IMiddleLableRepository _middleLableRepository, ISystemLabelRepository _systemLabelRepository, IMiddleLableNexusRepository middleLableNexusRepository, IMediaLableRepository _mediaLableRepository, IMapper _mapper, ITeacherRepository teacherRepository, ISystemLableMediaRepository systemLableMediaRepository)
         {
             this.articleGroupRepository = articleGroupRepository;
             this.mediaRepository = mediaRepository;
@@ -39,6 +40,7 @@ namespace GxPress.Service.Implement.AppHomePage
             this._mediaLableRepository = _mediaLableRepository;
             this._mapper = _mapper;
             this.teacherRepository = teacherRepository;
+            this.systemLableMediaRepository = systemLableMediaRepository;
         }
         /// <summary>
         /// 大咖讲座
@@ -122,6 +124,22 @@ namespace GxPress.Service.Implement.AppHomePage
             return result;
         }
         /// <summary>
+        /// 获取每日微课
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        public async Task<PagedList<MediaCathedraResult>> GetDayWeBookAsync(MediaDayWeBookRequest request)
+        {
+            var result = new PagedList<MediaCathedraResult>();
+            var systemLabel = await _systemLabelRepository.GetByNameAsync(request.Name);
+            var mediaLableIdRequest = new MediaLableIdRequest();
+            mediaLableIdRequest.Page = request.Page;
+            mediaLableIdRequest.PerPage = request.PerPage;
+            var ids = await systemLableMediaRepository.GetMediaIdsAsync(systemLabel.Id);
+            mediaLableIdRequest.Ids = ids.ToList();
+            return await mediaRepository.GetMediaByLableIdAsync(mediaLableIdRequest);
+        }
+        /// <summary>
         /// 会员特供
         /// </summary>
         /// <param name="request"></param>
@@ -143,7 +161,7 @@ namespace GxPress.Service.Implement.AppHomePage
                 {
                     //获取媒体标签
                     var mediaIds = await _mediaLableRepository.GetMediaIdsAysnc(item.Id);
-                    var medias = await mediaRepository.GetNavigationMediaResults(mediaIds, item.PageSize);
+                    var medias = await mediaRepository.GetNavigationMediaResults(mediaIds, 1, item.PageSize);
                     var list = new List<MediaCathedraResult>();
                     foreach (var mediaModel in medias)
                     {
@@ -238,7 +256,7 @@ namespace GxPress.Service.Implement.AppHomePage
             {
                 //获取媒体标签
                 var mediaIds = await _mediaLableRepository.GetMediaIdsAysnc(item.Id);
-                var medias = await mediaRepository.GetNavigationMediaResults(mediaIds, item.PageSize);
+                var medias = await mediaRepository.GetNavigationMediaResults(mediaIds, 1, item.PageSize);
                 var list = new List<MediaCathedraResult>();
                 foreach (var mediaModel in medias)
                 {

+ 1 - 1
gx_api/GxPress/Service/GxPress.Service.Implement/Navigation/NavigationService.cs

@@ -113,7 +113,7 @@ namespace GxPress.Service.Implement.Navigation
                         }
                         //获取媒体标签
                         var mediaIds = await _mediaLableRepository.GetMediaIdsAysnc(item.Id);
-                        var medias = await _mediaRepository.GetNavigationMediaResults(mediaIds,item.PageSize);
+                        var medias = await _mediaRepository.GetNavigationMediaResults(mediaIds,1,item.PageSize);
                         navigationLabelMediaResult.MediaResults = medias.ToList();
                         foreach (var itemMedia in navigationLabelMediaResult.MediaResults)
                             itemMedia.ImageUrls = StringUtils.AddDomain(itemMedia.ImageUrls);

+ 8 - 2
gx_api/GxPress/Service/GxPress.Service.Interface/AppHomePage/IAppHomePageService.cs

@@ -44,11 +44,17 @@ namespace GxPress.Service.Interface.AppHomePage
         /// </summary>
         /// <returns></returns>
         Task<PagedList<MediaCathedraResult>> GetMediaByLableIdAsync(MediaLableIdRequest request);
-         /// <summary>
+        /// <summary>
         /// 书城
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
-         Task<List<AppLabelResult<MediaCathedraResult>>> GetBookCityAsync(ArticleGroupRequest request);
+        Task<List<AppLabelResult<MediaCathedraResult>>> GetBookCityAsync(ArticleGroupRequest request);
+        /// <summary>
+        /// 获取每日微课
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        Task<PagedList<MediaCathedraResult>> GetDayWeBookAsync(MediaDayWeBookRequest request);
     }
 }