lihao 4 éve
szülő
commit
006333d99d

+ 18 - 58
gx_api/GxPress/Repository/GxPress.Repository.Implement/GroupRepository.cs

@@ -151,7 +151,15 @@ namespace GxPress.Repository.Implement
         /// <returns></returns>
         public async Task<IEnumerable<GroupUserFindResult>> FindGroupByGroupFolderId(GroupSearchRequest request)
         {
-            //var pagedList = new PagedList<GroupUserFindResult>();
+            var result = new List<GroupUserFindResult>();
+            result.AddRange(await GetGroupUserFindResult(true, request));
+            result.AddRange(await GetGroupUserFindResult(false, request));
+            foreach (var item in result)
+                item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
+            return result;
+        }
+        public async Task<IEnumerable<GroupUserFindResult>> GetGroupUserFindResult(bool IsTop, GroupSearchRequest request)
+        {
             var groupConst = AllTypeConst.Group.GetHashCode();
             var query = new SqlKata.Query("tede_Middle");
             query.LeftJoin("tede_group", "tede_group.Id", "tede_Middle.MiddleId");
@@ -164,9 +172,14 @@ namespace GxPress.Repository.Implement
             query.Where("tede_Middle.UserId", request.UserId);
             query.Where("tede_Middle.IsDelete", false);
             query.Where("tede_Middle.FolderType", groupConst);
-            query.Where("tede_Middle.IsTop", true);
-            query.OrderByDesc("tede_Middle.IsTop");
-            query.OrderByDesc("tede_Middle.LastModifiedDate");
+            query.Where("tede_Middle.IsTop", IsTop);
+            if (IsTop)
+            {
+                query.OrderByDesc("tede_Middle.IsTop");
+                query.OrderByDesc("tede_Middle.LastModifiedDate");
+            }
+            else
+                query.OrderByDesc("tede_group.LastModifiedDate");
             var topicSharingCountQuery = new SqlKata.Query("tede_group_user");
             topicSharingCountQuery.WhereColumns("tede_group_user.GroupId", "=", "tede_Middle.MiddleId");
             topicSharingCountQuery.AsCount();
@@ -202,61 +215,8 @@ namespace GxPress.Repository.Implement
             query.Select(fileCountQuery, "FileCount");
             query.Select("tede_Middle.{Id,IsTop,FolderName,AttributeValue}",
                           "tede_group.{Id as GroupId,AvatarUrl,Name as GroupName}");
-            var result = new List<GroupUserFindResult>();
-            result.AddRange(await middleRepository.GetAllAsync<GroupUserFindResult>(query));
-
-            query = new SqlKata.Query("tede_Middle");
-            query.LeftJoin("tede_group", "tede_group.Id", "tede_Middle.MiddleId");
-            if (request.GroupFolderId > 0)
-                query.Where("tede_Middle.ParentId", request.GroupFolderId);
-            if (!string.IsNullOrEmpty(request.Key))
-                query.Where(n => n.OrWhereLike("tede_Middle.FolderName", $"%request.Key%").OrWhereLike("tede_group.Name", $"%{request.Key}%"));
-            if (string.IsNullOrEmpty(request.Key) && request.GroupFolderId == 0)
-                query.Where("tede_Middle.ParentId", request.GroupFolderId);
-            query.Where("tede_Middle.UserId", request.UserId);
-            query.Where("tede_Middle.IsDelete", false);
-            query.Where("tede_Middle.FolderType", groupConst);
-            query.Where("tede_Middle.IsTop", false);
-            query.OrderByDesc("tede_group.LastModifiedDate");
-            topicSharingCountQuery = new SqlKata.Query("tede_group_user");
-            topicSharingCountQuery.WhereColumns("tede_group_user.GroupId", "=", "tede_Middle.MiddleId");
-            topicSharingCountQuery.AsCount();
-            query.Select(topicSharingCountQuery, "TopicSharingCount");
-            topicAllCountQuery = new SqlKata.Query("tede_topic");
-            topicAllCountQuery.WhereColumns("tede_topic.GroupId", "=", "tede_Middle.MiddleId");
-            topicAllCountQuery.Where("tede_topic.IsDraft", false);
-            topicAllCountQuery.AsCount();
-            query.Select(topicAllCountQuery, "TopicAllCount");
-            groupCountQuery = new SqlKata.Query("tede_middle as a");
-            groupCountQuery.WhereColumns("a.parentId", "=", "tede_Middle.Id");
-            groupCountQuery.AsCount();
-            query.Select(groupCountQuery, "GroupCount");
-            uReadTopicCountQuery = new SqlKata.Query("tede_topic");
-            uReadTopicCountQuery.WhereColumns("tede_topic.groupId", "=", "tede_group.Id");
-            groupUserQuery = new SqlKata.Query("tede_group_user");
-            groupUserQuery.WhereColumns("tede_group_user.groupId", "=", "tede_group.Id");
-            groupUserQuery.Where("tede_group_user.userId", request.UserId);
-            groupUserQuery.Select("ReadDate");
-            uReadTopicCountQuery.Where("tede_topic.LastModifiedDate", ">", groupUserQuery);
-            uReadTopicCountQuery.AsCount();
-            query.Select(uReadTopicCountQuery, "UReadTopicCount");
-            categoryNameQuery = new SqlKata.Query("tede_middle as a");
-            categoryNameQuery.WhereColumns("a.Id", "=", "tede_Middle.ParentId");
-            categoryNameQuery.Select("a.FolderName");
-            query.Select(categoryNameQuery, "CategoryName");
-            fileCountQuery = new SqlKata.Query("tede_group");
-            middleQuery = new SqlKata.Query("tede_Middle as a");
-            middleQuery.WhereColumns("a.ParentId", "=", "tede_Middle.Id");
-            middleQuery.Select("a.MiddleId");
-            fileCountQuery.WhereIn("tede_group.Id", middleQuery);
-            fileCountQuery.AsCount();
-            query.Select(fileCountQuery, "FileCount");
-            query.Select("tede_Middle.{Id,IsTop,FolderName,AttributeValue}",
-                          "tede_group.{Id as GroupId,AvatarUrl,Name as GroupName}");
-            result.AddRange(await middleRepository.GetAllAsync<GroupUserFindResult>(query));
-            return result;
+            return await middleRepository.GetAllAsync<GroupUserFindResult>(query);
         }
-
         /// <summary>
         /// 条数
         /// </summary>