李昊 4 роки тому
батько
коміт
1fde4c5d42

+ 16 - 2
gx_api/GxPress/Api/GxPress.Api/AppControllers/NoteController.cs

@@ -1,6 +1,7 @@
 using System.Threading.Tasks;
 using GxPress.Auth;
 using GxPress.Common.Page;
+using GxPress.Repository.Interface.Note;
 using GxPress.Request.App.Note;
 using GxPress.Result.App.Note;
 using GxPress.Service.Interface.Note;
@@ -21,12 +22,13 @@ namespace GxPress.Api.AppControllers
         private readonly ILogger<NoteController> _logger;
         private readonly INoteService _noteService;
         private readonly ILoginContext _loginContext;
-
-        public NoteController(ILogger<NoteController> logger, INoteService noteService, ILoginContext loginContext)
+        private readonly INoteRepository noteRepository;
+        public NoteController(ILogger<NoteController> logger, INoteService noteService, ILoginContext loginContext, INoteRepository noteRepository)
         {
             _logger = logger;
             _noteService = noteService;
             _loginContext = loginContext;
+            this.noteRepository = noteRepository;
         }
 
         /// <summary>
@@ -98,5 +100,17 @@ namespace GxPress.Api.AppControllers
         /// <returns></returns>
         [HttpDelete("{id}")]
         public async Task<bool> DeleteAsync(int id) => await _noteService.DeleteAsync(id, _loginContext.AccountId);
+
+        /// <summary>
+        /// 笔记没有文件夹分页
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("list")]
+        public async Task<PagedList<NoteNotFolderPageResult>> GetNoteNotFolderPageResult(NoteSearchPageListRequest request)
+        {
+            request.UserId = _loginContext.AccountId;
+            return await _noteService.GetNoteNotFolderPageResult(request);
+        }
     }
 }

+ 1 - 1
gx_api/GxPress/Api/GxPress.Api/AppControllers/TopicController.cs

@@ -87,7 +87,7 @@ namespace GxPress.Api.AppControllers
 
 
         /// <summary>
-        /// app话题分页列表
+        /// app笔记话题分页列表
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>

+ 11 - 0
gx_api/GxPress/Api/GxPress.Api/WebControllers/WebNoteController.cs

@@ -125,5 +125,16 @@ namespace GxPress.Api.WebControllers
             request.UserId = _loginContext.AccountId;
             return await noteRepository.GetTopicNoteAsync(request);
         }
+        /// <summary>
+        /// 笔记没有文件夹分页
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("list")]
+        public async Task<PagedList<NoteNotFolderPageResult>> GetNoteNotFolderPageResult(NoteSearchPageListRequest request)
+        {
+            request.UserId = _loginContext.AccountId;
+            return await _noteService.GetNoteNotFolderPageResult(request);
+        }
     }
 }

+ 5 - 1
gx_api/GxPress/Model/GxPress.Result/App/Note/NoteDetailResult.cs

@@ -57,7 +57,11 @@ namespace GxPress.Result.App.Note
         /// 数据
         /// </summary>
         public List<ContentJsonData> Data { get; set; }
-
+        /// <summary>
+        /// 文件数量
+        /// </summary>
+        /// <value></value>
+        public int FileCount { get; set; }
         /// <summary>
         /// 评论数量
         /// </summary>

+ 106 - 0
gx_api/GxPress/Model/GxPress.Result/App/Note/NoteResult.cs

@@ -1,3 +1,6 @@
+using System.Collections.Generic;
+using GxPress.Result.Media;
+
 namespace GxPress.Result.App.Note
 {
     /// <summary>
@@ -86,4 +89,107 @@ namespace GxPress.Result.App.Note
         /// <value></value>
         public bool IsCollect { get; set; }
     }
