李昊 4 years ago
parent
commit
a10989bed3

+ 11 - 0
gx_api/GxPress/Api/GxPress.Api/AppControllers/NoteController.cs

@@ -113,6 +113,17 @@ namespace GxPress.Api.AppControllers
             return await _noteService.GetNoteNotFolderPageResult(request);
         }
         /// <summary>
+        /// 获取笔记/话题草稿分页
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("draft-list")]
+        public async Task<PagedList<NoteNotFolderPageResult>> NoteTopicDraftPageListAsync(NoteSearchPageListRequest request)
+        {
+            request.UserId = _loginContext.AccountId;
+            return await _noteService.NoteTopicDraftPageListAsync(request);
+        }
+        /// <summary>
         /// 笔记设置置顶
         /// </summary>
         /// <param name="id"></param>

+ 44 - 0
gx_api/GxPress/Repository/GxPress.Repository.Implement/Note/NoteRepository.cs

@@ -94,6 +94,50 @@ namespace GxPress.Repository.Implement.Note
             pagedList.Total = await NotePageListCountAsync(GetCollectionSqlCount(request));
             return pagedList;
         }
+        /// <summary>
+        /// 获取笔记/话题草稿分页
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        public async Task<PagedList<NoteNotFolderPageResult>> NoteTopicDraftPageListAsync(NoteSearchPageListRequest request)
+        {
+            request.TypeValue = request.TypeValue == 1 ? 1 : 0;
+            var pagedList = new PagedList<NoteNotFolderPageResult>();
+            var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypestr, DatabaseType.MySql);
+            var database = new Database(databaseType, _connectionString);
+            var connection = database.GetConnection();
+            var sqlStr = string.Empty;
+            if (!string.IsNullOrEmpty(request.SearchKey))
+                sqlStr = $@"AND (a.Title LIKE '%1%' OR a.Content LIKE '%1%')";
+            var sql = $@"SELECT 
+                            a.*, b.Name, b.AvatarUrl
+                        FROM
+                            tede_note a
+                                INNER JOIN
+                            tede_user b ON a.UserId = b.Id
+                        WHERE
+                            a.UserId ={request.UserId} AND a.IsDraft = 1 and a.IsTopic={ request.TypeValue}
+                            {sqlStr} limit {(request.Page - 1) * request.PerPage},{request.PerPage}";
+            var result =
+                await connection
+                    .QueryAsync<NoteNotFolderPageResult>(sql);
+            foreach (var item in result)
+            {
+                item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
+            }
+            pagedList.Items = result;
+            sql = $@"SELECT 
+                            count(1)
+                        FROM
+                            tede_note a
+                                INNER JOIN
+                            tede_user b ON a.UserId = b.Id
+                        WHERE
+                            a.UserId ={request.UserId} AND a.IsDraft = 1 and a.IsTopic={ request.TypeValue}
+                            {sqlStr}";
+            pagedList.Total = await NotePageListCountAsync(sql);
+            return pagedList;
+        }
 
         /// <summary>
         /// 集合

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

@@ -74,6 +74,12 @@ namespace GxPress.Repository.Interface.Note
         /// </summary>
         /// <param name="userId"></param>
         /// <returns></returns>
-        Task<IEnumerable<int>>  GetLatelyFolderIdAsync(int userId,bool isTopic);
+        Task<IEnumerable<int>> GetLatelyFolderIdAsync(int userId, bool isTopic);
+        /// <summary>
+        /// 获取笔记/话题草稿分页
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        Task<PagedList<NoteNotFolderPageResult>> NoteTopicDraftPageListAsync(NoteSearchPageListRequest request);
     }
 }

+ 72 - 0
gx_api/GxPress/Service/GxPress.Service.Implement/Note/NoteService.cs

@@ -149,6 +149,78 @@ namespace GxPress.Service.Implement.Note
             return true;
         }
         /// <summary>
