李昊 4 years ago
parent
commit
e27ce8cf4c

+ 39 - 0
gx_api/GxPress/Api/GxPress.Api/AppControllers/ReplyController.cs

@@ -0,0 +1,39 @@
+using Microsoft.AspNetCore.Mvc;
+using GxPress.Service.Interface.Reply;
+using System.Threading.Tasks;
+using System.Collections.Generic;
+using GxPress.Request.Reply;
+using GxPress.Result.Reply;
+using GxPress.Auth;
+using Microsoft.AspNetCore.Authorization;
+
+namespace GxPress.Api.AppControllers
+{
+    /// <summary>
+    /// 回复我的
+    /// </summary>
+    [Route("api/app/reply")]
+    [ApiController]
+    [Authorize]
+    public class ReplyController : Controller
+    {
+        private readonly IReplyService replyService;
+        private readonly ILoginContext _loginContext;
+        public ReplyController(IReplyService replyService, ILoginContext _loginContext)
+        {
+            this.replyService = replyService;
+            this._loginContext = _loginContext;
+        }
+        /// <summary>
+        /// 获取回复我的笔记或者话题
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        [HttpPost("list")]
+        public async Task<IEnumerable<ReplyResult>> GetReplyNoteOrTopicResults(ReplyRequest request)
+        {
+            request.UserId = _loginContext.AccountId;
+            return await replyService.GetReplyNoteOrTopicResults(request);
+        }
+    }
+}

+ 24 - 0
gx_api/GxPress/Model/GxPress.Request/Reply/ReplyRequest.cs

@@ -0,0 +1,24 @@
+namespace GxPress.Request.Reply
+{
+    /// <summary>
+    /// 回复查询
+    /// </summary>
+    public class ReplyRequest
+    {
+        /// <summary>
+        /// 搜索
+        /// </summary>
+        /// <value></value>
+        public string KeyWord { get; set; }
+        /// <summary>
+        /// 用户ID
+        /// </summary>
+        /// <value></value>
+        public int UserId { get; set; }
+        /// <summary>
+        /// 0 回复我的 1 我回复的
+        /// </summary>
+        /// <value></value>
+        public int TypeValue { get; set; }
+    }
+}

+ 78 - 0
gx_api/GxPress/Model/GxPress.Result/Reply/ReplyResult.cs

@@ -0,0 +1,78 @@
+using System;
+
+namespace GxPress.Result.Reply
+{
+    public class ReplyResult
+    {
+        /// <summary>
+        /// 评论ID
+        /// </summary>
+        /// <value></value>
+        public int Id { get; set; }
+        /// <summary>
+        /// 话题或者笔记ID
+        /// </summary>
+        /// <value></value>
+        public int ArticleId { get; set; }
+        /// <summary>
+        /// 评论内容
+        /// </summary>
+        /// <value></value>
+        public string CommentContent { get; set; }
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <value></value>
+        public int Pid { get; set; }
+        /// <summary>
+        /// 类型
+        /// </summary>
+        /// <value></value>
+        public int TypeValue { get; set; }
+        /// <summary>
+        /// 话题或者笔记的标题
+        /// </summary>
+        /// <value></value>
+        public string Title { get; set; }
+        /// <summary>
+        /// 话题或者笔记的内容
+        /// </summary>
+        /// <value></value>
+        public string Content { get; set; }
+        /// <summary>
+        /// 回复人姓名
+        /// </summary>
+        /// <value></value>
+        public string UserName { get; set; }
+        /// <summary>
+        /// 回复人头像
+        /// </summary>
+        /// <value></value>
+        public string AvatarUrl { get; set; }
+        /// <summary>
+        /// 回复时间
+        /// </summary>
+        /// <value></value>
+        public DateTime ? CreatedDate { get; set; }
+        /// <summary>
+        /// 回复人姓名
+        /// </summary>
+        /// <value></value>
+        public int UserId { get; set; }
+        /// <summary>
+        /// 是否话题
+        /// </summary>
+        /// <value></value>
+        public bool IsTopic { get; set; }
+        /// <summary>
+        /// 当前用户姓名
+        /// </summary>
+        /// <value></value>
+        public string Name { get; set; }
+        /// <summary>
+        /// 备注
+        /// </summary>
+        /// <value></value>
+        public string Remark { get; set; }
+    }
+}

+ 102 - 0
gx_api/GxPress/Service/GxPress.Service.Implement/Reply/ReplyService.Note.Topic.cs

