李昊 4 years ago
parent
commit
6eea85264c

+ 2 - 2
gx_api/GxPress/Api/GxPress.Api/AppControllers/CollectionController.cs

@@ -69,9 +69,9 @@ namespace GxPress.Api.AppControllers
         /// <param name="request"></param>
         /// <returns></returns>
         [HttpPost("list")]
-        public async Task<PagedList<CollectionListPageResult>> GetCollectionNoFolderPageListAsync(CollectionPageSearchRequest request)
+        public async Task<PagedList<CollectionNoFolderResult>> GetCollectionNoFolderPageListAsync(CollectionPageSearchRequest request)
         {
-            request.UserId=_loginContext.AccountId;
+            request.UserId = _loginContext.AccountId;
             return await _collectionService.GetCollectionNoFolderPageListAsync(request);
         }
     }

+ 2 - 2
gx_api/GxPress/Api/GxPress.Api/WebControllers/WebCollectionController.cs

@@ -68,9 +68,9 @@ namespace GxPress.Api.WebControllers
         /// <param name="request"></param>
         /// <returns></returns>
         [HttpPost("list")]
-        public async Task<PagedList<CollectionListPageResult>> GetCollectionNoFolderPageListAsync(CollectionPageSearchRequest request)
+        public async Task<PagedList<CollectionNoFolderResult>> GetCollectionNoFolderPageListAsync(CollectionPageSearchRequest request)
         {
-              request.UserId=_loginContext.AccountId;
+            request.UserId = _loginContext.AccountId;
             return await _collectionService.GetCollectionNoFolderPageListAsync(request);
         }
     }

+ 47 - 0
gx_api/GxPress/Model/GxPress.Result/App/Collection/CollectionListPageResult.cs

@@ -86,4 +86,51 @@ namespace GxPress.Result.App.Collection
         public int ReadCount { get; set; }
 
     }
+
+    /// <summary>
+    /// 收藏分页结果
+    /// </summary>
+    public class CollectionNoFolderResult
+    {
+        /// <summary>
+        /// 自增ID
+        /// </summary>
+        public int Id { get; set; }
+        /// <summary>
+        /// 收藏类型 1文章 2话题 3 收藏 4笔记 5通知 6站内信 7小组 8 会议详情
+        /// </summary>
+        public int CollectionType { get; set; }
+        /// <summary>
+        /// 数据类型ID
+        /// </summary>
+        public int CollectionDataId { get; set; }
+
+        /// <summary>
+        /// 标题
+        /// </summary>
+        public string Title { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        public CollectionContentJsonData Data { get; set; }
+
+        /// <summary>
+        /// 文件夹名称
+        /// </summary>
+        public string FolderName { get; set; }
+        /// <summary>
+        /// 文件夹Id
+        /// </summary>
+        public int FolderId { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <value></value>
+        public int MiddleId { get; set; }
+        /// <summary>
+        /// 来源的用户ID
+        /// </summary>
+        /// <value></value>
+        public int SourceUserId { get; set; }
+    }
 }

+ 29 - 9
gx_api/GxPress/Repository/GxPress.Repository.Implement/Collection/CollectionRepository.cs

@@ -268,16 +268,36 @@ namespace GxPress.Repository.Implement.Collection
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
-        public async Task<PagedList<CollectionListPageResult>> GetCollectionNoFolderPageListAsync(CollectionPageSearchRequest request)
+        public async Task<PagedList<CollectionNoFolderResult>> GetCollectionNoFolderPageListAsync(CollectionPageSearchRequest request)
         {
-            var result = new PagedList<CollectionListPageResult>();
-            var query = Q.NewQuery();
-            query.Where(nameof(Entity.Collection.UserId), request.UserId);
-            if (!string.IsNullOrEmpty(request.SearchKey))
-                query.WhereLike(nameof(Entity.Collection.Title), $"%{request.SearchKey}%");
-            result.Total = await _repository.CountAsync(query);
-            query.ForPage(request.Page, request.PerPage);
-            result.Items = await _repository.GetAllAsync<CollectionListPageResult>(query);
+            var result = new PagedList<CollectionNoFolderResult>();
+            var collectionContsValue = GxPress.EnumConst.AllTypeConst.Collect.GetHashCode();
+            var sql = $@"SELECT 
+                            a.Id,a.UserId,a.CollectionType,a.CollectionDataId,a.SourceUserId,(select FolderName from tede_middle where id=b.ParentId) as FolderName,b.ParentId
+                        FROM
+                            tede_collection a
+                                INNER JOIN
+                            tede_middle b ON a.Id = b.MiddleId AND b.FolderType ={collectionContsValue}
+                                AND a.UserId ={request.UserId} and b.IsDelete=0 order by a.CreatedDate desc limit {(request.Page - 1) * request.PerPage},{request.PerPage} ";
+            var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypestr, DatabaseType.MySql);
+            var database = new Database(databaseType, _connectionString);
+            var connection = database.GetConnection();
+            result.Items = await connection.QueryAsync<CollectionNoFolderResult, Entity.Middle.Middle, CollectionNoFolderResult>(sql,
+                    (result, middle) =>
+                    {
+                        result.MiddleId = result.Id;
+                        result.FolderId = middle != null ? middle.ParentId : 0;
+                        return result;
+                    },
+                    splitOn: "ParentId");
+            sql = $@"SELECT 
+                           count(1)
+                        FROM
+                            tede_collection a
+                                INNER JOIN
+                            tede_middle b ON a.Id = b.MiddleId AND b.FolderType ={collectionContsValue}
+                                AND a.UserId ={request.UserId} and b.IsDelete=0";
+            result.Total = await connection.ExecuteScalarAsync<int>(sql);
             return result;
         }
     }

