李昊 лет назад: 4
Родитель
Сommit
75f6f65aec

+ 2 - 1
gx_api/GxPress/Api/GxPress.Api/AppControllers/ReplyController.cs

@@ -36,7 +36,7 @@ namespace GxPress.Api.AppControllers
             request.UserId = _loginContext.AccountId;
             var result = new ReplyPraiseCountResult();
             result.Item = await replyService.GetReplyResults(request);
-            result.PraiseCount = 3;
+            result.PraiseCount = await replyService.GetUReadPraiseCountAsync(request.UserId);
             return result;
         }
         /// <summary>
@@ -54,6 +54,7 @@ namespace GxPress.Api.AppControllers
             result.AddRange(await replyService.GetNoticePraiseAsync(request));
             result.AddRange(await replyService.GetTopicPraiseAsync(request));
             result.OrderByDescending(n => n.CreatedDate);
+            await replyService.UpdateUReadPraiseAsync(request.UserId);
             return result;
         }
     }

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

@@ -92,7 +92,7 @@ namespace GxPress.Service.Implement.Reply
                             a.Id,
                             a.Content,
                             a.TypeValue,
-                            a.IsRead,
+                            b.IsRead,
                             b.UserId,
                             c.Name AS UserName,
                             c.AvatarUrl,
@@ -247,5 +247,198 @@ namespace GxPress.Service.Implement.Reply
             }
             return result;
         }
+        /// <summary>
+        /// 未读点赞数量
+        /// </summary>
+        /// <param name="userId"></param>
+        /// <returns></returns>
+        public async Task<int> GetUReadPraiseCountAsync(int userId)
+        {
+            var sql = $@" SELECT 
+                        COUNT(1)
+                    FROM
+                        tede_analyze a
+                            INNER JOIN
+                        tede_note 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
+                        a.TypeValue = 4 AND e.IsDelete = 0
+                            AND a.CommentId = 0
+                            AND e.UserId = b.UserId
+                            AND a.AnalyzeType = 1
+                            AND b.UserId = {userId}
+                            AND a.IsRead = 0";
+            var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
+            var connection = database.GetConnection();
+            var count = await connection.ExecuteScalarAsync<int>(sql);
+            sql = $@" SELECT 
+                        count(1)
+                        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 ={userId}
+                                AND b.AnalyzeType = 2
+                                AND b.IsRead = 0";
+            count += await connection.ExecuteScalarAsync<int>(sql);
+            sql = $@"  SELECT 
+                            COUNT(1)
+                        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 ={userId} AND e.UserId = b.UserId
+                                AND a.TypeValue ={AllTypeConst.Notice.GetHashCode()}
+                                AND e.IsDelete = 0
+                                AND a.CommentId = 0
+                                AND a.AnalyzeType = 1";
+            count += await connection.ExecuteScalarAsync<int>(sql);
+             sql = $@"  SELECT 
+                                count(1)
+                                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 ={userId}";
+            count += await connection.ExecuteScalarAsync<int>(sql);
+            return count;
+        }
+
+        /// <summary>
+        /// 修改未读点赞数量
+        /// </summary>
+        /// <param name="userId"></param>
+        /// <returns></returns>
+        public async Task<int> UpdateUReadPraiseAsync(int userId)
+        {
+            var sql = $@" UPDATE tede_analyze 
+                            SET 
+                                IsRead = 1
+                                    AND Id IN (
+             SELECT 
+                       a.Id
+                    FROM
+                        tede_analyze a
+                            INNER JOIN
+                        tede_note 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
+                        a.TypeValue = 4 AND e.IsDelete = 0
+                            AND a.CommentId = 0
+                            AND e.UserId = b.UserId
+                            AND a.AnalyzeType = 1
+                            AND b.UserId = {userId}
+                            AND a.IsRead = 0";
+            var database = new Database(DatabaseType.MySql, ConfigHelper.GetValue("Database:ConnectionString"));
+            var connection = database.GetConnection();
+            var count = await connection.ExecuteScalarAsync<int>(sql);
+            sql = $@"  UPDATE tede_analyze 
+                            SET 
+                                IsRead = 1
+                                    AND Id IN (
+                    SELECT 
+                        b.Id
+                        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 ={userId}
+                                AND b.AnalyzeType = 2
+                                AND b.IsRead = 0)  and id>0) and id>0";
+            count += await connection.ExecuteScalarAsync<int>(sql);
+            sql = $@" 
+             UPDATE tede_analyze 
+                            SET 
+                                IsRead = 1
+                                    AND Id IN (
+                         SELECT 
+                            a.Id
+                        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 ={userId} AND e.UserId = b.UserId
+                                AND a.TypeValue ={AllTypeConst.Notice.GetHashCode()}
+                                AND e.IsDelete = 0
+                                AND a.CommentId = 0
+                                AND a.AnalyzeType = 1) and id>0";
+            count += await connection.ExecuteScalarAsync<int>(sql);
+             sql = $@" 
+              UPDATE tede_analyze 
+                            SET 
+                                IsRead = 1
+                                    AND Id IN (
+                              SELECT 
+                                a.Id
+                                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 ={userId}) and id>0";
+            count += await connection.ExecuteScalarAsync<int>(sql);
+            return count;
+        }
     }
 }

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

@@ -50,5 +50,17 @@ namespace GxPress.Service.Interface.Reply
         /// <param name="request"></param>
         /// <returns></returns>
         Task<IEnumerable<ReplyResult>> GetTopicPraiseAsync(ReplyRequest request);
+        /// <summary>
+        /// 未读点赞数量
+        /// </summary>
+        /// <param name="userId"></param>
+        /// <returns></returns>
+        Task<int> GetUReadPraiseCountAsync(int userId);
+        /// <summary>
+        /// 修改未读点赞数量
+        /// </summary>
+        /// <param name="userId"></param>
+        /// <returns></returns>
+        Task<int> UpdateUReadPraiseAsync(int userId);
     }
 }