update 广播模块,新增广播按钮和跳转路径。定时任务新增开关功能

This commit is contained in:
yyb
2025-07-08 14:22:25 +08:00
parent c698a8244c
commit a51771db2e
21 changed files with 493 additions and 95 deletions

View File

@@ -20,6 +20,7 @@ import org.springframework.messaging.simp.stomp.StompHeaderAccessor;
import org.springframework.messaging.support.ChannelInterceptor;
import org.springframework.messaging.support.MessageHeaderAccessor;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@@ -77,6 +78,7 @@ public class WebsocketChannelInterceptor implements ChannelInterceptor {
//获取链接建立时的请求头信息
StompHeaderAccessor accessor = StompHeaderAccessor.wrap(message);
if (accessor.getCommand() == StompCommand.CONNECT ) {
System.out.println("yyb-开始链接"+new Date());
StompHeaderAccessor mha = MessageHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
if(mha == null){
throw new MessageDeliveryException(ExceptionEnum.fromCode(ExceptionEnum.SET_PRINCIPAL_FAIL));
@@ -90,6 +92,7 @@ public class WebsocketChannelInterceptor implements ChannelInterceptor {
ipLimit(accessor,type,email);
//链接请求头中用户信息存入stomp中
mha.setUser(new StompPrincipal(email,type,true));
System.out.println("yyb-链接成功"+new Date());
}
if (accessor.getCommand() == StompCommand.SUBSCRIBE) {
LOGGER.info("------------websocket subscribe message");

View File

@@ -9,7 +9,11 @@ import com.m2pool.chat.entity.ChatRoom;
import com.m2pool.chat.mapper.ChatMessageMapper;
import com.m2pool.chat.mapper.ChatRoomMapper;
import com.m2pool.chat.service.ChatMessageHistoryService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
@@ -25,7 +29,9 @@ import java.util.stream.Collectors;
* @Author yyb
* @Date 2025/4/15 11:51
*/
@Data
@Configuration
@ConfigurationProperties(prefix = "task")
@EnableScheduling
public class ChatTask {
@@ -37,9 +43,15 @@ public class ChatTask {
@Autowired
private ChatRoomMapper chatRoomMapper;
private boolean enable;
// @Scheduled(cron = "0 0/1 * * * ?")
@Scheduled(cron = "0 15 1 * * ?")
public void chatMessageDataSeparatedForHotAndCold(){
if(!enable){
System.out.println("ChatTask 定时任务已关闭请在nacos修改配置");
return;
}
int pageNum = 1;
int pageSize = 1000; // 每批处理数量
List<ChatMessage> chatMessages;
@@ -82,8 +94,12 @@ public class ChatTask {
@Scheduled(cron = "0 16 1 * * ?")
//@Scheduled(cron = "0 0/1 * * * ?")
public void clearTouristDatas(){
if(!enable){
return;
}
chatMessageMapper.delete(new LambdaUpdateWrapper<ChatMessage>()
.like(ChatMessage::getSendEmail, "guest_"));
chatRoomMapper.delete(new LambdaUpdateWrapper<ChatRoom>().like(ChatRoom::getUserOneEmail, "guest_"));
}
}