♻️Refactor: 优化值获取的判空逻辑

This commit is contained in:
2025-10-20 20:44:27 +08:00
parent 06f72e5bee
commit 37ea93e923
@@ -88,10 +88,10 @@ public class ThumbServiceImpl extends ServiceImpl<ThumbMapper, Thumb>
Long blogId = doThumbRequest.getBlogId();
// 判断是否已点过赞
Object thumbIdObj = redisTemplate.opsForHash().get(ThumbConstant.USER_THUMB_KEY_PREFIX + loginUser.getId().toString(), blogId.toString());
Long thumbId = thumbIdObj == null ? null : ((Number) thumbIdObj).longValue();
if (thumbId == null) {
if (thumbIdObj == null) {
throw new BusinessException(ErrorCode.OPERATION_ERROR, "用户未点赞");
}
Long thumbId = ((Number) thumbIdObj).longValue();
// 更新帖子点赞计数器
boolean update = blogService.lambdaUpdate()
.eq(Blog::getId, blogId)