whyclxw
2024-06-15 2325edf52ba3e999e276dbb2347c887d4d981f9e
src/main/java/com/whyc/webSocket/BattSocket.java
@@ -5,6 +5,7 @@
import com.whyc.factory.ThreadPoolExecutorFactory;
import com.whyc.pojo.RtState;
import com.whyc.pojo.StationInf;
import com.whyc.service.BattAlarmService;
import com.whyc.service.BattInfService;
import com.whyc.service.RtDataService;
import com.whyc.service.RtStateService;
@@ -50,6 +51,8 @@
    private static RtDataService rtDataService;
    private static BattAlarmService battAlarmService;
    @Autowired
    public void setRtStateService(RtStateService rtStateService) {
@@ -60,6 +63,12 @@
    public void setRtDataService(RtDataService rtDataService) {
        BattSocket.rtDataService = rtDataService;
    }
    @Autowired
    public void setBattAlarmService(BattAlarmService battAlarmService) {
        BattSocket.battAlarmService = battAlarmService;
    }
    @OnOpen
    public void onOpen(Session session) {
        this.session = session;
@@ -75,7 +84,7 @@
                    Map<String, Object> res = new HashMap<>();
                    while (!currentThread().isInterrupted()) {
                        ThreadPoolExecutor poolExecutor = ThreadPoolExecutorFactory.getPoolExecutor();
                        CountDownLatch latch = new CountDownLatch(2);
                        CountDownLatch latch = new CountDownLatch(3);
                        poolExecutor.execute(() -> {
                            Response resRtState = rtStateService.getResRtState(binfId);
                            res.put("resRtState", resRtState);
@@ -86,6 +95,11 @@
                            res.put("resRtData", resRtData);
                            latch.countDown();
                        });
                        poolExecutor.execute(() -> {
                            Response resBattAlm = battAlarmService.getResBattAlm(binfId);
                            res.put("resBattAlm", resBattAlm);
                            latch.countDown();
                        });
                        latch.await(10, TimeUnit.MINUTES);
                        session.getBasicRemote().sendObject(new Response().set(1, res));
                        sleep(executeTime);