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

+ 2 - 2
gx_api/GxPress/Repository/GxPress.Repository.Implement/Note/NoteRepository.cs

@@ -734,12 +734,12 @@ namespace GxPress.Repository.Implement.Note
         /// </summary>
         /// <param name="userId"></param>
         /// <returns></returns>
-        public async Task<IEnumerable<int>> GetLatelyFolderIdAsync(int userId)
+        public async Task<IEnumerable<int>> GetLatelyFolderIdAsync(int userId,bool isTopic)
         {
             var query = Q.NewQuery();
             query.Select(nameof(Entity.Note.Note.FolderId));
             query.Where(nameof(Entity.Note.Note.UserId), userId);
-            query.Where(nameof(Entity.Note.Note.IsTopic), true);
+            query.Where(nameof(Entity.Note.Note.IsTopic), isTopic);
             query.Where(nameof(Entity.Note.Note.FolderId), ">", 0);
             query.OrderByDesc(nameof(Entity.Note.Note.CreatedDate));
             return await _repository.GetAllAsync<int>(query);

+ 1 - 1
gx_api/GxPress/Repository/GxPress.Repository.Interface/Note/INoteRepository.cs

@@ -74,6 +74,6 @@ namespace GxPress.Repository.Interface.Note
         /// </summary>
         /// <param name="userId"></param>
         /// <returns></returns>
-        Task<IEnumerable<int>> GetLatelyFolderIdAsync(int userId);
+        Task<IEnumerable<int>>  GetLatelyFolderIdAsync(int userId,bool isTopic);
     }
 }

+ 30 - 5
gx_api/GxPress/Service/GxPress.Service.Implement/Middle/MiddleService.cs

@@ -295,7 +295,7 @@ namespace GxPress.Service.Implement.Middle
             try
             {
                 using TransactionScope transactionScope = new TransactionScope();
-                var middleIds = new List<int>();
+                var middleIds = request.MiddleIds;
                 //获取
                 await _middleRepository.GetAllMiddleChildrenByParentIdAsync(request.MiddleIds, middleIds);
                 request.MiddleIds = middleIds;
@@ -881,7 +881,7 @@ namespace GxPress.Service.Implement.Middle
         public async Task<List<MiddleSearchFolderResult>> GetLatelyTopicFolderAsync(int userId)
         {
             //获取用户最近发布的话题
-            var folderIds = await _noteRepository.GetLatelyFolderIdAsync(userId);
+            var folderIds = await _noteRepository.GetLatelyFolderIdAsync(userId, true);
             var query = Q.NewQuery();
             query.Where(nameof(Entity.Middle.Middle.AttributeValue), 2)
                 .Where(nameof(Entity.Middle.Middle.FolderType), AllTypeConst.Note.GetHashCode())
@@ -889,7 +889,20 @@ namespace GxPress.Service.Implement.Middle
                 .Where(nameof(Entity.Middle.Middle.IsDelete), false)
                 .WhereIn(nameof(Entity.Middle.Middle.Id), folderIds);
             query.WhereIn(nameof(Entity.Middle.Middle.RoleId), new List<int>() { 1, 3 });
-            var middles = await _middleRepository.FindAsync(query.OrderByDesc(nameof(Entity.Middle.Middle.CreatedDate)));
+            var models = await _middleRepository.FindAsync(query.OrderByDesc(nameof(Entity.Middle.Middle.CreatedDate)));
+            var middles = new List<Entity.Middle.Middle>();
+
+            foreach (var folderId in folderIds.Distinct())
+            {
+                foreach (var item in models)
+                {
+                    if (item.Id == folderId)
+                    {
+                        middles.Add(item);
+                        break;
+                    }
+                }
+            }
             List<MiddleSearchFolderResult> result = new List<MiddleSearchFolderResult>();
             foreach (var item in middles)
             {
@@ -925,7 +938,7 @@ namespace GxPress.Service.Implement.Middle
         public async Task<List<MiddleSearchFolderResult>> GetLatelyNoteFolderAsync(int userId)
         {
             //获取用户最近发布的话题
-            var folderIds = await _noteRepository.GetLatelyFolderIdAsync(userId);
+            var folderIds = await _noteRepository.GetLatelyFolderIdAsync(userId, false);
             var query = Q.NewQuery();
             query.Where(nameof(Entity.Middle.Middle.AttributeValue), 2)
                 .Where(nameof(Entity.Middle.Middle.FolderType), AllTypeConst.Note.GetHashCode())
@@ -933,7 +946,19 @@ namespace GxPress.Service.Implement.Middle
                 .Where(nameof(Entity.Middle.Middle.IsDelete), false)
                 .WhereIn(nameof(Entity.Middle.Middle.Id), folderIds);
             query.WhereIn(nameof(Entity.Middle.Middle.RoleId), new List<int>() { 2 });
-            var middles = await _middleRepository.FindAsync(query.OrderByDesc(nameof(Entity.Middle.Middle.CreatedDate)));
+            var models = await _middleRepository.FindAsync(query.OrderByDesc(nameof(Entity.Middle.Middle.CreatedDate)));
+            var middles = new List<Entity.Middle.Middle>();
+            foreach (var folderId in folderIds.Distinct())
+            {
+                foreach (var item in models)
+                {
+                    if (item.Id == folderId)
+                    {
+                        middles.Add(item);
+                        break;
+                    }
+                }
+            }
             List<MiddleSearchFolderResult> result = new List<MiddleSearchFolderResult>();
             foreach (var item in middles)
             {