@@ -0,0 +1,102 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using Dapper;
+using Datory;
+using GxPress.Common.Tools;
+using GxPress.EnumConst;
+using GxPress.Request.Reply;
+using GxPress.Result;
+using GxPress.Result.Reply;
+using Newtonsoft.Json;
+namespace GxPress.Service.Implement.Reply
+{
+    /// <summary>
+    /// 回复笔记或者话题
+    /// </summary>
+    public partial class ReplyService
+    {
+        /// <summary>
+        /// 获取回复我的笔记或者话题
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        public async Task<IEnumerable<ReplyResult>> GetReplyNoteOrTopicResults(ReplyRequest request)
+        {
+            var noteConstValue = AllTypeConst.Note.GetHashCode();
+            string sqlStr = string.Empty;
+            if (!string.IsNullOrEmpty(request.KeyWord))
+            {
+                sqlStr = $@"AND (a.Content LIKE '%{request.KeyWord}%'
+                    OR b.Title LIKE '%{request.KeyWord}%'
+                    OR b.Content LIKE '%{request.KeyWord}%' or c.Name like '%{request.KeyWord}%')";
+            }
+            if (request.TypeValue == 0)
+                sqlStr = $@" and b.UserId = {request.UserId}";
+            else
+                sqlStr = $@" and a.UserId = {request.UserId}";
+            string sql = $@"
+                                SELECT 
+                                        a.Id,
+                                        a.UserId,
+                                        a.ArticleId,
+                                        a.Content as CommentContent,
+                                        a.Pid,
+                                        a.TypeValue,
+                                        b.Title,
+                                        b.Content,
+                                        b.CreatedDate,
+                                        b.IsTopic,
+                                        c.Name,
+                                        c.AvatarUrl,
+                                        d.Name
+                                    FROM
+                                        tede_comment a
+                                            INNER JOIN
+                                        tede_note b ON a.ArticleId = b.Id
+                                            INNER JOIN
+                                        tede_user c ON c.Id = a.UserId
+                                            INNER JOIN
+                                        tede_user d ON d.Id = b.UserId
+                                    WHERE
+                                        1=1 AND a.TypeValue ={noteConstValue}
+                                            AND b.IsDelete = 0
+                                            {sqlStr}
+                                    ORDER BY a.CreatedDate DESC
+          ";
+            var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
+            var connection = database.GetConnection();
+            return await connection.QueryAsync<ReplyResult, Entity.Note.Note, Entity.User, Entity.User, ReplyResult>(sql,
+                        (result, note, user, userModel) =>
+                        {
+                            result.UserName = user != null ? user.Name : "";
+                            result.AvatarUrl = StringUtils.AddDomainMin(user.AvatarUrl);
+                            result.IsTopic = note.IsTop;
+                            result.Title = string.IsNullOrEmpty(note.Title) ? GetTitleText(note.Content) : note.Title; ;
+                            //result.Content = note.Content;
+                            result.CreatedDate = note.CreatedDate;
+                            result.Name = userModel.Name;
+                            result.Remark = result.IsTopic ? AllTypeConst.Topic.GetDescriptionOriginal() : AllTypeConst.Note.GetDescriptionOriginal();
+                            return result;
+                        }, splitOn: "Id,Title,Name,Name");
+
+        }
+
+        public string GetTitleText(string content)
+        {
+            var data = JsonConvert.DeserializeObject<List<CollectionContentJsonData>>(content);
+            int i = 0;
+            foreach (var item in data)
+            {
+                if (item.Type == AllTypeConst.Text.GetHashCode() && i == 0)
+                    return item.Text;
+                else if (item.Type == AllTypeConst.Image.GetHashCode())
+                    return "[图片]";
+                else if (item.Type == AllTypeConst.File.GetHashCode())
+                    return "[附件]";
+                else
+                    return "[附件]";
+            }
+            return string.Empty;
+        }
+    }
+}

+ 12 - 0
gx_api/GxPress/Service/GxPress.Service.Implement/Reply/ReplyService.cs

@@ -0,0 +1,12 @@
+using GxPress.Service.Interface.Reply;
+
+namespace GxPress.Service.Implement.Reply
+{
+    /// <summary>
+    /// 回复
+    /// </summary>
+    public partial class ReplyService : IReplyService
+    {
+    
+    }
+}

+ 17 - 0
gx_api/GxPress/Service/GxPress.Service.Interface/Reply/IReplyService.cs

@@ -0,0 +1,17 @@
+using System.Collections.Generic;
+using System.Threading.Tasks;
+using GxPress.Request.Reply;
+using GxPress.Result.Reply;
+
+namespace GxPress.Service.Interface.Reply
+{
+    public interface IReplyService : IService
+    {
+        /// <summary>
+        /// 获取回复我的笔记或者话题
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        Task<IEnumerable<ReplyResult>> GetReplyNoteOrTopicResults(ReplyRequest request);
+    }
+}