feat: 增加通知系统、RabbitMQ集成及Docker一键部署脚本
All checks were successful
test/timeline-server/pipeline/head This commit looks good
All checks were successful
test/timeline-server/pipeline/head This commit looks good
1. 新增通知中心功能,支持好友请求、评论、点赞等多种通知类型的持久化与推送 2. 集成 RabbitMQ 用于异步处理动态日志,解耦动态服务与日志记录逻辑 3. 提供完整的 Docker Compose 部署方案及一键启动/停止脚本(Shell/Bat) 4. 优化文件服务,增加图片上传时的自动压缩处理以节省存储空间 5. 增强动态服务,支持通过 shareId 公开访问动态项及关键词搜索功能 6. 完善代码健壮性,在关键业务 Service 层增加 @Transactional 事务控制
This commit is contained in:
@@ -3,7 +3,11 @@ package com.timeline.user.controller;
|
||||
import com.timeline.common.response.ResponseEntity;
|
||||
import com.timeline.common.utils.UserContextUtils;
|
||||
import com.timeline.user.ws.WsNotifyService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import com.timeline.user.dto.NotificationPayload;
|
||||
import com.timeline.user.dto.NotificationType;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@@ -14,7 +18,7 @@ import java.util.Map;
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/user/ws/test")
|
||||
@RequestMapping("/user/ws-test")
|
||||
public class WebSocketTestController {
|
||||
|
||||
@Autowired
|
||||
@@ -29,16 +33,21 @@ public class WebSocketTestController {
|
||||
if (userId == null || userId.isEmpty()) {
|
||||
return ResponseEntity.error(401, "未获取到用户身份");
|
||||
}
|
||||
|
||||
|
||||
log.info("测试推送通知给用户: {}", userId);
|
||||
// 确保消息包含必要字段
|
||||
if (!message.containsKey("timestamp")) {
|
||||
message.put("timestamp", System.currentTimeMillis());
|
||||
|
||||
NotificationPayload payload = new NotificationPayload();
|
||||
payload.setContent((String) message.getOrDefault("content", "Test Message"));
|
||||
payload.setCreateTime(java.time.LocalDateTime.now());
|
||||
|
||||
String typeStr = (String) message.getOrDefault("type", "SYSTEM_MESSAGE");
|
||||
try {
|
||||
payload.setType(NotificationType.valueOf(typeStr));
|
||||
} catch (IllegalArgumentException e) {
|
||||
payload.setType(NotificationType.SYSTEM_MESSAGE);
|
||||
}
|
||||
if (!message.containsKey("type")) {
|
||||
message.put("type", "test");
|
||||
}
|
||||
wsNotifyService.sendNotificationToUser(userId, message);
|
||||
|
||||
wsNotifyService.sendNotificationToUser(userId, payload);
|
||||
return ResponseEntity.success("通知已推送给用户: " + userId);
|
||||
}
|
||||
|
||||
@@ -50,7 +59,19 @@ public class WebSocketTestController {
|
||||
@PathVariable String targetUserId,
|
||||
@RequestBody Map<String, Object> message) {
|
||||
log.info("测试推送通知给用户: {}", targetUserId);
|
||||
wsNotifyService.sendNotificationToUser(targetUserId, message);
|
||||
|
||||
NotificationPayload payload = new NotificationPayload();
|
||||
payload.setContent((String) message.getOrDefault("content", "Test Message"));
|
||||
payload.setCreateTime(java.time.LocalDateTime.now());
|
||||
|
||||
String typeStr = (String) message.getOrDefault("type", "SYSTEM_MESSAGE");
|
||||
try {
|
||||
payload.setType(NotificationType.valueOf(typeStr));
|
||||
} catch (IllegalArgumentException e) {
|
||||
payload.setType(NotificationType.SYSTEM_MESSAGE);
|
||||
}
|
||||
|
||||
wsNotifyService.sendNotificationToUser(targetUserId, payload);
|
||||
return ResponseEntity.success("通知已推送");
|
||||
}
|
||||
|
||||
@@ -78,4 +99,3 @@ public class WebSocketTestController {
|
||||
return ResponseEntity.success("聊天消息已推送");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user