+    /// <summary>
+    /// 笔记分页没有文件夹
+    /// </summary>
+    public class NoteNotFolderPageResult
+    {
+        /// <summary>
+        /// 笔记id
+        /// </summary>
+        /// <value></value>
+        public int Id { get; set; }
+        /// <summary>
+        /// 标题
+        /// </summary>
+        /// <value></value>
+        public string Title { get; set; }
+        /// <summary>
+        /// 媒体ID 获取摘录
+        /// </summary>
+        /// <value></value>
+        public int MediaId { get; set; }
+
+        /// <summary>
+        /// 数据类型 1 没有 2 图 3 文件
+        /// </summary>
+        public int DataType { get; set; }
+        /// <summary>
+        /// 文件数量
+        /// </summary>
+        /// <value></value>
+        public int FileCount { get; set; }
+        /// <summary>
+        /// 数据
+        /// </summary>
+        public List<ContentJsonData> Data { get; set; }
+        /// <summary>
+        /// 是否摘录
+        /// </summary>
+        /// <value></value>
+        public bool IsExtract { get; set; }
+
+        /// <summary>
+        /// 笔记摘录
+        /// </summary>
+        /// <value></value>
+        public MediaNoteResult MediaNoteResult { get; set; }
+        /// <summary>
+        /// 内容
+        /// </summary>
+        /// <value></value>
+        public string Content { get; set; }
+
+        /// <summary>
+        /// 创建时间
+        /// </summary>
+        /// <value></value>
+        public string CreatedDate { get; set; }
+        /// <summary>
+        /// 用户姓名
+        /// </summary>
+        /// <value></value>
+        public string UserName { get; set; }
+        /// <summary>
+        /// 用户Id
+        /// </summary>
+        /// <value></value>
+        public string UserId { get; set; }
+        /// <summary>
+        /// 头像
+        /// </summary>
+        /// <value></value>
+        public string AvatarUrl { get; set; }
+
+        /// <summary>
+        /// 点赞数量
+        /// </summary>
+        /// <value></value>
+        public int PraiseCount { get; set; }
+        /// <summary>
+        /// 是否点赞
+        /// </summary>
+        /// <value></value>
+        public bool IsPraise { get; set; }
+        /// <summary>
+        /// 评论数量
+        /// </summary>
+        /// <value></value>
+        public int CommentCount { get; set; }
+        /// <summary>
+        /// 转发数量
+        /// </summary>
+        /// <value></value>
+        public int RetransmissionCount { get; set; }
+        /// <summary>
+        /// 是否转发
+        /// </summary>
+        /// <value></value>
+        public bool IsRetransmission { get; set; }
+        /// <summary>
+        /// 是否收藏
+        /// </summary>
+        /// <value></value>
+        public bool IsCollect { get; set; }
+    }
 }

+ 105 - 1
gx_api/GxPress/Repository/GxPress.Repository.Implement/Note/NoteRepository.cs

@@ -573,7 +573,111 @@ namespace GxPress.Repository.Implement.Note
                  await connection.ExecuteScalarAsync<int>(sql);
             return result;
         }
