whyclxw
2025-05-28 e16302f9d475c7cc4dd18c5abf1a23cb5502e362
src/main/java/com/whyc/webSocket/HomeMonitorSocket.java
@@ -2,21 +2,18 @@
import com.whyc.config.WebSocketConfig;
import com.whyc.dto.Response;
import com.whyc.pojo.BattdischargePlan;
import com.whyc.service.BattalarmDataService;
import com.whyc.service.BattdischargePlanService;
import com.whyc.service.DevalarmDataService;
import com.whyc.service.PwrdevAlarmService;
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.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
 * 监控层首页
@@ -42,8 +39,12 @@
    private static PwrdevAlarmService pAlmService;
    private static StationInfService sinfService;
    private static Fbs9100StateService fbs9100StateService;
    private Session session;
    @Autowired
    public void setBattdischargePlanService(BattdischargePlanService planService) {
@@ -65,14 +66,24 @@
        HomeMonitorSocket.pAlmService = pAlmService;
    }
    @Autowired
    public void setStationInfService(StationInfService sinfService) {
        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;
        thread = new Thread("Thread_stationRt") {
        final int userId = user.getUId().intValue();
        //final int userId = 1087;
        thread = new Thread("Thread_homeMonitor") {
            @Override
            public void run() {
                while (runFlag && !isInterrupted()) {
@@ -83,31 +94,26 @@
                            //推送信息
                            synchronized (session) {
                                Map<String, Object> map = new HashMap<>();
                                Response planRes = new Response<>();
                                List<BattdischargePlan> planList = new ArrayList<>();
                                //今日放电任务统计
                                try {
                                    Map<String, Integer> planMap = new HashMap<>();
                                    planList = planService.getPlanStaticToday(userId);
                                    Map<Integer, List<BattdischargePlan>> disMap = planList.stream().collect(Collectors.groupingBy(BattdischargePlan::getDischargeState));
                                    for (Integer dischargeState : disMap.keySet()) {
                                        planMap.put(String.valueOf(dischargeState), disMap.get(dischargeState).size());
                                    }
                                    planMap.put("sumNum", planList.size());
                                    planRes.setII(1, planList.size() > 0, map, "今日放电任务统计");
                                } catch (Exception e) {
                                    planRes.set(1, false, "出现异常" + e.getMessage());
                                }
                                map.put("planRes", planRes);
                                map.put("planList", planList);
                                //今日实时告警
                                /*//今日放电任务统计
                                Response planRes = planService.getPlanStaticToday(userId);
                                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);
                                map.put("bDebRes", bDebRes);
                                Response bPwrRes = pAlmService.getPalmToday(userId);
                                map.put("bPwrRes", bPwrRes);
                                session.getBasicRemote().sendObject(map);
                                //追加今日计划放电的站点数
                                int stationNumOfDischargePlanToday = planService.getPlanStationToday(userId);
                                map.put("stationNumOfDischargePlanToday",stationNumOfDischargePlanToday);
                                //站点地图
                                List<StationInf> mapInMonitor = sinfService.getStationMapInMonitor(userId);
                                map.put("stationMap", mapInMonitor);
                                session.getBasicRemote().sendObject(new Response<>().set(1, map));
                            }
                            threadFlagMap.put(thread.getId(), false);
                        }