|
|
@ -15,6 +15,7 @@ import com.youlai.boot.mini.mapper.MiniStrayAnimalNoteMapper; |
|
|
import com.youlai.boot.mini.model.entity.MiniStrayAnimalNote; |
|
|
import com.youlai.boot.mini.model.entity.MiniStrayAnimalNote; |
|
|
import com.youlai.boot.mini.model.entity.MiniStrayAnimalNoteComment; |
|
|
import com.youlai.boot.mini.model.entity.MiniStrayAnimalNoteComment; |
|
|
import com.youlai.boot.mini.model.entity.MiniStrayAnimalNoteCommentLike; |
|
|
import com.youlai.boot.mini.model.entity.MiniStrayAnimalNoteCommentLike; |
|
|
|
|
|
import com.youlai.boot.mini.model.form.CommentLikeForm; |
|
|
import com.youlai.boot.mini.model.form.DeleteStrayAnimalNoteCommentForm; |
|
|
import com.youlai.boot.mini.model.form.DeleteStrayAnimalNoteCommentForm; |
|
|
import com.youlai.boot.mini.model.form.StrayAnimalNoteCommentForm; |
|
|
import com.youlai.boot.mini.model.form.StrayAnimalNoteCommentForm; |
|
|
import com.youlai.boot.mini.model.query.AnimalNoteFirstLevelCommentQueryParam; |
|
|
import com.youlai.boot.mini.model.query.AnimalNoteFirstLevelCommentQueryParam; |
|
|
@ -33,6 +34,7 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
import java.util.*; |
|
|
import java.util.*; |
|
|
import java.util.function.Function; |
|
|
import java.util.function.Function; |
|
|
import java.util.stream.Collectors; |
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker; |
|
|
|
|
|
|
|
|
@Slf4j |
|
|
@Slf4j |
|
|
@Service |
|
|
@Service |
|
|
@ -281,4 +283,61 @@ public class StrayAnimalNoteCommentServiceImpl extends ServiceImpl<MiniStrayAnim |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
|
|
public Map<String, Object> toggleLike(CommentLikeForm form, Long userId) { |
|
|
|
|
|
// 1. 根据评论UUID查询内部主键ID
|
|
|
|
|
|
Long commentId = baseMapper.selectIdByUuid(form.getCommentUuid()); |
|
|
|
|
|
if (commentId == null) { |
|
|
|
|
|
throw new MsgException("评论不存在或已删除"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
long currentTime = System.currentTimeMillis(); |
|
|
|
|
|
boolean targetLike = form.getLike(); |
|
|
|
|
|
Boolean currentLiked = null; |
|
|
|
|
|
|
|
|
|
|
|
// 2. 查询用户当前点赞状态
|
|
|
|
|
|
Integer count = miniStrayAnimalNoteCommentLikeMapper.selectUserLikeCount(commentId, userId); |
|
|
|
|
|
if (count != null && count > 0) { |
|
|
|
|
|
currentLiked = true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 3. 执行点赞/取消点赞操作
|
|
|
|
|
|
if (targetLike) { |
|
|
|
|
|
// 点赞操作:不存在则新增,存在则更新为未删除状态
|
|
|
|
|
|
if (!Boolean.TRUE.equals(currentLiked)) { |
|
|
|
|
|
MiniStrayAnimalNoteCommentLike like = new MiniStrayAnimalNoteCommentLike(); |
|
|
|
|
|
like.setUuid(IdWorker.get32UUID()); |
|
|
|
|
|
like.setNoteCommentId(commentId); |
|
|
|
|
|
like.setMiniUserId(userId); |
|
|
|
|
|
like.setCreateBy(userId); |
|
|
|
|
|
like.setCreateTimestamp(currentTime); |
|
|
|
|
|
like.setCreateTime(new Date(currentTime)); |
|
|
|
|
|
like.setUpdateBy(userId); |
|
|
|
|
|
like.setUpdateTimestamp(currentTime); |
|
|
|
|
|
like.setUpdateTime(new Date(currentTime)); |
|
|
|
|
|
like.setDeleted(false); |
|
|
|
|
|
miniStrayAnimalNoteCommentLikeMapper.insertOrUpdateLike(like); |
|
|
|
|
|
|
|
|
|
|
|
// 原子增加点赞数
|
|
|
|
|
|
baseMapper.incrementLikeCount(commentId); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
// 取消点赞操作:逻辑删除
|
|
|
|
|
|
if (Boolean.TRUE.equals(currentLiked)) { |
|
|
|
|
|
miniStrayAnimalNoteCommentLikeMapper.deleteLike(commentId, userId, currentTime); |
|
|
|
|
|
|
|
|
|
|
|
// 原子减少点赞数
|
|
|
|
|
|
baseMapper.decrementLikeCount(commentId); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 4. 查询最新点赞数返回
|
|
|
|
|
|
Long likeCount = baseMapper.selectLikeCount(commentId); |
|
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
|
result.put("isLiked", targetLike); |
|
|
|
|
|
result.put("likeCount", likeCount != null ? likeCount : 0); |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|