李昊 il y a 4 ans
Parent
commit
2191259203

+ 13 - 3
gx_api/GxPress/Api/GxPress.Api/AppControllers/ReplyController.cs

@@ -6,6 +6,7 @@ using GxPress.Request.Reply;
 using GxPress.Result.Reply;
 using GxPress.Auth;
 using Microsoft.AspNetCore.Authorization;
+using System.Linq;
 
 namespace GxPress.Api.AppControllers
 {
@@ -30,10 +31,13 @@ namespace GxPress.Api.AppControllers
         /// <param name="request"></param>
         /// <returns></returns>
         [HttpPost("list")]
-        public async Task<IEnumerable<ReplyResult>> GetReplyNoteOrTopicResults(ReplyRequest request)
+        public async Task<ReplyPraiseCountResult> GetReplyNoteOrTopicResults(ReplyRequest request)
         {
             request.UserId = _loginContext.AccountId;
-            return await replyService.GetReplyResults(request);
+            var result = new ReplyPraiseCountResult();
+            result.Item = await replyService.GetReplyResults(request);
+            result.PraiseCount = 3;
+            return result;
         }
         /// <summary>
         /// 获取我收到的赞
@@ -44,7 +48,13 @@ namespace GxPress.Api.AppControllers
         public async Task<IEnumerable<ReplyResult>> GetPraiseAsync(ReplyRequest request)
         {
             request.UserId = _loginContext.AccountId;
-            return await replyService.GetPraiseAsync(request);
+            var result = new List<ReplyResult>();
+            result.AddRange(await replyService.GetNotePraiseAsync(request));
+            result.AddRange(await replyService.GetCommentPraiseAsync(request));
+            result.AddRange(await replyService.GetNoticePraiseAsync(request));
+            result.AddRange(await replyService.GetTopicPraiseAsync(request));
+            result.OrderByDescending(n => n.CreatedDate);
+            return result;
         }
     }
 }

+ 6 - 0
gx_api/GxPress/Model/GxPress.Entity/Analyze/Analyze.cs

@@ -40,5 +40,11 @@ namespace GxPress.Entity.Analyze
         /// <value></value>
         [DataColumn]
         public int SourceUserId { get; set; }
+        /// <summary>
+        /// 是否阅读
+        /// </summary>
+        /// <value></value>
+        [DataColumn]
+        public bool IsRead { get; set; }
     }
 }

+ 6 - 1
gx_api/GxPress/Model/GxPress.Result/Reply/ReplyResult.cs

@@ -1,7 +1,12 @@
 using System;
