1
zj
2025-08-18 09f35ab58d22c6d8b186ddb1abefdee665d48ac3
src/main/java/com/nq/ws/WebsocketRunClient.java
@@ -43,21 +43,21 @@
    private static HttpPost httpPost;
    static {
        httpPost = new HttpPost("http://127.0.0.1:8001/api/sendNotification"); // 初始化 HttpPost
        httpPost = new HttpPost("http://127.0.0.1:8008/api/sendNotification"); // 初始化 HttpPost
    }
    @Override
    public void onOpen(ServerHandshake serverHandshake) {
        send(("key:"+ eStockType.getStockKey()+":"+eStockType.getContryId()).getBytes());
//        Timer heartbeatTimer;
//        // 启动心跳定时器
//        heartbeatTimer = new Timer();
//        heartbeatTimer.schedule(new TimerTask() {
//            @Override
//            public void run() {
//                send(("key:"+ eStockType.getStockKey()+":"+eStockType.getContryId()).getBytes());
//            }
//        }, 0, 3000); // 每3秒发送一次心跳消息
        Timer heartbeatTimer;
        // 启动心跳定时器
        heartbeatTimer = new Timer();
        heartbeatTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                send(("key:"+ eStockType.getStockKey()+":"+eStockType.getContryId()).getBytes());
            }
        }, 0, 3000); // 每3秒发送一次心跳消息
    }
    @Override
@@ -72,17 +72,24 @@
            stockRealTimeBean.setHigh(stringObjectMap.get("High").toString());
            stockRealTimeBean.setLow(stringObjectMap.get("Low").toString());
            stockRealTimeBean.setPc(stringObjectMap.get("Chg").toString());
            stockRealTimeBean.setPcp(stringObjectMap.get("ChgPct").toString());
            stockRealTimeBean.setPcp(stringObjectMap.get("ChgPct").toString()+"%");
            stockRealTimeBean.setTime(stringObjectMap.get("Time").toString());
            RedisKeyUtil.setCacheRealTimeStock(EStockType.IN,stockRealTimeBean);
            RedisKeyUtil.setCacheRealTimeStock(EStockType.US,stockRealTimeBean);
            ObjectMapper objectMapper = new ObjectMapper();
            try {
                if(!stockRealTimeBean.getPcp().contains("-")){
                    stockRealTimeBean.setPcp("+"+stringObjectMap.get("ChgPct").toString()+"%");
                }
                String json = objectMapper.writeValueAsString(stockRealTimeBean);
                sendLoca(json);
                StockRealTimeBean stockDetailBean =  new Gson().fromJson(s, StockRealTimeBean.class);
                RedisKeyUtil.setCacheRealTimeStock(EStockType.US,stockDetailBean);
            } catch (JsonProcessingException e) {
                throw new RuntimeException(e);
            }
        }else{
            log.error("websocket  消息错误:"+s);
        }
    }