From 29cf889dd7c6a807157f537d21cfe6358247684c Mon Sep 17 00:00:00 2001
From: Hanserwei <2628273921@qq.com>
Date: Fri, 7 Nov 2025 21:49:47 +0800
Subject: [PATCH] =?UTF-8?q?feat(comment):=20=E6=96=B0=E5=A2=9E=E4=B8=80?=
=?UTF-8?q?=E7=BA=A7=E8=AF=84=E8=AE=BA=E9=A6=96=E6=9D=A1=E5=9B=9E=E5=A4=8D?=
=?UTF-8?q?ID=E5=AD=97=E6=AE=B5=E5=8F=8A=E6=9B=B4=E6=96=B0=E6=9C=BA?=
=?UTF-8?q?=E5=88=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 在 CommentDO 中新增 firstReplyCommentId 字段,用于记录一级评论下最早回复的评论 ID
- 在 CommentDOMapper 中新增 selectEarliestByParentId 和 updateFirstReplyCommentIdByPrimaryKey 方法,用于查询和更新一级评论的首条回复 ID
- 在 t_comment 表中新增 first_reply_comment_id 字段- 新增 OneLevelCommentFirstReplyCommentIdUpdateConsumer 消费者,用于异步更新一级评论的首条回复 ID- 新增 RedisKeyConstants 常量类,用于构建 Redis Key
- 新增 RedisTemplateConfig 配置类,用于配置 RedisTemplate
- 在 pom.xml 中新增 spring-boot-starter-data-redis 依赖
---
han-note-comment/han-note-comment-biz/pom.xml | 6 +
.../biz/config/RedisTemplateConfig.java | 31 ++++
.../biz/constants/RedisKeyConstants.java | 21 +++
...mentFirstReplyCommentIdUpdateConsumer.java | 164 ++++++++++++++++++
.../biz/domain/dataobject/CommentDO.java | 6 +
.../biz/domain/mapper/CommentDOMapper.java | 18 ++
.../resources/mapperxml/CommentDOMapper.xml | 22 ++-
http-client/gateApi.http | 2 +-
sql/createTable.sql | 4 +
9 files changed, 271 insertions(+), 3 deletions(-)
create mode 100644 han-note-comment/han-note-comment-biz/src/main/java/com/hanserwei/hannote/comment/biz/config/RedisTemplateConfig.java
create mode 100644 han-note-comment/han-note-comment-biz/src/main/java/com/hanserwei/hannote/comment/biz/constants/RedisKeyConstants.java
create mode 100644 han-note-comment/han-note-comment-biz/src/main/java/com/hanserwei/hannote/comment/biz/consumer/OneLevelCommentFirstReplyCommentIdUpdateConsumer.java
diff --git a/han-note-comment/han-note-comment-biz/pom.xml b/han-note-comment/han-note-comment-biz/pom.xml
index 96ffe1e..2673d36 100644
--- a/han-note-comment/han-note-comment-biz/pom.xml
+++ b/han-note-comment/han-note-comment-biz/pom.xml
@@ -119,6 +119,12 @@
buffer-trigger
+
+
+ org.springframework.boot
+ spring-boot-starter-data-redis
+
+
diff --git a/han-note-comment/han-note-comment-biz/src/main/java/com/hanserwei/hannote/comment/biz/config/RedisTemplateConfig.java b/han-note-comment/han-note-comment-biz/src/main/java/com/hanserwei/hannote/comment/biz/config/RedisTemplateConfig.java
new file mode 100644
index 0000000..c811a55
--- /dev/null
+++ b/han-note-comment/han-note-comment-biz/src/main/java/com/hanserwei/hannote/comment/biz/config/RedisTemplateConfig.java
@@ -0,0 +1,31 @@
+package com.hanserwei.hannote.comment.biz.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.redis.connection.RedisConnectionFactory;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
+import org.springframework.data.redis.serializer.StringRedisSerializer;
+
+@Configuration
+public class RedisTemplateConfig {
+
+ @Bean
+ public RedisTemplate redisTemplate(RedisConnectionFactory connectionFactory) {
+ RedisTemplate redisTemplate = new RedisTemplate<>();
+ // 设置 RedisTemplate 的连接工厂
+ redisTemplate.setConnectionFactory(connectionFactory);
+
+ // 使用 StringRedisSerializer 来序列化和反序列化 redis 的 key 值,确保 key 是可读的字符串
+ redisTemplate.setKeySerializer(new StringRedisSerializer());
+ redisTemplate.setHashKeySerializer(new StringRedisSerializer());
+
+ // 使用 Jackson2JsonRedisSerializer 来序列化和反序列化 redis 的 value 值, 确保存储的是 JSON 格式
+ Jackson2JsonRedisSerializer