签退
All checks were successful
构建并部署 Spring Boot 应用 / build-and-deploy (push) Successful in 34m2s

This commit is contained in:
2025-10-19 13:39:45 +08:00
parent c33cbd799d
commit 272c674b4a

View File

@@ -132,10 +132,8 @@ public class LocationWebSocketHandler extends TextWebSocketHandler {
*/
public void userSignedOut(Long userId) {
if (userId != null) {
// 从所有映射中移除用户信息
sessions.remove(userId);
userFullInfos.remove(userId);
userLocations.remove(userId);
// 执行清理操作
cleanupUserData(userId);
System.out.println("用户 " + userId + " 已签退");
@@ -605,12 +603,20 @@ public class LocationWebSocketHandler extends TextWebSocketHandler {
*/
public void cleanupUserConnection(Long userId) {
if (userId != null) {
sessions.remove(userId);
// 注意这里不清理userFullInfos和userLocations因为用户可能只是断开了WebSocket连接但未签退
// 签退应该通过明确的签退操作来处理
cleanupUserData(userId);
}
}
/**
* 清理用户相关数据的通用方法
* @param userId 用户ID
*/
private void cleanupUserData(Long userId) {
sessions.remove(userId);
userFullInfos.remove(userId);
userLocations.remove(userId);
}
/**
* 定时检查并清理过期的连接和位置信息每30秒执行一次
*