李昊 пре 4 година
родитељ
комит
fc6987ee7d

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

@@ -13,6 +13,8 @@ using Microsoft.AspNetCore.Mvc;
 using GxPress.Repository.Interface.Media;
 using GxPress.EnumConst;
 using GxPress.Common.Tools;
+using GxPress.Result.Category;
+using GxPress.Repository.Interface.Category;
 
 namespace GxPress.Api.AppControllers
 {
@@ -26,10 +28,12 @@ namespace GxPress.Api.AppControllers
     {
         private readonly IAppHomePageService appHomePageService;
         private readonly IMediaRepository mediaRepository;
-        public AppPageController(IAppHomePageService appHomePageService, IMediaRepository mediaRepository)
+        private readonly ICategoryRepository categoryRepository;
+        public AppPageController(IAppHomePageService appHomePageService, IMediaRepository mediaRepository, ICategoryRepository categoryRepository)
         {
             this.appHomePageService = appHomePageService;
             this.mediaRepository = mediaRepository;
+            this.categoryRepository = categoryRepository;
         }
 
         /// <summary>
@@ -167,6 +171,7 @@ namespace GxPress.Api.AppControllers
         /// </summary>
         /// <returns></returns>
         [HttpGet("user-like")]
+        [AllowAnonymous]
         public async Task<IEnumerable<MediaCathedraResult>> GetUserLikeAsync()
         {
             var result = await mediaRepository.GetUserLikeAsync();
@@ -176,5 +181,27 @@ namespace GxPress.Api.AppControllers
             }
             return result;
         }
+        /// <summary>
+        /// 导航内容分页
+        /// </summary>
+        /// <returns></returns>
+        [HttpPost("content-navigation-list")]
+        [AllowAnonymous]
+        public async Task<PagedList<MediaCathedraResult>> GetContentNavigationAsync(MediaContentNavigationRequest request)
+        {
+            if (request.MediaIds == null)
+                request.MediaIds = new List<int>();
+            return await appHomePageService.GetContentNavigationAsync(request);
+        }
+        /// <summary>
+        /// 内容导航分类
+        /// </summary>
+        /// <returns></returns>
+        [HttpGet("category")]
+        [AllowAnonymous]
+        public async Task<IEnumerable<CategoryResult>> GetCategoryAllAsync()
+        {
+            return await categoryRepository.GetCategoryAllAsync(1);
+        }
     }
 }

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

@@ -286,4 +286,21 @@ namespace GxPress.Request.Media
         /// <value></value>
         public int TypeValue { get; set; }
     }
+    /// <summary>
+    /// 内容导航
+    /// </summary>
+    public class MediaContentNavigationRequest : Common.Page.PageParameter
+    {
+        /// <summary>
+        /// 导航ID
+        /// </summary>
+        /// <value></value>
+        public int CategoryId { get; set; }
+        /// <summary>
+        /// 媒体ID
+        /// </summary>
+        /// <value></value>
+        public List<int> MediaIds { get; set; }
+    }
 }
+

+ 29 - 4
gx_api/GxPress/Repository/GxPress.Repository.Implement/Category/CategoryRepository.cs

@@ -1,11 +1,13 @@
 using System;
 using System.Collections.Generic;
+using System.Linq;
 using System.Threading.Tasks;
 using AutoMapper;
 using Datory;
 using GxPress.Common.AppOptions;
 using GxPress.Common.Tools;
 using GxPress.Repository.Interface.Category;
+using GxPress.Result.Category;
 using Microsoft.Extensions.Options;
 using SqlKata;
 
@@ -40,7 +42,7 @@ namespace GxPress.Repository.Implement.Category
 
         public async Task<IEnumerable<Entity.tede2.Category.Category>> GetAllAsync(int typeValue)
         {
-            return await _repository.GetAllAsync(Q.Where(nameof(Entity.tede2.Category.Category.TypeValue),typeValue));
+            return await _repository.GetAllAsync(Q.Where(nameof(Entity.tede2.Category.Category.TypeValue), typeValue));
         }
 
         public async Task<Entity.tede2.Category.Category> GetAsync(int id)
@@ -48,9 +50,9 @@ namespace GxPress.Repository.Implement.Category
             return await _repository.GetAsync(id);
         }
 