-
+using System.Collections.Generic;
 namespace GxPress.Result.Reply
 {
+    public class ReplyPraiseCountResult
+    {
+        public int PraiseCount{get;set;}
+        public IEnumerable<ReplyResult> Item { get; set; }
+    }
     public class ReplyResult
     {
         /// <summary>

+ 193 - 16
gx_api/GxPress/Service/GxPress.Service.Implement/Reply/ReplyService.Praise.cs

@@ -15,11 +15,11 @@ namespace GxPress.Service.Implement.Reply
     public partial class ReplyService
     {
         /// <summary>
-        /// 获取我收到的
+        /// 获取话题本
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
-        public async Task<IEnumerable<ReplyResult>> GetPraiseAsync(ReplyRequest request)
+        public async Task<IEnumerable<ReplyResult>> GetNotePraiseAsync(ReplyRequest request)
         {
             var noteConstValue = AllTypeConst.Note.GetHashCode();
             string sqlStr = string.Empty;
@@ -34,6 +34,7 @@ namespace GxPress.Service.Implement.Reply
                                         a.Id,
                                         a.SourceId,
                                         a.TypeValue,
+                                        a.IsRead,
                                         b.Title,
                                         b.Content,
                                         c.Name,
@@ -50,25 +51,201 @@ namespace GxPress.Service.Implement.Reply
                                         tede_user c ON c.Id = a.UserId
                                             INNER JOIN
                                         tede_user d ON d.Id = b.UserId
+                                            INNER JOIN
+                                        tede_middle e ON e.MiddleId = b.Id
                                     WHERE
-                                        b.UserId = {request.UserId} AND a.TypeValue ={noteConstValue}
-                                            AND b.IsDelete = 0 and a.AnalyzeType in(1,2) {sqlStr}
+                                        a.TypeValue = 4 AND e.IsDelete = 0
+                                            AND a.CommentId = 0
+                                            AND e.UserId = b.UserId
+                                            AND a.AnalyzeType = 1 AND b.UserId ={request.UserId}
+                                            {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.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.TypeValue==AllTypeConst.Note.GetHashCode() ? AllTypeConst.Topic.GetDescriptionOriginal() : AllTypeConst.Note.GetDescriptionOriginal();
-                            return result;
-                        }, splitOn: "Id,Title,Name,Name");
+            var result = await connection.QueryAsync<ReplyResult>(sql);
+            foreach (var item in result)
+            {
+                item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
+                item.CommentContent = "点赞了你的" + ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
+                item.Title = string.IsNullOrEmpty(item.Title) ? GetTitleText(item.Content) : item.Title;
+                item.Remark = ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
+                item.Content = string.Empty;
+            }
+            return result;
+        }
+        /// <summary>
+        /// 获取评论点赞
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        public async Task<IEnumerable<ReplyResult>> GetCommentPraiseAsync(ReplyRequest request)
+        {
+            var sqlStr = string.Empty;
+            if (!string.IsNullOrEmpty(request.KeyWord))
+            {
+                sqlStr = $@" AND (a.Content LIKE '%{request.KeyWord}%'
+                                OR c.Name LIKE '%{request.KeyWord}%')";
+            }
+            string sql = $@"
+                        SELECT 
+                            a.Id,
+                            a.Content,
+                            a.TypeValue,
+                            a.IsRead,
+                            b.UserId,
+                            c.Name AS UserName,
+                            c.AvatarUrl,
+                            c.Id AS UserId,
+                            d.Name,
+                            b.CreatedDate
+                        FROM
+                            tede_comment a
+                                INNER JOIN
+                            tede_analyze b ON a.Id = b.CommentId
+                                INNER JOIN
+                            tede_user c ON c.Id = b.UserId
+                                INNER JOIN
+                            tede_user d ON d.Id = a.UserId
+                        WHERE
+                            a.TypeValue IN ({AllTypeConst.Topic.GetHashCode()},{AllTypeConst.Notice.GetHashCode()},{AllTypeConst.Note.GetHashCode()})
+                                AND a.UserId = {request.UserId}
+                                {sqlStr}
+                                AND b.AnalyzeType = 2
+                        ORDER BY a.CreatedDate DESC";
+            var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
+            var connection = database.GetConnection();
+            var result = await connection.QueryAsync<ReplyResult>(sql);
+            foreach (var item in result)
+            {
+                item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
+                item.CommentContent = "点赞了你的" + ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
+                item.Title = item.Content;
+                item.IsComment = true;
+                item.Remark = ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
+            }
+            return result;
+        }
+        /// <summary>
+        /// 获取通知点赞
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        public async Task<IEnumerable<ReplyResult>> GetNoticePraiseAsync(ReplyRequest request)
+        {
+            var sqlStr = string.Empty;
+            if (!string.IsNullOrEmpty(request.KeyWord))
+            {
+                sqlStr = $@" AND (b.Title LIKE '%{request.KeyWord}%'
+                    OR b.Content LIKE '%{request.KeyWord}%'
+                                OR c.Name LIKE '%{request.KeyWord}%')";
+            }
+            string sql = $@"
+                          SELECT 
+                                    a.Id,
+                                    a.SourceId,
+                                    a.TypeValue,
+                                    a.IsRead,
+                                    b.Title,
+                                    b.Content,
+                                    c.Name,
+                                    c.AvatarUrl,
+                                    b.CreatedDate,
+                                    a.UserId,
+                                    d.Name AS UserName
+                                FROM
+                                    tede_analyze a
+                                        INNER JOIN
+                                    tede_notice b ON a.SourceId = b.Id
+                                        INNER JOIN
+                                    tede_user c ON c.Id = a.UserId
+                                        INNER JOIN
+                                    tede_user d ON d.Id = b.UserId
+                                        INNER JOIN
+                                    tede_middle e ON e.MiddleId = b.Id
+                                WHERE
+                                    b.UserId = {request.UserId} AND e.UserId = b.UserId
+                                        AND a.TypeValue ={AllTypeConst.Notice.GetHashCode()}
+                                        AND e.IsDelete = 0
+                                        AND a.CommentId = 0
+                                        AND a.AnalyzeType = 1 
+                                        {sqlStr}
+                        ORDER BY a.CreatedDate DESC";
+            var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
+            var connection = database.GetConnection();
+            var result = await connection.QueryAsync<ReplyResult>(sql);
+            foreach (var item in result)
+            {
+                item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
+                item.CommentContent = "点赞了你的" + ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
+                item.Title = string.IsNullOrEmpty(item.Title) ? GetTitleText(item.Content) : item.Title;
+                item.Remark = ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
+                item.Content = string.Empty;
+            }
+            return result;
+        }
+        /// <summary>
+        /// 获取话题点赞
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        public async Task<IEnumerable<ReplyResult>> GetTopicPraiseAsync(ReplyRequest request)
+        {
+            var sqlStr = string.Empty;
+            if (!string.IsNullOrEmpty(request.KeyWord))
+            {
+                sqlStr = $@" AND ( b.Title LIKE '%{request.KeyWord}%'
+                    OR b.Content LIKE '%{request.KeyWord}%'
+                                OR c.Name LIKE '%{request.KeyWord}%')";
+            }
+            string sql = $@"
+                          SELECT 
+                                    a.Id,
+                                    a.SourceId,
+                                    a.TypeValue,
+                                    a.IsRead,
+                                    b.Title,
+                                    b.Content,
+                                    c.Name as UserName,
+                                    c.AvatarUrl,
+                                    b.CreatedDate,
+                                    a.UserId,
+                                    d.Name,
+                                    g.Id as GroupId,
+                                    g.Name as GroupName
+                                FROM
+                                    tede_analyze a
+                                        INNER JOIN
+                                    tede_topic b ON a.SourceId = b.Id
+                                        INNER JOIN
+                                    tede_user c ON c.Id = a.UserId
+                                        INNER JOIN
+                                    tede_user d ON d.Id = b.UserId
+                                        INNER JOIN
+                                    tede_middle e ON e.MiddleId = b.Id
+                                        INNER JOIN
+                                    tede_group g ON g.Id = b.GroupId
+                                WHERE
+                                    a.TypeValue ={AllTypeConst.Topic.GetHashCode()} AND e.IsDelete = 0
+                                        AND a.CommentId = 0
+                                        AND e.UserId = b.UserId
+                                        AND a.AnalyzeType = 1
+                                        AND b.UserId = {request.UserId}
+                                        {sqlStr}
+                        ORDER BY a.CreatedDate DESC";
+            var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
+            var connection = database.GetConnection();
+            var result = await connection.QueryAsync<ReplyResult>(sql);
+            foreach (var item in result)
+            {
+                item.AvatarUrl = StringUtils.AddDomainMin(item.AvatarUrl);
+                item.CommentContent = "点赞了你的" + ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
+                item.Title = string.IsNullOrEmpty(item.Title) ? GetTitleText(item.Content) : item.Title;
+                item.Remark = ((AllTypeConst)item.TypeValue).GetDescriptionOriginal();
+                item.IsGroup = true;
+                item.Content = string.Empty;
+            }
+            return result;
         }
     }
 }

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

