| 
					
				 | 
			
			
				@@ -11,8 +11,8 @@ import com.genersoft.iot.vmp.service.IMediaServerService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.genersoft.iot.vmp.service.IPlatformService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.genersoft.iot.vmp.service.bean.GPSMsgInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.genersoft.iot.vmp.storager.IRedisCatchStorage; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.genersoft.iot.vmp.storager.dao.GbStreamMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.genersoft.iot.vmp.storager.dao.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.genersoft.iot.vmp.utils.DateUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.github.pagehelper.PageHelper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.github.pagehelper.PageInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.slf4j.Logger; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -41,6 +41,15 @@ public class PlatformServiceImpl implements IPlatformService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private ParentPlatformMapper platformMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private PlatformCatalogMapper catalogMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private PlatformChannelMapper platformChannelMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private PlatformGbStreamMapper platformGbStreamMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private IRedisCatchStorage redisCatchStorage; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -112,6 +121,69 @@ public class PlatformServiceImpl implements IPlatformService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return result > 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public boolean update(ParentPlatform parentPlatform) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        parentPlatform.setCharacterSet(parentPlatform.getCharacterSet().toUpperCase()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ParentPlatform parentPlatformOld = platformMapper.getParentPlatById(parentPlatform.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        parentPlatform.setUpdateTime(DateUtil.getNow()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (!parentPlatformOld.getTreeType().equals(parentPlatform.getTreeType())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 目录结构发生变化,清空之前的关联关系 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            logger.info("保存平台{}时发现目录结构变化,清空关联关系", parentPlatform.getDeviceGBId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            catalogMapper.delByPlatformId(parentPlatformOld.getServerGBId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            platformChannelMapper.delByPlatformId(parentPlatformOld.getServerGBId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            platformGbStreamMapper.delByPlatformId(parentPlatformOld.getServerGBId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 停止心跳定时 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        final String keepaliveTaskKey = KEEPALIVE_KEY_PREFIX + parentPlatformOld.getServerGBId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        dynamicTask.stop(keepaliveTaskKey); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 停止注册定时 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        final String registerTaskKey = REGISTER_KEY_PREFIX + parentPlatformOld.getServerGBId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        dynamicTask.stop(registerTaskKey); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 注销旧的 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            commanderForPlatform.unregister(parentPlatformOld, null, eventResult -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                logger.info("[国标级联] 注销成功, 平台:{}", parentPlatformOld.getServerGBId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } catch (InvalidArgumentException | ParseException | SipException e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            logger.error("[命令发送失败] 国标级联 注销: {}", e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 更新数据库 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (parentPlatform.getCatalogGroup() == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            parentPlatform.setCatalogGroup(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (parentPlatform.getAdministrativeDivision() == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            parentPlatform.setAdministrativeDivision(parentPlatform.getAdministrativeDivision()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        platformMapper.updateParentPlatform(parentPlatform); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 更新redis 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        redisCatchStorage.delPlatformCatchInfo(parentPlatformOld.getServerGBId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ParentPlatformCatch parentPlatformCatch = new ParentPlatformCatch(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        parentPlatformCatch.setParentPlatform(parentPlatform); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        parentPlatformCatch.setId(parentPlatform.getServerGBId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 注册 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (parentPlatform.isEnable()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 保存时启用就发送注册 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            // 注册成功时由程序直接调用了online方法 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                commanderForPlatform.register(parentPlatform, eventResult -> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    logger.info("[国标级联] {},添加向上级注册失败,请确定上级平台可用时重新保存", parentPlatform.getServerGBId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                }, null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } catch (InvalidArgumentException | ParseException | SipException e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                logger.error("[命令发送失败] 国标级联: {}", e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 重新开启定时注册, 使用续订消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // 重新开始心跳保活 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public void online(ParentPlatform parentPlatform) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         logger.info("[国标级联]:{}, 平台上线/更新注册", parentPlatform.getServerGBId()); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -137,7 +209,7 @@ public class PlatformServiceImpl implements IPlatformService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 ()-> { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     registerTask(parentPlatform); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                (parentPlatform.getExpires() - 10) *1000); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                (parentPlatform.getExpires()) *1000); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -183,7 +255,7 @@ public class PlatformServiceImpl implements IPlatformService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             logger.error("[命令发送失败] 国标级联 发送心跳: {}", e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    (parentPlatform.getKeepTimeout() - 10)*1000); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    (parentPlatform.getKeepTimeout())*1000); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 |