-        public async Task<IEnumerable<Entity.tede2.Category.Category>> GetCategoryChildrenAsync(int parentId,int typeValue)
+        public async Task<IEnumerable<Entity.tede2.Category.Category>> GetCategoryChildrenAsync(int parentId, int typeValue)
         {
-            var result = await _repository.GetAllAsync(Q.Where(nameof(Entity.tede2.Category.Category.ParentId), parentId).Where(nameof(Entity.tede2.Category.Category.TypeValue),typeValue));
+            var result = await _repository.GetAllAsync(Q.Where(nameof(Entity.tede2.Category.Category.ParentId), parentId).Where(nameof(Entity.tede2.Category.Category.TypeValue), typeValue));
             foreach (var item in result)
             {
                 item.IsChildren = await IsChildren(item.Id);
@@ -89,6 +91,29 @@ namespace GxPress.Repository.Implement.Category
             categoryName = string.IsNullOrEmpty(categoryName) ? $"{result.Name}" : $"{result.Name}/{categoryName}";
             return await GetCategoryParentAsync(result.ParentId, categoryName);
         }
-
+        /// <summary>
+        /// 内容导航分类
+        /// </summary>
+        /// <param name="typeValue"></param>
+        /// <returns></returns>
+        public async Task<IEnumerable<CategoryResult>> GetCategoryAllAsync(int typeValue = 0)
+        {
+            var categoryAll = await GetAllAsync(typeValue);
+            var categoryResults = categoryAll.Where(n => n.ParentId == 0).Select(n => _mapper.Map<CategoryResult>(n)).ToList();
+            foreach (var item in categoryResults)
+            {
+                item.IsChildren = categoryAll.Any(n => n.ParentId == item.Id);
+                item.Children = categoryAll.Where(n => n.ParentId == item.Id).Select(n => _mapper.Map<CategoryResult>(n)).ToList();
+                if (item.IsChildren)
+                {
+                    foreach (var chidren in item.Children)
+                    {
+                        chidren.IsChildren = categoryAll.Any(n => n.ParentId == chidren.Id);
+                        chidren.Children = categoryAll.Where(n => n.ParentId == chidren.Id).Select(n => _mapper.Map<CategoryResult>(n)).ToList();
+                    }
+                }
+            }
+            return categoryResults;
+        }
     }
 }

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

@@ -683,5 +683,36 @@ namespace GxPress.Repository.Implement.Media
             var connection = database.GetConnection();
             return await connection.QueryAsync<MediaCathedraResult>(sql);
         }
+
+        /// <summary>
+        /// 导航内容
+        /// </summary>
+        /// <returns></returns>
+        public async Task<PagedList<MediaCathedraResult>> GetContentNavigationAsync(MediaContentNavigationRequest 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.MediaType), GxPress.EnumConst.AllTypeConst.Book.GetHashCode());
+            if (request.MediaIds.Count() > 0)
+                query.WhereIn(nameof(Entity.tede2.Media.Media.Id), request.MediaIds);
+            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;
+        }
     }
 }

+ 5 - 4
gx_api/GxPress/Repository/GxPress.Repository.Implement/Missive/MissiveRepository.cs

@@ -112,6 +112,7 @@ namespace GxPress.Repository.Implement.Missive
                 sb += $" AND a.UserId = {request.UserId} and b.MissiveType=2 and a.IsDelete=0";
             else
                 sb += $" AND a.UserId = {request.UserId} and a.IsDelete=0";
+            var missiveTypeValue = GxPress.EnumConst.AllTypeConst.Missive.GetHashCode();
             var sql = $@"SELECT 
                             a.*,(SELECT GROUP_CONCAT(SourceName Separator'、') from tede_user_middle where   MiddleType=30 and DataSourceId=a.MiddleId) as EnjoyUser,
                         (SELECT 
@@ -125,20 +126,20 @@ namespace GxPress.Repository.Implement.Missive
                             FROM
                                 tede_addressee
                             WHERE
-                                 SourceType={AllTypeConst.Missive.GetHashCode()} and 
+                                 SourceType={missiveTypeValue} and 
                                                             SourceId = a.MiddleId AND IsRead = 1) AS ReadCount,
                         (SELECT 
                                 COUNT(1)
                             FROM
                                 tede_addressee
-                            WHERE  SourceType={AllTypeConst.Missive.GetHashCode()} and 
+                            WHERE  SourceType={missiveTypeValue} and 
                                                             SourceId = a.MiddleId ) AS AllCount,
                         (SELECT 
                                 COUNT(1)
                             FROM
                                 tede_addressee
                             WHERE
-                                 SourceType={AllTypeConst.Missive.GetHashCode()} and 
+                                 SourceType={missiveTypeValue} and 
                                                             SourceId = a.MiddleId  AND IsRead = 1
                                     AND UserId =  {request.UserId}
                             LIMIT 0 , 1) AS IsRead, b.Title, b.UserName, b.MissiveType,b.SendUserId,b.Content,b.SourceId