+        /// 获取笔记/话题草稿分页
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        public async Task<PagedList<NoteNotFolderPageResult>> NoteTopicDraftPageListAsync(NoteSearchPageListRequest request)
+        {
+            var result = await _noteRepository.NoteTopicDraftPageListAsync(request);
+            foreach (var item in result.Items)
+            {
+                if (string.IsNullOrEmpty(item.FolderName))
+                    item.FolderName = "根目录";
+                // item.MiddleId = item.Id;
+                //是否摘录
+                if (item.MediaId > 0)
+                {
+                    item.IsExtract = true;
+                    var query = Q.NewQuery();
+                    query.Where(nameof(Entity.tede2.Media.Media.Id), item.MediaId);
+                    item.MediaNoteResult = await mediaRepository.GetAsync(query);
+                    if (item.MediaNoteResult != null)
+                        item.MediaNoteResult.ImageUrls = StringUtils.AddDomain(item.MediaNoteResult.ImageUrls);
+                }
+                if (string.IsNullOrWhiteSpace(item.Content))
+                    item.Content = "[]";
+                var contentJsonData = JsonConvert.DeserializeObject<List<ContentJsonData>>(item.Content);
+                foreach (var contentJsonDataItem in contentJsonData)
+                    contentJsonDataItem.File = StringUtils.AddDomain(contentJsonDataItem.File);
+                if (contentJsonData.Count == 0)
+                    item.DataType = 1;
+                item.Content = "";
+                if (contentJsonData.Count > 0)
+                {
+                    var imgData = new List<ContentJsonData>();
+                    var FileData = new List<ContentJsonData>();
+                    var forCount = 1;
+                    var firstContent = string.Empty;
+                    foreach (var jsonData in contentJsonData)
+                    {
+                        if (jsonData.TypeValue == AllTypeConst.Text.GetHashCode() && forCount == 1)
+                            //文本
+                            firstContent = jsonData.Text;
+                        else if (jsonData.TypeValue == AllTypeConst.Text.GetHashCode() && forCount > 1)
+                            //文本
+                            continue;
+                        //图片
+                        else if (jsonData.TypeValue == AllTypeConst.Image.GetHashCode() && FileData.Count == 0)
+                        {
+                            if (imgData.Count > 9)
+                                break;
+                            imgData.Add(jsonData);
+                        }
+                        //附件
+                        else
+                        {
+                            FileData.Add(jsonData);
+                            break;
+                        }
+                        forCount++;
+                    }
+                    item.Content = string.IsNullOrWhiteSpace(firstContent) ? "" : firstContent;
+                    if (imgData.Count > 0) { item.DataType = 2; item.Data = imgData; }
+                    else if (FileData.Count > 0) { item.DataType = 3; item.Data = FileData; }
+                    else item.DataType = 1;
+                    var contType = new List<int> { AllTypeConst.Text.GetHashCode(), AllTypeConst.Image.GetHashCode() };
+                    item.FileCount = contentJsonData.Count(n => !contType.Contains(n.Type));
+                }
+                if (item.Data == null || item.Data.Count == 0)
+                    item.Data = new List<ContentJsonData>();
+            }
+            return result;
+        }
+        /// <summary>
         /// 获取笔记分页
         /// </summary>
         /// <param name="request"></param>

+ 6 - 0
gx_api/GxPress/Service/GxPress.Service.Interface/Note/INoteService.cs

@@ -48,5 +48,11 @@ namespace GxPress.Service.Interface.Note
         /// <param name="request"></param>
         /// <returns></returns>
         Task<PagedList<NoteNotFolderPageResult>> GetNoteNotFolderPageResult(NoteSearchPageListRequest request);
+        /// <summary>
+        /// 获取笔记/话题草稿分页
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        Task<PagedList<NoteNotFolderPageResult>> NoteTopicDraftPageListAsync(NoteSearchPageListRequest request);
     }
 }