jiang
2022-08-18 8f77d0c25cdd37d4cc96c923b46ae28607bae51d
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java
@@ -4,12 +4,16 @@
import com.alibaba.fastjson.JSONObject;
import com.genersoft.iot.vmp.common.VideoManagerConstants;
import com.genersoft.iot.vmp.conf.DynamicTask;
import com.genersoft.iot.vmp.conf.UserSetup;
import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
import com.genersoft.iot.vmp.gb28181.bean.PlatformCatalog;
import com.genersoft.iot.vmp.gb28181.bean.SubscribeHolder;
import com.genersoft.iot.vmp.gb28181.bean.TreeType;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
import com.genersoft.iot.vmp.service.IPlatformChannelService;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import com.genersoft.iot.vmp.utils.DateUtil;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce;
import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.UpdateChannelParam;
@@ -41,13 +45,19 @@
    private final static Logger logger = LoggerFactory.getLogger(PlatformController.class);
    @Autowired
    private UserSetup userSetup;
    private UserSetting userSetting;
    @Autowired
    private IVideoManagerStorager storager;
    private IVideoManagerStorage storager;
    @Autowired
    private IPlatformChannelService platformChannelService;
    @Autowired
    private IRedisCatchStorage redisCatchStorage;
    @Autowired
    private SubscribeHolder subscribeHolder;
    @Autowired
    private ISIPCommanderForPlatform commanderForPlatform;
@@ -110,10 +120,14 @@
    })
    public PageInfo<ParentPlatform> platforms(@PathVariable int page, @PathVariable int count) {
//        if (logger.isDebugEnabled()) {
//            logger.debug("查询所有上级设备API调用");
//        }
        return storager.queryParentPlatformList(page, count);
        PageInfo<ParentPlatform> parentPlatformPageInfo = storager.queryParentPlatformList(page, count);
        if (parentPlatformPageInfo.getList().size() > 0) {
            for (ParentPlatform platform : parentPlatformPageInfo.getList()) {
                platform.setMobilePositionSubscribe(subscribeHolder.getMobilePositionSubscribe(platform.getServerGBId()) != null);
                platform.setCatalogSubscribe(subscribeHolder.getCatalogSubscribe(platform.getServerGBId()) != null);
            }
        }
        return parentPlatformPageInfo;
    }
    /**
@@ -161,6 +175,8 @@
            wvpResult.setMsg("平台 " + parentPlatform.getServerGBId() + " 已存在");
            return new ResponseEntity<>(wvpResult, HttpStatus.OK);
        }
        parentPlatform.setCreateTime(DateUtil.getNow());
        parentPlatform.setUpdateTime(DateUtil.getNow());
        boolean updateResult = storager.updateParentPlatform(parentPlatform);
        if (updateResult) {
@@ -222,8 +238,15 @@
            wvpResult.setMsg("missing parameters");
            return new ResponseEntity<>(wvpResult, HttpStatus.BAD_REQUEST);
        }
        parentPlatform.setCharacterSet(parentPlatform.getCharacterSet().toUpperCase());
        ParentPlatform parentPlatformOld = storager.queryParentPlatByServerGBId(parentPlatform.getServerGBId());
        parentPlatform.setUpdateTime(DateUtil.getNow());
        if (!parentPlatformOld.getTreeType().equals(parentPlatform.getTreeType())) {
             // 目录结构发生变化,清空之前的关联关系
             logger.info("保存平台{}时发现目录结构变化,清空关联关系", parentPlatform.getDeviceGBId());
             storager.cleanContentForPlatform(parentPlatform.getServerGBId());
        }
        boolean updateResult = storager.updateParentPlatform(parentPlatform);
        if (updateResult) {
@@ -244,6 +267,8 @@
                }
            } else if (parentPlatformOld != null && parentPlatformOld.isEnable() && !parentPlatform.isEnable()) { // 关闭启用时注销
                commanderForPlatform.unregister(parentPlatformOld, null, null);
                // 停止订阅相关的定时任务
                subscribeHolder.removeAllSubscribe(parentPlatform.getServerGBId());
            }
            wvpResult.setCode(0);
            wvpResult.setMsg("success");
@@ -277,7 +302,9 @@
            return new ResponseEntity<>("missing parameters", HttpStatus.BAD_REQUEST);
        }
        ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(serverGBId);
        if (parentPlatform == null) return new ResponseEntity<>("fail", HttpStatus.OK);
        if (parentPlatform == null) {
            return new ResponseEntity<>("fail", HttpStatus.OK);
        }
        // 发送离线消息,无论是否成功都删除缓存
        commanderForPlatform.unregister(parentPlatform, (event -> {
            // 清空redis缓存
@@ -295,8 +322,10 @@
        storager.delCatalogByPlatformId(parentPlatform.getServerGBId());
        storager.delRelationByPlatformId(parentPlatform.getServerGBId());
        // 停止发送位置订阅定时任务
        String key = VideoManagerConstants.SIP_SUBSCRIBE_PREFIX + userSetup.getServerId() +  "_MobilePosition_" + parentPlatform.getServerGBId();
        String key = VideoManagerConstants.SIP_SUBSCRIBE_PREFIX + userSetting.getServerId() +  "_MobilePosition_" + parentPlatform.getServerGBId();
        dynamicTask.stop(key);
        // 删除缓存的订阅信息
        subscribeHolder.removeAllSubscribe(parentPlatform.getServerGBId());
        if (deleteResult) {
            return new ResponseEntity<>("success", HttpStatus.OK);
        } else {
@@ -333,7 +362,6 @@
     * @param platformId  上级平台ID
     * @param query       查询内容
     * @param online      是否在线
     * @param choosed     是否已选中
     * @param channelType 通道类型
     * @return
     */
