1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- package com.gyee.alarm.stomp;
- import com.gyee.alarm.model.vo.AlarmTag;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.scheduling.annotation.Scheduled;
- import org.springframework.stereotype.Service;
- import java.time.LocalDateTime;
- import java.time.format.DateTimeFormatter;
- /**
- * 定时推送服务
- */
- @Service
- public class ScheduledPushService {
- @Autowired
- private MessagePushService pushService;
- /**
- * 每分钟发送一次系统时间广播
- */
- @Scheduled(fixedRate = 1000)
- public void pushSystemTime() {
- String time = LocalDateTime.now().format(
- DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
- );
- ChatMessage message= new ChatMessage(ChatMessage.MessageType.LEAVE,
- "test1" + " 测试", "test2",null, LocalDateTime.now());
- pushService.pushToUser("test1",message);
- }
- /**
- * 每小时发送一次活跃用户统计
- */
- // @Scheduled(cron = "0 0 * * * *")
- @Scheduled(fixedRate = 1000)
- public void pushUserStats() {
- ChatMessage message= new ChatMessage(ChatMessage.MessageType.LEAVE,
- "test2" + " 离开了聊天室", "test2",null, LocalDateTime.now());
- pushService.broadcastToAll(message);
- }
- }
|