@@ -157,7 +158,7 @@ namespace GxPress.Repository.Implement.Missive
                             tede_missive b ON a.MiddleId = b.Id  INNER JOIN
                             tede_user c ON c.Id = a.UserId
                         WHERE
-                            a.FolderType = 5 {sb} ";
+                            a.FolderType = {missiveTypeValue} {sb} ";
             var result = new PagedList<MissiveSearchResult>();
             var databaseType = _databaseTypeStr.ToEnum(DatabaseType.MySql);
             var database = new Database(databaseType, _connectionString);

+ 8 - 7
gx_api/GxPress/Repository/GxPress.Repository.Implement/NoticeRepository.cs

@@ -363,12 +363,13 @@ namespace GxPress.Repository.Implement
                 if (!searchList.Contains(request.SearchType))
                     sb += " AND a.ParentId = " + request.NoticeFolderId;
             }
+            var noticeTypeValue = GxPress.EnumConst.AllTypeConst.Notice.GetHashCode();
             var sql = $@"SELECT a.*,(SELECT GROUP_CONCAT(SourceName Separator'、') from tede_user_middle where MiddleType=10 and DataSourceId=a.MiddleId) as EnjoyUser,(SELECT 
                             COUNT(1)
                         FROM
                             tede_analyze
                         WHERE
-                              TypeValue = 2
+                              TypeValue = {noticeTypeValue}
                                 AND SourceId = a.MiddleId
                                 AND AnalyzeType = 1) AS PraiseCount,
                     (SELECT 
@@ -376,7 +377,7 @@ namespace GxPress.Repository.Implement
                         FROM
                             tede_analyze
                         WHERE
-                            UserId = {request.UserId} AND TypeValue = 2
+                            UserId = {request.UserId} AND TypeValue = {noticeTypeValue}
                                 AND SourceId = a.MiddleId
                                 AND AnalyzeType = 1
                         LIMIT 0 , 1) AS IsLaud,
@@ -386,13 +387,13 @@ namespace GxPress.Repository.Implement
                             tede_comment
                         WHERE
                             ArticleId =  a.MiddleId and pid=0
-                                AND TypeValue = 2) AS CommentCount,
+                                AND TypeValue = {noticeTypeValue}) AS CommentCount,
                     (SELECT 
                             COUNT(1)
                         FROM
                             tede_analyze
                         WHERE
-                            UserId = {request.UserId} AND TypeValue = 2
+                            UserId = {request.UserId} AND TypeValue = {noticeTypeValue}
                                 AND SourceId = a.MiddleId
                                 AND AnalyzeType = 4) AS RetransmissionCount,
                     (SELECT 
@@ -400,7 +401,7 @@ namespace GxPress.Repository.Implement
                         FROM
                             tede_analyze
                         WHERE
-                            UserId = {request.UserId} AND TypeValue = 2
+                            UserId = {request.UserId} AND TypeValue = {noticeTypeValue}
                                 AND SourceId = a.MiddleId
                                 AND AnalyzeType = 4
                         LIMIT 0 , 1) AS IsRetransmission,
@@ -409,7 +410,7 @@ namespace GxPress.Repository.Implement
                         FROM
                             tede_analyze
                         WHERE
-                            UserId = {request.UserId} AND TypeValue = 2
+                            UserId = {request.UserId} AND TypeValue = {noticeTypeValue}
                                 AND SourceId = a.MiddleId
                                 AND AnalyzeType = 4
                         LIMIT 0 , 1) AS IsCollect,
@@ -418,7 +419,7 @@ namespace GxPress.Repository.Implement
                         FROM
                             tede_analyze
                         WHERE
