package com.example.web.service; import com.example.web.dto.NotificationDTO; import com.example.web.dto.UserProductCartDTO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.messaging.simp.SimpMessagingTemplate; import org.springframework.stereotype.Service; import java.time.LocalDateTime; import java.time.ZoneOffset; import java.util.List; @Service public class RealTimeDataService { @Autowired private SimpMessagingTemplate messagingTemplate; /** * 推送客户数据更新 */ public void pushCustomerUpdate(String customerId, UserProductCartDTO customerData) { messagingTemplate.convertAndSend("/topic/customers/" + customerId, customerData); } /** * 推送公海池数据更新 */ public void pushPublicSeaUpdate(List customerList) { messagingTemplate.convertAndSend("/topic/public-sea", customerList); } /** * 推送所有客户数据更新 */ public void pushAllCustomersUpdate(List customerList) { messagingTemplate.convertAndSend("/topic/all-customers", customerList); } /** * 推送通知 */ public void pushNotification(String type, String title, String message, String customerId) { NotificationDTO notification = new NotificationDTO(); notification.setType(type); notification.setTitle(title); notification.setMessage(message); notification.setCustomerId(customerId); notification.setTimestamp(LocalDateTime.now(ZoneOffset.UTC)); messagingTemplate.convertAndSend("/topic/notifications", notification); } }