|
@@ -4,6 +4,7 @@ import java.io.IOException;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.socket.CloseStatus;
|
|
import org.springframework.web.socket.CloseStatus;
|
|
|
import org.springframework.web.socket.TextMessage;
|
|
import org.springframework.web.socket.TextMessage;
|
|
@@ -12,15 +13,23 @@ import org.springframework.web.socket.WebSocketMessage;
|
|
|
import org.springframework.web.socket.WebSocketSession;
|
|
import org.springframework.web.socket.WebSocketSession;
|
|
|
|
|
|
|
|
import com.goafanti.common.utils.LoggerUtils;
|
|
import com.goafanti.common.utils.LoggerUtils;
|
|
|
|
|
+import com.goafanti.core.mybatis.JDBCIdGenerator;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
|
public class SystemWebSocketHandler implements WebSocketHandler {
|
|
public class SystemWebSocketHandler implements WebSocketHandler {
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private JDBCIdGenerator idGenerator;
|
|
|
|
|
|
|
|
private static final Map<String, WebSocketSession> users = new ConcurrentHashMap<>();
|
|
private static final Map<String, WebSocketSession> users = new ConcurrentHashMap<>();
|
|
|
|
|
+
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
|
|
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
|
|
|
String userId = (String) session.getAttributes().get(Constants.WEBSOCKET_USERNAME);
|
|
String userId = (String) session.getAttributes().get(Constants.WEBSOCKET_USERNAME);
|
|
|
|
|
+ if (userId==null) {
|
|
|
|
|
+ userId=idGenerator.generateId().toString();
|
|
|
|
|
+ }
|
|
|
if (userId != null) {
|
|
if (userId != null) {
|
|
|
users.put(userId, session);
|
|
users.put(userId, session);
|
|
|
LoggerUtils.debug(getClass(), "添加用户websocket:" + userId);
|
|
LoggerUtils.debug(getClass(), "添加用户websocket:" + userId);
|