李昊 4 years ago
parent
commit
684875056d

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

@@ -2,7 +2,9 @@ using System.Threading.Tasks;
 using GxPress.Auth;
 using GxPress.Common.Page;
 using GxPress.Request.App.Note;
+using GxPress.Request.Web;
 using GxPress.Result.App.Note;
+using GxPress.Result.Web;
 using GxPress.Service.Interface.Note;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Mvc;
@@ -97,5 +99,17 @@ namespace GxPress.Api.WebControllers
         /// <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("extract")]
+        public async Task<PagedList<NoteUserExtractResult>> GetAllByUserId(NoteUserRequest request)
+        {
+            request.UserId = _loginContext.AccountId;
+            return await _noteService.GetAllByUserId(request);
+        }
     }
 }

+ 33 - 0
gx_api/GxPress/Model/GxPress.Request/Web/NoteRequest.cs

@@ -0,0 +1,33 @@
+namespace GxPress.Request.Web
+{
+     public class NoteRequest
+    {
+
+    }
+    /// <summary>
+    /// 查询用户摘要
+    /// </summary>
+    public class NoteUserRequest : Common.Page.PageParameter
+    {
+        /// <summary>
+        /// 用户ID
+        /// </summary>
+        /// <value></value>
+        public int UserId { get; set; }
+        /// <summary>
+        /// 媒体ID
+        /// </summary>
+        /// <value></value>
+        public int MediaId { get; set; }
+        /// <summary>
+        /// 目录ID
+        /// </summary>
+        /// <value></value>
+        public string CatalogId { get; set; }
+        /// <summary>
+        /// 章节ID
+        /// </summary>
+        /// <value></value>
+        public string ChapterId { get; set; }
+    }
+}

+ 98 - 0
gx_api/GxPress/Model/GxPress.Result/Web/NoteResult.cs

