|
|
@@ -13,11 +13,11 @@ import shop.alien.entity.store.LifeLikeRecord;
|
|
|
import shop.alien.entity.store.OrderReview;
|
|
|
import shop.alien.entity.store.ReviewComment;
|
|
|
import shop.alien.entity.store.dto.ReviewCommentDto;
|
|
|
-import shop.alien.entity.store.vo.CommentReplyVo;
|
|
|
+import shop.alien.entity.store.dto.ReviewCommentRequestDto;
|
|
|
+import shop.alien.entity.store.dto.ReviewReplyDto;
|
|
|
import shop.alien.entity.store.vo.ReviewCommentVo;
|
|
|
import shop.alien.lawyer.service.OrderReviewService;
|
|
|
import shop.alien.lawyer.service.ReviewCommentService;
|
|
|
-import shop.alien.mapper.CommentReplyMapper;
|
|
|
import shop.alien.mapper.LifeLikeRecordMapper;
|
|
|
import shop.alien.mapper.ReviewCommentMapper;
|
|
|
|
|
|
@@ -36,16 +36,13 @@ import java.util.List;
|
|
|
public class ReviewCommentServiceImpl extends ServiceImpl<ReviewCommentMapper, ReviewComment> implements ReviewCommentService {
|
|
|
|
|
|
private final ReviewCommentMapper reviewCommentMapper;
|
|
|
- private final CommentReplyMapper commentReplyMapper;
|
|
|
private final OrderReviewService orderReviewService;
|
|
|
private final LifeLikeRecordMapper lifeLikeRecordMapper;
|
|
|
|
|
|
public ReviewCommentServiceImpl(ReviewCommentMapper reviewCommentMapper,
|
|
|
- CommentReplyMapper commentReplyMapper,
|
|
|
@Lazy OrderReviewService orderReviewService,
|
|
|
LifeLikeRecordMapper lifeLikeRecordMapper) {
|
|
|
this.reviewCommentMapper = reviewCommentMapper;
|
|
|
- this.commentReplyMapper = commentReplyMapper;
|
|
|
this.orderReviewService = orderReviewService;
|
|
|
this.lifeLikeRecordMapper = lifeLikeRecordMapper;
|
|
|
}
|
|
|
@@ -111,15 +108,24 @@ public class ReviewCommentServiceImpl extends ServiceImpl<ReviewCommentMapper, R
|
|
|
}
|
|
|
|
|
|
List<ReviewCommentVo> comments = reviewCommentMapper.getCommentListByReviewId(reviewId, currentUserId);
|
|
|
+
|
|
|
+ // 为每个首评加载回复列表
|
|
|
+ if (comments != null && !comments.isEmpty()) {
|
|
|
+ for (ReviewCommentVo comment : comments) {
|
|
|
+ List<ReviewCommentVo> replies = reviewCommentMapper.getReplyListByHeadId(comment.getId(), currentUserId);
|
|
|
+ comment.setReplies(replies);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return R.data(comments);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public R<Boolean> deleteComment(CommentReplyVo commentReplyVo) {
|
|
|
- log.info("ReviewCommentController.deleteComment?CommentReplyVo={}", commentReplyVo);
|
|
|
+ public R<Boolean> deleteComment(ReviewCommentRequestDto requestDto) {
|
|
|
+ log.info("ReviewCommentServiceImpl.deleteComment?requestDto={}", requestDto);
|
|
|
|
|
|
- Integer commentId = commentReplyVo.getCommentId();
|
|
|
- Integer userId = commentReplyVo.getUserId();
|
|
|
+ Integer commentId = requestDto.getCommentId();
|
|
|
+ Integer userId = requestDto.getUserId();
|
|
|
|
|
|
if (commentId == null) {
|
|
|
return R.fail("评论ID不能为空");
|
|
|
@@ -139,8 +145,15 @@ public class ReviewCommentServiceImpl extends ServiceImpl<ReviewCommentMapper, R
|
|
|
return R.fail("只能删除自己的评论");
|
|
|
}
|
|
|
|
|
|
- // 删除评论下的所有回复
|
|
|
- commentReplyMapper.deleteRepliesByCommentId(commentId);
|
|
|
+ // 删除评论下的所有回复(逻辑删除)
|
|
|
+ LambdaUpdateWrapper<ReviewComment> replyUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ replyUpdateWrapper.eq(ReviewComment::getHeadId, commentId)
|
|
|
+ .eq(ReviewComment::getHeadType, 1)
|
|
|
+ .eq(ReviewComment::getDeleteFlag, 0);
|
|
|
+ replyUpdateWrapper.set(ReviewComment::getDeleteFlag, 1);
|
|
|
+ replyUpdateWrapper.set(ReviewComment::getUpdatedUserId, userId);
|
|
|
+ replyUpdateWrapper.set(ReviewComment::getUpdatedTime, new Date());
|
|
|
+ this.update(replyUpdateWrapper);
|
|
|
|
|
|
// 删除评论(逻辑删除)
|
|
|
comment.setDeleteFlag(1);
|
|
|
@@ -165,11 +178,11 @@ public class ReviewCommentServiceImpl extends ServiceImpl<ReviewCommentMapper, R
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public R<Boolean> likeComment(CommentReplyVo commentReplyVo) {
|
|
|
- log.info("ReviewCommentServiceImpl.likeComment?CommentReplyVo={}", commentReplyVo);
|
|
|
+ public R<Boolean> likeComment(ReviewCommentRequestDto requestDto) {
|
|
|
+ log.info("ReviewCommentServiceImpl.likeComment?requestDto={}", requestDto);
|
|
|
|
|
|
- Integer commentId = commentReplyVo.getCommentId();
|
|
|
- Integer userId = commentReplyVo.getUserId();
|
|
|
+ Integer commentId = requestDto.getCommentId();
|
|
|
+ Integer userId = requestDto.getUserId();
|
|
|
|
|
|
if (commentId == null) {
|
|
|
return R.fail("评论ID不能为空");
|
|
|
@@ -220,11 +233,11 @@ public class ReviewCommentServiceImpl extends ServiceImpl<ReviewCommentMapper, R
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public R<Boolean> cancelLikeComment(CommentReplyVo commentReplyVo) {
|
|
|
- log.info("ReviewCommentServiceImpl.cancelLikeComment?CommentReplyVo={}", commentReplyVo);
|
|
|
+ public R<Boolean> cancelLikeComment(ReviewCommentRequestDto requestDto) {
|
|
|
+ log.info("ReviewCommentServiceImpl.cancelLikeComment?requestDto={}", requestDto);
|
|
|
|
|
|
- Integer commentId = commentReplyVo.getCommentId();
|
|
|
- Integer userId = commentReplyVo.getUserId();
|
|
|
+ Integer commentId = requestDto.getCommentId();
|
|
|
+ Integer userId = requestDto.getUserId();
|
|
|
if (commentId == null) {
|
|
|
return R.fail("评论ID不能为空");
|
|
|
}
|
|
|
@@ -266,5 +279,220 @@ public class ReviewCommentServiceImpl extends ServiceImpl<ReviewCommentMapper, R
|
|
|
return R.data(true, "未点赞");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R<ReviewComment> createReply(ReviewReplyDto replyDto) {
|
|
|
+ log.info("ReviewCommentServiceImpl.createReply?replyDto={}", replyDto);
|
|
|
+
|
|
|
+ // 参数校验
|
|
|
+ if (replyDto == null) {
|
|
|
+ return R.fail("回复信息不能为空");
|
|
|
+ }
|
|
|
+ if (replyDto.getCommentId() == null) {
|
|
|
+ return R.fail("评论ID不能为空");
|
|
|
+ }
|
|
|
+ if (replyDto.getReplyContent() == null || replyDto.getReplyContent().trim().isEmpty()) {
|
|
|
+ return R.fail("回复内容不能为空");
|
|
|
+ }
|
|
|
+ Integer userId = replyDto.getUserId();
|
|
|
+ if (userId == null) {
|
|
|
+ return R.fail("用户ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证首评是否存在
|
|
|
+ ReviewComment headComment = this.getById(replyDto.getCommentId());
|
|
|
+ if (headComment == null || headComment.getDeleteFlag() == 1) {
|
|
|
+ return R.fail("评论不存在或已删除");
|
|
|
+ }
|
|
|
+ if (headComment.getHeadType() != 0) {
|
|
|
+ return R.fail("只能回复首评");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建回复
|
|
|
+ ReviewComment reply = new ReviewComment();
|
|
|
+ reply.setReviewId(headComment.getReviewId());
|
|
|
+ reply.setSendUserId(userId);
|
|
|
+ reply.setReceiveUserId(replyDto.getReplyToUserId() != null ? replyDto.getReplyToUserId() : headComment.getSendUserId());
|
|
|
+ reply.setCommentContent(replyDto.getReplyContent());
|
|
|
+ reply.setLikeCount(0);
|
|
|
+ reply.setReplyCount(0);
|
|
|
+ reply.setHeadType(1); // 1:是回复
|
|
|
+ reply.setHeadId(replyDto.getCommentId()); // 指向首评ID
|
|
|
+ reply.setCreatedUserId(userId);
|
|
|
+ reply.setCreatedTime(new Date());
|
|
|
+
|
|
|
+ boolean success = this.save(reply);
|
|
|
+ if (success) {
|
|
|
+ // 更新首评的回复数
|
|
|
+ headComment.setReplyCount((headComment.getReplyCount() == null ? 0 : headComment.getReplyCount()) + 1);
|
|
|
+ this.updateById(headComment);
|
|
|
+
|
|
|
+ log.info("创建回复成功,回复ID={}", reply.getId());
|
|
|
+ return R.data(reply, "回复成功");
|
|
|
+ } else {
|
|
|
+ log.error("创建回复失败");
|
|
|
+ return R.fail("创建回复失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R<List<ReviewCommentVo>> getReplyListByHeadId(Integer headId, Integer currentUserId) {
|
|
|
+ log.info("ReviewCommentServiceImpl.getReplyListByHeadId?headId={}, currentUserId={}", headId, currentUserId);
|
|
|
+
|
|
|
+ if (headId == null) {
|
|
|
+ return R.fail("首评ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ReviewCommentVo> replies = reviewCommentMapper.getReplyListByHeadId(headId, currentUserId);
|
|
|
+ return R.data(replies);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R<Boolean> deleteReply(Integer replyId, Integer userId) {
|
|
|
+ log.info("ReviewCommentServiceImpl.deleteReply?replyId={}, userId={}", replyId, userId);
|
|
|
+
|
|
|
+ if (replyId == null) {
|
|
|
+ return R.fail("回复ID不能为空");
|
|
|
+ }
|
|
|
+ if (userId == null) {
|
|
|
+ return R.fail("用户ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询回复
|
|
|
+ ReviewComment reply = this.getById(replyId);
|
|
|
+ if (reply == null) {
|
|
|
+ return R.fail("回复不存在");
|
|
|
+ }
|
|
|
+ if (reply.getHeadType() != 1) {
|
|
|
+ return R.fail("该记录不是回复");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证是否为回复用户
|
|
|
+ if (!reply.getSendUserId().equals(userId)) {
|
|
|
+ return R.fail("只能删除自己的回复");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除回复(逻辑删除)
|
|
|
+ reply.setDeleteFlag(1);
|
|
|
+ reply.setUpdatedUserId(userId);
|
|
|
+ reply.setUpdatedTime(new Date());
|
|
|
+ boolean success = this.updateById(reply);
|
|
|
+
|
|
|
+ if (success) {
|
|
|
+ // 更新首评的回复数
|
|
|
+ ReviewComment headComment = this.getById(reply.getHeadId());
|
|
|
+ if (headComment != null) {
|
|
|
+ headComment.setReplyCount((headComment.getReplyCount() == null ? 0 : headComment.getReplyCount()) - 1);
|
|
|
+ this.updateById(headComment);
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("删除回复成功,回复ID={}", replyId);
|
|
|
+ return R.data(true, "删除成功");
|
|
|
+ } else {
|
|
|
+ log.error("删除回复失败,回复ID={}", replyId);
|
|
|
+ return R.fail("删除回复失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R<Boolean> likeReply(Integer replyId, Integer userId) {
|
|
|
+ log.info("ReviewCommentServiceImpl.likeReply?replyId={}, userId={}", replyId, userId);
|
|
|
+
|
|
|
+ if (replyId == null) {
|
|
|
+ return R.fail("回复ID不能为空");
|
|
|
+ }
|
|
|
+ if (userId == null) {
|
|
|
+ return R.fail("用户ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证回复是否存在
|
|
|
+ ReviewComment reply = this.getById(replyId);
|
|
|
+ if (reply == null || reply.getDeleteFlag() == 1) {
|
|
|
+ return R.fail("回复不存在或已删除");
|
|
|
+ }
|
|
|
+ if (reply.getHeadType() != 1) {
|
|
|
+ return R.fail("该记录不是回复");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查是否已点赞
|
|
|
+ LambdaQueryWrapper<LifeLikeRecord> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(LifeLikeRecord::getType, "8")
|
|
|
+ .eq(LifeLikeRecord::getDianzanId, String.valueOf(userId))
|
|
|
+ .eq(LifeLikeRecord::getHuifuId, String.valueOf(replyId))
|
|
|
+ .eq(LifeLikeRecord::getDeleteFlag, 0);
|
|
|
+ List<LifeLikeRecord> records = lifeLikeRecordMapper.selectList(queryWrapper);
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(records)) {
|
|
|
+ // 插入点赞记录
|
|
|
+ LifeLikeRecord likeRecord = new LifeLikeRecord();
|
|
|
+ likeRecord.setDianzanId(String.valueOf(userId));
|
|
|
+ likeRecord.setHuifuId(String.valueOf(replyId));
|
|
|
+ likeRecord.setType("8");
|
|
|
+ likeRecord.setCreatedTime(new Date());
|
|
|
+ likeRecord.setCreatedUserId(userId);
|
|
|
+ lifeLikeRecordMapper.insert(likeRecord);
|
|
|
+
|
|
|
+ // 更新回复点赞数
|
|
|
+ LambdaUpdateWrapper<ReviewComment> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.eq(ReviewComment::getId, replyId);
|
|
|
+ updateWrapper.setSql("like_count = like_count + 1");
|
|
|
+ int result = reviewCommentMapper.update(null, updateWrapper);
|
|
|
+
|
|
|
+ if (result > 0) {
|
|
|
+ log.info("点赞回复成功,回复ID={}", replyId);
|
|
|
+ return R.data(true, "点赞成功");
|
|
|
+ } else {
|
|
|
+ return R.fail("点赞失败");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return R.data(true, "已点赞");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R<Boolean> cancelLikeReply(Integer replyId, Integer userId) {
|
|
|
+ log.info("ReviewCommentServiceImpl.cancelLikeReply?replyId={}, userId={}", replyId, userId);
|
|
|
+
|
|
|
+ if (replyId == null) {
|
|
|
+ return R.fail("回复ID不能为空");
|
|
|
+ }
|
|
|
+ if (userId == null) {
|
|
|
+ return R.fail("用户ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询点赞记录
|
|
|
+ LambdaQueryWrapper<LifeLikeRecord> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(LifeLikeRecord::getType, "8")
|
|
|
+ .eq(LifeLikeRecord::getDianzanId, String.valueOf(userId))
|
|
|
+ .eq(LifeLikeRecord::getHuifuId, String.valueOf(replyId))
|
|
|
+ .eq(LifeLikeRecord::getDeleteFlag, 0);
|
|
|
+ List<LifeLikeRecord> records = lifeLikeRecordMapper.selectList(queryWrapper);
|
|
|
+
|
|
|
+ if (!CollectionUtils.isEmpty(records)) {
|
|
|
+ // 删除点赞记录(逻辑删除)
|
|
|
+ for (LifeLikeRecord record : records) {
|
|
|
+ record.setDeleteFlag(1);
|
|
|
+ record.setUpdatedUserId(userId);
|
|
|
+ record.setUpdatedTime(new Date());
|
|
|
+ lifeLikeRecordMapper.updateById(record);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新回复点赞数
|
|
|
+ LambdaUpdateWrapper<ReviewComment> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.eq(ReviewComment::getId, replyId);
|
|
|
+ updateWrapper.gt(ReviewComment::getLikeCount, 0);
|
|
|
+ updateWrapper.setSql("like_count = like_count - 1");
|
|
|
+ int result = reviewCommentMapper.update(null, updateWrapper);
|
|
|
+
|
|
|
+ if (result > 0) {
|
|
|
+ log.info("取消点赞回复成功,回复ID={}", replyId);
|
|
|
+ return R.data(true, "取消点赞成功");
|
|
|
+ } else {
|
|
|
+ return R.fail("取消点赞失败");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return R.data(true, "未点赞");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|