You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.6 KiB

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<UserProductCartDTO> customerList) {
messagingTemplate.convertAndSend("/topic/public-sea", customerList);
}
/**
* 推送所有客户数据更新
*/
public void pushAllCustomersUpdate(List<UserProductCartDTO> 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);
}
}