Commit 8d87741dea3d174f098269073429a0f6b982baa1

Authored by mrjackwang
Committed by GitHub
2 parents 5e724cc0 a51b4111

Merge branch '648540858:wvp-28181-2.0' into wvp-28181-2.0

Showing 70 changed files with 1975 additions and 847 deletions

Too many changes to show.

To preserve performance only 70 of 95 files are displayed.

sql/mysql.sql
@@ -50,7 +50,7 @@ CREATE TABLE `device` ( @@ -50,7 +50,7 @@ CREATE TABLE `device` (
50 `treeType` varchar(50) COLLATE utf8mb4_general_ci NOT NULL, 50 `treeType` varchar(50) COLLATE utf8mb4_general_ci NOT NULL,
51 PRIMARY KEY (`id`) USING BTREE, 51 PRIMARY KEY (`id`) USING BTREE,
52 UNIQUE KEY `device_deviceId_uindex` (`deviceId`) USING BTREE 52 UNIQUE KEY `device_deviceId_uindex` (`deviceId`) USING BTREE
53 -) ENGINE=InnoDB AUTO_INCREMENT=37 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; 53 +) ENGINE=InnoDB AUTO_INCREMENT=45 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;
54 /*!40101 SET character_set_client = @saved_cs_client */; 54 /*!40101 SET character_set_client = @saved_cs_client */;
55 55
56 -- 56 --
@@ -142,7 +142,7 @@ CREATE TABLE `device_channel` ( @@ -142,7 +142,7 @@ CREATE TABLE `device_channel` (
142 PRIMARY KEY (`id`) USING BTREE, 142 PRIMARY KEY (`id`) USING BTREE,
143 UNIQUE KEY `device_channel_id_uindex` (`id`) USING BTREE, 143 UNIQUE KEY `device_channel_id_uindex` (`id`) USING BTREE,
144 UNIQUE KEY `device_channel_pk` (`channelId`,`deviceId`) USING BTREE 144 UNIQUE KEY `device_channel_pk` (`channelId`,`deviceId`) USING BTREE
145 -) ENGINE=InnoDB AUTO_INCREMENT=19324 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; 145 +) ENGINE=InnoDB AUTO_INCREMENT=19336 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;
146 /*!40101 SET character_set_client = @saved_cs_client */; 146 /*!40101 SET character_set_client = @saved_cs_client */;
147 147
148 -- 148 --
@@ -179,7 +179,7 @@ CREATE TABLE `device_mobile_position` ( @@ -179,7 +179,7 @@ CREATE TABLE `device_mobile_position` (
179 `latitudeWgs84` double DEFAULT NULL, 179 `latitudeWgs84` double DEFAULT NULL,
180 `createTime` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL, 180 `createTime` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
181 PRIMARY KEY (`id`) USING BTREE 181 PRIMARY KEY (`id`) USING BTREE
182 -) ENGINE=InnoDB AUTO_INCREMENT=5649 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; 182 +) ENGINE=InnoDB AUTO_INCREMENT=6751 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;
183 /*!40101 SET character_set_client = @saved_cs_client */; 183 /*!40101 SET character_set_client = @saved_cs_client */;
184 184
185 -- 185 --
@@ -208,13 +208,12 @@ CREATE TABLE `gb_stream` ( @@ -208,13 +208,12 @@ CREATE TABLE `gb_stream` (
208 `latitude` double DEFAULT NULL, 208 `latitude` double DEFAULT NULL,
209 `streamType` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL, 209 `streamType` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
210 `mediaServerId` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL, 210 `mediaServerId` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
211 - `status` int DEFAULT NULL,  
212 `createTime` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL, 211 `createTime` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
213 `gpsTime` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL, 212 `gpsTime` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
214 PRIMARY KEY (`gbStreamId`) USING BTREE, 213 PRIMARY KEY (`gbStreamId`) USING BTREE,
215 UNIQUE KEY `app` (`app`,`stream`) USING BTREE, 214 UNIQUE KEY `app` (`app`,`stream`) USING BTREE,
216 UNIQUE KEY `gbId` (`gbId`) USING BTREE 215 UNIQUE KEY `gbId` (`gbId`) USING BTREE
217 -) ENGINE=InnoDB AUTO_INCREMENT=301681 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; 216 +) ENGINE=InnoDB AUTO_INCREMENT=301740 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;
218 /*!40101 SET character_set_client = @saved_cs_client */; 217 /*!40101 SET character_set_client = @saved_cs_client */;
219 218
220 -- 219 --
@@ -244,7 +243,7 @@ CREATE TABLE `log` ( @@ -244,7 +243,7 @@ CREATE TABLE `log` (
244 `username` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, 243 `username` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
245 `createTime` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, 244 `createTime` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
246 PRIMARY KEY (`id`) USING BTREE 245 PRIMARY KEY (`id`) USING BTREE
247 -) ENGINE=InnoDB AUTO_INCREMENT=29943 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; 246 +) ENGINE=InnoDB AUTO_INCREMENT=37760 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;
248 /*!40101 SET character_set_client = @saved_cs_client */; 247 /*!40101 SET character_set_client = @saved_cs_client */;
249 248
250 -- 249 --
@@ -329,16 +328,16 @@ CREATE TABLE `parent_platform` ( @@ -329,16 +328,16 @@ CREATE TABLE `parent_platform` (
329 `ptz` int DEFAULT NULL, 328 `ptz` int DEFAULT NULL,
330 `rtcp` int DEFAULT NULL, 329 `rtcp` int DEFAULT NULL,
331 `status` bit(1) DEFAULT NULL, 330 `status` bit(1) DEFAULT NULL,
332 - `shareAllLiveStream` int DEFAULT NULL,  
333 `startOfflinePush` int DEFAULT '0', 331 `startOfflinePush` int DEFAULT '0',
334 `administrativeDivision` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, 332 `administrativeDivision` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
335 `catalogGroup` int DEFAULT '1', 333 `catalogGroup` int DEFAULT '1',
336 `createTime` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL, 334 `createTime` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
337 `updateTime` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL, 335 `updateTime` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  336 + `treeType` varchar(50) COLLATE utf8mb4_general_ci NOT NULL,
338 PRIMARY KEY (`id`) USING BTREE, 337 PRIMARY KEY (`id`) USING BTREE,
339 UNIQUE KEY `parent_platform_id_uindex` (`id`) USING BTREE, 338 UNIQUE KEY `parent_platform_id_uindex` (`id`) USING BTREE,
340 UNIQUE KEY `parent_platform_pk` (`serverGBId`) USING BTREE 339 UNIQUE KEY `parent_platform_pk` (`serverGBId`) USING BTREE
341 -) ENGINE=InnoDB AUTO_INCREMENT=33 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; 340 +) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;
342 /*!40101 SET character_set_client = @saved_cs_client */; 341 /*!40101 SET character_set_client = @saved_cs_client */;
343 342
344 -- 343 --
@@ -362,6 +361,8 @@ CREATE TABLE `platform_catalog` ( @@ -362,6 +361,8 @@ CREATE TABLE `platform_catalog` (
362 `platformId` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, 361 `platformId` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
363 `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, 362 `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
364 `parentId` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL, 363 `parentId` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
  364 + `civilCode` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  365 + `businessGroupId` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
365 PRIMARY KEY (`id`) USING BTREE 366 PRIMARY KEY (`id`) USING BTREE
366 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; 367 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;
367 /*!40101 SET character_set_client = @saved_cs_client */; 368 /*!40101 SET character_set_client = @saved_cs_client */;
@@ -388,7 +389,7 @@ CREATE TABLE `platform_gb_channel` ( @@ -388,7 +389,7 @@ CREATE TABLE `platform_gb_channel` (
388 `catalogId` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, 389 `catalogId` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
389 `deviceChannelId` int NOT NULL, 390 `deviceChannelId` int NOT NULL,
390 PRIMARY KEY (`id`) USING BTREE 391 PRIMARY KEY (`id`) USING BTREE
391 -) ENGINE=InnoDB AUTO_INCREMENT=4889 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; 392 +) ENGINE=InnoDB AUTO_INCREMENT=4912 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;
392 /*!40101 SET character_set_client = @saved_cs_client */; 393 /*!40101 SET character_set_client = @saved_cs_client */;
393 394
394 -- 395 --
@@ -414,7 +415,7 @@ CREATE TABLE `platform_gb_stream` ( @@ -414,7 +415,7 @@ CREATE TABLE `platform_gb_stream` (
414 `id` int NOT NULL AUTO_INCREMENT, 415 `id` int NOT NULL AUTO_INCREMENT,
415 PRIMARY KEY (`id`) USING BTREE, 416 PRIMARY KEY (`id`) USING BTREE,
416 UNIQUE KEY `platform_gb_stream_pk` (`platformId`,`catalogId`,`gbStreamId`) USING BTREE 417 UNIQUE KEY `platform_gb_stream_pk` (`platformId`,`catalogId`,`gbStreamId`) USING BTREE
417 -) ENGINE=InnoDB AUTO_INCREMENT=302077 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; 418 +) ENGINE=InnoDB AUTO_INCREMENT=302134 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;
418 /*!40101 SET character_set_client = @saved_cs_client */; 419 /*!40101 SET character_set_client = @saved_cs_client */;
419 420
420 -- 421 --
@@ -455,7 +456,7 @@ CREATE TABLE `stream_proxy` ( @@ -455,7 +456,7 @@ CREATE TABLE `stream_proxy` (
455 `updateTime` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL, 456 `updateTime` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
456 PRIMARY KEY (`id`) USING BTREE, 457 PRIMARY KEY (`id`) USING BTREE,
457 UNIQUE KEY `stream_proxy_pk` (`app`,`stream`) USING BTREE 458 UNIQUE KEY `stream_proxy_pk` (`app`,`stream`) USING BTREE
458 -) ENGINE=InnoDB AUTO_INCREMENT=65 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; 459 +) ENGINE=InnoDB AUTO_INCREMENT=66 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;
459 /*!40101 SET character_set_client = @saved_cs_client */; 460 /*!40101 SET character_set_client = @saved_cs_client */;
460 461
461 -- 462 --
@@ -487,9 +488,10 @@ CREATE TABLE `stream_push` ( @@ -487,9 +488,10 @@ CREATE TABLE `stream_push` (
487 `serverId` varchar(50) COLLATE utf8mb4_general_ci NOT NULL, 488 `serverId` varchar(50) COLLATE utf8mb4_general_ci NOT NULL,
488 `pushTime` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL, 489 `pushTime` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
489 `updateTime` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL, 490 `updateTime` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
  491 + `status` int DEFAULT NULL,
490 PRIMARY KEY (`id`) USING BTREE, 492 PRIMARY KEY (`id`) USING BTREE,
491 UNIQUE KEY `stream_push_pk` (`app`,`stream`) USING BTREE 493 UNIQUE KEY `stream_push_pk` (`app`,`stream`) USING BTREE
492 -) ENGINE=InnoDB AUTO_INCREMENT=305304 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; 494 +) ENGINE=InnoDB AUTO_INCREMENT=305390 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;
493 /*!40101 SET character_set_client = @saved_cs_client */; 495 /*!40101 SET character_set_client = @saved_cs_client */;
494 496
495 -- 497 --
@@ -515,6 +517,7 @@ CREATE TABLE `user` ( @@ -515,6 +517,7 @@ CREATE TABLE `user` (
515 `roleId` int NOT NULL, 517 `roleId` int NOT NULL,
516 `createTime` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, 518 `createTime` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
517 `updateTime` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, 519 `updateTime` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
  520 + `pushKey` varchar(50) COLLATE utf8mb4_general_ci DEFAULT NULL,
518 PRIMARY KEY (`id`) USING BTREE, 521 PRIMARY KEY (`id`) USING BTREE,
519 UNIQUE KEY `user_username_uindex` (`username`) USING BTREE 522 UNIQUE KEY `user_username_uindex` (`username`) USING BTREE
520 ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC; 523 ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC;
@@ -526,7 +529,7 @@ CREATE TABLE `user` ( @@ -526,7 +529,7 @@ CREATE TABLE `user` (
526 529
527 LOCK TABLES `user` WRITE; 530 LOCK TABLES `user` WRITE;
528 /*!40000 ALTER TABLE `user` DISABLE KEYS */; 531 /*!40000 ALTER TABLE `user` DISABLE KEYS */;
529 -INSERT INTO `user` VALUES (1,'admin','21232f297a57a5a743894a0e4a801fc3',1,'2021 - 04 - 13 14:14:57','2021 - 04 - 13 14:14:57'); 532 +INSERT INTO `user` VALUES (1,'admin','21232f297a57a5a743894a0e4a801fc3',1,'2021 - 04 - 13 14:14:57','2021 - 04 - 13 14:14:57','453df297a57a5a7438934sda801fc3');
530 /*!40000 ALTER TABLE `user` ENABLE KEYS */; 533 /*!40000 ALTER TABLE `user` ENABLE KEYS */;
531 UNLOCK TABLES; 534 UNLOCK TABLES;
532 535
@@ -566,4 +569,4 @@ UNLOCK TABLES; @@ -566,4 +569,4 @@ UNLOCK TABLES;
566 /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 569 /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
567 /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; 570 /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
568 571
569 --- Dump completed on 2022-07-06 9:43:54 572 +-- Dump completed on 2022-07-17 23:15:09
sql/update.sql
@@ -52,9 +52,30 @@ alter table stream_proxy @@ -52,9 +52,30 @@ alter table stream_proxy
52 alter table stream_push 52 alter table stream_push
53 add pushTime varchar(50) default null; 53 add pushTime varchar(50) default null;
54 alter table stream_push 54 alter table stream_push
  55 + add status int DEFAULT NULL;
  56 +alter table stream_push
55 add updateTime varchar(50) default null; 57 add updateTime varchar(50) default null;
56 alter table stream_push 58 alter table stream_push
  59 + add pushIng int DEFAULT NULL;
  60 +alter table stream_push
57 change createStamp createTime varchar(50) default null; 61 change createStamp createTime varchar(50) default null;
58 62
  63 +alter table gb_stream
  64 + drop column status;
  65 +
  66 +alter table user
  67 + add pushKey varchar(50) default null;
  68 +update user set pushKey='453df297a57a5a7438934sda801fc3' where id=1;
  69 +
  70 +alter table parent_platform
  71 + add treeType varchar(50) not null;
  72 +update parent_platform set parent_platform.treeType='BusinessGroup';
  73 +alter table parent_platform drop shareAllLiveStream;
  74 +
  75 +alter table platform_catalog
  76 + add civilCode varchar(50) default null;
  77 +alter table platform_catalog
  78 + add businessGroupId varchar(50) default null;
  79 +
59 80
60 81
src/main/java/com/genersoft/iot/vmp/VManageBootstrap.java
@@ -11,7 +11,7 @@ import org.springframework.scheduling.annotation.EnableScheduling; @@ -11,7 +11,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
11 import springfox.documentation.oas.annotations.EnableOpenApi; 11 import springfox.documentation.oas.annotations.EnableOpenApi;
12 12
13 /** 13 /**
14 - * 14 + * 启动类
15 */ 15 */
16 @ServletComponentScan("com.genersoft.iot.vmp.conf") 16 @ServletComponentScan("com.genersoft.iot.vmp.conf")
17 @SpringBootApplication 17 @SpringBootApplication
src/main/java/com/genersoft/iot/vmp/common/StreamInfo.java
@@ -9,6 +9,9 @@ public class StreamInfo { @@ -9,6 +9,9 @@ public class StreamInfo {
9 private String deviceID; 9 private String deviceID;
10 private String channelId; 10 private String channelId;
11 private String flv; 11 private String flv;
  12 +
  13 + private String ip;
  14 +
12 private String https_flv; 15 private String https_flv;
13 private String ws_flv; 16 private String ws_flv;
14 private String wss_flv; 17 private String wss_flv;
@@ -292,4 +295,12 @@ public class StreamInfo { @@ -292,4 +295,12 @@ public class StreamInfo {
292 public void setProgress(double progress) { 295 public void setProgress(double progress) {
293 this.progress = progress; 296 this.progress = progress;
294 } 297 }
  298 +
  299 + public String getIp() {
  300 + return ip;
  301 + }
  302 +
  303 + public void setIp(String ip) {
  304 + this.ip = ip;
  305 + }
295 } 306 }
src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java
@@ -58,6 +58,8 @@ public class VideoManagerConstants { @@ -58,6 +58,8 @@ public class VideoManagerConstants {
58 58
59 public static final String MEDIA_TRANSACTION_USED_PREFIX = "VMP_MEDIA_TRANSACTION_"; 59 public static final String MEDIA_TRANSACTION_USED_PREFIX = "VMP_MEDIA_TRANSACTION_";
60 60
  61 + public static final String MEDIA_STREAM_AUTHORITY = "MEDIA_STREAM_AUTHORITY_";
  62 +
61 public static final String SIP_CSEQ_PREFIX = "VMP_SIP_CSEQ_"; 63 public static final String SIP_CSEQ_PREFIX = "VMP_SIP_CSEQ_";
62 64
63 public static final String SIP_SN_PREFIX = "VMP_SIP_SN_"; 65 public static final String SIP_SN_PREFIX = "VMP_SIP_SN_";
@@ -71,6 +73,8 @@ public class VideoManagerConstants { @@ -71,6 +73,8 @@ public class VideoManagerConstants {
71 public static final String SYSTEM_INFO_NET_PREFIX = "VMP_SYSTEM_INFO_NET_"; 73 public static final String SYSTEM_INFO_NET_PREFIX = "VMP_SYSTEM_INFO_NET_";
72 74
73 75
  76 +
  77 +
74 //************************** redis 消息********************************* 78 //************************** redis 消息*********************************
75 79
76 // 流变化的通知 80 // 流变化的通知
@@ -79,9 +83,15 @@ public class VideoManagerConstants { @@ -79,9 +83,15 @@ public class VideoManagerConstants {
79 // 接收推流设备的GPS变化通知 83 // 接收推流设备的GPS变化通知
80 public static final String VM_MSG_GPS = "VM_MSG_GPS"; 84 public static final String VM_MSG_GPS = "VM_MSG_GPS";
81 85
  86 + // 接收推流设备的GPS变化通知
  87 + public static final String VM_MSG_PUSH_STREAM_STATUS_CHANGE = "VM_MSG_PUSH_STREAM_STATUS_CHANGE";
  88 +
82 // redis 消息通知设备推流到平台 89 // redis 消息通知设备推流到平台
83 public static final String VM_MSG_STREAM_PUSH_REQUESTED = "VM_MSG_STREAM_PUSH_REQUESTED"; 90 public static final String VM_MSG_STREAM_PUSH_REQUESTED = "VM_MSG_STREAM_PUSH_REQUESTED";
84 91
  92 + // redis 消息请求所有的在线通道
  93 + public static final String VM_MSG_GET_ALL_ONLINE_REQUESTED = "VM_MSG_GET_ALL_ONLINE_REQUESTED";
  94 +
85 // 移动位置订阅通知 95 // 移动位置订阅通知
86 public static final String VM_MSG_SUBSCRIBE_MOBILE_POSITION = "mobileposition"; 96 public static final String VM_MSG_SUBSCRIBE_MOBILE_POSITION = "mobileposition";
87 97
@@ -94,6 +104,10 @@ public class VideoManagerConstants { @@ -94,6 +104,10 @@ public class VideoManagerConstants {
94 // 设备状态订阅的通知 104 // 设备状态订阅的通知
95 public static final String VM_MSG_SUBSCRIBE_DEVICE_STATUS = "device"; 105 public static final String VM_MSG_SUBSCRIBE_DEVICE_STATUS = "device";
96 106
  107 +
  108 +
  109 +
  110 +
97 //************************** 第三方 **************************************** 111 //************************** 第三方 ****************************************
98 public static final String WVP_STREAM_GB_ID_PREFIX = "memberNo_"; 112 public static final String WVP_STREAM_GB_ID_PREFIX = "memberNo_";
99 public static final String WVP_STREAM_GPS_MSG_PREFIX = "WVP_STREAM_GPS_MSG_"; 113 public static final String WVP_STREAM_GPS_MSG_PREFIX = "WVP_STREAM_GPS_MSG_";
src/main/java/com/genersoft/iot/vmp/conf/DynamicTask.java
@@ -5,6 +5,7 @@ import org.slf4j.Logger; @@ -5,6 +5,7 @@ import org.slf4j.Logger;
5 import org.slf4j.LoggerFactory; 5 import org.slf4j.LoggerFactory;
6 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.context.annotation.Bean; 7 import org.springframework.context.annotation.Bean;
  8 +import org.springframework.scheduling.annotation.Scheduled;
8 import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; 9 import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
9 import org.springframework.stereotype.Component; 10 import org.springframework.stereotype.Component;
10 11
@@ -103,12 +104,9 @@ public class DynamicTask { @@ -103,12 +104,9 @@ public class DynamicTask {
103 104
104 public void stop(String key) { 105 public void stop(String key) {
105 if (futureMap.get(key) != null && !futureMap.get(key).isCancelled()) { 106 if (futureMap.get(key) != null && !futureMap.get(key).isCancelled()) {
106 -// Runnable runnable = runnableMap.get(key);  
107 -// if (runnable instanceof ISubscribeTask) {  
108 -// ISubscribeTask subscribeTask = (ISubscribeTask) runnable;  
109 -// subscribeTask.stop();  
110 -// }  
111 futureMap.get(key).cancel(false); 107 futureMap.get(key).cancel(false);
  108 + futureMap.remove(key);
  109 + runnableMap.remove(key);
112 } 110 }
113 } 111 }
114 112
@@ -123,4 +121,19 @@ public class DynamicTask { @@ -123,4 +121,19 @@ public class DynamicTask {
123 public Runnable get(String key) { 121 public Runnable get(String key) {
124 return runnableMap.get(key); 122 return runnableMap.get(key);
125 } 123 }
  124 +
  125 + /**
  126 + * 每五分钟检查失效的任务,并移除
  127 + */
  128 + @Scheduled(cron="0 0/5 * * * ?")
  129 + public void execute(){
  130 + if (futureMap.size() > 0) {
  131 + for (String key : futureMap.keySet()) {
  132 + if (futureMap.get(key).isDone()) {
  133 + futureMap.remove(key);
  134 + runnableMap.remove(key);
  135 + }
  136 + }
  137 + }
  138 + }
126 } 139 }
src/main/java/com/genersoft/iot/vmp/conf/RedisConfig.java
1 package com.genersoft.iot.vmp.conf; 1 package com.genersoft.iot.vmp.conf;
2 2
3 import com.genersoft.iot.vmp.common.VideoManagerConstants; 3 import com.genersoft.iot.vmp.common.VideoManagerConstants;
4 -import com.genersoft.iot.vmp.service.impl.RedisAlarmMsgListener;  
5 -import com.genersoft.iot.vmp.service.impl.RedisGpsMsgListener;  
6 -import com.genersoft.iot.vmp.service.impl.RedisGbPlayMsgListener;  
7 -import com.genersoft.iot.vmp.service.impl.RedisStreamMsgListener; 4 +import com.genersoft.iot.vmp.service.impl.*;
8 import org.apache.commons.lang3.StringUtils; 5 import org.apache.commons.lang3.StringUtils;
9 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.beans.factory.annotation.Value; 7 import org.springframework.beans.factory.annotation.Value;
@@ -60,6 +57,9 @@ public class RedisConfig extends CachingConfigurerSupport { @@ -60,6 +57,9 @@ public class RedisConfig extends CachingConfigurerSupport {
60 @Autowired 57 @Autowired
61 private RedisGbPlayMsgListener redisGbPlayMsgListener; 58 private RedisGbPlayMsgListener redisGbPlayMsgListener;
62 59
  60 + @Autowired
  61 + private RedisPushStreamStatusMsgListener redisPushStreamStatusMsgListener;
  62 +
63 @Bean 63 @Bean
64 public JedisPool jedisPool() { 64 public JedisPool jedisPool() {
65 if (StringUtils.isBlank(password)) { 65 if (StringUtils.isBlank(password)) {
@@ -108,6 +108,7 @@ public class RedisConfig extends CachingConfigurerSupport { @@ -108,6 +108,7 @@ public class RedisConfig extends CachingConfigurerSupport {
108 container.addMessageListener(redisAlarmMsgListener, new PatternTopic(VideoManagerConstants.VM_MSG_SUBSCRIBE_ALARM_RECEIVE)); 108 container.addMessageListener(redisAlarmMsgListener, new PatternTopic(VideoManagerConstants.VM_MSG_SUBSCRIBE_ALARM_RECEIVE));
109 container.addMessageListener(redisStreamMsgListener, new PatternTopic(VideoManagerConstants.WVP_MSG_STREAM_CHANGE_PREFIX + "PUSH")); 109 container.addMessageListener(redisStreamMsgListener, new PatternTopic(VideoManagerConstants.WVP_MSG_STREAM_CHANGE_PREFIX + "PUSH"));
110 container.addMessageListener(redisGbPlayMsgListener, new PatternTopic(RedisGbPlayMsgListener.WVP_PUSH_STREAM_KEY)); 110 container.addMessageListener(redisGbPlayMsgListener, new PatternTopic(RedisGbPlayMsgListener.WVP_PUSH_STREAM_KEY));
  111 + container.addMessageListener(redisPushStreamStatusMsgListener, new PatternTopic(VideoManagerConstants.VM_MSG_PUSH_STREAM_STATUS_CHANGE));
111 return container; 112 return container;
112 } 113 }
113 114
src/main/java/com/genersoft/iot/vmp/gb28181/bean/ParentPlatform.java
@@ -105,11 +105,6 @@ public class ParentPlatform { @@ -105,11 +105,6 @@ public class ParentPlatform {
105 private int channelCount; 105 private int channelCount;
106 106
107 /** 107 /**
108 - * 共享所有的直播流  
109 - */  
110 - private boolean shareAllLiveStream;  
111 -  
112 - /**  
113 * 默认目录Id,自动添加的通道多放在这个目录下 108 * 默认目录Id,自动添加的通道多放在这个目录下
114 */ 109 */
115 private String catalogId; 110 private String catalogId;
@@ -154,6 +149,11 @@ public class ParentPlatform { @@ -154,6 +149,11 @@ public class ParentPlatform {
154 */ 149 */
155 private String createTime; 150 private String createTime;
156 151
  152 + /**
  153 + * 树类型 国标规定了两种树的展现方式 行政区划 CivilCode 和业务分组:BusinessGroup
  154 + */
  155 + private String treeType;
  156 +
157 public Integer getId() { 157 public Integer getId() {
158 return id; 158 return id;
159 } 159 }
@@ -314,15 +314,6 @@ public class ParentPlatform { @@ -314,15 +314,6 @@ public class ParentPlatform {
314 this.channelCount = channelCount; 314 this.channelCount = channelCount;
315 } 315 }
316 316
317 -  
318 - public boolean isShareAllLiveStream() {  
319 - return shareAllLiveStream;  
320 - }  
321 -  
322 - public void setShareAllLiveStream(boolean shareAllLiveStream) {  
323 - this.shareAllLiveStream = shareAllLiveStream;  
324 - }  
325 -  
326 public String getCatalogId() { 317 public String getCatalogId() {
327 return catalogId; 318 return catalogId;
328 } 319 }
@@ -394,4 +385,12 @@ public class ParentPlatform { @@ -394,4 +385,12 @@ public class ParentPlatform {
394 public void setCreateTime(String createTime) { 385 public void setCreateTime(String createTime) {
395 this.createTime = createTime; 386 this.createTime = createTime;
396 } 387 }
  388 +
  389 + public String getTreeType() {
  390 + return treeType;
  391 + }
  392 +
  393 + public void setTreeType(String treeType) {
  394 + this.treeType = treeType;
  395 + }
397 } 396 }
src/main/java/com/genersoft/iot/vmp/gb28181/bean/PlatformCatalog.java
1 package com.genersoft.iot.vmp.gb28181.bean; 1 package com.genersoft.iot.vmp.gb28181.bean;
2 2
  3 +/**
  4 + * 国标级联-目录
  5 + * @author lin
  6 + */
3 public class PlatformCatalog { 7 public class PlatformCatalog {
4 private String id; 8 private String id;
5 private String name; 9 private String name;
6 private String platformId; 10 private String platformId;
7 private String parentId; 11 private String parentId;
8 - private int childrenCount; // 子节点数  
9 - private int type; // 0 目录, 1 国标通道, 2 直播流 12 +
  13 + private String civilCode;
  14 +
  15 + private String businessGroupId;
  16 +
  17 + /**
  18 + * 子节点数
  19 + */
  20 + private int childrenCount;
  21 +
  22 + /**
  23 + * 0 目录, 1 国标通道, 2 直播流
  24 + */
  25 + private int type;
10 26
11 public String getId() { 27 public String getId() {
12 return id; 28 return id;
@@ -68,4 +84,19 @@ public class PlatformCatalog { @@ -68,4 +84,19 @@ public class PlatformCatalog {
68 this.type = 2; 84 this.type = 2;
69 } 85 }
70 86
  87 + public String getCivilCode() {
  88 + return civilCode;
  89 + }
  90 +
  91 + public void setCivilCode(String civilCode) {
  92 + this.civilCode = civilCode;
  93 + }
  94 +
  95 + public String getBusinessGroupId() {
  96 + return businessGroupId;
  97 + }
  98 +
  99 + public void setBusinessGroupId(String businessGroupId) {
  100 + this.businessGroupId = businessGroupId;
  101 + }
71 } 102 }
src/main/java/com/genersoft/iot/vmp/domain/req/PresetQuerySipReq.java renamed to src/main/java/com/genersoft/iot/vmp/gb28181/bean/PresetQuerySipReq.java
1 -package com.genersoft.iot.vmp.domain.req; 1 +package com.genersoft.iot.vmp.gb28181.bean;
2 2
3 3
4 /** 4 /**
src/main/java/com/genersoft/iot/vmp/gb28181/bean/TreeType.java 0 → 100644
  1 +package com.genersoft.iot.vmp.gb28181.bean;
  2 +
  3 +/**
  4 + * 目录结构类型
  5 + * @author lin
  6 + */
  7 +public class TreeType {
  8 + public static final String BUSINESS_GROUP = "BusinessGroup";
  9 + public static final String CIVIL_CODE = "CivilCode";
  10 +}
src/main/java/com/genersoft/iot/vmp/gb28181/event/platformNotRegister/PlatformNotRegisterEventLister.java
@@ -65,7 +65,6 @@ public class PlatformNotRegisterEventLister implements ApplicationListener<Platf @@ -65,7 +65,6 @@ public class PlatformNotRegisterEventLister implements ApplicationListener<Platf
65 } 65 }
66 // 查询是否有推流, 如果有则都停止 66 // 查询是否有推流, 如果有则都停止
67 List<SendRtpItem> sendRtpItems = redisCatchStorage.querySendRTPServer(event.getPlatformGbID()); 67 List<SendRtpItem> sendRtpItems = redisCatchStorage.querySendRTPServer(event.getPlatformGbID());
68 - logger.info("[ 平台未注册事件 ] 停止[ {} ]的所有推流size", sendRtpItems.size());  
69 if (sendRtpItems != null && sendRtpItems.size() > 0) { 68 if (sendRtpItems != null && sendRtpItems.size() > 0) {
70 logger.info("[ 平台未注册事件 ] 停止[ {} ]的所有推流", event.getPlatformGbID()); 69 logger.info("[ 平台未注册事件 ] 停止[ {} ]的所有推流", event.getPlatformGbID());
71 for (SendRtpItem sendRtpItem : sendRtpItems) { 70 for (SendRtpItem sendRtpItem : sendRtpItems) {
src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEvent.java
@@ -11,13 +11,40 @@ public class CatalogEvent extends ApplicationEvent { @@ -11,13 +11,40 @@ public class CatalogEvent extends ApplicationEvent {
11 super(source); 11 super(source);
12 } 12 }
13 13
14 - public static final String ON = "ON"; // 上线  
15 - public static final String OFF = "OFF"; // 离线  
16 - public static final String VLOST = "VLOST"; // 视频丢失  
17 - public static final String DEFECT = "DEFECT"; // 故障  
18 - public static final String ADD = "ADD"; // 增加  
19 - public static final String DEL = "DEL"; // 删除  
20 - public static final String UPDATE = "UPDATE"; // 更新 14 + /**
  15 + * 上线
  16 + */
  17 + public static final String ON = "ON";
  18 +
  19 + /**
  20 + * 离线
  21 + */
  22 + public static final String OFF = "OFF";
  23 +
  24 + /**
  25 + * 视频丢失
  26 + */
  27 + public static final String VLOST = "VLOST";
  28 +
  29 + /**
  30 + * 故障
  31 + */
  32 + public static final String DEFECT = "DEFECT";
  33 +
  34 + /**
  35 + * 增加
  36 + */
  37 + public static final String ADD = "ADD";
  38 +
  39 + /**
  40 + * 删除
  41 + */
  42 + public static final String DEL = "DEL";
  43 +
  44 + /**
  45 + * 更新
  46 + */
  47 + public static final String UPDATE = "UPDATE";
21 48
22 private List<DeviceChannel> deviceChannels; 49 private List<DeviceChannel> deviceChannels;
23 private List<GbStream> gbStreams; 50 private List<GbStream> gbStreams;
src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEventLister.java
@@ -58,17 +58,16 @@ public class CatalogEventLister implements ApplicationListener&lt;CatalogEvent&gt; { @@ -58,17 +58,16 @@ public class CatalogEventLister implements ApplicationListener&lt;CatalogEvent&gt; {
58 ParentPlatform parentPlatform = null; 58 ParentPlatform parentPlatform = null;
59 59
60 Map<String, List<ParentPlatform>> parentPlatformMap = new HashMap<>(); 60 Map<String, List<ParentPlatform>> parentPlatformMap = new HashMap<>();
61 - if (event.getPlatformId() != null) { 61 + if (!StringUtils.isEmpty(event.getPlatformId())) {
  62 + subscribe = subscribeHolder.getCatalogSubscribe(event.getPlatformId());
  63 + if (subscribe == null) {
  64 + return;
  65 + }
62 parentPlatform = storager.queryParentPlatByServerGBId(event.getPlatformId()); 66 parentPlatform = storager.queryParentPlatByServerGBId(event.getPlatformId());
63 if (parentPlatform != null && !parentPlatform.isStatus()) { 67 if (parentPlatform != null && !parentPlatform.isStatus()) {
64 return; 68 return;
65 } 69 }
66 - subscribe = subscribeHolder.getCatalogSubscribe(event.getPlatformId());  
67 70
68 - if (subscribe == null) {  
69 - logger.info("发送订阅消息时发现订阅信息已经不存在: {}", event.getPlatformId());  
70 - return;  
71 - }  
72 }else { 71 }else {
73 // 获取所用订阅 72 // 获取所用订阅
74 List<String> platforms = subscribeHolder.getAllCatalogSubscribePlatform(); 73 List<String> platforms = subscribeHolder.getAllCatalogSubscribePlatform();
@@ -144,11 +143,8 @@ public class CatalogEventLister implements ApplicationListener&lt;CatalogEvent&gt; { @@ -144,11 +143,8 @@ public class CatalogEventLister implements ApplicationListener&lt;CatalogEvent&gt; {
144 } 143 }
145 if (event.getGbStreams() != null && event.getGbStreams().size() > 0){ 144 if (event.getGbStreams() != null && event.getGbStreams().size() > 0){
146 for (GbStream gbStream : event.getGbStreams()) { 145 for (GbStream gbStream : event.getGbStreams()) {
147 - DeviceChannel deviceChannelByStream = gbStreamService.getDeviceChannelListByStream(gbStream, gbStream.getCatalogId(), parentPlatform);  
148 - if (deviceChannelByStream.getParentId().length() <= 10) { // 父节点是行政区划,则设置CivilCode使用此行政区划  
149 - deviceChannelByStream.setCivilCode(deviceChannelByStream.getParentId());  
150 - }  
151 - deviceChannelList.add(deviceChannelByStream); 146 + deviceChannelList.add(
  147 + gbStreamService.getDeviceChannelListByStream(gbStream, gbStream.getCatalogId(), parentPlatform));
152 } 148 }
153 } 149 }
154 if (deviceChannelList.size() > 0) { 150 if (deviceChannelList.size() > 0) {
src/main/java/com/genersoft/iot/vmp/gb28181/task/impl/MobilePositionSubscribeHandlerTask.java
@@ -57,23 +57,17 @@ public class MobilePositionSubscribeHandlerTask implements ISubscribeTask { @@ -57,23 +57,17 @@ public class MobilePositionSubscribeHandlerTask implements ISubscribeTask {
57 SubscribeInfo subscribe = subscribeHolder.getMobilePositionSubscribe(platform.getServerGBId()); 57 SubscribeInfo subscribe = subscribeHolder.getMobilePositionSubscribe(platform.getServerGBId());
58 if (subscribe != null) { 58 if (subscribe != null) {
59 59
60 -// if (!parentPlatform.isStatus()) {  
61 -// logger.info("发送订阅时发现平台已经离线:{}", platformId);  
62 -// return;  
63 -// }  
64 // TODO 暂时只处理视频流的回复,后续增加对国标设备的支持 60 // TODO 暂时只处理视频流的回复,后续增加对国标设备的支持
65 - List<GbStream> gbStreams = storager.queryGbStreamListInPlatform(platform.getServerGBId()); 61 + List<DeviceChannel> gbStreams = storager.queryGbStreamListInPlatform(platform.getServerGBId());
66 if (gbStreams.size() == 0) { 62 if (gbStreams.size() == 0) {
67 logger.info("发送订阅时发现平台已经没有关联的直播流:{}", platform.getServerGBId()); 63 logger.info("发送订阅时发现平台已经没有关联的直播流:{}", platform.getServerGBId());
68 return; 64 return;
69 } 65 }
70 - for (GbStream gbStream : gbStreams) {  
71 - String gbId = gbStream.getGbId(); 66 + for (DeviceChannel deviceChannel : gbStreams) {
  67 + String gbId = deviceChannel.getChannelId();
72 GPSMsgInfo gpsMsgInfo = redisCatchStorage.getGpsMsgInfo(gbId); 68 GPSMsgInfo gpsMsgInfo = redisCatchStorage.getGpsMsgInfo(gbId);
73 - if (gpsMsgInfo != null) { // 无最新位置不发送  
74 - if (logger.isDebugEnabled()) {  
75 - logger.debug("无最新位置不发送");  
76 - } 69 + // 无最新位置不发送
  70 + if (gpsMsgInfo != null) {
77 // 经纬度都为0不发送 71 // 经纬度都为0不发送
78 if (gpsMsgInfo.getLng() == 0 && gpsMsgInfo.getLat() == 0) { 72 if (gpsMsgInfo.getLng() == 0 && gpsMsgInfo.getLat() == 0) {
79 continue; 73 continue;
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java
@@ -257,37 +257,37 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { @@ -257,37 +257,37 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
257 catalogXml.append("<DeviceList Num=\"" + channels.size() +"\">\r\n"); 257 catalogXml.append("<DeviceList Num=\"" + channels.size() +"\">\r\n");
258 if (channels.size() > 0) { 258 if (channels.size() > 0) {
259 for (DeviceChannel channel : channels) { 259 for (DeviceChannel channel : channels) {
  260 + if (parentPlatform.getServerGBId().equals(channel.getParentId())) {
  261 + channel.setParentId(parentPlatform.getDeviceGBId());
  262 + }
260 catalogXml.append("<Item>\r\n"); 263 catalogXml.append("<Item>\r\n");
  264 + // 行政区划分组只需要这两项就可以
261 catalogXml.append("<DeviceID>" + channel.getChannelId() + "</DeviceID>\r\n"); 265 catalogXml.append("<DeviceID>" + channel.getChannelId() + "</DeviceID>\r\n");
262 catalogXml.append("<Name>" + channel.getName() + "</Name>\r\n"); 266 catalogXml.append("<Name>" + channel.getName() + "</Name>\r\n");
263 - catalogXml.append("<Parental>" + channel.getParental() + "</Parental>\r\n");  
264 if (channel.getParentId() != null) { 267 if (channel.getParentId() != null) {
  268 + // 业务分组加上这一项即可,提高兼容性,
265 catalogXml.append("<ParentID>" + channel.getParentId() + "</ParentID>\r\n"); 269 catalogXml.append("<ParentID>" + channel.getParentId() + "</ParentID>\r\n");
266 } 270 }
267 - if (channel.getChannelId().length() == 20) {  
268 - if (Integer.parseInt(channel.getChannelId().substring(10, 13)) == 216) { // 虚拟组织增加BusinessGroupID字段  
269 - catalogXml.append("<BusinessGroupID>" + channel.getParentId() + "</BusinessGroupID>\r\n");  
270 - } 271 + if (channel.getChannelId().length() == 20 && Integer.parseInt(channel.getChannelId().substring(10, 13)) == 216) {
  272 + // 虚拟组织增加BusinessGroupID字段
  273 + catalogXml.append("<BusinessGroupID>" + channel.getParentId() + "</BusinessGroupID>\r\n");
  274 + }
  275 + catalogXml.append("<Parental>" + channel.getParental() + "</Parental>\r\n");
  276 + if (channel.getParental() == 0) {
  277 + // 通道项
271 catalogXml.append("<Manufacturer>" + channel.getManufacture() + "</Manufacturer>\r\n"); 278 catalogXml.append("<Manufacturer>" + channel.getManufacture() + "</Manufacturer>\r\n");
  279 + catalogXml.append("<Secrecy>" + channel.getSecrecy() + "</Secrecy>\r\n");
272 catalogXml.append("<RegisterWay>" + channel.getRegisterWay() + "</RegisterWay>\r\n"); 280 catalogXml.append("<RegisterWay>" + channel.getRegisterWay() + "</RegisterWay>\r\n");
273 - catalogXml.append("<Status>" + (channel.getStatus() == 0?"OFF":"ON") + "</Status>\r\n");  
274 - if (channel.getChannelType() != 2) { // 业务分组/虚拟组织/行政区划 不设置以下字段  
275 - catalogXml.append("<Secrecy>" + channel.getSecrecy() + "</Secrecy>\r\n"); 281 + catalogXml.append("<Status>" + (channel.getStatus() == 0 ? "OFF" : "ON") + "</Status>\r\n");
  282 +
  283 + if (channel.getChannelType() != 2) { // 业务分组/虚拟组织/行政区划 不设置以下属性
276 catalogXml.append("<Model>" + channel.getModel() + "</Model>\r\n"); 284 catalogXml.append("<Model>" + channel.getModel() + "</Model>\r\n");
277 - catalogXml.append("<Owner>" + channel.getOwner() + "</Owner>\r\n"); 285 + catalogXml.append("<Owner> " + channel.getOwner()+ "</Owner>\r\n");
278 catalogXml.append("<CivilCode>" + channel.getCivilCode() + "</CivilCode>\r\n"); 286 catalogXml.append("<CivilCode>" + channel.getCivilCode() + "</CivilCode>\r\n");
279 catalogXml.append("<Address>" + channel.getAddress() + "</Address>\r\n"); 287 catalogXml.append("<Address>" + channel.getAddress() + "</Address>\r\n");
280 - catalogXml.append("<Longitude>" + channel.getLongitudeWgs84() + "</Longitude>\r\n");  
281 - catalogXml.append("<Latitude>" + channel.getLatitudeWgs84() + "</Latitude>\r\n");  
282 - catalogXml.append("<IPAddress>" + channel.getIpAddress() + "</IPAddress>\r\n");  
283 - catalogXml.append("<Port>" + channel.getPort() + "</Port>\r\n");  
284 - catalogXml.append("<Info>\r\n");  
285 - catalogXml.append("<PTZType>" + channel.getPTZType() + "</PTZType>\r\n");  
286 - catalogXml.append("</Info>\r\n");  
287 } 288 }
288 - }  
289 -  
290 289
  290 + }
291 catalogXml.append("</Item>\r\n"); 291 catalogXml.append("</Item>\r\n");
292 } 292 }
293 } 293 }
@@ -592,27 +592,35 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { @@ -592,27 +592,35 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
592 channel.setParentId(parentPlatform.getDeviceGBId()); 592 channel.setParentId(parentPlatform.getDeviceGBId());
593 } 593 }
594 catalogXml.append("<Item>\r\n"); 594 catalogXml.append("<Item>\r\n");
  595 + // 行政区划分组只需要这两项就可以
595 catalogXml.append("<DeviceID>" + channel.getChannelId() + "</DeviceID>\r\n"); 596 catalogXml.append("<DeviceID>" + channel.getChannelId() + "</DeviceID>\r\n");
596 catalogXml.append("<Name>" + channel.getName() + "</Name>\r\n"); 597 catalogXml.append("<Name>" + channel.getName() + "</Name>\r\n");
597 - catalogXml.append("<Manufacturer>" + channel.getManufacture() + "</Manufacturer>\r\n");  
598 - catalogXml.append("<Parental>" + channel.getParental() + "</Parental>\r\n");  
599 if (channel.getParentId() != null) { 598 if (channel.getParentId() != null) {
  599 + // 业务分组加上这一项即可,提高兼容性,
600 catalogXml.append("<ParentID>" + channel.getParentId() + "</ParentID>\r\n"); 600 catalogXml.append("<ParentID>" + channel.getParentId() + "</ParentID>\r\n");
601 } 601 }
602 - catalogXml.append("<Secrecy>" + channel.getSecrecy() + "</Secrecy>\r\n");  
603 - catalogXml.append("<RegisterWay>" + channel.getRegisterWay() + "</RegisterWay>\r\n");  
604 - catalogXml.append("<Status>" + (channel.getStatus() == 0 ? "OFF" : "ON") + "</Status>\r\n");  
605 - if (channel.getChannelId().length() == 20 && Integer.parseInt(channel.getChannelId().substring(10, 13)) == 216) { // 虚拟组织增加BusinessGroupID字段 602 + if (channel.getChannelId().length() == 20 && Integer.parseInt(channel.getChannelId().substring(10, 13)) == 216) {
  603 + // 虚拟组织增加BusinessGroupID字段
606 catalogXml.append("<BusinessGroupID>" + channel.getParentId() + "</BusinessGroupID>\r\n"); 604 catalogXml.append("<BusinessGroupID>" + channel.getParentId() + "</BusinessGroupID>\r\n");
607 } 605 }
608 - if (channel.getChannelType() == 2) { // 业务分组/虚拟组织/行政区划 不设置以下属性  
609 - catalogXml.append("<Model>" + channel.getModel() + "</Model>\r\n");  
610 - catalogXml.append("<Owner>0</Owner>\r\n");  
611 - catalogXml.append("<CivilCode>CivilCode</CivilCode>\r\n");  
612 - catalogXml.append("<Address>" + channel.getAddress() + "</Address>\r\n");  
613 - }  
614 - if (!"presence".equals(subscribeInfo.getEventType())) {  
615 - catalogXml.append("<Event>" + type + "</Event>\r\n"); 606 + catalogXml.append("<Parental>" + channel.getParental() + "</Parental>\r\n");
  607 + if (channel.getParental() == 0) {
  608 + // 通道项
  609 + catalogXml.append("<Manufacturer>" + channel.getManufacture() + "</Manufacturer>\r\n");
  610 + catalogXml.append("<Secrecy>" + channel.getSecrecy() + "</Secrecy>\r\n");
  611 + catalogXml.append("<RegisterWay>" + channel.getRegisterWay() + "</RegisterWay>\r\n");
  612 + catalogXml.append("<Status>" + (channel.getStatus() == 0 ? "OFF" : "ON") + "</Status>\r\n");
  613 +
  614 + if (channel.getChannelType() != 2) { // 业务分组/虚拟组织/行政区划 不设置以下属性
  615 + catalogXml.append("<Model>" + channel.getModel() + "</Model>\r\n");
  616 + catalogXml.append("<Owner> " + channel.getOwner()+ "</Owner>\r\n");
  617 + catalogXml.append("<CivilCode>" + channel.getCivilCode() + "</CivilCode>\r\n");
  618 + catalogXml.append("<Address>" + channel.getAddress() + "</Address>\r\n");
  619 + }
  620 + if (!"presence".equals(subscribeInfo.getEventType())) {
  621 + catalogXml.append("<Event>" + type + "</Event>\r\n");
  622 + }
  623 +
616 } 624 }
617 catalogXml.append("</Item>\r\n"); 625 catalogXml.append("</Item>\r\n");
618 } 626 }
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; @@ -15,6 +15,7 @@ import com.genersoft.iot.vmp.gb28181.utils.Coordtransform;
15 import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; 15 import com.genersoft.iot.vmp.gb28181.utils.NumericUtil;
16 import com.genersoft.iot.vmp.gb28181.utils.SipUtils; 16 import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
17 import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; 17 import com.genersoft.iot.vmp.gb28181.utils.XmlUtil;
  18 +import com.genersoft.iot.vmp.service.IDeviceChannelService;
18 import com.genersoft.iot.vmp.storager.IRedisCatchStorage; 19 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
19 import com.genersoft.iot.vmp.storager.IVideoManagerStorage; 20 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
20 import com.genersoft.iot.vmp.utils.DateUtil; 21 import com.genersoft.iot.vmp.utils.DateUtil;
@@ -71,6 +72,9 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements @@ -71,6 +72,9 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements
71 @Autowired 72 @Autowired
72 private SIPProcessorObserver sipProcessorObserver; 73 private SIPProcessorObserver sipProcessorObserver;
73 74
  75 + @Autowired
  76 + private IDeviceChannelService deviceChannelService;
  77 +
74 private boolean taskQueueHandlerRun = false; 78 private boolean taskQueueHandlerRun = false;
75 79
76 private final ConcurrentLinkedQueue<HandlerCatchData> taskQueue = new ConcurrentLinkedQueue<>(); 80 private final ConcurrentLinkedQueue<HandlerCatchData> taskQueue = new ConcurrentLinkedQueue<>();
@@ -173,28 +177,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements @@ -173,28 +177,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements
173 logger.info("[收到 移动位置订阅]:{}/{}->{}.{}", mobilePosition.getDeviceId(), mobilePosition.getChannelId(), 177 logger.info("[收到 移动位置订阅]:{}/{}->{}.{}", mobilePosition.getDeviceId(), mobilePosition.getChannelId(),
174 mobilePosition.getLongitude(), mobilePosition.getLatitude()); 178 mobilePosition.getLongitude(), mobilePosition.getLatitude());
175 mobilePosition.setReportSource("Mobile Position"); 179 mobilePosition.setReportSource("Mobile Position");
176 - // 默认来源坐标系为WGS-84处理  
177 - if ("WGS84".equals(device.getGeoCoordSys())) {  
178 - mobilePosition.setLongitudeWgs84(mobilePosition.getLongitude());  
179 - mobilePosition.setLatitudeWgs84(mobilePosition.getLatitude());  
180 - Double[] position = Coordtransform.WGS84ToGCJ02(mobilePosition.getLongitude(), mobilePosition.getLatitude());  
181 - mobilePosition.setLongitudeGcj02(position[0]);  
182 - mobilePosition.setLatitudeGcj02(position[1]);  
183 - }else if ("GCJ02".equals(device.getGeoCoordSys())) {  
184 - mobilePosition.setLongitudeGcj02(mobilePosition.getLongitude());  
185 - mobilePosition.setLatitudeGcj02(mobilePosition.getLatitude());  
186 - Double[] position = Coordtransform.GCJ02ToWGS84(mobilePosition.getLongitude(), mobilePosition.getLatitude());  
187 - mobilePosition.setLongitudeWgs84(position[0]);  
188 - mobilePosition.setLatitudeWgs84(position[1]);  
189 - }else {  
190 - mobilePosition.setLongitudeGcj02(0.00);  
191 - mobilePosition.setLatitudeGcj02(0.00);  
192 - mobilePosition.setLongitudeWgs84(0.00);  
193 - mobilePosition.setLatitudeWgs84(0.00);  
194 - }  
195 - if (userSetting.getSavePositionHistory()) {  
196 - storager.insertMobilePosition(mobilePosition);  
197 - } 180 +
198 181
199 // 更新device channel 的经纬度 182 // 更新device channel 的经纬度
200 DeviceChannel deviceChannel = new DeviceChannel(); 183 DeviceChannel deviceChannel = new DeviceChannel();
@@ -202,11 +185,18 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements @@ -202,11 +185,18 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements
202 deviceChannel.setChannelId(channelId); 185 deviceChannel.setChannelId(channelId);
203 deviceChannel.setLongitude(mobilePosition.getLongitude()); 186 deviceChannel.setLongitude(mobilePosition.getLongitude());
204 deviceChannel.setLatitude(mobilePosition.getLatitude()); 187 deviceChannel.setLatitude(mobilePosition.getLatitude());
205 - deviceChannel.setLongitudeWgs84(mobilePosition.getLongitudeWgs84());  
206 - deviceChannel.setLatitudeWgs84(mobilePosition.getLatitudeWgs84());  
207 - deviceChannel.setLongitudeGcj02(mobilePosition.getLongitudeGcj02());  
208 - deviceChannel.setLatitudeGcj02(mobilePosition.getLatitudeGcj02());  
209 deviceChannel.setGpsTime(mobilePosition.getTime()); 188 deviceChannel.setGpsTime(mobilePosition.getTime());
  189 + deviceChannel = deviceChannelService.updateGps(deviceChannel, device);
  190 +
  191 + mobilePosition.setLongitudeWgs84(deviceChannel.getLongitudeWgs84());
  192 + mobilePosition.setLatitudeWgs84(deviceChannel.getLatitudeWgs84());
  193 + mobilePosition.setLongitudeGcj02(deviceChannel.getLongitudeGcj02());
  194 + mobilePosition.setLatitudeGcj02(deviceChannel.getLatitudeGcj02());
  195 +
  196 + if (userSetting.getSavePositionHistory()) {
  197 + storager.insertMobilePosition(mobilePosition);
  198 + }
  199 +
210 storager.updateChannelPosition(deviceChannel); 200 storager.updateChannelPosition(deviceChannel);
211 // 发送redis消息。 通知位置信息的变化 201 // 发送redis消息。 通知位置信息的变化
212 JSONObject jsonObject = new JSONObject(); 202 JSONObject jsonObject = new JSONObject();
@@ -281,38 +271,28 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements @@ -281,38 +271,28 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements
281 mobilePosition.setLongitude(deviceAlarm.getLongitude()); 271 mobilePosition.setLongitude(deviceAlarm.getLongitude());
282 mobilePosition.setLatitude(deviceAlarm.getLatitude()); 272 mobilePosition.setLatitude(deviceAlarm.getLatitude());
283 mobilePosition.setReportSource("GPS Alarm"); 273 mobilePosition.setReportSource("GPS Alarm");
284 - if ("WGS84".equals(device.getGeoCoordSys())) {  
285 - mobilePosition.setLongitudeWgs84(mobilePosition.getLongitude());  
286 - mobilePosition.setLatitudeWgs84(mobilePosition.getLatitude());  
287 - Double[] position = Coordtransform.WGS84ToGCJ02(mobilePosition.getLongitude(), mobilePosition.getLatitude());  
288 - mobilePosition.setLongitudeGcj02(position[0]);  
289 - mobilePosition.setLatitudeGcj02(position[1]);  
290 - }else if ("GCJ02".equals(device.getGeoCoordSys())) {  
291 - mobilePosition.setLongitudeGcj02(mobilePosition.getLongitude());  
292 - mobilePosition.setLatitudeGcj02(mobilePosition.getLatitude());  
293 - Double[] position = Coordtransform.GCJ02ToWGS84(mobilePosition.getLongitude(), mobilePosition.getLatitude());  
294 - mobilePosition.setLongitudeWgs84(position[0]);  
295 - mobilePosition.setLatitudeWgs84(position[1]);  
296 - }else {  
297 - mobilePosition.setLongitudeGcj02(0.00);  
298 - mobilePosition.setLatitudeGcj02(0.00);  
299 - mobilePosition.setLongitudeWgs84(0.00);  
300 - mobilePosition.setLatitudeWgs84(0.00);  
301 - }  
302 - if (userSetting.getSavePositionHistory()) {  
303 - storager.insertMobilePosition(mobilePosition);  
304 - } 274 +
  275 +
  276 +
305 // 更新device channel 的经纬度 277 // 更新device channel 的经纬度
306 DeviceChannel deviceChannel = new DeviceChannel(); 278 DeviceChannel deviceChannel = new DeviceChannel();
307 deviceChannel.setDeviceId(device.getDeviceId()); 279 deviceChannel.setDeviceId(device.getDeviceId());
308 deviceChannel.setChannelId(channelId); 280 deviceChannel.setChannelId(channelId);
309 deviceChannel.setLongitude(mobilePosition.getLongitude()); 281 deviceChannel.setLongitude(mobilePosition.getLongitude());
310 deviceChannel.setLatitude(mobilePosition.getLatitude()); 282 deviceChannel.setLatitude(mobilePosition.getLatitude());
311 - deviceChannel.setLongitudeWgs84(mobilePosition.getLongitudeWgs84());  
312 - deviceChannel.setLatitudeWgs84(mobilePosition.getLatitudeWgs84());  
313 - deviceChannel.setLongitudeGcj02(mobilePosition.getLongitudeGcj02());  
314 - deviceChannel.setLatitudeGcj02(mobilePosition.getLatitudeGcj02());  
315 deviceChannel.setGpsTime(mobilePosition.getTime()); 283 deviceChannel.setGpsTime(mobilePosition.getTime());
  284 +
  285 + deviceChannel = deviceChannelService.updateGps(deviceChannel, device);
  286 +
  287 + mobilePosition.setLongitudeWgs84(deviceChannel.getLongitudeWgs84());
  288 + mobilePosition.setLatitudeWgs84(deviceChannel.getLatitudeWgs84());
  289 + mobilePosition.setLongitudeGcj02(deviceChannel.getLongitudeGcj02());
  290 + mobilePosition.setLatitudeGcj02(deviceChannel.getLatitudeGcj02());
  291 +
  292 + if (userSetting.getSavePositionHistory()) {
  293 + storager.insertMobilePosition(mobilePosition);
  294 + }
  295 +
316 storager.updateChannelPosition(deviceChannel); 296 storager.updateChannelPosition(deviceChannel);
317 } 297 }
318 // TODO: 需要实现存储报警信息、报警分类 298 // TODO: 需要实现存储报警信息、报警分类
@@ -364,7 +344,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements @@ -364,7 +344,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements
364 }else { 344 }else {
365 event = eventElement.getText().toUpperCase(); 345 event = eventElement.getText().toUpperCase();
366 } 346 }
367 - DeviceChannel channel = XmlUtil.channelContentHander(itemDevice, device); 347 + DeviceChannel channel = XmlUtil.channelContentHander(itemDevice, device, event);
368 channel.setDeviceId(device.getDeviceId()); 348 channel.setDeviceId(device.getDeviceId());
369 logger.info("[收到 目录订阅]:{}/{}", device.getDeviceId(), channel.getChannelId()); 349 logger.info("[收到 目录订阅]:{}/{}", device.getDeviceId(), channel.getChannelId());
370 switch (event) { 350 switch (event) {
@@ -389,7 +369,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements @@ -389,7 +369,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements
389 case CatalogEvent.ADD: 369 case CatalogEvent.ADD:
390 // 增加 370 // 增加
391 logger.info("收到来自设备【{}】的增加通道【{}】通知", device.getDeviceId(), channel.getChannelId()); 371 logger.info("收到来自设备【{}】的增加通道【{}】通知", device.getDeviceId(), channel.getChannelId());
392 - storager.updateChannel(deviceId, channel); 372 + deviceChannelService.updateChannel(deviceId, channel);
393 break; 373 break;
394 case CatalogEvent.DEL: 374 case CatalogEvent.DEL:
395 // 删除 375 // 删除
@@ -399,7 +379,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements @@ -399,7 +379,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements
399 case CatalogEvent.UPDATE: 379 case CatalogEvent.UPDATE:
400 // 更新 380 // 更新
401 logger.info("收到来自设备【{}】的更新通道【{}】通知", device.getDeviceId(), channel.getChannelId()); 381 logger.info("收到来自设备【{}】的更新通道【{}】通知", device.getDeviceId(), channel.getChannelId());
402 - storager.updateChannel(deviceId, channel); 382 + deviceChannelService.updateChannel(deviceId, channel);
403 break; 383 break;
404 default: 384 default:
405 logger.warn("[ NotifyCatalog ] event not found : {}", event ); 385 logger.warn("[ NotifyCatalog ] event not found : {}", event );
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; @@ -11,6 +11,7 @@ import com.genersoft.iot.vmp.gb28181.utils.Coordtransform;
11 import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; 11 import com.genersoft.iot.vmp.gb28181.utils.NumericUtil;
12 import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; 12 import com.genersoft.iot.vmp.gb28181.utils.XmlUtil;
13 import com.genersoft.iot.vmp.service.IDeviceAlarmService; 13 import com.genersoft.iot.vmp.service.IDeviceAlarmService;
  14 +import com.genersoft.iot.vmp.service.IDeviceChannelService;
14 import com.genersoft.iot.vmp.storager.IRedisCatchStorage; 15 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
15 import com.genersoft.iot.vmp.storager.IVideoManagerStorage; 16 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
16 import com.genersoft.iot.vmp.utils.DateUtil; 17 import com.genersoft.iot.vmp.utils.DateUtil;
@@ -58,6 +59,9 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme @@ -58,6 +59,9 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme
58 @Autowired 59 @Autowired
59 private IDeviceAlarmService deviceAlarmService; 60 private IDeviceAlarmService deviceAlarmService;
60 61
  62 + @Autowired
  63 + private IDeviceChannelService deviceChannelService;
  64 +
61 @Override 65 @Override
62 public void afterPropertiesSet() throws Exception { 66 public void afterPropertiesSet() throws Exception {
63 notifyMessageHandler.addHandler(cmdType, this); 67 notifyMessageHandler.addHandler(cmdType, this);
@@ -119,38 +123,26 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme @@ -119,38 +123,26 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme
119 mobilePosition.setLongitude(deviceAlarm.getLongitude()); 123 mobilePosition.setLongitude(deviceAlarm.getLongitude());
120 mobilePosition.setLatitude(deviceAlarm.getLatitude()); 124 mobilePosition.setLatitude(deviceAlarm.getLatitude());
121 mobilePosition.setReportSource("GPS Alarm"); 125 mobilePosition.setReportSource("GPS Alarm");
122 - if ("WGS84".equals(device.getGeoCoordSys())) {  
123 - mobilePosition.setLongitudeWgs84(mobilePosition.getLongitude());  
124 - mobilePosition.setLatitudeWgs84(mobilePosition.getLatitude());  
125 - Double[] position = Coordtransform.WGS84ToGCJ02(mobilePosition.getLongitude(), mobilePosition.getLatitude());  
126 - mobilePosition.setLongitudeGcj02(position[0]);  
127 - mobilePosition.setLatitudeGcj02(position[1]);  
128 - }else if ("GCJ02".equals(device.getGeoCoordSys())) {  
129 - mobilePosition.setLongitudeGcj02(mobilePosition.getLongitude());  
130 - mobilePosition.setLatitudeGcj02(mobilePosition.getLatitude());  
131 - Double[] position = Coordtransform.GCJ02ToWGS84(mobilePosition.getLongitude(), mobilePosition.getLatitude());  
132 - mobilePosition.setLongitudeWgs84(position[0]);  
133 - mobilePosition.setLatitudeWgs84(position[1]);  
134 - }else {  
135 - mobilePosition.setLongitudeGcj02(0.00);  
136 - mobilePosition.setLatitudeGcj02(0.00);  
137 - mobilePosition.setLongitudeWgs84(0.00);  
138 - mobilePosition.setLatitudeWgs84(0.00);  
139 - }  
140 - if (userSetting.getSavePositionHistory()) {  
141 - storager.insertMobilePosition(mobilePosition);  
142 - } 126 +
  127 +
143 // 更新device channel 的经纬度 128 // 更新device channel 的经纬度
144 DeviceChannel deviceChannel = new DeviceChannel(); 129 DeviceChannel deviceChannel = new DeviceChannel();
145 deviceChannel.setDeviceId(device.getDeviceId()); 130 deviceChannel.setDeviceId(device.getDeviceId());
146 deviceChannel.setChannelId(channelId); 131 deviceChannel.setChannelId(channelId);
147 deviceChannel.setLongitude(mobilePosition.getLongitude()); 132 deviceChannel.setLongitude(mobilePosition.getLongitude());
148 deviceChannel.setLatitude(mobilePosition.getLatitude()); 133 deviceChannel.setLatitude(mobilePosition.getLatitude());
149 - deviceChannel.setLongitudeWgs84(mobilePosition.getLongitudeWgs84());  
150 - deviceChannel.setLatitudeWgs84(mobilePosition.getLatitudeWgs84());  
151 - deviceChannel.setLongitudeGcj02(mobilePosition.getLongitudeGcj02());  
152 - deviceChannel.setLatitudeGcj02(mobilePosition.getLatitudeGcj02());  
153 deviceChannel.setGpsTime(mobilePosition.getTime()); 134 deviceChannel.setGpsTime(mobilePosition.getTime());
  135 +
  136 + deviceChannel = deviceChannelService.updateGps(deviceChannel, device);
  137 +
  138 + mobilePosition.setLongitudeWgs84(deviceChannel.getLongitudeWgs84());
  139 + mobilePosition.setLatitudeWgs84(deviceChannel.getLatitudeWgs84());
  140 + mobilePosition.setLongitudeGcj02(deviceChannel.getLongitudeGcj02());
  141 + mobilePosition.setLatitudeGcj02(deviceChannel.getLatitudeGcj02());
  142 +
  143 + if (userSetting.getSavePositionHistory()) {
  144 + storager.insertMobilePosition(mobilePosition);
  145 + }
154 storager.updateChannelPosition(deviceChannel); 146 storager.updateChannelPosition(deviceChannel);
155 } 147 }
156 } 148 }
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 @@ -58,85 +58,21 @@ public class CatalogNotifyMessageHandler extends SIPRequestProcessorParent imple
58 // 准备回复通道信息 58 // 准备回复通道信息
59 List<DeviceChannelInPlatform> deviceChannels = storage.queryChannelListInParentPlatform(parentPlatform.getServerGBId()); 59 List<DeviceChannelInPlatform> deviceChannels = storage.queryChannelListInParentPlatform(parentPlatform.getServerGBId());
60 // 查询关联的直播通道 60 // 查询关联的直播通道
61 - List<GbStream> gbStreams = storage.queryGbStreamListInPlatform(parentPlatform.getServerGBId()); 61 + List<DeviceChannel> gbStreams = storage.queryGbStreamListInPlatform(parentPlatform.getServerGBId());
  62 + // 回复目录信息
  63 + List<DeviceChannel> catalogs = storage.queryCatalogInPlatform(parentPlatform.getServerGBId());
62 64
63 List<DeviceChannel> allChannels = new ArrayList<>(); 65 List<DeviceChannel> allChannels = new ArrayList<>();
64 - // 回复目录信息  
65 - List<PlatformCatalog> catalogs = storage.queryCatalogInPlatform(parentPlatform.getServerGBId());  
66 if (catalogs.size() > 0) { 66 if (catalogs.size() > 0) {
67 - for (PlatformCatalog catalog : catalogs) {  
68 - if (catalog.getParentId().equals(catalog.getPlatformId())) {  
69 - catalog.setParentId(parentPlatform.getDeviceGBId());  
70 - }  
71 - DeviceChannel deviceChannel = new DeviceChannel();  
72 - deviceChannel.setChannelId(catalog.getId());  
73 - deviceChannel.setName(catalog.getName());  
74 - deviceChannel.setLongitude(0.0);  
75 - deviceChannel.setLatitude(0.0);  
76 - deviceChannel.setDeviceId(parentPlatform.getDeviceGBId());  
77 - deviceChannel.setManufacture("wvp-pro");  
78 - deviceChannel.setStatus(1);  
79 - deviceChannel.setParental(1);  
80 - deviceChannel.setParentId(catalog.getParentId());  
81 - deviceChannel.setRegisterWay(1);  
82 - if (catalog.getParentId() != null && catalog.getParentId().length() <= 10) {  
83 - deviceChannel.setCivilCode(catalog.getParentId());  
84 - }else {  
85 - deviceChannel.setCivilCode(parentPlatform.getAdministrativeDivision());  
86 - }  
87 - deviceChannel.setCivilCode(parentPlatform.getAdministrativeDivision());  
88 - deviceChannel.setModel("live");  
89 - deviceChannel.setOwner("wvp-pro");  
90 - deviceChannel.setSecrecy("0");  
91 - allChannels.add(deviceChannel);  
92 - } 67 + allChannels.addAll(catalogs);
93 } 68 }
94 // 回复级联的通道 69 // 回复级联的通道
95 if (deviceChannels.size() > 0) { 70 if (deviceChannels.size() > 0) {
96 - for (DeviceChannelInPlatform channel : deviceChannels) {  
97 - if (channel.getCatalogId().equals(parentPlatform.getServerGBId())) {  
98 - channel.setCatalogId(parentPlatform.getDeviceGBId());  
99 - }  
100 - DeviceChannel deviceChannel = storage.queryChannel(channel.getDeviceId(), channel.getChannelId());  
101 - deviceChannel.setParental(0);  
102 - deviceChannel.setParentId(channel.getCatalogId());  
103 - if (channel.getCatalogId() != null && channel.getCatalogId().length() <= 10) {  
104 - channel.setCivilCode(channel.getCatalogId());  
105 - }else {  
106 - deviceChannel.setCivilCode(parentPlatform.getAdministrativeDivision());  
107 - }  
108 -  
109 - allChannels.add(deviceChannel);  
110 - } 71 + allChannels.addAll(deviceChannels);
111 } 72 }
112 // 回复直播的通道 73 // 回复直播的通道
113 if (gbStreams.size() > 0) { 74 if (gbStreams.size() > 0) {
114 - for (GbStream gbStream : gbStreams) {  
115 - if (gbStream.getCatalogId().equals(parentPlatform.getServerGBId())) {  
116 - gbStream.setCatalogId(null);  
117 - }  
118 - DeviceChannel deviceChannel = new DeviceChannel();  
119 - deviceChannel.setChannelId(gbStream.getGbId());  
120 - deviceChannel.setName(gbStream.getName());  
121 - deviceChannel.setLongitude(gbStream.getLongitude());  
122 - deviceChannel.setLatitude(gbStream.getLatitude());  
123 - deviceChannel.setDeviceId(parentPlatform.getDeviceGBId());  
124 - deviceChannel.setManufacture("wvp-pro");  
125 -// deviceChannel.setStatus(gbStream.isStatus()?1:0);  
126 - deviceChannel.setStatus(1);  
127 - deviceChannel.setParentId(gbStream.getCatalogId());  
128 - deviceChannel.setRegisterWay(1);  
129 - if (gbStream.getCatalogId() != null && gbStream.getCatalogId().length() <= 10) {  
130 - deviceChannel.setCivilCode(gbStream.getCatalogId());  
131 - }else {  
132 - deviceChannel.setCivilCode(parentPlatform.getAdministrativeDivision());  
133 - }  
134 - deviceChannel.setModel("live");  
135 - deviceChannel.setOwner("wvp-pro");  
136 - deviceChannel.setParental(0);  
137 - deviceChannel.setSecrecy("0");  
138 - allChannels.add(deviceChannel);  
139 - } 75 + allChannels.addAll(gbStreams);
140 } 76 }
141 if (allChannels.size() > 0) { 77 if (allChannels.size() > 0) {
142 cmderFroPlatform.catalogQuery(allChannels, parentPlatform, sn, fromHeader.getTag()); 78 cmderFroPlatform.catalogQuery(allChannels, parentPlatform, sn, fromHeader.getTag());
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 @@ -7,6 +7,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessag
7 import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.NotifyMessageHandler; 7 import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.NotifyMessageHandler;
8 import com.genersoft.iot.vmp.gb28181.utils.Coordtransform; 8 import com.genersoft.iot.vmp.gb28181.utils.Coordtransform;
9 import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; 9 import com.genersoft.iot.vmp.gb28181.utils.NumericUtil;
  10 +import com.genersoft.iot.vmp.service.IDeviceChannelService;
10 import com.genersoft.iot.vmp.storager.IVideoManagerStorage; 11 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
11 import com.genersoft.iot.vmp.utils.DateUtil; 12 import com.genersoft.iot.vmp.utils.DateUtil;
12 import com.genersoft.iot.vmp.utils.GpsUtil; 13 import com.genersoft.iot.vmp.utils.GpsUtil;
@@ -42,6 +43,9 @@ public class MobilePositionNotifyMessageHandler extends SIPRequestProcessorParen @@ -42,6 +43,9 @@ public class MobilePositionNotifyMessageHandler extends SIPRequestProcessorParen
42 @Autowired 43 @Autowired
43 private IVideoManagerStorage storager; 44 private IVideoManagerStorage storager;
44 45
  46 + @Autowired
  47 + private IDeviceChannelService deviceChannelService;
  48 +
45 @Override 49 @Override
46 public void afterPropertiesSet() throws Exception { 50 public void afterPropertiesSet() throws Exception {
47 notifyMessageHandler.addHandler(cmdType, this); 51 notifyMessageHandler.addHandler(cmdType, this);
@@ -79,38 +83,26 @@ public class MobilePositionNotifyMessageHandler extends SIPRequestProcessorParen @@ -79,38 +83,26 @@ public class MobilePositionNotifyMessageHandler extends SIPRequestProcessorParen
79 mobilePosition.setAltitude(0.0); 83 mobilePosition.setAltitude(0.0);
80 } 84 }
81 mobilePosition.setReportSource("Mobile Position"); 85 mobilePosition.setReportSource("Mobile Position");
82 - if ("WGS84".equals(device.getGeoCoordSys())) {  
83 - mobilePosition.setLongitudeWgs84(mobilePosition.getLongitude());  
84 - mobilePosition.setLatitudeWgs84(mobilePosition.getLatitude());  
85 - Double[] position = Coordtransform.WGS84ToGCJ02(mobilePosition.getLongitude(), mobilePosition.getLatitude());  
86 - mobilePosition.setLongitudeGcj02(position[0]);  
87 - mobilePosition.setLatitudeGcj02(position[1]);  
88 - }else if ("GCJ02".equals(device.getGeoCoordSys())) {  
89 - mobilePosition.setLongitudeGcj02(mobilePosition.getLongitude());  
90 - mobilePosition.setLatitudeGcj02(mobilePosition.getLatitude());  
91 - Double[] position = Coordtransform.GCJ02ToWGS84(mobilePosition.getLongitude(), mobilePosition.getLatitude());  
92 - mobilePosition.setLongitudeWgs84(position[0]);  
93 - mobilePosition.setLatitudeWgs84(position[1]);  
94 - }else {  
95 - mobilePosition.setLongitudeGcj02(0.00);  
96 - mobilePosition.setLatitudeGcj02(0.00);  
97 - mobilePosition.setLongitudeWgs84(0.00);  
98 - mobilePosition.setLatitudeWgs84(0.00);  
99 - }  
100 - if (userSetting.getSavePositionHistory()) {  
101 - storager.insertMobilePosition(mobilePosition);  
102 - } 86 +
  87 +
103 // 更新device channel 的经纬度 88 // 更新device channel 的经纬度
104 DeviceChannel deviceChannel = new DeviceChannel(); 89 DeviceChannel deviceChannel = new DeviceChannel();
105 deviceChannel.setDeviceId(device.getDeviceId()); 90 deviceChannel.setDeviceId(device.getDeviceId());
106 deviceChannel.setChannelId(mobilePosition.getChannelId()); 91 deviceChannel.setChannelId(mobilePosition.getChannelId());
107 deviceChannel.setLongitude(mobilePosition.getLongitude()); 92 deviceChannel.setLongitude(mobilePosition.getLongitude());
108 deviceChannel.setLatitude(mobilePosition.getLatitude()); 93 deviceChannel.setLatitude(mobilePosition.getLatitude());
109 - deviceChannel.setLongitudeWgs84(mobilePosition.getLongitudeWgs84());  
110 - deviceChannel.setLatitudeWgs84(mobilePosition.getLatitudeWgs84());  
111 - deviceChannel.setLongitudeGcj02(mobilePosition.getLongitudeGcj02());  
112 - deviceChannel.setLatitudeGcj02(mobilePosition.getLatitudeGcj02());  
113 deviceChannel.setGpsTime(mobilePosition.getTime()); 94 deviceChannel.setGpsTime(mobilePosition.getTime());
  95 +
  96 + deviceChannel = deviceChannelService.updateGps(deviceChannel, device);
  97 +
  98 + mobilePosition.setLongitudeWgs84(deviceChannel.getLongitudeWgs84());
  99 + mobilePosition.setLatitudeWgs84(deviceChannel.getLatitudeWgs84());
  100 + mobilePosition.setLongitudeGcj02(deviceChannel.getLongitudeGcj02());
  101 + mobilePosition.setLatitudeGcj02(deviceChannel.getLatitudeGcj02());
  102 +
  103 + if (userSetting.getSavePositionHistory()) {
  104 + storager.insertMobilePosition(mobilePosition);
  105 + }
114 storager.updateChannelPosition(deviceChannel); 106 storager.updateChannelPosition(deviceChannel);
115 //回复 200 OK 107 //回复 200 OK
116 responseAck(evt, Response.OK); 108 responseAck(evt, Response.OK);
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 @@ -70,86 +70,24 @@ public class CatalogQueryMessageHandler extends SIPRequestProcessorParent implem
70 Element snElement = rootElement.element("SN"); 70 Element snElement = rootElement.element("SN");
71 String sn = snElement.getText(); 71 String sn = snElement.getText();
72 // 准备回复通道信息 72 // 准备回复通道信息
73 - List<DeviceChannelInPlatform> deviceChannelInPlatforms = storager.queryChannelListInParentPlatform(parentPlatform.getServerGBId()); 73 + List<DeviceChannel> deviceChannelInPlatforms = storager.queryChannelWithCatalog(parentPlatform.getServerGBId());
74 // 查询关联的直播通道 74 // 查询关联的直播通道
75 - List<GbStream> gbStreams = storager.queryGbStreamListInPlatform(parentPlatform.getServerGBId()); 75 + List<DeviceChannel> gbStreams = storager.queryGbStreamListInPlatform(parentPlatform.getServerGBId());
76 // 回复目录信息 76 // 回复目录信息
77 - List<PlatformCatalog> catalogs = storager.queryCatalogInPlatform(parentPlatform.getServerGBId()); 77 + List<DeviceChannel> catalogs = storager.queryCatalogInPlatform(parentPlatform.getServerGBId());
78 78
79 List<DeviceChannel> allChannels = new ArrayList<>(); 79 List<DeviceChannel> allChannels = new ArrayList<>();
  80 +
80 if (catalogs.size() > 0) { 81 if (catalogs.size() > 0) {
81 - for (PlatformCatalog catalog : catalogs) {  
82 - if (catalog.getParentId().equals(catalog.getPlatformId())) {  
83 - catalog.setParentId(parentPlatform.getDeviceGBId());  
84 - }  
85 - DeviceChannel deviceChannel = new DeviceChannel();  
86 - // 通道的类型,0->国标通道 1->直播流通道 2->业务分组/虚拟组织/行政区划  
87 - deviceChannel.setChannelType(2);  
88 - deviceChannel.setChannelId(catalog.getId());  
89 - deviceChannel.setName(catalog.getName());  
90 - deviceChannel.setDeviceId(parentPlatform.getDeviceGBId());  
91 - deviceChannel.setManufacture("wvp-pro");  
92 - deviceChannel.setStatus(1);  
93 - deviceChannel.setParental(1);  
94 - deviceChannel.setParentId(catalog.getParentId());  
95 - deviceChannel.setRegisterWay(1);  
96 - if (catalog.getParentId() != null && catalog.getParentId().length() < 10) {  
97 - deviceChannel.setCivilCode(catalog.getParentId());  
98 - }else {  
99 - deviceChannel.setCivilCode(parentPlatform.getAdministrativeDivision());  
100 - }  
101 - allChannels.add(deviceChannel);  
102 - } 82 + allChannels.addAll(catalogs);
103 } 83 }
104 // 回复级联的通道 84 // 回复级联的通道
105 if (deviceChannelInPlatforms.size() > 0) { 85 if (deviceChannelInPlatforms.size() > 0) {
106 - for (DeviceChannelInPlatform channel : deviceChannelInPlatforms) {  
107 - if (channel.getCatalogId().equals(parentPlatform.getServerGBId())) {  
108 - channel.setCatalogId(parentPlatform.getDeviceGBId());  
109 - }  
110 - DeviceChannel deviceChannel = storage.queryChannel(channel.getDeviceId(), channel.getChannelId());  
111 - // 通道的类型,0->国标通道 1->直播流通道 2->业务分组/虚拟组织/行政区划  
112 - deviceChannel.setChannelType(0);  
113 - deviceChannel.setParental(0);  
114 - deviceChannel.setParentId(channel.getCatalogId());  
115 - if (channel.getCatalogId() != null && channel.getCatalogId().length() < 10) {  
116 - deviceChannel.setCivilCode(channel.getCatalogId());  
117 - }else {  
118 - deviceChannel.setCivilCode(parentPlatform.getAdministrativeDivision());  
119 - }  
120 - allChannels.add(deviceChannel);  
121 - } 86 + allChannels.addAll(deviceChannelInPlatforms);
122 } 87 }
123 // 回复直播的通道 88 // 回复直播的通道
124 if (gbStreams.size() > 0) { 89 if (gbStreams.size() > 0) {
125 - for (GbStream gbStream : gbStreams) {  
126 - if (gbStream.getCatalogId().equals(parentPlatform.getServerGBId())) {  
127 - gbStream.setCatalogId(null);  
128 - }  
129 - DeviceChannel deviceChannel = new DeviceChannel();  
130 - // 通道的类型,0->国标通道 1->直播流通道 2->业务分组/虚拟组织/行政区划  
131 - deviceChannel.setChannelType(1);  
132 - deviceChannel.setChannelId(gbStream.getGbId());  
133 - deviceChannel.setName(gbStream.getName());  
134 - deviceChannel.setLongitude(gbStream.getLongitude());  
135 - deviceChannel.setLatitude(gbStream.getLatitude());  
136 - deviceChannel.setDeviceId(parentPlatform.getDeviceGBId());  
137 - deviceChannel.setManufacture("wvp-pro");  
138 -// deviceChannel.setStatus(gbStream.isStatus()?1:0);  
139 - deviceChannel.setStatus(1);  
140 - deviceChannel.setParentId(gbStream.getCatalogId());  
141 - deviceChannel.setRegisterWay(1);  
142 - if (gbStream.getCatalogId() != null && gbStream.getCatalogId().length() < 10) {  
143 - deviceChannel.setCivilCode(gbStream.getCatalogId());  
144 - }else {  
145 - deviceChannel.setCivilCode(parentPlatform.getAdministrativeDivision());  
146 - }  
147 - deviceChannel.setModel("live");  
148 - deviceChannel.setOwner("wvp-pro");  
149 - deviceChannel.setParental(0);  
150 - deviceChannel.setSecrecy("0");  
151 - allChannels.add(deviceChannel);  
152 - } 90 + allChannels.addAll(gbStreams);
153 } 91 }
154 if (allChannels.size() > 0) { 92 if (allChannels.size() > 0) {
155 cmderFroPlatform.catalogQuery(allChannels, parentPlatform, sn, fromHeader.getTag()); 93 cmderFroPlatform.catalogQuery(allChannels, parentPlatform, sn, fromHeader.getTag());
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 @@ -125,11 +125,7 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp
125 if (channelDeviceElement == null) { 125 if (channelDeviceElement == null) {
126 continue; 126 continue;
127 } 127 }
128 - //by brewswang  
129 - // if (NumericUtil.isDouble(XmlUtil.getText(itemDevice, "Longitude"))) {//如果包含位置信息,就更新一下位置  
130 - // processNotifyMobilePosition(evt, itemDevice);  
131 - // }  
132 - DeviceChannel deviceChannel = XmlUtil.channelContentHander(itemDevice, device); 128 + DeviceChannel deviceChannel = XmlUtil.channelContentHander(itemDevice, device, null);
133 deviceChannel.setDeviceId(take.getDevice().getDeviceId()); 129 deviceChannel.setDeviceId(take.getDevice().getDeviceId());
134 130
135 channelList.add(deviceChannel); 131 channelList.add(deviceChannel);
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 @@ -87,7 +87,6 @@ public class DeviceInfoResponseMessageHandler extends SIPRequestProcessorParent
87 device.setStreamMode("UDP"); 87 device.setStreamMode("UDP");
88 } 88 }
89 deviceService.updateDevice(device); 89 deviceService.updateDevice(device);
90 -// storager.updateDevice(device);  
91 90
92 RequestMessage msg = new RequestMessage(); 91 RequestMessage msg = new RequestMessage();
93 msg.setKey(key); 92 msg.setKey(key);
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 @@ -7,6 +7,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessag
7 import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler; 7 import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler;
8 import com.genersoft.iot.vmp.gb28181.utils.Coordtransform; 8 import com.genersoft.iot.vmp.gb28181.utils.Coordtransform;
9 import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; 9 import com.genersoft.iot.vmp.gb28181.utils.NumericUtil;
  10 +import com.genersoft.iot.vmp.service.IDeviceChannelService;
10 import com.genersoft.iot.vmp.storager.IVideoManagerStorage; 11 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
11 import com.genersoft.iot.vmp.utils.DateUtil; 12 import com.genersoft.iot.vmp.utils.DateUtil;
12 import com.genersoft.iot.vmp.utils.GpsUtil; 13 import com.genersoft.iot.vmp.utils.GpsUtil;
@@ -42,6 +43,9 @@ public class MobilePositionResponseMessageHandler extends SIPRequestProcessorPar @@ -42,6 +43,9 @@ public class MobilePositionResponseMessageHandler extends SIPRequestProcessorPar
42 @Autowired 43 @Autowired
43 private IVideoManagerStorage storager; 44 private IVideoManagerStorage storager;
44 45
  46 + @Autowired
  47 + private IDeviceChannelService deviceChannelService;
  48 +
45 @Override 49 @Override
46 public void afterPropertiesSet() throws Exception { 50 public void afterPropertiesSet() throws Exception {
47 responseMessageHandler.addHandler(cmdType, this); 51 responseMessageHandler.addHandler(cmdType, this);
@@ -79,38 +83,25 @@ public class MobilePositionResponseMessageHandler extends SIPRequestProcessorPar @@ -79,38 +83,25 @@ public class MobilePositionResponseMessageHandler extends SIPRequestProcessorPar
79 mobilePosition.setAltitude(0.0); 83 mobilePosition.setAltitude(0.0);
80 } 84 }
81 mobilePosition.setReportSource("Mobile Position"); 85 mobilePosition.setReportSource("Mobile Position");
82 - if ("WGS84".equals(device.getGeoCoordSys())) {  
83 - mobilePosition.setLongitudeWgs84(mobilePosition.getLongitude());  
84 - mobilePosition.setLatitudeWgs84(mobilePosition.getLatitude());  
85 - Double[] position = Coordtransform.WGS84ToGCJ02(mobilePosition.getLongitude(), mobilePosition.getLatitude());  
86 - mobilePosition.setLongitudeGcj02(position[0]);  
87 - mobilePosition.setLatitudeGcj02(position[1]);  
88 - }else if ("GCJ02".equals(device.getGeoCoordSys())) {  
89 - mobilePosition.setLongitudeGcj02(mobilePosition.getLongitude());  
90 - mobilePosition.setLatitudeGcj02(mobilePosition.getLatitude());  
91 - Double[] position = Coordtransform.GCJ02ToWGS84(mobilePosition.getLongitude(), mobilePosition.getLatitude());  
92 - mobilePosition.setLongitudeWgs84(position[0]);  
93 - mobilePosition.setLatitudeWgs84(position[1]);  
94 - }else {  
95 - mobilePosition.setLongitudeGcj02(0.00);  
96 - mobilePosition.setLatitudeGcj02(0.00);  
97 - mobilePosition.setLongitudeWgs84(0.00);  
98 - mobilePosition.setLatitudeWgs84(0.00);  
99 - }  
100 - if (userSetting.getSavePositionHistory()) {  
101 - storager.insertMobilePosition(mobilePosition);  
102 - } 86 +
103 // 更新device channel 的经纬度 87 // 更新device channel 的经纬度
104 DeviceChannel deviceChannel = new DeviceChannel(); 88 DeviceChannel deviceChannel = new DeviceChannel();
105 deviceChannel.setDeviceId(device.getDeviceId()); 89 deviceChannel.setDeviceId(device.getDeviceId());
106 deviceChannel.setChannelId(mobilePosition.getChannelId()); 90 deviceChannel.setChannelId(mobilePosition.getChannelId());
107 deviceChannel.setLongitude(mobilePosition.getLongitude()); 91 deviceChannel.setLongitude(mobilePosition.getLongitude());
108 deviceChannel.setLatitude(mobilePosition.getLatitude()); 92 deviceChannel.setLatitude(mobilePosition.getLatitude());
109 - deviceChannel.setLongitudeWgs84(mobilePosition.getLongitudeWgs84());  
110 - deviceChannel.setLatitudeWgs84(mobilePosition.getLatitudeWgs84());  
111 - deviceChannel.setLongitudeGcj02(mobilePosition.getLongitudeGcj02());  
112 - deviceChannel.setLatitudeGcj02(mobilePosition.getLatitudeGcj02());  
113 deviceChannel.setGpsTime(mobilePosition.getTime()); 93 deviceChannel.setGpsTime(mobilePosition.getTime());
  94 +
  95 + deviceChannel = deviceChannelService.updateGps(deviceChannel, device);
  96 +
  97 + mobilePosition.setLongitudeWgs84(deviceChannel.getLongitudeWgs84());
  98 + mobilePosition.setLatitudeWgs84(deviceChannel.getLatitudeWgs84());
  99 + mobilePosition.setLongitudeGcj02(deviceChannel.getLongitudeGcj02());
  100 + mobilePosition.setLatitudeGcj02(deviceChannel.getLatitudeGcj02());
  101 +
  102 + if (userSetting.getSavePositionHistory()) {
  103 + storager.insertMobilePosition(mobilePosition);
  104 + }
114 storager.updateChannelPosition(deviceChannel); 105 storager.updateChannelPosition(deviceChannel);
115 //回复 200 OK 106 //回复 200 OK
116 responseAck(evt, Response.OK); 107 responseAck(evt, Response.OK);
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/PresetQueryResponseMessageHandler.java
1 package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd; 1 package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd;
2 2
3 -import com.genersoft.iot.vmp.domain.req.PresetQuerySipReq; 3 +import com.genersoft.iot.vmp.gb28181.bean.PresetQuerySipReq;
4 import com.genersoft.iot.vmp.gb28181.bean.*; 4 import com.genersoft.iot.vmp.gb28181.bean.*;
5 import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; 5 import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
6 import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; 6 import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java
@@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONArray; @@ -4,6 +4,8 @@ import com.alibaba.fastjson.JSONArray;
4 import com.alibaba.fastjson.JSONObject; 4 import com.alibaba.fastjson.JSONObject;
5 import com.genersoft.iot.vmp.gb28181.bean.Device; 5 import com.genersoft.iot.vmp.gb28181.bean.Device;
6 import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; 6 import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
  7 +import com.genersoft.iot.vmp.gb28181.bean.TreeType;
  8 +import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
7 import com.genersoft.iot.vmp.utils.DateUtil; 9 import com.genersoft.iot.vmp.utils.DateUtil;
8 import org.dom4j.Attribute; 10 import org.dom4j.Attribute;
9 import org.dom4j.Document; 11 import org.dom4j.Document;
@@ -29,7 +31,7 @@ public class XmlUtil { @@ -29,7 +31,7 @@ public class XmlUtil {
29 /** 31 /**
30 * 日志服务 32 * 日志服务
31 */ 33 */
32 - private static Logger LOG = LoggerFactory.getLogger(XmlUtil.class); 34 + private static Logger logger = LoggerFactory.getLogger(XmlUtil.class);
33 35
34 /** 36 /**
35 * 解析XML为Document对象 37 * 解析XML为Document对象
@@ -46,7 +48,7 @@ public class XmlUtil { @@ -46,7 +48,7 @@ public class XmlUtil {
46 try { 48 try {
47 document = saxReader.read(sr); 49 document = saxReader.read(sr);
48 } catch (DocumentException e) { 50 } catch (DocumentException e) {
49 - LOG.error("解析失败", e); 51 + logger.error("解析失败", e);
50 } 52 }
51 return null == document ? null : document.getRootElement(); 53 return null == document ? null : document.getRootElement();
52 } 54 }
@@ -182,47 +184,69 @@ public class XmlUtil { @@ -182,47 +184,69 @@ public class XmlUtil {
182 return xml.getRootElement(); 184 return xml.getRootElement();
183 } 185 }
184 186
185 - public static DeviceChannel channelContentHander(Element itemDevice, Device device){  
186 - Element channdelNameElement = itemDevice.element("Name");  
187 - String channelName = channdelNameElement != null ? channdelNameElement.getTextTrim().toString() : "";  
188 - Element statusElement = itemDevice.element("Status");  
189 - String status = statusElement != null ? statusElement.getTextTrim().toString() : "ON"; 187 + private enum ChannelType{
  188 + CivilCode, BusinessGroup,VirtualOrganization,Other
  189 + }
  190 +
  191 + public static DeviceChannel channelContentHander(Element itemDevice, Device device, String event){
190 DeviceChannel deviceChannel = new DeviceChannel(); 192 DeviceChannel deviceChannel = new DeviceChannel();
191 - deviceChannel.setName(channelName); 193 + deviceChannel.setDeviceId(device.getDeviceId());
192 Element channdelIdElement = itemDevice.element("DeviceID"); 194 Element channdelIdElement = itemDevice.element("DeviceID");
193 - String channelId = channdelIdElement != null ? channdelIdElement.getTextTrim().toString() : ""; 195 + if (channdelIdElement == null) {
  196 + logger.warn("解析Catalog消息时发现缺少 DeviceID");
  197 + return null;
  198 + }
  199 + String channelId = channdelIdElement.getTextTrim();
  200 + if (StringUtils.isEmpty(channelId)) {
  201 + logger.warn("解析Catalog消息时发现缺少 DeviceID");
  202 + return null;
  203 + }
194 deviceChannel.setChannelId(channelId); 204 deviceChannel.setChannelId(channelId);
195 - // ONLINE OFFLINE HIKVISION DS-7716N-E4 NVR的兼容性处理  
196 - if (status.equals("ON") || status.equals("On") || status.equals("ONLINE") || status.equals("OK")) {  
197 - deviceChannel.setStatus(1); 205 + if (event != null && !event.equals(CatalogEvent.ADD) && !event.equals(CatalogEvent.UPDATE)) {
  206 + // 除了ADD和update情况下需要识别全部内容,
  207 + return deviceChannel;
198 } 208 }
199 - if (status.equals("OFF") || status.equals("Off") || status.equals("OFFLINE")) {  
200 - deviceChannel.setStatus(0); 209 +
  210 + ChannelType channelType = ChannelType.Other;
  211 + if (channelId.length() <= 8) {
  212 + channelType = ChannelType.CivilCode;
  213 + }else {
  214 + if (channelId.length() == 20) {
  215 + int code = Integer.parseInt(channelId.substring(10, 13));
  216 + switch (code){
  217 + case 215:
  218 + channelType = ChannelType.BusinessGroup;
  219 + break;
  220 + case 216:
  221 + channelType = ChannelType.VirtualOrganization;
  222 + break;
  223 + default:
  224 + break;
  225 +
  226 + }
  227 + }
201 } 228 }
202 229
203 - deviceChannel.setManufacture(XmlUtil.getText(itemDevice, "Manufacturer"));  
204 - deviceChannel.setModel(XmlUtil.getText(itemDevice, "Model"));  
205 - deviceChannel.setOwner(XmlUtil.getText(itemDevice, "Owner"));  
206 - deviceChannel.setCivilCode(XmlUtil.getText(itemDevice, "CivilCode"));  
207 - deviceChannel.setBlock(XmlUtil.getText(itemDevice, "Block"));  
208 - deviceChannel.setAddress(XmlUtil.getText(itemDevice, "Address"));  
209 - String businessGroupID = XmlUtil.getText(itemDevice, "BusinessGroupID");  
210 - if (XmlUtil.getText(itemDevice, "Parental") == null  
211 - || XmlUtil.getText(itemDevice, "Parental").equals("")) {  
212 - if (deviceChannel.getChannelId().length() <= 10  
213 - || (deviceChannel.getChannelId().length() == 20 && (  
214 - Integer.parseInt(deviceChannel.getChannelId().substring(10, 13)) == 215  
215 - || Integer.parseInt(deviceChannel.getChannelId().substring(10, 13)) == 216  
216 - )  
217 - )  
218 - ) {  
219 - deviceChannel.setParental(1);  
220 - }else {  
221 - deviceChannel.setParental(0); 230 + Element channdelNameElement = itemDevice.element("Name");
  231 + String channelName = channdelNameElement != null ? channdelNameElement.getTextTrim() : "";
  232 + deviceChannel.setName(channelName);
  233 +
  234 + String civilCode = XmlUtil.getText(itemDevice, "CivilCode");
  235 + deviceChannel.setCivilCode(civilCode);
  236 + if (channelType == ChannelType.CivilCode && civilCode == null) {
  237 + deviceChannel.setParental(1);
  238 + // 行政区划如果没有传递具体值,则推测一个
  239 + if (channelId.length() > 2) {
  240 + deviceChannel.setCivilCode(channelId.substring(0, channelId.length() - 2));
222 } 241 }
223 - } else {  
224 - // 由于海康会错误的发送65535作为这里的取值,所以这里除非是0否则认为是1  
225 - deviceChannel.setParental(Integer.parseInt(XmlUtil.getText(itemDevice, "Parental")) == 1?1:0); 242 + }
  243 + if (channelType.equals(ChannelType.CivilCode)) {
  244 + // 行政区划其他字段没必要识别了,默认在线即可
  245 + deviceChannel.setStatus(1);
  246 + deviceChannel.setParental(1);
  247 + deviceChannel.setCreateTime(DateUtil.getNow());
  248 + deviceChannel.setUpdateTime(DateUtil.getNow());
  249 + return deviceChannel;
226 } 250 }
227 /** 251 /**
228 * 行政区划展示设备树与业务分组展示设备树是两种不同的模式 252 * 行政区划展示设备树与业务分组展示设备树是两种不同的模式
@@ -230,7 +254,17 @@ public class XmlUtil { @@ -230,7 +254,17 @@ public class XmlUtil {
230 * 河北省 254 * 河北省
231 * --> 石家庄市 255 * --> 石家庄市
232 * --> 摄像头 256 * --> 摄像头
233 - * --> 正定县 257 + *String parentId = XmlUtil.getText(itemDevice, "ParentID");
  258 + if (parentId != null) {
  259 + if (parentId.contains("/")) {
  260 + String lastParentId = parentId.substring(parentId.lastIndexOf("/") + 1);
  261 + String businessGroup = parentId.substring(0, parentId.indexOf("/"));
  262 + deviceChannel.setParentId(lastParentId);
  263 + }else {
  264 + deviceChannel.setParentId(parentId);
  265 + }
  266 + }
  267 + deviceCh --> 正定县
234 * --> 摄像头 268 * --> 摄像头
235 * --> 摄像头 269 * --> 摄像头
236 * 270 *
@@ -243,59 +277,88 @@ public class XmlUtil { @@ -243,59 +277,88 @@ public class XmlUtil {
243 * --> 摄像头 277 * --> 摄像头
244 */ 278 */
245 String parentId = XmlUtil.getText(itemDevice, "ParentID"); 279 String parentId = XmlUtil.getText(itemDevice, "ParentID");
  280 + String businessGroupID = XmlUtil.getText(itemDevice, "BusinessGroupID");
246 if (parentId != null) { 281 if (parentId != null) {
247 if (parentId.contains("/")) { 282 if (parentId.contains("/")) {
248 String lastParentId = parentId.substring(parentId.lastIndexOf("/") + 1); 283 String lastParentId = parentId.substring(parentId.lastIndexOf("/") + 1);
  284 + if (businessGroupID == null) {
  285 + businessGroupID = parentId.substring(0, parentId.indexOf("/"));
  286 + }
249 deviceChannel.setParentId(lastParentId); 287 deviceChannel.setParentId(lastParentId);
250 }else { 288 }else {
251 deviceChannel.setParentId(parentId); 289 deviceChannel.setParentId(parentId);
252 } 290 }
253 } 291 }
254 deviceChannel.setBusinessGroupId(businessGroupID); 292 deviceChannel.setBusinessGroupId(businessGroupID);
  293 + if (channelType.equals(ChannelType.BusinessGroup) || channelType.equals(ChannelType.VirtualOrganization)) {
  294 + // 业务分组和虚拟组织 其他字段没必要识别了,默认在线即可
  295 + deviceChannel.setStatus(1);
  296 + deviceChannel.setParental(1);
  297 + deviceChannel.setCreateTime(DateUtil.getNow());
  298 + deviceChannel.setUpdateTime(DateUtil.getNow());
  299 + return deviceChannel;
  300 + }
255 301
256 -// else {  
257 -// if (deviceChannel.getChannelId().length() <= 10) { // 此时为行政区划, 上下级行政区划使用DeviceId关联  
258 -// deviceChannel.setParentId(deviceChannel.getChannelId().substring(0, deviceChannel.getChannelId().length() - 2));  
259 -// }else if (deviceChannel.getChannelId().length() == 20) {  
260 -// if (Integer.parseInt(deviceChannel.getChannelId().substring(10, 13)) == 216) { // 虚拟组织  
261 -// deviceChannel.setBusinessGroupId(businessGroupID);  
262 -// }else if (Integer.parseInt(device.getDeviceId().substring(10, 13) )== 118) {//NVR 如果上级设备编号是NVR则直接将NVR的编号设置给通道的上级编号  
263 -// deviceChannel.setParentId(device.getDeviceId());  
264 -// }else if (deviceChannel.getCivilCode() != null) {  
265 -// // 设备, 无parentId的20位是使用CivilCode表示上级的设备,  
266 -// // 注:215 业务分组是需要有parentId的  
267 -// deviceChannel.setParentId(deviceChannel.getCivilCode());  
268 -// }  
269 -// }else {  
270 -// deviceChannel.setParentId(deviceChannel.getDeviceId());  
271 -// }  
272 -// }  
273 -  
274 - if (XmlUtil.getText(itemDevice, "SafetyWay") == null  
275 - || XmlUtil.getText(itemDevice, "SafetyWay") == "") { 302 + Element statusElement = itemDevice.element("Status");
  303 +
  304 + if (statusElement != null) {
  305 + String status = statusElement.getTextTrim().trim();
  306 + // ONLINE OFFLINE HIKVISION DS-7716N-E4 NVR的兼容性处理
  307 + if (status.equals("ON") || status.equals("On") || status.equals("ONLINE") || status.equals("OK")) {
  308 + deviceChannel.setStatus(1);
  309 + }
  310 + if (status.equals("OFF") || status.equals("Off") || status.equals("OFFLINE")) {
  311 + deviceChannel.setStatus(0);
  312 + }
  313 + }else {
  314 + deviceChannel.setStatus(1);
  315 + }
  316 + // 识别自带的目录标识
  317 + String parental = XmlUtil.getText(itemDevice, "Parental");
  318 + // 由于海康会错误的发送65535作为这里的取值,所以这里除非是0否则认为是1
  319 + if (!StringUtils.isEmpty(parental) && parental.length() == 1 && Integer.parseInt(parental) == 0) {
  320 + deviceChannel.setParental(0);
  321 + }else {
  322 + deviceChannel.setParental(1);
  323 + }
  324 +
  325 +
  326 + deviceChannel.setManufacture(XmlUtil.getText(itemDevice, "Manufacturer"));
  327 + deviceChannel.setModel(XmlUtil.getText(itemDevice, "Model"));
  328 + deviceChannel.setOwner(XmlUtil.getText(itemDevice, "Owner"));
  329 + deviceChannel.setCertNum(XmlUtil.getText(itemDevice, "CertNum"));
  330 + deviceChannel.setBlock(XmlUtil.getText(itemDevice, "Block"));
  331 + deviceChannel.setAddress(XmlUtil.getText(itemDevice, "Address"));
  332 + deviceChannel.setPassword(XmlUtil.getText(itemDevice, "Password"));
  333 +
  334 + String safetyWay = XmlUtil.getText(itemDevice, "SafetyWay");
  335 + if (StringUtils.isEmpty(safetyWay)) {
276 deviceChannel.setSafetyWay(0); 336 deviceChannel.setSafetyWay(0);
277 } else { 337 } else {
278 - deviceChannel.setSafetyWay(Integer.parseInt(XmlUtil.getText(itemDevice, "SafetyWay"))); 338 + deviceChannel.setSafetyWay(Integer.parseInt(safetyWay));
279 } 339 }
280 - if (XmlUtil.getText(itemDevice, "RegisterWay") == null  
281 - || XmlUtil.getText(itemDevice, "RegisterWay") == "") { 340 +
  341 + String registerWay = XmlUtil.getText(itemDevice, "RegisterWay");
  342 + if (StringUtils.isEmpty(registerWay)) {
282 deviceChannel.setRegisterWay(1); 343 deviceChannel.setRegisterWay(1);
283 } else { 344 } else {
284 - deviceChannel.setRegisterWay(Integer.parseInt(XmlUtil.getText(itemDevice, "RegisterWay"))); 345 + deviceChannel.setRegisterWay(Integer.parseInt(registerWay));
285 } 346 }
286 - deviceChannel.setCertNum(XmlUtil.getText(itemDevice, "CertNum")); 347 +
287 if (XmlUtil.getText(itemDevice, "Certifiable") == null 348 if (XmlUtil.getText(itemDevice, "Certifiable") == null
288 || XmlUtil.getText(itemDevice, "Certifiable") == "") { 349 || XmlUtil.getText(itemDevice, "Certifiable") == "") {
289 deviceChannel.setCertifiable(0); 350 deviceChannel.setCertifiable(0);
290 } else { 351 } else {
291 deviceChannel.setCertifiable(Integer.parseInt(XmlUtil.getText(itemDevice, "Certifiable"))); 352 deviceChannel.setCertifiable(Integer.parseInt(XmlUtil.getText(itemDevice, "Certifiable")));
292 } 353 }
  354 +
293 if (XmlUtil.getText(itemDevice, "ErrCode") == null 355 if (XmlUtil.getText(itemDevice, "ErrCode") == null
294 || XmlUtil.getText(itemDevice, "ErrCode") == "") { 356 || XmlUtil.getText(itemDevice, "ErrCode") == "") {
295 deviceChannel.setErrCode(0); 357 deviceChannel.setErrCode(0);
296 } else { 358 } else {
297 deviceChannel.setErrCode(Integer.parseInt(XmlUtil.getText(itemDevice, "ErrCode"))); 359 deviceChannel.setErrCode(Integer.parseInt(XmlUtil.getText(itemDevice, "ErrCode")));
298 } 360 }
  361 +
299 deviceChannel.setEndTime(XmlUtil.getText(itemDevice, "EndTime")); 362 deviceChannel.setEndTime(XmlUtil.getText(itemDevice, "EndTime"));
300 deviceChannel.setSecrecy(XmlUtil.getText(itemDevice, "Secrecy")); 363 deviceChannel.setSecrecy(XmlUtil.getText(itemDevice, "Secrecy"));
301 deviceChannel.setIpAddress(XmlUtil.getText(itemDevice, "IPAddress")); 364 deviceChannel.setIpAddress(XmlUtil.getText(itemDevice, "IPAddress"));
@@ -304,43 +367,23 @@ public class XmlUtil { @@ -304,43 +367,23 @@ public class XmlUtil {
304 } else { 367 } else {
305 deviceChannel.setPort(Integer.parseInt(XmlUtil.getText(itemDevice, "Port"))); 368 deviceChannel.setPort(Integer.parseInt(XmlUtil.getText(itemDevice, "Port")));
306 } 369 }
307 - deviceChannel.setPassword(XmlUtil.getText(itemDevice, "Password"));  
308 - if (NumericUtil.isDouble(XmlUtil.getText(itemDevice, "Longitude"))) {  
309 - deviceChannel.setLongitude(Double.parseDouble(XmlUtil.getText(itemDevice, "Longitude"))); 370 +
  371 +
  372 + String longitude = XmlUtil.getText(itemDevice, "Longitude");
  373 + if (NumericUtil.isDouble(longitude)) {
  374 + deviceChannel.setLongitude(Double.parseDouble(longitude));
310 } else { 375 } else {
311 deviceChannel.setLongitude(0.00); 376 deviceChannel.setLongitude(0.00);
312 } 377 }
313 - if (NumericUtil.isDouble(XmlUtil.getText(itemDevice, "Latitude"))) {  
314 - deviceChannel.setLatitude(Double.parseDouble(XmlUtil.getText(itemDevice, "Latitude"))); 378 + String latitude = XmlUtil.getText(itemDevice, "Latitude");
  379 + if (NumericUtil.isDouble(latitude)) {
  380 + deviceChannel.setLatitude(Double.parseDouble(latitude));
315 } else { 381 } else {
316 deviceChannel.setLatitude(0.00); 382 deviceChannel.setLatitude(0.00);
317 } 383 }
318 deviceChannel.setGpsTime(DateUtil.getNow()); 384 deviceChannel.setGpsTime(DateUtil.getNow());
319 - if (deviceChannel.getLongitude()*deviceChannel.getLatitude() > 0) {  
320 - if ("WGS84".equals(device.getGeoCoordSys())) {  
321 - deviceChannel.setLongitudeWgs84(deviceChannel.getLongitude());  
322 - deviceChannel.setLatitudeWgs84(deviceChannel.getLatitude());  
323 - Double[] position = Coordtransform.WGS84ToGCJ02(deviceChannel.getLongitude(), deviceChannel.getLatitude());  
324 - deviceChannel.setLongitudeGcj02(position[0]);  
325 - deviceChannel.setLatitudeGcj02(position[1]);  
326 - }else if ("GCJ02".equals(device.getGeoCoordSys())) {  
327 - deviceChannel.setLongitudeGcj02(deviceChannel.getLongitude());  
328 - deviceChannel.setLatitudeGcj02(deviceChannel.getLatitude());  
329 - Double[] position = Coordtransform.GCJ02ToWGS84(deviceChannel.getLongitude(), deviceChannel.getLatitude());  
330 - deviceChannel.setLongitudeWgs84(position[0]);  
331 - deviceChannel.setLatitudeWgs84(position[1]);  
332 - }else {  
333 - deviceChannel.setLongitudeGcj02(0.00);  
334 - deviceChannel.setLatitudeGcj02(0.00);  
335 - deviceChannel.setLongitudeWgs84(0.00);  
336 - deviceChannel.setLatitudeWgs84(0.00);  
337 - }  
338 - }else {  
339 - deviceChannel.setLongitudeGcj02(deviceChannel.getLongitude());  
340 - deviceChannel.setLatitudeGcj02(deviceChannel.getLatitude());  
341 - deviceChannel.setLongitudeWgs84(deviceChannel.getLongitude());  
342 - deviceChannel.setLatitudeWgs84(deviceChannel.getLatitude());  
343 - } 385 +
  386 +
344 if (XmlUtil.getText(itemDevice, "PTZType") == null || "".equals(XmlUtil.getText(itemDevice, "PTZType"))) { 387 if (XmlUtil.getText(itemDevice, "PTZType") == null || "".equals(XmlUtil.getText(itemDevice, "PTZType"))) {
345 //兼容INFO中的信息 388 //兼容INFO中的信息
346 Element info = itemDevice.element("Info"); 389 Element info = itemDevice.element("Info");
src/main/java/com/genersoft/iot/vmp/media/zlm/AssistRESTfulUtils.java
@@ -136,4 +136,12 @@ public class AssistRESTfulUtils { @@ -136,4 +136,12 @@ public class AssistRESTfulUtils {
136 return sendGet(mediaServerItem, "api/record/file/duration",param, callback); 136 return sendGet(mediaServerItem, "api/record/file/duration",param, callback);
137 } 137 }
138 138
  139 + public JSONObject addStreamCallInfo(MediaServerItem mediaServerItem, String app, String stream, String callId, RequestCallback callback){
  140 + Map<String, Object> param = new HashMap<>();
  141 + param.put("app",app);
  142 + param.put("stream",stream);
  143 + param.put("callId",callId);
  144 + return sendGet(mediaServerItem, "api/record/addStreamCallInfo",param, callback);
  145 + }
  146 +
139 } 147 }
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
1 package com.genersoft.iot.vmp.media.zlm; 1 package com.genersoft.iot.vmp.media.zlm;
2 2
3 -import java.util.ArrayList; 3 +import java.util.HashMap;
4 import java.util.List; 4 import java.util.List;
  5 +import java.util.Map;
5 6
6 import com.alibaba.fastjson.JSON; 7 import com.alibaba.fastjson.JSON;
7 import com.genersoft.iot.vmp.common.StreamInfo; 8 import com.genersoft.iot.vmp.common.StreamInfo;
@@ -21,6 +22,7 @@ import org.slf4j.LoggerFactory; @@ -21,6 +22,7 @@ import org.slf4j.LoggerFactory;
21 import org.springframework.beans.factory.annotation.Autowired; 22 import org.springframework.beans.factory.annotation.Autowired;
22 import org.springframework.http.HttpStatus; 23 import org.springframework.http.HttpStatus;
23 import org.springframework.http.ResponseEntity; 24 import org.springframework.http.ResponseEntity;
  25 +import org.springframework.util.StringUtils;
24 import org.springframework.web.bind.annotation.PostMapping; 26 import org.springframework.web.bind.annotation.PostMapping;
25 import org.springframework.web.bind.annotation.RequestBody; 27 import org.springframework.web.bind.annotation.RequestBody;
26 import org.springframework.web.bind.annotation.RequestMapping; 28 import org.springframework.web.bind.annotation.RequestMapping;
@@ -80,8 +82,14 @@ public class ZLMHttpHookListener { @@ -80,8 +82,14 @@ public class ZLMHttpHookListener {
80 private UserSetting userSetting; 82 private UserSetting userSetting;
81 83
82 @Autowired 84 @Autowired
  85 + private IUserService userService;
  86 +
  87 + @Autowired
83 private VideoStreamSessionManager sessionManager; 88 private VideoStreamSessionManager sessionManager;
84 89
  90 + @Autowired
  91 + private AssistRESTfulUtils assistRESTfulUtils;
  92 +
85 /** 93 /**
86 * 服务器定时上报时间,上报间隔可配置,默认10s上报一次 94 * 服务器定时上报时间,上报间隔可配置,默认10s上报一次
87 * 95 *
@@ -151,12 +159,14 @@ public class ZLMHttpHookListener { @@ -151,12 +159,14 @@ public class ZLMHttpHookListener {
151 */ 159 */
152 @ResponseBody 160 @ResponseBody
153 @PostMapping(value = "/on_play", produces = "application/json;charset=UTF-8") 161 @PostMapping(value = "/on_play", produces = "application/json;charset=UTF-8")
154 - public ResponseEntity<String> onPlay(@RequestBody JSONObject json){  
155 - 162 + public ResponseEntity<String> onPlay(@RequestBody OnPlayHookParam param){
  163 +
  164 + JSONObject json = (JSONObject)JSON.toJSON(param);
  165 +
156 if (logger.isDebugEnabled()) { 166 if (logger.isDebugEnabled()) {
157 - logger.debug("[ ZLM HOOK ]on_play API调用,参数:" + json.toString()); 167 + logger.debug("[ ZLM HOOK ]on_play API调用,参数:" + JSON.toJSONString(param));
158 } 168 }
159 - String mediaServerId = json.getString("mediaServerId"); 169 + String mediaServerId = param.getMediaServerId();
160 ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_play, json); 170 ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_play, json);
161 if (subscribe != null ) { 171 if (subscribe != null ) {
162 MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId); 172 MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId);
@@ -165,9 +175,20 @@ public class ZLMHttpHookListener { @@ -165,9 +175,20 @@ public class ZLMHttpHookListener {
165 } 175 }
166 } 176 }
167 JSONObject ret = new JSONObject(); 177 JSONObject ret = new JSONObject();
  178 + if (!"rtp".equals(param.getApp())) {
  179 + Map<String, String> paramMap = urlParamToMap(param.getParams());
  180 + StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(param.getApp(), param.getStream());
  181 + if (streamAuthorityInfo == null
  182 + || (streamAuthorityInfo.getCallId() != null && !streamAuthorityInfo.getCallId().equals(paramMap.get("callId")))) {
  183 + ret.put("code", 401);
  184 + ret.put("msg", "Unauthorized");
  185 + return new ResponseEntity<>(ret.toString(),HttpStatus.OK);
  186 + }
  187 + }
  188 +
168 ret.put("code", 0); 189 ret.put("code", 0);
169 ret.put("msg", "success"); 190 ret.put("msg", "success");
170 - return new ResponseEntity<String>(ret.toString(),HttpStatus.OK); 191 + return new ResponseEntity<>(ret.toString(),HttpStatus.OK);
171 } 192 }
172 193
173 /** 194 /**
@@ -176,23 +197,61 @@ public class ZLMHttpHookListener { @@ -176,23 +197,61 @@ public class ZLMHttpHookListener {
176 */ 197 */
177 @ResponseBody 198 @ResponseBody
178 @PostMapping(value = "/on_publish", produces = "application/json;charset=UTF-8") 199 @PostMapping(value = "/on_publish", produces = "application/json;charset=UTF-8")
179 - public ResponseEntity<String> onPublish(@RequestBody JSONObject json) { 200 + public ResponseEntity<String> onPublish(@RequestBody OnPublishHookParam param) {
  201 +
  202 + JSONObject json = (JSONObject) JSON.toJSON(param);
180 203
181 logger.info("[ ZLM HOOK ]on_publish API调用,参数:" + json.toString()); 204 logger.info("[ ZLM HOOK ]on_publish API调用,参数:" + json.toString());
182 JSONObject ret = new JSONObject(); 205 JSONObject ret = new JSONObject();
  206 + String mediaServerId = json.getString("mediaServerId");
  207 + MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId);
  208 + if (!"rtp".equals(param.getApp())) {
  209 + // 推流鉴权
  210 + if (param.getParams() == null) {
  211 + logger.info("推流鉴权失败: 缺少不要参数:sign=md5(user表的pushKey)");
  212 + ret.put("code", 401);
  213 + ret.put("msg", "Unauthorized");
  214 + return new ResponseEntity<>(ret.toString(), HttpStatus.OK);
  215 + }
  216 + Map<String, String> paramMap = urlParamToMap(param.getParams());
  217 + String sign = paramMap.get("sign");
  218 + if (sign == null) {
  219 + logger.info("推流鉴权失败: 缺少不要参数:sign=md5(user表的pushKey)");
  220 + ret.put("code", 401);
  221 + ret.put("msg", "Unauthorized");
  222 + return new ResponseEntity<>(ret.toString(), HttpStatus.OK);
  223 + }
  224 + // 推流自定义播放鉴权码
  225 + String callId = paramMap.get("callId");
  226 + // 鉴权配置
  227 + boolean hasAuthority = userService.checkPushAuthority(callId, sign);
  228 + if (!hasAuthority) {
  229 + logger.info("推流鉴权失败: sign 无权限: callId={}. sign={}", callId, sign);
  230 + ret.put("code", 401);
  231 + ret.put("msg", "Unauthorized");
  232 + return new ResponseEntity<>(ret.toString(), HttpStatus.OK);
  233 + }
  234 + StreamAuthorityInfo streamAuthorityInfo = StreamAuthorityInfo.getInstanceByHook(param);
  235 + streamAuthorityInfo.setCallId(callId);
  236 + streamAuthorityInfo.setSign(sign);
  237 + // 鉴权通过
  238 + redisCatchStorage.updateStreamAuthorityInfo(param.getApp(), param.getStream(), streamAuthorityInfo);
  239 + // 通知assist新的callId
  240 + if (mediaInfo != null) {
  241 + assistRESTfulUtils.addStreamCallInfo(mediaInfo, param.getApp(), param.getStream(), callId, null);
  242 + }
  243 + }
  244 +
183 ret.put("code", 0); 245 ret.put("code", 0);
184 ret.put("msg", "success"); 246 ret.put("msg", "success");
185 ret.put("enable_hls", true); 247 ret.put("enable_hls", true);
186 - if (json.getInteger("originType") == 1  
187 - || json.getInteger("originType") == 2  
188 - || json.getInteger("originType") == 3) { 248 + if (!"rtp".equals(param.getApp())) {
189 ret.put("enable_audio", true); 249 ret.put("enable_audio", true);
190 } 250 }
191 251
192 - String mediaServerId = json.getString("mediaServerId"); 252 +
193 ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_publish, json); 253 ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_publish, json);
194 if (subscribe != null) { 254 if (subscribe != null) {
195 - MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId);  
196 if (mediaInfo != null) { 255 if (mediaInfo != null) {
197 subscribe.response(mediaInfo, json); 256 subscribe.response(mediaInfo, json);
198 }else { 257 }else {
@@ -200,14 +259,13 @@ public class ZLMHttpHookListener { @@ -200,14 +259,13 @@ public class ZLMHttpHookListener {
200 ret.put("msg", "zlm not register"); 259 ret.put("msg", "zlm not register");
201 } 260 }
202 } 261 }
203 - String app = json.getString("app");  
204 - String stream = json.getString("stream");  
205 - if ("rtp".equals(app)) { 262 +
  263 + if ("rtp".equals(param.getApp())) {
206 ret.put("enable_mp4", userSetting.getRecordSip()); 264 ret.put("enable_mp4", userSetting.getRecordSip());
207 }else { 265 }else {
208 ret.put("enable_mp4", userSetting.isRecordPushLive()); 266 ret.put("enable_mp4", userSetting.isRecordPushLive());
209 } 267 }
210 - List<SsrcTransaction> ssrcTransactionForAll = sessionManager.getSsrcTransactionForAll(null, null, null, stream); 268 + List<SsrcTransaction> ssrcTransactionForAll = sessionManager.getSsrcTransactionForAll(null, null, null, param.getStream());
211 if (ssrcTransactionForAll != null && ssrcTransactionForAll.size() == 1) { 269 if (ssrcTransactionForAll != null && ssrcTransactionForAll.size() == 1) {
212 String deviceId = ssrcTransactionForAll.get(0).getDeviceId(); 270 String deviceId = ssrcTransactionForAll.get(0).getDeviceId();
213 String channelId = ssrcTransactionForAll.get(0).getChannelId(); 271 String channelId = ssrcTransactionForAll.get(0).getChannelId();
@@ -220,14 +278,17 @@ public class ZLMHttpHookListener { @@ -220,14 +278,17 @@ public class ZLMHttpHookListener {
220 ret.put("mp4_max_second", 10); 278 ret.put("mp4_max_second", 10);
221 ret.put("enable_mp4", true); 279 ret.put("enable_mp4", true);
222 ret.put("enable_audio", true); 280 ret.put("enable_audio", true);
223 - }  
224 281
  282 + }
225 } 283 }
226 284
227 285
  286 +
228 return new ResponseEntity<String>(ret.toString(), HttpStatus.OK); 287 return new ResponseEntity<String>(ret.toString(), HttpStatus.OK);
229 } 288 }
230 - 289 +
  290 +
  291 +
231 /** 292 /**
232 * 录制mp4完成后通知事件;此事件对回复不敏感。 293 * 录制mp4完成后通知事件;此事件对回复不敏感。
233 * 294 *
@@ -312,9 +373,6 @@ public class ZLMHttpHookListener { @@ -312,9 +373,6 @@ public class ZLMHttpHookListener {
312 if (logger.isDebugEnabled()) { 373 if (logger.isDebugEnabled()) {
313 logger.debug("[ ZLM HOOK ]on_shell_login API调用,参数:" + json.toString()); 374 logger.debug("[ ZLM HOOK ]on_shell_login API调用,参数:" + json.toString());
314 } 375 }
315 - // TODO 如果是带有rtpstream则开启按需拉流  
316 - // String app = json.getString("app");  
317 - // String stream = json.getString("stream");  
318 String mediaServerId = json.getString("mediaServerId"); 376 String mediaServerId = json.getString("mediaServerId");
319 ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_shell_login, json); 377 ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_shell_login, json);
320 if (subscribe != null ) { 378 if (subscribe != null ) {
@@ -351,12 +409,24 @@ public class ZLMHttpHookListener { @@ -351,12 +409,24 @@ public class ZLMHttpHookListener {
351 } 409 }
352 // 流消失移除redis play 410 // 流消失移除redis play
353 String app = item.getApp(); 411 String app = item.getApp();
354 - String streamId = item.getStream(); 412 + String stream = item.getStream();
355 String schema = item.getSchema(); 413 String schema = item.getSchema();
356 List<MediaItem.MediaTrack> tracks = item.getTracks(); 414 List<MediaItem.MediaTrack> tracks = item.getTracks();
357 boolean regist = item.isRegist(); 415 boolean regist = item.isRegist();
  416 + if (regist) {
  417 + StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(app, stream);
  418 + if (streamAuthorityInfo == null) {
  419 + streamAuthorityInfo = StreamAuthorityInfo.getInstanceByHook(item);
  420 + }else {
  421 + streamAuthorityInfo.setOriginType(item.getOriginType());
  422 + streamAuthorityInfo.setOriginTypeStr(item.getOriginTypeStr());
  423 + }
  424 + redisCatchStorage.updateStreamAuthorityInfo(app, stream, streamAuthorityInfo);
  425 + }else {
  426 + redisCatchStorage.removeStreamAuthorityInfo(app, stream);
  427 + }
358 if ("rtmp".equals(schema)){ 428 if ("rtmp".equals(schema)){
359 - logger.info("on_stream_changed:注册->{}, app->{}, stream->{}", regist, app, streamId); 429 + logger.info("on_stream_changed:注册->{}, app->{}, stream->{}", regist, app, stream);
360 if (regist) { 430 if (regist) {
361 mediaServerService.addCount(mediaServerId); 431 mediaServerService.addCount(mediaServerId);
362 }else { 432 }else {
@@ -365,15 +435,15 @@ public class ZLMHttpHookListener { @@ -365,15 +435,15 @@ public class ZLMHttpHookListener {
365 if (item.getOriginType() == OriginType.PULL.ordinal() 435 if (item.getOriginType() == OriginType.PULL.ordinal()
366 || item.getOriginType() == OriginType.FFMPEG_PULL.ordinal()) { 436 || item.getOriginType() == OriginType.FFMPEG_PULL.ordinal()) {
367 // 设置拉流代理上线/离线 437 // 设置拉流代理上线/离线
368 - streamProxyService.updateStatus(regist, app, streamId); 438 + streamProxyService.updateStatus(regist, app, stream);
369 } 439 }
370 if ("rtp".equals(app) && !regist ) { 440 if ("rtp".equals(app) && !regist ) {
371 - StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId); 441 + StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(stream);
372 if (streamInfo!=null){ 442 if (streamInfo!=null){
373 redisCatchStorage.stopPlay(streamInfo); 443 redisCatchStorage.stopPlay(streamInfo);
374 storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId()); 444 storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
375 }else{ 445 }else{
376 - streamInfo = redisCatchStorage.queryPlayback(null, null, streamId, null); 446 + streamInfo = redisCatchStorage.queryPlayback(null, null, stream, null);
377 if (streamInfo != null) { 447 if (streamInfo != null) {
378 redisCatchStorage.stopPlayback(streamInfo.getDeviceID(), streamInfo.getChannelId(), 448 redisCatchStorage.stopPlayback(streamInfo.getDeviceID(), streamInfo.getChannelId(),
379 streamInfo.getStream(), null); 449 streamInfo.getStream(), null);
@@ -387,10 +457,12 @@ public class ZLMHttpHookListener { @@ -387,10 +457,12 @@ public class ZLMHttpHookListener {
387 457
388 if (mediaServerItem != null){ 458 if (mediaServerItem != null){
389 if (regist) { 459 if (regist) {
390 - StreamInfo streamInfoByAppAndStream = mediaService.getStreamInfoByAppAndStream(mediaServerItem, app, streamId, tracks); 460 + StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(app, stream);
  461 + StreamInfo streamInfoByAppAndStream = mediaService.getStreamInfoByAppAndStream(mediaServerItem,
  462 + app, stream, tracks, streamAuthorityInfo.getCallId());
391 item.setStreamInfo(streamInfoByAppAndStream); 463 item.setStreamInfo(streamInfoByAppAndStream);
392 -  
393 - redisCatchStorage.addStream(mediaServerItem, type, app, streamId, item); 464 + item.setSeverId(userSetting.getServerId());
  465 + redisCatchStorage.addStream(mediaServerItem, type, app, stream, item);
394 if (item.getOriginType() == OriginType.RTSP_PUSH.ordinal() 466 if (item.getOriginType() == OriginType.RTSP_PUSH.ordinal()
395 || item.getOriginType() == OriginType.RTMP_PUSH.ordinal() 467 || item.getOriginType() == OriginType.RTMP_PUSH.ordinal()
396 || item.getOriginType() == OriginType.RTC_PUSH.ordinal() ) { 468 || item.getOriginType() == OriginType.RTC_PUSH.ordinal() ) {
@@ -413,23 +485,23 @@ public class ZLMHttpHookListener { @@ -413,23 +485,23 @@ public class ZLMHttpHookListener {
413 485
414 }else { 486 }else {
415 // 兼容流注销时类型从redis记录获取 487 // 兼容流注销时类型从redis记录获取
416 - MediaItem mediaItem = redisCatchStorage.getStreamInfo(app, streamId, mediaServerId); 488 + MediaItem mediaItem = redisCatchStorage.getStreamInfo(app, stream, mediaServerId);
417 if (mediaItem != null) { 489 if (mediaItem != null) {
418 type = OriginType.values()[mediaItem.getOriginType()].getType(); 490 type = OriginType.values()[mediaItem.getOriginType()].getType();
419 - redisCatchStorage.removeStream(mediaServerItem.getId(), type, app, streamId); 491 + redisCatchStorage.removeStream(mediaServerItem.getId(), type, app, stream);
420 } 492 }
421 - GbStream gbStream = storager.getGbStream(app, streamId); 493 + GbStream gbStream = storager.getGbStream(app, stream);
422 if (gbStream != null) { 494 if (gbStream != null) {
423 // eventPublisher.catalogEventPublishForStream(null, gbStream, CatalogEvent.OFF); 495 // eventPublisher.catalogEventPublishForStream(null, gbStream, CatalogEvent.OFF);
424 } 496 }
425 - zlmMediaListManager.removeMedia(app, streamId); 497 + zlmMediaListManager.removeMedia(app, stream);
426 } 498 }
427 if (type != null) { 499 if (type != null) {
428 // 发送流变化redis消息 500 // 发送流变化redis消息
429 JSONObject jsonObject = new JSONObject(); 501 JSONObject jsonObject = new JSONObject();
430 jsonObject.put("serverId", userSetting.getServerId()); 502 jsonObject.put("serverId", userSetting.getServerId());
431 jsonObject.put("app", app); 503 jsonObject.put("app", app);
432 - jsonObject.put("stream", streamId); 504 + jsonObject.put("stream", stream);
433 jsonObject.put("register", regist); 505 jsonObject.put("register", regist);
434 jsonObject.put("mediaServerId", mediaServerId); 506 jsonObject.put("mediaServerId", mediaServerId);
435 redisCatchStorage.sendStreamChangeMsg(type, jsonObject); 507 redisCatchStorage.sendStreamChangeMsg(type, jsonObject);
@@ -565,4 +637,22 @@ public class ZLMHttpHookListener { @@ -565,4 +637,22 @@ public class ZLMHttpHookListener {
565 ret.put("msg", "success"); 637 ret.put("msg", "success");
566 return new ResponseEntity<String>(ret.toString(),HttpStatus.OK); 638 return new ResponseEntity<String>(ret.toString(),HttpStatus.OK);
567 } 639 }
  640 +
  641 + private Map<String, String> urlParamToMap(String params) {
  642 + HashMap<String, String> map = new HashMap<>();
  643 + if (StringUtils.isEmpty(params)) {
  644 + return map;
  645 + }
  646 + String[] paramsArray = params.split("&");
  647 + if (paramsArray.length == 0) {
  648 + return map;
  649 + }
  650 + for (String param : paramsArray) {
  651 + String[] paramArray = param.split("=");
  652 + if (paramArray.length == 2){
  653 + map.put(paramArray[0], paramArray[1]);
  654 + }
  655 + }
  656 + return map;
  657 + }
568 } 658 }
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMMediaListManager.java
@@ -115,64 +115,16 @@ public class ZLMMediaListManager { @@ -115,64 +115,16 @@ public class ZLMMediaListManager {
115 public StreamPushItem addPush(MediaItem mediaItem) { 115 public StreamPushItem addPush(MediaItem mediaItem) {
116 // 查找此直播流是否存在redis预设gbId 116 // 查找此直播流是否存在redis预设gbId
117 StreamPushItem transform = streamPushService.transform(mediaItem); 117 StreamPushItem transform = streamPushService.transform(mediaItem);
118 - // 从streamId取出查询关键值  
119 - Pattern pattern = Pattern.compile(userSetting.getThirdPartyGBIdReg());  
120 - Matcher matcher = pattern.matcher(mediaItem.getStream());// 指定要匹配的字符串  
121 - String queryKey = null;  
122 - if (matcher.find()) { //此处find()每次被调用后,会偏移到下一个匹配  
123 - queryKey = matcher.group();  
124 - }  
125 - if (queryKey != null) {  
126 - ThirdPartyGB thirdPartyGB = redisCatchStorage.queryMemberNoGBId(queryKey);  
127 - if (thirdPartyGB != null && !StringUtils.isEmpty(thirdPartyGB.getNationalStandardNo())) {  
128 - transform.setGbId(thirdPartyGB.getNationalStandardNo());  
129 - transform.setName(thirdPartyGB.getName());  
130 - }  
131 - }  
132 - if (!StringUtils.isEmpty(transform.getGbId())) {  
133 - // 如果这个国标ID已经给了其他推流且流已离线,则移除其他推流  
134 - List<GbStream> gbStreams = gbStreamMapper.selectByGBId(transform.getGbId());  
135 - if (gbStreams.size() > 0) {  
136 - for (GbStream gbStream : gbStreams) {  
137 - // 出现使用相同国标Id的视频流时,使用新流替换旧流,  
138 - if (queryKey != null && gbStream.getApp().equals(mediaItem.getApp())) {  
139 - Matcher matcherForStream = pattern.matcher(gbStream.getStream());  
140 - String queryKeyForStream = null;  
141 - if (matcherForStream.find()) { //此处find()每次被调用后,会偏移到下一个匹配  
142 - queryKeyForStream = matcherForStream.group();  
143 - }  
144 - if (queryKeyForStream == null || !queryKeyForStream.equals(queryKey)) {  
145 - // 此时不是同一个流  
146 - gbStreamMapper.del(gbStream.getApp(), gbStream.getStream());  
147 - if (!gbStream.isStatus()) {  
148 - streamPushMapper.del(gbStream.getApp(), gbStream.getStream());  
149 - }  
150 - }  
151 - }  
152 - }  
153 - }  
154 - List<GbStream> gbStreamList = gbStreamMapper.selectByGBId(transform.getGbId());  
155 - if (gbStreamList != null && gbStreamList.size() == 1) {  
156 - transform.setGbStreamId(gbStreamList.get(0).getGbStreamId());  
157 - transform.setPlatformId(gbStreamList.get(0).getPlatformId());  
158 - transform.setCatalogId(gbStreamList.get(0).getCatalogId());  
159 - transform.setGbId(gbStreamList.get(0).getGbId());  
160 - gbStreamMapper.update(transform);  
161 - streamPushMapper.del(gbStreamList.get(0).getApp(), gbStreamList.get(0).getStream());  
162 - }else {  
163 - transform.setCreateTime(DateUtil.getNow());  
164 - transform.setUpdateTime(DateUtil.getNow());  
165 - gbStreamMapper.add(transform);  
166 - }  
167 - if (transform != null) {  
168 - if (channelOnlineEvents.get(transform.getGbId()) != null) {  
169 - channelOnlineEvents.get(transform.getGbId()).run(transform.getApp(), transform.getStream(), transform.getServerId());  
170 - channelOnlineEvents.remove(transform.getGbId());  
171 - }  
172 - } 118 + StreamPushItem pushInDb = streamPushService.getPush(mediaItem.getApp(), mediaItem.getStream());
  119 + transform.setPushIng(true);
  120 + transform.setUpdateTime(DateUtil.getNow());
  121 + transform.setPushTime(DateUtil.getNow());
  122 + if (pushInDb == null) {
  123 + transform.setCreateTime(DateUtil.getNow());
  124 + streamPushMapper.add(transform);
  125 + }else {
  126 + streamPushMapper.update(transform);
173 } 127 }
174 -  
175 - storager.updateMedia(transform);  
176 return transform; 128 return transform;
177 } 129 }
178 130
@@ -206,13 +158,13 @@ public class ZLMMediaListManager { @@ -206,13 +158,13 @@ public class ZLMMediaListManager {
206 158
207 public int removeMedia(String app, String streamId) { 159 public int removeMedia(String app, String streamId) {
208 // 查找是否关联了国标, 关联了不删除, 置为离线 160 // 查找是否关联了国标, 关联了不删除, 置为离线
209 - StreamProxyItem streamProxyItem = gbStreamMapper.selectOne(app, streamId);  
210 - int result = 0;  
211 - if (streamProxyItem == null) { 161 + GbStream gbStream = gbStreamMapper.selectOne(app, streamId);
  162 + int result;
  163 + if (gbStream == null) {
212 result = storager.removeMedia(app, streamId); 164 result = storager.removeMedia(app, streamId);
213 }else { 165 }else {
214 // TODO 暂不设置为离线 166 // TODO 暂不设置为离线
215 - result =storager.mediaOutline(app, streamId); 167 + result =storager.mediaOffline(app, streamId);
216 } 168 }
217 return result; 169 return result;
218 } 170 }
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java
@@ -66,7 +66,7 @@ public class ZLMRTPServerFactory { @@ -66,7 +66,7 @@ public class ZLMRTPServerFactory {
66 String stream = UUID.randomUUID().toString(); 66 String stream = UUID.randomUUID().toString();
67 param.put("enable_tcp", 1); 67 param.put("enable_tcp", 1);
68 param.put("stream_id", stream); 68 param.put("stream_id", stream);
69 - param.put("port", 0); 69 +// param.put("port", 0);
70 JSONObject openRtpServerResultJson = zlmresTfulUtils.openRtpServer(mediaServerItem, param); 70 JSONObject openRtpServerResultJson = zlmresTfulUtils.openRtpServer(mediaServerItem, param);
71 71
72 if (openRtpServerResultJson != null) { 72 if (openRtpServerResultJson != null) {
@@ -101,9 +101,10 @@ public class ZLMRTPServerFactory { @@ -101,9 +101,10 @@ public class ZLMRTPServerFactory {
101 } 101 }
102 102
103 Map<String, Object> param = new HashMap<>(); 103 Map<String, Object> param = new HashMap<>();
104 - // 推流端口设置0则使用随机端口 104 +
105 param.put("enable_tcp", 1); 105 param.put("enable_tcp", 1);
106 param.put("stream_id", streamId); 106 param.put("stream_id", streamId);
  107 + // 推流端口设置0则使用随机端口
107 param.put("port", 0); 108 param.put("port", 0);
108 param.put("ssrc", ssrc); 109 param.put("ssrc", ssrc);
109 JSONObject openRtpServerResultJson = zlmresTfulUtils.openRtpServer(mediaServerItem, param); 110 JSONObject openRtpServerResultJson = zlmresTfulUtils.openRtpServer(mediaServerItem, param);
@@ -291,7 +292,7 @@ public class ZLMRTPServerFactory { @@ -291,7 +292,7 @@ public class ZLMRTPServerFactory {
291 logger.warn("查询流({}/{})是否有其它观看者时得到: {}", app, streamId, mediaInfo.getString("msg")); 292 logger.warn("查询流({}/{})是否有其它观看者时得到: {}", app, streamId, mediaInfo.getString("msg"));
292 return -1; 293 return -1;
293 } 294 }
294 - if ( code == 0 && ! mediaInfo.getBoolean("online")) { 295 + if ( code == 0 && mediaInfo.getBoolean("online") != null && !mediaInfo.getBoolean("online")) {
295 logger.warn("查询流({}/{})是否有其它观看者时得到: {}", app, streamId, mediaInfo.getString("msg")); 296 logger.warn("查询流({}/{})是否有其它观看者时得到: {}", app, streamId, mediaInfo.getString("msg"));
296 return -1; 297 return -1;
297 } 298 }
src/main/java/com/genersoft/iot/vmp/media/zlm/dto/HookParam.java 0 → 100644
  1 +package com.genersoft.iot.vmp.media.zlm.dto;
  2 +
  3 +/**
  4 + * zlm hook事件的参数
  5 + * @author lin
  6 + */
  7 +public class HookParam {
  8 + private String mediaServerId;
  9 +
  10 + public String getMediaServerId() {
  11 + return mediaServerId;
  12 + }
  13 +
  14 + public void setMediaServerId(String mediaServerId) {
  15 + this.mediaServerId = mediaServerId;
  16 + }
  17 +}
src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaItem.java
@@ -4,6 +4,9 @@ import com.genersoft.iot.vmp.common.StreamInfo; @@ -4,6 +4,9 @@ import com.genersoft.iot.vmp.common.StreamInfo;
4 4
5 import java.util.List; 5 import java.util.List;
6 6
  7 +/**
  8 + * @author lin
  9 + */
7 public class MediaItem { 10 public class MediaItem {
8 11
9 /** 12 /**
@@ -22,6 +25,11 @@ public class MediaItem { @@ -22,6 +25,11 @@ public class MediaItem {
22 private String stream; 25 private String stream;
23 26
24 /** 27 /**
  28 + * 推流鉴权Id
  29 + */
  30 + private String callId;
  31 +
  32 + /**
25 * 观看总人数,包括hls/rtsp/rtmp/http-flv/ws-flv 33 * 观看总人数,包括hls/rtsp/rtmp/http-flv/ws-flv
26 */ 34 */
27 private String totalReaderCount; 35 private String totalReaderCount;
@@ -427,4 +435,12 @@ public class MediaItem { @@ -427,4 +435,12 @@ public class MediaItem {
427 public void setSeverId(String severId) { 435 public void setSeverId(String severId) {
428 this.severId = severId; 436 this.severId = severId;
429 } 437 }
  438 +
  439 + public String getCallId() {
  440 + return callId;
  441 + }
  442 +
  443 + public void setCallId(String callId) {
  444 + this.callId = callId;
  445 + }
430 } 446 }
src/main/java/com/genersoft/iot/vmp/media/zlm/dto/OnPlayHookParam.java 0 → 100644
  1 +package com.genersoft.iot.vmp.media.zlm.dto;
  2 +
  3 +/**
  4 + * zlm hook事件中的on_play事件的参数
  5 + * @author lin
  6 + */
  7 +public class OnPlayHookParam extends HookParam{
  8 + private String id;
  9 + private String app;
  10 + private String stream;
  11 + private String ip;
  12 + private String params;
  13 + private int port;
  14 + private String schema;
  15 + private String vhost;
  16 +
  17 +
  18 + public String getId() {
  19 + return id;
  20 + }
  21 +
  22 + public void setId(String id) {
  23 + this.id = id;
  24 + }
  25 +
  26 + public String getApp() {
  27 + return app;
  28 + }
  29 +
  30 + public void setApp(String app) {
  31 + this.app = app;
  32 + }
  33 +
  34 + public String getStream() {
  35 + return stream;
  36 + }
  37 +
  38 + public void setStream(String stream) {
  39 + this.stream = stream;
  40 + }
  41 +
  42 + public String getIp() {
  43 + return ip;
  44 + }
  45 +
  46 + public void setIp(String ip) {
  47 + this.ip = ip;
  48 + }
  49 +
  50 + public String getParams() {
  51 + return params;
  52 + }
  53 +
  54 + public void setParams(String params) {
  55 + this.params = params;
  56 + }
  57 +
  58 + public int getPort() {
  59 + return port;
  60 + }
  61 +
  62 + public void setPort(int port) {
  63 + this.port = port;
  64 + }
  65 +
  66 + public String getSchema() {
  67 + return schema;
  68 + }
  69 +
  70 + public void setSchema(String schema) {
  71 + this.schema = schema;
  72 + }
  73 +
  74 + public String getVhost() {
  75 + return vhost;
  76 + }
  77 +
  78 + public void setVhost(String vhost) {
  79 + this.vhost = vhost;
  80 + }
  81 +
  82 +}
src/main/java/com/genersoft/iot/vmp/media/zlm/dto/OnPublishHookParam.java 0 → 100644
  1 +package com.genersoft.iot.vmp.media.zlm.dto;
  2 +
  3 +/**
  4 + * zlm hook事件中的on_publish事件的参数
  5 + * @author lin
  6 + */
  7 +public class OnPublishHookParam extends HookParam{
  8 + private String id;
  9 + private String app;
  10 + private String stream;
  11 + private String ip;
  12 + private String params;
  13 + private int port;
  14 + private String schema;
  15 + private String vhost;
  16 +
  17 +
  18 + public String getId() {
  19 + return id;
  20 + }
  21 +
  22 + public void setId(String id) {
  23 + this.id = id;
  24 + }
  25 +
  26 + public String getApp() {
  27 + return app;
  28 + }
  29 +
  30 + public void setApp(String app) {
  31 + this.app = app;
  32 + }
  33 +
  34 + public String getStream() {
  35 + return stream;
  36 + }
  37 +
  38 + public void setStream(String stream) {
  39 + this.stream = stream;
  40 + }
  41 +
  42 + public String getIp() {
  43 + return ip;
  44 + }
  45 +
  46 + public void setIp(String ip) {
  47 + this.ip = ip;
  48 + }
  49 +
  50 + public String getParams() {
  51 + return params;
  52 + }
  53 +
  54 + public void setParams(String params) {
  55 + this.params = params;
  56 + }
  57 +
  58 + public int getPort() {
  59 + return port;
  60 + }
  61 +
  62 + public void setPort(int port) {
  63 + this.port = port;
  64 + }
  65 +
  66 + public String getSchema() {
  67 + return schema;
  68 + }
  69 +
  70 + public void setSchema(String schema) {
  71 + this.schema = schema;
  72 + }
  73 +
  74 + public String getVhost() {
  75 + return vhost;
  76 + }
  77 +
  78 + public void setVhost(String vhost) {
  79 + this.vhost = vhost;
  80 + }
  81 +
  82 +}
src/main/java/com/genersoft/iot/vmp/media/zlm/dto/StreamAuthorityInfo.java 0 → 100644
  1 +package com.genersoft.iot.vmp.media.zlm.dto;
  2 +
  3 +/**
  4 + * 流的鉴权信息
  5 + * @author lin
  6 + */
  7 +public class StreamAuthorityInfo {
  8 +
  9 + private String id;
  10 + private String app;
  11 + private String stream;
  12 +
  13 + /**
  14 + * 产生源类型,
  15 + * unknown = 0,
  16 + * rtmp_push=1,
  17 + * rtsp_push=2,
  18 + * rtp_push=3,
  19 + * pull=4,
  20 + * ffmpeg_pull=5,
  21 + * mp4_vod=6,
  22 + * device_chn=7
  23 + */
  24 + private int originType;
  25 +
  26 + /**
  27 + * 产生源类型的字符串描述
  28 + */
  29 + private String originTypeStr;
  30 +
  31 + /**
  32 + * 推流时自定义的播放鉴权ID
  33 + */
  34 + private String callId;
  35 +
  36 + /**
  37 + * 推流的鉴权签名
  38 + */
  39 + private String sign;
  40 +
  41 + public String getId() {
  42 + return id;
  43 + }
  44 +
  45 + public void setId(String id) {
  46 + this.id = id;
  47 + }
  48 +
  49 + public String getApp() {
  50 + return app;
  51 + }
  52 +
  53 + public void setApp(String app) {
  54 + this.app = app;
  55 + }
  56 +
  57 + public String getStream() {
  58 + return stream;
  59 + }
  60 +
  61 + public void setStream(String stream) {
  62 + this.stream = stream;
  63 + }
  64 +
  65 + public int getOriginType() {
  66 + return originType;
  67 + }
  68 +
  69 + public void setOriginType(int originType) {
  70 + this.originType = originType;
  71 + }
  72 +
  73 + public String getOriginTypeStr() {
  74 + return originTypeStr;
  75 + }
  76 +
  77 + public void setOriginTypeStr(String originTypeStr) {
  78 + this.originTypeStr = originTypeStr;
  79 + }
  80 +
  81 + public String getCallId() {
  82 + return callId;
  83 + }
  84 +
  85 + public void setCallId(String callId) {
  86 + this.callId = callId;
  87 + }
  88 +
  89 + public String getSign() {
  90 + return sign;
  91 + }
  92 +
  93 + public void setSign(String sign) {
  94 + this.sign = sign;
  95 + }
  96 +
  97 + public static StreamAuthorityInfo getInstanceByHook(OnPublishHookParam hookParam) {
  98 + StreamAuthorityInfo streamAuthorityInfo = new StreamAuthorityInfo();
  99 + streamAuthorityInfo.setApp(hookParam.getApp());
  100 + streamAuthorityInfo.setStream(hookParam.getStream());
  101 + streamAuthorityInfo.setId(hookParam.getId());
  102 + return streamAuthorityInfo;
  103 + }
  104 +
  105 + public static StreamAuthorityInfo getInstanceByHook(MediaItem mediaItem) {
  106 + StreamAuthorityInfo streamAuthorityInfo = new StreamAuthorityInfo();
  107 + streamAuthorityInfo.setApp(mediaItem.getApp());
  108 + streamAuthorityInfo.setStream(mediaItem.getStream());
  109 + streamAuthorityInfo.setId(mediaItem.getMediaServerId());
  110 + streamAuthorityInfo.setOriginType(mediaItem.getOriginType());
  111 + streamAuthorityInfo.setOriginTypeStr(mediaItem.getOriginTypeStr());
  112 + return streamAuthorityInfo;
  113 + }
  114 +}
src/main/java/com/genersoft/iot/vmp/media/zlm/dto/StreamPushItem.java
@@ -103,6 +103,11 @@ public class StreamPushItem extends GbStream implements Comparable&lt;StreamPushIte @@ -103,6 +103,11 @@ public class StreamPushItem extends GbStream implements Comparable&lt;StreamPushIte
103 */ 103 */
104 private String createTime; 104 private String createTime;
105 105
  106 + /**
  107 + * 是否正在推流
  108 + */
  109 + private boolean pushIng;
  110 +
106 public String getVhost() { 111 public String getVhost() {
107 return vhost; 112 return vhost;
108 } 113 }
@@ -277,5 +282,13 @@ public class StreamPushItem extends GbStream implements Comparable&lt;StreamPushIte @@ -277,5 +282,13 @@ public class StreamPushItem extends GbStream implements Comparable&lt;StreamPushIte
277 public void setCreateTime(String createTime) { 282 public void setCreateTime(String createTime) {
278 this.createTime = createTime; 283 this.createTime = createTime;
279 } 284 }
  285 +
  286 + public boolean isPushIng() {
  287 + return pushIng;
  288 + }
  289 +
  290 + public void setPushIng(boolean pushIng) {
  291 + this.pushIng = pushIng;
  292 + }
280 } 293 }
281 294
src/main/java/com/genersoft/iot/vmp/service/IDeviceChannelService.java 0 → 100644
  1 +package com.genersoft.iot.vmp.service;
  2 +
  3 +import com.genersoft.iot.vmp.gb28181.bean.Device;
  4 +import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
  5 +
  6 +import java.util.List;
  7 +
  8 +/**
  9 + * 国标通道业务类
  10 + * @author lin
  11 + */
  12 +public interface IDeviceChannelService {
  13 +
  14 + /**
  15 + * 更新gps信息
  16 + */
  17 + DeviceChannel updateGps(DeviceChannel deviceChannel, Device device);
  18 +
  19 + /**
  20 + * 添加设备通道
  21 + *
  22 + * @param deviceId 设备id
  23 + * @param channel 通道
  24 + */
  25 + void updateChannel(String deviceId, DeviceChannel channel);
  26 +
  27 + /**
  28 + * 批量添加设备通道
  29 + *
  30 + * @param deviceId 设备id
  31 + * @param channels 多个通道
  32 + */
  33 + int updateChannels(String deviceId, List<DeviceChannel> channels);
  34 +
  35 +}
src/main/java/com/genersoft/iot/vmp/service/IGbStreamService.java
@@ -18,7 +18,7 @@ public interface IGbStreamService { @@ -18,7 +18,7 @@ public interface IGbStreamService {
18 * @param count 18 * @param count
19 * @return 19 * @return
20 */ 20 */
21 - PageInfo<GbStream> getAll(Integer page, Integer count, String platFormId, String catalogId,String query,Boolean pushing,String mediaServerId); 21 + PageInfo<GbStream> getAll(Integer page, Integer count, String platFormId, String catalogId,String query,String mediaServerId);
22 22
23 23
24 /** 24 /**
src/main/java/com/genersoft/iot/vmp/service/IMediaService.java
@@ -15,7 +15,7 @@ public interface IMediaService { @@ -15,7 +15,7 @@ public interface IMediaService {
15 * @param stream 15 * @param stream
16 * @return 16 * @return
17 */ 17 */
18 - StreamInfo getStreamInfoByAppAndStreamWithCheck(String app, String stream, String mediaServerId,String addr); 18 + StreamInfo getStreamInfoByAppAndStreamWithCheck(String app, String stream, String mediaServerId,String addr, boolean authority);
19 19
20 20
21 /** 21 /**
@@ -24,7 +24,7 @@ public interface IMediaService { @@ -24,7 +24,7 @@ public interface IMediaService {
24 * @param stream 24 * @param stream
25 * @return 25 * @return
26 */ 26 */
27 - StreamInfo getStreamInfoByAppAndStreamWithCheck(String app, String stream, String mediaServerId); 27 + StreamInfo getStreamInfoByAppAndStreamWithCheck(String app, String stream, String mediaServerId, boolean authority);
28 28
29 /** 29 /**
30 * 根据应用名和流ID获取播放地址, 只是地址拼接 30 * 根据应用名和流ID获取播放地址, 只是地址拼接
@@ -32,7 +32,7 @@ public interface IMediaService { @@ -32,7 +32,7 @@ public interface IMediaService {
32 * @param stream 32 * @param stream
33 * @return 33 * @return
34 */ 34 */
35 - StreamInfo getStreamInfoByAppAndStream(MediaServerItem mediaServerItem, String app, String stream, Object tracks); 35 + StreamInfo getStreamInfoByAppAndStream(MediaServerItem mediaServerItem, String app, String stream, Object tracks, String callId);
36 36
37 /** 37 /**
38 * 根据应用名和流ID获取播放地址, 只是地址拼接,返回的ip使用远程访问ip,适用与zlm与wvp在一台主机的情况 38 * 根据应用名和流ID获取播放地址, 只是地址拼接,返回的ip使用远程访问ip,适用与zlm与wvp在一台主机的情况
@@ -40,5 +40,5 @@ public interface IMediaService { @@ -40,5 +40,5 @@ public interface IMediaService {
40 * @param stream 40 * @param stream
41 * @return 41 * @return
42 */ 42 */
43 - StreamInfo getStreamInfoByAppAndStream(MediaServerItem mediaInfo, String app, String stream, Object tracks, String addr); 43 + StreamInfo getStreamInfoByAppAndStream(MediaServerItem mediaInfo, String app, String stream, Object tracks, String addr, String callId);
44 } 44 }
src/main/java/com/genersoft/iot/vmp/service/IPlatformChannelService.java 0 → 100644
  1 +package com.genersoft.iot.vmp.service;
  2 +
  3 +import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce;
  4 +
  5 +import java.util.List;
  6 +
  7 +/**
  8 + * 平台关联通道管理
  9 + * @author lin
  10 + */
  11 +public interface IPlatformChannelService {
  12 +
  13 + /**
  14 + * 更新目录下的通道
  15 + * @param platformId 平台编号
  16 + * @param channelReduces 通道信息
  17 + * @param catalogId 目录编号
  18 + * @return
  19 + */
  20 + int updateChannelForGB(String platformId, List<ChannelReduce> channelReduces, String catalogId);
  21 +
  22 +}
src/main/java/com/genersoft/iot/vmp/service/IStreamProxyService.java
@@ -101,4 +101,9 @@ public interface IStreamProxyService { @@ -101,4 +101,9 @@ public interface IStreamProxyService {
101 void zlmServerOffline(String mediaServerId); 101 void zlmServerOffline(String mediaServerId);
102 102
103 void clean(); 103 void clean();
  104 +
  105 + /**
  106 + * 更新代理流
  107 + */
  108 + boolean updateStreamProxy(StreamProxyItem streamProxyItem);
104 } 109 }
src/main/java/com/genersoft/iot/vmp/service/IStreamPushService.java
@@ -5,6 +5,7 @@ import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig; @@ -5,6 +5,7 @@ import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig;
5 import com.genersoft.iot.vmp.media.zlm.dto.MediaItem; 5 import com.genersoft.iot.vmp.media.zlm.dto.MediaItem;
6 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; 6 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
7 import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; 7 import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
  8 +import com.genersoft.iot.vmp.service.bean.StreamPushItemFromRedis;
8 import com.genersoft.iot.vmp.vmanager.bean.StreamPushExcelDto; 9 import com.genersoft.iot.vmp.vmanager.bean.StreamPushExcelDto;
9 import com.github.pagehelper.PageInfo; 10 import com.github.pagehelper.PageInfo;
10 11
@@ -44,31 +45,55 @@ public interface IStreamPushService { @@ -44,31 +45,55 @@ public interface IStreamPushService {
44 * 停止一路推流 45 * 停止一路推流
45 * @param app 应用名 46 * @param app 应用名
46 * @param streamId 流ID 47 * @param streamId 流ID
47 - * @return  
48 */ 48 */
49 boolean stop(String app, String streamId); 49 boolean stop(String app, String streamId);
50 50
51 /** 51 /**
52 * 新的节点加入 52 * 新的节点加入
53 - * @param mediaServerId  
54 - * @return  
55 */ 53 */
56 void zlmServerOnline(String mediaServerId); 54 void zlmServerOnline(String mediaServerId);
57 55
58 /** 56 /**
59 * 节点离线 57 * 节点离线
60 - * @param mediaServerId  
61 - * @return  
62 */ 58 */
63 void zlmServerOffline(String mediaServerId); 59 void zlmServerOffline(String mediaServerId);
64 60
  61 + /**
  62 + * 清空
  63 + */
65 void clean(); 64 void clean();
66 65
  66 +
67 boolean saveToRandomGB(); 67 boolean saveToRandomGB();
68 68
  69 + /**
  70 + * 批量添加
  71 + */
69 void batchAdd(List<StreamPushItem> streamPushExcelDtoList); 72 void batchAdd(List<StreamPushItem> streamPushExcelDtoList);
70 73
  74 + /**
  75 + * 中止多个推流
  76 + */
71 boolean batchStop(List<GbStream> streamPushItems); 77 boolean batchStop(List<GbStream> streamPushItems);
72 78
  79 + /**
  80 + * 导入时批量增加
  81 + */
73 void batchAddForUpload(List<StreamPushItem> streamPushItems, Map<String, List<String[]>> streamPushItemsForAll); 82 void batchAddForUpload(List<StreamPushItem> streamPushItems, Map<String, List<String[]>> streamPushItemsForAll);
  83 +
  84 + /**
  85 + * 全部离线
  86 + */
  87 + void allStreamOffline();
  88 +
  89 + /**
  90 + * 推流离线
  91 + */
  92 + void offline(List<StreamPushItemFromRedis> offlineStreams);
  93 +
  94 + /**
  95 + * 推流上线
  96 + */
  97 + void online(List<StreamPushItemFromRedis> onlineStreams);
  98 +
74 } 99 }
src/main/java/com/genersoft/iot/vmp/service/IUserService.java
1 package com.genersoft.iot.vmp.service; 1 package com.genersoft.iot.vmp.service;
2 2
3 import com.genersoft.iot.vmp.storager.dao.dto.User; 3 import com.genersoft.iot.vmp.storager.dao.dto.User;
  4 +import com.github.pagehelper.PageInfo;
4 5
5 import java.util.List; 6 import java.util.List;
6 7
@@ -19,4 +20,10 @@ public interface IUserService { @@ -19,4 +20,10 @@ public interface IUserService {
19 List<User> getAllUsers(); 20 List<User> getAllUsers();
20 21
21 int updateUsers(User user); 22 int updateUsers(User user);
  23 +
  24 + boolean checkPushAuthority(String callId, String sign);
  25 +
  26 + PageInfo<User> getUsers(int page, int count);
  27 +
  28 + int changePushKey(int id, String pushKey);
22 } 29 }
src/main/java/com/genersoft/iot/vmp/service/bean/PushStreamStatusChangeFromRedisDto.java 0 → 100644
  1 +package com.genersoft.iot.vmp.service.bean;
  2 +
  3 +import java.util.List;
  4 +
  5 +/**
  6 + * 收到redis通知修改推流通道状态
  7 + * @author lin
  8 + */
  9 +public class PushStreamStatusChangeFromRedisDto {
  10 +
  11 + private boolean setAllOffline;
  12 +
  13 + private List<StreamPushItemFromRedis> onlineStreams;
  14 +
  15 + private List<StreamPushItemFromRedis> offlineStreams;
  16 +
  17 +
  18 + public boolean isSetAllOffline() {
  19 + return setAllOffline;
  20 + }
  21 +
  22 + public void setSetAllOffline(boolean setAllOffline) {
  23 + this.setAllOffline = setAllOffline;
  24 + }
  25 +
  26 + public List<StreamPushItemFromRedis> getOnlineStreams() {
  27 + return onlineStreams;
  28 + }
  29 +
  30 + public void setOnlineStreams(List<StreamPushItemFromRedis> onlineStreams) {
  31 + this.onlineStreams = onlineStreams;
  32 + }
  33 +
  34 + public List<StreamPushItemFromRedis> getOfflineStreams() {
  35 + return offlineStreams;
  36 + }
  37 +
  38 + public void setOfflineStreams(List<StreamPushItemFromRedis> offlineStreams) {
  39 + this.offlineStreams = offlineStreams;
  40 + }
  41 +}
src/main/java/com/genersoft/iot/vmp/service/bean/StreamPushItemFromRedis.java 0 → 100644
  1 +package com.genersoft.iot.vmp.service.bean;
  2 +
  3 +
  4 +public class StreamPushItemFromRedis {
  5 + private String app;
  6 + private String stream;
  7 + private long timeStamp;
  8 +
  9 + public String getApp() {
  10 + return app;
  11 + }
  12 +
  13 + public void setApp(String app) {
  14 + this.app = app;
  15 + }
  16 +
  17 + public String getStream() {
  18 + return stream;
  19 + }
  20 +
  21 + public void setStream(String stream) {
  22 + this.stream = stream;
  23 + }
  24 +
  25 + public long getTimeStamp() {
  26 + return timeStamp;
  27 + }
  28 +
  29 + public void setTimeStamp(long timeStamp) {
  30 + this.timeStamp = timeStamp;
  31 + }
  32 +}
  33 +
  34 +
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceAlarmServiceImpl.java
@@ -17,7 +17,6 @@ public class DeviceAlarmServiceImpl implements IDeviceAlarmService { @@ -17,7 +17,6 @@ public class DeviceAlarmServiceImpl implements IDeviceAlarmService {
17 @Autowired 17 @Autowired
18 private DeviceAlarmMapper deviceAlarmMapper; 18 private DeviceAlarmMapper deviceAlarmMapper;
19 19
20 -  
21 @Override 20 @Override
22 public PageInfo<DeviceAlarm> getAllAlarm(int page, int count, String deviceId, String alarmPriority, String alarmMethod, String alarmType, String startTime, String endTime) { 21 public PageInfo<DeviceAlarm> getAllAlarm(int page, int count, String deviceId, String alarmPriority, String alarmMethod, String alarmType, String startTime, String endTime) {
23 PageHelper.startPage(page, count); 22 PageHelper.startPage(page, count);
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java 0 → 100644
  1 +package com.genersoft.iot.vmp.service.impl;
  2 +
  3 +import com.genersoft.iot.vmp.common.StreamInfo;
  4 +import com.genersoft.iot.vmp.gb28181.bean.Device;
  5 +import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
  6 +import com.genersoft.iot.vmp.gb28181.utils.Coordtransform;
  7 +import com.genersoft.iot.vmp.service.IDeviceChannelService;
  8 +import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
  9 +import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper;
  10 +import com.genersoft.iot.vmp.storager.dao.DeviceMapper;
  11 +import com.genersoft.iot.vmp.utils.DateUtil;
  12 +import org.slf4j.Logger;
  13 +import org.slf4j.LoggerFactory;
  14 +import org.springframework.beans.factory.annotation.Autowired;
  15 +import org.springframework.stereotype.Service;
  16 +
  17 +import java.util.ArrayList;
  18 +import java.util.HashMap;
  19 +import java.util.List;
  20 +
  21 +/**
  22 + * @author lin
  23 + */
  24 +@Service
  25 +public class DeviceChannelServiceImpl implements IDeviceChannelService {
  26 +
  27 + private final static Logger logger = LoggerFactory.getLogger(DeviceChannelServiceImpl.class);
  28 +
  29 + @Autowired
  30 + private IRedisCatchStorage redisCatchStorage;
  31 +
  32 + @Autowired
  33 + private DeviceChannelMapper channelMapper;
  34 +
  35 + @Autowired
  36 + private DeviceMapper deviceMapper;
  37 +
  38 + @Override
  39 + public DeviceChannel updateGps(DeviceChannel deviceChannel, Device device) {
  40 + if (deviceChannel.getLongitude()*deviceChannel.getLatitude() > 0) {
  41 + if (device == null) {
  42 + device = deviceMapper.getDeviceByDeviceId(deviceChannel.getDeviceId());
  43 + }
  44 +
  45 + if ("WGS84".equals(device.getGeoCoordSys())) {
  46 + deviceChannel.setLongitudeWgs84(deviceChannel.getLongitude());
  47 + deviceChannel.setLatitudeWgs84(deviceChannel.getLatitude());
  48 + Double[] position = Coordtransform.WGS84ToGCJ02(deviceChannel.getLongitude(), deviceChannel.getLatitude());
  49 + deviceChannel.setLongitudeGcj02(position[0]);
  50 + deviceChannel.setLatitudeGcj02(position[1]);
  51 + }else if ("GCJ02".equals(device.getGeoCoordSys())) {
  52 + deviceChannel.setLongitudeGcj02(deviceChannel.getLongitude());
  53 + deviceChannel.setLatitudeGcj02(deviceChannel.getLatitude());
  54 + Double[] position = Coordtransform.GCJ02ToWGS84(deviceChannel.getLongitude(), deviceChannel.getLatitude());
  55 + deviceChannel.setLongitudeWgs84(position[0]);
  56 + deviceChannel.setLatitudeWgs84(position[1]);
  57 + }else {
  58 + deviceChannel.setLongitudeGcj02(0.00);
  59 + deviceChannel.setLatitudeGcj02(0.00);
  60 + deviceChannel.setLongitudeWgs84(0.00);
  61 + deviceChannel.setLatitudeWgs84(0.00);
  62 + }
  63 + }else {
  64 + deviceChannel.setLongitudeGcj02(deviceChannel.getLongitude());
  65 + deviceChannel.setLatitudeGcj02(deviceChannel.getLatitude());
  66 + deviceChannel.setLongitudeWgs84(deviceChannel.getLongitude());
  67 + deviceChannel.setLatitudeWgs84(deviceChannel.getLatitude());
  68 + }
  69 + return deviceChannel;
  70 + }
  71 +
  72 + @Override
  73 + public void updateChannel(String deviceId, DeviceChannel channel) {
  74 + String channelId = channel.getChannelId();
  75 + channel.setDeviceId(deviceId);
  76 + StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId);
  77 + if (streamInfo != null) {
  78 + channel.setStreamId(streamInfo.getStream());
  79 + }
  80 + String now = DateUtil.getNow();
  81 + channel.setUpdateTime(now);
  82 + DeviceChannel deviceChannel = channelMapper.queryChannel(deviceId, channelId);
  83 + channel = updateGps(channel, null);
  84 + if (deviceChannel == null) {
  85 + channel.setCreateTime(now);
  86 + channelMapper.add(channel);
  87 + }else {
  88 + channelMapper.update(channel);
  89 + }
  90 + channelMapper.updateChannelSubCount(deviceId,channel.getParentId());
  91 + }
  92 +
  93 + @Override
  94 + public int updateChannels(String deviceId, List<DeviceChannel> channels) {
  95 + List<DeviceChannel> addChannels = new ArrayList<>();
  96 + List<DeviceChannel> updateChannels = new ArrayList<>();
  97 + HashMap<String, DeviceChannel> channelsInStore = new HashMap<>();
  98 + Device device = deviceMapper.getDeviceByDeviceId(deviceId);
  99 + if (channels != null && channels.size() > 0) {
  100 + List<DeviceChannel> channelList = channelMapper.queryChannels(deviceId, null, null, null, null);
  101 + if (channelList.size() == 0) {
  102 + for (DeviceChannel channel : channels) {
  103 + channel.setDeviceId(deviceId);
  104 + StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channel.getChannelId());
  105 + if (streamInfo != null) {
  106 + channel.setStreamId(streamInfo.getStream());
  107 + }
  108 + String now = DateUtil.getNow();
  109 + channel.setUpdateTime(now);
  110 + channel.setCreateTime(now);
  111 + channel = updateGps(channel, device);
  112 + addChannels.add(channel);
  113 + }
  114 + }else {
  115 + for (DeviceChannel deviceChannel : channelList) {
  116 + channelsInStore.put(deviceChannel.getChannelId(), deviceChannel);
  117 + }
  118 + for (DeviceChannel channel : channels) {
  119 + channel.setDeviceId(deviceId);
  120 + StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channel.getChannelId());
  121 + if (streamInfo != null) {
  122 + channel.setStreamId(streamInfo.getStream());
  123 + }
  124 + String now = DateUtil.getNow();
  125 + channel.setUpdateTime(now);
  126 + channel = updateGps(channel, device);
  127 + if (channelsInStore.get(channel.getChannelId()) != null) {
  128 + updateChannels.add(channel);
  129 + }else {
  130 + addChannels.add(channel);
  131 + channel.setCreateTime(now);
  132 + }
  133 + }
  134 + }
  135 + int limitCount = 300;
  136 + if (addChannels.size() > 0) {
  137 + if (addChannels.size() > limitCount) {
  138 + for (int i = 0; i < addChannels.size(); i += limitCount) {
  139 + int toIndex = i + limitCount;
  140 + if (i + limitCount > addChannels.size()) {
  141 + toIndex = addChannels.size();
  142 + }
  143 + channelMapper.batchAdd(addChannels.subList(i, toIndex));
  144 + }
  145 + }else {
  146 + channelMapper.batchAdd(addChannels);
  147 + }
  148 + }
  149 + if (updateChannels.size() > 0) {
  150 + if (updateChannels.size() > limitCount) {
  151 + for (int i = 0; i < updateChannels.size(); i += limitCount) {
  152 + int toIndex = i + limitCount;
  153 + if (i + limitCount > updateChannels.size()) {
  154 + toIndex = updateChannels.size();
  155 + }
  156 + channelMapper.batchUpdate(updateChannels.subList(i, toIndex));
  157 + }
  158 + }else {
  159 + channelMapper.batchUpdate(updateChannels);
  160 + }
  161 + }
  162 + }
  163 + return addChannels.size() + updateChannels.size();
  164 + }
  165 +}
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
@@ -7,6 +7,7 @@ import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask; @@ -7,6 +7,7 @@ import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask;
7 import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander; 7 import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
8 import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd.CatalogResponseMessageHandler; 8 import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd.CatalogResponseMessageHandler;
9 import com.genersoft.iot.vmp.gb28181.utils.Coordtransform; 9 import com.genersoft.iot.vmp.gb28181.utils.Coordtransform;
  10 +import com.genersoft.iot.vmp.service.IDeviceChannelService;
10 import com.genersoft.iot.vmp.service.IDeviceService; 11 import com.genersoft.iot.vmp.service.IDeviceService;
11 import com.genersoft.iot.vmp.gb28181.task.impl.CatalogSubscribeTask; 12 import com.genersoft.iot.vmp.gb28181.task.impl.CatalogSubscribeTask;
12 import com.genersoft.iot.vmp.gb28181.task.impl.MobilePositionSubscribeTask; 13 import com.genersoft.iot.vmp.gb28181.task.impl.MobilePositionSubscribeTask;
@@ -56,6 +57,9 @@ public class DeviceServiceImpl implements IDeviceService { @@ -56,6 +57,9 @@ public class DeviceServiceImpl implements IDeviceService {
56 private DeviceMapper deviceMapper; 57 private DeviceMapper deviceMapper;
57 58
58 @Autowired 59 @Autowired
  60 + private IDeviceChannelService deviceChannelService;
  61 +
  62 + @Autowired
59 private DeviceChannelMapper deviceChannelMapper; 63 private DeviceChannelMapper deviceChannelMapper;
60 64
61 @Autowired 65 @Autowired
@@ -324,23 +328,12 @@ public class DeviceServiceImpl implements IDeviceService { @@ -324,23 +328,12 @@ public class DeviceServiceImpl implements IDeviceService {
324 private void updateDeviceChannelGeoCoordSys(Device device) { 328 private void updateDeviceChannelGeoCoordSys(Device device) {
325 List<DeviceChannel> deviceChannels = deviceChannelMapper.getAllChannelWithCoordinate(device.getDeviceId()); 329 List<DeviceChannel> deviceChannels = deviceChannelMapper.getAllChannelWithCoordinate(device.getDeviceId());
326 if (deviceChannels.size() > 0) { 330 if (deviceChannels.size() > 0) {
  331 + List<DeviceChannel> deviceChannelsForStore = new ArrayList<>();
327 for (DeviceChannel deviceChannel : deviceChannels) { 332 for (DeviceChannel deviceChannel : deviceChannels) {
328 - if ("WGS84".equals(device.getGeoCoordSys())) {  
329 - deviceChannel.setLongitudeWgs84(deviceChannel.getLongitude());  
330 - deviceChannel.setLatitudeWgs84(deviceChannel.getLatitude());  
331 - Double[] position = Coordtransform.WGS84ToGCJ02(deviceChannel.getLongitude(), deviceChannel.getLatitude());  
332 - deviceChannel.setLongitudeGcj02(position[0]);  
333 - deviceChannel.setLatitudeGcj02(position[1]);  
334 - }else if ("GCJ02".equals(device.getGeoCoordSys())) {  
335 - deviceChannel.setLongitudeGcj02(deviceChannel.getLongitude());  
336 - deviceChannel.setLatitudeGcj02(deviceChannel.getLatitude());  
337 - Double[] position = Coordtransform.GCJ02ToWGS84(deviceChannel.getLongitude(), deviceChannel.getLatitude());  
338 - deviceChannel.setLongitudeWgs84(position[0]);  
339 - deviceChannel.setLatitudeWgs84(position[1]);  
340 - } 333 + deviceChannelsForStore.add(deviceChannelService.updateGps(deviceChannel, device));
341 } 334 }
  335 + deviceChannelService.updateChannels(device.getDeviceId(), deviceChannelsForStore);
342 } 336 }
343 - storage.updateChannels(device.getDeviceId(), deviceChannels);  
344 } 337 }
345 338
346 339
@@ -352,11 +345,11 @@ public class DeviceServiceImpl implements IDeviceService { @@ -352,11 +345,11 @@ public class DeviceServiceImpl implements IDeviceService {
352 } 345 }
353 if (parentId == null || parentId.equals(deviceId)) { 346 if (parentId == null || parentId.equals(deviceId)) {
354 // 字根节点开始查询 347 // 字根节点开始查询
355 - List<DeviceChannel> rootNodes = getRootNodes(deviceId, "CivilCode".equals(device.getTreeType()), true, !onlyCatalog); 348 + List<DeviceChannel> rootNodes = getRootNodes(deviceId, TreeType.CIVIL_CODE.equals(device.getTreeType()), true, !onlyCatalog);
356 return transportChannelsToTree(rootNodes, ""); 349 return transportChannelsToTree(rootNodes, "");
357 } 350 }
358 351
359 - if ("CivilCode".equals(device.getTreeType())) { 352 + if (TreeType.CIVIL_CODE.equals(device.getTreeType())) {
360 if (parentId.length()%2 != 0) { 353 if (parentId.length()%2 != 0) {
361 return null; 354 return null;
362 } 355 }
@@ -386,7 +379,7 @@ public class DeviceServiceImpl implements IDeviceService { @@ -386,7 +379,7 @@ public class DeviceServiceImpl implements IDeviceService {
386 379
387 } 380 }
388 // 使用业务分组展示树 381 // 使用业务分组展示树
389 - if ("BusinessGroup".equals(device.getTreeType())) { 382 + if (TreeType.BUSINESS_GROUP.equals(device.getTreeType())) {
390 if (parentId.length() < 14 ) { 383 if (parentId.length() < 14 ) {
391 return null; 384 return null;
392 } 385 }
@@ -406,11 +399,11 @@ public class DeviceServiceImpl implements IDeviceService { @@ -406,11 +399,11 @@ public class DeviceServiceImpl implements IDeviceService {
406 } 399 }
407 if (parentId == null || parentId.equals(deviceId)) { 400 if (parentId == null || parentId.equals(deviceId)) {
408 // 字根节点开始查询 401 // 字根节点开始查询
409 - List<DeviceChannel> rootNodes = getRootNodes(deviceId, "CivilCode".equals(device.getTreeType()), false, true); 402 + List<DeviceChannel> rootNodes = getRootNodes(deviceId, TreeType.CIVIL_CODE.equals(device.getTreeType()), false, true);
410 return rootNodes; 403 return rootNodes;
411 } 404 }
412 405
413 - if ("CivilCode".equals(device.getTreeType())) { 406 + if (TreeType.CIVIL_CODE.equals(device.getTreeType())) {
414 if (parentId.length()%2 != 0) { 407 if (parentId.length()%2 != 0) {
415 return null; 408 return null;
416 } 409 }
@@ -431,7 +424,7 @@ public class DeviceServiceImpl implements IDeviceService { @@ -431,7 +424,7 @@ public class DeviceServiceImpl implements IDeviceService {
431 424
432 } 425 }
433 // 使用业务分组展示树 426 // 使用业务分组展示树
434 - if ("BusinessGroup".equals(device.getTreeType())) { 427 + if (TreeType.BUSINESS_GROUP.equals(device.getTreeType())) {
435 if (parentId.length() < 14 ) { 428 if (parentId.length() < 14 ) {
436 return null; 429 return null;
437 } 430 }
src/main/java/com/genersoft/iot/vmp/service/impl/GbStreamServiceImpl.java
1 package com.genersoft.iot.vmp.service.impl; 1 package com.genersoft.iot.vmp.service.impl;
2 2
3 import com.genersoft.iot.vmp.conf.SipConfig; 3 import com.genersoft.iot.vmp.conf.SipConfig;
4 -import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;  
5 -import com.genersoft.iot.vmp.gb28181.bean.GbStream;  
6 -import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; 4 +import com.genersoft.iot.vmp.gb28181.bean.*;
7 import com.genersoft.iot.vmp.gb28181.event.EventPublisher; 5 import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
8 import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; 6 import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
9 import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; 7 import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
10 import com.genersoft.iot.vmp.storager.dao.GbStreamMapper; 8 import com.genersoft.iot.vmp.storager.dao.GbStreamMapper;
11 import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper; 9 import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper;
  10 +import com.genersoft.iot.vmp.storager.dao.PlatformCatalogMapper;
12 import com.genersoft.iot.vmp.storager.dao.PlatformGbStreamMapper; 11 import com.genersoft.iot.vmp.storager.dao.PlatformGbStreamMapper;
13 import com.genersoft.iot.vmp.service.IGbStreamService; 12 import com.genersoft.iot.vmp.service.IGbStreamService;
14 import com.github.pagehelper.PageHelper; 13 import com.github.pagehelper.PageHelper;
@@ -46,15 +45,15 @@ public class GbStreamServiceImpl implements IGbStreamService { @@ -46,15 +45,15 @@ public class GbStreamServiceImpl implements IGbStreamService {
46 private ParentPlatformMapper platformMapper; 45 private ParentPlatformMapper platformMapper;
47 46
48 @Autowired 47 @Autowired
49 - private SipConfig sipConfig; 48 + private PlatformCatalogMapper catalogMapper;
50 49
51 @Autowired 50 @Autowired
52 private EventPublisher eventPublisher; 51 private EventPublisher eventPublisher;
53 52
54 @Override 53 @Override
55 - public PageInfo<GbStream> getAll(Integer page, Integer count, String platFormId, String catalogId, String query, Boolean pushing, String mediaServerId) { 54 + public PageInfo<GbStream> getAll(Integer page, Integer count, String platFormId, String catalogId, String query, String mediaServerId) {
56 PageHelper.startPage(page, count); 55 PageHelper.startPage(page, count);
57 - List<GbStream> all = gbStreamMapper.selectAll(platFormId, catalogId, query, pushing, mediaServerId); 56 + List<GbStream> all = gbStreamMapper.selectAll(platFormId, catalogId, query, mediaServerId);
58 return new PageInfo<>(all); 57 return new PageInfo<>(all);
59 } 58 }
60 59
@@ -102,16 +101,25 @@ public class GbStreamServiceImpl implements IGbStreamService { @@ -102,16 +101,25 @@ public class GbStreamServiceImpl implements IGbStreamService {
102 deviceChannel.setLatitude(gbStream.getLatitude()); 101 deviceChannel.setLatitude(gbStream.getLatitude());
103 deviceChannel.setDeviceId(platform.getDeviceGBId()); 102 deviceChannel.setDeviceId(platform.getDeviceGBId());
104 deviceChannel.setManufacture("wvp-pro"); 103 deviceChannel.setManufacture("wvp-pro");
105 -// deviceChannel.setStatus(gbStream.isStatus()?1:0);  
106 - deviceChannel.setStatus(1);  
107 - deviceChannel.setParentId(catalogId ==null?gbStream.getCatalogId():catalogId); 104 + deviceChannel.setStatus(gbStream.isStatus()?1:0);
  105 +
108 deviceChannel.setRegisterWay(1); 106 deviceChannel.setRegisterWay(1);
109 - if (catalogId.length() > 0 && catalogId.length() <= 10) {  
110 - // 父节点是行政区划,则设置CivilCode使用此行政区划 107 + deviceChannel.setCivilCode(platform.getAdministrativeDivision());
  108 +
  109 + if (platform.getTreeType().equals(TreeType.CIVIL_CODE)){
111 deviceChannel.setCivilCode(catalogId); 110 deviceChannel.setCivilCode(catalogId);
112 - }else {  
113 - deviceChannel.setCivilCode(platform.getAdministrativeDivision()); 111 + }else if (platform.getTreeType().equals(TreeType.BUSINESS_GROUP)){
  112 + PlatformCatalog catalog = catalogMapper.select(catalogId);
  113 + if (catalog == null) {
  114 + deviceChannel.setParentId(platform.getDeviceGBId());
  115 + deviceChannel.setBusinessGroupId(null);
  116 + }else {
  117 + deviceChannel.setParentId(catalog.getId());
  118 + deviceChannel.setBusinessGroupId(catalog.getBusinessGroupId());
  119 + }
  120 +
114 } 121 }
  122 +
115 deviceChannel.setModel("live"); 123 deviceChannel.setModel("live");
116 deviceChannel.setOwner("wvp-pro"); 124 deviceChannel.setOwner("wvp-pro");
117 deviceChannel.setParental(0); 125 deviceChannel.setParental(0);
@@ -149,9 +157,9 @@ public class GbStreamServiceImpl implements IGbStreamService { @@ -149,9 +157,9 @@ public class GbStreamServiceImpl implements IGbStreamService {
149 if (gbStream.getGbId() != null) { 157 if (gbStream.getGbId() != null) {
150 gbStreams.add(gbStream); 158 gbStreams.add(gbStream);
151 }else { 159 }else {
152 - StreamProxyItem streamProxyItem = gbStreamMapper.selectOne(gbStream.getApp(), gbStream.getStream());  
153 - if (streamProxyItem != null && streamProxyItem.getGbId() != null){  
154 - gbStreams.add(streamProxyItem); 160 + GbStream gbStreamIndb = gbStreamMapper.selectOne(gbStream.getApp(), gbStream.getStream());
  161 + if (gbStreamIndb != null && gbStreamIndb.getGbId() != null){
  162 + gbStreams.add(gbStreamIndb);
155 } 163 }
156 } 164 }
157 sendCatalogMsgs(gbStreams, type); 165 sendCatalogMsgs(gbStreams, type);
src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java
@@ -7,12 +7,15 @@ import com.genersoft.iot.vmp.common.StreamInfo; @@ -7,12 +7,15 @@ import com.genersoft.iot.vmp.common.StreamInfo;
7 import com.genersoft.iot.vmp.conf.MediaConfig; 7 import com.genersoft.iot.vmp.conf.MediaConfig;
8 import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils; 8 import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
9 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; 9 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
  10 +import com.genersoft.iot.vmp.media.zlm.dto.OnPublishHookParam;
  11 +import com.genersoft.iot.vmp.media.zlm.dto.StreamAuthorityInfo;
10 import com.genersoft.iot.vmp.service.IMediaServerService; 12 import com.genersoft.iot.vmp.service.IMediaServerService;
11 import com.genersoft.iot.vmp.storager.IRedisCatchStorage; 13 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
12 import com.genersoft.iot.vmp.storager.IVideoManagerStorage; 14 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
13 import com.genersoft.iot.vmp.service.IMediaService; 15 import com.genersoft.iot.vmp.service.IMediaService;
14 import org.springframework.beans.factory.annotation.Autowired; 16 import org.springframework.beans.factory.annotation.Autowired;
15 import org.springframework.stereotype.Service; 17 import org.springframework.stereotype.Service;
  18 +import org.springframework.util.StringUtils;
16 19
17 @Service 20 @Service
18 public class MediaServiceImpl implements IMediaService { 21 public class MediaServiceImpl implements IMediaService {
@@ -36,20 +39,24 @@ public class MediaServiceImpl implements IMediaService { @@ -36,20 +39,24 @@ public class MediaServiceImpl implements IMediaService {
36 39
37 40
38 @Override 41 @Override
39 - public StreamInfo getStreamInfoByAppAndStream(MediaServerItem mediaInfo, String app, String stream, Object tracks) {  
40 - return getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks, null); 42 + public StreamInfo getStreamInfoByAppAndStream(MediaServerItem mediaInfo, String app, String stream, Object tracks, String callId) {
  43 + return getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks, null, callId);
41 } 44 }
42 45
43 @Override 46 @Override
44 - public StreamInfo getStreamInfoByAppAndStreamWithCheck(String app, String stream, String mediaServerId, String addr) { 47 + public StreamInfo getStreamInfoByAppAndStreamWithCheck(String app, String stream, String mediaServerId, String addr, boolean authority) {
45 StreamInfo streamInfo = null; 48 StreamInfo streamInfo = null;
46 if (mediaServerId == null) { 49 if (mediaServerId == null) {
47 mediaServerId = mediaConfig.getId(); 50 mediaServerId = mediaConfig.getId();
48 } 51 }
49 - MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId);; 52 + MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId);
50 if (mediaInfo == null) { 53 if (mediaInfo == null) {
51 return null; 54 return null;
52 } 55 }
  56 + StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(app, stream);
  57 + if (streamAuthorityInfo == null) {
  58 + return null;
  59 + }
53 JSONObject mediaList = zlmresTfulUtils.getMediaList(mediaInfo, app, stream); 60 JSONObject mediaList = zlmresTfulUtils.getMediaList(mediaInfo, app, stream);
54 if (mediaList != null) { 61 if (mediaList != null) {
55 if (mediaList.getInteger("code") == 0) { 62 if (mediaList.getInteger("code") == 0) {
@@ -59,7 +66,12 @@ public class MediaServiceImpl implements IMediaService { @@ -59,7 +66,12 @@ public class MediaServiceImpl implements IMediaService {
59 } 66 }
60 JSONObject mediaJSON = JSON.parseObject(JSON.toJSONString(data.get(0)), JSONObject.class); 67 JSONObject mediaJSON = JSON.parseObject(JSON.toJSONString(data.get(0)), JSONObject.class);
61 JSONArray tracks = mediaJSON.getJSONArray("tracks"); 68 JSONArray tracks = mediaJSON.getJSONArray("tracks");
62 - streamInfo = getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks); 69 + if (authority) {
  70 + streamInfo = getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks, streamAuthorityInfo.getCallId());
  71 + }else {
  72 + streamInfo = getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks, null);
  73 + }
  74 +
63 } 75 }
64 } 76 }
65 return streamInfo; 77 return streamInfo;
@@ -68,46 +80,48 @@ public class MediaServiceImpl implements IMediaService { @@ -68,46 +80,48 @@ public class MediaServiceImpl implements IMediaService {
68 80
69 81
70 @Override 82 @Override
71 - public StreamInfo getStreamInfoByAppAndStreamWithCheck(String app, String stream, String mediaServerId) {  
72 - return getStreamInfoByAppAndStreamWithCheck(app, stream, mediaServerId, null); 83 + public StreamInfo getStreamInfoByAppAndStreamWithCheck(String app, String stream, String mediaServerId, boolean authority) {
  84 + return getStreamInfoByAppAndStreamWithCheck(app, stream, mediaServerId, null, authority);
73 } 85 }
74 86
75 @Override 87 @Override
76 - public StreamInfo getStreamInfoByAppAndStream(MediaServerItem mediaInfo, String app, String stream, Object tracks, String addr) { 88 + public StreamInfo getStreamInfoByAppAndStream(MediaServerItem mediaInfo, String app, String stream, Object tracks, String addr, String callId) {
77 StreamInfo streamInfoResult = new StreamInfo(); 89 StreamInfo streamInfoResult = new StreamInfo();
78 streamInfoResult.setStream(stream); 90 streamInfoResult.setStream(stream);
79 streamInfoResult.setApp(app); 91 streamInfoResult.setApp(app);
80 if (addr == null) { 92 if (addr == null) {
81 addr = mediaInfo.getStreamIp(); 93 addr = mediaInfo.getStreamIp();
82 } 94 }
  95 + streamInfoResult.setIp(addr);
83 streamInfoResult.setMediaServerId(mediaInfo.getId()); 96 streamInfoResult.setMediaServerId(mediaInfo.getId());
84 - streamInfoResult.setRtmp(String.format("rtmp://%s:%s/%s/%s", addr, mediaInfo.getRtmpPort(), app, stream)); 97 + String callIdParam = StringUtils.isEmpty(callId)?"":"?callId=" + callId;
  98 + streamInfoResult.setRtmp(String.format("rtmp://%s:%s/%s/%s%s", addr, mediaInfo.getRtmpPort(), app, stream, callIdParam));
85 if (mediaInfo.getRtmpSSlPort() != 0) { 99 if (mediaInfo.getRtmpSSlPort() != 0) {
86 - streamInfoResult.setRtmps(String.format("rtmps://%s:%s/%s/%s", addr, mediaInfo.getRtmpSSlPort(), app, stream)); 100 + streamInfoResult.setRtmps(String.format("rtmps://%s:%s/%s/%s%s", addr, mediaInfo.getRtmpSSlPort(), app, stream, callIdParam));
87 } 101 }
88 - streamInfoResult.setRtsp(String.format("rtsp://%s:%s/%s/%s", addr, mediaInfo.getRtspPort(), app, stream)); 102 + streamInfoResult.setRtsp(String.format("rtsp://%s:%s/%s/%s%s", addr, mediaInfo.getRtspPort(), app, stream, callIdParam));
89 if (mediaInfo.getRtspSSLPort() != 0) { 103 if (mediaInfo.getRtspSSLPort() != 0) {
90 - streamInfoResult.setRtsps(String.format("rtsps://%s:%s/%s/%s", addr, mediaInfo.getRtspSSLPort(), app, stream)); 104 + streamInfoResult.setRtsps(String.format("rtsps://%s:%s/%s/%s%s", addr, mediaInfo.getRtspSSLPort(), app, stream, callIdParam));
91 } 105 }
92 - streamInfoResult.setFlv(String.format("http://%s:%s/%s/%s.live.flv", addr, mediaInfo.getHttpPort(), app, stream));  
93 - streamInfoResult.setWs_flv(String.format("ws://%s:%s/%s/%s.live.flv", addr, mediaInfo.getHttpPort(), app, stream));  
94 - streamInfoResult.setHls(String.format("http://%s:%s/%s/%s/hls.m3u8", addr, mediaInfo.getHttpPort(), app, stream));  
95 - streamInfoResult.setWs_hls(String.format("ws://%s:%s/%s/%s/hls.m3u8", addr, mediaInfo.getHttpPort(), app, stream));  
96 - streamInfoResult.setFmp4(String.format("http://%s:%s/%s/%s.live.mp4", addr, mediaInfo.getHttpPort(), app, stream));  
97 - streamInfoResult.setWs_fmp4(String.format("ws://%s:%s/%s/%s.live.mp4", addr, mediaInfo.getHttpPort(), app, stream));  
98 - streamInfoResult.setTs(String.format("http://%s:%s/%s/%s.live.ts", addr, mediaInfo.getHttpPort(), app, stream));  
99 - streamInfoResult.setWs_ts(String.format("ws://%s:%s/%s/%s.live.ts", addr, mediaInfo.getHttpPort(), app, stream)); 106 + streamInfoResult.setFlv(String.format("http://%s:%s/%s/%s.live.flv%s", addr, mediaInfo.getHttpPort(), app, stream, callIdParam));
  107 + streamInfoResult.setWs_flv(String.format("ws://%s:%s/%s/%s.live.flv%s", addr, mediaInfo.getHttpPort(), app, stream, callIdParam));
  108 + streamInfoResult.setHls(String.format("http://%s:%s/%s/%s/hls.m3u8%s", addr, mediaInfo.getHttpPort(), app, stream, callIdParam));
  109 + streamInfoResult.setWs_hls(String.format("ws://%s:%s/%s/%s/hls.m3u8%s", addr, mediaInfo.getHttpPort(), app, stream, callIdParam));
  110 + streamInfoResult.setFmp4(String.format("http://%s:%s/%s/%s.live.mp4%s", addr, mediaInfo.getHttpPort(), app, stream, callIdParam));
  111 + streamInfoResult.setWs_fmp4(String.format("ws://%s:%s/%s/%s.live.mp4%s", addr, mediaInfo.getHttpPort(), app, stream, callIdParam));
  112 + streamInfoResult.setTs(String.format("http://%s:%s/%s/%s.live.ts%s", addr, mediaInfo.getHttpPort(), app, stream, callIdParam));
  113 + streamInfoResult.setWs_ts(String.format("ws://%s:%s/%s/%s.live.ts%s", addr, mediaInfo.getHttpPort(), app, stream, callIdParam));
100 if (mediaInfo.getHttpSSlPort() != 0) { 114 if (mediaInfo.getHttpSSlPort() != 0) {
101 - streamInfoResult.setHttps_flv(String.format("https://%s:%s/%s/%s.live.flv", addr, mediaInfo.getHttpSSlPort(), app, stream));  
102 - streamInfoResult.setWss_flv(String.format("wss://%s:%s/%s/%s.live.flv", addr, mediaInfo.getHttpSSlPort(), app, stream));  
103 - streamInfoResult.setHttps_hls(String.format("https://%s:%s/%s/%s/hls.m3u8", addr, mediaInfo.getHttpSSlPort(), app, stream));  
104 - streamInfoResult.setWss_hls(String.format("wss://%s:%s/%s/%s/hls.m3u8", addr, mediaInfo.getHttpSSlPort(), app, stream));  
105 - streamInfoResult.setHttps_fmp4(String.format("https://%s:%s/%s/%s.live.mp4", addr, mediaInfo.getHttpSSlPort(), app, stream));  
106 - streamInfoResult.setWss_fmp4(String.format("wss://%s:%s/%s/%s.live.mp4", addr, mediaInfo.getHttpSSlPort(), app, stream));  
107 - streamInfoResult.setHttps_ts(String.format("https://%s:%s/%s/%s.live.ts", addr, mediaInfo.getHttpSSlPort(), app, stream));  
108 - streamInfoResult.setWss_ts(String.format("wss://%s:%s/%s/%s.live.ts", addr, mediaInfo.getHttpSSlPort(), app, stream));  
109 - streamInfoResult.setWss_ts(String.format("wss://%s:%s/%s/%s.live.ts", addr, mediaInfo.getHttpSSlPort(), app, stream));  
110 - streamInfoResult.setRtc(String.format("https://%s:%s/index/api/webrtc?app=%s&stream=%s&type=play", mediaInfo.getStreamIp(), mediaInfo.getHttpSSlPort(), app, stream)); 115 + streamInfoResult.setHttps_flv(String.format("https://%s:%s/%s/%s.live.flv%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam));
  116 + streamInfoResult.setWss_flv(String.format("wss://%s:%s/%s/%s.live.flv%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam));
  117 + streamInfoResult.setHttps_hls(String.format("https://%s:%s/%s/%s/hls.m3u8%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam));
  118 + streamInfoResult.setWss_hls(String.format("wss://%s:%s/%s/%s/hls.m3u8%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam));
  119 + streamInfoResult.setHttps_fmp4(String.format("https://%s:%s/%s/%s.live.mp4%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam));
  120 + streamInfoResult.setWss_fmp4(String.format("wss://%s:%s/%s/%s.live.mp4%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam));
  121 + streamInfoResult.setHttps_ts(String.format("https://%s:%s/%s/%s.live.ts%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam));
  122 + streamInfoResult.setWss_ts(String.format("wss://%s:%s/%s/%s.live.ts%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam));
  123 + streamInfoResult.setWss_ts(String.format("wss://%s:%s/%s/%s.live.ts%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam));
  124 + 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));
111 } 125 }
112 126
113 streamInfoResult.setTracks(tracks); 127 streamInfoResult.setTracks(tracks);
src/main/java/com/genersoft/iot/vmp/service/impl/PlatformChannelServiceImpl.java 0 → 100644
  1 +package com.genersoft.iot.vmp.service.impl;
  2 +
  3 +import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
  4 +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
  5 +import com.genersoft.iot.vmp.gb28181.bean.PlatformCatalog;
  6 +import com.genersoft.iot.vmp.gb28181.bean.TreeType;
  7 +import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
  8 +import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
  9 +import com.genersoft.iot.vmp.service.IPlatformChannelService;
  10 +import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper;
  11 +import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper;
  12 +import com.genersoft.iot.vmp.storager.dao.PlatformCatalogMapper;
  13 +import com.genersoft.iot.vmp.storager.dao.PlatformChannelMapper;
  14 +import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce;
  15 +import org.slf4j.Logger;
  16 +import org.slf4j.LoggerFactory;
  17 +import org.springframework.beans.factory.annotation.Autowired;
  18 +import org.springframework.stereotype.Service;
  19 +
  20 +import java.util.ArrayList;
  21 +import java.util.HashMap;
  22 +import java.util.List;
  23 +import java.util.Map;
  24 +
  25 +/**
  26 + * @author lin
  27 + */
  28 +@Service
  29 +public class PlatformChannelServiceImpl implements IPlatformChannelService {
  30 +
  31 + private final static Logger logger = LoggerFactory.getLogger(PlatformChannelServiceImpl.class);
  32 +
  33 + @Autowired
  34 + private PlatformChannelMapper platformChannelMapper;
  35 +
  36 + @Autowired
  37 + private DeviceChannelMapper deviceChannelMapper;
  38 +
  39 + @Autowired
  40 + private PlatformCatalogMapper catalogManager;
  41 +
  42 + @Autowired
  43 + private ParentPlatformMapper platformMapper;
  44 +
  45 + @Autowired
  46 + EventPublisher eventPublisher;
  47 +
  48 + @Override
  49 + public int updateChannelForGB(String platformId, List<ChannelReduce> channelReduces, String catalogId) {
  50 + ParentPlatform platform = platformMapper.getParentPlatByServerGBId(platformId);
  51 + if (platform == null) {
  52 + logger.warn("更新级联通道信息时未找到平台{}的信息", platformId);
  53 + return 0;
  54 + }
  55 + Map<Integer, ChannelReduce> deviceAndChannels = new HashMap<>();
  56 + for (ChannelReduce channelReduce : channelReduces) {
  57 + channelReduce.setCatalogId(catalogId);
  58 + deviceAndChannels.put(channelReduce.getId(), channelReduce);
  59 + }
  60 + List<Integer> deviceAndChannelList = new ArrayList<>(deviceAndChannels.keySet());
  61 + // 查询当前已经存在的
  62 + List<Integer> channelIds = platformChannelMapper.findChannelRelatedPlatform(platformId, channelReduces);
  63 + if (deviceAndChannelList != null) {
  64 + deviceAndChannelList.removeAll(channelIds);
  65 + }
  66 + for (Integer channelId : channelIds) {
  67 + deviceAndChannels.remove(channelId);
  68 + }
  69 + List<ChannelReduce> channelReducesToAdd = new ArrayList<>(deviceAndChannels.values());
  70 + // 对剩下的数据进行存储
  71 + int result = 0;
  72 + if (channelReducesToAdd.size() > 0) {
  73 + result = platformChannelMapper.addChannels(platformId, channelReducesToAdd);
  74 + // TODO 后续给平台增加控制开关以控制是否响应目录订阅
  75 + List<DeviceChannel> deviceChannelList = getDeviceChannelListByChannelReduceList(channelReducesToAdd, catalogId, platform);
  76 + eventPublisher.catalogEventPublish(platformId, deviceChannelList, CatalogEvent.ADD);
  77 + }
  78 +
  79 + return result;
  80 + }
  81 +
  82 + private List<DeviceChannel> getDeviceChannelListByChannelReduceList(List<ChannelReduce> channelReduces, String catalogId, ParentPlatform platform) {
  83 + List<DeviceChannel> deviceChannelList = new ArrayList<>();
  84 + if (channelReduces.size() > 0){
  85 + PlatformCatalog catalog = catalogManager.select(catalogId);
  86 + if (catalog == null && !catalogId.equals(platform.getServerGBId())) {
  87 + logger.warn("未查询到目录{}的信息", catalogId);
  88 + return null;
  89 + }
  90 + for (ChannelReduce channelReduce : channelReduces) {
  91 + DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(channelReduce.getDeviceId(), channelReduce.getChannelId());
  92 + deviceChannel.setParental(0);
  93 + deviceChannelList.add(deviceChannel);
  94 + if (platform.getTreeType().equals(TreeType.CIVIL_CODE)){
  95 + deviceChannel.setCivilCode(catalogId);
  96 + }else if (platform.getTreeType().equals(TreeType.BUSINESS_GROUP)){
  97 + deviceChannel.setParentId(catalogId);
  98 + if (catalog != null) {
  99 + deviceChannel.setBusinessGroupId(catalog.getBusinessGroupId());
  100 + }
  101 + }
  102 + }
  103 + }
  104 + return deviceChannelList;
  105 + }
  106 +}
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
@@ -620,7 +620,7 @@ public class PlayServiceImpl implements IPlayService { @@ -620,7 +620,7 @@ public class PlayServiceImpl implements IPlayService {
620 public StreamInfo onPublishHandler(MediaServerItem mediaServerItem, JSONObject resonse, String deviceId, String channelId) { 620 public StreamInfo onPublishHandler(MediaServerItem mediaServerItem, JSONObject resonse, String deviceId, String channelId) {
621 String streamId = resonse.getString("stream"); 621 String streamId = resonse.getString("stream");
622 JSONArray tracks = resonse.getJSONArray("tracks"); 622 JSONArray tracks = resonse.getJSONArray("tracks");
623 - StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream(mediaServerItem,"rtp", streamId, tracks); 623 + StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream(mediaServerItem,"rtp", streamId, tracks, null);
624 streamInfo.setDeviceID(deviceId); 624 streamInfo.setDeviceID(deviceId);
625 streamInfo.setChannelId(channelId); 625 streamInfo.setChannelId(channelId);
626 return streamInfo; 626 return streamInfo;
src/main/java/com/genersoft/iot/vmp/service/impl/RedisGpsMsgListener.java
@@ -25,9 +25,7 @@ public class RedisGpsMsgListener implements MessageListener { @@ -25,9 +25,7 @@ public class RedisGpsMsgListener implements MessageListener {
25 25
26 @Override 26 @Override
27 public void onMessage(@NotNull Message message, byte[] bytes) { 27 public void onMessage(@NotNull Message message, byte[] bytes) {
28 - if (logger.isDebugEnabled()) {  
29 - logger.debug("收到来自REDIS的GPS通知: {}", new String(message.getBody()));  
30 - } 28 + // TODO 加消息队列
31 GPSMsgInfo gpsMsgInfo = JSON.parseObject(message.getBody(), GPSMsgInfo.class); 29 GPSMsgInfo gpsMsgInfo = JSON.parseObject(message.getBody(), GPSMsgInfo.class);
32 redisCatchStorage.updateGpsMsgInfo(gpsMsgInfo); 30 redisCatchStorage.updateGpsMsgInfo(gpsMsgInfo);
33 } 31 }
src/main/java/com/genersoft/iot/vmp/service/impl/RedisPushStreamStatusMsgListener.java 0 → 100644
  1 +package com.genersoft.iot.vmp.service.impl;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.alibaba.fastjson.JSONObject;
  5 +import com.genersoft.iot.vmp.common.VideoManagerConstants;
  6 +import com.genersoft.iot.vmp.conf.DynamicTask;
  7 +import com.genersoft.iot.vmp.conf.UserSetting;
  8 +import com.genersoft.iot.vmp.gb28181.bean.GbStream;
  9 +import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
  10 +import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
  11 +import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
  12 +import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
  13 +import com.genersoft.iot.vmp.media.zlm.ZLMMediaListManager;
  14 +import com.genersoft.iot.vmp.media.zlm.dto.MediaItem;
  15 +import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
  16 +import com.genersoft.iot.vmp.service.IStreamPushService;
  17 +import com.genersoft.iot.vmp.service.bean.PushStreamStatusChangeFromRedisDto;
  18 +import com.genersoft.iot.vmp.service.bean.StreamPushItemFromRedis;
  19 +import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
  20 +import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
  21 +import org.slf4j.Logger;
  22 +import org.slf4j.LoggerFactory;
  23 +import org.springframework.beans.factory.annotation.Autowired;
  24 +import org.springframework.boot.ApplicationArguments;
  25 +import org.springframework.boot.ApplicationRunner;
  26 +import org.springframework.data.redis.connection.Message;
  27 +import org.springframework.data.redis.connection.MessageListener;
  28 +import org.springframework.stereotype.Component;
  29 +
  30 +import java.util.ArrayList;
  31 +import java.util.List;
  32 +
  33 +
  34 +/**
  35 + * 接收redis发送的推流设备上线下线通知
  36 + * @author lin
  37 + */
  38 +@Component
  39 +public class RedisPushStreamStatusMsgListener implements MessageListener, ApplicationRunner {
  40 +
  41 + private final static Logger logger = LoggerFactory.getLogger(RedisPushStreamStatusMsgListener.class);
  42 +
  43 + @Autowired
  44 + private IRedisCatchStorage redisCatchStorage;
  45 +
  46 + @Autowired
  47 + private IStreamPushService streamPushService;
  48 +
  49 + @Autowired
  50 + private EventPublisher eventPublisher;
  51 +
  52 + @Autowired
  53 + private UserSetting userSetting;
  54 +
  55 + @Autowired
  56 + private DynamicTask dynamicTask;
  57 +
  58 + @Override
  59 + public void onMessage(Message message, byte[] bytes) {
  60 + PushStreamStatusChangeFromRedisDto statusChangeFromPushStream = JSON.parseObject(message.getBody(), PushStreamStatusChangeFromRedisDto.class);
  61 + if (statusChangeFromPushStream == null) {
  62 + logger.warn("[REDIS 消息]推流设备状态变化消息解析失败");
  63 + return;
  64 + }
  65 + if (statusChangeFromPushStream.isSetAllOffline()) {
  66 + // 所有设备离线
  67 + streamPushService.allStreamOffline();
  68 + }
  69 + if (statusChangeFromPushStream.getOfflineStreams() != null
  70 + && statusChangeFromPushStream.getOfflineStreams().size() > 0) {
  71 + // 更新部分设备离线
  72 + streamPushService.offline(statusChangeFromPushStream.getOfflineStreams());
  73 + }
  74 + if (statusChangeFromPushStream.getOnlineStreams() != null &&
  75 + statusChangeFromPushStream.getOnlineStreams().size() > 0) {
  76 + // 更新部分设备上线
  77 + streamPushService.online(statusChangeFromPushStream.getOnlineStreams());
  78 + }
  79 + }
  80 +
  81 + @Override
  82 + public void run(ApplicationArguments args) throws Exception {
  83 + // 启动时设置所有推流通道离线,发起查询请求
  84 + redisCatchStorage.sendStreamPushRequestedMsgForStatus();
  85 + dynamicTask.startDelay(VideoManagerConstants.VM_MSG_GET_ALL_ONLINE_REQUESTED, ()->{
  86 + logger.info("[REDIS 消息]未收到redis回复推流设备状态,执行推流设备离线");
  87 + // 五秒收不到请求就设置通道离线,然后通知上级离线
  88 + streamPushService.allStreamOffline();
  89 + }, 5000);
  90 + }
  91 +
  92 +}
src/main/java/com/genersoft/iot/vmp/service/impl/RedisStreamMsgListener.java
@@ -3,16 +3,12 @@ package com.genersoft.iot.vmp.service.impl; @@ -3,16 +3,12 @@ package com.genersoft.iot.vmp.service.impl;
3 import com.alibaba.fastjson.JSON; 3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONObject; 4 import com.alibaba.fastjson.JSONObject;
5 import com.genersoft.iot.vmp.conf.UserSetting; 5 import com.genersoft.iot.vmp.conf.UserSetting;
6 -import com.genersoft.iot.vmp.gb28181.bean.AlarmChannelMessage;  
7 -import com.genersoft.iot.vmp.gb28181.bean.Device;  
8 -import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm;  
9 -import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; 6 +
10 import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander; 7 import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
11 import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; 8 import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
12 import com.genersoft.iot.vmp.media.zlm.ZLMMediaListManager; 9 import com.genersoft.iot.vmp.media.zlm.ZLMMediaListManager;
13 import com.genersoft.iot.vmp.media.zlm.dto.MediaItem; 10 import com.genersoft.iot.vmp.media.zlm.dto.MediaItem;
14 import com.genersoft.iot.vmp.storager.IVideoManagerStorage; 11 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
15 -import com.genersoft.iot.vmp.utils.DateUtil;  
16 import org.slf4j.Logger; 12 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory; 13 import org.slf4j.LoggerFactory;
18 import org.springframework.beans.factory.annotation.Autowired; 14 import org.springframework.beans.factory.annotation.Autowired;
@@ -22,6 +18,7 @@ import org.springframework.stereotype.Component; @@ -22,6 +18,7 @@ import org.springframework.stereotype.Component;
22 18
23 19
24 /** 20 /**
  21 + * 接收其他wvp发送流变化通知
25 * @author lin 22 * @author lin
26 */ 23 */
27 @Component 24 @Component
src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java
@@ -3,10 +3,10 @@ package com.genersoft.iot.vmp.service.impl; @@ -3,10 +3,10 @@ package com.genersoft.iot.vmp.service.impl;
3 import com.alibaba.fastjson.JSONArray; 3 import com.alibaba.fastjson.JSONArray;
4 import com.alibaba.fastjson.JSONObject; 4 import com.alibaba.fastjson.JSONObject;
5 import com.genersoft.iot.vmp.common.StreamInfo; 5 import com.genersoft.iot.vmp.common.StreamInfo;
6 -import com.genersoft.iot.vmp.conf.SipConfig;  
7 import com.genersoft.iot.vmp.conf.UserSetting; 6 import com.genersoft.iot.vmp.conf.UserSetting;
8 import com.genersoft.iot.vmp.gb28181.bean.GbStream; 7 import com.genersoft.iot.vmp.gb28181.bean.GbStream;
9 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; 8 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
  9 +import com.genersoft.iot.vmp.gb28181.bean.TreeType;
10 import com.genersoft.iot.vmp.gb28181.event.EventPublisher; 10 import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
11 import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; 11 import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
12 import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils; 12 import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
@@ -23,14 +23,19 @@ import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper; @@ -23,14 +23,19 @@ import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper;
23 import com.genersoft.iot.vmp.storager.dao.PlatformGbStreamMapper; 23 import com.genersoft.iot.vmp.storager.dao.PlatformGbStreamMapper;
24 import com.genersoft.iot.vmp.storager.dao.StreamProxyMapper; 24 import com.genersoft.iot.vmp.storager.dao.StreamProxyMapper;
25 import com.genersoft.iot.vmp.service.IStreamProxyService; 25 import com.genersoft.iot.vmp.service.IStreamProxyService;
  26 +import com.genersoft.iot.vmp.utils.DateUtil;
26 import com.genersoft.iot.vmp.vmanager.bean.WVPResult; 27 import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
27 import com.github.pagehelper.PageInfo; 28 import com.github.pagehelper.PageInfo;
28 import org.slf4j.Logger; 29 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory; 30 import org.slf4j.LoggerFactory;
30 import org.springframework.beans.factory.annotation.Autowired; 31 import org.springframework.beans.factory.annotation.Autowired;
  32 +import org.springframework.jdbc.datasource.DataSourceTransactionManager;
31 import org.springframework.stereotype.Service; 33 import org.springframework.stereotype.Service;
  34 +import org.springframework.transaction.TransactionDefinition;
  35 +import org.springframework.transaction.TransactionStatus;
32 import org.springframework.util.StringUtils; 36 import org.springframework.util.StringUtils;
33 37
  38 +import java.net.InetAddress;
34 import java.util.*; 39 import java.util.*;
35 40
36 /** 41 /**
@@ -48,7 +53,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService { @@ -48,7 +53,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
48 private IMediaService mediaService; 53 private IMediaService mediaService;
49 54
50 @Autowired 55 @Autowired
51 - private ZLMRESTfulUtils zlmresTfulUtils;; 56 + private ZLMRESTfulUtils zlmresTfulUtils;
52 57
53 @Autowired 58 @Autowired
54 private StreamProxyMapper streamProxyMapper; 59 private StreamProxyMapper streamProxyMapper;
@@ -63,9 +68,6 @@ public class StreamProxyServiceImpl implements IStreamProxyService { @@ -63,9 +68,6 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
63 private UserSetting userSetting; 68 private UserSetting userSetting;
64 69
65 @Autowired 70 @Autowired
66 - private SipConfig sipConfig;  
67 -  
68 - @Autowired  
69 private GbStreamMapper gbStreamMapper; 71 private GbStreamMapper gbStreamMapper;
70 72
71 @Autowired 73 @Autowired
@@ -83,6 +85,12 @@ public class StreamProxyServiceImpl implements IStreamProxyService { @@ -83,6 +85,12 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
83 @Autowired 85 @Autowired
84 private IMediaServerService mediaServerService; 86 private IMediaServerService mediaServerService;
85 87
  88 + @Autowired
  89 + DataSourceTransactionManager dataSourceTransactionManager;
  90 +
  91 + @Autowired
  92 + TransactionDefinition transactionDefinition;
  93 +
86 94
87 @Override 95 @Override
88 public WVPResult<StreamInfo> save(StreamProxyItem param) { 96 public WVPResult<StreamInfo> save(StreamProxyItem param) {
@@ -99,6 +107,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService { @@ -99,6 +107,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
99 wvpResult.setMsg("保存失败"); 107 wvpResult.setMsg("保存失败");
100 return wvpResult; 108 return wvpResult;
101 } 109 }
  110 +
102 String dstUrl = String.format("rtmp://%s:%s/%s/%s", "127.0.0.1", mediaInfo.getRtmpPort(), param.getApp(), 111 String dstUrl = String.format("rtmp://%s:%s/%s/%s", "127.0.0.1", mediaInfo.getRtmpPort(), param.getApp(),
103 param.getStream() ); 112 param.getStream() );
104 param.setDst_url(dstUrl); 113 param.setDst_url(dstUrl);
@@ -108,9 +117,9 @@ public class StreamProxyServiceImpl implements IStreamProxyService { @@ -108,9 +117,9 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
108 boolean saveResult; 117 boolean saveResult;
109 // 更新 118 // 更新
110 if (videoManagerStorager.queryStreamProxy(param.getApp(), param.getStream()) != null) { 119 if (videoManagerStorager.queryStreamProxy(param.getApp(), param.getStream()) != null) {
111 - saveResult = videoManagerStorager.updateStreamProxy(param); 120 + saveResult = updateStreamProxy(param);
112 }else { // 新增 121 }else { // 新增
113 - saveResult = videoManagerStorager.addStreamProxy(param); 122 + saveResult = addStreamProxy(param);
114 } 123 }
115 if (saveResult) { 124 if (saveResult) {
116 result.append("保存成功"); 125 result.append("保存成功");
@@ -124,7 +133,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService { @@ -124,7 +133,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
124 if (param.isEnable_remove_none_reader()) { 133 if (param.isEnable_remove_none_reader()) {
125 del(param.getApp(), param.getStream()); 134 del(param.getApp(), param.getStream());
126 }else { 135 }else {
127 - videoManagerStorager.updateStreamProxy(param); 136 + updateStreamProxy(param);
128 } 137 }
129 138
130 }else { 139 }else {
@@ -147,25 +156,79 @@ public class StreamProxyServiceImpl implements IStreamProxyService { @@ -147,25 +156,79 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
147 result.append(", 关联国标平台[ " + param.getPlatformGbId() + " ]失败"); 156 result.append(", 关联国标平台[ " + param.getPlatformGbId() + " ]失败");
148 } 157 }
149 } 158 }
150 - if (!StringUtils.isEmpty(param.getGbId())) {  
151 - // 查找开启了全部直播流共享的上级平台  
152 - List<ParentPlatform> parentPlatforms = parentPlatformMapper.selectAllAhareAllLiveStream();  
153 - if (parentPlatforms.size() > 0) {  
154 - for (ParentPlatform parentPlatform : parentPlatforms) {  
155 - param.setPlatformId(parentPlatform.getServerGBId());  
156 - param.setCatalogId(parentPlatform.getCatalogId());  
157 - String stream = param.getStream();  
158 - StreamProxyItem streamProxyItems = platformGbStreamMapper.selectOne(param.getApp(), stream, parentPlatform.getServerGBId());  
159 - if (streamProxyItems == null) {  
160 - platformGbStreamMapper.add(param);  
161 - eventPublisher.catalogEventPublishForStream(parentPlatform.getServerGBId(), param, CatalogEvent.ADD); 159 + wvpResult.setMsg(result.toString());
  160 + return wvpResult;
  161 + }
  162 +
  163 + /**
  164 + * 新增代理流
  165 + * @param streamProxyItem
  166 + * @return
  167 + */
  168 + private boolean addStreamProxy(StreamProxyItem streamProxyItem) {
  169 + TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
  170 + boolean result = false;
  171 + streamProxyItem.setStreamType("proxy");
  172 + streamProxyItem.setStatus(true);
  173 + String now = DateUtil.getNow();
  174 + streamProxyItem.setCreateTime(now);
  175 + try {
  176 + if (streamProxyMapper.add(streamProxyItem) > 0) {
  177 + if (!StringUtils.isEmpty(streamProxyItem.getGbId())) {
  178 + if (gbStreamMapper.add(streamProxyItem) < 0) {
  179 + //事务回滚
  180 + dataSourceTransactionManager.rollback(transactionStatus);
  181 + return false;
162 } 182 }
163 } 183 }
  184 + }else {
  185 + //事务回滚
  186 + dataSourceTransactionManager.rollback(transactionStatus);
  187 + return false;
164 } 188 }
  189 + result = true;
  190 + dataSourceTransactionManager.commit(transactionStatus); //手动提交
  191 + }catch (Exception e) {
  192 + logger.error("向数据库添加流代理失败:", e);
  193 + dataSourceTransactionManager.rollback(transactionStatus);
165 } 194 }
166 195
167 - wvpResult.setMsg(result.toString());  
168 - return wvpResult; 196 +
  197 + return result;
  198 + }
  199 +
  200 + /**
  201 + * 更新代理流
  202 + * @param streamProxyItem
  203 + * @return
  204 + */
  205 + @Override
  206 + public boolean updateStreamProxy(StreamProxyItem streamProxyItem) {
  207 + TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
  208 + boolean result = false;
  209 + streamProxyItem.setStreamType("proxy");
  210 + try {
  211 + if (streamProxyMapper.update(streamProxyItem) > 0) {
  212 + if (!StringUtils.isEmpty(streamProxyItem.getGbId())) {
  213 + if (gbStreamMapper.updateByAppAndStream(streamProxyItem) == 0) {
  214 + //事务回滚
  215 + dataSourceTransactionManager.rollback(transactionStatus);
  216 + return false;
  217 + }
  218 + }
  219 + } else {
  220 + //事务回滚
  221 + dataSourceTransactionManager.rollback(transactionStatus);
  222 + return false;
  223 + }
  224 +
  225 + dataSourceTransactionManager.commit(transactionStatus); //手动提交
  226 + result = true;
  227 + }catch (Exception e) {
  228 + e.printStackTrace();
  229 + dataSourceTransactionManager.rollback(transactionStatus);
  230 + }
  231 + return result;
169 } 232 }
170 233
171 @Override 234 @Override
@@ -239,7 +302,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService { @@ -239,7 +302,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
239 if (jsonObject.getInteger("code") == 0) { 302 if (jsonObject.getInteger("code") == 0) {
240 result = true; 303 result = true;
241 streamProxy.setEnable(true); 304 streamProxy.setEnable(true);
242 - videoManagerStorager.updateStreamProxy(streamProxy); 305 + updateStreamProxy(streamProxy);
243 } 306 }
244 } 307 }
245 return result; 308 return result;
@@ -253,7 +316,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService { @@ -253,7 +316,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
253 JSONObject jsonObject = removeStreamProxyFromZlm(streamProxyDto); 316 JSONObject jsonObject = removeStreamProxyFromZlm(streamProxyDto);
254 if (jsonObject != null && jsonObject.getInteger("code") == 0) { 317 if (jsonObject != null && jsonObject.getInteger("code") == 0) {
255 streamProxyDto.setEnable(false); 318 streamProxyDto.setEnable(false);
256 - result = videoManagerStorager.updateStreamProxy(streamProxyDto); 319 + result = updateStreamProxy(streamProxyDto);
257 } 320 }
258 } 321 }
259 return result; 322 return result;
@@ -319,7 +382,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService { @@ -319,7 +382,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
319 } 382 }
320 streamProxyMapper.deleteAutoRemoveItemByMediaServerId(mediaServerId); 383 streamProxyMapper.deleteAutoRemoveItemByMediaServerId(mediaServerId);
321 // 其他的流设置离线 384 // 其他的流设置离线
322 - streamProxyMapper.updateStatusByMediaServerId(false, mediaServerId); 385 + streamProxyMapper.updateStatusByMediaServerId(mediaServerId, false);
323 String type = "PULL"; 386 String type = "PULL";
324 387
325 // 发送redis消息 388 // 发送redis消息
@@ -346,7 +409,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService { @@ -346,7 +409,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
346 409
347 @Override 410 @Override
348 public int updateStatus(boolean status, String app, String stream) { 411 public int updateStatus(boolean status, String app, String stream) {
349 - return streamProxyMapper.updateStatus(status, app, stream); 412 + return streamProxyMapper.updateStatus(app, stream, status);
350 } 413 }
351 414
352 private void syncPullStream(String mediaServerId){ 415 private void syncPullStream(String mediaServerId){
src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushServiceImpl.java
@@ -13,6 +13,7 @@ import com.genersoft.iot.vmp.media.zlm.dto.*; @@ -13,6 +13,7 @@ import com.genersoft.iot.vmp.media.zlm.dto.*;
13 import com.genersoft.iot.vmp.service.IGbStreamService; 13 import com.genersoft.iot.vmp.service.IGbStreamService;
14 import com.genersoft.iot.vmp.service.IMediaServerService; 14 import com.genersoft.iot.vmp.service.IMediaServerService;
15 import com.genersoft.iot.vmp.service.IStreamPushService; 15 import com.genersoft.iot.vmp.service.IStreamPushService;
  16 +import com.genersoft.iot.vmp.service.bean.StreamPushItemFromRedis;
16 import com.genersoft.iot.vmp.storager.IRedisCatchStorage; 17 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
17 import com.genersoft.iot.vmp.storager.dao.*; 18 import com.genersoft.iot.vmp.storager.dao.*;
18 import com.genersoft.iot.vmp.utils.DateUtil; 19 import com.genersoft.iot.vmp.utils.DateUtil;
@@ -39,6 +40,9 @@ public class StreamPushServiceImpl implements IStreamPushService { @@ -39,6 +40,9 @@ public class StreamPushServiceImpl implements IStreamPushService {
39 private StreamPushMapper streamPushMapper; 40 private StreamPushMapper streamPushMapper;
40 41
41 @Autowired 42 @Autowired
  43 + private StreamProxyMapper streamProxyMapper;
  44 +
  45 + @Autowired
42 private ParentPlatformMapper parentPlatformMapper; 46 private ParentPlatformMapper parentPlatformMapper;
43 47
44 @Autowired 48 @Autowired
@@ -130,29 +134,6 @@ public class StreamPushServiceImpl implements IStreamPushService { @@ -130,29 +134,6 @@ public class StreamPushServiceImpl implements IStreamPushService {
130 stream.setStatus(true); 134 stream.setStatus(true);
131 stream.setCreateTime(DateUtil.getNow()); 135 stream.setCreateTime(DateUtil.getNow());
132 int add = gbStreamMapper.add(stream); 136 int add = gbStreamMapper.add(stream);
133 -  
134 - // 查找开启了全部直播流共享的上级平台  
135 - List<ParentPlatform> parentPlatforms = parentPlatformMapper.selectAllAhareAllLiveStream();  
136 - if (parentPlatforms.size() > 0) {  
137 - for (ParentPlatform parentPlatform : parentPlatforms) {  
138 - stream.setCatalogId(parentPlatform.getCatalogId());  
139 - stream.setPlatformId(parentPlatform.getServerGBId());  
140 - String streamId = stream.getStream();  
141 - StreamProxyItem streamProxyItem = platformGbStreamMapper.selectOne(stream.getApp(), streamId, parentPlatform.getServerGBId());  
142 - if (streamProxyItem == null) {  
143 - platformGbStreamMapper.add(stream);  
144 - eventPublisher.catalogEventPublishForStream(parentPlatform.getServerGBId(), stream, CatalogEvent.ADD);  
145 - }else {  
146 - if (!streamProxyItem.getGbId().equals(stream.getGbId())) {  
147 - // 此流使用另一个国标Id已经与该平台关联,移除此记录  
148 - platformGbStreamMapper.delByAppAndStreamAndPlatform(stream.getApp(), streamId, parentPlatform.getServerGBId());  
149 - platformGbStreamMapper.add(stream);  
150 - eventPublisher.catalogEventPublishForStream(parentPlatform.getServerGBId(), stream, CatalogEvent.ADD);  
151 - }  
152 - }  
153 - }  
154 - }  
155 -  
156 return add > 0; 137 return add > 0;
157 } 138 }
158 139
@@ -178,7 +159,6 @@ public class StreamPushServiceImpl implements IStreamPushService { @@ -178,7 +159,6 @@ public class StreamPushServiceImpl implements IStreamPushService {
178 159
179 @Override 160 @Override
180 public StreamPushItem getPush(String app, String streamId) { 161 public StreamPushItem getPush(String app, String streamId) {
181 -  
182 return streamPushMapper.selectOne(app, streamId); 162 return streamPushMapper.selectOne(app, streamId);
183 } 163 }
184 164
@@ -285,7 +265,8 @@ public class StreamPushServiceImpl implements IStreamPushService { @@ -285,7 +265,8 @@ public class StreamPushServiceImpl implements IStreamPushService {
285 streamPushMapper.deleteWithoutGBId(mediaServerId); 265 streamPushMapper.deleteWithoutGBId(mediaServerId);
286 gbStreamMapper.deleteWithoutGBId("push", mediaServerId); 266 gbStreamMapper.deleteWithoutGBId("push", mediaServerId);
287 // 其他的流设置未启用 267 // 其他的流设置未启用
288 - gbStreamMapper.updateStatusByMediaServerId(mediaServerId, false); 268 + streamPushMapper.updateStatusByMediaServerId(mediaServerId, false);
  269 + streamProxyMapper.updateStatusByMediaServerId(mediaServerId, false);
289 // 发送流停止消息 270 // 发送流停止消息
290 String type = "PUSH"; 271 String type = "PUSH";
291 // 发送redis消息 272 // 发送redis消息
@@ -341,31 +322,6 @@ public class StreamPushServiceImpl implements IStreamPushService { @@ -341,31 +322,6 @@ public class StreamPushServiceImpl implements IStreamPushService {
341 public void batchAdd(List<StreamPushItem> streamPushItems) { 322 public void batchAdd(List<StreamPushItem> streamPushItems) {
342 streamPushMapper.addAll(streamPushItems); 323 streamPushMapper.addAll(streamPushItems);
343 gbStreamMapper.batchAdd(streamPushItems); 324 gbStreamMapper.batchAdd(streamPushItems);
344 - // 查找开启了全部直播流共享的上级平台  
345 - List<ParentPlatform> parentPlatforms = parentPlatformMapper.selectAllAhareAllLiveStream();  
346 - if (parentPlatforms.size() > 0) {  
347 - for (StreamPushItem stream : streamPushItems) {  
348 - for (ParentPlatform parentPlatform : parentPlatforms) {  
349 - stream.setCatalogId(parentPlatform.getCatalogId());  
350 - stream.setPlatformId(parentPlatform.getServerGBId());  
351 - String streamId = stream.getStream();  
352 - StreamProxyItem streamProxyItem = platformGbStreamMapper.selectOne(stream.getApp(), streamId, parentPlatform.getServerGBId());  
353 - if (streamProxyItem == null) {  
354 - platformGbStreamMapper.add(stream);  
355 - eventPublisher.catalogEventPublishForStream(parentPlatform.getServerGBId(), stream, CatalogEvent.ADD);  
356 - }else {  
357 - if (!streamProxyItem.getGbId().equals(stream.getGbId())) {  
358 - // 此流使用另一个国标Id已经与该平台关联,移除此记录  
359 - platformGbStreamMapper.delByAppAndStreamAndPlatform(stream.getApp(), streamId, parentPlatform.getServerGBId());  
360 - platformGbStreamMapper.add(stream);  
361 - eventPublisher.catalogEventPublishForStream(parentPlatform.getServerGBId(), stream, CatalogEvent.ADD);  
362 - stream.setGbId(streamProxyItem.getGbId());  
363 - eventPublisher.catalogEventPublishForStream(parentPlatform.getServerGBId(), stream, CatalogEvent.DEL);  
364 - }  
365 - }  
366 - }  
367 - }  
368 - }  
369 } 325 }
370 326
371 @Override 327 @Override
@@ -477,4 +433,34 @@ public class StreamPushServiceImpl implements IStreamPushService { @@ -477,4 +433,34 @@ public class StreamPushServiceImpl implements IStreamPushService {
477 } 433 }
478 return true; 434 return true;
479 } 435 }
  436 +
  437 + @Override
  438 + public void allStreamOffline() {
  439 + List<GbStream> onlinePushers = streamPushMapper.getOnlinePusherForGb();
  440 + if (onlinePushers.size() == 0) {
  441 + return;
  442 + }
  443 + streamPushMapper.setAllStreamOffline();
  444 +
  445 + // 发送通知
  446 + eventPublisher.catalogEventPublishForStream(null, onlinePushers, CatalogEvent.OFF);
  447 + }
  448 +
  449 + @Override
  450 + public void offline(List<StreamPushItemFromRedis> offlineStreams) {
  451 + // 更新部分设备离线
  452 + List<GbStream> onlinePushers = streamPushMapper.getOnlinePusherForGbInList(offlineStreams);
  453 + streamPushMapper.offline(offlineStreams);
  454 + // 发送通知
  455 + eventPublisher.catalogEventPublishForStream(null, onlinePushers, CatalogEvent.OFF);
  456 + }
  457 +
  458 + @Override
  459 + public void online(List<StreamPushItemFromRedis> onlineStreams) {
  460 + // 更新部分设备上线streamPushService
  461 + List<GbStream> onlinePushers = streamPushMapper.getOfflinePusherForGbInList(onlineStreams);
  462 + streamPushMapper.online(onlineStreams);
  463 + // 发送通知
  464 + eventPublisher.catalogEventPublishForStream(null, onlinePushers, CatalogEvent.ON);
  465 + }
480 } 466 }
src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushUploadFileHandler.java
@@ -14,38 +14,60 @@ import java.util.*; @@ -14,38 +14,60 @@ import java.util.*;
14 14
15 public class StreamPushUploadFileHandler extends AnalysisEventListener<StreamPushExcelDto> { 15 public class StreamPushUploadFileHandler extends AnalysisEventListener<StreamPushExcelDto> {
16 16
17 - // 错误数据的回调,用于将错误数据发送给页面 17 + /**
  18 + * 错误数据的回调,用于将错误数据发送给页面
  19 + */
18 private ErrorDataHandler errorDataHandler; 20 private ErrorDataHandler errorDataHandler;
19 21
20 - // 推流的业务类用于存储数据 22 + /**
  23 + * 推流的业务类用于存储数据
  24 + */
21 private IStreamPushService pushService; 25 private IStreamPushService pushService;
22 26
23 - // 默认流媒体节点ID 27 + /**
  28 + * 默认流媒体节点ID
  29 + */
24 private String defaultMediaServerId; 30 private String defaultMediaServerId;
25 31
26 - // 用于存储不加过滤的所有数据 32 + /**
  33 + * 用于存储不加过滤的所有数据
  34 + */
27 private List<StreamPushItem> streamPushItems = new ArrayList<>(); 35 private List<StreamPushItem> streamPushItems = new ArrayList<>();
28 36
29 - // 用于存储更具APP+Stream过滤后的数据,可以直接存入stream_push表与gb_stream表 37 + /**
  38 + * 用于存储更具APP+Stream过滤后的数据,可以直接存入stream_push表与gb_stream表
  39 + */
30 private Map<String,StreamPushItem> streamPushItemForSave = new HashMap<>(); 40 private Map<String,StreamPushItem> streamPushItemForSave = new HashMap<>();
31 41
32 - // 用于存储按照APP+Stream为KEY, 平台ID+目录Id 为value的数据,用于存储到gb_stream表后获取app+Stream对应的平台与目录信息,然后存入关联表 42 + /**
  43 + * 用于存储按照APP+Stream为KEY, 平台ID+目录Id 为value的数据,用于存储到gb_stream表后获取app+Stream对应的平台与目录信息,然后存入关联表
  44 + */
33 private Map<String, List<String[]>> streamPushItemsForPlatform = new HashMap<>(); 45 private Map<String, List<String[]>> streamPushItemsForPlatform = new HashMap<>();
34 46
35 - // 用于判断文件是否存在重复的app+Stream+平台ID 47 + /**
  48 + * 用于判断文件是否存在重复的app+Stream+平台ID
  49 + */
36 private Set<String> streamPushStreamSet = new HashSet<>(); 50 private Set<String> streamPushStreamSet = new HashSet<>();
37 51
38 - // 用于存储APP+Stream->国标ID 的数据结构, 数据一一对应,全局判断APP+Stream->国标ID是否存在不对应 52 + /**
  53 + * 用于存储APP+Stream->国标ID 的数据结构, 数据一一对应,全局判断APP+Stream->国标ID是否存在不对应
  54 + */
39 private BiMap<String,String> gBMap = HashBiMap.create(); 55 private BiMap<String,String> gBMap = HashBiMap.create();
40 56
41 - // 记录错误的APP+Stream 57 + /**
  58 + * 记录错误的APP+Stream
  59 + */
42 private List<String> errorStreamList = new ArrayList<>(); 60 private List<String> errorStreamList = new ArrayList<>();
43 61
44 62
45 - // 记录错误的国标ID 63 + /**
  64 + * 记录错误的国标ID
  65 + */
46 private List<String> errorGBList = new ArrayList<>(); 66 private List<String> errorGBList = new ArrayList<>();
47 67
48 - // 读取数量计数器 68 + /**
  69 + * 读取数量计数器
  70 + */
49 private int loadedSize = 0; 71 private int loadedSize = 0;
50 72
51 public StreamPushUploadFileHandler(IStreamPushService pushService, String defaultMediaServerId, ErrorDataHandler errorDataHandler) { 73 public StreamPushUploadFileHandler(IStreamPushService pushService, String defaultMediaServerId, ErrorDataHandler errorDataHandler) {
src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java
@@ -3,14 +3,17 @@ package com.genersoft.iot.vmp.service.impl; @@ -3,14 +3,17 @@ package com.genersoft.iot.vmp.service.impl;
3 import com.genersoft.iot.vmp.service.IUserService; 3 import com.genersoft.iot.vmp.service.IUserService;
4 import com.genersoft.iot.vmp.storager.dao.UserMapper; 4 import com.genersoft.iot.vmp.storager.dao.UserMapper;
5 import com.genersoft.iot.vmp.storager.dao.dto.User; 5 import com.genersoft.iot.vmp.storager.dao.dto.User;
  6 +import com.github.pagehelper.PageHelper;
  7 +import com.github.pagehelper.PageInfo;
6 import org.springframework.beans.factory.annotation.Autowired; 8 import org.springframework.beans.factory.annotation.Autowired;
7 import org.springframework.stereotype.Service; 9 import org.springframework.stereotype.Service;
  10 +import org.springframework.util.StringUtils;
8 11
9 import java.util.List; 12 import java.util.List;
10 13
11 @Service 14 @Service
12 public class UserServiceImpl implements IUserService { 15 public class UserServiceImpl implements IUserService {
13 - 16 +
14 @Autowired 17 @Autowired
15 private UserMapper userMapper; 18 private UserMapper userMapper;
16 19
@@ -55,4 +58,24 @@ public class UserServiceImpl implements IUserService { @@ -55,4 +58,24 @@ public class UserServiceImpl implements IUserService {
55 } 58 }
56 59
57 60
  61 + @Override
  62 + public boolean checkPushAuthority(String callId, String sign) {
  63 + if (StringUtils.isEmpty(callId)) {
  64 + return userMapper.checkPushAuthorityByCallId(sign).size() > 0;
  65 + }else {
  66 + return userMapper.checkPushAuthorityByCallIdAndSign(callId, sign).size() > 0;
  67 + }
  68 + }
  69 +
  70 + @Override
  71 + public PageInfo<User> getUsers(int page, int count) {
  72 + PageHelper.startPage(page, count);
  73 + List<User> users = userMapper.getUsers();
  74 + return new PageInfo<>(users);
  75 + }
  76 +
  77 + @Override
  78 + public int changePushKey(int id, String pushKey) {
  79 + return userMapper.changePushKey(id,pushKey);
  80 + }
58 } 81 }
src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java
@@ -3,9 +3,7 @@ package com.genersoft.iot.vmp.storager; @@ -3,9 +3,7 @@ package com.genersoft.iot.vmp.storager;
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
4 import com.genersoft.iot.vmp.common.StreamInfo; 4 import com.genersoft.iot.vmp.common.StreamInfo;
5 import com.genersoft.iot.vmp.gb28181.bean.*; 5 import com.genersoft.iot.vmp.gb28181.bean.*;
6 -import com.genersoft.iot.vmp.media.zlm.dto.MediaItem;  
7 -import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;  
8 -import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; 6 +import com.genersoft.iot.vmp.media.zlm.dto.*;
9 import com.genersoft.iot.vmp.service.bean.GPSMsgInfo; 7 import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
10 import com.genersoft.iot.vmp.service.bean.MessageForPushChannel; 8 import com.genersoft.iot.vmp.service.bean.MessageForPushChannel;
11 import com.genersoft.iot.vmp.service.bean.SSRCInfo; 9 import com.genersoft.iot.vmp.service.bean.SSRCInfo;
@@ -213,4 +211,31 @@ public interface IRedisCatchStorage { @@ -213,4 +211,31 @@ public interface IRedisCatchStorage {
213 */ 211 */
214 public boolean deviceIsOnline(String deviceId); 212 public boolean deviceIsOnline(String deviceId);
215 213
  214 + /**
  215 + * 存储推流的鉴权信息
  216 + * @param app 应用名
  217 + * @param stream 流
  218 + * @param streamAuthorityInfo 鉴权信息
  219 + */
  220 + void updateStreamAuthorityInfo(String app, String stream, StreamAuthorityInfo streamAuthorityInfo);
  221 +
  222 + /**
  223 + * 移除推流的鉴权信息
  224 + * @param app 应用名
  225 + * @param streamId 流
  226 + */
  227 + void removeStreamAuthorityInfo(String app, String streamId);
  228 +
  229 + /**
  230 + * 获取推流的鉴权信息
  231 + * @param app 应用名
  232 + * @param stream 流
  233 + * @return
  234 + */
  235 + StreamAuthorityInfo getStreamAuthorityInfo(String app, String stream);
  236 +
  237 + /**
  238 + * 发送redis消息 查询所有推流设备的状态
  239 + */
  240 + void sendStreamPushRequestedMsgForStatus();
216 } 241 }
src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java
@@ -27,22 +27,6 @@ public interface IVideoManagerStorage { @@ -27,22 +27,6 @@ public interface IVideoManagerStorage {
27 public boolean exists(String deviceId); 27 public boolean exists(String deviceId);
28 28
29 /** 29 /**
30 - * 添加设备通道  
31 - *  
32 - * @param deviceId 设备id  
33 - * @param channel 通道  
34 - */  
35 - public void updateChannel(String deviceId, DeviceChannel channel);  
36 -  
37 - /**  
38 - * 批量添加设备通道  
39 - *  
40 - * @param deviceId 设备id  
41 - * @param channels 多个通道  
42 - */  
43 - public int updateChannels(String deviceId, List<DeviceChannel> channels);  
44 -  
45 - /**  
46 * 开始播放 30 * 开始播放
47 * @param deviceId 设备id 31 * @param deviceId 设备id
48 * @param channelId 通道ID 32 * @param channelId 通道ID
@@ -224,13 +208,6 @@ public interface IVideoManagerStorage { @@ -224,13 +208,6 @@ public interface IVideoManagerStorage {
224 List<DeviceChannelInPlatform> queryChannelListInParentPlatform(String platformId); 208 List<DeviceChannelInPlatform> queryChannelListInParentPlatform(String platformId);
225 209
226 210
227 - /**  
228 - * 更新上级平台的通道信息  
229 - * @param platformId  
230 - * @param channelReduces  
231 - * @return  
232 - */  
233 - int updateChannelForGB(String platformId, List<ChannelReduce> channelReduces, String catalogId);  
234 211
235 /** 212 /**
236 * 移除上级平台的通道信息 213 * 移除上级平台的通道信息
@@ -277,20 +254,6 @@ public interface IVideoManagerStorage { @@ -277,20 +254,6 @@ public interface IVideoManagerStorage {
277 public int clearMobilePositionsByDeviceId(String deviceId); 254 public int clearMobilePositionsByDeviceId(String deviceId);
278 255
279 /** 256 /**
280 - * 新增代理流  
281 - * @param streamProxyDto  
282 - * @return  
283 - */  
284 - public boolean addStreamProxy(StreamProxyItem streamProxyDto);  
285 -  
286 - /**  
287 - * 更新代理流  
288 - * @param streamProxyDto  
289 - * @return  
290 - */  
291 - public boolean updateStreamProxy(StreamProxyItem streamProxyDto);  
292 -  
293 - /**  
294 * 移除代理流 257 * 移除代理流
295 * @param app 258 * @param app
296 * @param stream 259 * @param stream
@@ -334,7 +297,7 @@ public interface IVideoManagerStorage { @@ -334,7 +297,7 @@ public interface IVideoManagerStorage {
334 * @param platformId 297 * @param platformId
335 * @return 298 * @return
336 */ 299 */
337 - List<GbStream> queryGbStreamListInPlatform(String platformId); 300 + List<DeviceChannel> queryGbStreamListInPlatform(String platformId);
338 301
339 /** 302 /**
340 * 批量更新推流列表 303 * 批量更新推流列表
@@ -372,14 +335,16 @@ public interface IVideoManagerStorage { @@ -372,14 +335,16 @@ public interface IVideoManagerStorage {
372 335
373 /** 336 /**
374 * 设置流离线 337 * 设置流离线
375 - * @param app  
376 - * @param streamId  
377 */ 338 */
378 - int mediaOutline(String app, String streamId); 339 + int mediaOffline(String app, String streamId);
  340 +
  341 + /**
  342 + * 设置流上线
  343 + */
  344 + int mediaOnline(String app, String streamId);
379 345
380 /** 346 /**
381 * 设置平台在线/离线 347 * 设置平台在线/离线
382 - * @param online  
383 */ 348 */
384 void updateParentPlatformStatus(String platformGbID, boolean online); 349 void updateParentPlatformStatus(String platformGbID, boolean online);
385 350
@@ -443,7 +408,7 @@ public interface IVideoManagerStorage { @@ -443,7 +408,7 @@ public interface IVideoManagerStorage {
443 408
444 int setDefaultCatalog(String platformId, String catalogId); 409 int setDefaultCatalog(String platformId, String catalogId);
445 410
446 - List<PlatformCatalog> queryCatalogInPlatform(String serverGBId); 411 + List<DeviceChannel> queryCatalogInPlatform(String serverGBId);
447 412
448 int delRelation(PlatformCatalog platformCatalog); 413 int delRelation(PlatformCatalog platformCatalog);
449 414
@@ -464,4 +429,8 @@ public interface IVideoManagerStorage { @@ -464,4 +429,8 @@ public interface IVideoManagerStorage {
464 List<ChannelSourceInfo> getChannelSource(String platformId, String gbId); 429 List<ChannelSourceInfo> getChannelSource(String platformId, String gbId);
465 430
466 void updateChannelPosition(DeviceChannel deviceChannel); 431 void updateChannelPosition(DeviceChannel deviceChannel);
  432 +
  433 + void cleanContentForPlatform(String serverGBId);
  434 +
  435 + List<DeviceChannel> queryChannelWithCatalog(String serverGBId);
467 } 436 }
src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java
@@ -329,5 +329,13 @@ public interface DeviceChannelMapper { @@ -329,5 +329,13 @@ public interface DeviceChannelMapper {
329 @Select("select * from device_channel where deviceId=#{deviceId} and SUBSTRING(channelId, 11, 3)=#{typeCode}") 329 @Select("select * from device_channel where deviceId=#{deviceId} and SUBSTRING(channelId, 11, 3)=#{typeCode}")
330 List<DeviceChannel> getBusinessGroups(String deviceId, String typeCode); 330 List<DeviceChannel> getBusinessGroups(String deviceId, String typeCode);
331 331
332 - 332 + @Select("select dc.id, dc.channelId, dc.deviceId, dc.name, dc.manufacture,dc.model,dc.owner, pc.civilCode,dc.block, " +
  333 + " dc.address, '0' as parental,'0' as channelType, pc.id as parentId, dc.safetyWay, dc.registerWay,dc.certNum, dc.certifiable, " +
  334 + " dc.errCode,dc.endTime, dc.secrecy, dc.ipAddress, dc.port, dc.PTZType, dc.password, dc.status, " +
  335 + " dc.longitudeWgs84 as longitude, dc.latitudeWgs84 as latitude, pc.businessGroupId " +
  336 + " from device_channel dc" +
  337 + " left join platform_gb_channel pgc on dc.id = pgc.deviceChannelId" +
  338 + " left join platform_catalog pc on pgc.catalogId = pc.id and pgc.platformId = pc.platformId" +
  339 + " where pgc.platformId=#{serverGBId}")
  340 + List<DeviceChannel> queryChannelWithCatalog(String serverGBId);
333 } 341 }
src/main/java/com/genersoft/iot/vmp/storager/dao/GbStreamMapper.java
1 package com.genersoft.iot.vmp.storager.dao; 1 package com.genersoft.iot.vmp.storager.dao;
2 2
  3 +import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
3 import com.genersoft.iot.vmp.gb28181.bean.GbStream; 4 import com.genersoft.iot.vmp.gb28181.bean.GbStream;
4 import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; 5 import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
5 import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; 6 import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
@@ -15,10 +16,10 @@ import java.util.List; @@ -15,10 +16,10 @@ import java.util.List;
15 public interface GbStreamMapper { 16 public interface GbStreamMapper {
16 17
17 @Insert("REPLACE INTO gb_stream (app, stream, gbId, name, " + 18 @Insert("REPLACE INTO gb_stream (app, stream, gbId, name, " +
18 - "longitude, latitude, streamType, mediaServerId, status, createTime) VALUES" + 19 + "longitude, latitude, streamType, mediaServerId, createTime) VALUES" +
19 "('${app}', '${stream}', '${gbId}', '${name}', " + 20 "('${app}', '${stream}', '${gbId}', '${name}', " +
20 "'${longitude}', '${latitude}', '${streamType}', " + 21 "'${longitude}', '${latitude}', '${streamType}', " +
21 - "'${mediaServerId}', ${status}, '${createTime}')") 22 + "'${mediaServerId}', '${createTime}')")
22 @Options(useGeneratedKeys = true, keyProperty = "gbStreamId", keyColumn = "gbStreamId") 23 @Options(useGeneratedKeys = true, keyProperty = "gbStreamId", keyColumn = "gbStreamId")
23 int add(GbStream gbStream); 24 int add(GbStream gbStream);
24 25
@@ -30,8 +31,7 @@ public interface GbStreamMapper { @@ -30,8 +31,7 @@ public interface GbStreamMapper {
30 "streamType=#{streamType}," + 31 "streamType=#{streamType}," +
31 "longitude=#{longitude}, " + 32 "longitude=#{longitude}, " +
32 "latitude=#{latitude}," + 33 "latitude=#{latitude}," +
33 - "mediaServerId=#{mediaServerId}," +  
34 - "status=${status} " + 34 + "mediaServerId=#{mediaServerId}" +
35 "WHERE app=#{app} AND stream=#{stream}") 35 "WHERE app=#{app} AND stream=#{stream}")
36 int updateByAppAndStream(GbStream gbStream); 36 int updateByAppAndStream(GbStream gbStream);
37 37
@@ -43,8 +43,7 @@ public interface GbStreamMapper { @@ -43,8 +43,7 @@ public interface GbStreamMapper {
43 "streamType=#{streamType}," + 43 "streamType=#{streamType}," +
44 "longitude=#{longitude}, " + 44 "longitude=#{longitude}, " +
45 "latitude=#{latitude}," + 45 "latitude=#{latitude}," +
46 - "mediaServerId=#{mediaServerId}," +  
47 - "status=${status} " + 46 + "mediaServerId=#{mediaServerId}" +
48 "WHERE gbStreamId=#{gbStreamId}") 47 "WHERE gbStreamId=#{gbStreamId}")
49 int update(GbStream gbStream); 48 int update(GbStream gbStream);
50 49
@@ -60,15 +59,13 @@ public interface GbStreamMapper { @@ -60,15 +59,13 @@ public interface GbStreamMapper {
60 " <if test='catalogId == null'> AND gs.gbStreamId not in" + 59 " <if test='catalogId == null'> AND gs.gbStreamId not in" +
61 "(select pgs.gbStreamId from platform_gb_stream pgs where pgs.platformId = #{platformId}) </if> " + 60 "(select pgs.gbStreamId from platform_gb_stream pgs where pgs.platformId = #{platformId}) </if> " +
62 " <if test='query != null'> AND (gs.app LIKE '%${query}%' OR gs.stream LIKE '%${query}%' OR gs.gbId LIKE '%${query}%' OR gs.name LIKE '%${query}%')</if> " + 61 " <if test='query != null'> AND (gs.app LIKE '%${query}%' OR gs.stream LIKE '%${query}%' OR gs.gbId LIKE '%${query}%' OR gs.name LIKE '%${query}%')</if> " +
63 - " <if test='pushing == true' > AND gs.status=1</if>" +  
64 - " <if test='pushing == false' > AND gs.status=0</if>" +  
65 " <if test='mediaServerId != null' > AND gs.mediaServerId=#{mediaServerId} </if>" + 62 " <if test='mediaServerId != null' > AND gs.mediaServerId=#{mediaServerId} </if>" +
66 " order by gs.gbStreamId asc " + 63 " order by gs.gbStreamId asc " +
67 "</script>") 64 "</script>")
68 - List<GbStream> selectAll(String platformId, String catalogId, String query, Boolean pushing, String mediaServerId); 65 + List<GbStream> selectAll(String platformId, String catalogId, String query, String mediaServerId);
69 66
70 @Select("SELECT * FROM gb_stream WHERE app=#{app} AND stream=#{stream}") 67 @Select("SELECT * FROM gb_stream WHERE app=#{app} AND stream=#{stream}")
71 - StreamProxyItem selectOne(String app, String stream); 68 + GbStream selectOne(String app, String stream);
72 69
73 @Select("SELECT * FROM gb_stream WHERE gbId=#{gbId}") 70 @Select("SELECT * FROM gb_stream WHERE gbId=#{gbId}")
74 List<GbStream> selectByGBId(String gbId); 71 List<GbStream> selectByGBId(String gbId);
@@ -78,26 +75,24 @@ public interface GbStreamMapper { @@ -78,26 +75,24 @@ public interface GbStreamMapper {
78 "WHERE gs.gbId = '${gbId}' AND pgs.platformId = '${platformId}'") 75 "WHERE gs.gbId = '${gbId}' AND pgs.platformId = '${platformId}'")
79 GbStream queryStreamInPlatform(String platformId, String gbId); 76 GbStream queryStreamInPlatform(String platformId, String gbId);
80 77
81 - @Select("SELECT gs.*, pgs.platformId as platformId, pgs.catalogId as catalogId FROM gb_stream gs " +  
82 - "LEFT JOIN platform_gb_stream pgs ON gs.gbStreamId = pgs.gbStreamId " +  
83 - "WHERE pgs.platformId = #{platformId}")  
84 - List<GbStream> queryGbStreamListInPlatform(String platformId); 78 + @Select("select gt.gbId as channelId, gt.name, 'wvp-pro' as manufacture, st.status, gt.longitude, gt.latitude, pc.id as parentId," +
  79 + " '1' as registerWay, pc.civilCode, 'live' as model, 'wvp-pro' as owner, '0' as parental,'0' as secrecy" +
  80 + " from gb_stream gt " +
  81 + " left join (" +
  82 + " select sp.status, sp.app, sp.stream from stream_push sp" +
  83 + " union all" +
  84 + " select spxy.status, spxy.app, spxy.stream from stream_proxy spxy" +
  85 + " ) st on st.app = gt.app and st.stream = gt.stream" +
  86 + " left join platform_gb_stream pgs on gt.gbStreamId = pgs.gbStreamId" +
  87 + " left join platform_catalog pc on pgs.catalogId = pc.id and pgs.platformId = pc.platformId" +
  88 + " where pgs.platformId=#{platformId}")
  89 + List<DeviceChannel> queryGbStreamListInPlatform(String platformId);
85 90
86 91
87 @Select("SELECT gs.* FROM gb_stream gs LEFT JOIN platform_gb_stream pgs " + 92 @Select("SELECT gs.* FROM gb_stream gs LEFT JOIN platform_gb_stream pgs " +
88 "ON gs.gbStreamId = pgs.gbStreamId WHERE pgs.gbStreamId is NULL") 93 "ON gs.gbStreamId = pgs.gbStreamId WHERE pgs.gbStreamId is NULL")
89 List<GbStream> queryStreamNotInPlatform(); 94 List<GbStream> queryStreamNotInPlatform();
90 95
91 - @Update("UPDATE gb_stream " +  
92 - "SET status=${status} " +  
93 - "WHERE app=#{app} AND stream=#{stream}")  
94 - int setStatus(String app, String stream, boolean status);  
95 -  
96 - @Update("UPDATE gb_stream " +  
97 - "SET status=${status} " +  
98 - "WHERE mediaServerId=#{mediaServerId} ")  
99 - void updateStatusByMediaServerId(String mediaServerId, boolean status);  
100 -  
101 @Delete("DELETE FROM gb_stream WHERE streamType=#{type} AND gbId=NULL AND mediaServerId=#{mediaServerId}") 96 @Delete("DELETE FROM gb_stream WHERE streamType=#{type} AND gbId=NULL AND mediaServerId=#{mediaServerId}")
102 void deleteWithoutGBId(String type, String mediaServerId); 97 void deleteWithoutGBId(String type, String mediaServerId);
103 98
@@ -120,12 +115,12 @@ public interface GbStreamMapper { @@ -120,12 +115,12 @@ public interface GbStreamMapper {
120 @Insert("<script> " + 115 @Insert("<script> " +
121 "INSERT IGNORE into gb_stream " + 116 "INSERT IGNORE into gb_stream " +
122 "(app, stream, gbId, name, " + 117 "(app, stream, gbId, name, " +
123 - "longitude, latitude, streamType, mediaServerId, status, createTime)" + 118 + "longitude, latitude, streamType, mediaServerId, createTime)" +
124 "values " + 119 "values " +
125 "<foreach collection='subList' index='index' item='item' separator=','> " + 120 "<foreach collection='subList' index='index' item='item' separator=','> " +
126 "('${item.app}', '${item.stream}', '${item.gbId}', '${item.name}', " + 121 "('${item.app}', '${item.stream}', '${item.gbId}', '${item.name}', " +
127 "'${item.longitude}', '${item.latitude}', '${item.streamType}', " + 122 "'${item.longitude}', '${item.latitude}', '${item.streamType}', " +
128 - "'${item.mediaServerId}', ${item.status}, '${item.createTime}') "+ 123 + "'${item.mediaServerId}', '${item.createTime}') "+
129 "</foreach> " + 124 "</foreach> " +
130 "</script>") 125 "</script>")
131 @Options(useGeneratedKeys = true, keyProperty = "gbStreamId", keyColumn = "gbStreamId") 126 @Options(useGeneratedKeys = true, keyProperty = "gbStreamId", keyColumn = "gbStreamId")
src/main/java/com/genersoft/iot/vmp/storager/dao/ParentPlatformMapper.java
@@ -16,10 +16,10 @@ public interface ParentPlatformMapper { @@ -16,10 +16,10 @@ public interface ParentPlatformMapper {
16 16
17 @Insert("INSERT INTO parent_platform (enable, name, serverGBId, serverGBDomain, serverIP, serverPort, deviceGBId, deviceIp, " + 17 @Insert("INSERT INTO parent_platform (enable, name, serverGBId, serverGBDomain, serverIP, serverPort, deviceGBId, deviceIp, " +
18 " devicePort, username, password, expires, keepTimeout, transport, characterSet, ptz, rtcp, " + 18 " devicePort, username, password, expires, keepTimeout, transport, characterSet, ptz, rtcp, " +
19 - " status, shareAllLiveStream, startOfflinePush, catalogId, administrativeDivision, catalogGroup, createTime, updateTime) " + 19 + " status, startOfflinePush, catalogId, administrativeDivision, catalogGroup, createTime, updateTime, treeType) " +
20 " VALUES (${enable}, '${name}', '${serverGBId}', '${serverGBDomain}', '${serverIP}', ${serverPort}, '${deviceGBId}', '${deviceIp}', " + 20 " VALUES (${enable}, '${name}', '${serverGBId}', '${serverGBDomain}', '${serverIP}', ${serverPort}, '${deviceGBId}', '${deviceIp}', " +
21 " '${devicePort}', '${username}', '${password}', '${expires}', '${keepTimeout}', '${transport}', '${characterSet}', ${ptz}, ${rtcp}, " + 21 " '${devicePort}', '${username}', '${password}', '${expires}', '${keepTimeout}', '${transport}', '${characterSet}', ${ptz}, ${rtcp}, " +
22 - " ${status}, ${shareAllLiveStream}, ${startOfflinePush}, #{catalogId}, #{administrativeDivision}, #{catalogGroup}, #{createTime}, #{updateTime})") 22 + " ${status}, ${startOfflinePush}, #{catalogId}, #{administrativeDivision}, #{catalogGroup}, #{createTime}, #{updateTime}, #{treeType})")
23 int addParentPlatform(ParentPlatform parentPlatform); 23 int addParentPlatform(ParentPlatform parentPlatform);
24 24
25 @Update("UPDATE parent_platform " + 25 @Update("UPDATE parent_platform " +
@@ -41,12 +41,12 @@ public interface ParentPlatformMapper { @@ -41,12 +41,12 @@ public interface ParentPlatformMapper {
41 "ptz=#{ptz}, " + 41 "ptz=#{ptz}, " +
42 "rtcp=#{rtcp}, " + 42 "rtcp=#{rtcp}, " +
43 "status=#{status}, " + 43 "status=#{status}, " +
44 - "shareAllLiveStream=#{shareAllLiveStream}, " +  
45 "startOfflinePush=${startOfflinePush}, " + 44 "startOfflinePush=${startOfflinePush}, " +
46 "catalogGroup=#{catalogGroup}, " + 45 "catalogGroup=#{catalogGroup}, " +
47 "administrativeDivision=#{administrativeDivision}, " + 46 "administrativeDivision=#{administrativeDivision}, " +
48 "createTime=#{createTime}, " + 47 "createTime=#{createTime}, " +
49 "updateTime=#{updateTime}, " + 48 "updateTime=#{updateTime}, " +
  49 + "treeType=#{treeType}, " +
50 "catalogId=#{catalogId} " + 50 "catalogId=#{catalogId} " +
51 "WHERE id=#{id}") 51 "WHERE id=#{id}")
52 int updateParentPlatform(ParentPlatform parentPlatform); 52 int updateParentPlatform(ParentPlatform parentPlatform);
@@ -83,9 +83,6 @@ public interface ParentPlatformMapper { @@ -83,9 +83,6 @@ public interface ParentPlatformMapper {
83 @Update("UPDATE parent_platform SET status=#{online} WHERE serverGBId=#{platformGbID}" ) 83 @Update("UPDATE parent_platform SET status=#{online} WHERE serverGBId=#{platformGbID}" )
84 int updateParentPlatformStatus(String platformGbID, boolean online); 84 int updateParentPlatformStatus(String platformGbID, boolean online);
85 85
86 - @Select("SELECT * FROM parent_platform WHERE shareAllLiveStream=true")  
87 - List<ParentPlatform> selectAllAhareAllLiveStream();  
88 -  
89 @Update(value = {" <script>" + 86 @Update(value = {" <script>" +
90 "UPDATE parent_platform " + 87 "UPDATE parent_platform " +
91 "SET catalogId=#{catalogId}, updateTime=#{updateTime}" + 88 "SET catalogId=#{catalogId}, updateTime=#{updateTime}" +
src/main/java/com/genersoft/iot/vmp/storager/dao/PlatformCatalogMapper.java
1 package com.genersoft.iot.vmp.storager.dao; 1 package com.genersoft.iot.vmp.storager.dao;
2 2
  3 +import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
3 import com.genersoft.iot.vmp.gb28181.bean.GbStream; 4 import com.genersoft.iot.vmp.gb28181.bean.GbStream;
4 import com.genersoft.iot.vmp.gb28181.bean.PlatformCatalog; 5 import com.genersoft.iot.vmp.gb28181.bean.PlatformCatalog;
5 import com.genersoft.iot.vmp.gb28181.bean.PlatformGbStream; 6 import com.genersoft.iot.vmp.gb28181.bean.PlatformGbStream;
@@ -14,8 +15,8 @@ import java.util.List; @@ -14,8 +15,8 @@ import java.util.List;
14 @Repository 15 @Repository
15 public interface PlatformCatalogMapper { 16 public interface PlatformCatalogMapper {
16 17
17 - @Insert("INSERT INTO platform_catalog (id, name, platformId, parentId) VALUES" +  
18 - "(#{id}, #{name}, #{platformId}, #{parentId})") 18 + @Insert("INSERT INTO platform_catalog (id, name, platformId, parentId, civilCode, businessGroupId) VALUES" +
  19 + "(#{id}, #{name}, #{platformId}, #{parentId}, #{civilCode}, #{businessGroupId})")
19 int add(PlatformCatalog platformCatalog); 20 int add(PlatformCatalog platformCatalog);
20 21
21 @Delete("DELETE FROM platform_catalog WHERE id=#{id}") 22 @Delete("DELETE FROM platform_catalog WHERE id=#{id}")
@@ -44,4 +45,12 @@ public interface PlatformCatalogMapper { @@ -44,4 +45,12 @@ public interface PlatformCatalogMapper {
44 45
45 @Select("SELECT pc.* FROM platform_catalog pc WHERE pc.id = (SELECT pp.catalogId from parent_platform pp WHERE pp.serverGBId=#{platformId})") 46 @Select("SELECT pc.* FROM platform_catalog pc WHERE pc.id = (SELECT pp.catalogId from parent_platform pp WHERE pp.serverGBId=#{platformId})")
46 PlatformCatalog selectDefaultByPlatFormId(String platformId); 47 PlatformCatalog selectDefaultByPlatFormId(String platformId);
  48 +
  49 +
  50 + @Select("SELECT pc.* FROM platform_catalog pc WHERE pc.id = #{id}")
  51 + PlatformCatalog selectParentCatalog(String id);
  52 +
  53 + @Select("SELECT pc.id as channelId, pc.name, pc.civilCode, pc.businessGroupId,'0' as parental, pc.parentId " +
  54 + " FROM platform_catalog pc WHERE pc.platformId=#{platformId}")
  55 + List<DeviceChannel> queryCatalogInPlatform(String platformId);
47 } 56 }
src/main/java/com/genersoft/iot/vmp/storager/dao/StreamProxyMapper.java
@@ -62,12 +62,12 @@ public interface StreamProxyMapper { @@ -62,12 +62,12 @@ public interface StreamProxyMapper {
62 @Update("UPDATE stream_proxy " + 62 @Update("UPDATE stream_proxy " +
63 "SET status=#{status} " + 63 "SET status=#{status} " +
64 "WHERE mediaServerId=#{mediaServerId}") 64 "WHERE mediaServerId=#{mediaServerId}")
65 - void updateStatusByMediaServerId(boolean status, String mediaServerId); 65 + void updateStatusByMediaServerId(String mediaServerId, boolean status);
66 66
67 @Update("UPDATE stream_proxy " + 67 @Update("UPDATE stream_proxy " +
68 "SET status=${status} " + 68 "SET status=${status} " +
69 "WHERE app=#{app} AND stream=#{stream}") 69 "WHERE app=#{app} AND stream=#{stream}")
70 - int updateStatus(boolean status, String app, String stream); 70 + int updateStatus(String app, String stream, boolean status);
71 71
72 @Delete("DELETE FROM stream_proxy WHERE enable_remove_none_reader=true AND mediaServerId=#{mediaServerId}") 72 @Delete("DELETE FROM stream_proxy WHERE enable_remove_none_reader=true AND mediaServerId=#{mediaServerId}")
73 void deleteAutoRemoveItemByMediaServerId(String mediaServerId); 73 void deleteAutoRemoveItemByMediaServerId(String mediaServerId);
src/main/java/com/genersoft/iot/vmp/storager/dao/StreamPushMapper.java
@@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.storager.dao; @@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.storager.dao;
2 2
3 import com.genersoft.iot.vmp.gb28181.bean.GbStream; 3 import com.genersoft.iot.vmp.gb28181.bean.GbStream;
4 import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; 4 import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
  5 +import com.genersoft.iot.vmp.service.bean.StreamPushItemFromRedis;
5 import org.apache.ibatis.annotations.*; 6 import org.apache.ibatis.annotations.*;
6 // import org.omg.PortableInterceptor.INACTIVE; 7 // import org.omg.PortableInterceptor.INACTIVE;
7 import org.springframework.stereotype.Repository; 8 import org.springframework.stereotype.Repository;
@@ -14,21 +15,24 @@ import java.util.List; @@ -14,21 +15,24 @@ import java.util.List;
14 public interface StreamPushMapper { 15 public interface StreamPushMapper {
15 16
16 @Insert("INSERT INTO stream_push (app, stream, totalReaderCount, originType, originTypeStr, " + 17 @Insert("INSERT INTO stream_push (app, stream, totalReaderCount, originType, originTypeStr, " +
17 - "createStamp, aliveSecond, mediaServerId, serverId) VALUES" + 18 + "pushTime, aliveSecond, mediaServerId, serverId, updateTime, createTime, pushIng) VALUES" +
18 "('${app}', '${stream}', '${totalReaderCount}', '${originType}', '${originTypeStr}', " + 19 "('${app}', '${stream}', '${totalReaderCount}', '${originType}', '${originTypeStr}', " +
19 - "'${createStamp}', '${aliveSecond}', '${mediaServerId}' , '${serverId}' )") 20 + "'${pushTime}', '${aliveSecond}', '${mediaServerId}' , '${serverId}' , '${updateTime}' , '${createTime}', ${pushIng} )")
20 int add(StreamPushItem streamPushItem); 21 int add(StreamPushItem streamPushItem);
21 22
22 - @Update("UPDATE stream_push " +  
23 - "SET app=#{app}," +  
24 - "stream=#{stream}," +  
25 - "mediaServerId=#{mediaServerId}," +  
26 - "totalReaderCount=#{totalReaderCount}, " +  
27 - "originType=#{originType}," +  
28 - "originTypeStr=#{originTypeStr}, " +  
29 - "createStamp=#{createStamp}, " +  
30 - "aliveSecond=#{aliveSecond} " +  
31 - "WHERE app=#{app} AND stream=#{stream}") 23 +
  24 + @Update(value = {" <script>" +
  25 + "UPDATE stream_push " +
  26 + "SET updateTime='${updateTime}'" +
  27 + "<if test=\"mediaServerId != null\">, mediaServerId='${mediaServerId}'</if>" +
  28 + "<if test=\"totalReaderCount != null\">, totalReaderCount='${totalReaderCount}'</if>" +
  29 + "<if test=\"originType != null\">, originType=${originType}</if>" +
  30 + "<if test=\"originTypeStr != null\">, originTypeStr='${originTypeStr}'</if>" +
  31 + "<if test=\"pushTime != null\">, pushTime='${pushTime}'</if>" +
  32 + "<if test=\"aliveSecond != null\">, aliveSecond='${aliveSecond}'</if>" +
  33 + "<if test=\"pushIng != null\">, pushIng=${pushIng}</if>" +
  34 + "WHERE app=#{app} AND stream=#{stream}"+
  35 + " </script>"})
32 int update(StreamPushItem streamPushItem); 36 int update(StreamPushItem streamPushItem);
33 37
34 @Delete("DELETE FROM stream_push WHERE app=#{app} AND stream=#{stream}") 38 @Delete("DELETE FROM stream_push WHERE app=#{app} AND stream=#{stream}")
@@ -62,7 +66,7 @@ public interface StreamPushMapper { @@ -62,7 +66,7 @@ public interface StreamPushMapper {
62 @Select(value = {" <script>" + 66 @Select(value = {" <script>" +
63 "SELECT " + 67 "SELECT " +
64 "st.*, " + 68 "st.*, " +
65 - "gs.gbId, gs.status, gs.name, gs.longitude, gs.latitude, gs.gbStreamId " + 69 + "gs.gbId, gs.name, gs.longitude, gs.latitude, gs.gbStreamId " +
66 "from " + 70 "from " +
67 "stream_push st " + 71 "stream_push st " +
68 "LEFT JOIN gb_stream gs " + 72 "LEFT JOIN gb_stream gs " +
@@ -70,25 +74,26 @@ public interface StreamPushMapper { @@ -70,25 +74,26 @@ public interface StreamPushMapper {
70 "WHERE " + 74 "WHERE " +
71 "1=1 " + 75 "1=1 " +
72 " <if test='query != null'> AND (st.app LIKE '%${query}%' OR st.stream LIKE '%${query}%' OR gs.gbId LIKE '%${query}%' OR gs.name LIKE '%${query}%')</if> " + 76 " <if test='query != null'> AND (st.app LIKE '%${query}%' OR st.stream LIKE '%${query}%' OR gs.gbId LIKE '%${query}%' OR gs.name LIKE '%${query}%')</if> " +
73 - " <if test='pushing == true' > AND (gs.gbId is null OR gs.status=1)</if>" +  
74 - " <if test='pushing == false' > AND gs.status=0</if>" + 77 + " <if test='pushing == true' > AND (gs.gbId is null OR st.status=1)</if>" +
  78 + " <if test='pushing == false' > AND st.status=0</if>" +
75 " <if test='mediaServerId != null' > AND st.mediaServerId=#{mediaServerId} </if>" + 79 " <if test='mediaServerId != null' > AND st.mediaServerId=#{mediaServerId} </if>" +
76 - "order by st.createStamp desc" + 80 + "order by st.createTime desc" +
77 " </script>"}) 81 " </script>"})
78 List<StreamPushItem> selectAllForList(String query, Boolean pushing, String mediaServerId); 82 List<StreamPushItem> selectAllForList(String query, Boolean pushing, String mediaServerId);
79 83
80 - @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") 84 + @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")
81 List<StreamPushItem> selectAll(); 85 List<StreamPushItem> selectAll();
82 86
83 - @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}") 87 + @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}")
84 StreamPushItem selectOne(String app, String stream); 88 StreamPushItem selectOne(String app, String stream);
85 89
86 @Insert("<script>" + 90 @Insert("<script>" +
87 "Insert IGNORE INTO stream_push (app, stream, totalReaderCount, originType, originTypeStr, " + 91 "Insert IGNORE INTO stream_push (app, stream, totalReaderCount, originType, originTypeStr, " +
88 - "createStamp, aliveSecond, mediaServerId) " + 92 + "createTime, aliveSecond, mediaServerId, status, pushIng) " +
89 "VALUES <foreach collection='streamPushItems' item='item' index='index' separator=','>" + 93 "VALUES <foreach collection='streamPushItems' item='item' index='index' separator=','>" +
90 "( '${item.app}', '${item.stream}', '${item.totalReaderCount}', #{item.originType}, " + 94 "( '${item.app}', '${item.stream}', '${item.totalReaderCount}', #{item.originType}, " +
91 - "'${item.originTypeStr}',#{item.createStamp}, #{item.aliveSecond}, '${item.mediaServerId}' )" + 95 + "'${item.originTypeStr}',#{item.createTime}, #{item.aliveSecond}, '${item.mediaServerId}', ${item.status} ," +
  96 + " ${item.pushIng} )" +
92 " </foreach>" + 97 " </foreach>" +
93 "</script>") 98 "</script>")
94 @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") 99 @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
@@ -106,4 +111,59 @@ public interface StreamPushMapper { @@ -106,4 +111,59 @@ public interface StreamPushMapper {
106 @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") 111 @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")
107 List<StreamPushItem> selectAllByMediaServerIdWithOutGbID(String mediaServerId); 112 List<StreamPushItem> selectAllByMediaServerIdWithOutGbID(String mediaServerId);
108 113
  114 + @Update("UPDATE stream_push " +
  115 + "SET status=${status} " +
  116 + "WHERE app=#{app} AND stream=#{stream}")
  117 + int updateStatus(String app, String stream, boolean status);
  118 +
  119 + @Update("UPDATE stream_push " +
  120 + "SET pushIng=${pushIng} " +
  121 + "WHERE app=#{app} AND stream=#{stream}")
  122 + int updatePushStatus(String app, String stream, boolean status);
  123 +
  124 + @Update("UPDATE stream_push " +
  125 + "SET status=#{status} " +
  126 + "WHERE mediaServerId=#{mediaServerId}")
  127 + void updateStatusByMediaServerId(String mediaServerId, boolean status);
  128 +
  129 +
  130 + @Select("<script> "+
  131 + "SELECT gs.* FROM stream_push sp left join gb_stream gs on sp.app = gs.app AND sp.stream = gs.stream " +
  132 + "where sp.status = 1 and (gs.app, gs.stream) in (" +
  133 + "<foreach collection='offlineStreams' item='item' separator=','>" +
  134 + "(#{item.app}, #{item.stream}) " +
  135 + "</foreach>" +
  136 + ")</script>")
  137 + List<GbStream> getOnlinePusherForGbInList(List<StreamPushItemFromRedis> offlineStreams);
  138 +
  139 + @Update("<script> "+
  140 + "UPDATE stream_push SET status=0 where (app, stream) in (" +
  141 + "<foreach collection='offlineStreams' item='item' separator=','>" +
  142 + "(#{item.app}, #{item.stream}) " +
  143 + "</foreach>" +
  144 + ")</script>")
  145 + void offline(List<StreamPushItemFromRedis> offlineStreams);
  146 +
  147 + @Select("<script> "+
  148 + "SELECT * FROM stream_push sp left join gb_stream gs on sp.app = gs.app AND sp.stream = gs.stream " +
  149 + "where sp.status = 0 and (gs.app, gs.stream) in (" +
  150 + "<foreach collection='onlineStreams' item='item' separator=','>" +
  151 + "(#{item.app}, #{item.stream}) " +
  152 + "</foreach>" +
  153 + ") </script>")
  154 + List<GbStream> getOfflinePusherForGbInList(List<StreamPushItemFromRedis> onlineStreams);
  155 +
  156 + @Update("<script> "+
  157 + "UPDATE stream_push SET status=1 where (app, stream) in (" +
  158 + "<foreach collection='onlineStreams' item='item' separator=','>" +
  159 + "(#{item.app}, #{item.stream}) " +
  160 + "</foreach>" +
  161 + ")</script>")
  162 + void online(List<StreamPushItemFromRedis> onlineStreams);
  163 +
  164 + @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")
  165 + List<GbStream> getOnlinePusherForGb();
  166 +
  167 + @Update("UPDATE stream_push SET status=0")
  168 + void setAllStreamOffline();
109 } 169 }
src/main/java/com/genersoft/iot/vmp/storager/dao/UserMapper.java
@@ -10,13 +10,14 @@ import java.util.List; @@ -10,13 +10,14 @@ import java.util.List;
10 @Repository 10 @Repository
11 public interface UserMapper { 11 public interface UserMapper {
12 12
13 - @Insert("INSERT INTO user (username, password, roleId, createTime, updateTime) VALUES" +  
14 - "('${username}', '${password}', '${role.id}', '${createTime}', '${updateTime}')") 13 + @Insert("INSERT INTO user (username, password, roleId, pushKey, createTime, updateTime) VALUES" +
  14 + "('${username}', '${password}', '${role.id}', '${pushKey}', '${createTime}', '${updateTime}')")
15 int add(User user); 15 int add(User user);
16 16
17 @Update(value = {" <script>" + 17 @Update(value = {" <script>" +
18 "UPDATE user " + 18 "UPDATE user " +
19 "SET updateTime='${updateTime}' " + 19 "SET updateTime='${updateTime}' " +
  20 + "<if test=\"pushKey != null\">, pushKey='${pushKey}'</if>" +
20 "<if test=\"role != null\">, roleId='${role.id}'</if>" + 21 "<if test=\"role != null\">, roleId='${role.id}'</if>" +
21 "<if test=\"password != null\">, password='${password}'</if>" + 22 "<if test=\"password != null\">, password='${password}'</if>" +
22 "<if test=\"username != null\">, username='${username}'</if>" + 23 "<if test=\"username != null\">, username='${username}'</if>" +
@@ -48,4 +49,17 @@ public interface UserMapper { @@ -48,4 +49,17 @@ public interface UserMapper {
48 @Select("select u.*, r.id as roleID, r.name as roleName, r.authority as roleAuthority , r.createTime as roleCreateTime , r.updateTime as roleUpdateTime FROM user u, user_role r WHERE u.roleId=r.id") 49 @Select("select u.*, r.id as roleID, r.name as roleName, r.authority as roleAuthority , r.createTime as roleCreateTime , r.updateTime as roleUpdateTime FROM user u, user_role r WHERE u.roleId=r.id")
49 @ResultMap(value="roleMap") 50 @ResultMap(value="roleMap")
50 List<User> selectAll(); 51 List<User> selectAll();
  52 +
  53 + @Select("select * from (select user.*, concat('${callId}_', pushKey) as str1 from user) as u where md5(u.str1) = '${sign}'")
  54 + List<User> checkPushAuthorityByCallIdAndSign(String callId, String sign);
  55 +
  56 + @Select("select * from user where md5(pushKey) = '${sign}'")
  57 + List<User> checkPushAuthorityByCallId(String sign);
  58 +
  59 + @Select("select u.id, u.username,u.pushKey,u.roleId, r.id as roleID, r.name as roleName, r.authority as roleAuthority , r.createTime as roleCreateTime , r.updateTime as roleUpdateTime FROM user u join user_role r on u.roleId=r.id")
  60 + @ResultMap(value="roleMap")
  61 + List<User> getUsers();
  62 +
  63 + @Update("update user set pushKey=#{pushKey} where id=#{id}")
  64 + int changePushKey(int id, String pushKey);
51 } 65 }
src/main/java/com/genersoft/iot/vmp/storager/dao/dto/User.java
@@ -7,6 +7,7 @@ public class User { @@ -7,6 +7,7 @@ public class User {
7 private String password; 7 private String password;
8 private String createTime; 8 private String createTime;
9 private String updateTime; 9 private String updateTime;
  10 + private String pushKey;
10 private Role role; 11 private Role role;
11 12
12 public int getId() { 13 public int getId() {
@@ -56,4 +57,12 @@ public class User { @@ -56,4 +57,12 @@ public class User {
56 public void setRole(Role role) { 57 public void setRole(Role role) {
57 this.role = role; 58 this.role = role;
58 } 59 }
  60 +
  61 + public String getPushKey() {
  62 + return pushKey;
  63 + }
  64 +
  65 + public void setPushKey(String pushKey) {
  66 + this.pushKey = pushKey;
  67 + }
59 } 68 }
src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
@@ -9,6 +9,8 @@ import com.genersoft.iot.vmp.conf.UserSetting; @@ -9,6 +9,8 @@ import com.genersoft.iot.vmp.conf.UserSetting;
9 import com.genersoft.iot.vmp.gb28181.bean.*; 9 import com.genersoft.iot.vmp.gb28181.bean.*;
10 import com.genersoft.iot.vmp.media.zlm.dto.MediaItem; 10 import com.genersoft.iot.vmp.media.zlm.dto.MediaItem;
11 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; 11 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
  12 +import com.genersoft.iot.vmp.media.zlm.dto.OnPublishHookParam;
  13 +import com.genersoft.iot.vmp.media.zlm.dto.StreamAuthorityInfo;
12 import com.genersoft.iot.vmp.service.bean.GPSMsgInfo; 14 import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
13 import com.genersoft.iot.vmp.service.bean.MessageForPushChannel; 15 import com.genersoft.iot.vmp.service.bean.MessageForPushChannel;
14 import com.genersoft.iot.vmp.service.bean.ThirdPartyGB; 16 import com.genersoft.iot.vmp.service.bean.ThirdPartyGB;
@@ -20,6 +22,7 @@ import org.slf4j.Logger; @@ -20,6 +22,7 @@ import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory; 22 import org.slf4j.LoggerFactory;
21 import org.springframework.beans.factory.annotation.Autowired; 23 import org.springframework.beans.factory.annotation.Autowired;
22 import org.springframework.stereotype.Component; 24 import org.springframework.stereotype.Component;
  25 +import org.springframework.util.StringUtils;
23 26
24 import java.util.*; 27 import java.util.*;
25 28
@@ -482,7 +485,12 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { @@ -482,7 +485,12 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
482 485
483 @Override 486 @Override
484 public void addStream(MediaServerItem mediaServerItem, String type, String app, String streamId, MediaItem mediaItem) { 487 public void addStream(MediaServerItem mediaServerItem, String type, String app, String streamId, MediaItem mediaItem) {
  488 + // 查找是否使用了callID
  489 + StreamAuthorityInfo streamAuthorityInfo = getStreamAuthorityInfo(app, streamId);
485 String key = VideoManagerConstants.WVP_SERVER_STREAM_PREFIX + userSetting.getServerId() + "_" + type + "_" + app + "_" + streamId + "_" + mediaServerItem.getId(); 490 String key = VideoManagerConstants.WVP_SERVER_STREAM_PREFIX + userSetting.getServerId() + "_" + type + "_" + app + "_" + streamId + "_" + mediaServerItem.getId();
  491 + if (streamAuthorityInfo != null) {
  492 + mediaItem.setCallId(streamAuthorityInfo.getCallId());
  493 + }
486 redis.set(key, mediaItem); 494 redis.set(key, mediaItem);
487 } 495 }
488 496
@@ -599,6 +607,26 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { @@ -599,6 +607,26 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
599 } 607 }
600 608
601 @Override 609 @Override
  610 + public void updateStreamAuthorityInfo(String app, String stream, StreamAuthorityInfo streamAuthorityInfo) {
  611 + String key = VideoManagerConstants.MEDIA_STREAM_AUTHORITY + userSetting.getServerId() + "_" + app+ "_" + stream;
  612 + redis.set(key, streamAuthorityInfo);
  613 + }
  614 +
  615 + @Override
  616 + public void removeStreamAuthorityInfo(String app, String stream) {
  617 + String key = VideoManagerConstants.MEDIA_STREAM_AUTHORITY + userSetting.getServerId() + "_" + app+ "_" + stream ;
  618 + redis.del(key);
  619 + }
  620 +
  621 + @Override
  622 + public StreamAuthorityInfo getStreamAuthorityInfo(String app, String stream) {
  623 + String key = VideoManagerConstants.MEDIA_STREAM_AUTHORITY + userSetting.getServerId() + "_" + app+ "_" + stream ;
  624 + return (StreamAuthorityInfo) redis.get(key);
  625 +
  626 + }
  627 +
  628 +
  629 + @Override
602 public MediaItem getStreamInfo(String app, String streamId, String mediaServerId) { 630 public MediaItem getStreamInfo(String app, String streamId, String mediaServerId) {
603 String scanKey = VideoManagerConstants.WVP_SERVER_STREAM_PREFIX + userSetting.getServerId() + "_*_" + app + "_" + streamId + "_" + mediaServerId; 631 String scanKey = VideoManagerConstants.WVP_SERVER_STREAM_PREFIX + userSetting.getServerId() + "_*_" + app + "_" + streamId + "_" + mediaServerId;
604 632
@@ -682,4 +710,14 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { @@ -682,4 +710,14 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
682 public boolean deviceIsOnline(String deviceId) { 710 public boolean deviceIsOnline(String deviceId) {
683 return getDevice(deviceId).getOnline() == 1; 711 return getDevice(deviceId).getOnline() == 1;
684 } 712 }
  713 +
  714 +
  715 + @Override
  716 + public void sendStreamPushRequestedMsgForStatus() {
  717 + String key = VideoManagerConstants.VM_MSG_GET_ALL_ONLINE_REQUESTED;
  718 + logger.info("[redis 通知]获取所有推流设备的状态");
  719 + JSONObject jsonObject = new JSONObject();
  720 + jsonObject.put(key, key);
  721 + redis.convertAndSend(key, jsonObject);
  722 + }
685 } 723 }