| | |
| | | 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; |
| | |
| | | //查询有没有对应人员的点赞信息 |
| | | 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("更新作品点赞状态失败"); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |