diff --git a/sql/mysql.sql b/sql/mysql.sql index ffe39c3f..7d0996f6 100644 --- a/sql/mysql.sql +++ b/sql/mysql.sql @@ -50,7 +50,7 @@ CREATE TABLE `device` ( `treeType` varchar(50) COLLATE utf8mb4_general_ci NOT NULL, PRIMARY KEY (`id`) USING BTREE, UNIQUE KEY `device_deviceId_uindex` (`deviceId`) USING BTREE -) ENGINE=InnoDB AUTO_INCREMENT=37 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; +) ENGINE=InnoDB AUTO_INCREMENT=45 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -142,7 +142,7 @@ CREATE TABLE `device_channel` ( PRIMARY KEY (`id`) USING BTREE, UNIQUE KEY `device_channel_id_uindex` (`id`) USING BTREE, UNIQUE KEY `device_channel_pk` (`channelId`,`deviceId`) USING BTREE -) ENGINE=InnoDB AUTO_INCREMENT=19324 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; +) ENGINE=InnoDB AUTO_INCREMENT=19336 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -179,7 +179,7 @@ CREATE TABLE `device_mobile_position` ( `latitudeWgs84` double DEFAULT NULL, `createTime` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL, PRIMARY KEY (`id`) USING BTREE -) ENGINE=InnoDB AUTO_INCREMENT=5649 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; +) ENGINE=InnoDB AUTO_INCREMENT=6751 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -208,13 +208,12 @@ CREATE TABLE `gb_stream` ( `latitude` double DEFAULT NULL, `streamType` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL, `mediaServerId` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL, - `status` int DEFAULT NULL, `createTime` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL, `gpsTime` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL, PRIMARY KEY (`gbStreamId`) USING BTREE, UNIQUE KEY `app` (`app`,`stream`) USING BTREE, UNIQUE KEY `gbId` (`gbId`) USING BTREE -) ENGINE=InnoDB AUTO_INCREMENT=301681 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; +) ENGINE=InnoDB AUTO_INCREMENT=301740 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -244,7 +243,7 @@ CREATE TABLE `log` ( `username` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, `createTime` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, PRIMARY KEY (`id`) USING BTREE -) ENGINE=InnoDB AUTO_INCREMENT=29943 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; +) ENGINE=InnoDB AUTO_INCREMENT=37760 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -329,16 +328,16 @@ CREATE TABLE `parent_platform` ( `ptz` int DEFAULT NULL, `rtcp` int DEFAULT NULL, `status` bit(1) DEFAULT NULL, - `shareAllLiveStream` int DEFAULT NULL, `startOfflinePush` int DEFAULT '0', `administrativeDivision` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, `catalogGroup` int DEFAULT '1', `createTime` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL, `updateTime` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL, + `treeType` varchar(50) COLLATE utf8mb4_general_ci NOT NULL, PRIMARY KEY (`id`) USING BTREE, UNIQUE KEY `parent_platform_id_uindex` (`id`) USING BTREE, UNIQUE KEY `parent_platform_pk` (`serverGBId`) USING BTREE -) ENGINE=InnoDB AUTO_INCREMENT=33 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; +) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -362,6 +361,8 @@ CREATE TABLE `platform_catalog` ( `platformId` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, `parentId` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL, + `civilCode` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL, + `businessGroupId` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL, PRIMARY KEY (`id`) USING BTREE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; /*!40101 SET character_set_client = @saved_cs_client */; @@ -388,7 +389,7 @@ CREATE TABLE `platform_gb_channel` ( `catalogId` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, `deviceChannelId` int NOT NULL, PRIMARY KEY (`id`) USING BTREE -) ENGINE=InnoDB AUTO_INCREMENT=4889 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; +) ENGINE=InnoDB AUTO_INCREMENT=4912 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -414,7 +415,7 @@ CREATE TABLE `platform_gb_stream` ( `id` int NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) USING BTREE, UNIQUE KEY `platform_gb_stream_pk` (`platformId`,`catalogId`,`gbStreamId`) USING BTREE -) ENGINE=InnoDB AUTO_INCREMENT=302077 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; +) ENGINE=InnoDB AUTO_INCREMENT=302134 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -455,7 +456,7 @@ CREATE TABLE `stream_proxy` ( `updateTime` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL, PRIMARY KEY (`id`) USING BTREE, UNIQUE KEY `stream_proxy_pk` (`app`,`stream`) USING BTREE -) ENGINE=InnoDB AUTO_INCREMENT=65 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; +) ENGINE=InnoDB AUTO_INCREMENT=66 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -487,9 +488,10 @@ CREATE TABLE `stream_push` ( `serverId` varchar(50) COLLATE utf8mb4_general_ci NOT NULL, `pushTime` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL, `updateTime` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL, + `status` int DEFAULT NULL, PRIMARY KEY (`id`) USING BTREE, UNIQUE KEY `stream_push_pk` (`app`,`stream`) USING BTREE -) ENGINE=InnoDB AUTO_INCREMENT=305304 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; +) ENGINE=InnoDB AUTO_INCREMENT=305390 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -515,6 +517,7 @@ CREATE TABLE `user` ( `roleId` int NOT NULL, `createTime` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, `updateTime` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, + `pushKey` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL, PRIMARY KEY (`id`) USING BTREE, UNIQUE KEY `user_username_uindex` (`username`) USING BTREE ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; @@ -526,7 +529,7 @@ CREATE TABLE `user` ( LOCK TABLES `user` WRITE; /*!40000 ALTER TABLE `user` DISABLE KEYS */; -INSERT INTO `user` VALUES (1,'admin','21232f297a57a5a743894a0e4a801fc3',1,'2021 - 04 - 13 14:14:57','2021 - 04 - 13 14:14:57'); +INSERT INTO `user` VALUES (1,'admin','21232f297a57a5a743894a0e4a801fc3',1,'2021 - 04 - 13 14:14:57','2021 - 04 - 13 14:14:57','453df297a57a5a7438934sda801fc3'); /*!40000 ALTER TABLE `user` ENABLE KEYS */; UNLOCK TABLES; @@ -566,4 +569,4 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2022-07-06 9:43:54 +-- Dump completed on 2022-07-17 23:15:09 diff --git a/sql/update.sql b/sql/update.sql index 43413552..91f725ec 100644 --- a/sql/update.sql +++ b/sql/update.sql @@ -51,10 +51,31 @@ alter table stream_proxy alter table stream_push add pushTime varchar(50) default null; +alter table stream_push + add status int DEFAULT NULL; alter table stream_push add updateTime varchar(50) default null; +alter table stream_push + add pushIng int DEFAULT NULL; alter table stream_push change createStamp createTime varchar(50) default null; +alter table gb_stream + drop column status; + +alter table user + add pushKey varchar(50) default null; +update user set pushKey='453df297a57a5a7438934sda801fc3' where id=1; + +alter table parent_platform + add treeType varchar(50) not null; +update parent_platform set parent_platform.treeType='BusinessGroup'; +alter table parent_platform drop shareAllLiveStream; + +alter table platform_catalog + add civilCode varchar(50) default null; +alter table platform_catalog + add businessGroupId varchar(50) default null; + diff --git a/src/main/java/com/genersoft/iot/vmp/VManageBootstrap.java b/src/main/java/com/genersoft/iot/vmp/VManageBootstrap.java index 8ff2efb8..3bac82d6 100644 --- a/src/main/java/com/genersoft/iot/vmp/VManageBootstrap.java +++ b/src/main/java/com/genersoft/iot/vmp/VManageBootstrap.java @@ -11,7 +11,7 @@ import org.springframework.scheduling.annotation.EnableScheduling; import springfox.documentation.oas.annotations.EnableOpenApi; /** - * + * 启动类 */ @ServletComponentScan("com.genersoft.iot.vmp.conf") @SpringBootApplication diff --git a/src/main/java/com/genersoft/iot/vmp/common/StreamInfo.java b/src/main/java/com/genersoft/iot/vmp/common/StreamInfo.java index 4e4ba15e..b5788aed 100644 --- a/src/main/java/com/genersoft/iot/vmp/common/StreamInfo.java +++ b/src/main/java/com/genersoft/iot/vmp/common/StreamInfo.java @@ -9,6 +9,9 @@ public class StreamInfo { private String deviceID; private String channelId; private String flv; + + private String ip; + private String https_flv; private String ws_flv; private String wss_flv; @@ -292,4 +295,12 @@ public class StreamInfo { public void setProgress(double progress) { this.progress = progress; } + + public String getIp() { + return ip; + } + + public void setIp(String ip) { + this.ip = ip; + } } diff --git a/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java b/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java index 57f764b5..40a73521 100644 --- a/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java +++ b/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java @@ -58,6 +58,8 @@ public class VideoManagerConstants { public static final String MEDIA_TRANSACTION_USED_PREFIX = "VMP_MEDIA_TRANSACTION_"; + public static final String MEDIA_STREAM_AUTHORITY = "MEDIA_STREAM_AUTHORITY_"; + public static final String SIP_CSEQ_PREFIX = "VMP_SIP_CSEQ_"; public static final String SIP_SN_PREFIX = "VMP_SIP_SN_"; @@ -71,6 +73,8 @@ public class VideoManagerConstants { public static final String SYSTEM_INFO_NET_PREFIX = "VMP_SYSTEM_INFO_NET_"; + + //************************** redis 消息********************************* // 流变化的通知 @@ -79,9 +83,15 @@ public class VideoManagerConstants { // 接收推流设备的GPS变化通知 public static final String VM_MSG_GPS = "VM_MSG_GPS"; + // 接收推流设备的GPS变化通知 + public static final String VM_MSG_PUSH_STREAM_STATUS_CHANGE = "VM_MSG_PUSH_STREAM_STATUS_CHANGE"; + // redis 消息通知设备推流到平台 public static final String VM_MSG_STREAM_PUSH_REQUESTED = "VM_MSG_STREAM_PUSH_REQUESTED"; + // redis 消息请求所有的在线通道 + public static final String VM_MSG_GET_ALL_ONLINE_REQUESTED = "VM_MSG_GET_ALL_ONLINE_REQUESTED"; + // 移动位置订阅通知 public static final String VM_MSG_SUBSCRIBE_MOBILE_POSITION = "mobileposition"; @@ -94,6 +104,10 @@ public class VideoManagerConstants { // 设备状态订阅的通知 public static final String VM_MSG_SUBSCRIBE_DEVICE_STATUS = "device"; + + + + //************************** 第三方 **************************************** public static final String WVP_STREAM_GB_ID_PREFIX = "memberNo_"; public static final String WVP_STREAM_GPS_MSG_PREFIX = "WVP_STREAM_GPS_MSG_"; diff --git a/src/main/java/com/genersoft/iot/vmp/conf/DynamicTask.java b/src/main/java/com/genersoft/iot/vmp/conf/DynamicTask.java index ade2e622..1885632a 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/DynamicTask.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/DynamicTask.java @@ -5,6 +5,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.stereotype.Component; @@ -103,12 +104,9 @@ public class DynamicTask { public void stop(String key) { if (futureMap.get(key) != null && !futureMap.get(key).isCancelled()) { -// Runnable runnable = runnableMap.get(key); -// if (runnable instanceof ISubscribeTask) { -// ISubscribeTask subscribeTask = (ISubscribeTask) runnable; -// subscribeTask.stop(); -// } futureMap.get(key).cancel(false); + futureMap.remove(key); + runnableMap.remove(key); } } @@ -123,4 +121,19 @@ public class DynamicTask { public Runnable get(String key) { return runnableMap.get(key); } + + /** + * 每五分钟检查失效的任务,并移除 + */ + @Scheduled(cron="0 0/5 * * * ?") + public void execute(){ + if (futureMap.size() > 0) { + for (String key : futureMap.keySet()) { + if (futureMap.get(key).isDone()) { + futureMap.remove(key); + runnableMap.remove(key); + } + } + } + } } diff --git a/src/main/java/com/genersoft/iot/vmp/conf/RedisConfig.java b/src/main/java/com/genersoft/iot/vmp/conf/RedisConfig.java index ec1f9bac..6a862ae3 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/RedisConfig.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/RedisConfig.java @@ -1,10 +1,7 @@ package com.genersoft.iot.vmp.conf; import com.genersoft.iot.vmp.common.VideoManagerConstants; -import com.genersoft.iot.vmp.service.impl.RedisAlarmMsgListener; -import com.genersoft.iot.vmp.service.impl.RedisGpsMsgListener; -import com.genersoft.iot.vmp.service.impl.RedisGbPlayMsgListener; -import com.genersoft.iot.vmp.service.impl.RedisStreamMsgListener; +import com.genersoft.iot.vmp.service.impl.*; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -60,6 +57,9 @@ public class RedisConfig extends CachingConfigurerSupport { @Autowired private RedisGbPlayMsgListener redisGbPlayMsgListener; + @Autowired + private RedisPushStreamStatusMsgListener redisPushStreamStatusMsgListener; + @Bean public JedisPool jedisPool() { if (StringUtils.isBlank(password)) { @@ -108,6 +108,7 @@ public class RedisConfig extends CachingConfigurerSupport { container.addMessageListener(redisAlarmMsgListener, new PatternTopic(VideoManagerConstants.VM_MSG_SUBSCRIBE_ALARM_RECEIVE)); container.addMessageListener(redisStreamMsgListener, new PatternTopic(VideoManagerConstants.WVP_MSG_STREAM_CHANGE_PREFIX + "PUSH")); container.addMessageListener(redisGbPlayMsgListener, new PatternTopic(RedisGbPlayMsgListener.WVP_PUSH_STREAM_KEY)); + container.addMessageListener(redisPushStreamStatusMsgListener, new PatternTopic(VideoManagerConstants.VM_MSG_PUSH_STREAM_STATUS_CHANGE)); return container; } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/ParentPlatform.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/ParentPlatform.java index 4377282d..61e777ad 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/ParentPlatform.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/ParentPlatform.java @@ -104,11 +104,6 @@ public class ParentPlatform { */ private int channelCount; - /** - * 共享所有的直播流 - */ - private boolean shareAllLiveStream; - /** * 默认目录Id,自动添加的通道多放在这个目录下 */ @@ -154,6 +149,11 @@ public class ParentPlatform { */ private String createTime; + /** + * 树类型 国标规定了两种树的展现方式 行政区划 CivilCode 和业务分组:BusinessGroup + */ + private String treeType; + public Integer getId() { return id; } @@ -314,15 +314,6 @@ public class ParentPlatform { this.channelCount = channelCount; } - - public boolean isShareAllLiveStream() { - return shareAllLiveStream; - } - - public void setShareAllLiveStream(boolean shareAllLiveStream) { - this.shareAllLiveStream = shareAllLiveStream; - } - public String getCatalogId() { return catalogId; } @@ -394,4 +385,12 @@ public class ParentPlatform { public void setCreateTime(String createTime) { this.createTime = createTime; } + + public String getTreeType() { + return treeType; + } + + public void setTreeType(String treeType) { + this.treeType = treeType; + } } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/PlatformCatalog.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/PlatformCatalog.java index 065971dd..58a9cbb0 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/PlatformCatalog.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/PlatformCatalog.java @@ -1,12 +1,28 @@ package com.genersoft.iot.vmp.gb28181.bean; +/** + * 国标级联-目录 + * @author lin + */ public class PlatformCatalog { private String id; private String name; private String platformId; private String parentId; - private int childrenCount; // 子节点数 - private int type; // 0 目录, 1 国标通道, 2 直播流 + + private String civilCode; + + private String businessGroupId; + + /** + * 子节点数 + */ + private int childrenCount; + + /** + * 0 目录, 1 国标通道, 2 直播流 + */ + private int type; public String getId() { return id; @@ -68,4 +84,19 @@ public class PlatformCatalog { this.type = 2; } + public String getCivilCode() { + return civilCode; + } + + public void setCivilCode(String civilCode) { + this.civilCode = civilCode; + } + + public String getBusinessGroupId() { + return businessGroupId; + } + + public void setBusinessGroupId(String businessGroupId) { + this.businessGroupId = businessGroupId; + } } diff --git a/src/main/java/com/genersoft/iot/vmp/domain/req/PresetQuerySipReq.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/PresetQuerySipReq.java similarity index 91% rename from src/main/java/com/genersoft/iot/vmp/domain/req/PresetQuerySipReq.java rename to src/main/java/com/genersoft/iot/vmp/gb28181/bean/PresetQuerySipReq.java index e2f3ec62..d1971a2e 100644 --- a/src/main/java/com/genersoft/iot/vmp/domain/req/PresetQuerySipReq.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/PresetQuerySipReq.java @@ -1,4 +1,4 @@ -package com.genersoft.iot.vmp.domain.req; +package com.genersoft.iot.vmp.gb28181.bean; /** diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/TreeType.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/TreeType.java new file mode 100644 index 00000000..bb684e1a --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/TreeType.java @@ -0,0 +1,10 @@ +package com.genersoft.iot.vmp.gb28181.bean; + +/** + * 目录结构类型 + * @author lin + */ +public class TreeType { + public static final String BUSINESS_GROUP = "BusinessGroup"; + public static final String CIVIL_CODE = "CivilCode"; +} diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformNotRegisterEventLister.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformNotRegisterEventLister.java index 14ed76a2..56bdeb58 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformNotRegisterEventLister.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformNotRegisterEventLister.java @@ -65,7 +65,6 @@ public class PlatformNotRegisterEventLister implements ApplicationListener sendRtpItems = redisCatchStorage.querySendRTPServer(event.getPlatformGbID()); - logger.info("[ 平台未注册事件 ] 停止[ {} ]的所有推流size", sendRtpItems.size()); if (sendRtpItems != null && sendRtpItems.size() > 0) { logger.info("[ 平台未注册事件 ] 停止[ {} ]的所有推流", event.getPlatformGbID()); for (SendRtpItem sendRtpItem : sendRtpItems) { diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEvent.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEvent.java index c035b808..5c064f75 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEvent.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEvent.java @@ -11,13 +11,40 @@ public class CatalogEvent extends ApplicationEvent { super(source); } - public static final String ON = "ON"; // 上线 - public static final String OFF = "OFF"; // 离线 - public static final String VLOST = "VLOST"; // 视频丢失 - public static final String DEFECT = "DEFECT"; // 故障 - public static final String ADD = "ADD"; // 增加 - public static final String DEL = "DEL"; // 删除 - public static final String UPDATE = "UPDATE"; // 更新 + /** + * 上线 + */ + public static final String ON = "ON"; + + /** + * 离线 + */ + public static final String OFF = "OFF"; + + /** + * 视频丢失 + */ + public static final String VLOST = "VLOST"; + + /** + * 故障 + */ + public static final String DEFECT = "DEFECT"; + + /** + * 增加 + */ + public static final String ADD = "ADD"; + + /** + * 删除 + */ + public static final String DEL = "DEL"; + + /** + * 更新 + */ + public static final String UPDATE = "UPDATE"; private List deviceChannels; private List gbStreams; diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEventLister.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEventLister.java index e38733d5..224fa1e6 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEventLister.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEventLister.java @@ -58,17 +58,16 @@ public class CatalogEventLister implements ApplicationListener { ParentPlatform parentPlatform = null; Map> parentPlatformMap = new HashMap<>(); - if (event.getPlatformId() != null) { + if (!StringUtils.isEmpty(event.getPlatformId())) { + subscribe = subscribeHolder.getCatalogSubscribe(event.getPlatformId()); + if (subscribe == null) { + return; + } parentPlatform = storager.queryParentPlatByServerGBId(event.getPlatformId()); if (parentPlatform != null && !parentPlatform.isStatus()) { return; } - subscribe = subscribeHolder.getCatalogSubscribe(event.getPlatformId()); - if (subscribe == null) { - logger.info("发送订阅消息时发现订阅信息已经不存在: {}", event.getPlatformId()); - return; - } }else { // 获取所用订阅 List platforms = subscribeHolder.getAllCatalogSubscribePlatform(); @@ -144,11 +143,8 @@ public class CatalogEventLister implements ApplicationListener { } if (event.getGbStreams() != null && event.getGbStreams().size() > 0){ for (GbStream gbStream : event.getGbStreams()) { - DeviceChannel deviceChannelByStream = gbStreamService.getDeviceChannelListByStream(gbStream, gbStream.getCatalogId(), parentPlatform); - if (deviceChannelByStream.getParentId().length() <= 10) { // 父节点是行政区划,则设置CivilCode使用此行政区划 - deviceChannelByStream.setCivilCode(deviceChannelByStream.getParentId()); - } - deviceChannelList.add(deviceChannelByStream); + deviceChannelList.add( + gbStreamService.getDeviceChannelListByStream(gbStream, gbStream.getCatalogId(), parentPlatform)); } } if (deviceChannelList.size() > 0) { diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/task/impl/MobilePositionSubscribeHandlerTask.java b/src/main/java/com/genersoft/iot/vmp/gb28181/task/impl/MobilePositionSubscribeHandlerTask.java index 66b57fec..7edee4dd 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/task/impl/MobilePositionSubscribeHandlerTask.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/task/impl/MobilePositionSubscribeHandlerTask.java @@ -57,23 +57,17 @@ public class MobilePositionSubscribeHandlerTask implements ISubscribeTask { SubscribeInfo subscribe = subscribeHolder.getMobilePositionSubscribe(platform.getServerGBId()); if (subscribe != null) { -// if (!parentPlatform.isStatus()) { -// logger.info("发送订阅时发现平台已经离线:{}", platformId); -// return; -// } // TODO 暂时只处理视频流的回复,后续增加对国标设备的支持 - List gbStreams = storager.queryGbStreamListInPlatform(platform.getServerGBId()); + List gbStreams = storager.queryGbStreamListInPlatform(platform.getServerGBId()); if (gbStreams.size() == 0) { logger.info("发送订阅时发现平台已经没有关联的直播流:{}", platform.getServerGBId()); return; } - for (GbStream gbStream : gbStreams) { - String gbId = gbStream.getGbId(); + for (DeviceChannel deviceChannel : gbStreams) { + String gbId = deviceChannel.getChannelId(); GPSMsgInfo gpsMsgInfo = redisCatchStorage.getGpsMsgInfo(gbId); - if (gpsMsgInfo != null) { // 无最新位置不发送 - if (logger.isDebugEnabled()) { - logger.debug("无最新位置不发送"); - } + // 无最新位置不发送 + if (gpsMsgInfo != null) { // 经纬度都为0不发送 if (gpsMsgInfo.getLng() == 0 && gpsMsgInfo.getLat() == 0) { continue; diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java index 73f9c4f7..10f428b0 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java @@ -257,37 +257,37 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { catalogXml.append("\r\n"); if (channels.size() > 0) { for (DeviceChannel channel : channels) { + if (parentPlatform.getServerGBId().equals(channel.getParentId())) { + channel.setParentId(parentPlatform.getDeviceGBId()); + } catalogXml.append("\r\n"); + // 行政区划分组只需要这两项就可以 catalogXml.append("" + channel.getChannelId() + "\r\n"); catalogXml.append("" + channel.getName() + "\r\n"); - catalogXml.append("" + channel.getParental() + "\r\n"); if (channel.getParentId() != null) { + // 业务分组加上这一项即可,提高兼容性, catalogXml.append("" + channel.getParentId() + "\r\n"); } - if (channel.getChannelId().length() == 20) { - if (Integer.parseInt(channel.getChannelId().substring(10, 13)) == 216) { // 虚拟组织增加BusinessGroupID字段 - catalogXml.append("" + channel.getParentId() + "\r\n"); - } + if (channel.getChannelId().length() == 20 && Integer.parseInt(channel.getChannelId().substring(10, 13)) == 216) { + // 虚拟组织增加BusinessGroupID字段 + catalogXml.append("" + channel.getParentId() + "\r\n"); + } + catalogXml.append("" + channel.getParental() + "\r\n"); + if (channel.getParental() == 0) { + // 通道项 catalogXml.append("" + channel.getManufacture() + "\r\n"); + catalogXml.append("" + channel.getSecrecy() + "\r\n"); catalogXml.append("" + channel.getRegisterWay() + "\r\n"); - catalogXml.append("" + (channel.getStatus() == 0?"OFF":"ON") + "\r\n"); - if (channel.getChannelType() != 2) { // 业务分组/虚拟组织/行政区划 不设置以下字段 - catalogXml.append("" + channel.getSecrecy() + "\r\n"); + catalogXml.append("" + (channel.getStatus() == 0 ? "OFF" : "ON") + "\r\n"); + + if (channel.getChannelType() != 2) { // 业务分组/虚拟组织/行政区划 不设置以下属性 catalogXml.append("" + channel.getModel() + "\r\n"); - catalogXml.append("" + channel.getOwner() + "\r\n"); + catalogXml.append(" " + channel.getOwner()+ "\r\n"); catalogXml.append("" + channel.getCivilCode() + "\r\n"); catalogXml.append("
" + channel.getAddress() + "
\r\n"); - catalogXml.append("" + channel.getLongitudeWgs84() + "\r\n"); - catalogXml.append("" + channel.getLatitudeWgs84() + "\r\n"); - catalogXml.append("" + channel.getIpAddress() + "\r\n"); - catalogXml.append("" + channel.getPort() + "\r\n"); - catalogXml.append("\r\n"); - catalogXml.append("" + channel.getPTZType() + "\r\n"); - catalogXml.append("\r\n"); } + } - - catalogXml.append("
\r\n"); } } @@ -592,27 +592,35 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { channel.setParentId(parentPlatform.getDeviceGBId()); } catalogXml.append("\r\n"); + // 行政区划分组只需要这两项就可以 catalogXml.append("" + channel.getChannelId() + "\r\n"); catalogXml.append("" + channel.getName() + "\r\n"); - catalogXml.append("" + channel.getManufacture() + "\r\n"); - catalogXml.append("" + channel.getParental() + "\r\n"); if (channel.getParentId() != null) { + // 业务分组加上这一项即可,提高兼容性, catalogXml.append("" + channel.getParentId() + "\r\n"); } - catalogXml.append("" + channel.getSecrecy() + "\r\n"); - catalogXml.append("" + channel.getRegisterWay() + "\r\n"); - catalogXml.append("" + (channel.getStatus() == 0 ? "OFF" : "ON") + "\r\n"); - if (channel.getChannelId().length() == 20 && Integer.parseInt(channel.getChannelId().substring(10, 13)) == 216) { // 虚拟组织增加BusinessGroupID字段 + if (channel.getChannelId().length() == 20 && Integer.parseInt(channel.getChannelId().substring(10, 13)) == 216) { + // 虚拟组织增加BusinessGroupID字段 catalogXml.append("" + channel.getParentId() + "\r\n"); } - if (channel.getChannelType() == 2) { // 业务分组/虚拟组织/行政区划 不设置以下属性 - catalogXml.append("" + channel.getModel() + "\r\n"); - catalogXml.append("0\r\n"); - catalogXml.append("CivilCode\r\n"); - catalogXml.append("
" + channel.getAddress() + "
\r\n"); - } - if (!"presence".equals(subscribeInfo.getEventType())) { - catalogXml.append("" + type + "\r\n"); + catalogXml.append("" + channel.getParental() + "\r\n"); + if (channel.getParental() == 0) { + // 通道项 + catalogXml.append("" + channel.getManufacture() + "\r\n"); + catalogXml.append("" + channel.getSecrecy() + "\r\n"); + catalogXml.append("" + channel.getRegisterWay() + "\r\n"); + catalogXml.append("" + (channel.getStatus() == 0 ? "OFF" : "ON") + "\r\n"); + + if (channel.getChannelType() != 2) { // 业务分组/虚拟组织/行政区划 不设置以下属性 + catalogXml.append("" + channel.getModel() + "\r\n"); + catalogXml.append(" " + channel.getOwner()+ "\r\n"); + catalogXml.append("" + channel.getCivilCode() + "\r\n"); + catalogXml.append("
" + channel.getAddress() + "
\r\n"); + } + if (!"presence".equals(subscribeInfo.getEventType())) { + catalogXml.append("" + type + "\r\n"); + } + } catalogXml.append("
\r\n"); } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java index 376d74b0..c8a221bd 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java @@ -15,6 +15,7 @@ import com.genersoft.iot.vmp.gb28181.utils.Coordtransform; import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; import com.genersoft.iot.vmp.gb28181.utils.SipUtils; import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; +import com.genersoft.iot.vmp.service.IDeviceChannelService; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.IVideoManagerStorage; import com.genersoft.iot.vmp.utils.DateUtil; @@ -71,6 +72,9 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements @Autowired private SIPProcessorObserver sipProcessorObserver; + @Autowired + private IDeviceChannelService deviceChannelService; + private boolean taskQueueHandlerRun = false; private final ConcurrentLinkedQueue taskQueue = new ConcurrentLinkedQueue<>(); @@ -173,28 +177,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements logger.info("[收到 移动位置订阅]:{}/{}->{}.{}", mobilePosition.getDeviceId(), mobilePosition.getChannelId(), mobilePosition.getLongitude(), mobilePosition.getLatitude()); mobilePosition.setReportSource("Mobile Position"); - // 默认来源坐标系为WGS-84处理 - if ("WGS84".equals(device.getGeoCoordSys())) { - mobilePosition.setLongitudeWgs84(mobilePosition.getLongitude()); - mobilePosition.setLatitudeWgs84(mobilePosition.getLatitude()); - Double[] position = Coordtransform.WGS84ToGCJ02(mobilePosition.getLongitude(), mobilePosition.getLatitude()); - mobilePosition.setLongitudeGcj02(position[0]); - mobilePosition.setLatitudeGcj02(position[1]); - }else if ("GCJ02".equals(device.getGeoCoordSys())) { - mobilePosition.setLongitudeGcj02(mobilePosition.getLongitude()); - mobilePosition.setLatitudeGcj02(mobilePosition.getLatitude()); - Double[] position = Coordtransform.GCJ02ToWGS84(mobilePosition.getLongitude(), mobilePosition.getLatitude()); - mobilePosition.setLongitudeWgs84(position[0]); - mobilePosition.setLatitudeWgs84(position[1]); - }else { - mobilePosition.setLongitudeGcj02(0.00); - mobilePosition.setLatitudeGcj02(0.00); - mobilePosition.setLongitudeWgs84(0.00); - mobilePosition.setLatitudeWgs84(0.00); - } - if (userSetting.getSavePositionHistory()) { - storager.insertMobilePosition(mobilePosition); - } + // 更新device channel 的经纬度 DeviceChannel deviceChannel = new DeviceChannel(); @@ -202,11 +185,18 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements deviceChannel.setChannelId(channelId); deviceChannel.setLongitude(mobilePosition.getLongitude()); deviceChannel.setLatitude(mobilePosition.getLatitude()); - deviceChannel.setLongitudeWgs84(mobilePosition.getLongitudeWgs84()); - deviceChannel.setLatitudeWgs84(mobilePosition.getLatitudeWgs84()); - deviceChannel.setLongitudeGcj02(mobilePosition.getLongitudeGcj02()); - deviceChannel.setLatitudeGcj02(mobilePosition.getLatitudeGcj02()); deviceChannel.setGpsTime(mobilePosition.getTime()); + deviceChannel = deviceChannelService.updateGps(deviceChannel, device); + + mobilePosition.setLongitudeWgs84(deviceChannel.getLongitudeWgs84()); + mobilePosition.setLatitudeWgs84(deviceChannel.getLatitudeWgs84()); + mobilePosition.setLongitudeGcj02(deviceChannel.getLongitudeGcj02()); + mobilePosition.setLatitudeGcj02(deviceChannel.getLatitudeGcj02()); + + if (userSetting.getSavePositionHistory()) { + storager.insertMobilePosition(mobilePosition); + } + storager.updateChannelPosition(deviceChannel); // 发送redis消息。 通知位置信息的变化 JSONObject jsonObject = new JSONObject(); @@ -281,38 +271,28 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements mobilePosition.setLongitude(deviceAlarm.getLongitude()); mobilePosition.setLatitude(deviceAlarm.getLatitude()); mobilePosition.setReportSource("GPS Alarm"); - if ("WGS84".equals(device.getGeoCoordSys())) { - mobilePosition.setLongitudeWgs84(mobilePosition.getLongitude()); - mobilePosition.setLatitudeWgs84(mobilePosition.getLatitude()); - Double[] position = Coordtransform.WGS84ToGCJ02(mobilePosition.getLongitude(), mobilePosition.getLatitude()); - mobilePosition.setLongitudeGcj02(position[0]); - mobilePosition.setLatitudeGcj02(position[1]); - }else if ("GCJ02".equals(device.getGeoCoordSys())) { - mobilePosition.setLongitudeGcj02(mobilePosition.getLongitude()); - mobilePosition.setLatitudeGcj02(mobilePosition.getLatitude()); - Double[] position = Coordtransform.GCJ02ToWGS84(mobilePosition.getLongitude(), mobilePosition.getLatitude()); - mobilePosition.setLongitudeWgs84(position[0]); - mobilePosition.setLatitudeWgs84(position[1]); - }else { - mobilePosition.setLongitudeGcj02(0.00); - mobilePosition.setLatitudeGcj02(0.00); - mobilePosition.setLongitudeWgs84(0.00); - mobilePosition.setLatitudeWgs84(0.00); - } - if (userSetting.getSavePositionHistory()) { - storager.insertMobilePosition(mobilePosition); - } + + + // 更新device channel 的经纬度 DeviceChannel deviceChannel = new DeviceChannel(); deviceChannel.setDeviceId(device.getDeviceId()); deviceChannel.setChannelId(channelId); deviceChannel.setLongitude(mobilePosition.getLongitude()); deviceChannel.setLatitude(mobilePosition.getLatitude()); - deviceChannel.setLongitudeWgs84(mobilePosition.getLongitudeWgs84()); - deviceChannel.setLatitudeWgs84(mobilePosition.getLatitudeWgs84()); - deviceChannel.setLongitudeGcj02(mobilePosition.getLongitudeGcj02()); - deviceChannel.setLatitudeGcj02(mobilePosition.getLatitudeGcj02()); deviceChannel.setGpsTime(mobilePosition.getTime()); + + deviceChannel = deviceChannelService.updateGps(deviceChannel, device); + + mobilePosition.setLongitudeWgs84(deviceChannel.getLongitudeWgs84()); + mobilePosition.setLatitudeWgs84(deviceChannel.getLatitudeWgs84()); + mobilePosition.setLongitudeGcj02(deviceChannel.getLongitudeGcj02()); + mobilePosition.setLatitudeGcj02(deviceChannel.getLatitudeGcj02()); + + if (userSetting.getSavePositionHistory()) { + storager.insertMobilePosition(mobilePosition); + } + storager.updateChannelPosition(deviceChannel); } // TODO: 需要实现存储报警信息、报警分类 @@ -364,7 +344,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements }else { event = eventElement.getText().toUpperCase(); } - DeviceChannel channel = XmlUtil.channelContentHander(itemDevice, device); + DeviceChannel channel = XmlUtil.channelContentHander(itemDevice, device, event); channel.setDeviceId(device.getDeviceId()); logger.info("[收到 目录订阅]:{}/{}", device.getDeviceId(), channel.getChannelId()); switch (event) { @@ -389,7 +369,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements case CatalogEvent.ADD: // 增加 logger.info("收到来自设备【{}】的增加通道【{}】通知", device.getDeviceId(), channel.getChannelId()); - storager.updateChannel(deviceId, channel); + deviceChannelService.updateChannel(deviceId, channel); break; case CatalogEvent.DEL: // 删除 @@ -399,7 +379,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements case CatalogEvent.UPDATE: // 更新 logger.info("收到来自设备【{}】的更新通道【{}】通知", device.getDeviceId(), channel.getChannelId()); - storager.updateChannel(deviceId, channel); + deviceChannelService.updateChannel(deviceId, channel); break; default: logger.warn("[ NotifyCatalog ] event not found : {}", event ); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java index 8dfd2331..265694ae 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java @@ -11,6 +11,7 @@ import com.genersoft.iot.vmp.gb28181.utils.Coordtransform; import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; import com.genersoft.iot.vmp.service.IDeviceAlarmService; +import com.genersoft.iot.vmp.service.IDeviceChannelService; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.IVideoManagerStorage; import com.genersoft.iot.vmp.utils.DateUtil; @@ -58,6 +59,9 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme @Autowired private IDeviceAlarmService deviceAlarmService; + @Autowired + private IDeviceChannelService deviceChannelService; + @Override public void afterPropertiesSet() throws Exception { notifyMessageHandler.addHandler(cmdType, this); @@ -119,38 +123,26 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme mobilePosition.setLongitude(deviceAlarm.getLongitude()); mobilePosition.setLatitude(deviceAlarm.getLatitude()); mobilePosition.setReportSource("GPS Alarm"); - if ("WGS84".equals(device.getGeoCoordSys())) { - mobilePosition.setLongitudeWgs84(mobilePosition.getLongitude()); - mobilePosition.setLatitudeWgs84(mobilePosition.getLatitude()); - Double[] position = Coordtransform.WGS84ToGCJ02(mobilePosition.getLongitude(), mobilePosition.getLatitude()); - mobilePosition.setLongitudeGcj02(position[0]); - mobilePosition.setLatitudeGcj02(position[1]); - }else if ("GCJ02".equals(device.getGeoCoordSys())) { - mobilePosition.setLongitudeGcj02(mobilePosition.getLongitude()); - mobilePosition.setLatitudeGcj02(mobilePosition.getLatitude()); - Double[] position = Coordtransform.GCJ02ToWGS84(mobilePosition.getLongitude(), mobilePosition.getLatitude()); - mobilePosition.setLongitudeWgs84(position[0]); - mobilePosition.setLatitudeWgs84(position[1]); - }else { - mobilePosition.setLongitudeGcj02(0.00); - mobilePosition.setLatitudeGcj02(0.00); - mobilePosition.setLongitudeWgs84(0.00); - mobilePosition.setLatitudeWgs84(0.00); - } - if (userSetting.getSavePositionHistory()) { - storager.insertMobilePosition(mobilePosition); - } + + // 更新device channel 的经纬度 DeviceChannel deviceChannel = new DeviceChannel(); deviceChannel.setDeviceId(device.getDeviceId()); deviceChannel.setChannelId(channelId); deviceChannel.setLongitude(mobilePosition.getLongitude()); deviceChannel.setLatitude(mobilePosition.getLatitude()); - deviceChannel.setLongitudeWgs84(mobilePosition.getLongitudeWgs84()); - deviceChannel.setLatitudeWgs84(mobilePosition.getLatitudeWgs84()); - deviceChannel.setLongitudeGcj02(mobilePosition.getLongitudeGcj02()); - deviceChannel.setLatitudeGcj02(mobilePosition.getLatitudeGcj02()); deviceChannel.setGpsTime(mobilePosition.getTime()); + + deviceChannel = deviceChannelService.updateGps(deviceChannel, device); + + mobilePosition.setLongitudeWgs84(deviceChannel.getLongitudeWgs84()); + mobilePosition.setLatitudeWgs84(deviceChannel.getLatitudeWgs84()); + mobilePosition.setLongitudeGcj02(deviceChannel.getLongitudeGcj02()); + mobilePosition.setLatitudeGcj02(deviceChannel.getLatitudeGcj02()); + + if (userSetting.getSavePositionHistory()) { + storager.insertMobilePosition(mobilePosition); + } storager.updateChannelPosition(deviceChannel); } } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/CatalogNotifyMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/CatalogNotifyMessageHandler.java index d714ee4f..0b27855f 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/CatalogNotifyMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/CatalogNotifyMessageHandler.java @@ -58,85 +58,21 @@ public class CatalogNotifyMessageHandler extends SIPRequestProcessorParent imple // 准备回复通道信息 List deviceChannels = storage.queryChannelListInParentPlatform(parentPlatform.getServerGBId()); // 查询关联的直播通道 - List gbStreams = storage.queryGbStreamListInPlatform(parentPlatform.getServerGBId()); + List gbStreams = storage.queryGbStreamListInPlatform(parentPlatform.getServerGBId()); + // 回复目录信息 + List catalogs = storage.queryCatalogInPlatform(parentPlatform.getServerGBId()); List allChannels = new ArrayList<>(); - // 回复目录信息 - List catalogs = storage.queryCatalogInPlatform(parentPlatform.getServerGBId()); if (catalogs.size() > 0) { - for (PlatformCatalog catalog : catalogs) { - if (catalog.getParentId().equals(catalog.getPlatformId())) { - catalog.setParentId(parentPlatform.getDeviceGBId()); - } - DeviceChannel deviceChannel = new DeviceChannel(); - deviceChannel.setChannelId(catalog.getId()); - deviceChannel.setName(catalog.getName()); - deviceChannel.setLongitude(0.0); - deviceChannel.setLatitude(0.0); - deviceChannel.setDeviceId(parentPlatform.getDeviceGBId()); - deviceChannel.setManufacture("wvp-pro"); - deviceChannel.setStatus(1); - deviceChannel.setParental(1); - deviceChannel.setParentId(catalog.getParentId()); - deviceChannel.setRegisterWay(1); - if (catalog.getParentId() != null && catalog.getParentId().length() <= 10) { - deviceChannel.setCivilCode(catalog.getParentId()); - }else { - deviceChannel.setCivilCode(parentPlatform.getAdministrativeDivision()); - } - deviceChannel.setCivilCode(parentPlatform.getAdministrativeDivision()); - deviceChannel.setModel("live"); - deviceChannel.setOwner("wvp-pro"); - deviceChannel.setSecrecy("0"); - allChannels.add(deviceChannel); - } + allChannels.addAll(catalogs); } // 回复级联的通道 if (deviceChannels.size() > 0) { - for (DeviceChannelInPlatform channel : deviceChannels) { - if (channel.getCatalogId().equals(parentPlatform.getServerGBId())) { - channel.setCatalogId(parentPlatform.getDeviceGBId()); - } - DeviceChannel deviceChannel = storage.queryChannel(channel.getDeviceId(), channel.getChannelId()); - deviceChannel.setParental(0); - deviceChannel.setParentId(channel.getCatalogId()); - if (channel.getCatalogId() != null && channel.getCatalogId().length() <= 10) { - channel.setCivilCode(channel.getCatalogId()); - }else { - deviceChannel.setCivilCode(parentPlatform.getAdministrativeDivision()); - } - - allChannels.add(deviceChannel); - } + allChannels.addAll(deviceChannels); } // 回复直播的通道 if (gbStreams.size() > 0) { - for (GbStream gbStream : gbStreams) { - if (gbStream.getCatalogId().equals(parentPlatform.getServerGBId())) { - gbStream.setCatalogId(null); - } - DeviceChannel deviceChannel = new DeviceChannel(); - deviceChannel.setChannelId(gbStream.getGbId()); - deviceChannel.setName(gbStream.getName()); - deviceChannel.setLongitude(gbStream.getLongitude()); - deviceChannel.setLatitude(gbStream.getLatitude()); - deviceChannel.setDeviceId(parentPlatform.getDeviceGBId()); - deviceChannel.setManufacture("wvp-pro"); -// deviceChannel.setStatus(gbStream.isStatus()?1:0); - deviceChannel.setStatus(1); - deviceChannel.setParentId(gbStream.getCatalogId()); - deviceChannel.setRegisterWay(1); - if (gbStream.getCatalogId() != null && gbStream.getCatalogId().length() <= 10) { - deviceChannel.setCivilCode(gbStream.getCatalogId()); - }else { - deviceChannel.setCivilCode(parentPlatform.getAdministrativeDivision()); - } - deviceChannel.setModel("live"); - deviceChannel.setOwner("wvp-pro"); - deviceChannel.setParental(0); - deviceChannel.setSecrecy("0"); - allChannels.add(deviceChannel); - } + allChannels.addAll(gbStreams); } if (allChannels.size() > 0) { cmderFroPlatform.catalogQuery(allChannels, parentPlatform, sn, fromHeader.getTag()); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MobilePositionNotifyMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MobilePositionNotifyMessageHandler.java index aa91556f..2402494c 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MobilePositionNotifyMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MobilePositionNotifyMessageHandler.java @@ -7,6 +7,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessag import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.NotifyMessageHandler; import com.genersoft.iot.vmp.gb28181.utils.Coordtransform; import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; +import com.genersoft.iot.vmp.service.IDeviceChannelService; import com.genersoft.iot.vmp.storager.IVideoManagerStorage; import com.genersoft.iot.vmp.utils.DateUtil; import com.genersoft.iot.vmp.utils.GpsUtil; @@ -42,6 +43,9 @@ public class MobilePositionNotifyMessageHandler extends SIPRequestProcessorParen @Autowired private IVideoManagerStorage storager; + @Autowired + private IDeviceChannelService deviceChannelService; + @Override public void afterPropertiesSet() throws Exception { notifyMessageHandler.addHandler(cmdType, this); @@ -79,38 +83,26 @@ public class MobilePositionNotifyMessageHandler extends SIPRequestProcessorParen mobilePosition.setAltitude(0.0); } mobilePosition.setReportSource("Mobile Position"); - if ("WGS84".equals(device.getGeoCoordSys())) { - mobilePosition.setLongitudeWgs84(mobilePosition.getLongitude()); - mobilePosition.setLatitudeWgs84(mobilePosition.getLatitude()); - Double[] position = Coordtransform.WGS84ToGCJ02(mobilePosition.getLongitude(), mobilePosition.getLatitude()); - mobilePosition.setLongitudeGcj02(position[0]); - mobilePosition.setLatitudeGcj02(position[1]); - }else if ("GCJ02".equals(device.getGeoCoordSys())) { - mobilePosition.setLongitudeGcj02(mobilePosition.getLongitude()); - mobilePosition.setLatitudeGcj02(mobilePosition.getLatitude()); - Double[] position = Coordtransform.GCJ02ToWGS84(mobilePosition.getLongitude(), mobilePosition.getLatitude()); - mobilePosition.setLongitudeWgs84(position[0]); - mobilePosition.setLatitudeWgs84(position[1]); - }else { - mobilePosition.setLongitudeGcj02(0.00); - mobilePosition.setLatitudeGcj02(0.00); - mobilePosition.setLongitudeWgs84(0.00); - mobilePosition.setLatitudeWgs84(0.00); - } - if (userSetting.getSavePositionHistory()) { - storager.insertMobilePosition(mobilePosition); - } + + // 更新device channel 的经纬度 DeviceChannel deviceChannel = new DeviceChannel(); deviceChannel.setDeviceId(device.getDeviceId()); deviceChannel.setChannelId(mobilePosition.getChannelId()); deviceChannel.setLongitude(mobilePosition.getLongitude()); deviceChannel.setLatitude(mobilePosition.getLatitude()); - deviceChannel.setLongitudeWgs84(mobilePosition.getLongitudeWgs84()); - deviceChannel.setLatitudeWgs84(mobilePosition.getLatitudeWgs84()); - deviceChannel.setLongitudeGcj02(mobilePosition.getLongitudeGcj02()); - deviceChannel.setLatitudeGcj02(mobilePosition.getLatitudeGcj02()); deviceChannel.setGpsTime(mobilePosition.getTime()); + + deviceChannel = deviceChannelService.updateGps(deviceChannel, device); + + mobilePosition.setLongitudeWgs84(deviceChannel.getLongitudeWgs84()); + mobilePosition.setLatitudeWgs84(deviceChannel.getLatitudeWgs84()); + mobilePosition.setLongitudeGcj02(deviceChannel.getLongitudeGcj02()); + mobilePosition.setLatitudeGcj02(deviceChannel.getLatitudeGcj02()); + + if (userSetting.getSavePositionHistory()) { + storager.insertMobilePosition(mobilePosition); + } storager.updateChannelPosition(deviceChannel); //回复 200 OK responseAck(evt, Response.OK); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/query/cmd/CatalogQueryMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/query/cmd/CatalogQueryMessageHandler.java index 0e979619..7f6f8177 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/query/cmd/CatalogQueryMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/query/cmd/CatalogQueryMessageHandler.java @@ -70,86 +70,24 @@ public class CatalogQueryMessageHandler extends SIPRequestProcessorParent implem Element snElement = rootElement.element("SN"); String sn = snElement.getText(); // 准备回复通道信息 - List deviceChannelInPlatforms = storager.queryChannelListInParentPlatform(parentPlatform.getServerGBId()); + List deviceChannelInPlatforms = storager.queryChannelWithCatalog(parentPlatform.getServerGBId()); // 查询关联的直播通道 - List gbStreams = storager.queryGbStreamListInPlatform(parentPlatform.getServerGBId()); + List gbStreams = storager.queryGbStreamListInPlatform(parentPlatform.getServerGBId()); // 回复目录信息 - List catalogs = storager.queryCatalogInPlatform(parentPlatform.getServerGBId()); + List catalogs = storager.queryCatalogInPlatform(parentPlatform.getServerGBId()); List allChannels = new ArrayList<>(); + if (catalogs.size() > 0) { - for (PlatformCatalog catalog : catalogs) { - if (catalog.getParentId().equals(catalog.getPlatformId())) { - catalog.setParentId(parentPlatform.getDeviceGBId()); - } - DeviceChannel deviceChannel = new DeviceChannel(); - // 通道的类型,0->国标通道 1->直播流通道 2->业务分组/虚拟组织/行政区划 - deviceChannel.setChannelType(2); - deviceChannel.setChannelId(catalog.getId()); - deviceChannel.setName(catalog.getName()); - deviceChannel.setDeviceId(parentPlatform.getDeviceGBId()); - deviceChannel.setManufacture("wvp-pro"); - deviceChannel.setStatus(1); - deviceChannel.setParental(1); - deviceChannel.setParentId(catalog.getParentId()); - deviceChannel.setRegisterWay(1); - if (catalog.getParentId() != null && catalog.getParentId().length() < 10) { - deviceChannel.setCivilCode(catalog.getParentId()); - }else { - deviceChannel.setCivilCode(parentPlatform.getAdministrativeDivision()); - } - allChannels.add(deviceChannel); - } + allChannels.addAll(catalogs); } // 回复级联的通道 if (deviceChannelInPlatforms.size() > 0) { - for (DeviceChannelInPlatform channel : deviceChannelInPlatforms) { - if (channel.getCatalogId().equals(parentPlatform.getServerGBId())) { - channel.setCatalogId(parentPlatform.getDeviceGBId()); - } - DeviceChannel deviceChannel = storage.queryChannel(channel.getDeviceId(), channel.getChannelId()); - // 通道的类型,0->国标通道 1->直播流通道 2->业务分组/虚拟组织/行政区划 - deviceChannel.setChannelType(0); - deviceChannel.setParental(0); - deviceChannel.setParentId(channel.getCatalogId()); - if (channel.getCatalogId() != null && channel.getCatalogId().length() < 10) { - deviceChannel.setCivilCode(channel.getCatalogId()); - }else { - deviceChannel.setCivilCode(parentPlatform.getAdministrativeDivision()); - } - allChannels.add(deviceChannel); - } + allChannels.addAll(deviceChannelInPlatforms); } // 回复直播的通道 if (gbStreams.size() > 0) { - for (GbStream gbStream : gbStreams) { - if (gbStream.getCatalogId().equals(parentPlatform.getServerGBId())) { - gbStream.setCatalogId(null); - } - DeviceChannel deviceChannel = new DeviceChannel(); - // 通道的类型,0->国标通道 1->直播流通道 2->业务分组/虚拟组织/行政区划 - deviceChannel.setChannelType(1); - deviceChannel.setChannelId(gbStream.getGbId()); - deviceChannel.setName(gbStream.getName()); - deviceChannel.setLongitude(gbStream.getLongitude()); - deviceChannel.setLatitude(gbStream.getLatitude()); - deviceChannel.setDeviceId(parentPlatform.getDeviceGBId()); - deviceChannel.setManufacture("wvp-pro"); -// deviceChannel.setStatus(gbStream.isStatus()?1:0); - deviceChannel.setStatus(1); - deviceChannel.setParentId(gbStream.getCatalogId()); - deviceChannel.setRegisterWay(1); - if (gbStream.getCatalogId() != null && gbStream.getCatalogId().length() < 10) { - deviceChannel.setCivilCode(gbStream.getCatalogId()); - }else { - deviceChannel.setCivilCode(parentPlatform.getAdministrativeDivision()); - } - deviceChannel.setModel("live"); - deviceChannel.setOwner("wvp-pro"); - deviceChannel.setParental(0); - deviceChannel.setSecrecy("0"); - allChannels.add(deviceChannel); - } + allChannels.addAll(gbStreams); } if (allChannels.size() > 0) { cmderFroPlatform.catalogQuery(allChannels, parentPlatform, sn, fromHeader.getTag()); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java index 2766474e..66e92c52 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java @@ -125,11 +125,7 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp if (channelDeviceElement == null) { continue; } - //by brewswang - // if (NumericUtil.isDouble(XmlUtil.getText(itemDevice, "Longitude"))) {//如果包含位置信息,就更新一下位置 - // processNotifyMobilePosition(evt, itemDevice); - // } - DeviceChannel deviceChannel = XmlUtil.channelContentHander(itemDevice, device); + DeviceChannel deviceChannel = XmlUtil.channelContentHander(itemDevice, device, null); deviceChannel.setDeviceId(take.getDevice().getDeviceId()); channelList.add(deviceChannel); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceInfoResponseMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceInfoResponseMessageHandler.java index eb2c7b8f..f5d04be9 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceInfoResponseMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceInfoResponseMessageHandler.java @@ -87,7 +87,6 @@ public class DeviceInfoResponseMessageHandler extends SIPRequestProcessorParent device.setStreamMode("UDP"); } deviceService.updateDevice(device); -// storager.updateDevice(device); RequestMessage msg = new RequestMessage(); msg.setKey(key); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/MobilePositionResponseMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/MobilePositionResponseMessageHandler.java index e562fa45..4c723abd 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/MobilePositionResponseMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/MobilePositionResponseMessageHandler.java @@ -7,6 +7,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessag import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler; import com.genersoft.iot.vmp.gb28181.utils.Coordtransform; import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; +import com.genersoft.iot.vmp.service.IDeviceChannelService; import com.genersoft.iot.vmp.storager.IVideoManagerStorage; import com.genersoft.iot.vmp.utils.DateUtil; import com.genersoft.iot.vmp.utils.GpsUtil; @@ -42,6 +43,9 @@ public class MobilePositionResponseMessageHandler extends SIPRequestProcessorPar @Autowired private IVideoManagerStorage storager; + @Autowired + private IDeviceChannelService deviceChannelService; + @Override public void afterPropertiesSet() throws Exception { responseMessageHandler.addHandler(cmdType, this); @@ -79,38 +83,25 @@ public class MobilePositionResponseMessageHandler extends SIPRequestProcessorPar mobilePosition.setAltitude(0.0); } mobilePosition.setReportSource("Mobile Position"); - if ("WGS84".equals(device.getGeoCoordSys())) { - mobilePosition.setLongitudeWgs84(mobilePosition.getLongitude()); - mobilePosition.setLatitudeWgs84(mobilePosition.getLatitude()); - Double[] position = Coordtransform.WGS84ToGCJ02(mobilePosition.getLongitude(), mobilePosition.getLatitude()); - mobilePosition.setLongitudeGcj02(position[0]); - mobilePosition.setLatitudeGcj02(position[1]); - }else if ("GCJ02".equals(device.getGeoCoordSys())) { - mobilePosition.setLongitudeGcj02(mobilePosition.getLongitude()); - mobilePosition.setLatitudeGcj02(mobilePosition.getLatitude()); - Double[] position = Coordtransform.GCJ02ToWGS84(mobilePosition.getLongitude(), mobilePosition.getLatitude()); - mobilePosition.setLongitudeWgs84(position[0]); - mobilePosition.setLatitudeWgs84(position[1]); - }else { - mobilePosition.setLongitudeGcj02(0.00); - mobilePosition.setLatitudeGcj02(0.00); - mobilePosition.setLongitudeWgs84(0.00); - mobilePosition.setLatitudeWgs84(0.00); - } - if (userSetting.getSavePositionHistory()) { - storager.insertMobilePosition(mobilePosition); - } + // 更新device channel 的经纬度 DeviceChannel deviceChannel = new DeviceChannel(); deviceChannel.setDeviceId(device.getDeviceId()); deviceChannel.setChannelId(mobilePosition.getChannelId()); deviceChannel.setLongitude(mobilePosition.getLongitude()); deviceChannel.setLatitude(mobilePosition.getLatitude()); - deviceChannel.setLongitudeWgs84(mobilePosition.getLongitudeWgs84()); - deviceChannel.setLatitudeWgs84(mobilePosition.getLatitudeWgs84()); - deviceChannel.setLongitudeGcj02(mobilePosition.getLongitudeGcj02()); - deviceChannel.setLatitudeGcj02(mobilePosition.getLatitudeGcj02()); deviceChannel.setGpsTime(mobilePosition.getTime()); + + deviceChannel = deviceChannelService.updateGps(deviceChannel, device); + + mobilePosition.setLongitudeWgs84(deviceChannel.getLongitudeWgs84()); + mobilePosition.setLatitudeWgs84(deviceChannel.getLatitudeWgs84()); + mobilePosition.setLongitudeGcj02(deviceChannel.getLongitudeGcj02()); + mobilePosition.setLatitudeGcj02(deviceChannel.getLatitudeGcj02()); + + if (userSetting.getSavePositionHistory()) { + storager.insertMobilePosition(mobilePosition); + } storager.updateChannelPosition(deviceChannel); //回复 200 OK responseAck(evt, Response.OK); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/PresetQueryResponseMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/PresetQueryResponseMessageHandler.java index 36626004..45265c5b 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/PresetQueryResponseMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/PresetQueryResponseMessageHandler.java @@ -1,6 +1,6 @@ package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd; -import com.genersoft.iot.vmp.domain.req.PresetQuerySipReq; +import com.genersoft.iot.vmp.gb28181.bean.PresetQuerySipReq; import com.genersoft.iot.vmp.gb28181.bean.*; import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java b/src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java index 72206d87..ced97efe 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java @@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; +import com.genersoft.iot.vmp.gb28181.bean.TreeType; +import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; import com.genersoft.iot.vmp.utils.DateUtil; import org.dom4j.Attribute; import org.dom4j.Document; @@ -29,7 +31,7 @@ public class XmlUtil { /** * 日志服务 */ - private static Logger LOG = LoggerFactory.getLogger(XmlUtil.class); + private static Logger logger = LoggerFactory.getLogger(XmlUtil.class); /** * 解析XML为Document对象 @@ -46,7 +48,7 @@ public class XmlUtil { try { document = saxReader.read(sr); } catch (DocumentException e) { - LOG.error("解析失败", e); + logger.error("解析失败", e); } return null == document ? null : document.getRootElement(); } @@ -182,47 +184,69 @@ public class XmlUtil { return xml.getRootElement(); } - public static DeviceChannel channelContentHander(Element itemDevice, Device device){ - Element channdelNameElement = itemDevice.element("Name"); - String channelName = channdelNameElement != null ? channdelNameElement.getTextTrim().toString() : ""; - Element statusElement = itemDevice.element("Status"); - String status = statusElement != null ? statusElement.getTextTrim().toString() : "ON"; + private enum ChannelType{ + CivilCode, BusinessGroup,VirtualOrganization,Other + } + + public static DeviceChannel channelContentHander(Element itemDevice, Device device, String event){ DeviceChannel deviceChannel = new DeviceChannel(); - deviceChannel.setName(channelName); + deviceChannel.setDeviceId(device.getDeviceId()); Element channdelIdElement = itemDevice.element("DeviceID"); - String channelId = channdelIdElement != null ? channdelIdElement.getTextTrim().toString() : ""; - deviceChannel.setChannelId(channelId); - // ONLINE OFFLINE HIKVISION DS-7716N-E4 NVR的兼容性处理 - if (status.equals("ON") || status.equals("On") || status.equals("ONLINE") || status.equals("OK")) { - deviceChannel.setStatus(1); + if (channdelIdElement == null) { + logger.warn("解析Catalog消息时发现缺少 DeviceID"); + return null; } - if (status.equals("OFF") || status.equals("Off") || status.equals("OFFLINE")) { - deviceChannel.setStatus(0); + String channelId = channdelIdElement.getTextTrim(); + if (StringUtils.isEmpty(channelId)) { + logger.warn("解析Catalog消息时发现缺少 DeviceID"); + return null; + } + deviceChannel.setChannelId(channelId); + if (event != null && !event.equals(CatalogEvent.ADD) && !event.equals(CatalogEvent.UPDATE)) { + // 除了ADD和update情况下需要识别全部内容, + return deviceChannel; } - deviceChannel.setManufacture(XmlUtil.getText(itemDevice, "Manufacturer")); - deviceChannel.setModel(XmlUtil.getText(itemDevice, "Model")); - deviceChannel.setOwner(XmlUtil.getText(itemDevice, "Owner")); - deviceChannel.setCivilCode(XmlUtil.getText(itemDevice, "CivilCode")); - deviceChannel.setBlock(XmlUtil.getText(itemDevice, "Block")); - deviceChannel.setAddress(XmlUtil.getText(itemDevice, "Address")); - String businessGroupID = XmlUtil.getText(itemDevice, "BusinessGroupID"); - if (XmlUtil.getText(itemDevice, "Parental") == null - || XmlUtil.getText(itemDevice, "Parental").equals("")) { - if (deviceChannel.getChannelId().length() <= 10 - || (deviceChannel.getChannelId().length() == 20 && ( - Integer.parseInt(deviceChannel.getChannelId().substring(10, 13)) == 215 - || Integer.parseInt(deviceChannel.getChannelId().substring(10, 13)) == 216 - ) - ) - ) { - deviceChannel.setParental(1); - }else { - deviceChannel.setParental(0); + ChannelType channelType = ChannelType.Other; + if (channelId.length() <= 8) { + channelType = ChannelType.CivilCode; + }else { + if (channelId.length() == 20) { + int code = Integer.parseInt(channelId.substring(10, 13)); + switch (code){ + case 215: + channelType = ChannelType.BusinessGroup; + break; + case 216: + channelType = ChannelType.VirtualOrganization; + break; + default: + break; + + } } - } else { - // 由于海康会错误的发送65535作为这里的取值,所以这里除非是0否则认为是1 - deviceChannel.setParental(Integer.parseInt(XmlUtil.getText(itemDevice, "Parental")) == 1?1:0); + } + + Element channdelNameElement = itemDevice.element("Name"); + String channelName = channdelNameElement != null ? channdelNameElement.getTextTrim() : ""; + deviceChannel.setName(channelName); + + String civilCode = XmlUtil.getText(itemDevice, "CivilCode"); + deviceChannel.setCivilCode(civilCode); + if (channelType == ChannelType.CivilCode && civilCode == null) { + deviceChannel.setParental(1); + // 行政区划如果没有传递具体值,则推测一个 + if (channelId.length() > 2) { + deviceChannel.setCivilCode(channelId.substring(0, channelId.length() - 2)); + } + } + if (channelType.equals(ChannelType.CivilCode)) { + // 行政区划其他字段没必要识别了,默认在线即可 + deviceChannel.setStatus(1); + deviceChannel.setParental(1); + deviceChannel.setCreateTime(DateUtil.getNow()); + deviceChannel.setUpdateTime(DateUtil.getNow()); + return deviceChannel; } /** * 行政区划展示设备树与业务分组展示设备树是两种不同的模式 @@ -230,7 +254,17 @@ public class XmlUtil { * 河北省 * --> 石家庄市 * --> 摄像头 - * --> 正定县 + *String parentId = XmlUtil.getText(itemDevice, "ParentID"); + if (parentId != null) { + if (parentId.contains("/")) { + String lastParentId = parentId.substring(parentId.lastIndexOf("/") + 1); + String businessGroup = parentId.substring(0, parentId.indexOf("/")); + deviceChannel.setParentId(lastParentId); + }else { + deviceChannel.setParentId(parentId); + } + } + deviceCh --> 正定县 * --> 摄像头 * --> 摄像头 * @@ -243,59 +277,88 @@ public class XmlUtil { * --> 摄像头 */ String parentId = XmlUtil.getText(itemDevice, "ParentID"); + String businessGroupID = XmlUtil.getText(itemDevice, "BusinessGroupID"); if (parentId != null) { if (parentId.contains("/")) { String lastParentId = parentId.substring(parentId.lastIndexOf("/") + 1); + if (businessGroupID == null) { + businessGroupID = parentId.substring(0, parentId.indexOf("/")); + } deviceChannel.setParentId(lastParentId); }else { deviceChannel.setParentId(parentId); } } deviceChannel.setBusinessGroupId(businessGroupID); + if (channelType.equals(ChannelType.BusinessGroup) || channelType.equals(ChannelType.VirtualOrganization)) { + // 业务分组和虚拟组织 其他字段没必要识别了,默认在线即可 + deviceChannel.setStatus(1); + deviceChannel.setParental(1); + deviceChannel.setCreateTime(DateUtil.getNow()); + deviceChannel.setUpdateTime(DateUtil.getNow()); + return deviceChannel; + } -// else { -// if (deviceChannel.getChannelId().length() <= 10) { // 此时为行政区划, 上下级行政区划使用DeviceId关联 -// deviceChannel.setParentId(deviceChannel.getChannelId().substring(0, deviceChannel.getChannelId().length() - 2)); -// }else if (deviceChannel.getChannelId().length() == 20) { -// if (Integer.parseInt(deviceChannel.getChannelId().substring(10, 13)) == 216) { // 虚拟组织 -// deviceChannel.setBusinessGroupId(businessGroupID); -// }else if (Integer.parseInt(device.getDeviceId().substring(10, 13) )== 118) {//NVR 如果上级设备编号是NVR则直接将NVR的编号设置给通道的上级编号 -// deviceChannel.setParentId(device.getDeviceId()); -// }else if (deviceChannel.getCivilCode() != null) { -// // 设备, 无parentId的20位是使用CivilCode表示上级的设备, -// // 注:215 业务分组是需要有parentId的 -// deviceChannel.setParentId(deviceChannel.getCivilCode()); -// } -// }else { -// deviceChannel.setParentId(deviceChannel.getDeviceId()); -// } -// } + Element statusElement = itemDevice.element("Status"); - if (XmlUtil.getText(itemDevice, "SafetyWay") == null - || XmlUtil.getText(itemDevice, "SafetyWay") == "") { + if (statusElement != null) { + String status = statusElement.getTextTrim().trim(); + // ONLINE OFFLINE HIKVISION DS-7716N-E4 NVR的兼容性处理 + if (status.equals("ON") || status.equals("On") || status.equals("ONLINE") || status.equals("OK")) { + deviceChannel.setStatus(1); + } + if (status.equals("OFF") || status.equals("Off") || status.equals("OFFLINE")) { + deviceChannel.setStatus(0); + } + }else { + deviceChannel.setStatus(1); + } + // 识别自带的目录标识 + String parental = XmlUtil.getText(itemDevice, "Parental"); + // 由于海康会错误的发送65535作为这里的取值,所以这里除非是0否则认为是1 + if (!StringUtils.isEmpty(parental) && parental.length() == 1 && Integer.parseInt(parental) == 0) { + deviceChannel.setParental(0); + }else { + deviceChannel.setParental(1); + } + + + deviceChannel.setManufacture(XmlUtil.getText(itemDevice, "Manufacturer")); + deviceChannel.setModel(XmlUtil.getText(itemDevice, "Model")); + deviceChannel.setOwner(XmlUtil.getText(itemDevice, "Owner")); + deviceChannel.setCertNum(XmlUtil.getText(itemDevice, "CertNum")); + deviceChannel.setBlock(XmlUtil.getText(itemDevice, "Block")); + deviceChannel.setAddress(XmlUtil.getText(itemDevice, "Address")); + deviceChannel.setPassword(XmlUtil.getText(itemDevice, "Password")); + + String safetyWay = XmlUtil.getText(itemDevice, "SafetyWay"); + if (StringUtils.isEmpty(safetyWay)) { deviceChannel.setSafetyWay(0); } else { - deviceChannel.setSafetyWay(Integer.parseInt(XmlUtil.getText(itemDevice, "SafetyWay"))); + deviceChannel.setSafetyWay(Integer.parseInt(safetyWay)); } - if (XmlUtil.getText(itemDevice, "RegisterWay") == null - || XmlUtil.getText(itemDevice, "RegisterWay") == "") { + + String registerWay = XmlUtil.getText(itemDevice, "RegisterWay"); + if (StringUtils.isEmpty(registerWay)) { deviceChannel.setRegisterWay(1); } else { - deviceChannel.setRegisterWay(Integer.parseInt(XmlUtil.getText(itemDevice, "RegisterWay"))); + deviceChannel.setRegisterWay(Integer.parseInt(registerWay)); } - deviceChannel.setCertNum(XmlUtil.getText(itemDevice, "CertNum")); + if (XmlUtil.getText(itemDevice, "Certifiable") == null || XmlUtil.getText(itemDevice, "Certifiable") == "") { deviceChannel.setCertifiable(0); } else { deviceChannel.setCertifiable(Integer.parseInt(XmlUtil.getText(itemDevice, "Certifiable"))); } + if (XmlUtil.getText(itemDevice, "ErrCode") == null || XmlUtil.getText(itemDevice, "ErrCode") == "") { deviceChannel.setErrCode(0); } else { deviceChannel.setErrCode(Integer.parseInt(XmlUtil.getText(itemDevice, "ErrCode"))); } + deviceChannel.setEndTime(XmlUtil.getText(itemDevice, "EndTime")); deviceChannel.setSecrecy(XmlUtil.getText(itemDevice, "Secrecy")); deviceChannel.setIpAddress(XmlUtil.getText(itemDevice, "IPAddress")); @@ -304,43 +367,23 @@ public class XmlUtil { } else { deviceChannel.setPort(Integer.parseInt(XmlUtil.getText(itemDevice, "Port"))); } - deviceChannel.setPassword(XmlUtil.getText(itemDevice, "Password")); - if (NumericUtil.isDouble(XmlUtil.getText(itemDevice, "Longitude"))) { - deviceChannel.setLongitude(Double.parseDouble(XmlUtil.getText(itemDevice, "Longitude"))); + + + String longitude = XmlUtil.getText(itemDevice, "Longitude"); + if (NumericUtil.isDouble(longitude)) { + deviceChannel.setLongitude(Double.parseDouble(longitude)); } else { deviceChannel.setLongitude(0.00); } - if (NumericUtil.isDouble(XmlUtil.getText(itemDevice, "Latitude"))) { - deviceChannel.setLatitude(Double.parseDouble(XmlUtil.getText(itemDevice, "Latitude"))); + String latitude = XmlUtil.getText(itemDevice, "Latitude"); + if (NumericUtil.isDouble(latitude)) { + deviceChannel.setLatitude(Double.parseDouble(latitude)); } else { deviceChannel.setLatitude(0.00); } deviceChannel.setGpsTime(DateUtil.getNow()); - if (deviceChannel.getLongitude()*deviceChannel.getLatitude() > 0) { - if ("WGS84".equals(device.getGeoCoordSys())) { - deviceChannel.setLongitudeWgs84(deviceChannel.getLongitude()); - deviceChannel.setLatitudeWgs84(deviceChannel.getLatitude()); - Double[] position = Coordtransform.WGS84ToGCJ02(deviceChannel.getLongitude(), deviceChannel.getLatitude()); - deviceChannel.setLongitudeGcj02(position[0]); - deviceChannel.setLatitudeGcj02(position[1]); - }else if ("GCJ02".equals(device.getGeoCoordSys())) { - deviceChannel.setLongitudeGcj02(deviceChannel.getLongitude()); - deviceChannel.setLatitudeGcj02(deviceChannel.getLatitude()); - Double[] position = Coordtransform.GCJ02ToWGS84(deviceChannel.getLongitude(), deviceChannel.getLatitude()); - deviceChannel.setLongitudeWgs84(position[0]); - deviceChannel.setLatitudeWgs84(position[1]); - }else { - deviceChannel.setLongitudeGcj02(0.00); - deviceChannel.setLatitudeGcj02(0.00); - deviceChannel.setLongitudeWgs84(0.00); - deviceChannel.setLatitudeWgs84(0.00); - } - }else { - deviceChannel.setLongitudeGcj02(deviceChannel.getLongitude()); - deviceChannel.setLatitudeGcj02(deviceChannel.getLatitude()); - deviceChannel.setLongitudeWgs84(deviceChannel.getLongitude()); - deviceChannel.setLatitudeWgs84(deviceChannel.getLatitude()); - } + + if (XmlUtil.getText(itemDevice, "PTZType") == null || "".equals(XmlUtil.getText(itemDevice, "PTZType"))) { //兼容INFO中的信息 Element info = itemDevice.element("Info"); diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/AssistRESTfulUtils.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/AssistRESTfulUtils.java index 249ec03c..c8f90402 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/AssistRESTfulUtils.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/AssistRESTfulUtils.java @@ -136,4 +136,12 @@ public class AssistRESTfulUtils { return sendGet(mediaServerItem, "api/record/file/duration",param, callback); } + public JSONObject addStreamCallInfo(MediaServerItem mediaServerItem, String app, String stream, String callId, RequestCallback callback){ + Map param = new HashMap<>(); + param.put("app",app); + param.put("stream",stream); + param.put("callId",callId); + return sendGet(mediaServerItem, "api/record/addStreamCallInfo",param, callback); + } + } diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java index 7f6ea02c..055cccbd 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java @@ -1,7 +1,8 @@ package com.genersoft.iot.vmp.media.zlm; -import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import com.alibaba.fastjson.JSON; import com.genersoft.iot.vmp.common.StreamInfo; @@ -21,6 +22,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -79,9 +81,15 @@ public class ZLMHttpHookListener { @Autowired private UserSetting userSetting; + @Autowired + private IUserService userService; + @Autowired private VideoStreamSessionManager sessionManager; + @Autowired + private AssistRESTfulUtils assistRESTfulUtils; + /** * 服务器定时上报时间,上报间隔可配置,默认10s上报一次 * @@ -151,12 +159,14 @@ public class ZLMHttpHookListener { */ @ResponseBody @PostMapping(value = "/on_play", produces = "application/json;charset=UTF-8") - public ResponseEntity onPlay(@RequestBody JSONObject json){ - + public ResponseEntity onPlay(@RequestBody OnPlayHookParam param){ + + JSONObject json = (JSONObject)JSON.toJSON(param); + if (logger.isDebugEnabled()) { - logger.debug("[ ZLM HOOK ]on_play API调用,参数:" + json.toString()); + logger.debug("[ ZLM HOOK ]on_play API调用,参数:" + JSON.toJSONString(param)); } - String mediaServerId = json.getString("mediaServerId"); + String mediaServerId = param.getMediaServerId(); ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_play, json); if (subscribe != null ) { MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId); @@ -165,9 +175,20 @@ public class ZLMHttpHookListener { } } JSONObject ret = new JSONObject(); + if (!"rtp".equals(param.getApp())) { + Map paramMap = urlParamToMap(param.getParams()); + StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(param.getApp(), param.getStream()); + if (streamAuthorityInfo == null + || (streamAuthorityInfo.getCallId() != null && !streamAuthorityInfo.getCallId().equals(paramMap.get("callId")))) { + ret.put("code", 401); + ret.put("msg", "Unauthorized"); + return new ResponseEntity<>(ret.toString(),HttpStatus.OK); + } + } + ret.put("code", 0); ret.put("msg", "success"); - return new ResponseEntity(ret.toString(),HttpStatus.OK); + return new ResponseEntity<>(ret.toString(),HttpStatus.OK); } /** @@ -176,23 +197,61 @@ public class ZLMHttpHookListener { */ @ResponseBody @PostMapping(value = "/on_publish", produces = "application/json;charset=UTF-8") - public ResponseEntity onPublish(@RequestBody JSONObject json) { + public ResponseEntity onPublish(@RequestBody OnPublishHookParam param) { + + JSONObject json = (JSONObject) JSON.toJSON(param); logger.info("[ ZLM HOOK ]on_publish API调用,参数:" + json.toString()); JSONObject ret = new JSONObject(); + String mediaServerId = json.getString("mediaServerId"); + MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId); + if (!"rtp".equals(param.getApp())) { + // 推流鉴权 + if (param.getParams() == null) { + logger.info("推流鉴权失败: 缺少不要参数:sign=md5(user表的pushKey)"); + ret.put("code", 401); + ret.put("msg", "Unauthorized"); + return new ResponseEntity<>(ret.toString(), HttpStatus.OK); + } + Map paramMap = urlParamToMap(param.getParams()); + String sign = paramMap.get("sign"); + if (sign == null) { + logger.info("推流鉴权失败: 缺少不要参数:sign=md5(user表的pushKey)"); + ret.put("code", 401); + ret.put("msg", "Unauthorized"); + return new ResponseEntity<>(ret.toString(), HttpStatus.OK); + } + // 推流自定义播放鉴权码 + String callId = paramMap.get("callId"); + // 鉴权配置 + boolean hasAuthority = userService.checkPushAuthority(callId, sign); + if (!hasAuthority) { + logger.info("推流鉴权失败: sign 无权限: callId={}. sign={}", callId, sign); + ret.put("code", 401); + ret.put("msg", "Unauthorized"); + return new ResponseEntity<>(ret.toString(), HttpStatus.OK); + } + StreamAuthorityInfo streamAuthorityInfo = StreamAuthorityInfo.getInstanceByHook(param); + streamAuthorityInfo.setCallId(callId); + streamAuthorityInfo.setSign(sign); + // 鉴权通过 + redisCatchStorage.updateStreamAuthorityInfo(param.getApp(), param.getStream(), streamAuthorityInfo); + // 通知assist新的callId + if (mediaInfo != null) { + assistRESTfulUtils.addStreamCallInfo(mediaInfo, param.getApp(), param.getStream(), callId, null); + } + } + ret.put("code", 0); ret.put("msg", "success"); ret.put("enable_hls", true); - if (json.getInteger("originType") == 1 - || json.getInteger("originType") == 2 - || json.getInteger("originType") == 3) { + if (!"rtp".equals(param.getApp())) { ret.put("enable_audio", true); } - String mediaServerId = json.getString("mediaServerId"); + ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_publish, json); if (subscribe != null) { - MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId); if (mediaInfo != null) { subscribe.response(mediaInfo, json); }else { @@ -200,14 +259,13 @@ public class ZLMHttpHookListener { ret.put("msg", "zlm not register"); } } - String app = json.getString("app"); - String stream = json.getString("stream"); - if ("rtp".equals(app)) { + + if ("rtp".equals(param.getApp())) { ret.put("enable_mp4", userSetting.getRecordSip()); }else { ret.put("enable_mp4", userSetting.isRecordPushLive()); } - List ssrcTransactionForAll = sessionManager.getSsrcTransactionForAll(null, null, null, stream); + List ssrcTransactionForAll = sessionManager.getSsrcTransactionForAll(null, null, null, param.getStream()); if (ssrcTransactionForAll != null && ssrcTransactionForAll.size() == 1) { String deviceId = ssrcTransactionForAll.get(0).getDeviceId(); String channelId = ssrcTransactionForAll.get(0).getChannelId(); @@ -220,14 +278,17 @@ public class ZLMHttpHookListener { ret.put("mp4_max_second", 10); ret.put("enable_mp4", true); ret.put("enable_audio", true); - } + } } + return new ResponseEntity(ret.toString(), HttpStatus.OK); } - + + + /** * 录制mp4完成后通知事件;此事件对回复不敏感。 * @@ -312,9 +373,6 @@ public class ZLMHttpHookListener { if (logger.isDebugEnabled()) { logger.debug("[ ZLM HOOK ]on_shell_login API调用,参数:" + json.toString()); } - // TODO 如果是带有rtpstream则开启按需拉流 - // String app = json.getString("app"); - // String stream = json.getString("stream"); String mediaServerId = json.getString("mediaServerId"); ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_shell_login, json); if (subscribe != null ) { @@ -351,12 +409,24 @@ public class ZLMHttpHookListener { } // 流消失移除redis play String app = item.getApp(); - String streamId = item.getStream(); + String stream = item.getStream(); String schema = item.getSchema(); List tracks = item.getTracks(); boolean regist = item.isRegist(); + if (regist) { + StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(app, stream); + if (streamAuthorityInfo == null) { + streamAuthorityInfo = StreamAuthorityInfo.getInstanceByHook(item); + }else { + streamAuthorityInfo.setOriginType(item.getOriginType()); + streamAuthorityInfo.setOriginTypeStr(item.getOriginTypeStr()); + } + redisCatchStorage.updateStreamAuthorityInfo(app, stream, streamAuthorityInfo); + }else { + redisCatchStorage.removeStreamAuthorityInfo(app, stream); + } if ("rtmp".equals(schema)){ - logger.info("on_stream_changed:注册->{}, app->{}, stream->{}", regist, app, streamId); + logger.info("on_stream_changed:注册->{}, app->{}, stream->{}", regist, app, stream); if (regist) { mediaServerService.addCount(mediaServerId); }else { @@ -365,15 +435,15 @@ public class ZLMHttpHookListener { if (item.getOriginType() == OriginType.PULL.ordinal() || item.getOriginType() == OriginType.FFMPEG_PULL.ordinal()) { // 设置拉流代理上线/离线 - streamProxyService.updateStatus(regist, app, streamId); + streamProxyService.updateStatus(regist, app, stream); } if ("rtp".equals(app) && !regist ) { - StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId); + StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(stream); if (streamInfo!=null){ redisCatchStorage.stopPlay(streamInfo); storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId()); }else{ - streamInfo = redisCatchStorage.queryPlayback(null, null, streamId, null); + streamInfo = redisCatchStorage.queryPlayback(null, null, stream, null); if (streamInfo != null) { redisCatchStorage.stopPlayback(streamInfo.getDeviceID(), streamInfo.getChannelId(), streamInfo.getStream(), null); @@ -387,10 +457,12 @@ public class ZLMHttpHookListener { if (mediaServerItem != null){ if (regist) { - StreamInfo streamInfoByAppAndStream = mediaService.getStreamInfoByAppAndStream(mediaServerItem, app, streamId, tracks); + StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(app, stream); + StreamInfo streamInfoByAppAndStream = mediaService.getStreamInfoByAppAndStream(mediaServerItem, + app, stream, tracks, streamAuthorityInfo.getCallId()); item.setStreamInfo(streamInfoByAppAndStream); - - redisCatchStorage.addStream(mediaServerItem, type, app, streamId, item); + item.setSeverId(userSetting.getServerId()); + redisCatchStorage.addStream(mediaServerItem, type, app, stream, item); if (item.getOriginType() == OriginType.RTSP_PUSH.ordinal() || item.getOriginType() == OriginType.RTMP_PUSH.ordinal() || item.getOriginType() == OriginType.RTC_PUSH.ordinal() ) { @@ -413,23 +485,23 @@ public class ZLMHttpHookListener { }else { // 兼容流注销时类型从redis记录获取 - MediaItem mediaItem = redisCatchStorage.getStreamInfo(app, streamId, mediaServerId); + MediaItem mediaItem = redisCatchStorage.getStreamInfo(app, stream, mediaServerId); if (mediaItem != null) { type = OriginType.values()[mediaItem.getOriginType()].getType(); - redisCatchStorage.removeStream(mediaServerItem.getId(), type, app, streamId); + redisCatchStorage.removeStream(mediaServerItem.getId(), type, app, stream); } - GbStream gbStream = storager.getGbStream(app, streamId); + GbStream gbStream = storager.getGbStream(app, stream); if (gbStream != null) { // eventPublisher.catalogEventPublishForStream(null, gbStream, CatalogEvent.OFF); } - zlmMediaListManager.removeMedia(app, streamId); + zlmMediaListManager.removeMedia(app, stream); } if (type != null) { // 发送流变化redis消息 JSONObject jsonObject = new JSONObject(); jsonObject.put("serverId", userSetting.getServerId()); jsonObject.put("app", app); - jsonObject.put("stream", streamId); + jsonObject.put("stream", stream); jsonObject.put("register", regist); jsonObject.put("mediaServerId", mediaServerId); redisCatchStorage.sendStreamChangeMsg(type, jsonObject); @@ -565,4 +637,22 @@ public class ZLMHttpHookListener { ret.put("msg", "success"); return new ResponseEntity(ret.toString(),HttpStatus.OK); } + + private Map urlParamToMap(String params) { + HashMap map = new HashMap<>(); + if (StringUtils.isEmpty(params)) { + return map; + } + String[] paramsArray = params.split("&"); + if (paramsArray.length == 0) { + return map; + } + for (String param : paramsArray) { + String[] paramArray = param.split("="); + if (paramArray.length == 2){ + map.put(paramArray[0], paramArray[1]); + } + } + return map; + } } diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaListManager.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaListManager.java index 35069aa6..3d9b7cbf 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaListManager.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaListManager.java @@ -115,64 +115,16 @@ public class ZLMMediaListManager { public StreamPushItem addPush(MediaItem mediaItem) { // 查找此直播流是否存在redis预设gbId StreamPushItem transform = streamPushService.transform(mediaItem); - // 从streamId取出查询关键值 - Pattern pattern = Pattern.compile(userSetting.getThirdPartyGBIdReg()); - Matcher matcher = pattern.matcher(mediaItem.getStream());// 指定要匹配的字符串 - String queryKey = null; - if (matcher.find()) { //此处find()每次被调用后,会偏移到下一个匹配 - queryKey = matcher.group(); + StreamPushItem pushInDb = streamPushService.getPush(mediaItem.getApp(), mediaItem.getStream()); + transform.setPushIng(true); + transform.setUpdateTime(DateUtil.getNow()); + transform.setPushTime(DateUtil.getNow()); + if (pushInDb == null) { + transform.setCreateTime(DateUtil.getNow()); + streamPushMapper.add(transform); + }else { + streamPushMapper.update(transform); } - if (queryKey != null) { - ThirdPartyGB thirdPartyGB = redisCatchStorage.queryMemberNoGBId(queryKey); - if (thirdPartyGB != null && !StringUtils.isEmpty(thirdPartyGB.getNationalStandardNo())) { - transform.setGbId(thirdPartyGB.getNationalStandardNo()); - transform.setName(thirdPartyGB.getName()); - } - } - if (!StringUtils.isEmpty(transform.getGbId())) { - // 如果这个国标ID已经给了其他推流且流已离线,则移除其他推流 - List gbStreams = gbStreamMapper.selectByGBId(transform.getGbId()); - if (gbStreams.size() > 0) { - for (GbStream gbStream : gbStreams) { - // 出现使用相同国标Id的视频流时,使用新流替换旧流, - if (queryKey != null && gbStream.getApp().equals(mediaItem.getApp())) { - Matcher matcherForStream = pattern.matcher(gbStream.getStream()); - String queryKeyForStream = null; - if (matcherForStream.find()) { //此处find()每次被调用后,会偏移到下一个匹配 - queryKeyForStream = matcherForStream.group(); - } - if (queryKeyForStream == null || !queryKeyForStream.equals(queryKey)) { - // 此时不是同一个流 - gbStreamMapper.del(gbStream.getApp(), gbStream.getStream()); - if (!gbStream.isStatus()) { - streamPushMapper.del(gbStream.getApp(), gbStream.getStream()); - } - } - } - } - } - List gbStreamList = gbStreamMapper.selectByGBId(transform.getGbId()); - if (gbStreamList != null && gbStreamList.size() == 1) { - transform.setGbStreamId(gbStreamList.get(0).getGbStreamId()); - transform.setPlatformId(gbStreamList.get(0).getPlatformId()); - transform.setCatalogId(gbStreamList.get(0).getCatalogId()); - transform.setGbId(gbStreamList.get(0).getGbId()); - gbStreamMapper.update(transform); - streamPushMapper.del(gbStreamList.get(0).getApp(), gbStreamList.get(0).getStream()); - }else { - transform.setCreateTime(DateUtil.getNow()); - transform.setUpdateTime(DateUtil.getNow()); - gbStreamMapper.add(transform); - } - if (transform != null) { - if (channelOnlineEvents.get(transform.getGbId()) != null) { - channelOnlineEvents.get(transform.getGbId()).run(transform.getApp(), transform.getStream(), transform.getServerId()); - channelOnlineEvents.remove(transform.getGbId()); - } - } - } - - storager.updateMedia(transform); return transform; } @@ -206,13 +158,13 @@ public class ZLMMediaListManager { public int removeMedia(String app, String streamId) { // 查找是否关联了国标, 关联了不删除, 置为离线 - StreamProxyItem streamProxyItem = gbStreamMapper.selectOne(app, streamId); - int result = 0; - if (streamProxyItem == null) { + GbStream gbStream = gbStreamMapper.selectOne(app, streamId); + int result; + if (gbStream == null) { result = storager.removeMedia(app, streamId); }else { // TODO 暂不设置为离线 - result =storager.mediaOutline(app, streamId); + result =storager.mediaOffline(app, streamId); } return result; } diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java index 2a99b1b3..cbef9ce2 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java @@ -66,7 +66,7 @@ public class ZLMRTPServerFactory { String stream = UUID.randomUUID().toString(); param.put("enable_tcp", 1); param.put("stream_id", stream); - param.put("port", 0); +// param.put("port", 0); JSONObject openRtpServerResultJson = zlmresTfulUtils.openRtpServer(mediaServerItem, param); if (openRtpServerResultJson != null) { @@ -101,9 +101,10 @@ public class ZLMRTPServerFactory { } Map param = new HashMap<>(); - // 推流端口设置0则使用随机端口 + param.put("enable_tcp", 1); param.put("stream_id", streamId); + // 推流端口设置0则使用随机端口 param.put("port", 0); param.put("ssrc", ssrc); JSONObject openRtpServerResultJson = zlmresTfulUtils.openRtpServer(mediaServerItem, param); @@ -291,7 +292,7 @@ public class ZLMRTPServerFactory { logger.warn("查询流({}/{})是否有其它观看者时得到: {}", app, streamId, mediaInfo.getString("msg")); return -1; } - if ( code == 0 && ! mediaInfo.getBoolean("online")) { + if ( code == 0 && mediaInfo.getBoolean("online") != null && !mediaInfo.getBoolean("online")) { logger.warn("查询流({}/{})是否有其它观看者时得到: {}", app, streamId, mediaInfo.getString("msg")); return -1; } diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/HookParam.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/HookParam.java new file mode 100644 index 00000000..50e37234 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/HookParam.java @@ -0,0 +1,17 @@ +package com.genersoft.iot.vmp.media.zlm.dto; + +/** + * zlm hook事件的参数 + * @author lin + */ +public class HookParam { + private String mediaServerId; + + public String getMediaServerId() { + return mediaServerId; + } + + public void setMediaServerId(String mediaServerId) { + this.mediaServerId = mediaServerId; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaItem.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaItem.java index 8abac5b0..96cbfbd8 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaItem.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaItem.java @@ -4,6 +4,9 @@ import com.genersoft.iot.vmp.common.StreamInfo; import java.util.List; +/** + * @author lin + */ public class MediaItem { /** @@ -21,6 +24,11 @@ public class MediaItem { */ private String stream; + /** + * 推流鉴权Id + */ + private String callId; + /** * 观看总人数,包括hls/rtsp/rtmp/http-flv/ws-flv */ @@ -427,4 +435,12 @@ public class MediaItem { public void setSeverId(String severId) { this.severId = severId; } + + public String getCallId() { + return callId; + } + + public void setCallId(String callId) { + this.callId = callId; + } } diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/OnPlayHookParam.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/OnPlayHookParam.java new file mode 100644 index 00000000..92ecb47c --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/OnPlayHookParam.java @@ -0,0 +1,82 @@ +package com.genersoft.iot.vmp.media.zlm.dto; + +/** + * zlm hook事件中的on_play事件的参数 + * @author lin + */ +public class OnPlayHookParam extends HookParam{ + private String id; + private String app; + private String stream; + private String ip; + private String params; + private int port; + private String schema; + private String vhost; + + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getApp() { + return app; + } + + public void setApp(String app) { + this.app = app; + } + + public String getStream() { + return stream; + } + + public void setStream(String stream) { + this.stream = stream; + } + + public String getIp() { + return ip; + } + + public void setIp(String ip) { + this.ip = ip; + } + + public String getParams() { + return params; + } + + public void setParams(String params) { + this.params = params; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public String getSchema() { + return schema; + } + + public void setSchema(String schema) { + this.schema = schema; + } + + public String getVhost() { + return vhost; + } + + public void setVhost(String vhost) { + this.vhost = vhost; + } + +} diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/OnPublishHookParam.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/OnPublishHookParam.java new file mode 100644 index 00000000..354c1195 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/OnPublishHookParam.java @@ -0,0 +1,82 @@ +package com.genersoft.iot.vmp.media.zlm.dto; + +/** + * zlm hook事件中的on_publish事件的参数 + * @author lin + */ +public class OnPublishHookParam extends HookParam{ + private String id; + private String app; + private String stream; + private String ip; + private String params; + private int port; + private String schema; + private String vhost; + + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getApp() { + return app; + } + + public void setApp(String app) { + this.app = app; + } + + public String getStream() { + return stream; + } + + public void setStream(String stream) { + this.stream = stream; + } + + public String getIp() { + return ip; + } + + public void setIp(String ip) { + this.ip = ip; + } + + public String getParams() { + return params; + } + + public void setParams(String params) { + this.params = params; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public String getSchema() { + return schema; + } + + public void setSchema(String schema) { + this.schema = schema; + } + + public String getVhost() { + return vhost; + } + + public void setVhost(String vhost) { + this.vhost = vhost; + } + +} diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/StreamAuthorityInfo.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/StreamAuthorityInfo.java new file mode 100644 index 00000000..36a03630 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/StreamAuthorityInfo.java @@ -0,0 +1,114 @@ +package com.genersoft.iot.vmp.media.zlm.dto; + +/** + * 流的鉴权信息 + * @author lin + */ +public class StreamAuthorityInfo { + + private String id; + private String app; + private String stream; + + /** + * 产生源类型, + * unknown = 0, + * rtmp_push=1, + * rtsp_push=2, + * rtp_push=3, + * pull=4, + * ffmpeg_pull=5, + * mp4_vod=6, + * device_chn=7 + */ + private int originType; + + /** + * 产生源类型的字符串描述 + */ + private String originTypeStr; + + /** + * 推流时自定义的播放鉴权ID + */ + private String callId; + + /** + * 推流的鉴权签名 + */ + private String sign; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getApp() { + return app; + } + + public void setApp(String app) { + this.app = app; + } + + public String getStream() { + return stream; + } + + public void setStream(String stream) { + this.stream = stream; + } + + public int getOriginType() { + return originType; + } + + public void setOriginType(int originType) { + this.originType = originType; + } + + public String getOriginTypeStr() { + return originTypeStr; + } + + public void setOriginTypeStr(String originTypeStr) { + this.originTypeStr = originTypeStr; + } + + public String getCallId() { + return callId; + } + + public void setCallId(String callId) { + this.callId = callId; + } + + public String getSign() { + return sign; + } + + public void setSign(String sign) { + this.sign = sign; + } + + public static StreamAuthorityInfo getInstanceByHook(OnPublishHookParam hookParam) { + StreamAuthorityInfo streamAuthorityInfo = new StreamAuthorityInfo(); + streamAuthorityInfo.setApp(hookParam.getApp()); + streamAuthorityInfo.setStream(hookParam.getStream()); + streamAuthorityInfo.setId(hookParam.getId()); + return streamAuthorityInfo; + } + + public static StreamAuthorityInfo getInstanceByHook(MediaItem mediaItem) { + StreamAuthorityInfo streamAuthorityInfo = new StreamAuthorityInfo(); + streamAuthorityInfo.setApp(mediaItem.getApp()); + streamAuthorityInfo.setStream(mediaItem.getStream()); + streamAuthorityInfo.setId(mediaItem.getMediaServerId()); + streamAuthorityInfo.setOriginType(mediaItem.getOriginType()); + streamAuthorityInfo.setOriginTypeStr(mediaItem.getOriginTypeStr()); + return streamAuthorityInfo; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/StreamPushItem.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/StreamPushItem.java index 91fa6198..d5830060 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/StreamPushItem.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/StreamPushItem.java @@ -103,6 +103,11 @@ public class StreamPushItem extends GbStream implements Comparable channels); + +} diff --git a/src/main/java/com/genersoft/iot/vmp/service/IGbStreamService.java b/src/main/java/com/genersoft/iot/vmp/service/IGbStreamService.java index abdde6de..0a392060 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/IGbStreamService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IGbStreamService.java @@ -18,7 +18,7 @@ public interface IGbStreamService { * @param count * @return */ - PageInfo getAll(Integer page, Integer count, String platFormId, String catalogId,String query,Boolean pushing,String mediaServerId); + PageInfo getAll(Integer page, Integer count, String platFormId, String catalogId,String query,String mediaServerId); /** diff --git a/src/main/java/com/genersoft/iot/vmp/service/IMediaService.java b/src/main/java/com/genersoft/iot/vmp/service/IMediaService.java index 8c05b85f..b5431c9f 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/IMediaService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IMediaService.java @@ -15,7 +15,7 @@ public interface IMediaService { * @param stream * @return */ - StreamInfo getStreamInfoByAppAndStreamWithCheck(String app, String stream, String mediaServerId,String addr); + StreamInfo getStreamInfoByAppAndStreamWithCheck(String app, String stream, String mediaServerId,String addr, boolean authority); /** @@ -24,7 +24,7 @@ public interface IMediaService { * @param stream * @return */ - StreamInfo getStreamInfoByAppAndStreamWithCheck(String app, String stream, String mediaServerId); + StreamInfo getStreamInfoByAppAndStreamWithCheck(String app, String stream, String mediaServerId, boolean authority); /** * 根据应用名和流ID获取播放地址, 只是地址拼接 @@ -32,7 +32,7 @@ public interface IMediaService { * @param stream * @return */ - StreamInfo getStreamInfoByAppAndStream(MediaServerItem mediaServerItem, String app, String stream, Object tracks); + StreamInfo getStreamInfoByAppAndStream(MediaServerItem mediaServerItem, String app, String stream, Object tracks, String callId); /** * 根据应用名和流ID获取播放地址, 只是地址拼接,返回的ip使用远程访问ip,适用与zlm与wvp在一台主机的情况 @@ -40,5 +40,5 @@ public interface IMediaService { * @param stream * @return */ - StreamInfo getStreamInfoByAppAndStream(MediaServerItem mediaInfo, String app, String stream, Object tracks, String addr); + StreamInfo getStreamInfoByAppAndStream(MediaServerItem mediaInfo, String app, String stream, Object tracks, String addr, String callId); } diff --git a/src/main/java/com/genersoft/iot/vmp/service/IPlatformChannelService.java b/src/main/java/com/genersoft/iot/vmp/service/IPlatformChannelService.java new file mode 100644 index 00000000..739e6b86 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/service/IPlatformChannelService.java @@ -0,0 +1,22 @@ +package com.genersoft.iot.vmp.service; + +import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce; + +import java.util.List; + +/** + * 平台关联通道管理 + * @author lin + */ +public interface IPlatformChannelService { + + /** + * 更新目录下的通道 + * @param platformId 平台编号 + * @param channelReduces 通道信息 + * @param catalogId 目录编号 + * @return + */ + int updateChannelForGB(String platformId, List channelReduces, String catalogId); + +} diff --git a/src/main/java/com/genersoft/iot/vmp/service/IStreamProxyService.java b/src/main/java/com/genersoft/iot/vmp/service/IStreamProxyService.java index ac100006..1dd74ee2 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/IStreamProxyService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IStreamProxyService.java @@ -101,4 +101,9 @@ public interface IStreamProxyService { void zlmServerOffline(String mediaServerId); void clean(); + + /** + * 更新代理流 + */ + boolean updateStreamProxy(StreamProxyItem streamProxyItem); } diff --git a/src/main/java/com/genersoft/iot/vmp/service/IStreamPushService.java b/src/main/java/com/genersoft/iot/vmp/service/IStreamPushService.java index acf0d274..5dd45ef9 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/IStreamPushService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IStreamPushService.java @@ -5,6 +5,7 @@ import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig; import com.genersoft.iot.vmp.media.zlm.dto.MediaItem; import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; +import com.genersoft.iot.vmp.service.bean.StreamPushItemFromRedis; import com.genersoft.iot.vmp.vmanager.bean.StreamPushExcelDto; import com.github.pagehelper.PageInfo; @@ -44,31 +45,55 @@ public interface IStreamPushService { * 停止一路推流 * @param app 应用名 * @param streamId 流ID - * @return */ boolean stop(String app, String streamId); /** * 新的节点加入 - * @param mediaServerId - * @return */ void zlmServerOnline(String mediaServerId); /** * 节点离线 - * @param mediaServerId - * @return */ void zlmServerOffline(String mediaServerId); + /** + * 清空 + */ void clean(); + boolean saveToRandomGB(); + /** + * 批量添加 + */ void batchAdd(List streamPushExcelDtoList); + /** + * 中止多个推流 + */ boolean batchStop(List streamPushItems); + /** + * 导入时批量增加 + */ void batchAddForUpload(List streamPushItems, Map> streamPushItemsForAll); + + /** + * 全部离线 + */ + void allStreamOffline(); + + /** + * 推流离线 + */ + void offline(List offlineStreams); + + /** + * 推流上线 + */ + void online(List onlineStreams); + } diff --git a/src/main/java/com/genersoft/iot/vmp/service/IUserService.java b/src/main/java/com/genersoft/iot/vmp/service/IUserService.java index c170c021..7e2a8395 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/IUserService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IUserService.java @@ -1,6 +1,7 @@ package com.genersoft.iot.vmp.service; import com.genersoft.iot.vmp.storager.dao.dto.User; +import com.github.pagehelper.PageInfo; import java.util.List; @@ -19,4 +20,10 @@ public interface IUserService { List getAllUsers(); int updateUsers(User user); + + boolean checkPushAuthority(String callId, String sign); + + PageInfo getUsers(int page, int count); + + int changePushKey(int id, String pushKey); } diff --git a/src/main/java/com/genersoft/iot/vmp/service/bean/PushStreamStatusChangeFromRedisDto.java b/src/main/java/com/genersoft/iot/vmp/service/bean/PushStreamStatusChangeFromRedisDto.java new file mode 100644 index 00000000..5bb7b77f --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/service/bean/PushStreamStatusChangeFromRedisDto.java @@ -0,0 +1,41 @@ +package com.genersoft.iot.vmp.service.bean; + +import java.util.List; + +/** + * 收到redis通知修改推流通道状态 + * @author lin + */ +public class PushStreamStatusChangeFromRedisDto { + + private boolean setAllOffline; + + private List onlineStreams; + + private List offlineStreams; + + + public boolean isSetAllOffline() { + return setAllOffline; + } + + public void setSetAllOffline(boolean setAllOffline) { + this.setAllOffline = setAllOffline; + } + + public List getOnlineStreams() { + return onlineStreams; + } + + public void setOnlineStreams(List onlineStreams) { + this.onlineStreams = onlineStreams; + } + + public List getOfflineStreams() { + return offlineStreams; + } + + public void setOfflineStreams(List offlineStreams) { + this.offlineStreams = offlineStreams; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/service/bean/StreamPushItemFromRedis.java b/src/main/java/com/genersoft/iot/vmp/service/bean/StreamPushItemFromRedis.java new file mode 100644 index 00000000..ff32d791 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/service/bean/StreamPushItemFromRedis.java @@ -0,0 +1,34 @@ +package com.genersoft.iot.vmp.service.bean; + + +public class StreamPushItemFromRedis { + private String app; + private String stream; + private long timeStamp; + + public String getApp() { + return app; + } + + public void setApp(String app) { + this.app = app; + } + + public String getStream() { + return stream; + } + + public void setStream(String stream) { + this.stream = stream; + } + + public long getTimeStamp() { + return timeStamp; + } + + public void setTimeStamp(long timeStamp) { + this.timeStamp = timeStamp; + } +} + + diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceAlarmServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceAlarmServiceImpl.java index ead291c0..8c55986e 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceAlarmServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceAlarmServiceImpl.java @@ -17,7 +17,6 @@ public class DeviceAlarmServiceImpl implements IDeviceAlarmService { @Autowired private DeviceAlarmMapper deviceAlarmMapper; - @Override public PageInfo getAllAlarm(int page, int count, String deviceId, String alarmPriority, String alarmMethod, String alarmType, String startTime, String endTime) { PageHelper.startPage(page, count); diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java new file mode 100644 index 00000000..99ad3dee --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java @@ -0,0 +1,165 @@ +package com.genersoft.iot.vmp.service.impl; + +import com.genersoft.iot.vmp.common.StreamInfo; +import com.genersoft.iot.vmp.gb28181.bean.Device; +import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; +import com.genersoft.iot.vmp.gb28181.utils.Coordtransform; +import com.genersoft.iot.vmp.service.IDeviceChannelService; +import com.genersoft.iot.vmp.storager.IRedisCatchStorage; +import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper; +import com.genersoft.iot.vmp.storager.dao.DeviceMapper; +import com.genersoft.iot.vmp.utils.DateUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +/** + * @author lin + */ +@Service +public class DeviceChannelServiceImpl implements IDeviceChannelService { + + private final static Logger logger = LoggerFactory.getLogger(DeviceChannelServiceImpl.class); + + @Autowired + private IRedisCatchStorage redisCatchStorage; + + @Autowired + private DeviceChannelMapper channelMapper; + + @Autowired + private DeviceMapper deviceMapper; + + @Override + public DeviceChannel updateGps(DeviceChannel deviceChannel, Device device) { + if (deviceChannel.getLongitude()*deviceChannel.getLatitude() > 0) { + if (device == null) { + device = deviceMapper.getDeviceByDeviceId(deviceChannel.getDeviceId()); + } + + if ("WGS84".equals(device.getGeoCoordSys())) { + deviceChannel.setLongitudeWgs84(deviceChannel.getLongitude()); + deviceChannel.setLatitudeWgs84(deviceChannel.getLatitude()); + Double[] position = Coordtransform.WGS84ToGCJ02(deviceChannel.getLongitude(), deviceChannel.getLatitude()); + deviceChannel.setLongitudeGcj02(position[0]); + deviceChannel.setLatitudeGcj02(position[1]); + }else if ("GCJ02".equals(device.getGeoCoordSys())) { + deviceChannel.setLongitudeGcj02(deviceChannel.getLongitude()); + deviceChannel.setLatitudeGcj02(deviceChannel.getLatitude()); + Double[] position = Coordtransform.GCJ02ToWGS84(deviceChannel.getLongitude(), deviceChannel.getLatitude()); + deviceChannel.setLongitudeWgs84(position[0]); + deviceChannel.setLatitudeWgs84(position[1]); + }else { + deviceChannel.setLongitudeGcj02(0.00); + deviceChannel.setLatitudeGcj02(0.00); + deviceChannel.setLongitudeWgs84(0.00); + deviceChannel.setLatitudeWgs84(0.00); + } + }else { + deviceChannel.setLongitudeGcj02(deviceChannel.getLongitude()); + deviceChannel.setLatitudeGcj02(deviceChannel.getLatitude()); + deviceChannel.setLongitudeWgs84(deviceChannel.getLongitude()); + deviceChannel.setLatitudeWgs84(deviceChannel.getLatitude()); + } + return deviceChannel; + } + + @Override + public void updateChannel(String deviceId, DeviceChannel channel) { + String channelId = channel.getChannelId(); + channel.setDeviceId(deviceId); + StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId); + if (streamInfo != null) { + channel.setStreamId(streamInfo.getStream()); + } + String now = DateUtil.getNow(); + channel.setUpdateTime(now); + DeviceChannel deviceChannel = channelMapper.queryChannel(deviceId, channelId); + channel = updateGps(channel, null); + if (deviceChannel == null) { + channel.setCreateTime(now); + channelMapper.add(channel); + }else { + channelMapper.update(channel); + } + channelMapper.updateChannelSubCount(deviceId,channel.getParentId()); + } + + @Override + public int updateChannels(String deviceId, List channels) { + List addChannels = new ArrayList<>(); + List updateChannels = new ArrayList<>(); + HashMap channelsInStore = new HashMap<>(); + Device device = deviceMapper.getDeviceByDeviceId(deviceId); + if (channels != null && channels.size() > 0) { + List channelList = channelMapper.queryChannels(deviceId, null, null, null, null); + if (channelList.size() == 0) { + for (DeviceChannel channel : channels) { + channel.setDeviceId(deviceId); + StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channel.getChannelId()); + if (streamInfo != null) { + channel.setStreamId(streamInfo.getStream()); + } + String now = DateUtil.getNow(); + channel.setUpdateTime(now); + channel.setCreateTime(now); + channel = updateGps(channel, device); + addChannels.add(channel); + } + }else { + for (DeviceChannel deviceChannel : channelList) { + channelsInStore.put(deviceChannel.getChannelId(), deviceChannel); + } + for (DeviceChannel channel : channels) { + channel.setDeviceId(deviceId); + StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channel.getChannelId()); + if (streamInfo != null) { + channel.setStreamId(streamInfo.getStream()); + } + String now = DateUtil.getNow(); + channel.setUpdateTime(now); + channel = updateGps(channel, device); + if (channelsInStore.get(channel.getChannelId()) != null) { + updateChannels.add(channel); + }else { + addChannels.add(channel); + channel.setCreateTime(now); + } + } + } + int limitCount = 300; + if (addChannels.size() > 0) { + if (addChannels.size() > limitCount) { + for (int i = 0; i < addChannels.size(); i += limitCount) { + int toIndex = i + limitCount; + if (i + limitCount > addChannels.size()) { + toIndex = addChannels.size(); + } + channelMapper.batchAdd(addChannels.subList(i, toIndex)); + } + }else { + channelMapper.batchAdd(addChannels); + } + } + if (updateChannels.size() > 0) { + if (updateChannels.size() > limitCount) { + for (int i = 0; i < updateChannels.size(); i += limitCount) { + int toIndex = i + limitCount; + if (i + limitCount > updateChannels.size()) { + toIndex = updateChannels.size(); + } + channelMapper.batchUpdate(updateChannels.subList(i, toIndex)); + } + }else { + channelMapper.batchUpdate(updateChannels); + } + } + } + return addChannels.size() + updateChannels.size(); + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java index 9d376fb0..579184c9 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java @@ -7,6 +7,7 @@ import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask; import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander; import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd.CatalogResponseMessageHandler; import com.genersoft.iot.vmp.gb28181.utils.Coordtransform; +import com.genersoft.iot.vmp.service.IDeviceChannelService; import com.genersoft.iot.vmp.service.IDeviceService; import com.genersoft.iot.vmp.gb28181.task.impl.CatalogSubscribeTask; import com.genersoft.iot.vmp.gb28181.task.impl.MobilePositionSubscribeTask; @@ -55,6 +56,9 @@ public class DeviceServiceImpl implements IDeviceService { @Autowired private DeviceMapper deviceMapper; + @Autowired + private IDeviceChannelService deviceChannelService; + @Autowired private DeviceChannelMapper deviceChannelMapper; @@ -324,23 +328,12 @@ public class DeviceServiceImpl implements IDeviceService { private void updateDeviceChannelGeoCoordSys(Device device) { List deviceChannels = deviceChannelMapper.getAllChannelWithCoordinate(device.getDeviceId()); if (deviceChannels.size() > 0) { + List deviceChannelsForStore = new ArrayList<>(); for (DeviceChannel deviceChannel : deviceChannels) { - if ("WGS84".equals(device.getGeoCoordSys())) { - deviceChannel.setLongitudeWgs84(deviceChannel.getLongitude()); - deviceChannel.setLatitudeWgs84(deviceChannel.getLatitude()); - Double[] position = Coordtransform.WGS84ToGCJ02(deviceChannel.getLongitude(), deviceChannel.getLatitude()); - deviceChannel.setLongitudeGcj02(position[0]); - deviceChannel.setLatitudeGcj02(position[1]); - }else if ("GCJ02".equals(device.getGeoCoordSys())) { - deviceChannel.setLongitudeGcj02(deviceChannel.getLongitude()); - deviceChannel.setLatitudeGcj02(deviceChannel.getLatitude()); - Double[] position = Coordtransform.GCJ02ToWGS84(deviceChannel.getLongitude(), deviceChannel.getLatitude()); - deviceChannel.setLongitudeWgs84(position[0]); - deviceChannel.setLatitudeWgs84(position[1]); - } + deviceChannelsForStore.add(deviceChannelService.updateGps(deviceChannel, device)); } + deviceChannelService.updateChannels(device.getDeviceId(), deviceChannelsForStore); } - storage.updateChannels(device.getDeviceId(), deviceChannels); } @@ -352,11 +345,11 @@ public class DeviceServiceImpl implements IDeviceService { } if (parentId == null || parentId.equals(deviceId)) { // 字根节点开始查询 - List rootNodes = getRootNodes(deviceId, "CivilCode".equals(device.getTreeType()), true, !onlyCatalog); + List rootNodes = getRootNodes(deviceId, TreeType.CIVIL_CODE.equals(device.getTreeType()), true, !onlyCatalog); return transportChannelsToTree(rootNodes, ""); } - if ("CivilCode".equals(device.getTreeType())) { + if (TreeType.CIVIL_CODE.equals(device.getTreeType())) { if (parentId.length()%2 != 0) { return null; } @@ -386,7 +379,7 @@ public class DeviceServiceImpl implements IDeviceService { } // 使用业务分组展示树 - if ("BusinessGroup".equals(device.getTreeType())) { + if (TreeType.BUSINESS_GROUP.equals(device.getTreeType())) { if (parentId.length() < 14 ) { return null; } @@ -406,11 +399,11 @@ public class DeviceServiceImpl implements IDeviceService { } if (parentId == null || parentId.equals(deviceId)) { // 字根节点开始查询 - List rootNodes = getRootNodes(deviceId, "CivilCode".equals(device.getTreeType()), false, true); + List rootNodes = getRootNodes(deviceId, TreeType.CIVIL_CODE.equals(device.getTreeType()), false, true); return rootNodes; } - if ("CivilCode".equals(device.getTreeType())) { + if (TreeType.CIVIL_CODE.equals(device.getTreeType())) { if (parentId.length()%2 != 0) { return null; } @@ -431,7 +424,7 @@ public class DeviceServiceImpl implements IDeviceService { } // 使用业务分组展示树 - if ("BusinessGroup".equals(device.getTreeType())) { + if (TreeType.BUSINESS_GROUP.equals(device.getTreeType())) { if (parentId.length() < 14 ) { return null; } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/GbStreamServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/GbStreamServiceImpl.java index c813b115..8734882f 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/GbStreamServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/GbStreamServiceImpl.java @@ -1,14 +1,13 @@ package com.genersoft.iot.vmp.service.impl; import com.genersoft.iot.vmp.conf.SipConfig; -import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; -import com.genersoft.iot.vmp.gb28181.bean.GbStream; -import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; +import com.genersoft.iot.vmp.gb28181.bean.*; import com.genersoft.iot.vmp.gb28181.event.EventPublisher; import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; import com.genersoft.iot.vmp.storager.dao.GbStreamMapper; import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper; +import com.genersoft.iot.vmp.storager.dao.PlatformCatalogMapper; import com.genersoft.iot.vmp.storager.dao.PlatformGbStreamMapper; import com.genersoft.iot.vmp.service.IGbStreamService; import com.github.pagehelper.PageHelper; @@ -46,15 +45,15 @@ public class GbStreamServiceImpl implements IGbStreamService { private ParentPlatformMapper platformMapper; @Autowired - private SipConfig sipConfig; + private PlatformCatalogMapper catalogMapper; @Autowired private EventPublisher eventPublisher; @Override - public PageInfo getAll(Integer page, Integer count, String platFormId, String catalogId, String query, Boolean pushing, String mediaServerId) { + public PageInfo getAll(Integer page, Integer count, String platFormId, String catalogId, String query, String mediaServerId) { PageHelper.startPage(page, count); - List all = gbStreamMapper.selectAll(platFormId, catalogId, query, pushing, mediaServerId); + List all = gbStreamMapper.selectAll(platFormId, catalogId, query, mediaServerId); return new PageInfo<>(all); } @@ -102,16 +101,25 @@ public class GbStreamServiceImpl implements IGbStreamService { deviceChannel.setLatitude(gbStream.getLatitude()); deviceChannel.setDeviceId(platform.getDeviceGBId()); deviceChannel.setManufacture("wvp-pro"); -// deviceChannel.setStatus(gbStream.isStatus()?1:0); - deviceChannel.setStatus(1); - deviceChannel.setParentId(catalogId ==null?gbStream.getCatalogId():catalogId); + deviceChannel.setStatus(gbStream.isStatus()?1:0); + deviceChannel.setRegisterWay(1); - if (catalogId.length() > 0 && catalogId.length() <= 10) { - // 父节点是行政区划,则设置CivilCode使用此行政区划 + deviceChannel.setCivilCode(platform.getAdministrativeDivision()); + + if (platform.getTreeType().equals(TreeType.CIVIL_CODE)){ deviceChannel.setCivilCode(catalogId); - }else { - deviceChannel.setCivilCode(platform.getAdministrativeDivision()); + }else if (platform.getTreeType().equals(TreeType.BUSINESS_GROUP)){ + PlatformCatalog catalog = catalogMapper.select(catalogId); + if (catalog == null) { + deviceChannel.setParentId(platform.getDeviceGBId()); + deviceChannel.setBusinessGroupId(null); + }else { + deviceChannel.setParentId(catalog.getId()); + deviceChannel.setBusinessGroupId(catalog.getBusinessGroupId()); + } + } + deviceChannel.setModel("live"); deviceChannel.setOwner("wvp-pro"); deviceChannel.setParental(0); @@ -149,9 +157,9 @@ public class GbStreamServiceImpl implements IGbStreamService { if (gbStream.getGbId() != null) { gbStreams.add(gbStream); }else { - StreamProxyItem streamProxyItem = gbStreamMapper.selectOne(gbStream.getApp(), gbStream.getStream()); - if (streamProxyItem != null && streamProxyItem.getGbId() != null){ - gbStreams.add(streamProxyItem); + GbStream gbStreamIndb = gbStreamMapper.selectOne(gbStream.getApp(), gbStream.getStream()); + if (gbStreamIndb != null && gbStreamIndb.getGbId() != null){ + gbStreams.add(gbStreamIndb); } } sendCatalogMsgs(gbStreams, type); diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java index 2c084a55..fb7cea09 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java @@ -7,12 +7,15 @@ import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.conf.MediaConfig; import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils; import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; +import com.genersoft.iot.vmp.media.zlm.dto.OnPublishHookParam; +import com.genersoft.iot.vmp.media.zlm.dto.StreamAuthorityInfo; import com.genersoft.iot.vmp.service.IMediaServerService; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.IVideoManagerStorage; import com.genersoft.iot.vmp.service.IMediaService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; @Service public class MediaServiceImpl implements IMediaService { @@ -36,20 +39,24 @@ public class MediaServiceImpl implements IMediaService { @Override - public StreamInfo getStreamInfoByAppAndStream(MediaServerItem mediaInfo, String app, String stream, Object tracks) { - return getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks, null); + public StreamInfo getStreamInfoByAppAndStream(MediaServerItem mediaInfo, String app, String stream, Object tracks, String callId) { + return getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks, null, callId); } @Override - public StreamInfo getStreamInfoByAppAndStreamWithCheck(String app, String stream, String mediaServerId, String addr) { + public StreamInfo getStreamInfoByAppAndStreamWithCheck(String app, String stream, String mediaServerId, String addr, boolean authority) { StreamInfo streamInfo = null; if (mediaServerId == null) { mediaServerId = mediaConfig.getId(); } - MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId);; + MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId); if (mediaInfo == null) { return null; } + StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(app, stream); + if (streamAuthorityInfo == null) { + return null; + } JSONObject mediaList = zlmresTfulUtils.getMediaList(mediaInfo, app, stream); if (mediaList != null) { if (mediaList.getInteger("code") == 0) { @@ -59,7 +66,12 @@ public class MediaServiceImpl implements IMediaService { } JSONObject mediaJSON = JSON.parseObject(JSON.toJSONString(data.get(0)), JSONObject.class); JSONArray tracks = mediaJSON.getJSONArray("tracks"); - streamInfo = getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks); + if (authority) { + streamInfo = getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks, streamAuthorityInfo.getCallId()); + }else { + streamInfo = getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks, null); + } + } } return streamInfo; @@ -68,46 +80,48 @@ public class MediaServiceImpl implements IMediaService { @Override - public StreamInfo getStreamInfoByAppAndStreamWithCheck(String app, String stream, String mediaServerId) { - return getStreamInfoByAppAndStreamWithCheck(app, stream, mediaServerId, null); + public StreamInfo getStreamInfoByAppAndStreamWithCheck(String app, String stream, String mediaServerId, boolean authority) { + return getStreamInfoByAppAndStreamWithCheck(app, stream, mediaServerId, null, authority); } @Override - public StreamInfo getStreamInfoByAppAndStream(MediaServerItem mediaInfo, String app, String stream, Object tracks, String addr) { + public StreamInfo getStreamInfoByAppAndStream(MediaServerItem mediaInfo, String app, String stream, Object tracks, String addr, String callId) { StreamInfo streamInfoResult = new StreamInfo(); streamInfoResult.setStream(stream); streamInfoResult.setApp(app); if (addr == null) { addr = mediaInfo.getStreamIp(); } + streamInfoResult.setIp(addr); streamInfoResult.setMediaServerId(mediaInfo.getId()); - streamInfoResult.setRtmp(String.format("rtmp://%s:%s/%s/%s", addr, mediaInfo.getRtmpPort(), app, stream)); + String callIdParam = StringUtils.isEmpty(callId)?"":"?callId=" + callId; + streamInfoResult.setRtmp(String.format("rtmp://%s:%s/%s/%s%s", addr, mediaInfo.getRtmpPort(), app, stream, callIdParam)); if (mediaInfo.getRtmpSSlPort() != 0) { - streamInfoResult.setRtmps(String.format("rtmps://%s:%s/%s/%s", addr, mediaInfo.getRtmpSSlPort(), app, stream)); + streamInfoResult.setRtmps(String.format("rtmps://%s:%s/%s/%s%s", addr, mediaInfo.getRtmpSSlPort(), app, stream, callIdParam)); } - streamInfoResult.setRtsp(String.format("rtsp://%s:%s/%s/%s", addr, mediaInfo.getRtspPort(), app, stream)); + streamInfoResult.setRtsp(String.format("rtsp://%s:%s/%s/%s%s", addr, mediaInfo.getRtspPort(), app, stream, callIdParam)); if (mediaInfo.getRtspSSLPort() != 0) { - streamInfoResult.setRtsps(String.format("rtsps://%s:%s/%s/%s", addr, mediaInfo.getRtspSSLPort(), app, stream)); + streamInfoResult.setRtsps(String.format("rtsps://%s:%s/%s/%s%s", addr, mediaInfo.getRtspSSLPort(), app, stream, callIdParam)); } - streamInfoResult.setFlv(String.format("http://%s:%s/%s/%s.live.flv", addr, mediaInfo.getHttpPort(), app, stream)); - streamInfoResult.setWs_flv(String.format("ws://%s:%s/%s/%s.live.flv", addr, mediaInfo.getHttpPort(), app, stream)); - streamInfoResult.setHls(String.format("http://%s:%s/%s/%s/hls.m3u8", addr, mediaInfo.getHttpPort(), app, stream)); - streamInfoResult.setWs_hls(String.format("ws://%s:%s/%s/%s/hls.m3u8", addr, mediaInfo.getHttpPort(), app, stream)); - streamInfoResult.setFmp4(String.format("http://%s:%s/%s/%s.live.mp4", addr, mediaInfo.getHttpPort(), app, stream)); - streamInfoResult.setWs_fmp4(String.format("ws://%s:%s/%s/%s.live.mp4", addr, mediaInfo.getHttpPort(), app, stream)); - streamInfoResult.setTs(String.format("http://%s:%s/%s/%s.live.ts", addr, mediaInfo.getHttpPort(), app, stream)); - streamInfoResult.setWs_ts(String.format("ws://%s:%s/%s/%s.live.ts", addr, mediaInfo.getHttpPort(), app, stream)); + streamInfoResult.setFlv(String.format("http://%s:%s/%s/%s.live.flv%s", addr, mediaInfo.getHttpPort(), app, stream, callIdParam)); + streamInfoResult.setWs_flv(String.format("ws://%s:%s/%s/%s.live.flv%s", addr, mediaInfo.getHttpPort(), app, stream, callIdParam)); + streamInfoResult.setHls(String.format("http://%s:%s/%s/%s/hls.m3u8%s", addr, mediaInfo.getHttpPort(), app, stream, callIdParam)); + streamInfoResult.setWs_hls(String.format("ws://%s:%s/%s/%s/hls.m3u8%s", addr, mediaInfo.getHttpPort(), app, stream, callIdParam)); + streamInfoResult.setFmp4(String.format("http://%s:%s/%s/%s.live.mp4%s", addr, mediaInfo.getHttpPort(), app, stream, callIdParam)); + streamInfoResult.setWs_fmp4(String.format("ws://%s:%s/%s/%s.live.mp4%s", addr, mediaInfo.getHttpPort(), app, stream, callIdParam)); + streamInfoResult.setTs(String.format("http://%s:%s/%s/%s.live.ts%s", addr, mediaInfo.getHttpPort(), app, stream, callIdParam)); + streamInfoResult.setWs_ts(String.format("ws://%s:%s/%s/%s.live.ts%s", addr, mediaInfo.getHttpPort(), app, stream, callIdParam)); if (mediaInfo.getHttpSSlPort() != 0) { - streamInfoResult.setHttps_flv(String.format("https://%s:%s/%s/%s.live.flv", addr, mediaInfo.getHttpSSlPort(), app, stream)); - streamInfoResult.setWss_flv(String.format("wss://%s:%s/%s/%s.live.flv", addr, mediaInfo.getHttpSSlPort(), app, stream)); - streamInfoResult.setHttps_hls(String.format("https://%s:%s/%s/%s/hls.m3u8", addr, mediaInfo.getHttpSSlPort(), app, stream)); - streamInfoResult.setWss_hls(String.format("wss://%s:%s/%s/%s/hls.m3u8", addr, mediaInfo.getHttpSSlPort(), app, stream)); - streamInfoResult.setHttps_fmp4(String.format("https://%s:%s/%s/%s.live.mp4", addr, mediaInfo.getHttpSSlPort(), app, stream)); - streamInfoResult.setWss_fmp4(String.format("wss://%s:%s/%s/%s.live.mp4", addr, mediaInfo.getHttpSSlPort(), app, stream)); - streamInfoResult.setHttps_ts(String.format("https://%s:%s/%s/%s.live.ts", addr, mediaInfo.getHttpSSlPort(), app, stream)); - streamInfoResult.setWss_ts(String.format("wss://%s:%s/%s/%s.live.ts", addr, mediaInfo.getHttpSSlPort(), app, stream)); - streamInfoResult.setWss_ts(String.format("wss://%s:%s/%s/%s.live.ts", addr, mediaInfo.getHttpSSlPort(), app, stream)); - streamInfoResult.setRtc(String.format("https://%s:%s/index/api/webrtc?app=%s&stream=%s&type=play", mediaInfo.getStreamIp(), mediaInfo.getHttpSSlPort(), app, stream)); + streamInfoResult.setHttps_flv(String.format("https://%s:%s/%s/%s.live.flv%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam)); + streamInfoResult.setWss_flv(String.format("wss://%s:%s/%s/%s.live.flv%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam)); + streamInfoResult.setHttps_hls(String.format("https://%s:%s/%s/%s/hls.m3u8%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam)); + streamInfoResult.setWss_hls(String.format("wss://%s:%s/%s/%s/hls.m3u8%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam)); + streamInfoResult.setHttps_fmp4(String.format("https://%s:%s/%s/%s.live.mp4%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam)); + streamInfoResult.setWss_fmp4(String.format("wss://%s:%s/%s/%s.live.mp4%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam)); + streamInfoResult.setHttps_ts(String.format("https://%s:%s/%s/%s.live.ts%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam)); + streamInfoResult.setWss_ts(String.format("wss://%s:%s/%s/%s.live.ts%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam)); + streamInfoResult.setWss_ts(String.format("wss://%s:%s/%s/%s.live.ts%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam)); + streamInfoResult.setRtc(String.format("https://%s:%s/index/api/webrtc?app=%s&stream=%s&type=play%s", mediaInfo.getStreamIp(), mediaInfo.getHttpSSlPort(), app, stream, StringUtils.isEmpty(callId)?"":"&callId=" + callId)); } streamInfoResult.setTracks(tracks); diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformChannelServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformChannelServiceImpl.java new file mode 100644 index 00000000..d0245502 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformChannelServiceImpl.java @@ -0,0 +1,106 @@ +package com.genersoft.iot.vmp.service.impl; + +import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; +import com.genersoft.iot.vmp.gb28181.bean.PlatformCatalog; +import com.genersoft.iot.vmp.gb28181.bean.TreeType; +import com.genersoft.iot.vmp.gb28181.event.EventPublisher; +import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; +import com.genersoft.iot.vmp.service.IPlatformChannelService; +import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper; +import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper; +import com.genersoft.iot.vmp.storager.dao.PlatformCatalogMapper; +import com.genersoft.iot.vmp.storager.dao.PlatformChannelMapper; +import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author lin + */ +@Service +public class PlatformChannelServiceImpl implements IPlatformChannelService { + + private final static Logger logger = LoggerFactory.getLogger(PlatformChannelServiceImpl.class); + + @Autowired + private PlatformChannelMapper platformChannelMapper; + + @Autowired + private DeviceChannelMapper deviceChannelMapper; + + @Autowired + private PlatformCatalogMapper catalogManager; + + @Autowired + private ParentPlatformMapper platformMapper; + + @Autowired + EventPublisher eventPublisher; + + @Override + public int updateChannelForGB(String platformId, List channelReduces, String catalogId) { + ParentPlatform platform = platformMapper.getParentPlatByServerGBId(platformId); + if (platform == null) { + logger.warn("更新级联通道信息时未找到平台{}的信息", platformId); + return 0; + } + Map deviceAndChannels = new HashMap<>(); + for (ChannelReduce channelReduce : channelReduces) { + channelReduce.setCatalogId(catalogId); + deviceAndChannels.put(channelReduce.getId(), channelReduce); + } + List deviceAndChannelList = new ArrayList<>(deviceAndChannels.keySet()); + // 查询当前已经存在的 + List channelIds = platformChannelMapper.findChannelRelatedPlatform(platformId, channelReduces); + if (deviceAndChannelList != null) { + deviceAndChannelList.removeAll(channelIds); + } + for (Integer channelId : channelIds) { + deviceAndChannels.remove(channelId); + } + List channelReducesToAdd = new ArrayList<>(deviceAndChannels.values()); + // 对剩下的数据进行存储 + int result = 0; + if (channelReducesToAdd.size() > 0) { + result = platformChannelMapper.addChannels(platformId, channelReducesToAdd); + // TODO 后续给平台增加控制开关以控制是否响应目录订阅 + List deviceChannelList = getDeviceChannelListByChannelReduceList(channelReducesToAdd, catalogId, platform); + eventPublisher.catalogEventPublish(platformId, deviceChannelList, CatalogEvent.ADD); + } + + return result; + } + + private List getDeviceChannelListByChannelReduceList(List channelReduces, String catalogId, ParentPlatform platform) { + List deviceChannelList = new ArrayList<>(); + if (channelReduces.size() > 0){ + PlatformCatalog catalog = catalogManager.select(catalogId); + if (catalog == null && !catalogId.equals(platform.getServerGBId())) { + logger.warn("未查询到目录{}的信息", catalogId); + return null; + } + for (ChannelReduce channelReduce : channelReduces) { + DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(channelReduce.getDeviceId(), channelReduce.getChannelId()); + deviceChannel.setParental(0); + deviceChannelList.add(deviceChannel); + if (platform.getTreeType().equals(TreeType.CIVIL_CODE)){ + deviceChannel.setCivilCode(catalogId); + }else if (platform.getTreeType().equals(TreeType.BUSINESS_GROUP)){ + deviceChannel.setParentId(catalogId); + if (catalog != null) { + deviceChannel.setBusinessGroupId(catalog.getBusinessGroupId()); + } + } + } + } + return deviceChannelList; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java index 041fdf00..ddfbc794 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java @@ -620,7 +620,7 @@ public class PlayServiceImpl implements IPlayService { public StreamInfo onPublishHandler(MediaServerItem mediaServerItem, JSONObject resonse, String deviceId, String channelId) { String streamId = resonse.getString("stream"); JSONArray tracks = resonse.getJSONArray("tracks"); - StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream(mediaServerItem,"rtp", streamId, tracks); + StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream(mediaServerItem,"rtp", streamId, tracks, null); streamInfo.setDeviceID(deviceId); streamInfo.setChannelId(channelId); return streamInfo; diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/RedisGpsMsgListener.java b/src/main/java/com/genersoft/iot/vmp/service/impl/RedisGpsMsgListener.java index 238aafdb..74828334 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/RedisGpsMsgListener.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/RedisGpsMsgListener.java @@ -25,9 +25,7 @@ public class RedisGpsMsgListener implements MessageListener { @Override public void onMessage(@NotNull Message message, byte[] bytes) { - if (logger.isDebugEnabled()) { - logger.debug("收到来自REDIS的GPS通知: {}", new String(message.getBody())); - } + // TODO 加消息队列 GPSMsgInfo gpsMsgInfo = JSON.parseObject(message.getBody(), GPSMsgInfo.class); redisCatchStorage.updateGpsMsgInfo(gpsMsgInfo); } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/RedisPushStreamStatusMsgListener.java b/src/main/java/com/genersoft/iot/vmp/service/impl/RedisPushStreamStatusMsgListener.java new file mode 100644 index 00000000..27e4a7d1 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/RedisPushStreamStatusMsgListener.java @@ -0,0 +1,92 @@ +package com.genersoft.iot.vmp.service.impl; + +import com.alibaba.fastjson.JSON; +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.UserSetting; +import com.genersoft.iot.vmp.gb28181.bean.GbStream; +import com.genersoft.iot.vmp.gb28181.event.EventPublisher; +import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; +import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander; +import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; +import com.genersoft.iot.vmp.media.zlm.ZLMMediaListManager; +import com.genersoft.iot.vmp.media.zlm.dto.MediaItem; +import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; +import com.genersoft.iot.vmp.service.IStreamPushService; +import com.genersoft.iot.vmp.service.bean.PushStreamStatusChangeFromRedisDto; +import com.genersoft.iot.vmp.service.bean.StreamPushItemFromRedis; +import com.genersoft.iot.vmp.storager.IRedisCatchStorage; +import com.genersoft.iot.vmp.storager.IVideoManagerStorage; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.data.redis.connection.Message; +import org.springframework.data.redis.connection.MessageListener; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + + +/** + * 接收redis发送的推流设备上线下线通知 + * @author lin + */ +@Component +public class RedisPushStreamStatusMsgListener implements MessageListener, ApplicationRunner { + + private final static Logger logger = LoggerFactory.getLogger(RedisPushStreamStatusMsgListener.class); + + @Autowired + private IRedisCatchStorage redisCatchStorage; + + @Autowired + private IStreamPushService streamPushService; + + @Autowired + private EventPublisher eventPublisher; + + @Autowired + private UserSetting userSetting; + + @Autowired + private DynamicTask dynamicTask; + + @Override + public void onMessage(Message message, byte[] bytes) { + PushStreamStatusChangeFromRedisDto statusChangeFromPushStream = JSON.parseObject(message.getBody(), PushStreamStatusChangeFromRedisDto.class); + if (statusChangeFromPushStream == null) { + logger.warn("[REDIS 消息]推流设备状态变化消息解析失败"); + return; + } + if (statusChangeFromPushStream.isSetAllOffline()) { + // 所有设备离线 + streamPushService.allStreamOffline(); + } + if (statusChangeFromPushStream.getOfflineStreams() != null + && statusChangeFromPushStream.getOfflineStreams().size() > 0) { + // 更新部分设备离线 + streamPushService.offline(statusChangeFromPushStream.getOfflineStreams()); + } + if (statusChangeFromPushStream.getOnlineStreams() != null && + statusChangeFromPushStream.getOnlineStreams().size() > 0) { + // 更新部分设备上线 + streamPushService.online(statusChangeFromPushStream.getOnlineStreams()); + } + } + + @Override + public void run(ApplicationArguments args) throws Exception { + // 启动时设置所有推流通道离线,发起查询请求 + redisCatchStorage.sendStreamPushRequestedMsgForStatus(); + dynamicTask.startDelay(VideoManagerConstants.VM_MSG_GET_ALL_ONLINE_REQUESTED, ()->{ + logger.info("[REDIS 消息]未收到redis回复推流设备状态,执行推流设备离线"); + // 五秒收不到请求就设置通道离线,然后通知上级离线 + streamPushService.allStreamOffline(); + }, 5000); + } + +} diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/RedisStreamMsgListener.java b/src/main/java/com/genersoft/iot/vmp/service/impl/RedisStreamMsgListener.java index 07fffdcc..83116f3a 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/RedisStreamMsgListener.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/RedisStreamMsgListener.java @@ -3,16 +3,12 @@ package com.genersoft.iot.vmp.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.genersoft.iot.vmp.conf.UserSetting; -import com.genersoft.iot.vmp.gb28181.bean.AlarmChannelMessage; -import com.genersoft.iot.vmp.gb28181.bean.Device; -import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm; -import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; + import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander; import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; import com.genersoft.iot.vmp.media.zlm.ZLMMediaListManager; import com.genersoft.iot.vmp.media.zlm.dto.MediaItem; import com.genersoft.iot.vmp.storager.IVideoManagerStorage; -import com.genersoft.iot.vmp.utils.DateUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -22,6 +18,7 @@ import org.springframework.stereotype.Component; /** + * 接收其他wvp发送流变化通知 * @author lin */ @Component diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java index 67dfb6f9..40c37c23 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java @@ -3,10 +3,10 @@ package com.genersoft.iot.vmp.service.impl; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.genersoft.iot.vmp.common.StreamInfo; -import com.genersoft.iot.vmp.conf.SipConfig; import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.gb28181.bean.GbStream; import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; +import com.genersoft.iot.vmp.gb28181.bean.TreeType; import com.genersoft.iot.vmp.gb28181.event.EventPublisher; import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils; @@ -23,14 +23,19 @@ import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper; import com.genersoft.iot.vmp.storager.dao.PlatformGbStreamMapper; import com.genersoft.iot.vmp.storager.dao.StreamProxyMapper; import com.genersoft.iot.vmp.service.IStreamProxyService; +import com.genersoft.iot.vmp.utils.DateUtil; import com.genersoft.iot.vmp.vmanager.bean.WVPResult; import com.github.pagehelper.PageInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.stereotype.Service; +import org.springframework.transaction.TransactionDefinition; +import org.springframework.transaction.TransactionStatus; import org.springframework.util.StringUtils; +import java.net.InetAddress; import java.util.*; /** @@ -48,7 +53,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService { private IMediaService mediaService; @Autowired - private ZLMRESTfulUtils zlmresTfulUtils;; + private ZLMRESTfulUtils zlmresTfulUtils; @Autowired private StreamProxyMapper streamProxyMapper; @@ -62,9 +67,6 @@ public class StreamProxyServiceImpl implements IStreamProxyService { @Autowired private UserSetting userSetting; - @Autowired - private SipConfig sipConfig; - @Autowired private GbStreamMapper gbStreamMapper; @@ -83,6 +85,12 @@ public class StreamProxyServiceImpl implements IStreamProxyService { @Autowired private IMediaServerService mediaServerService; + @Autowired + DataSourceTransactionManager dataSourceTransactionManager; + + @Autowired + TransactionDefinition transactionDefinition; + @Override public WVPResult save(StreamProxyItem param) { @@ -99,6 +107,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService { wvpResult.setMsg("保存失败"); return wvpResult; } + String dstUrl = String.format("rtmp://%s:%s/%s/%s", "127.0.0.1", mediaInfo.getRtmpPort(), param.getApp(), param.getStream() ); param.setDst_url(dstUrl); @@ -108,9 +117,9 @@ public class StreamProxyServiceImpl implements IStreamProxyService { boolean saveResult; // 更新 if (videoManagerStorager.queryStreamProxy(param.getApp(), param.getStream()) != null) { - saveResult = videoManagerStorager.updateStreamProxy(param); + saveResult = updateStreamProxy(param); }else { // 新增 - saveResult = videoManagerStorager.addStreamProxy(param); + saveResult = addStreamProxy(param); } if (saveResult) { result.append("保存成功"); @@ -124,7 +133,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService { if (param.isEnable_remove_none_reader()) { del(param.getApp(), param.getStream()); }else { - videoManagerStorager.updateStreamProxy(param); + updateStreamProxy(param); } }else { @@ -147,27 +156,81 @@ public class StreamProxyServiceImpl implements IStreamProxyService { result.append(", 关联国标平台[ " + param.getPlatformGbId() + " ]失败"); } } - if (!StringUtils.isEmpty(param.getGbId())) { - // 查找开启了全部直播流共享的上级平台 - List parentPlatforms = parentPlatformMapper.selectAllAhareAllLiveStream(); - if (parentPlatforms.size() > 0) { - for (ParentPlatform parentPlatform : parentPlatforms) { - param.setPlatformId(parentPlatform.getServerGBId()); - param.setCatalogId(parentPlatform.getCatalogId()); - String stream = param.getStream(); - StreamProxyItem streamProxyItems = platformGbStreamMapper.selectOne(param.getApp(), stream, parentPlatform.getServerGBId()); - if (streamProxyItems == null) { - platformGbStreamMapper.add(param); - eventPublisher.catalogEventPublishForStream(parentPlatform.getServerGBId(), param, CatalogEvent.ADD); - } - } - } - } - wvpResult.setMsg(result.toString()); return wvpResult; } + /** + * 新增代理流 + * @param streamProxyItem + * @return + */ + private boolean addStreamProxy(StreamProxyItem streamProxyItem) { + TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); + boolean result = false; + streamProxyItem.setStreamType("proxy"); + streamProxyItem.setStatus(true); + String now = DateUtil.getNow(); + streamProxyItem.setCreateTime(now); + try { + if (streamProxyMapper.add(streamProxyItem) > 0) { + if (!StringUtils.isEmpty(streamProxyItem.getGbId())) { + if (gbStreamMapper.add(streamProxyItem) < 0) { + //事务回滚 + dataSourceTransactionManager.rollback(transactionStatus); + return false; + } + } + }else { + //事务回滚 + dataSourceTransactionManager.rollback(transactionStatus); + return false; + } + result = true; + dataSourceTransactionManager.commit(transactionStatus); //手动提交 + }catch (Exception e) { + logger.error("向数据库添加流代理失败:", e); + dataSourceTransactionManager.rollback(transactionStatus); + } + + + return result; + } + + /** + * 更新代理流 + * @param streamProxyItem + * @return + */ + @Override + public boolean updateStreamProxy(StreamProxyItem streamProxyItem) { + TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); + boolean result = false; + streamProxyItem.setStreamType("proxy"); + try { + if (streamProxyMapper.update(streamProxyItem) > 0) { + if (!StringUtils.isEmpty(streamProxyItem.getGbId())) { + if (gbStreamMapper.updateByAppAndStream(streamProxyItem) == 0) { + //事务回滚 + dataSourceTransactionManager.rollback(transactionStatus); + return false; + } + } + } else { + //事务回滚 + dataSourceTransactionManager.rollback(transactionStatus); + return false; + } + + dataSourceTransactionManager.commit(transactionStatus); //手动提交 + result = true; + }catch (Exception e) { + e.printStackTrace(); + dataSourceTransactionManager.rollback(transactionStatus); + } + return result; + } + @Override public JSONObject addStreamProxyToZlm(StreamProxyItem param) { JSONObject result = null; @@ -239,7 +302,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService { if (jsonObject.getInteger("code") == 0) { result = true; streamProxy.setEnable(true); - videoManagerStorager.updateStreamProxy(streamProxy); + updateStreamProxy(streamProxy); } } return result; @@ -253,7 +316,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService { JSONObject jsonObject = removeStreamProxyFromZlm(streamProxyDto); if (jsonObject != null && jsonObject.getInteger("code") == 0) { streamProxyDto.setEnable(false); - result = videoManagerStorager.updateStreamProxy(streamProxyDto); + result = updateStreamProxy(streamProxyDto); } } return result; @@ -319,7 +382,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService { } streamProxyMapper.deleteAutoRemoveItemByMediaServerId(mediaServerId); // 其他的流设置离线 - streamProxyMapper.updateStatusByMediaServerId(false, mediaServerId); + streamProxyMapper.updateStatusByMediaServerId(mediaServerId, false); String type = "PULL"; // 发送redis消息 @@ -346,7 +409,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService { @Override public int updateStatus(boolean status, String app, String stream) { - return streamProxyMapper.updateStatus(status, app, stream); + return streamProxyMapper.updateStatus(app, stream, status); } private void syncPullStream(String mediaServerId){ diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushServiceImpl.java index a8ef1087..62cf20fa 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushServiceImpl.java @@ -13,6 +13,7 @@ import com.genersoft.iot.vmp.media.zlm.dto.*; import com.genersoft.iot.vmp.service.IGbStreamService; import com.genersoft.iot.vmp.service.IMediaServerService; import com.genersoft.iot.vmp.service.IStreamPushService; +import com.genersoft.iot.vmp.service.bean.StreamPushItemFromRedis; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.dao.*; import com.genersoft.iot.vmp.utils.DateUtil; @@ -38,6 +39,9 @@ public class StreamPushServiceImpl implements IStreamPushService { @Autowired private StreamPushMapper streamPushMapper; + @Autowired + private StreamProxyMapper streamProxyMapper; + @Autowired private ParentPlatformMapper parentPlatformMapper; @@ -130,29 +134,6 @@ public class StreamPushServiceImpl implements IStreamPushService { stream.setStatus(true); stream.setCreateTime(DateUtil.getNow()); int add = gbStreamMapper.add(stream); - - // 查找开启了全部直播流共享的上级平台 - List parentPlatforms = parentPlatformMapper.selectAllAhareAllLiveStream(); - if (parentPlatforms.size() > 0) { - for (ParentPlatform parentPlatform : parentPlatforms) { - stream.setCatalogId(parentPlatform.getCatalogId()); - stream.setPlatformId(parentPlatform.getServerGBId()); - String streamId = stream.getStream(); - StreamProxyItem streamProxyItem = platformGbStreamMapper.selectOne(stream.getApp(), streamId, parentPlatform.getServerGBId()); - if (streamProxyItem == null) { - platformGbStreamMapper.add(stream); - eventPublisher.catalogEventPublishForStream(parentPlatform.getServerGBId(), stream, CatalogEvent.ADD); - }else { - if (!streamProxyItem.getGbId().equals(stream.getGbId())) { - // 此流使用另一个国标Id已经与该平台关联,移除此记录 - platformGbStreamMapper.delByAppAndStreamAndPlatform(stream.getApp(), streamId, parentPlatform.getServerGBId()); - platformGbStreamMapper.add(stream); - eventPublisher.catalogEventPublishForStream(parentPlatform.getServerGBId(), stream, CatalogEvent.ADD); - } - } - } - } - return add > 0; } @@ -178,7 +159,6 @@ public class StreamPushServiceImpl implements IStreamPushService { @Override public StreamPushItem getPush(String app, String streamId) { - return streamPushMapper.selectOne(app, streamId); } @@ -285,7 +265,8 @@ public class StreamPushServiceImpl implements IStreamPushService { streamPushMapper.deleteWithoutGBId(mediaServerId); gbStreamMapper.deleteWithoutGBId("push", mediaServerId); // 其他的流设置未启用 - gbStreamMapper.updateStatusByMediaServerId(mediaServerId, false); + streamPushMapper.updateStatusByMediaServerId(mediaServerId, false); + streamProxyMapper.updateStatusByMediaServerId(mediaServerId, false); // 发送流停止消息 String type = "PUSH"; // 发送redis消息 @@ -341,31 +322,6 @@ public class StreamPushServiceImpl implements IStreamPushService { public void batchAdd(List streamPushItems) { streamPushMapper.addAll(streamPushItems); gbStreamMapper.batchAdd(streamPushItems); - // 查找开启了全部直播流共享的上级平台 - List parentPlatforms = parentPlatformMapper.selectAllAhareAllLiveStream(); - if (parentPlatforms.size() > 0) { - for (StreamPushItem stream : streamPushItems) { - for (ParentPlatform parentPlatform : parentPlatforms) { - stream.setCatalogId(parentPlatform.getCatalogId()); - stream.setPlatformId(parentPlatform.getServerGBId()); - String streamId = stream.getStream(); - StreamProxyItem streamProxyItem = platformGbStreamMapper.selectOne(stream.getApp(), streamId, parentPlatform.getServerGBId()); - if (streamProxyItem == null) { - platformGbStreamMapper.add(stream); - eventPublisher.catalogEventPublishForStream(parentPlatform.getServerGBId(), stream, CatalogEvent.ADD); - }else { - if (!streamProxyItem.getGbId().equals(stream.getGbId())) { - // 此流使用另一个国标Id已经与该平台关联,移除此记录 - platformGbStreamMapper.delByAppAndStreamAndPlatform(stream.getApp(), streamId, parentPlatform.getServerGBId()); - platformGbStreamMapper.add(stream); - eventPublisher.catalogEventPublishForStream(parentPlatform.getServerGBId(), stream, CatalogEvent.ADD); - stream.setGbId(streamProxyItem.getGbId()); - eventPublisher.catalogEventPublishForStream(parentPlatform.getServerGBId(), stream, CatalogEvent.DEL); - } - } - } - } - } } @Override @@ -477,4 +433,34 @@ public class StreamPushServiceImpl implements IStreamPushService { } return true; } + + @Override + public void allStreamOffline() { + List onlinePushers = streamPushMapper.getOnlinePusherForGb(); + if (onlinePushers.size() == 0) { + return; + } + streamPushMapper.setAllStreamOffline(); + + // 发送通知 + eventPublisher.catalogEventPublishForStream(null, onlinePushers, CatalogEvent.OFF); + } + + @Override + public void offline(List offlineStreams) { + // 更新部分设备离线 + List onlinePushers = streamPushMapper.getOnlinePusherForGbInList(offlineStreams); + streamPushMapper.offline(offlineStreams); + // 发送通知 + eventPublisher.catalogEventPublishForStream(null, onlinePushers, CatalogEvent.OFF); + } + + @Override + public void online(List onlineStreams) { + // 更新部分设备上线streamPushService + List onlinePushers = streamPushMapper.getOfflinePusherForGbInList(onlineStreams); + streamPushMapper.online(onlineStreams); + // 发送通知 + eventPublisher.catalogEventPublishForStream(null, onlinePushers, CatalogEvent.ON); + } } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushUploadFileHandler.java b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushUploadFileHandler.java index 45cbcf6e..0baad966 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushUploadFileHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushUploadFileHandler.java @@ -14,38 +14,60 @@ import java.util.*; public class StreamPushUploadFileHandler extends AnalysisEventListener { - // 错误数据的回调,用于将错误数据发送给页面 + /** + * 错误数据的回调,用于将错误数据发送给页面 + */ private ErrorDataHandler errorDataHandler; - // 推流的业务类用于存储数据 + /** + * 推流的业务类用于存储数据 + */ private IStreamPushService pushService; - // 默认流媒体节点ID + /** + * 默认流媒体节点ID + */ private String defaultMediaServerId; - // 用于存储不加过滤的所有数据 + /** + * 用于存储不加过滤的所有数据 + */ private List streamPushItems = new ArrayList<>(); - // 用于存储更具APP+Stream过滤后的数据,可以直接存入stream_push表与gb_stream表 + /** + * 用于存储更具APP+Stream过滤后的数据,可以直接存入stream_push表与gb_stream表 + */ private Map streamPushItemForSave = new HashMap<>(); - // 用于存储按照APP+Stream为KEY, 平台ID+目录Id 为value的数据,用于存储到gb_stream表后获取app+Stream对应的平台与目录信息,然后存入关联表 + /** + * 用于存储按照APP+Stream为KEY, 平台ID+目录Id 为value的数据,用于存储到gb_stream表后获取app+Stream对应的平台与目录信息,然后存入关联表 + */ private Map> streamPushItemsForPlatform = new HashMap<>(); - // 用于判断文件是否存在重复的app+Stream+平台ID + /** + * 用于判断文件是否存在重复的app+Stream+平台ID + */ private Set streamPushStreamSet = new HashSet<>(); - // 用于存储APP+Stream->国标ID 的数据结构, 数据一一对应,全局判断APP+Stream->国标ID是否存在不对应 + /** + * 用于存储APP+Stream->国标ID 的数据结构, 数据一一对应,全局判断APP+Stream->国标ID是否存在不对应 + */ private BiMap gBMap = HashBiMap.create(); - // 记录错误的APP+Stream + /** + * 记录错误的APP+Stream + */ private List errorStreamList = new ArrayList<>(); - // 记录错误的国标ID + /** + * 记录错误的国标ID + */ private List errorGBList = new ArrayList<>(); - // 读取数量计数器 + /** + * 读取数量计数器 + */ private int loadedSize = 0; public StreamPushUploadFileHandler(IStreamPushService pushService, String defaultMediaServerId, ErrorDataHandler errorDataHandler) { diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java index 9f156d25..f5dc7b0f 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java @@ -3,14 +3,17 @@ package com.genersoft.iot.vmp.service.impl; import com.genersoft.iot.vmp.service.IUserService; import com.genersoft.iot.vmp.storager.dao.UserMapper; import com.genersoft.iot.vmp.storager.dao.dto.User; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; import java.util.List; @Service public class UserServiceImpl implements IUserService { - + @Autowired private UserMapper userMapper; @@ -55,4 +58,24 @@ public class UserServiceImpl implements IUserService { } + @Override + public boolean checkPushAuthority(String callId, String sign) { + if (StringUtils.isEmpty(callId)) { + return userMapper.checkPushAuthorityByCallId(sign).size() > 0; + }else { + return userMapper.checkPushAuthorityByCallIdAndSign(callId, sign).size() > 0; + } + } + + @Override + public PageInfo getUsers(int page, int count) { + PageHelper.startPage(page, count); + List users = userMapper.getUsers(); + return new PageInfo<>(users); + } + + @Override + public int changePushKey(int id, String pushKey) { + return userMapper.changePushKey(id,pushKey); + } } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java b/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java index 4a3aa78b..b9811da1 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java @@ -3,9 +3,7 @@ package com.genersoft.iot.vmp.storager; import com.alibaba.fastjson.JSONObject; import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.gb28181.bean.*; -import com.genersoft.iot.vmp.media.zlm.dto.MediaItem; -import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; -import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; +import com.genersoft.iot.vmp.media.zlm.dto.*; import com.genersoft.iot.vmp.service.bean.GPSMsgInfo; import com.genersoft.iot.vmp.service.bean.MessageForPushChannel; import com.genersoft.iot.vmp.service.bean.SSRCInfo; @@ -213,4 +211,31 @@ public interface IRedisCatchStorage { */ public boolean deviceIsOnline(String deviceId); + /** + * 存储推流的鉴权信息 + * @param app 应用名 + * @param stream 流 + * @param streamAuthorityInfo 鉴权信息 + */ + void updateStreamAuthorityInfo(String app, String stream, StreamAuthorityInfo streamAuthorityInfo); + + /** + * 移除推流的鉴权信息 + * @param app 应用名 + * @param streamId 流 + */ + void removeStreamAuthorityInfo(String app, String streamId); + + /** + * 获取推流的鉴权信息 + * @param app 应用名 + * @param stream 流 + * @return + */ + StreamAuthorityInfo getStreamAuthorityInfo(String app, String stream); + + /** + * 发送redis消息 查询所有推流设备的状态 + */ + void sendStreamPushRequestedMsgForStatus(); } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java b/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java index 4ee90945..543d8c16 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java @@ -26,22 +26,6 @@ public interface IVideoManagerStorage { */ public boolean exists(String deviceId); - /** - * 添加设备通道 - * - * @param deviceId 设备id - * @param channel 通道 - */ - public void updateChannel(String deviceId, DeviceChannel channel); - - /** - * 批量添加设备通道 - * - * @param deviceId 设备id - * @param channels 多个通道 - */ - public int updateChannels(String deviceId, List channels); - /** * 开始播放 * @param deviceId 设备id @@ -224,13 +208,6 @@ public interface IVideoManagerStorage { List queryChannelListInParentPlatform(String platformId); - /** - * 更新上级平台的通道信息 - * @param platformId - * @param channelReduces - * @return - */ - int updateChannelForGB(String platformId, List channelReduces, String catalogId); /** * 移除上级平台的通道信息 @@ -276,20 +253,6 @@ public interface IVideoManagerStorage { */ public int clearMobilePositionsByDeviceId(String deviceId); - /** - * 新增代理流 - * @param streamProxyDto - * @return - */ - public boolean addStreamProxy(StreamProxyItem streamProxyDto); - - /** - * 更新代理流 - * @param streamProxyDto - * @return - */ - public boolean updateStreamProxy(StreamProxyItem streamProxyDto); - /** * 移除代理流 * @param app @@ -334,7 +297,7 @@ public interface IVideoManagerStorage { * @param platformId * @return */ - List queryGbStreamListInPlatform(String platformId); + List queryGbStreamListInPlatform(String platformId); /** * 批量更新推流列表 @@ -372,14 +335,16 @@ public interface IVideoManagerStorage { /** * 设置流离线 - * @param app - * @param streamId */ - int mediaOutline(String app, String streamId); + int mediaOffline(String app, String streamId); + + /** + * 设置流上线 + */ + int mediaOnline(String app, String streamId); /** * 设置平台在线/离线 - * @param online */ void updateParentPlatformStatus(String platformGbID, boolean online); @@ -443,7 +408,7 @@ public interface IVideoManagerStorage { int setDefaultCatalog(String platformId, String catalogId); - List queryCatalogInPlatform(String serverGBId); + List queryCatalogInPlatform(String serverGBId); int delRelation(PlatformCatalog platformCatalog); @@ -464,4 +429,8 @@ public interface IVideoManagerStorage { List getChannelSource(String platformId, String gbId); void updateChannelPosition(DeviceChannel deviceChannel); + + void cleanContentForPlatform(String serverGBId); + + List queryChannelWithCatalog(String serverGBId); } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java index ffa5cf15..653e39da 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java @@ -329,5 +329,13 @@ public interface DeviceChannelMapper { @Select("select * from device_channel where deviceId=#{deviceId} and SUBSTRING(channelId, 11, 3)=#{typeCode}") List getBusinessGroups(String deviceId, String typeCode); - + @Select("select dc.id, dc.channelId, dc.deviceId, dc.name, dc.manufacture,dc.model,dc.owner, pc.civilCode,dc.block, " + + " dc.address, '0' as parental,'0' as channelType, pc.id as parentId, dc.safetyWay, dc.registerWay,dc.certNum, dc.certifiable, " + + " dc.errCode,dc.endTime, dc.secrecy, dc.ipAddress, dc.port, dc.PTZType, dc.password, dc.status, " + + " dc.longitudeWgs84 as longitude, dc.latitudeWgs84 as latitude, pc.businessGroupId " + + " from device_channel dc" + + " left join platform_gb_channel pgc on dc.id = pgc.deviceChannelId" + + " left join platform_catalog pc on pgc.catalogId = pc.id and pgc.platformId = pc.platformId" + + " where pgc.platformId=#{serverGBId}") + List queryChannelWithCatalog(String serverGBId); } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/GbStreamMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/GbStreamMapper.java index fa8381c1..73fff576 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/GbStreamMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/GbStreamMapper.java @@ -1,5 +1,6 @@ package com.genersoft.iot.vmp.storager.dao; +import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; import com.genersoft.iot.vmp.gb28181.bean.GbStream; import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; @@ -15,10 +16,10 @@ import java.util.List; public interface GbStreamMapper { @Insert("REPLACE INTO gb_stream (app, stream, gbId, name, " + - "longitude, latitude, streamType, mediaServerId, status, createTime) VALUES" + + "longitude, latitude, streamType, mediaServerId, createTime) VALUES" + "('${app}', '${stream}', '${gbId}', '${name}', " + "'${longitude}', '${latitude}', '${streamType}', " + - "'${mediaServerId}', ${status}, '${createTime}')") + "'${mediaServerId}', '${createTime}')") @Options(useGeneratedKeys = true, keyProperty = "gbStreamId", keyColumn = "gbStreamId") int add(GbStream gbStream); @@ -30,8 +31,7 @@ public interface GbStreamMapper { "streamType=#{streamType}," + "longitude=#{longitude}, " + "latitude=#{latitude}," + - "mediaServerId=#{mediaServerId}," + - "status=${status} " + + "mediaServerId=#{mediaServerId}" + "WHERE app=#{app} AND stream=#{stream}") int updateByAppAndStream(GbStream gbStream); @@ -43,8 +43,7 @@ public interface GbStreamMapper { "streamType=#{streamType}," + "longitude=#{longitude}, " + "latitude=#{latitude}," + - "mediaServerId=#{mediaServerId}," + - "status=${status} " + + "mediaServerId=#{mediaServerId}" + "WHERE gbStreamId=#{gbStreamId}") int update(GbStream gbStream); @@ -60,15 +59,13 @@ public interface GbStreamMapper { " AND gs.gbStreamId not in" + "(select pgs.gbStreamId from platform_gb_stream pgs where pgs.platformId = #{platformId}) " + " AND (gs.app LIKE '%${query}%' OR gs.stream LIKE '%${query}%' OR gs.gbId LIKE '%${query}%' OR gs.name LIKE '%${query}%') " + - " AND gs.status=1" + - " AND gs.status=0" + " AND gs.mediaServerId=#{mediaServerId} " + " order by gs.gbStreamId asc " + "") - List selectAll(String platformId, String catalogId, String query, Boolean pushing, String mediaServerId); + List selectAll(String platformId, String catalogId, String query, String mediaServerId); @Select("SELECT * FROM gb_stream WHERE app=#{app} AND stream=#{stream}") - StreamProxyItem selectOne(String app, String stream); + GbStream selectOne(String app, String stream); @Select("SELECT * FROM gb_stream WHERE gbId=#{gbId}") List selectByGBId(String gbId); @@ -78,26 +75,24 @@ public interface GbStreamMapper { "WHERE gs.gbId = '${gbId}' AND pgs.platformId = '${platformId}'") GbStream queryStreamInPlatform(String platformId, String gbId); - @Select("SELECT gs.*, pgs.platformId as platformId, pgs.catalogId as catalogId FROM gb_stream gs " + - "LEFT JOIN platform_gb_stream pgs ON gs.gbStreamId = pgs.gbStreamId " + - "WHERE pgs.platformId = #{platformId}") - List queryGbStreamListInPlatform(String platformId); + @Select("select gt.gbId as channelId, gt.name, 'wvp-pro' as manufacture, st.status, gt.longitude, gt.latitude, pc.id as parentId," + + " '1' as registerWay, pc.civilCode, 'live' as model, 'wvp-pro' as owner, '0' as parental,'0' as secrecy" + + " from gb_stream gt " + + " left join (" + + " select sp.status, sp.app, sp.stream from stream_push sp" + + " union all" + + " select spxy.status, spxy.app, spxy.stream from stream_proxy spxy" + + " ) st on st.app = gt.app and st.stream = gt.stream" + + " left join platform_gb_stream pgs on gt.gbStreamId = pgs.gbStreamId" + + " left join platform_catalog pc on pgs.catalogId = pc.id and pgs.platformId = pc.platformId" + + " where pgs.platformId=#{platformId}") + List queryGbStreamListInPlatform(String platformId); @Select("SELECT gs.* FROM gb_stream gs LEFT JOIN platform_gb_stream pgs " + "ON gs.gbStreamId = pgs.gbStreamId WHERE pgs.gbStreamId is NULL") List queryStreamNotInPlatform(); - @Update("UPDATE gb_stream " + - "SET status=${status} " + - "WHERE app=#{app} AND stream=#{stream}") - int setStatus(String app, String stream, boolean status); - - @Update("UPDATE gb_stream " + - "SET status=${status} " + - "WHERE mediaServerId=#{mediaServerId} ") - void updateStatusByMediaServerId(String mediaServerId, boolean status); - @Delete("DELETE FROM gb_stream WHERE streamType=#{type} AND gbId=NULL AND mediaServerId=#{mediaServerId}") void deleteWithoutGBId(String type, String mediaServerId); @@ -120,12 +115,12 @@ public interface GbStreamMapper { @Insert("") @Options(useGeneratedKeys = true, keyProperty = "gbStreamId", keyColumn = "gbStreamId") diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/ParentPlatformMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/ParentPlatformMapper.java index b57e103c..554354a8 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/ParentPlatformMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/ParentPlatformMapper.java @@ -16,10 +16,10 @@ public interface ParentPlatformMapper { @Insert("INSERT INTO parent_platform (enable, name, serverGBId, serverGBDomain, serverIP, serverPort, deviceGBId, deviceIp, " + " devicePort, username, password, expires, keepTimeout, transport, characterSet, ptz, rtcp, " + - " status, shareAllLiveStream, startOfflinePush, catalogId, administrativeDivision, catalogGroup, createTime, updateTime) " + + " status, startOfflinePush, catalogId, administrativeDivision, catalogGroup, createTime, updateTime, treeType) " + " VALUES (${enable}, '${name}', '${serverGBId}', '${serverGBDomain}', '${serverIP}', ${serverPort}, '${deviceGBId}', '${deviceIp}', " + " '${devicePort}', '${username}', '${password}', '${expires}', '${keepTimeout}', '${transport}', '${characterSet}', ${ptz}, ${rtcp}, " + - " ${status}, ${shareAllLiveStream}, ${startOfflinePush}, #{catalogId}, #{administrativeDivision}, #{catalogGroup}, #{createTime}, #{updateTime})") + " ${status}, ${startOfflinePush}, #{catalogId}, #{administrativeDivision}, #{catalogGroup}, #{createTime}, #{updateTime}, #{treeType})") int addParentPlatform(ParentPlatform parentPlatform); @Update("UPDATE parent_platform " + @@ -41,12 +41,12 @@ public interface ParentPlatformMapper { "ptz=#{ptz}, " + "rtcp=#{rtcp}, " + "status=#{status}, " + - "shareAllLiveStream=#{shareAllLiveStream}, " + "startOfflinePush=${startOfflinePush}, " + "catalogGroup=#{catalogGroup}, " + "administrativeDivision=#{administrativeDivision}, " + "createTime=#{createTime}, " + "updateTime=#{updateTime}, " + + "treeType=#{treeType}, " + "catalogId=#{catalogId} " + "WHERE id=#{id}") int updateParentPlatform(ParentPlatform parentPlatform); @@ -83,9 +83,6 @@ public interface ParentPlatformMapper { @Update("UPDATE parent_platform SET status=#{online} WHERE serverGBId=#{platformGbID}" ) int updateParentPlatformStatus(String platformGbID, boolean online); - @Select("SELECT * FROM parent_platform WHERE shareAllLiveStream=true") - List selectAllAhareAllLiveStream(); - @Update(value = {" "}) int update(StreamPushItem streamPushItem); @Delete("DELETE FROM stream_push WHERE app=#{app} AND stream=#{stream}") @@ -62,7 +66,7 @@ public interface StreamPushMapper { @Select(value = {" "}) List selectAllForList(String query, Boolean pushing, String mediaServerId); - @Select("SELECT st.*, gs.gbId, gs.status, gs.name, gs.longitude, gs.latitude FROM stream_push st LEFT JOIN gb_stream gs on st.app = gs.app AND st.stream = gs.stream order by st.createStamp desc") + @Select("SELECT st.*, gs.gbId, gs.name, gs.longitude, gs.latitude FROM stream_push st LEFT JOIN gb_stream gs on st.app = gs.app AND st.stream = gs.stream order by st.createTime desc") List selectAll(); - @Select("SELECT st.*, gs.gbId, gs.status, gs.name, gs.longitude, gs.latitude FROM stream_push st LEFT JOIN gb_stream gs on st.app = gs.app AND st.stream = gs.stream WHERE st.app=#{app} AND st.stream=#{stream}") + @Select("SELECT st.*, gs.gbId, gs.name, gs.longitude, gs.latitude FROM stream_push st LEFT JOIN gb_stream gs on st.app = gs.app AND st.stream = gs.stream WHERE st.app=#{app} AND st.stream=#{stream}") StreamPushItem selectOne(String app, String stream); @Insert("") @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") @@ -106,4 +111,59 @@ public interface StreamPushMapper { @Select("SELECT sp.* FROM stream_push sp left join gb_stream gs on gs.app = sp.app and gs.stream= sp.stream WHERE sp.mediaServerId=#{mediaServerId} and gs.gbId is null") List selectAllByMediaServerIdWithOutGbID(String mediaServerId); + @Update("UPDATE stream_push " + + "SET status=${status} " + + "WHERE app=#{app} AND stream=#{stream}") + int updateStatus(String app, String stream, boolean status); + + @Update("UPDATE stream_push " + + "SET pushIng=${pushIng} " + + "WHERE app=#{app} AND stream=#{stream}") + int updatePushStatus(String app, String stream, boolean status); + + @Update("UPDATE stream_push " + + "SET status=#{status} " + + "WHERE mediaServerId=#{mediaServerId}") + void updateStatusByMediaServerId(String mediaServerId, boolean status); + + + @Select("") + List getOnlinePusherForGbInList(List offlineStreams); + + @Update("") + void offline(List offlineStreams); + + @Select("") + List getOfflinePusherForGbInList(List onlineStreams); + + @Update("") + void online(List onlineStreams); + + @Select("SELECT gs.* FROM stream_push sp left join gb_stream gs on sp.app = gs.app AND sp.stream = gs.stream where sp.status = 1") + List getOnlinePusherForGb(); + + @Update("UPDATE stream_push SET status=0") + void setAllStreamOffline(); } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java index addb27d0..c7a44fd2 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java @@ -10,13 +10,14 @@ import java.util.List; @Repository public interface UserMapper { - @Insert("INSERT INTO user (username, password, roleId, createTime, updateTime) VALUES" + - "('${username}', '${password}', '${role.id}', '${createTime}', '${updateTime}')") + @Insert("INSERT INTO user (username, password, roleId, pushKey, createTime, updateTime) VALUES" + + "('${username}', '${password}', '${role.id}', '${pushKey}', '${createTime}', '${updateTime}')") int add(User user); @Update(value = {" + diff --git a/web_src/src/components/dialog/addUser.vue b/web_src/src/components/dialog/addUser.vue new file mode 100644 index 00000000..403ecebe --- /dev/null +++ b/web_src/src/components/dialog/addUser.vue @@ -0,0 +1,159 @@ + + + diff --git a/web_src/src/components/dialog/catalogEdit.vue b/web_src/src/components/dialog/catalogEdit.vue index 13cabfb5..22ff1816 100644 --- a/web_src/src/components/dialog/catalogEdit.vue +++ b/web_src/src/components/dialog/catalogEdit.vue @@ -49,11 +49,43 @@ export default { props: ['platformId'], created() {}, data() { + let checkId = (rule, value, callback) => { + console.log("checkId") + console.log(this.treeType) + console.log(rule) + console.log(value) + console.log(value.length) + console.log(this.level) + if (!value) { + return callback(new Error('编号不能为空')); + } + if (this.treeType === "BusinessGroup" && value.length !== 20) { + return callback(new Error('编号必须由20位数字组成')); + } + if (this.treeType === "CivilCode" && value.length <= 8 && value.length%2 !== 0) { + return callback(new Error('行政区划必须是八位以下的偶数个数字组成')); + } + if (this.treeType === "BusinessGroup") { + let catalogType = value.substring(10, 13); + console.log(catalogType) + // 216 为虚拟组织 215 为业务分组;目录第一级必须为业务分组, 业务分组下为虚拟组织,虚拟组织下可以有其他虚拟组织 + if (this.level === 1 && catalogType !== "215") { + return callback(new Error('业务分组模式下第一层目录的编号10到13位必须为215')); + } + if (this.level > 1 && catalogType !== "216") { + return callback(new Error('业务分组模式下第一层以下目录的编号10到13位必须为216')); + } + + } + callback(); + } return { submitCallback: null, showDialog: false, isLoging: false, isEdit: false, + treeType: null, + level: 0, form: { id: null, name: null, @@ -62,12 +94,12 @@ export default { }, rules: { name: [{ required: true, message: "请输入名称", trigger: "blur" }], - id: [{ required: true, message: "请输入ID", trigger: "blur" }] + id: [{ trigger: "blur",validator: checkId }] }, }; }, methods: { - openDialog: function (isEdit, id, name, parentId, callback) { + openDialog: function (isEdit, id, name, parentId, treeType, level, callback) { console.log("parentId: " + parentId) console.log(this.form) this.isEdit = isEdit; @@ -77,6 +109,8 @@ export default { this.form.parentId = parentId; this.showDialog = true; this.submitCallback = callback; + this.treeType = treeType; + this.level = level; }, onSubmit: function () { console.log("onSubmit"); diff --git a/web_src/src/components/dialog/changePasswordForAdmin.vue b/web_src/src/components/dialog/changePasswordForAdmin.vue new file mode 100644 index 00000000..0e0ae229 --- /dev/null +++ b/web_src/src/components/dialog/changePasswordForAdmin.vue @@ -0,0 +1,121 @@ + + + diff --git a/web_src/src/components/dialog/changePushKey.vue b/web_src/src/components/dialog/changePushKey.vue new file mode 100644 index 00000000..9f184756 --- /dev/null +++ b/web_src/src/components/dialog/changePushKey.vue @@ -0,0 +1,102 @@ + + + diff --git a/web_src/src/components/dialog/chooseChannel.vue b/web_src/src/components/dialog/chooseChannel.vue index 599921ec..cd8132a4 100644 --- a/web_src/src/components/dialog/chooseChannel.vue +++ b/web_src/src/components/dialog/chooseChannel.vue @@ -8,7 +8,7 @@ - + @@ -66,18 +66,20 @@ export default { platformName: "", defaultCatalogId: "", showDialog: false, + treeType: null, chooseData: {}, winHeight: window.innerHeight - 250, }; }, methods: { - openDialog(platformId, platformName, defaultCatalogId, closeCallback) { + openDialog(platformId, platformName, defaultCatalogId, treeType, closeCallback) { this.platformId = platformId this.platformName = platformName this.defaultCatalogId = defaultCatalogId this.showDialog = true this.closeCallback = closeCallback + this.treeType = treeType }, tabClick (tab, event){ diff --git a/web_src/src/components/dialog/chooseChannelForCatalog.vue b/web_src/src/components/dialog/chooseChannelForCatalog.vue index a0cb98c8..86fb48d9 100644 --- a/web_src/src/components/dialog/chooseChannelForCatalog.vue +++ b/web_src/src/components/dialog/chooseChannelForCatalog.vue @@ -38,7 +38,7 @@ import catalogEdit from './catalogEdit.vue' export default { name: 'chooseChannelForCatalog', - props: ['platformId', 'platformName', 'defaultCatalogId', 'catalogIdChange'], + props: ['platformId', 'platformName', 'defaultCatalogId', 'catalogIdChange', 'treeType'], created() { this.chooseId = this.defaultCatalogId; this.defaultCatalogIdSign = this.defaultCatalogId; @@ -102,8 +102,9 @@ export default { }, addCatalog: function (parentId, node){ let that = this; + console.log(this.treeType) // 打开添加弹窗 - that.$refs.catalogEdit.openDialog(false, null, null, parentId, ()=>{ + that.$refs.catalogEdit.openDialog(false, null, null, parentId, this.treeType, node.level, ()=>{ node.loaded = false node.expand(); }); diff --git a/web_src/src/components/dialog/chooseChannelForStream.vue b/web_src/src/components/dialog/chooseChannelForStream.vue index d5e5ac38..1eec0b25 100644 --- a/web_src/src/components/dialog/chooseChannelForStream.vue +++ b/web_src/src/components/dialog/chooseChannelForStream.vue @@ -174,7 +174,6 @@ export default { page: that.currentPage, count: that.count, query: that.searchSrt, - pushing: that.pushing, platformId: that.platformId, catalogId: that.catalogId, mediaServerId: that.mediaServerId diff --git a/web_src/src/components/dialog/platformEdit.vue b/web_src/src/components/dialog/platformEdit.vue index 0caec322..819c002e 100644 --- a/web_src/src/components/dialog/platformEdit.vue +++ b/web_src/src/components/dialog/platformEdit.vue @@ -78,6 +78,12 @@ + + + + + + - @@ -153,10 +158,10 @@ export default { keepTimeout: 60, transport: "UDP", characterSet: "GB2312", - shareAllLiveStream: false, startOfflinePush: false, catalogGroup: 1, administrativeDivision: null, + treeType: "BusinessGroup", }, rules: { name: [{ required: true, message: "请输入平台名称", trigger: "blur" }], @@ -194,6 +199,7 @@ export default { that.platform.devicePort = res.data.devicePort; that.platform.username = res.data.username; that.platform.password = res.data.password; + that.platform.treeType = "BusinessGroup"; that.platform.administrativeDivision = res.data.username.substr(0, 6); }).catch(function (error) { console.log(error); @@ -217,11 +223,11 @@ export default { this.platform.keepTimeout = platform.keepTimeout; this.platform.transport = platform.transport; this.platform.characterSet = platform.characterSet; - this.platform.shareAllLiveStream = platform.shareAllLiveStream; this.platform.catalogId = platform.catalogId; this.platform.startOfflinePush = platform.startOfflinePush; this.platform.catalogGroup = platform.catalogGroup; this.platform.administrativeDivision = platform.administrativeDivision; + this.platform.treeType = platform.treeType; this.onSubmit_text = "保存"; this.saveUrl = "/api/platform/save"; } @@ -242,32 +248,49 @@ export default { }, onSubmit: function () { + if (this.onSubmit_text === "保存") { + this.$confirm("修改目录结构会导致关联目录与通道数据被清空", '提示', { + dangerouslyUseHTMLString: true, + confirmButtonText: '确定', + cancelButtonText: '取消', + center: true, + type: 'warning' + }).then(() => { + this.saveForm() + }).catch(() => { + + }); + }else { + this.saveForm() + } + }, + saveForm: function (){ var that = this; that.$axios({ method: 'post', url: this.saveUrl, data: that.platform }).then(function (res) { - if (res.data.code === 0) { - that.$message({ - showClose: true, - message: "保存成功", - type: "success", - }); - that.showDialog = false; - if (that.listChangeCallback != null) { - that.listChangeCallback(); - } - }else { - that.$message({ - showClose: true, - message: res.data.msg, - type: "error", - }); + if (res.data.code === 0) { + that.$message({ + showClose: true, + message: "保存成功", + type: "success", + }); + that.showDialog = false; + if (that.listChangeCallback != null) { + that.listChangeCallback(); } - }).catch(function (error) { - console.log(error); - }); + }else { + that.$message({ + showClose: true, + message: res.data.msg, + type: "error", + }); + } + }).catch(function (error) { + console.log(error); + }); }, close: function () { this.showDialog = false; @@ -293,7 +316,7 @@ export default { keepTimeout: 60, transport: "UDP", characterSet: "GB2312", - shareAllLiveStream: false, + treeType: "BusinessGroup", startOfflinePush: false, catalogGroup: 1, } diff --git a/web_src/src/layout/UiHeader.vue b/web_src/src/layout/UiHeader.vue index 8e104bd9..42d617e9 100644 --- a/web_src/src/layout/UiHeader.vue +++ b/web_src/src/layout/UiHeader.vue @@ -13,6 +13,7 @@ 云端录像 节点管理 国标级联 + 用户管理 @@ -23,12 +24,12 @@ - 修改密码 - 注销 在线文档 + 修改密码 + 注销 @@ -47,9 +48,11 @@ export default { alarmNotify: false, sseSource: null, activeIndex: this.$route.path, + editUser: this.$cookies.get("session").roleId==1 }; }, created() { + console.log(this.$cookies.get("session")) if (this.$route.path.startsWith("/channelList")) { this.activeIndex = "/deviceList" } diff --git a/web_src/src/router/index.js b/web_src/src/router/index.js index 2c9c6f37..7651a725 100644 --- a/web_src/src/router/index.js +++ b/web_src/src/router/index.js @@ -17,6 +17,7 @@ import sip from '../components/setting/Sip.vue' import media from '../components/setting/Media.vue' import live from '../components/live.vue' import deviceTree from '../components/common/DeviceTree.vue' +import userManager from '../components/UserManager.vue' import wasmPlayer from '../components/common/jessibuca.vue' import rtcPlayer from '../components/dialog/rtcPlayer.vue' @@ -103,6 +104,11 @@ export default new VueRouter({ name: 'map', component: map, }, + { + path: '/userManager', + name: 'userManager', + component: userManager, + } ] }, { diff --git a/web_src/static/file/推流通道导入.zip b/web_src/static/file/推流通道导入.zip index c5ab3ab7..fb95c613 100644 Binary files a/web_src/static/file/推流通道导入.zip and b/web_src/static/file/推流通道导入.zip differ