@@ -23,6 +23,7 @@ namespace GxPress.Service.Implement.Reply
         public async Task<IEnumerable<ReplyResult>> GetReplyResults(ReplyRequest request)
         {
             var result = new List<ReplyResult>();
+            //话题本
             result.AddRange(await GetReplyNoteOrTopicResults(request));
             //小组话题
             result.AddRange(await GetReplyGroupTopicResults(request));

+ 14 - 1
gx_api/GxPress/Service/GxPress.Service.Interface/Reply/IReplyService.cs

@@ -25,7 +25,7 @@ namespace GxPress.Service.Interface.Reply
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
-        Task<IEnumerable<ReplyResult>> GetPraiseAsync(ReplyRequest request);
+        Task<IEnumerable<ReplyResult>> GetNotePraiseAsync(ReplyRequest request);
 
         /// <summary>
         /// 获取我收到的评论
@@ -37,5 +37,18 @@ namespace GxPress.Service.Interface.Reply
         /// </summary>
         /// <returns></returns>
         Task<IEnumerable<ReplyResult>> GetMyReceiptCommentResult(int userId);
+        Task<IEnumerable<ReplyResult>> GetCommentPraiseAsync(ReplyRequest request);
+        /// <summary>
+        /// 获取通知点赞
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        Task<IEnumerable<ReplyResult>> GetNoticePraiseAsync(ReplyRequest request);
+        /// <summary>
+        /// 获取话题点赞
+        /// </summary>
+        /// <param name="request"></param>
+        /// <returns></returns>
+        Task<IEnumerable<ReplyResult>> GetTopicPraiseAsync(ReplyRequest request);
     }
 }