|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.glxp.sale.admin.socket.client;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.thread.ThreadUtil;
|
|
|
|
|
import com.glxp.sale.admin.constant.SocketMsgType;
|
|
|
|
|
import com.glxp.sale.admin.service.param.SystemParamConfigService;
|
|
|
|
|
import com.glxp.sale.admin.thread.HeartTaskService;
|
|
|
|
@ -29,34 +30,40 @@ public class WebSocketComponent implements CommandLineRunner {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void run(String... args) throws Exception {
|
|
|
|
|
String ip = systemParamConfigService.selectValueByParamKey("upper_server_ip");
|
|
|
|
|
ip = ip.replace("http://", "");
|
|
|
|
|
try {
|
|
|
|
|
SpsWebSocketClient client = new SpsWebSocketClient("ws://" + ip + "/spms/sync/1/" + socketToken);
|
|
|
|
|
client.setSocketMsgService(socketMsgService);
|
|
|
|
|
initConnect(client);
|
|
|
|
|
//等待WebSocket服务端响应
|
|
|
|
|
String message = null;
|
|
|
|
|
while (true) {
|
|
|
|
|
while ((message = client.getExcptMessage()) == null) {
|
|
|
|
|
log.info("已连接,等待接收数据--------");
|
|
|
|
|
Thread.sleep(1000);
|
|
|
|
|
if (client.isClosed()) {
|
|
|
|
|
|
|
|
|
|
ThreadUtil.execAsync(() -> {
|
|
|
|
|
String ip = systemParamConfigService.selectValueByParamKey("upper_server_ip");
|
|
|
|
|
ip = ip.replace("http://", "");
|
|
|
|
|
try {
|
|
|
|
|
SpsWebSocketClient client = new SpsWebSocketClient("ws://" + ip + "/spms/sync/1/" + socketToken);
|
|
|
|
|
client.setSocketMsgService(socketMsgService);
|
|
|
|
|
initConnect(client);
|
|
|
|
|
//等待WebSocket服务端响应
|
|
|
|
|
String message = null;
|
|
|
|
|
while (true) {
|
|
|
|
|
while ((message = client.getExcptMessage()) == null) {
|
|
|
|
|
log.info("已连接,等待接收数据--------");
|
|
|
|
|
Thread.sleep(1000);
|
|
|
|
|
if (client.isClosed()) {
|
|
|
|
|
initConnect(client);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (message.contains(SocketMsgType.DL_ALL_DATA)) {
|
|
|
|
|
heartTaskService.dlAllData();
|
|
|
|
|
}
|
|
|
|
|
//打印服务端返回的数据
|
|
|
|
|
log.info("成功获取数据:" + message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (URISyntaxException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (message.contains(SocketMsgType.DL_ALL_DATA)) {
|
|
|
|
|
heartTaskService.dlAllData();
|
|
|
|
|
}
|
|
|
|
|
//打印服务端返回的数据
|
|
|
|
|
log.info("成功获取数据:" + message);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (URISyntaxException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void initConnect(SpsWebSocketClient client) {
|
|
|
|
|