lxw
2023-08-15 160e150009b51a39fa95d9462c3798ba28d51a09
src/main/java/com/whyc/webSocket/HomeMonitorSocket.java
@@ -3,10 +3,12 @@
import com.whyc.config.WebSocketConfig;
import com.whyc.dto.Response;
import com.whyc.pojo.StationInf;
import com.whyc.pojo.UserInf;
import com.whyc.service.*;
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;
@@ -38,7 +40,11 @@
    private static PwrdevAlarmService pAlmService;
    private static StationInfService sinfService;
    private static Fbs9100StateService fbs9100StateService;
    private Session session;
    @Autowired
    public void setBattdischargePlanService(BattdischargePlanService planService) {
@@ -65,13 +71,18 @@
        HomeMonitorSocket.sinfService = sinfService;
    }
    @Autowired
    public void setFbs9100StateService(Fbs9100StateService fbs9100StateService) {
        HomeMonitorSocket.fbs9100StateService = fbs9100StateService;
    }
    @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;
        final int userId = user.getUId().intValue();
        //final int userId = 1087;
        thread = new Thread("Thread_homeMonitor") {
            @Override
            public void run() {
@@ -83,10 +94,13 @@
                            //推送信息
                            synchronized (session) {
                                Map<String, Object> map = new HashMap<>();
                                //今日放电任务统计
                                /*//今日放电任务统计
                                Response planRes = planService.getPlanStaticToday(userId);
                                map.put("planRes", planRes);
                                //今日实时告警
                                map.put("planRes", planRes);*/
                                //今日放电站点统计
                                Response chargeRes = fbs9100StateService.getChargeStaticToday(userId);
                                map.put("chargeRes", chargeRes);
                                //今日实时告警(实时告警)
                                Response bAlmRes = bAlmService.getBalmToday(userId);
                                map.put("bAlmRes", bAlmRes);
                                Response bDebRes = dAlmService.getDalmToday(userId);
@@ -94,8 +108,8 @@
                                Response bPwrRes = pAlmService.getPalmToday(userId);
                                map.put("bPwrRes", bPwrRes);
                                //站点地图
                                List<StationInf> mapAndWorkStateList = sinfService.getStationMapAndWorkState(userId);
                                map.put("stationMap", mapAndWorkStateList);
                                List<StationInf> mapInMonitor = sinfService.getStationMapInMonitor(userId);
                                map.put("stationMap", mapInMonitor);
                                session.getBasicRemote().sendObject(new Response<>().set(1, map));
                            }
                            threadFlagMap.put(thread.getId(), false);