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