diff --git a/珞珈岛-项目相关文件/luojia-island/common/src/main/java/com/luojia_channel/common/config/WebMvcConfig.java b/珞珈岛-项目相关文件/luojia-island/common/src/main/java/com/luojia_channel/common/config/WebMvcConfig.java index 4cd928c..45f7801 100644 --- a/珞珈岛-项目相关文件/luojia-island/common/src/main/java/com/luojia_channel/common/config/WebMvcConfig.java +++ b/珞珈岛-项目相关文件/luojia-island/common/src/main/java/com/luojia_channel/common/config/WebMvcConfig.java @@ -16,8 +16,10 @@ public class WebMvcConfig implements WebMvcConfigurer { registry.addInterceptor(authInterceptor) .excludePathPatterns("/user/login", "/user/register", - "/post/page", - "/post/detail" + "/post/list", + "/post/detail", + "/comment/list", + "/comment/list/reply" ); } diff --git a/珞珈岛-项目相关文件/luojia-island/common/src/main/java/com/luojia_channel/common/utils/UserContext.java b/珞珈岛-项目相关文件/luojia-island/common/src/main/java/com/luojia_channel/common/utils/UserContext.java index 596d7b8..241bd65 100644 --- a/珞珈岛-项目相关文件/luojia-island/common/src/main/java/com/luojia_channel/common/utils/UserContext.java +++ b/珞珈岛-项目相关文件/luojia-island/common/src/main/java/com/luojia_channel/common/utils/UserContext.java @@ -16,10 +16,7 @@ public final class UserContext { public static Long getUserId() { UserDTO userInfoDTO = USER_THREAD_LOCAL.get(); - if(userInfoDTO == null){ - throw new UserException("用户不存在"); - } - return userInfoDTO.getUserId(); + return Optional.ofNullable(userInfoDTO).map(UserDTO::getUserId).orElse(null); } public static String getUsername() { diff --git a/珞珈岛-项目相关文件/luojia-island/common/target/classes/com/luojia_channel/common/config/WebMvcConfig.class b/珞珈岛-项目相关文件/luojia-island/common/target/classes/com/luojia_channel/common/config/WebMvcConfig.class index 919eef6..3da92f5 100644 Binary files a/珞珈岛-项目相关文件/luojia-island/common/target/classes/com/luojia_channel/common/config/WebMvcConfig.class and b/珞珈岛-项目相关文件/luojia-island/common/target/classes/com/luojia_channel/common/config/WebMvcConfig.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/common/target/classes/com/luojia_channel/common/utils/JWTUtil.class b/珞珈岛-项目相关文件/luojia-island/common/target/classes/com/luojia_channel/common/utils/JWTUtil.class index 0d3d235..2810290 100644 Binary files a/珞珈岛-项目相关文件/luojia-island/common/target/classes/com/luojia_channel/common/utils/JWTUtil.class and b/珞珈岛-项目相关文件/luojia-island/common/target/classes/com/luojia_channel/common/utils/JWTUtil.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/common/target/classes/com/luojia_channel/common/utils/UserContext.class b/珞珈岛-项目相关文件/luojia-island/common/target/classes/com/luojia_channel/common/utils/UserContext.class index a294254..c140c14 100644 Binary files a/珞珈岛-项目相关文件/luojia-island/common/target/classes/com/luojia_channel/common/utils/UserContext.class and b/珞珈岛-项目相关文件/luojia-island/common/target/classes/com/luojia_channel/common/utils/UserContext.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/message/mq/config/RabbitMQConfig.java b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/message/mq/config/RabbitMQConfig.java new file mode 100644 index 0000000..01fc393 --- /dev/null +++ b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/message/mq/config/RabbitMQConfig.java @@ -0,0 +1,25 @@ +package com.luojia_channel.modules.message.mq.config; + +import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory; +import org.springframework.amqp.rabbit.connection.ConnectionFactory; +import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; +import org.springframework.amqp.support.converter.MessageConverter; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class RabbitMQConfig { + + @Bean + public MessageConverter jsonMessageConverter() { + return new Jackson2JsonMessageConverter(); + } + + @Bean + public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(ConnectionFactory connectionFactory, MessageConverter jsonMessageConverter) { + SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); + factory.setConnectionFactory(connectionFactory); + factory.setMessageConverter(jsonMessageConverter); + return factory; + } +} diff --git a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/message/mq/consumer/NotificationListener.java b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/message/mq/consumer/NotificationListener.java index f3c7f78..cf0b89b 100644 --- a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/message/mq/consumer/NotificationListener.java +++ b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/message/mq/consumer/NotificationListener.java @@ -1,10 +1,13 @@ package com.luojia_channel.modules.message.mq.consumer; import cn.hutool.core.bean.BeanUtil; +import com.alibaba.fastjson.JSON; import com.luojia_channel.modules.message.dto.MessageRequest; +import com.luojia_channel.modules.message.mq.MessageWrapper; import com.luojia_channel.modules.message.mq.domain.NotificationMessage; import com.luojia_channel.modules.message.server.WebSocketServer; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.amqp.rabbit.annotation.Exchange; import org.springframework.amqp.rabbit.annotation.Queue; import org.springframework.amqp.rabbit.annotation.QueueBinding; @@ -13,6 +16,7 @@ import org.springframework.stereotype.Component; @Component @RequiredArgsConstructor +@Slf4j public class NotificationListener { public static final String EXCHANGE_NAME = "notify.exchange"; public static final String QUEUE_NAME = "notify.queue"; @@ -24,13 +28,20 @@ public class NotificationListener { exchange = @Exchange(name = EXCHANGE_NAME, type = "direct"), key = ROUTING_KEY )) - - public void handleNotification(NotificationMessage message) { - MessageRequest request = BeanUtil.copyProperties(message, MessageRequest.class); - if (message.getMessageType() == 0) { - webSocketServer.sendPrivateMessage(message.getSenderId(), request); - } else { - webSocketServer.sendSystemNotification(request); + public void handleNotification(MessageWrapper wrapper) { + try { + NotificationMessage message = wrapper.getMessage(); + MessageRequest request = BeanUtil.copyProperties(message, MessageRequest.class); + Integer messageType = message.getMessageType(); + if (messageType != null && messageType == 0) { + webSocketServer.sendPrivateMessage(message.getSenderId(), request); + } else { + webSocketServer.sendSystemNotification(request); + } + } catch (Exception e) { + // 记录异常日志 + log.error("处理消息时发生异常: {}", e.getMessage(), e); + throw e; } } } diff --git a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/message/mq/domain/NotificationMessage.java b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/message/mq/domain/NotificationMessage.java index 7d96dc8..811280a 100644 --- a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/message/mq/domain/NotificationMessage.java +++ b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/message/mq/domain/NotificationMessage.java @@ -5,6 +5,8 @@ import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; +import java.io.Serializable; + @Data @AllArgsConstructor @NoArgsConstructor diff --git a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/message/server/WebSocketServer.java b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/message/server/WebSocketServer.java index 4b9d87c..32bcdf8 100644 --- a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/message/server/WebSocketServer.java +++ b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/message/server/WebSocketServer.java @@ -96,7 +96,7 @@ public class WebSocketServer { if (receiverSession != null && receiverSession.isOpen()) { sendMessage(receiverSession, JSON.toJSONString(response)); } else { - log.warn("接收方 [{}] 不在线,消息无法即时送达", receiverId); + log.info("接收方 [{}] 不在线,消息无法即时送达", receiverId); } MessageDO message = BeanUtil.copyProperties(response, MessageDO.class); messageMapper.insert(message); diff --git a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/controller/CommentController.java b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/controller/CommentController.java index 616cb10..be21f3b 100644 --- a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/controller/CommentController.java +++ b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/controller/CommentController.java @@ -17,7 +17,7 @@ import java.util.List; @RequiredArgsConstructor @RestController -@RequestMapping("/comments") +@RequestMapping("/comment") public class CommentController { private final CommentService commentService; @@ -58,4 +58,11 @@ public class CommentController { return Result.success(commentInfoDTOList); } + // 点赞评论 + @PutMapping("/like/{id}") + public Result likeComment(@PathVariable("id") Long id) { + commentService.likeComment(id); + return Result.success(); + } + } diff --git a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/controller/PostController.java b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/controller/PostController.java index 1dd7fff..e7fc622 100644 --- a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/controller/PostController.java +++ b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/controller/PostController.java @@ -7,7 +7,6 @@ import com.luojia_channel.modules.post.dto.req.PostSaveDTO; import com.luojia_channel.modules.post.dto.req.PostPageQueryDTO; import com.luojia_channel.modules.post.dto.resp.PostBasicInfoDTO; import com.luojia_channel.modules.post.dto.resp.PostInfoDTO; -import com.luojia_channel.modules.post.entity.Post; import com.luojia_channel.modules.post.service.PostService; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; @@ -22,8 +21,8 @@ public class PostController { // 创建帖子 @PostMapping - public Result createPost(@RequestBody PostSaveDTO postSaveDTO) { - postService.createPost(postSaveDTO); + public Result savePost(@RequestBody PostSaveDTO postSaveDTO) { + postService.savePost(postSaveDTO); return Result.success(); } @@ -64,4 +63,11 @@ public class PostController { public Result> pagePostOfMe(@RequestBody PostPageQueryDTO postPageQueryDTO) { return Result.success(postService.pagePostOfMe(postPageQueryDTO)); } + + // 点赞帖子 + @PutMapping("/like/{id}") + public Result likePost(@PathVariable("id") Long id) { + postService.likePost(id); + return Result.success(); + } } diff --git a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/dto/resp/CommentInfoDTO.java b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/dto/resp/CommentInfoDTO.java index b2e0663..595f9be 100644 --- a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/dto/resp/CommentInfoDTO.java +++ b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/dto/resp/CommentInfoDTO.java @@ -23,6 +23,8 @@ public class CommentInfoDTO { private Long topId; private LocalDateTime createTime; + private Boolean isLike; + private String userName; private String userAvatar; diff --git a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/service/CommentService.java b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/service/CommentService.java index 3ebeab1..3bcb599 100644 --- a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/service/CommentService.java +++ b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/service/CommentService.java @@ -21,4 +21,6 @@ public interface CommentService { PageResponse getCommentsByPostId(CommentPageQueryDTO commentPageQueryDTO); PageResponse getReplyById(CommentPageQueryDTO commentPageQueryDTO); + + void likeComment(Long id); } diff --git a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/service/PostService.java b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/service/PostService.java index 68cecb0..da9b84b 100644 --- a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/service/PostService.java +++ b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/service/PostService.java @@ -10,7 +10,7 @@ import com.luojia_channel.modules.post.entity.Post; import org.springframework.web.multipart.MultipartFile; public interface PostService extends IService { - void createPost(PostSaveDTO postSaveDTO); + void savePost(PostSaveDTO postSaveDTO); String setCover(MultipartFile file); @@ -23,4 +23,6 @@ public interface PostService extends IService { PageResponse pagePost(PostPageQueryDTO postPageQueryDTO); PageResponse pagePostOfMe(PostPageQueryDTO postPageQueryDTO); + + void likePost(Long id); } diff --git a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/service/impl/CommentServiceImpl.java b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/service/impl/CommentServiceImpl.java index 9278ddb..548139e 100644 --- a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/service/impl/CommentServiceImpl.java +++ b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/service/impl/CommentServiceImpl.java @@ -8,25 +8,28 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.luojia_channel.common.domain.page.PageResponse; import com.luojia_channel.common.exception.PostException; +import com.luojia_channel.common.exception.UserException; import com.luojia_channel.common.utils.PageUtil; +import com.luojia_channel.common.utils.RedisUtil; import com.luojia_channel.common.utils.UserContext; import com.luojia_channel.modules.message.mq.domain.NotificationMessage; import com.luojia_channel.modules.post.dto.req.CommentPageQueryDTO; import com.luojia_channel.modules.post.dto.req.CommentSaveDTO; import com.luojia_channel.modules.post.dto.resp.CommentInfoDTO; -import com.luojia_channel.modules.post.dto.resp.PostBasicInfoDTO; import com.luojia_channel.modules.post.entity.Comment; import com.luojia_channel.modules.post.entity.Post; import com.luojia_channel.modules.post.mapper.CommentMapper; +import com.luojia_channel.modules.post.mapper.PostMapper; import com.luojia_channel.modules.post.mq.producer.NotificationProducer; import com.luojia_channel.modules.post.service.CommentService; import com.luojia_channel.modules.post.utils.ValidatePostUtil; import com.luojia_channel.modules.user.entity.User; import com.luojia_channel.modules.user.mapper.UserMapper; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; -import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -38,6 +41,7 @@ import java.util.Map; import java.util.stream.Collectors; @Service +@Slf4j @RequiredArgsConstructor public class CommentServiceImpl extends ServiceImpl implements CommentService { @@ -45,19 +49,49 @@ public class CommentServiceImpl extends ServiceImpl impl private final CommentMapper commentMapper; private final UserMapper userMapper; private final NotificationProducer notificationProducer; + private final RedisUtil redisUtil; + private final PostMapper postMapper; @Override @Transactional(rollbackFor = Exception.class) public void saveComment(CommentSaveDTO commentSaveDTO) { + Long userId = UserContext.getUserId(); + if(userId == null){ + throw new UserException("用户未登录"); + } validatePostUtil.validateComment(commentSaveDTO); Comment comment = BeanUtil.copyProperties(commentSaveDTO, Comment.class); + comment.setUserId(UserContext.getUserId()); comment.setCreateTime(LocalDateTime.now()); comment.setUpdateTime(LocalDateTime.now()); if(!save(comment)){ throw new PostException("创建评论失败"); } + + Long postId = commentSaveDTO.getPostId(); + Post post = postMapper.selectById(postId); + if (post == null) { + throw new PostException("回复的帖子不存在"); + } + Long receiveUserId = post.getUserId(); Long parentCommentId = commentSaveDTO.getParentCommentId(); + // 消息通知,回复帖子 + if(!userId.equals(receiveUserId) && parentCommentId == null) { + String content = String.format("%s 回复了你的帖子: %s", + UserContext.getUsername(), + StringUtils.abbreviate(commentSaveDTO.getContent(), 20)); + NotificationMessage notificationMessage = NotificationMessage.builder() + .senderId(UserContext.getUserId()) + .senderName(UserContext.getUsername()) + .senderAvatar(UserContext.getAvatar()) + .receiverId(receiveUserId) + .content(content) + .messageType(0) + .build(); + notificationProducer.sendMessage(notificationMessage); + } if(parentCommentId != null){ + // 是回复的评论 Comment partentComment = commentMapper.selectById(parentCommentId); partentComment.setReplyCount(partentComment.getReplyCount() + 1); int update = commentMapper.updateById(partentComment); @@ -75,7 +109,7 @@ public class CommentServiceImpl extends ServiceImpl impl throw new PostException("回复顶级评论失败"); } } - // 消息通知 + // 消息通知,回复评论 String content = String.format("%s 回复了你的评论: %s", UserContext.getUsername(), StringUtils.abbreviate(commentSaveDTO.getContent(), 20)); @@ -85,6 +119,7 @@ public class CommentServiceImpl extends ServiceImpl impl .senderAvatar(UserContext.getAvatar()) .receiverId(partentComment.getUserId()) .content(content) + .messageType(0) .build(); notificationProducer.sendMessage(notificationMessage); } @@ -95,6 +130,7 @@ public class CommentServiceImpl extends ServiceImpl impl validatePostUtil.validateComment(commentSaveDTO); validatePostUtil.validateCommentOwnership(commentSaveDTO.getId()); Comment comment = BeanUtil.copyProperties(commentSaveDTO, Comment.class); + comment.setUserId(UserContext.getUserId()); comment.setUpdateTime(LocalDateTime.now()); if(!updateById(comment)){ throw new PostException("更新评论失败"); @@ -137,12 +173,45 @@ public class CommentServiceImpl extends ServiceImpl impl return getCommentInfoDTOPageResponse(commentPageQueryDTO, queryWrapper); } + @Override + public void likeComment(Long id) { + Long userId = UserContext.getUserId(); + String likeCommentKey = "comment:like:" + id; + RedisTemplate redisTemplate = redisUtil.getInstance(); + // 检查是否未点赞 + if (!isLikedComment(id)) { + // 数据库点赞记录加一 + boolean success = updateCommentLikeCount(id, 1); + if (success) { + redisTemplate.opsForSet().add(likeCommentKey, userId, System.currentTimeMillis()); + } + } else { + // 数据库点赞记录减一 + boolean success = updateCommentLikeCount(id, -1); + if (success) { + redisTemplate.opsForSet().remove(likeCommentKey, userId); + } + } + } + + private boolean isLikedComment(Long commentId) { + Long userId = UserContext.getUserId(); + String likeCommentKey = "comment:like:" + commentId; + RedisTemplate redisTemplate = redisUtil.getInstance(); + return Boolean.TRUE.equals(redisTemplate.opsForSet().isMember(likeCommentKey, userId)); + } + + private boolean updateCommentLikeCount(Long commentId, int increment) { + LambdaUpdateWrapper updateWrapper = Wrappers.lambdaUpdate(Comment.class) + .setSql("like_count = like_count + " + increment) + .eq(Comment::getId, commentId); + return commentMapper.update(null, updateWrapper) > 0; + } + private PageResponse getCommentInfoDTOPageResponse(CommentPageQueryDTO commentPageQueryDTO, LambdaQueryWrapper queryWrapper) { IPage commentPage = commentMapper.selectPage(PageUtil.convert(commentPageQueryDTO), queryWrapper); List userIds = new ArrayList<>(); - commentPage.getRecords().forEach(comment -> { - userIds.add(comment.getUserId()); - }); + commentPage.getRecords().forEach(comment -> userIds.add(comment.getUserId())); List users = userMapper.selectBatchIds(userIds); Map userMap = users.stream() .collect(Collectors.toMap(User::getId, user -> user)); @@ -151,6 +220,7 @@ public class CommentServiceImpl extends ServiceImpl impl User user = userMap.getOrDefault(comment.getUserId(), new User()); commentInfoDTO.setUserAvatar(user.getAvatar()); commentInfoDTO.setUserName(user.getUsername()); + commentInfoDTO.setIsLike(isLikedComment(comment.getId())); return commentInfoDTO; }); } diff --git a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/service/impl/PostServiceImpl.java b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/service/impl/PostServiceImpl.java index d89f44d..05b0ade 100644 --- a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/service/impl/PostServiceImpl.java +++ b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/service/impl/PostServiceImpl.java @@ -7,17 +7,15 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.luojia_channel.common.domain.page.PageResponse; import com.luojia_channel.common.exception.PostException; +import com.luojia_channel.common.exception.UserException; import com.luojia_channel.common.utils.PageUtil; import com.luojia_channel.common.utils.RedisUtil; import com.luojia_channel.common.utils.UserContext; import com.luojia_channel.modules.file.service.impl.FileServiceImpl; -import com.luojia_channel.modules.post.dto.req.CommentPageQueryDTO; import com.luojia_channel.modules.post.dto.req.PostSaveDTO; import com.luojia_channel.modules.post.dto.req.PostPageQueryDTO; -import com.luojia_channel.modules.post.dto.resp.CommentInfoDTO; import com.luojia_channel.modules.post.dto.resp.PostBasicInfoDTO; import com.luojia_channel.modules.post.dto.resp.PostInfoDTO; -import com.luojia_channel.modules.post.entity.Comment; import com.luojia_channel.modules.post.entity.Post; import com.luojia_channel.modules.post.mapper.PostMapper; import com.luojia_channel.modules.post.service.PostService; @@ -25,6 +23,7 @@ import com.luojia_channel.modules.post.utils.ValidatePostUtil; import com.luojia_channel.modules.user.entity.User; import com.luojia_channel.modules.user.mapper.UserMapper; import lombok.RequiredArgsConstructor; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; import java.time.LocalDateTime; @@ -44,15 +43,26 @@ public class PostServiceImpl extends ServiceImpl implements Po private final RedisUtil redisUtil; private final UserMapper userMapper; + // 匿名用户名与匿名头像 + private static final String ANONYMOUS_NAME = "匿名用户"; + private static final String ANONYMOUS_AVATAR = ""; + @Override - public void createPost(PostSaveDTO postSaveDTO) { + public void savePost(PostSaveDTO postSaveDTO) { + Long userId = UserContext.getUserId(); + if(userId == null){ + throw new UserException("用户未登录"); + } validatePostUtil.validatePost(postSaveDTO); Post post = BeanUtil.copyProperties(postSaveDTO, Post.class); + post.setUserId(UserContext.getUserId()); post.setCreateTime(LocalDateTime.now()); post.setUpdateTime(LocalDateTime.now()); if(!save(post)){ throw new PostException("创建帖子失败"); } + redisUtil.delete("post:detail:" + postSaveDTO.getId()); + redisUtil.delete("post:of:user:" + UserContext.getUserId()); } @Override @@ -65,10 +75,13 @@ public class PostServiceImpl extends ServiceImpl implements Po validatePostUtil.validatePost(postSaveDTO); validatePostUtil.validatePostOwnership(postSaveDTO.getId()); Post post = BeanUtil.copyProperties(postSaveDTO, Post.class); + post.setUserId(UserContext.getUserId()); post.setUpdateTime(LocalDateTime.now()); if(!updateById(post)){ throw new PostException("更新帖子失败"); } + redisUtil.delete("post:detail:" + postSaveDTO.getId()); + redisUtil.delete("post:of:user:" + UserContext.getUserId()); } @Override @@ -78,11 +91,13 @@ public class PostServiceImpl extends ServiceImpl implements Po if(delete <= 0){ throw new PostException("删除帖子失败"); } + redisUtil.delete("post:detail:" + id.toString()); + redisUtil.delete("post:of:user:" + UserContext.getUserId()); } @Override public PostInfoDTO getPostDetail(Long id) { - return redisUtil.safeGet("post:detail" + id.toString(), PostInfoDTO.class, + return redisUtil.safeGet("post:detail:" + id, PostInfoDTO.class, () -> { Post post = getById(id); if(post == null){ @@ -93,6 +108,11 @@ public class PostServiceImpl extends ServiceImpl implements Po .eq(User::getId, post.getUserId())); postInfoDTO.setUserAvatar(user.getAvatar()); postInfoDTO.setUserName(user.getUsername()); + if (post.getStatus() == 1) { // 匿名帖子 + postInfoDTO.setUserName(ANONYMOUS_NAME); + postInfoDTO.setUserAvatar(ANONYMOUS_AVATAR); + } + postInfoDTO.setIsLike(isLikedPost(post.getId())); return postInfoDTO; }, 60, TimeUnit.MINUTES); @@ -105,9 +125,7 @@ public class PostServiceImpl extends ServiceImpl implements Po .orderByDesc(Post::getCreateTime); IPage postPage = postMapper.selectPage(PageUtil.convert(postPageQueryDTO), queryWrapper); List userIds = new ArrayList<>(); - postPage.getRecords().forEach(comment -> { - userIds.add(comment.getUserId()); - }); + postPage.getRecords().forEach(comment -> userIds.add(comment.getUserId())); List users = userMapper.selectBatchIds(userIds); Map userMap = users.stream() .collect(Collectors.toMap(User::getId, user -> user)); @@ -117,6 +135,10 @@ public class PostServiceImpl extends ServiceImpl implements Po User user = userMap.getOrDefault(post.getUserId(), new User()); postBasicInfoDTO.setUserAvatar(user.getAvatar()); postBasicInfoDTO.setUserName(user.getUsername()); + if (post.getStatus() == 1) { // 匿名帖子 + postBasicInfoDTO.setUserName(ANONYMOUS_NAME); + postBasicInfoDTO.setUserAvatar(ANONYMOUS_AVATAR); + } return postBasicInfoDTO; }); } @@ -124,11 +146,63 @@ public class PostServiceImpl extends ServiceImpl implements Po @Override public PageResponse pagePostOfMe(PostPageQueryDTO postPageQueryDTO) { Long userId = UserContext.getUserId(); - LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(Post.class) - .eq(Post::getUserId, userId) - .orderByDesc(Post::getCreateTime); - IPage postPage = postMapper.selectPage(PageUtil.convert(postPageQueryDTO), queryWrapper); - return PageUtil.convert(postPage, PostBasicInfoDTO.class); + if(userId == null){ + throw new UserException("用户未登录"); + } + // 构建包含分页信息的缓存键 + String cacheKey = "post:of:user:" + userId + ":page:" + postPageQueryDTO.getCurrent() + ":size:" + postPageQueryDTO.getSize(); + return redisUtil.safeGet(cacheKey, PageResponse.class, + () -> { + LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(Post.class) + .eq(Post::getUserId, userId) + .orderByDesc(Post::getCreateTime); + IPage postPage = postMapper.selectPage(PageUtil.convert(postPageQueryDTO), queryWrapper); + return PageUtil.convert(postPage, post -> { + PostBasicInfoDTO postBasicInfoDTO = BeanUtil.copyProperties(post, PostBasicInfoDTO.class); + postBasicInfoDTO.setUserAvatar(UserContext.getAvatar()); + postBasicInfoDTO.setUserName(UserContext.getUsername()); + if (post.getStatus() == 1) { // 匿名帖子 + postBasicInfoDTO.setUserName(ANONYMOUS_NAME); + postBasicInfoDTO.setUserAvatar(ANONYMOUS_AVATAR); + } + return postBasicInfoDTO; + }); + }, + 60, TimeUnit.MINUTES); + } + + private boolean isLikedPost(Long postId){ + Long userId = UserContext.getUserId(); + if(userId == null){ + return false; + } + String likeBlogKey = "post:like:" + postId; + RedisTemplate redisTemplate = redisUtil.getInstance(); + return Boolean.TRUE.equals(redisTemplate.opsForSet().isMember(likeBlogKey, userId)); + } + + @Override + public void likePost(Long id) { + Long userId = UserContext.getUserId(); + if(userId == null){ + throw new UserException("用户未登录"); + } + String likeBlogKey = "post:like:" + id; + RedisTemplate redisTemplate = redisUtil.getInstance(); + //没点赞 + if(!isLikedPost(id)){ + //数据库点赞记录加一 + boolean success = update().setSql("liked = liked + 1").eq("id",id).update(); + if(success){ + redisTemplate.opsForSet().add(likeBlogKey, userId, System.currentTimeMillis()); + } + }else{ + //数据库点赞记录减一 + boolean success = update().setSql("liked = liked - 1").eq("id",id).update(); + if(success){ + redisTemplate.opsForSet().remove(likeBlogKey, userId); + } + } } } diff --git a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/utils/ValidatePostUtil.java b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/utils/ValidatePostUtil.java index ba5236b..aa073e4 100644 --- a/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/utils/ValidatePostUtil.java +++ b/珞珈岛-项目相关文件/luojia-island/service/src/main/java/com/luojia_channel/modules/post/utils/ValidatePostUtil.java @@ -2,6 +2,7 @@ package com.luojia_channel.modules.post.utils; import cn.hutool.core.util.StrUtil; import com.luojia_channel.common.exception.PostException; +import com.luojia_channel.common.exception.UserException; import com.luojia_channel.common.utils.UserContext; import com.luojia_channel.modules.post.dto.req.CommentSaveDTO; import com.luojia_channel.modules.post.dto.req.PostSaveDTO; @@ -39,6 +40,9 @@ public class ValidatePostUtil { public void validatePostOwnership(Long id){ Long userId = UserContext.getUserId(); + if(userId == null){ + throw new UserException("用户未登录"); + } if(id == null){ throw new PostException("传入id不能为空"); } @@ -68,6 +72,9 @@ public class ValidatePostUtil { public void validateCommentOwnership(Long id) { Long userId = UserContext.getUserId(); + if(userId == null){ + throw new UserException("用户未登录"); + } if(id == null){ throw new PostException("传入id不能为空"); } diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/interact/controller/ChatController.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/interact/controller/ChatController.class new file mode 100644 index 0000000..72df823 Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/interact/controller/ChatController.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/interact/controller/FollowController.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/interact/controller/FollowController.class new file mode 100644 index 0000000..7c94e6c Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/interact/controller/FollowController.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/interact/entity/Follow.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/interact/entity/Follow.class new file mode 100644 index 0000000..6582d08 Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/interact/entity/Follow.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/interact/mapper/FollowMapper.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/interact/mapper/FollowMapper.class new file mode 100644 index 0000000..dad2710 Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/interact/mapper/FollowMapper.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/interact/service/FollowService.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/interact/service/FollowService.class new file mode 100644 index 0000000..41761a5 Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/interact/service/FollowService.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/interact/service/impl/FollowServiceImpl.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/interact/service/impl/FollowServiceImpl.class new file mode 100644 index 0000000..4fd57cc Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/interact/service/impl/FollowServiceImpl.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/config/WebSocketConfig.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/config/WebSocketConfig.class new file mode 100644 index 0000000..a827b04 Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/config/WebSocketConfig.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/dto/MessageRequest$MessageRequestBuilder.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/dto/MessageRequest$MessageRequestBuilder.class new file mode 100644 index 0000000..60a681d Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/dto/MessageRequest$MessageRequestBuilder.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/dto/MessageRequest.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/dto/MessageRequest.class new file mode 100644 index 0000000..95b232e Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/dto/MessageRequest.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/dto/MessageResponse$MessageResponseBuilder.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/dto/MessageResponse$MessageResponseBuilder.class new file mode 100644 index 0000000..12d5eab Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/dto/MessageResponse$MessageResponseBuilder.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/dto/MessageResponse.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/dto/MessageResponse.class new file mode 100644 index 0000000..c723f83 Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/dto/MessageResponse.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/entity/MessageDO.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/entity/MessageDO.class new file mode 100644 index 0000000..84847ae Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/entity/MessageDO.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mapper/MessageMapper.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mapper/MessageMapper.class new file mode 100644 index 0000000..31ea2eb Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mapper/MessageMapper.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mq/AbstractSendProduceTemplate.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mq/AbstractSendProduceTemplate.class new file mode 100644 index 0000000..cb56f9d Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mq/AbstractSendProduceTemplate.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mq/BaseSendExtendDTO$BaseSendExtendDTOBuilder.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mq/BaseSendExtendDTO$BaseSendExtendDTOBuilder.class new file mode 100644 index 0000000..e01512b Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mq/BaseSendExtendDTO$BaseSendExtendDTOBuilder.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mq/BaseSendExtendDTO.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mq/BaseSendExtendDTO.class new file mode 100644 index 0000000..4a1f3d2 Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mq/BaseSendExtendDTO.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mq/MessageWrapper$MessageWrapperBuilder.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mq/MessageWrapper$MessageWrapperBuilder.class new file mode 100644 index 0000000..a62f142 Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mq/MessageWrapper$MessageWrapperBuilder.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mq/MessageWrapper.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mq/MessageWrapper.class new file mode 100644 index 0000000..17c6378 Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mq/MessageWrapper.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mq/config/RabbitMQConfig.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mq/config/RabbitMQConfig.class new file mode 100644 index 0000000..760c8f6 Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mq/config/RabbitMQConfig.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mq/consumer/NotificationListener.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mq/consumer/NotificationListener.class new file mode 100644 index 0000000..46dc55c Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mq/consumer/NotificationListener.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mq/domain/NotificationMessage$NotificationMessageBuilder.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mq/domain/NotificationMessage$NotificationMessageBuilder.class new file mode 100644 index 0000000..4b2e805 Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mq/domain/NotificationMessage$NotificationMessageBuilder.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mq/domain/NotificationMessage.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mq/domain/NotificationMessage.class new file mode 100644 index 0000000..d535fb2 Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/mq/domain/NotificationMessage.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/server/WebSocketServer.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/server/WebSocketServer.class new file mode 100644 index 0000000..11faa8d Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/message/server/WebSocketServer.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/controller/CommentController.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/controller/CommentController.class new file mode 100644 index 0000000..2d192a7 Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/controller/CommentController.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/controller/PostController.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/controller/PostController.class index e6aa9dc..f11bd91 100644 Binary files a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/controller/PostController.class and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/controller/PostController.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/dto/req/CommentPageQueryDTO.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/dto/req/CommentPageQueryDTO.class new file mode 100644 index 0000000..1fa052e Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/dto/req/CommentPageQueryDTO.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/dto/req/CommentSaveDTO$CommentSaveDTOBuilder.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/dto/req/CommentSaveDTO$CommentSaveDTOBuilder.class new file mode 100644 index 0000000..f72b0e2 Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/dto/req/CommentSaveDTO$CommentSaveDTOBuilder.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/dto/req/CommentSaveDTO.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/dto/req/CommentSaveDTO.class new file mode 100644 index 0000000..df00a6f Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/dto/req/CommentSaveDTO.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/dto/req/PostSaveDTO.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/dto/req/PostSaveDTO.class index 25359fe..4c53328 100644 Binary files a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/dto/req/PostSaveDTO.class and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/dto/req/PostSaveDTO.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/dto/resp/CommentInfoDTO$CommentInfoDTOBuilder.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/dto/resp/CommentInfoDTO$CommentInfoDTOBuilder.class new file mode 100644 index 0000000..a6f43a0 Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/dto/resp/CommentInfoDTO$CommentInfoDTOBuilder.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/dto/resp/CommentInfoDTO.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/dto/resp/CommentInfoDTO.class new file mode 100644 index 0000000..aeb04b2 Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/dto/resp/CommentInfoDTO.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/dto/resp/PostBasicInfoDTO.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/dto/resp/PostBasicInfoDTO.class index 8cd50b3..d6efdf6 100644 Binary files a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/dto/resp/PostBasicInfoDTO.class and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/dto/resp/PostBasicInfoDTO.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/dto/resp/PostInfoDTO.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/dto/resp/PostInfoDTO.class new file mode 100644 index 0000000..710aca9 Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/dto/resp/PostInfoDTO.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/entity/Comment$CommentBuilder.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/entity/Comment$CommentBuilder.class new file mode 100644 index 0000000..6f7d7fa Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/entity/Comment$CommentBuilder.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/entity/Comment.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/entity/Comment.class new file mode 100644 index 0000000..31431b9 Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/entity/Comment.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/mapper/CommentMapper.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/mapper/CommentMapper.class new file mode 100644 index 0000000..03448b5 Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/mapper/CommentMapper.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/mq/producer/NotificationProducer.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/mq/producer/NotificationProducer.class new file mode 100644 index 0000000..6288652 Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/mq/producer/NotificationProducer.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/service/CommentService.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/service/CommentService.class new file mode 100644 index 0000000..3587a11 Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/service/CommentService.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/service/PostService.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/service/PostService.class index 48c20d5..a82b2f1 100644 Binary files a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/service/PostService.class and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/service/PostService.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/service/impl/CommentServiceImpl.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/service/impl/CommentServiceImpl.class new file mode 100644 index 0000000..b9783a1 Binary files /dev/null and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/service/impl/CommentServiceImpl.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/service/impl/PostServiceImpl.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/service/impl/PostServiceImpl.class index 4a4b405..0fa5568 100644 Binary files a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/service/impl/PostServiceImpl.class and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/service/impl/PostServiceImpl.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/utils/ValidatePostUtil.class b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/utils/ValidatePostUtil.class index 19b4373..2336248 100644 Binary files a/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/utils/ValidatePostUtil.class and b/珞珈岛-项目相关文件/luojia-island/service/target/classes/com/luojia_channel/modules/post/utils/ValidatePostUtil.class differ diff --git a/珞珈岛-项目相关文件/luojia-island/service/target/classes/db/luojia_channel.sql b/珞珈岛-项目相关文件/luojia-island/service/target/classes/db/luojia_channel.sql index b801e0d..ac2a900 100644 --- a/珞珈岛-项目相关文件/luojia-island/service/target/classes/db/luojia_channel.sql +++ b/珞珈岛-项目相关文件/luojia-island/service/target/classes/db/luojia_channel.sql @@ -101,10 +101,11 @@ DROP TABLE IF EXISTS `comment`; CREATE TABLE `comment` ( `id` BIGINT PRIMARY KEY AUTO_INCREMENT COMMENT '主键ID', `content` TEXT NOT NULL COMMENT '评论内容', + `like_count` INT DEFAULT 0 COMMENT '点赞数', + `reply_count` INT DEFAULT 0 COMMENT '回复数', `user_id` BIGINT NOT NULL COMMENT '评论用户ID', - `post_type` VARCHAR(20) NOT NULL COMMENT '帖子类型(post/video)', `post_id` BIGINT NOT NULL COMMENT '关联的帖子ID', - `parent_comment_id` BIGINT COMMENT '父评论ID', + `parent_comment_id` BIGINT DEFAULT 0 COMMENT '父评论ID', `top_id` BIGINT COMMENT '顶层评论ID', `create_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', `update_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', @@ -151,3 +152,27 @@ CREATE TABLE `view_record` ( INDEX idx_post_type (post_type), INDEX idx_post_id (post_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='浏览记录表'; + +## 私信消息表 +DROP TABLE IF EXISTS `message`; +CREATE TABLE message ( + id BIGINT AUTO_INCREMENT PRIMARY KEY, + message_type TINYINT NOT NULL COMMENT '0-私聊, 1-系统消息', + content TEXT NOT NULL, + sender_id BIGINT NOT NULL, + receiver_id BIGINT NOT NULL, + create_time DATETIME NOT NULL, + INDEX idx_sender_id (sender_id), + INDEX idx_receiver_id (receiver_id), + INDEX idx_create_time (create_time) +); + +## 关注表 +DROP TABLE IF EXISTS `follow`; +CREATE TABLE `follow` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键', + `user_id` bigint(20) UNSIGNED NOT NULL COMMENT '用户id', + `follow_user_id` bigint(20) UNSIGNED NOT NULL COMMENT '关联的用户id', + `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='关注表';