+        /// <summary>
+        /// 笔记没有文件夹分页
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        public async Task<PagedList<NoteNotFolderPageResult>> GetNoteNotFolderPageResult(NoteSearchPageListRequest request)
+        {
+            var sqlValue = "";
+            if (!string.IsNullOrEmpty(request.SearchKey))
+            {
+                sqlValue += $" and (a.Title like '%{request.SearchKey}%' or a.Content like '%{request.SearchKey}%')";
+            }
+            var noteConstValue = GxPress.EnumConst.AllTypeConst.Note.GetHashCode();
+            var sql = $@"SELECT 
+                                a.Id,
+                                a.Title,
+                                a.Content,
+                                a.UserId,
+                                a.CreatedDate,
+                                a.MediaId,
+                                (SELECT 
+                                        COUNT(1)
+                                    FROM
+                                        tede_analyze
+                                    WHERE
+                                        UserId = {request.UserId} AND TypeValue = {noteConstValue}
+                                            AND SourceId = a.Id
+                                            AND AnalyzeType = 1) AS PraiseCount,
+                                (SELECT 
+                                        COUNT(1)
+                                    FROM
+                                        tede_analyze
+                                    WHERE
+                                        UserId = {request.UserId} AND TypeValue = {noteConstValue}
+                                            AND SourceId = a.Id
+                                            AND AnalyzeType = 1
+                                    LIMIT 0 , 1) AS IsPraise,
+                                (SELECT 
+                                        COUNT(1)
+                                    FROM
+                                        tede_comment
+                                    WHERE
+                                        UserId = {request.UserId} AND ArticleId = a.Id
+                                            AND TypeValue = {noteConstValue}) AS CommentCount,
+                                (SELECT 
+                                        COUNT(1)
+                                    FROM
+                                        tede_analyze
+                                    WHERE
+                                       UserId = {request.UserId} AND TypeValue = {noteConstValue}
+                                            AND SourceId = a.Id
+                                            AND AnalyzeType = 4) AS RetransmissionCount,
+                                (SELECT 
+                                        COUNT(1)
+                                    FROM
+                                        tede_analyze
+                                    WHERE
+                                        UserId = {request.UserId} AND TypeValue = {noteConstValue}
+                                            AND SourceId = a.Id
+                                            AND AnalyzeType = 4
+                                    LIMIT 0 , 1) AS IsRetransmission,
+                                (SELECT 
+                                        COUNT(1)
+                                    FROM
+                                        tede_analyze
+                                    WHERE
+                                        UserId = {request.UserId} AND TypeValue = {noteConstValue}
+                                            AND SourceId = a.Id
+                                            AND AnalyzeType = 3
+                                    LIMIT 0 , 1) AS IsCollect,
+                                (SELECT 
+                                        COUNT(1)
+                                    FROM
+                                        tede_analyze
+                                    WHERE
+                                        UserId = {request.UserId} AND TypeValue = {noteConstValue}
+                                            AND SourceId = a.Id
+                                            AND AnalyzeType = 3) AS IsCollect
+                                            ,b.Name,b.AvatarUrl
+                            FROM
+                                tede_note a inner join tede_user b on a.UserId=b.Id
+                            WHERE
+                                a.UserId = {request.UserId} {sqlValue}
+                            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();
+            var result = new PagedList<NoteNotFolderPageResult>();
+            result.Items =
+                  await connection
+                      .QueryAsync<NoteNotFolderPageResult, User, NoteNotFolderPageResult>(sql,
+                        (result, user) =>
+                        {
+                            result.UserName = user == null ? "" : user.Name;
+                            result.AvatarUrl = user == null ? "" : StringUtils.AddDomainMin(user.AvatarUrl);
+                            return result;
+                        }, splitOn: "Id,Name");
+            sql = $@"SELECT count(1)
+                            FROM
+                                tede_note a inner join tede_user b on a.UserId=b.Id
+                            WHERE
+                                a.UserId = {request.UserId} {sqlValue}";
+            result.Total = await connection.ExecuteScalarAsync<int>(sql);
+            return result;
+        }
     }
-
 }
 

+ 3 - 3
gx_api/GxPress/Repository/GxPress.Repository.Implement/TopicRepository.cs

@@ -419,7 +419,7 @@ namespace GxPress.Repository.Implement
             return result.ToList();
         }
         /// <summary>
-        /// 新版 获取题列表
+        /// 新版 获取笔记话题列表
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
@@ -684,7 +684,7 @@ namespace GxPress.Repository.Implement
                                                                     FROM
                                                                         tede_middle
                                                                     WHERE
-                                                                        id = a.FolderId)
+                                                                        id = a.FolderId) and Id=a.UserId
                                                                     ))";
 
             if (request.TopicGroupIds.Count > 0)
@@ -739,7 +739,7 @@ namespace GxPress.Repository.Implement
                                                                         tede_middle
                                                                     WHERE
                                                                         id = a.FolderId)
-                                                                    AND id = {request.UserId}))";
+                                                                    AND id = a.UserId))";
 
             if (request.TopicGroupIds.Count > 0)
             {

+ 6 - 0
gx_api/GxPress/Repository/GxPress.Repository.Interface/Note/INoteRepository.cs

@@ -57,5 +57,11 @@ namespace GxPress.Repository.Interface.Note
         /// <param name="request"></param>
         /// <returns></returns>
         Task<PagedList<NoteTopicResult>> GetTopicNoteAsync(NoteSearchPageListRequest request);
+        /// <summary>
+        /// 笔记没有文件夹分页
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        Task<PagedList<NoteNotFolderPageResult>> GetNoteNotFolderPageResult(NoteSearchPageListRequest request);
     }
 }