@@ -390,7 +418,7 @@
        if (logger.isDebugEnabled()) {
            logger.debug("给上级平台添加国标通道API调用");
        }
        int result = storager.updateChannelForGB(param.getPlatformId(), param.getChannelReduces(), param.getCatalogId());
        int result = platformChannelService.updateChannelForGB(param.getPlatformId(), param.getChannelReduces(), param.getCatalogId());
        return new ResponseEntity<>(String.valueOf(result > 0), HttpStatus.OK);
    }
@@ -436,13 +464,20 @@
        if (logger.isDebugEnabled()) {
            logger.debug("查询目录,platformId: {}, parentId: {}", platformId, parentId);
        }
        ParentPlatform platform = storager.queryParentPlatByServerGBId(platformId);
        if (platform == null) {
            return new ResponseEntity<>(new WVPResult<>(400, "平台未找到", null), HttpStatus.OK);
        }
        if (platformId.equals(parentId)) {
            parentId = platform.getDeviceGBId();
        }
        List<PlatformCatalog> platformCatalogList = storager.getChildrenCatalogByPlatform(platformId, parentId);
        // 查询下属的国标通道
//        List<PlatformCatalog> catalogsForChannel = storager.queryChannelInParentPlatformAndCatalog(platformId, parentId);
        // 查询下属的直播流通道
//        List<PlatformCatalog> catalogsForStream = storager.queryStreamInParentPlatformAndCatalog(platformId, parentId);
//        platformCatalogList.addAll(catalogsForChannel);
//        platformCatalogList.addAll(catalogsForStream);
//        if (platform.getTreeType().equals(TreeType.BUSINESS_GROUP)) {
//            platformCatalogList = storager.getChildrenCatalogByPlatform(platformId, parentId);
//        }else {
//
//        }
        WVPResult<List<PlatformCatalog>> result = new WVPResult<>();
        result.setCode(0);
        result.setMsg("success");
@@ -469,7 +504,6 @@
        }
        PlatformCatalog platformCatalogInStore = storager.getCatalog(platformCatalog.getId());
        WVPResult<List<PlatformCatalog>> result = new WVPResult<>();
        if (platformCatalogInStore != null) {
            result.setCode(-1);