初次提交

This commit is contained in:
李玉东 2025-09-15 00:45:00 +08:00
parent 3dab4b367f
commit 08ee625021
2 changed files with 17 additions and 29 deletions

View File

@ -1,4 +1,4 @@
package com.hivekion;
package com.hivekion.startup;
import com.hivekion.thread.HandleReceiveThread;
import com.hivekion.thread.HandleSendThread;
@ -20,8 +20,8 @@ import org.springframework.stereotype.Component;
public class Init {
@PostConstruct
public void init() {
public void appInit() {
log.info("Init start");
new Thread(new HandleSendThread()).start();
new Thread(new HandleReceiveThread()).start();
}

View File

@ -60,13 +60,7 @@ public class WsServer {
}
try{
session.getBasicRemote().sendText(testWeatherJson("start_rain"));
Thread.sleep(10000);
session.getBasicRemote().sendText(testWeatherJson("start_snow"));
}catch (Exception e){
log.error("error::",e);
}
}
}
@ -120,27 +114,21 @@ public class WsServer {
Object lock = lockMap.computeIfAbsent(scenarioId, k -> new Object());
synchronized (lock) {
Map<String, Map<String, Session>> roomMap = SESSION_MAP.get(String.valueOf(scenarioId));
if (roomMap.containsKey(room)) {
Map<String, Session> singleRoomMap = roomMap.get(room);
singleRoomMap.forEach((sessionId, session) -> {
try{
session.getBasicRemote().sendText(message);
}catch (Exception e){
log.error("error::",e);
}
if(roomMap!=null){
if (roomMap.containsKey(room)) {
Map<String, Session> singleRoomMap = roomMap.get(room);
singleRoomMap.forEach((sessionId, session) -> {
try{
session.getBasicRemote().sendText(message);
}catch (Exception e){
log.error("error::",e);
}
});
});
}
}
}
}
private String testWeatherJson(String tag){
ResponseCmdInfo responseCmdInfo = new ResponseCmdInfo();
responseCmdInfo.setCmdType(tag);
responseCmdInfo.setRoom("123");
responseCmdInfo.setScenarioId(2746);
Map<String,Object> data = new HashMap<>();
data.put("begTime","2028-03-09 10:00:00");
data.put("endTime","2028-03-19 00:20:00");
return JSON.toJSONString(responseCmdInfo);
}
}