+ 71 - 1
gx_api/GxPress/Service/GxPress.Service.Implement/Note/NoteService.cs

@@ -100,7 +100,7 @@ namespace GxPress.Service.Implement.Note
                         item.File = StringUtils.RemoveDomain(item.File);
                     //添加笔记
                     var note = new Entity.Note.Note
-                    { Title = request.Title, Content = JsonConvert.SerializeObject(noteContent), HtmlContent = request.HtmlContent, UserId = request.UserId, IsDelete = false, IsTopic = request.IsTopic, FolderId = request.FolderId, MediaId = request.MediaId, MediaType = request.MediaType, CatalogId = request.CatalogId, ChapterId = request.ChapterId};
+                    { Title = request.Title, Content = JsonConvert.SerializeObject(noteContent), HtmlContent = request.HtmlContent, UserId = request.UserId, IsDelete = false, IsTopic = request.IsTopic, FolderId = request.FolderId, MediaId = request.MediaId, MediaType = request.MediaType, CatalogId = request.CatalogId, ChapterId = request.ChapterId };
                     var noteId = await _noteRepository.InsertAsync(note);
                     //添加中间件
                     var middleInsertTypes = new MiddleInsertTypeRequest
@@ -562,6 +562,76 @@ namespace GxPress.Service.Implement.Note
             }
             return result;
         }
+
+        /// <summary>
+        /// 笔记没有文件夹分页
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        public async Task<PagedList<NoteNotFolderPageResult>> GetNoteNotFolderPageResult(NoteSearchPageListRequest request)
+        {
+            var result = await _noteRepository.GetNoteNotFolderPageResult(request);
+            foreach (var item in result.Items)
+            {
+                //是否摘录
+                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 == OldTextEditorTypeConst.Text.GetHashCode() && forCount == 1)
+                            //文本
+                            firstContent = jsonData.Text;
+                        else if (jsonData.TypeValue == OldTextEditorTypeConst.Text.GetHashCode() && forCount > 1)
+                            //文本
+                            continue;
+                        //图片
+                        else if (jsonData.TypeValue == OldTextEditorTypeConst.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> { OldTextEditorTypeConst.Text.GetHashCode(), OldTextEditorTypeConst.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;
+        }
     }
 
 }

+ 1 - 1
gx_api/GxPress/Service/GxPress.Service.Implement/Topic/TopicService.cs

@@ -225,7 +225,7 @@ namespace GxPress.Service.Implement.Topic
             return result;
         }
         /// <summary>
-        /// 获取话题列表
+        ///  新版 获取笔记话题列表
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>

+ 10 - 3
gx_api/GxPress/Service/GxPress.Service.Interface/Note/INoteService.cs

@@ -22,7 +22,7 @@ namespace GxPress.Service.Interface.Note
         /// <param name="id"></param>
         /// <param name="userId"></param>
         /// <returns></returns>
-        Task<NoteDetailResult> GetNoteDetailAsync(int id,int userId);
+        Task<NoteDetailResult> GetNoteDetailAsync(int id, int userId);
         /// <summary>
         /// 修改笔记
         /// </summary>
@@ -34,12 +34,19 @@ namespace GxPress.Service.Interface.Note
         /// </summary>
         /// <param name="id"></param>
         /// <returns></returns>
-        Task<bool> DeleteAsync(int id,int userId);
-         /// <summary>
+        Task<bool> DeleteAsync(int id, int userId);
+        /// <summary>
         ///查询个人摘录
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
         Task<PagedList<NoteUserExtractResult>> GetAllByUserId(NoteUserRequest request);
+
+        /// <summary>
+        /// 笔记没有文件夹分页
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        Task<PagedList<NoteNotFolderPageResult>> GetNoteNotFolderPageResult(NoteSearchPageListRequest request);
     }
 }