648540858
2022-01-25 abc65c6317db3d57c501615125b5a4e17b0448c9
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java
@@ -87,21 +87,22 @@
    }
    /**
     * 保存上级平台信息
     * 添加上级平台信息
     * @param parentPlatform
     * @return
     */
    @ApiOperation("保存上级平台信息")
    @ApiOperation("添加上级平台信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parentPlatform", value = "上级平台信息", dataTypeClass = ParentPlatform.class),
    })
    @PostMapping("/save")
    @PostMapping("/add")
    @ResponseBody
    public ResponseEntity<String> savePlatform(@RequestBody ParentPlatform parentPlatform){
    public ResponseEntity<WVPResult<String>> addPlatform(@RequestBody ParentPlatform parentPlatform){
        if (logger.isDebugEnabled()) {
            logger.debug("保存上级平台信息API调用");
        }
        WVPResult<String> wvpResult = new WVPResult<>();
        if (StringUtils.isEmpty(parentPlatform.getName())
                ||StringUtils.isEmpty(parentPlatform.getServerGBId())
                ||StringUtils.isEmpty(parentPlatform.getServerGBDomain())
@@ -113,11 +114,69 @@
                ||StringUtils.isEmpty(parentPlatform.getTransport())
                ||StringUtils.isEmpty(parentPlatform.getCharacterSet())
        ){
            return new ResponseEntity<>("missing parameters", HttpStatus.BAD_REQUEST);
            wvpResult.setCode(-1);
            wvpResult.setMsg("missing parameters");
            return new ResponseEntity<>(wvpResult, HttpStatus.BAD_REQUEST);
        }
        // TODO 检查是否已经存在,且注册成功, 如果注册成功,需要先注销之前再,修改并注册
        // ParentPlatform parentPlatformOld = storager.queryParentPlatById(parentPlatform.getDeviceGBId());
        ParentPlatform parentPlatformOld = storager.queryParentPlatByServerGBId(parentPlatform.getServerGBId());
        if (parentPlatformOld != null) {
            wvpResult.setCode(-1);
            wvpResult.setMsg("平台 "+parentPlatform.getServerGBId()+" 已存在");
            return new ResponseEntity<>(wvpResult, HttpStatus.OK);
        }
        boolean updateResult = storager.updateParentPlatform(parentPlatform);
        if (updateResult) {
            // 保存时启用就发送注册
            if (parentPlatform.isEnable()) {
                //  只要保存就发送注册
                commanderForPlatform.register(parentPlatform, null, null);
            } else if (parentPlatformOld != null && parentPlatformOld.isEnable() && !parentPlatform.isEnable()){ // 关闭启用时注销
                commanderForPlatform.unregister(parentPlatform, null, null);
            }
            wvpResult.setCode(0);
            wvpResult.setMsg("success");
            return new ResponseEntity<>(wvpResult, HttpStatus.OK);
        } else {
            wvpResult.setCode(-1);
            wvpResult.setMsg("写入数据库失败");
            return new ResponseEntity<>(wvpResult, HttpStatus.OK);
        }
    }
    /**
     * 保存上级平台信息
     * @param parentPlatform
     * @return
     */
    @ApiOperation("保存上级平台信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parentPlatform", value = "上级平台信息", dataTypeClass = ParentPlatform.class),
    })
    @PostMapping("/save")
    @ResponseBody
    public ResponseEntity<WVPResult<String>> savePlatform(@RequestBody ParentPlatform parentPlatform){
        if (logger.isDebugEnabled()) {
            logger.debug("保存上级平台信息API调用");
        }
        WVPResult<String> wvpResult = new WVPResult<>();
        if (StringUtils.isEmpty(parentPlatform.getName())
                ||StringUtils.isEmpty(parentPlatform.getServerGBId())
                ||StringUtils.isEmpty(parentPlatform.getServerGBDomain())
                ||StringUtils.isEmpty(parentPlatform.getServerIP())
                ||StringUtils.isEmpty(parentPlatform.getServerPort())
                ||StringUtils.isEmpty(parentPlatform.getDeviceGBId())
                ||StringUtils.isEmpty(parentPlatform.getExpires())
                ||StringUtils.isEmpty(parentPlatform.getKeepTimeout())
                ||StringUtils.isEmpty(parentPlatform.getTransport())
                ||StringUtils.isEmpty(parentPlatform.getCharacterSet())
        ){
            wvpResult.setCode(-1);
            wvpResult.setMsg("missing parameters");
            return new ResponseEntity<>(wvpResult, HttpStatus.BAD_REQUEST);
        }
        ParentPlatform parentPlatformOld = storager.queryParentPlatByServerGBId(parentPlatform.getServerGBId());
        boolean updateResult = storager.updateParentPlatform(parentPlatform);
@@ -130,9 +189,13 @@
            } else if (parentPlatformOld != null && parentPlatformOld.isEnable() && !parentPlatform.isEnable()){ // 关闭启用时注销
                commanderForPlatform.unregister(parentPlatform, null, null);
            }
            return new ResponseEntity<>("success", HttpStatus.OK);
            wvpResult.setCode(0);
            wvpResult.setMsg("success");
            return new ResponseEntity<>(wvpResult, HttpStatus.OK);
        } else {
            return new ResponseEntity<>("fail", HttpStatus.OK);
            wvpResult.setCode(0);
            wvpResult.setMsg("写入数据库失败");
            return new ResponseEntity<>(wvpResult, HttpStatus.OK);
        }
    }
@@ -172,6 +235,8 @@
        }));
        boolean deleteResult = storager.deleteParentPlatform(parentPlatform);
        storager.delCatalogByPlatformId(parentPlatform.getServerGBId());
        storager.delRelationByPlatformId(parentPlatform.getServerGBId());
        if (deleteResult) {
@@ -400,15 +465,31 @@
    })
    @DeleteMapping("/catalog/del")
    @ResponseBody
    public ResponseEntity<WVPResult<List<PlatformCatalog>>> delCatalog(String id){
    public ResponseEntity<WVPResult<String>> delCatalog(String id, String platformId){
        if (logger.isDebugEnabled()) {
            logger.debug("删除目录,{}", id);
        }
        int delResult = storager.delCatalog(id);
        WVPResult<List<PlatformCatalog>> result = new WVPResult<>();
        WVPResult<String> result = new WVPResult<>();
        if (StringUtils.isEmpty(id) || StringUtils.isEmpty(platformId)) {
            result.setCode(-1);
            result.setMsg("param error");
            return new ResponseEntity<>(result, HttpStatus.BAD_REQUEST);
        }
        result.setCode(0);
        int delResult = storager.delCatalog(id);
        // 如果删除的是默认目录则根目录设置为默认目录
        PlatformCatalog parentPlatform = storager.queryDefaultCatalogInPlatform(platformId);
        // 默认节点被移除
        if (parentPlatform == null) {
            storager.setDefaultCatalog(platformId, platformId);
            result.setData(platformId);
        }
        if (delResult > 0) {
            result.setMsg("success");
            return new ResponseEntity<>(result, HttpStatus.OK);