lxw
2023-08-15 160e150009b51a39fa95d9462c3798ba28d51a09
src/main/java/com/whyc/webSocket/HomeSystemSocket.java
@@ -1,17 +1,19 @@
package com.whyc.webSocket;
import com.whyc.config.WebSocketConfig;
import com.whyc.pojo.UserInf;
import com.whyc.service.StationInfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpSession;
import javax.websocket.*;
import javax.websocket.server.ServerEndpoint;
import java.util.HashMap;
import java.util.Map;
/**
 * 站点实时界面推送
 * 管理员首页
 */
@Component
@ServerEndpoint(value = "/homeSystem", encoders = WebSocketEncoder.class, configurator = WebSocketConfig.class)
@@ -38,11 +40,11 @@
    @OnOpen
    public void onOpen(Session session, EndpointConfig config) {
        this.session = session;
        /*HttpSession httpSession = (HttpSession) config.getUserProperties().get("httpSession");
        HttpSession httpSession = (HttpSession) config.getUserProperties().get("httpSession");
        UserInf user = (UserInf) httpSession.getAttribute("user");
        final int userId = user.getUId().intValue();*/
        final int userId = 1001;
        thread = new Thread("Thread_stationRt") {
        final int userId = user.getUId().intValue();
        //final int userId = 1001;
        thread = new Thread("Thread_homeSystem") {
            @Override
            public void run() {
                while (runFlag && !isInterrupted()) {
@@ -52,7 +54,7 @@
                        if (session.isOpen()) {
                            //推送信息
                            synchronized (session) {
                                session.getBasicRemote().sendObject(service.getAll(userId));
                                session.getBasicRemote().sendObject(service.getSystemAll(userId));
                            }
                            threadFlagMap.put(thread.getId(), false);
                        }