Commit 53ffefe0915827a27be66cd4b499e25c9f10c11a

Authored by panlinlin
1 parent 54d79531

完成向上级联->保存时注册或注销

src/main/java/com/genersoft/iot/vmp/vmanager/platform/PlatformController.java
... ... @@ -75,10 +75,19 @@ public class PlatformController {
75 75 }
76 76 // TODO 检查是否已经存在,且注册成功, 如果注册成功,需要先注销之前再,修改并注册
77 77  
  78 + ParentPlatform parentPlatformOld = storager.queryParentPlatById(parentPlatform.getDeviceGBId());
  79 +
78 80 boolean updateResult = storager.updateParentPlatform(parentPlatform);
79 81  
80 82 if (updateResult) {
81   - commanderForPlatform.register(parentPlatform);
  83 + // 保存时启用就发送注册
  84 + if (parentPlatform.isEnable()) {
  85 + // 只要保存就发送注册
  86 + commanderForPlatform.register(parentPlatform);
  87 + }else if (parentPlatformOld != null && parentPlatformOld.isEnable() && !parentPlatform.isEnable()){ // 关闭启用时注销
  88 + commanderForPlatform.unregister(parentPlatform, null, null);
  89 + }
  90 +
82 91  
83 92 return new ResponseEntity<>("success", HttpStatus.OK);
84 93 }else {
... ... @@ -98,7 +107,7 @@ public class PlatformController {
98 107 return new ResponseEntity<>("missing parameters", HttpStatus.BAD_REQUEST);
99 108 }
100 109  
101   - // 发送离线消息,
  110 + // 发送离线消息,无论是否成功都删除缓存
102 111 commanderForPlatform.unregister(parentPlatform, (event -> {
103 112 // 清空redis缓存
104 113 redisCatchStorage.delPlatformCatchInfo(parentPlatform.getDeviceGBId());
... ...