From b06162b2966eea4f092b3edf3032de843059af4b Mon Sep 17 00:00:00 2001
From: cloudroam <cloudroam>
Date: 星期四, 12 六月 2025 18:16:10 +0800
Subject: [PATCH] add: 评论开发

---
 src/main/java/com/mzl/flower/service/film/impl/CommentLikesServiceImpl.java |   29 +++++++++++++++++++++++------
 1 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/src/main/java/com/mzl/flower/service/film/impl/CommentLikesServiceImpl.java b/src/main/java/com/mzl/flower/service/film/impl/CommentLikesServiceImpl.java
index 392b493..f61c5c7 100644
--- a/src/main/java/com/mzl/flower/service/film/impl/CommentLikesServiceImpl.java
+++ b/src/main/java/com/mzl/flower/service/film/impl/CommentLikesServiceImpl.java
@@ -1,6 +1,7 @@
 package com.mzl.flower.service.film.impl;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.mzl.flower.config.exception.ValidationException;
 import com.mzl.flower.config.security.SecurityUtils;
 import com.mzl.flower.dto.request.film.CommentLikesDTO;
 import com.mzl.flower.dto.request.film.CommentLikesQueryDTO;
@@ -37,16 +38,32 @@
         //查询有没有对应人员的点赞信息
         CommentLikes commentLikes = commentLikesMapper.getCommentLikeByUserIdAndCommentId(SecurityUtils.getUserId(), commentLikesDTO.getCommentId());
         if (commentLikes == null) {
-            CommentLikes commentLikes1 = new CommentLikes();
-            commentLikes1.setCommentId(commentLikesDTO.getCommentId());
-            commentLikes1.setStatus(true);
-            commentLikes1.create();
-            commentLikesMapper.insert(commentLikes1);
+            commentLikes = new CommentLikes();
+            commentLikes.setCommentId(commentLikesDTO.getCommentId());
+            commentLikes.setStatus(true);
+            commentLikes.setCreateBy(SecurityUtils.getUserId());
+            commentLikes.create();
+            if (commentLikesMapper.insert(commentLikes) <= 0) {
+                throw new ValidationException("添加评论点赞失败");
+            }
         } else {
             // 状态取反
             commentLikes.setStatus(!commentLikes.getStatus());
             commentLikes.update(SecurityUtils.getUserId());
-            commentLikesMapper.updateById(commentLikes);
+
+            // 校验主键是否存在
+            if (commentLikes.getId() == null) {
+                throw new ValidationException("主键 ID 不能为空");
+            }
+            int affectedRows = commentLikesMapper.updateStatusById(
+                    commentLikes.getId(),         // 确保 id 是 Long 类型
+                    commentLikes.getStatus(),
+                    SecurityUtils.getUserId()  // 更新人
+            );
+            if (affectedRows <= 0) {
+                throw new ValidationException("更新作品点赞状态失败");
+            }
+
         }
     }
 

--
Gitblit v1.9.3