@@ -0,0 +1,98 @@
+namespace GxPress.Result.Web
+{
+    public class NoteResult
+    {
+
+    }
+    /// <summary>
+    /// 查询用户摘要
+    /// </summary>
+    public class NoteUserExtractResult
+    {
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <value></value>
+        public int Id { get; set; }
+        /// <summary>
+        /// 创建时间
+        /// </summary>
+        /// <value></value>
+        public string CreatedDate { get; set; }
+        /// <summary>
+        /// 标题
+        /// </summary>
+        /// <value></value>
+        public string Title { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <value></value>
+        public string Content { get; set; }
+        /// <summary>
+        /// 用户ID
+        /// </summary>
+        /// <value></value>
+        public string UserId { get; set; }
+        /// <summary>
+        /// 阅读数量
+        /// </summary>
+        /// <value></value>
+        public string ReadCount { get; set; }
+        /// <summary>
+        /// 内容
+        /// </summary>
+        /// <value></value>
+        public string HtmlContent { get; set; }
+        /// <summary>
+        /// 媒体ID
+        /// </summary>
+        /// <value></value>
+        public string MediaId { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <value></value>
+        public string CatalogId { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <value></value>
+        public string ChapterId { get; set; }
+        /// <summary>
+        /// 点赞数量
+        /// </summary>
+        /// <value></value>
+        public string PraiseCount { get; set; }
+        /// <summary>
+        /// 是否点赞
+        /// </summary>
+        /// <value></value>
+        public string IsPraise { get; set; }
+        /// <summary>
+        /// 评论数量
+        /// </summary>
+        /// <value></value>
+        public string CommentCount { get; set; }
+        /// <summary>
+        /// 转发数量
+        /// </summary>
+        /// <value></value>
+        public string RetransmissionCount { get; set; }
+        /// <summary>
+        /// 是否转发
+        /// </summary>
+        /// <value></value>
+        public string IsRetransmission { get; set; }
+        /// <summary>
+        /// 姓名
+        /// </summary>
+        /// <value></value>
+        public string Name { get; set; }
+        /// <summary>
+        /// 头像
+        /// </summary>
+        /// <value></value>
+        public string AvatarUrl { get; set; }
+    }
+}

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

@@ -9,7 +9,9 @@ using GxPress.Common.Tools;
 using GxPress.Entity;
 using GxPress.Repository.Interface.Note;
 using GxPress.Request.App.Note;
+using GxPress.Request.Web;
 using GxPress.Result.App.Note;
+using GxPress.Result.Web;
 using Microsoft.Extensions.Options;
 
 namespace GxPress.Repository.Implement.Note
@@ -326,6 +328,94 @@ namespace GxPress.Repository.Implement.Note
         /// <param name="id"></param>
         /// <returns></returns>
         public async Task<bool> DeleteAsync(int id) => await _repository.DeleteAsync(id);
+
+        /// <summary>
+        ///查询个人摘录
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        public async Task<PagedList<NoteUserExtractResult>> GetAllByUserId(NoteUserRequest request)
+        {
+            var result = new PagedList<NoteUserExtractResult>();
+            var sql = $@"SELECT 
+                            a.Id,
+                            a.CreatedDate,
+                            a.Title,
+                            a.Content,
+                            a.UserId,
+                            a.ReadCount,
+                            a.HtmlContent,
+                            a.MediaId,
+                            a.CatalogId,
+                            a.ChapterId,
+                            (SELECT 
+                                    COUNT(1)
+                                FROM
+                                    tede_analyze
+                                WHERE
+                                    UserId = {request.UserId} AND TypeValue = 3
+                                        AND SourceId = a.Id
+                                        AND AnalyzeType = 1) AS PraiseCount,
+                            (SELECT 
+                                    COUNT(1)
+                                FROM
+                                    tede_analyze
+                                WHERE
+                                    UserId = {request.UserId} AND TypeValue = 3
+                                        AND SourceId = a.Id
+                                        AND AnalyzeType = 1
+                                LIMIT 0 , 1) AS IsPraise,
+                            (SELECT 
+                                    COUNT(1)
+                                FROM
+                                    tede_comment
+                                WHERE
+                                    ArticleId = a.Id AND pid = 0
+                                        AND TypeValue = 3) AS CommentCount,
+                            (SELECT 
+                                    COUNT(1)
+                                FROM
+                                    tede_analyze
+                                WHERE
+                                    UserId = {request.UserId} AND TypeValue = 3
+                                        AND SourceId = a.Id
+                                        AND AnalyzeType = 4) AS RetransmissionCount,
+                            (SELECT 
+                                    COUNT(1)
+                                FROM
+                                    tede_analyze
+                                WHERE
+                                    UserId = {request.UserId} AND TypeValue = 3
+                                        AND SourceId = a.Id
+                                        AND AnalyzeType = 4
+                                LIMIT 0 , 1) AS IsRetransmission,
+                            b.Name,b.AvatarUrl
+                        FROM
+                            tede_note a
+                                INNER JOIN
+                            tede_user b ON a.UserId = b.Id
+                        WHERE
+                            UserId = {request.UserId}
+                        ORDER BY CreatedDate DESC";
+
+            var databaseType = StringUtils.ToEnum<DatabaseType>(_databaseTypestr, DatabaseType.MySql);
+            var database = new Database(databaseType, _connectionString);
+            var connection = database.GetConnection();
+            result.Items =
+                  await connection
+                      .QueryAsync<NoteUserExtractResult>(sql);
+            sql = $@"SELECT 
+                          count(1)
+                        FROM
+                            tede_note a
+                                INNER JOIN
+                            tede_user b ON a.UserId = b.Id
+                        WHERE
+                            UserId = {request.UserId}";
+            result.Total =
+                 await connection.ExecuteScalarAsync<int>(sql);
+            return result;
+        }
     }
 
 }

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

@@ -5,7 +5,9 @@ using System.Threading.Tasks;
 using Datory;
 using GxPress.Common.Page;
 using GxPress.Request.App.Note;
+using GxPress.Request.Web;
 using GxPress.Result.App.Note;
+using GxPress.Result.Web;
 
 namespace GxPress.Repository.Interface.Note
 {
@@ -43,5 +45,11 @@ namespace GxPress.Repository.Interface.Note
         Task<bool> DeleteAsync(int id);
 
         Task<bool> UpdateAsync(SqlKata.Query query);
+        /// <summary>
+        ///查询个人摘录
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        Task<PagedList<NoteUserExtractResult>> GetAllByUserId(NoteUserRequest request);
     }
 }

+ 16 - 3
gx_api/GxPress/Service/GxPress.Service.Implement/Note/NoteService.cs

@@ -27,6 +27,8 @@ using GxPress.Service.Interface.UserMiddle;
 using GxPress.Repository.Interface.RecordFolder;
 using GxPress.EnumConst;
 using GxPress.Request.App.Analyze;
+using GxPress.Result.Web;
+using GxPress.Request.Web;
 
 namespace GxPress.Service.Implement.Note
 {
@@ -534,9 +536,20 @@ namespace GxPress.Service.Implement.Note
             }
             return true;
         }
-
-
-
+        /// <summary>
+        /// 查询个人摘录
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        public async Task<PagedList<NoteUserExtractResult>> GetAllByUserId(NoteUserRequest request)
+        {
+            var result = await _noteRepository.GetAllByUserId(request);
+            foreach (var item in result.Items)
+            {
+                item.AvatarUrl = StringUtils.AddDomain(item.AvatarUrl);
+            }
+            return result;
+        }
     }
 
 }

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

@@ -4,7 +4,9 @@ using System.Text;
 using System.Threading.Tasks;
 using GxPress.Common.Page;
 using GxPress.Request.App.Note;
+using GxPress.Request.Web;
 using GxPress.Result.App.Note;
+using GxPress.Result.Web;
 
 namespace GxPress.Service.Interface.Note
 {
@@ -33,5 +35,11 @@ namespace GxPress.Service.Interface.Note
         /// <param name="id"></param>
         /// <returns></returns>
         Task<bool> DeleteAsync(int id,int userId);
+         /// <summary>
+        ///查询个人摘录
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        Task<PagedList<NoteUserExtractResult>> GetAllByUserId(NoteUserRequest request);
     }
 }