+ 1 - 0
gx_api/GxPress/Repository/GxPress.Repository.Implement/GroupRepository.cs

@@ -267,6 +267,7 @@ namespace GxPress.Repository.Implement
             groupDetailResult.IsAdmin = groupDetail != null && groupUser != null ? groupDetail.UserId == groupUser.UserId : false;
             groupDetailResult.IsUser = groupUser != null ? groupUser.UserId == request.UserId : false;
             groupDetailResult.CreatedDate = groupDetail.CreatedDate;
+            groupDetailResult.QRCoder = StringUtils.AddDomain(groupDetailResult.QRCoder);
             return groupDetailResult;
         }
         /// <summary>

+ 1 - 1
gx_api/GxPress/Repository/GxPress.Repository.Interface/Collection/ICollectionRepository.cs

@@ -51,7 +51,7 @@ namespace GxPress.Repository.Interface.Collection
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
-      Task<PagedList<CollectionListPageResult>> GetCollectionNoFolderPageListAsync(CollectionPageSearchRequest request);
+      Task<PagedList<CollectionNoFolderResult>> GetCollectionNoFolderPageListAsync(CollectionPageSearchRequest request);
     }
 
 }

+ 3 - 1
gx_api/GxPress/Service/GxPress.Service.Implement/Collection/CollectionService.cs

@@ -243,9 +243,11 @@ namespace GxPress.Service.Implement.Collection
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
-        public async Task<PagedList<CollectionListPageResult>> GetCollectionNoFolderPageListAsync(CollectionPageSearchRequest request)
+        public async Task<PagedList<CollectionNoFolderResult>> GetCollectionNoFolderPageListAsync(CollectionPageSearchRequest request)
         {
             var result = await _collectionRepository.GetCollectionNoFolderPageListAsync(request);
+            if (result == null || result.Items == null)
+                return new PagedList<CollectionNoFolderResult>();
             foreach (var item in result.Items)
             {
                 item.Data = await StructCollectionData(item.CollectionDataId, item.CollectionType, item.SourceUserId);

+ 1 - 1
gx_api/GxPress/Service/GxPress.Service.Interface/Collection/ICollectionService.cs

@@ -22,6 +22,6 @@ namespace GxPress.Service.Interface.Collection
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
-        Task<PagedList<CollectionListPageResult>> GetCollectionNoFolderPageListAsync(CollectionPageSearchRequest request);
+        Task<PagedList<CollectionNoFolderResult>> GetCollectionNoFolderPageListAsync(CollectionPageSearchRequest request);
     }
 }