From ed0dc655e6732f15d30f399c0d460ad7b9fe42da Mon Sep 17 00:00:00 2001 From: cloudroam <cloudroam> Date: 星期三, 04 六月 2025 16:55:42 +0800 Subject: [PATCH] add:影视作品点赞和评论点赞 --- src/main/java/com/mzl/flower/service/film/impl/CommentLikesServiceImpl.java | 31 ++++++++++++++++++++++++++++++- 1 files changed, 30 insertions(+), 1 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 441c9a9..d9d8bd7 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.security.SecurityUtils; import com.mzl.flower.dto.request.film.CommentLikesDTO; import com.mzl.flower.dto.request.film.CommentLikesQueryDTO; import com.mzl.flower.dto.response.film.CommentLikesVO; @@ -10,12 +11,17 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; +import javax.annotation.Resource; + /** * @author generator@Fang * @since 2025-05-29 */ @Service public class CommentLikesServiceImpl extends ServiceImpl<CommentLikesMapper, CommentLikes> implements CommentLikesService { + + @Resource + private CommentLikesMapper commentLikesMapper; @Override public void saveCommentLikes(CommentLikesDTO commentLikesDTO) { @@ -24,7 +30,20 @@ @Override public void updateCommentLikes(CommentLikesDTO commentLikesDTO) { - + //查询有没有对应人员的点赞信息 + 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); + } else { + // 状态取反 + commentLikes.setStatus(!commentLikes.getStatus()); + commentLikes.update(SecurityUtils.getUserId()); + commentLikesMapper.updateById(commentLikes); + } } @Override @@ -36,4 +55,14 @@ public Page<CommentLikesVO> queryPage(CommentLikesQueryDTO commentLikesQueryDTO, Page page) { return null; } + + @Override + public Long getLikeCountCommentId(Integer id) { + return commentLikesMapper.getLikeCountCommentId(id); + } + + @Override + public Boolean isLike(Integer commentId, String userId) { + return commentLikesMapper.isLike(commentId,userId); + } } -- Gitblit v1.9.3