lxw
2023-08-15 160e150009b51a39fa95d9462c3798ba28d51a09
src/main/java/com/whyc/webSocket/ScreenSocket.java
@@ -2,6 +2,7 @@
import com.whyc.config.WebSocketConfig;
import com.whyc.dto.Response;
import com.whyc.factory.ThreadPoolExecutorFactory;
import com.whyc.pojo.Battinf;
import com.whyc.pojo.UserInf;
import com.whyc.service.*;
@@ -15,6 +16,9 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
@@ -37,6 +41,10 @@
    private static BattInfService battInfService;
    private static BattEnduranceService battEnduranceService;
    private static BaoJiGroupService baoJiGroupService;
    @Autowired
    public void setPowerAlarmService(PwrdevAlarmService powerAlarmService) {
        ScreenSocket.powerAlarmService = powerAlarmService;
@@ -58,19 +66,118 @@
        ScreenSocket.battInfService = battInfService;
    }
    @Autowired
    public void setBattEnduranceService(BattEnduranceService battEnduranceService) {
        ScreenSocket.battEnduranceService = battEnduranceService;
    }
    @Autowired
    public void setBaoJiGroupService(BaoJiGroupService baoJiGroupService) {
        ScreenSocket.baoJiGroupService = baoJiGroupService;
    }
    @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;
        Thread thread = new Thread() {
            @Override
            public void run() {
                try {
                    Map<String, Object> res = new HashMap<>();
                    while (!currentThread().isInterrupted()) {
                        //一体   告警:交流ABC
                        ThreadPoolExecutor poolExecutor = ThreadPoolExecutorFactory.getPoolExecutor();
                        CountDownLatch latch = new CountDownLatch(9);
                        poolExecutor.execute(()->{
                            //一体   告警:交流ABC
                            Response res_acABC = powerAlarmService.getAcABCAnalysis(userId);
                            res.put("acABC", res_acABC);
                            latch.countDown();
                        });
                        poolExecutor.execute(()->{
                            //一体   组端容量
                            //Response res_monCapacityLowAnalysis = battAlarmDataService.getMonCapacityLowAnalysis(userId);
                            Response res_groupCap = battEnduranceService.getGroupCapList(userId);
                            res.put("groupCap", res_groupCap);
                            latch.countDown();
                        });
                        poolExecutor.execute(()->{
                            //一体   告警:单体温度内阻温度
                            Response res_monVRTAnalysis = battAlarmDataService.getMonVRTAnalysis(userId);
                            res.put("monVRTAnalysis", res_monVRTAnalysis);
                            latch.countDown();
                        });
                        poolExecutor.execute(()->{
                            //一体   统计:三种设备类型 告警数统计
                            Response res_devAlarmNum = new Response();
                            Map<String, Integer> devAlarmNumMap = new HashMap<>();
                            try {
                                int battAlarmNum = battAlarmDataService.getRealTimeWithLevel1(userId).getCode();
                                int devAlarmNum = devAlarmDataService.getRealTimeWithLevel1(userId);
                                int powerAlarmNum = powerAlarmService.getRealTimeWithLevel1(userId);
                                devAlarmNumMap.put("battAlarmNum",battAlarmNum);
                                devAlarmNumMap.put("devAlarmNum",devAlarmNum);
                                devAlarmNumMap.put("powerAlarmNum",powerAlarmNum);
                                res_devAlarmNum.setII(1,true,devAlarmNumMap,null);
                            }catch (Exception e){
                                res_devAlarmNum.set(1,false,"发生异常:"+e.getCause());
                            }
                            res.put("devAlarmNum", res_devAlarmNum);
                            latch.countDown();
                        });
                        poolExecutor.execute(()->{
                            //一体   统计:电池统计 分为品牌和标称电压
                            Response res_battGroupInfo = new Response();
                            try {
                                List<Battinf> battinfList = battInfService.getBattGroupList(userId);
                                Map<String, List<Battinf>> battProducerMap = battinfList.stream().collect(Collectors.groupingBy(Battinf::getBattProducer));
                                Map<Float, List<Battinf>> battMonVolStdMap = battinfList.stream().collect(Collectors.groupingBy(Battinf::getMonVolStd));
                                Map<String, Object> battGroupProducerMap = new HashMap<>();
                                Map<String, Object> battGroupMonVolMap = new HashMap<>();
                                Map<String, Object> battGroupInfoMap = new HashMap<>();
                                int battSize = battinfList.size();
                                for (String producer : battProducerMap.keySet()) {
                                    battGroupProducerMap.put(producer, battProducerMap.get(producer).size());
                                }
                                for (Float monVolStd : battMonVolStdMap.keySet()) {
                                    battGroupMonVolMap.put(Float.toString(monVolStd), battMonVolStdMap.get(monVolStd).size());
                                }
                                battGroupInfoMap.put("producer",battGroupProducerMap);
                                battGroupInfoMap.put("monVol",battGroupMonVolMap);
                                battGroupInfoMap.put("totalNum",battSize);
                                res_battGroupInfo.setII(1,true,battGroupInfoMap,null);
                            }catch (Exception e){
                                res_battGroupInfo.set(1,false,"发生异常:"+e.getCause());
                            }
                            res.put("battGroupInfo", res_battGroupInfo);
                            latch.countDown();
                        });
                        poolExecutor.execute(()->{
                            //一体   统计:设备状态
                            Response<Map> res_devStates = fbs9100StateService.getBTSEquipStatus2(userId);
                            res.put("devStates", res_devStates);
                            latch.countDown();
                        });
                        poolExecutor.execute(()->{
                            //一体   统计:各种设备类型总数 电池 设备 电源 站点
                            Response<Map> res_devCountMap = battInfService.getDevCountMap(userId);
                            res.put("devCountMap", res_devCountMap);
                            latch.countDown();
                        });
                        poolExecutor.execute(()->{
                            Response res_endurance = battEnduranceService.getEnduranceTimeLong(userId,4);
                            res.put("enduranceLow", res_endurance);
                            latch.countDown();
                        });
                        poolExecutor.execute(()->{
                            Response res_groupInfo = baoJiGroupService.getGroupWithStationAndAlarmForScreen(userId);
                            res.put("res_groupInfo", res_groupInfo);
                            latch.countDown();
                        });
                        /*//一体   告警:交流ABC
                        Response res_acABC = powerAlarmService.getAcABCAnalysis(userId);
                        //一体   告警:单体容量
                        Response res_monCapacityLowAnalysis = battAlarmDataService.getMonCapacityLowAnalysis(userId);
@@ -97,13 +204,19 @@
                            List<Battinf> battinfList = battInfService.getBattGroupList(userId);
                            Map<String, List<Battinf>> battProducerMap = battinfList.stream().collect(Collectors.groupingBy(Battinf::getBattProducer));
                            Map<Float, List<Battinf>> battMonVolStdMap = battinfList.stream().collect(Collectors.groupingBy(Battinf::getMonVolStd));
                            Map<String, Object> battGroupProducerMap = new HashMap<>();
                            Map<String, Object> battGroupMonVolMap = new HashMap<>();
                            Map<String, Object> battGroupInfoMap = new HashMap<>();
                            int battSize = battinfList.size();
                            for (String producer : battProducerMap.keySet()) {
                                battGroupInfoMap.put(producer, battProducerMap.get(producer).size());
                                battGroupProducerMap.put(producer, battProducerMap.get(producer).size());
                            }
                            for (Float monVolStd : battMonVolStdMap.keySet()) {
                                battGroupInfoMap.put(Float.toString(monVolStd), battMonVolStdMap.get(monVolStd).size());
                                battGroupMonVolMap.put(Float.toString(monVolStd), battMonVolStdMap.get(monVolStd).size());
                            }
                            battGroupInfoMap.put("producer",battProducerMap);
                            battGroupInfoMap.put("monVol",battGroupMonVolMap);
                            battGroupInfoMap.put("totalNum",battSize);
                            res_battGroupInfo.setII(1,true,battGroupInfoMap,null);
                        }catch (Exception e){
                            res_battGroupInfo.set(1,false,"发生异常:"+e.getCause());
@@ -129,7 +242,8 @@
                        res.put("battGroupInfo", res_battGroupInfo);
                        res.put("devStates", res_devStates);
                        res.put("devCountMap", res_devCountMap);
                        res.put("capAlarmNum", res_capAlarmNum);
                        res.put("capAlarmNum", res_capAlarmNum);*/
                        latch.await(10, TimeUnit.MINUTES);
                        session.getBasicRemote().sendObject(new Response().set(1, res));
                        sleep(4000);
                    }