|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.glxp.api.service.sync;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.thread.ThreadUtil;
|
|
|
|
|
import com.glxp.api.constant.SocketMsgType;
|
|
|
|
|
import com.glxp.api.dao.system.SyncDataSetDao;
|
|
|
|
|
import com.glxp.api.entity.system.SyncDataSetEntity;
|
|
|
|
@ -30,43 +31,45 @@ public class WebSocketComponent implements CommandLineRunner {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void run(String... args) throws Exception {
|
|
|
|
|
|
|
|
|
|
SyncDataSetEntity syncDataSetEntity = syncDataSetDao.selectSet();
|
|
|
|
|
String ip = syncDataSetEntity.getSyncIp();
|
|
|
|
|
ip = ip.replace("http://", "");
|
|
|
|
|
ThreadUtil.execAsync(() -> {
|
|
|
|
|
SyncDataSetEntity syncDataSetEntity = syncDataSetDao.selectSet();
|
|
|
|
|
String ip = syncDataSetEntity.getSyncIp();
|
|
|
|
|
ip = ip.replace("http://", "");
|
|
|
|
|
// ip = ip.replace("/SP_SYNC_SERVER", "");
|
|
|
|
|
try {
|
|
|
|
|
SpsWebSocketClient client = new SpsWebSocketClient("ws://" + ip + "/sps/web/sync/2/" + socketToken);
|
|
|
|
|
client.setSocketMsgService(socketMsgService);
|
|
|
|
|
initConnect(client);
|
|
|
|
|
//等待服务端响应
|
|
|
|
|
while (!client.getReadyState().equals(ReadyState.OPEN)) {
|
|
|
|
|
log.info("连接中···请稍后");
|
|
|
|
|
Thread.sleep(1000);
|
|
|
|
|
}
|
|
|
|
|
//等待WebSocket服务端响应
|
|
|
|
|
String message = null;
|
|
|
|
|
while (true) {
|
|
|
|
|
while ((message = client.getExcptMessage()) == null) {
|
|
|
|
|
log.info("已连接,等待接收数据--------");
|
|
|
|
|
try {
|
|
|
|
|
SpsWebSocketClient client = new SpsWebSocketClient("ws://" + ip + "/sps/web/sync/2/" + socketToken);
|
|
|
|
|
client.setSocketMsgService(socketMsgService);
|
|
|
|
|
initConnect(client);
|
|
|
|
|
//等待服务端响应
|
|
|
|
|
while (!client.getReadyState().equals(ReadyState.OPEN)) {
|
|
|
|
|
log.info("连接中···请稍后");
|
|
|
|
|
Thread.sleep(1000);
|
|
|
|
|
if (client.isClosed()) {
|
|
|
|
|
initConnect(client);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (message.equals(SocketMsgType.DL_ALL_DATA)) {
|
|
|
|
|
heartTaskService.pullData();
|
|
|
|
|
//等待WebSocket服务端响应
|
|
|
|
|
String message = null;
|
|
|
|
|
while (true) {
|
|
|
|
|
while ((message = client.getExcptMessage()) == null) {
|
|
|
|
|
log.info("已连接,等待接收数据--------");
|
|
|
|
|
Thread.sleep(1000);
|
|
|
|
|
if (client.isClosed()) {
|
|
|
|
|
initConnect(client);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (message.equals(SocketMsgType.DL_ALL_DATA)) {
|
|
|
|
|
heartTaskService.pullData();
|
|
|
|
|
}
|
|
|
|
|
//打印服务端返回的数据
|
|
|
|
|
log.info("成功获取数据:" + message);
|
|
|
|
|
}
|
|
|
|
|
//打印服务端返回的数据
|
|
|
|
|
log.info("成功获取数据:" + message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (URISyntaxException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
} catch (URISyntaxException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|