feat(comment): Implement comment module foundation

This commit is contained in:
2025-04-10 02:02:02 +08:00
parent 27dd1409f6
commit 449f5418b2
34 changed files with 2624 additions and 13 deletions
@@ -0,0 +1,25 @@
spring:
datasource:
dynamic:
primary: master
strict: false
datasource:
master:
url: jdbc:mysql://5.180.253.115:3306/video_comment?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
username: root
password: sty@G458221
driver-class-name: com.mysql.cj.jdbc.Driver
data:
redis:
database: 3
host: 5.180.253.115
port: 6379
password: redis_EsJ8FX
timeout: 10000
# 开发环境日志级别
logging:
level:
com.nuaa.video: debug
org.springframework.security: debug
@@ -4,30 +4,109 @@ server:
spring:
application:
name: video-comment
profiles:
active: dev
config:
import:
- optional:nacos:${spring.application.name}.yaml
cloud:
nacos:
discovery:
server-addr: 5.180.253.115:8848
namespace: public
group: DEFAULT_GROUP
server-addr: ${NACOS_HOST:5.180.253.115}:${NACOS_PORT:8848}
namespace: ${NACOS_NAMESPACE:public}
group: ${NACOS_GROUP:DEFAULT_GROUP}
config:
server-addr: ${spring.cloud.nacos.discovery.server-addr}
namespace: ${spring.cloud.nacos.discovery.namespace}
group: ${spring.cloud.nacos.discovery.group}
file-extension: yaml
sentinel:
transport:
dashboard: 5.180.253.115:8080
dashboard: ${SENTINEL_DASHBOARD_HOST:5.180.253.115}:${SENTINEL_DASHBOARD_PORT:8080}
port: 8723
eager: true
datasource:
url: jdbc:mysql://5.180.253.115:3306/video_comment?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: sty@G458221
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://${MYSQL_HOST:5.180.253.115}:${MYSQL_PORT:3306}/video_comment?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
username: ${MYSQL_USERNAME:root}
password: ${MYSQL_PASSWORD:sty@G458221}
hikari:
minimum-idle: 5
maximum-pool-size: 20
idle-timeout: 30000
max-lifetime: 1200000
connection-timeout: 30000
connection-test-query: SELECT 1
data:
redis:
host: 5.180.253.115
port: 6379
password: redis_EsJ8FX
host: ${REDIS_HOST:5.180.253.115}
port: ${REDIS_PORT:6379}
password: ${REDIS_PASSWORD:redis_EsJ8FX}
database: 3
timeout: 10000
lettuce:
pool:
max-active: 200
max-wait: -1
max-idle: 10
min-idle: 0
mybatis-plus:
mapper-locations: classpath:mapper/*.xml
type-aliases-package: com.nuaa.video.comment.entity
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case: true
cache-enabled: false
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
global-config:
db-config:
id-type: auto
logic-delete-field: status
logic-delete-value: 0
logic-not-delete-value: 1
# 评论服务配置
comment:
# 敏感词过滤
sensitive-filter:
enabled: true
# 评论审核
review:
enabled: false # 默认不开启自动审核,由管理员手动审核
# JWT配置与auth模块保持一致
jwt:
secret: video-platform-secret-key-2024-nuaa
expiration: 86400
token-header: Authorization
token-prefix: "Bearer "
auth:
ignore-urls:
- /comment/public/**
- /actuator/**
management:
endpoints:
web:
exposure:
include: '*'
endpoint:
health:
show-details: always
feign:
client:
config:
default:
connectTimeout: 5000
readTimeout: 5000
circuitbreaker:
enabled: true
logging:
level:
com.nuaa.video: info
org.springframework.security: info
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nuaa.video.comment.mapper.CommentLikeMapper">
<!-- 检查用户是否已点赞 -->
<select id="checkUserLiked" resultType="long">
SELECT COUNT(1)
FROM comment_like
WHERE comment_id = #{commentId}
AND user_id = #{userId}
AND type = #{type}
</select>
<!-- 统计视频评论点赞数 -->
<select id="countVideoCommentLikes" resultType="int">
SELECT COUNT(1)
FROM comment_like cl
LEFT JOIN comment c ON cl.comment_id = c.id AND cl.type = 1
LEFT JOIN comment_reply cr ON cl.comment_id = cr.id AND cl.type = 2
WHERE (c.video_id = #{videoId} OR cr.video_id = #{videoId})
</select>
</mapper>
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nuaa.video.comment.mapper.CommentMapper">
<!-- 分页查询评论列表 -->
<select id="selectCommentList" resultType="com.nuaa.video.comment.entity.Comment">
SELECT *
FROM comment
<where>
status = 1
<if test="query.videoId != null">
AND video_id = #{query.videoId}
</if>
<if test="query.userId != null">
AND user_id = #{query.userId}
</if>
</where>
<choose>
<when test="query.orderBy != null and query.orderBy != ''">
ORDER BY top_status DESC, ${query.orderBy}
<if test="query.orderDirection != null and query.orderDirection != ''">
${query.orderDirection}
</if>
</when>
<otherwise>
ORDER BY top_status DESC, create_time DESC
</otherwise>
</choose>
</select>
<!-- 增加点赞数 -->
<update id="increaseLikeCount">
UPDATE comment
SET like_count = like_count + #{count}
WHERE id = #{commentId}
</update>
<!-- 增加回复数 -->
<update id="increaseReplyCount">
UPDATE comment
SET reply_count = reply_count + #{count}
WHERE id = #{commentId}
</update>
<!-- 统计视频评论数 -->
<select id="countVideoComments" resultType="int">
SELECT COUNT(1)
FROM comment
WHERE video_id = #{videoId}
AND status = 1
</select>
</mapper>
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nuaa.video.comment.mapper.CommentReplyMapper">
<!-- 查询评论的回复列表 -->
<select id="selectCommentReplyList" resultType="com.nuaa.video.comment.entity.CommentReply">
SELECT *
FROM comment_reply
WHERE comment_id = #{commentId}
AND status = 1
ORDER BY create_time ASC
</select>
<!-- 获取评论的热门回复 -->
<select id="selectHotReplies" resultType="com.nuaa.video.comment.entity.CommentReply">
SELECT *
FROM comment_reply
WHERE comment_id = #{commentId}
AND status = 1
ORDER BY like_count DESC, create_time ASC
LIMIT #{limit}
</select>
<!-- 增加点赞数 -->
<update id="increaseLikeCount">
UPDATE comment_reply
SET like_count = like_count + #{count}
WHERE id = #{replyId}
</update>
<!-- 统计视频回复数 -->
<select id="countVideoReplies" resultType="int">
SELECT COUNT(1)
FROM comment_reply
WHERE video_id = #{videoId}
AND status = 1
</select>
</mapper>