whyclxw
2025-05-28 e16302f9d475c7cc4dd18c5abf1a23cb5502e362
src/main/java/com/whyc/webSocket/ScreenForNWKMSocket.java
@@ -48,6 +48,12 @@
    private static PowerInfService powerInfService;
    //private static BatttestdataInfService testInfService;
    private static BatttestdataInfService batttestdataInfService;
    private static BattRtstateService battRtStateService;
    @Autowired
    public void setPowerAlarmService(PwrdevAlarmService powerAlarmService) {
        ScreenForNWKMSocket.powerAlarmService = powerAlarmService;
@@ -84,13 +90,23 @@
        ScreenForNWKMSocket.powerInfService = powerInfService;
    }
    @Autowired
    public void setBatttestdataInfService(BatttestdataInfService batttestdataInfService) {
        ScreenForNWKMSocket.batttestdataInfService = batttestdataInfService;
    }
    @Autowired
    public void setBattRtStateService(BattRtstateService battRtStateService) {
        ScreenForNWKMSocket.battRtStateService = battRtStateService;
    }
    @OnOpen
    public void onOpen(Session session, EndpointConfig config){
        this.session = session;
        //HttpSession httpSession = (HttpSession) config.getUserProperties().get("httpSession");
        //UserInf user = (UserInf) httpSession.getAttribute("user");
        //final int userId = user.getUId().intValue();
        final int userId = 1001;
        HttpSession httpSession = (HttpSession) config.getUserProperties().get("httpSession");
        UserInf user = (UserInf) httpSession.getAttribute("user");
        final int userId = user.getUId().intValue();
        //final int userId = 1001;
        Thread thread = new Thread() {
            @Override
            public void run() {
@@ -98,7 +114,7 @@
                    Map<String, Object> res = new HashMap<>();
                    while (!currentThread().isInterrupted()) {
                        ThreadPoolExecutor poolExecutor = ThreadPoolExecutorFactory.getPoolExecutor();
                        CountDownLatch latch = new CountDownLatch(9);
                        CountDownLatch latch = new CountDownLatch(8);
                        poolExecutor.execute(()->{
                            //1.统计:电池统计 分为品牌和标称电压
                            Response res_battGroupInfo = new Response();
@@ -128,7 +144,7 @@
                        });
                        poolExecutor.execute(()->{
                            //2.统计:设备状态
                            Response<Map> res_devStates = fbs9100StateService.getBTSEquipStatus2(userId);
                            Response<Map> res_devStates = fbs9100StateService.getBTSEquipStatus2(userId,2);
                            res.put("devStates", res_devStates);
                            latch.countDown();
                        });
@@ -146,23 +162,16 @@
                            latch.countDown();
                        });
                        //5.统计:每个省的机房数统计
                        /*//5.统计:每个省的机房数统计
                        poolExecutor.execute(()->{
                            Response res_stationCount = stationService.getProvinceCountMap(userId);
                            res.put("stationCount", res_stationCount);
                            latch.countDown();
                        });
                        });*/
                        poolExecutor.execute(()->{
                            //6.统计:实时告警 跟告警统计逻辑一致
                            Response res_alarm = new Response();
                            Map<String, Integer> devAlarmNumMap = new HashMap<>();
                            try {
                                Response realAlarmList = battAlarmDataService.getRealAlarmListWithLevel1(userId);
                                res_alarm.setII(1,true,realAlarmList,null);
                            }catch (Exception e){
                                res_alarm.set(1,false,"发生异常:"+e.getCause());
                            }
                            res.put("realTimeAlarm", res_alarm);
                            //6.统计:实时放电信息 正在放电的电池信息展示
                            Response dischargingList = battRtStateService.getDischargingList(userId);
                            res.put("dischargingBattery", dischargingList);
                            latch.countDown();
                        });
                        poolExecutor.execute(()->{
@@ -178,17 +187,25 @@
                            latch.countDown();
                        });
                        poolExecutor.execute(()->{
                            //8.统计:TODO 能效统计
                            /*//8.统计:能效统计,默认取五年的能效
                            Response resNX = new Response();
                            try {
                                resNX=testInfService.getEnergyStatistics_nj(5,userId);
                            }catch (Exception e){
                                resNX.set(1,false,"发生异常:"+e.getCause());
                            }
                            res.put("nx", resNX);
                            res.put("nx", resNX);*/
                            //测试信息
                            Response resTestdataInfAnalysis = new Response();
                            try {
                                resTestdataInfAnalysis = batttestdataInfService.getTestdataInfAnalysis(userId);
                            }catch (Exception e){
                                resTestdataInfAnalysis.set(1,false,"发生异常:"+e.getCause());
                            }
                            res.put("resTestdataInfAnalysis", resTestdataInfAnalysis);
                            latch.countDown();
                        });
                        poolExecutor.execute(()->{
                        /*poolExecutor.execute(()->{
                            //9.统计:告警统计 电源,设备,电池
                            Response res_devAlarmNum = new Response();
                            Map<String, Integer> devAlarmNumMap = new HashMap<>();
@@ -205,6 +222,19 @@
                            }
                            res.put("devAlarmNum", res_devAlarmNum);
                            latch.countDown();
                        });*/
                        poolExecutor.execute(()->{
                            //9-2.统计:告警统计 级别及类型统计
                            Response res_alarmLevel = new Response();
                            Map<String, Integer> devAlarmNumMap = new HashMap<>();
                            try {
                                Response alarmsCountByLevel = battAlarmDataService.getByLevel(userId);
                                res_alarmLevel.setII(1,true,alarmsCountByLevel,null);
                            }catch (Exception e){
                                res_alarmLevel.set(1,false,"发生异常:"+e.getCause());
                            }
                            res.put("alarmsLevel", res_alarmLevel);
                            latch.countDown();
                        });
                        latch.await(10, TimeUnit.MINUTES);