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