-                            UserId = {request.UserId} AND TypeValue = 2
+                            UserId = {request.UserId} AND TypeValue = {noticeTypeValue}
                                 AND SourceId = a.MiddleId
                                 AND AnalyzeType = 4) AS CollectCount,
                     (SELECT 

+ 9 - 2
gx_api/GxPress/Repository/GxPress.Repository.Interface/Category/CategoryRepository.cs

@@ -2,13 +2,14 @@
 using System.Collections.Generic;
 using System.Threading.Tasks;
 using Datory;
+using GxPress.Result.Category;
 
 namespace GxPress.Repository.Interface.Category
 {
     /// <summary>
     /// 类别
     /// </summary>
-    public interface ICategoryRepository:IRepository
+    public interface ICategoryRepository : IRepository
     {
         Task<Entity.tede2.Category.Category> GetAsync(int id);
 
@@ -30,8 +31,14 @@ namespace GxPress.Repository.Interface.Category
         /// </summary>
         /// <param name="parentId"></param>
         /// <returns></returns>
-        Task<IEnumerable<Entity.tede2.Category.Category>> GetCategoryChildrenAsync(int parentId,int typeValue);
+        Task<IEnumerable<Entity.tede2.Category.Category>> GetCategoryChildrenAsync(int parentId, int typeValue);
 
         Task<string> GetCategoryParentAsync(int id, string categoryName);
+        /// <summary>
+        /// 内容导航分类
+        /// </summary>
+        /// <param name="typeValue"></param>
+        /// <returns></returns>
+        Task<IEnumerable<CategoryResult>> GetCategoryAllAsync(int typeValue = 0);
     }
 }

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

@@ -105,5 +105,10 @@ namespace GxPress.Repository.Interface.Media
         /// </summary>
         /// <returns></returns>
         Task<IEnumerable<MediaCathedraResult>> GetUserLikeAsync();
+         /// <summary>
+        /// 导航内容
+        /// </summary>
+        /// <returns></returns>
+       Task<PagedList<MediaCathedraResult>> GetContentNavigationAsync(MediaContentNavigationRequest request);
     }
 }

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

@@ -135,7 +135,7 @@ namespace GxPress.Service.Implement.AppHomePage
             var mediaLableIdRequest = new MediaLableIdRequest();
             mediaLableIdRequest.Page = request.Page;
             mediaLableIdRequest.PerPage = request.PerPage;
-            var ids = await systemLableMediaRepository.GetMediaIdsAsync(systemLabel.Id,0);
+            var ids = await systemLableMediaRepository.GetMediaIdsAsync(systemLabel.Id, 0);
             mediaLableIdRequest.Ids = ids.ToList();
             return await mediaRepository.GetMediaByLableIdAsync(mediaLableIdRequest);
         }
@@ -278,6 +278,18 @@ namespace GxPress.Service.Implement.AppHomePage
 
             return result;
         }
-
+        /// <summary>
+        /// 导航内容分页
+        /// </summary>
+        /// <returns></returns>
+        public async Task<PagedList<MediaCathedraResult>> GetContentNavigationAsync(MediaContentNavigationRequest request)
+        {
+            if (request.CategoryId > 0)
+            {
+                var mediaIds = await systemLableMediaRepository.GetMediaIdsAsync(request.CategoryId, 1);
+                request.MediaIds = mediaIds.ToList();
+            }
+            return await mediaRepository.GetContentNavigationAsync(request);
+        }
     }
 }

+ 1 - 1
gx_api/GxPress/Service/GxPress.Service.Implement/Notice/NoticeService.cs

@@ -106,7 +106,7 @@ namespace GxPress.Service.Implement.Notice
             //修改middle的阅读
             // await _middleRepository.UpdateAsync(Q.Set(nameof(Entity.Middle.Middle.IsRead), true).Where(nameof(Entity.Middle.Middle.UserId), userId).Where(nameof(Entity.Middle.Middle.MiddleId), id).Where(nameof(Entity.Middle.Middle.FolderType), 1));
             var analyzeRequest = new Request.App.Analyze.AnalyzeRequest();
-            analyzeRequest.TypeValue = 2;
+            analyzeRequest.TypeValue = GxPress.EnumConst.AllTypeConst.Notice.GetHashCode();
             analyzeRequest.AnalyzeType = 1;
             analyzeRequest.SourceId = id;
             analyzeRequest.UserId = userId;

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

@@ -56,5 +56,10 @@ namespace GxPress.Service.Interface.AppHomePage
         /// <param name="request"></param>
         /// <returns></returns>
         Task<PagedList<MediaCathedraResult>> GetDayWeBookAsync(MediaDayWeBookRequest request);
+         /// <summary>
+        /// 导航内容分页
+        /// </summary>
+        /// <returns></returns>
+        Task<PagedList<MediaCathedraResult>> GetContentNavigationAsync(MediaContentNavigationRequest request);
     }
 }