panlinlin
2021-01-07 53ffefe0915827a27be66cd4b499e25c9f10c11a
src/main/java/com/genersoft/iot/vmp/vmanager/platform/PlatformController.java
@@ -3,6 +3,7 @@
import com.alibaba.fastjson.JSONObject;
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
@@ -24,6 +25,8 @@
    @Autowired
    private IVideoManagerStorager storager;
    @Autowired
    private IRedisCatchStorage redisCatchStorage;
    @Autowired
    private ISIPCommanderForPlatform commanderForPlatform;
@@ -72,10 +75,19 @@
        }
        // TODO 检查是否已经存在,且注册成功, 如果注册成功,需要先注销之前再,修改并注册
        ParentPlatform parentPlatformOld = storager.queryParentPlatById(parentPlatform.getDeviceGBId());
        boolean updateResult = storager.updateParentPlatform(parentPlatform);
        if (updateResult) {
            commanderForPlatform.register(parentPlatform, null, null, null, null);
            // 保存时启用就发送注册
            if (parentPlatform.isEnable()) {
                //  只要保存就发送注册
                commanderForPlatform.register(parentPlatform);
            }else if (parentPlatformOld != null && parentPlatformOld.isEnable() && !parentPlatform.isEnable()){ // 关闭启用时注销
                commanderForPlatform.unregister(parentPlatform, null, null);
            }
            return new ResponseEntity<>("success", HttpStatus.OK);
        }else {
@@ -94,7 +106,23 @@
        ){
            return new ResponseEntity<>("missing parameters", HttpStatus.BAD_REQUEST);
        }
        // 发送离线消息,无论是否成功都删除缓存
        commanderForPlatform.unregister(parentPlatform, (event -> {
            // 清空redis缓存
            redisCatchStorage.delPlatformCatchInfo(parentPlatform.getDeviceGBId());
            redisCatchStorage.delPlatformKeepalive(parentPlatform.getDeviceGBId());
            redisCatchStorage.delPlatformRegister(parentPlatform.getDeviceGBId());
        }), (event -> {
            // 清空redis缓存
            redisCatchStorage.delPlatformCatchInfo(parentPlatform.getDeviceGBId());
            redisCatchStorage.delPlatformKeepalive(parentPlatform.getDeviceGBId());
            redisCatchStorage.delPlatformRegister(parentPlatform.getDeviceGBId());
        }));
        boolean deleteResult = storager.deleteParentPlatform(parentPlatform);
        if (deleteResult) {
            return new ResponseEntity<>("success", HttpStatus.OK);
        }else {