Commit ce035dbcdb38fc1f73ec82f54336f490a632b53b

Authored by 648540858
Committed by GitHub
2 parents 7b601a3e 809e4c98

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

@@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
11 11
12 <groupId>com.genersoft</groupId> 12 <groupId>com.genersoft</groupId>
13 <artifactId>wvp-pro</artifactId> 13 <artifactId>wvp-pro</artifactId>
14 - <version>2.6.6</version> 14 + <version>2.6.7</version>
15 <name>web video platform</name> 15 <name>web video platform</name>
16 <description>国标28181视频平台</description> 16 <description>国标28181视频平台</description>
17 17
sql/update.sql
1 -alter table media_server  
2 - drop column streamNoneReaderDelayMS;  
3 -  
4 -alter table media_server  
5 - drop column sendRtpPortRange;  
6 -  
7 -alter table stream_proxy  
8 - add enable_disable_none_reader bit(1) default null;  
9 - 1 +-- 2.6.6->2.6.7
10 alter table device 2 alter table device
11 - add mediaServerId varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT 'auto';  
12 -  
13 -alter table device  
14 - add custom_name varchar(255) default null;  
15 -  
16 -alter table device  
17 - add sdpIp varchar(50) default null;  
18 -  
19 -alter table device  
20 - add localIp varchar(50) default null;  
21 -  
22 -alter table device  
23 - add password varchar(255) default null;  
24 -  
25 -alter table device  
26 - modify ip varchar(50) null;  
27 -  
28 -alter table device  
29 - modify port int null;  
30 -  
31 -alter table device  
32 - modify expires int null;  
33 -  
34 -alter table device  
35 - modify subscribeCycleForCatalog int null;  
36 -  
37 -alter table device  
38 - modify hostAddress varchar(50) null;  
39 -  
40 -alter table stream_proxy  
41 - change enable_hls enable_audio bit null;  
42 -  
43 - 3 + add keepaliveIntervalTime int default null;
44 \ No newline at end of file 4 \ No newline at end of file
src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java
@@ -70,6 +70,8 @@ public class VideoManagerConstants { @@ -70,6 +70,8 @@ public class VideoManagerConstants {
70 70
71 public static final String SYSTEM_INFO_DISK_PREFIX = "VMP_SYSTEM_INFO_DISK_"; 71 public static final String SYSTEM_INFO_DISK_PREFIX = "VMP_SYSTEM_INFO_DISK_";
72 72
  73 + public static final String REGISTER_EXPIRE_TASK_KEY_PREFIX = "VMP_device_register_expire_";
  74 +
73 75
74 76
75 77
src/main/java/com/genersoft/iot/vmp/gb28181/bean/Device.java
@@ -94,6 +94,13 @@ public class Device { @@ -94,6 +94,13 @@ public class Device {
94 @Schema(description = "心跳时间") 94 @Schema(description = "心跳时间")
95 private String keepaliveTime; 95 private String keepaliveTime;
96 96
  97 +
  98 + /**
  99 + * 心跳间隔
  100 + */
  101 + @Schema(description = "心跳间隔")
  102 + private int keepaliveIntervalTime;
  103 +
97 /** 104 /**
98 * 通道个数 105 * 通道个数
99 */ 106 */
@@ -413,4 +420,12 @@ public class Device { @@ -413,4 +420,12 @@ public class Device {
413 public void setLocalIp(String localIp) { 420 public void setLocalIp(String localIp) {
414 this.localIp = localIp; 421 this.localIp = localIp;
415 } 422 }
  423 +
  424 + public int getKeepaliveIntervalTime() {
  425 + return keepaliveIntervalTime;
  426 + }
  427 +
  428 + public void setKeepaliveIntervalTime(int keepaliveIntervalTime) {
  429 + this.keepaliveIntervalTime = keepaliveIntervalTime;
  430 + }
416 } 431 }
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java
1 package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.cmd; 1 package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.cmd;
2 2
  3 +import com.genersoft.iot.vmp.common.VideoManagerConstants;
  4 +import com.genersoft.iot.vmp.conf.DynamicTask;
3 import com.genersoft.iot.vmp.conf.UserSetting; 5 import com.genersoft.iot.vmp.conf.UserSetting;
4 import com.genersoft.iot.vmp.gb28181.bean.Device; 6 import com.genersoft.iot.vmp.gb28181.bean.Device;
5 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; 7 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
@@ -43,6 +45,9 @@ public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent imp @@ -43,6 +45,9 @@ public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent imp
43 @Autowired 45 @Autowired
44 private UserSetting userSetting; 46 private UserSetting userSetting;
45 47
  48 + @Autowired
  49 + private DynamicTask dynamicTask;
  50 +
46 @Override 51 @Override
47 public void afterPropertiesSet() throws Exception { 52 public void afterPropertiesSet() throws Exception {
48 notifyMessageHandler.addHandler(cmdType, this); 53 notifyMessageHandler.addHandler(cmdType, this);
@@ -68,6 +73,13 @@ public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent imp @@ -68,6 +73,13 @@ public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent imp
68 device.setHostAddress(remoteAddressInfo.getIp().concat(":").concat(String.valueOf(remoteAddressInfo.getPort()))); 73 device.setHostAddress(remoteAddressInfo.getIp().concat(":").concat(String.valueOf(remoteAddressInfo.getPort())));
69 device.setIp(remoteAddressInfo.getIp()); 74 device.setIp(remoteAddressInfo.getIp());
70 } 75 }
  76 + if (device.getKeepaliveTime() == null) {
  77 + device.setKeepaliveIntervalTime(60);
  78 + }else {
  79 + long lastTime = DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(device.getKeepaliveTime());
  80 + device.setKeepaliveIntervalTime(new Long(System.currentTimeMillis()/1000-lastTime).intValue());
  81 + }
  82 +
71 device.setKeepaliveTime(DateUtil.getNow()); 83 device.setKeepaliveTime(DateUtil.getNow());
72 84
73 if (device.getOnline() == 1) { 85 if (device.getOnline() == 1) {
@@ -75,9 +87,15 @@ public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent imp @@ -75,9 +87,15 @@ public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent imp
75 }else { 87 }else {
76 // 对于已经离线的设备判断他的注册是否已经过期 88 // 对于已经离线的设备判断他的注册是否已经过期
77 if (!deviceService.expire(device)){ 89 if (!deviceService.expire(device)){
  90 + device.setOnline(0);
78 deviceService.online(device); 91 deviceService.online(device);
79 } 92 }
80 } 93 }
  94 + // 刷新过期任务
  95 + String registerExpireTaskKey = VideoManagerConstants.REGISTER_EXPIRE_TASK_KEY_PREFIX + device.getDeviceId();
  96 + // 如果三次心跳失败,则设置设备离线
  97 + dynamicTask.startDelay(registerExpireTaskKey, ()-> deviceService.offline(device.getDeviceId()), device.getKeepaliveIntervalTime()*1000*3);
  98 +
81 } 99 }
82 100
83 @Override 101 @Override
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java
@@ -99,7 +99,7 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { @@ -99,7 +99,7 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
99 HashMap<String, DeviceChannel> channelsInStore = new HashMap<>(); 99 HashMap<String, DeviceChannel> channelsInStore = new HashMap<>();
100 Device device = deviceMapper.getDeviceByDeviceId(deviceId); 100 Device device = deviceMapper.getDeviceByDeviceId(deviceId);
101 if (channels != null && channels.size() > 0) { 101 if (channels != null && channels.size() > 0) {
102 - List<DeviceChannel> channelList = channelMapper.queryChannels(deviceId, null, null, null, null); 102 + List<DeviceChannel> channelList = channelMapper.queryChannels(deviceId, null, null, null, null,null);
103 if (channelList.size() == 0) { 103 if (channelList.size() == 0) {
104 for (DeviceChannel channel : channels) { 104 for (DeviceChannel channel : channels) {
105 channel.setDeviceId(deviceId); 105 channel.setDeviceId(deviceId);
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.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.common.VideoManagerConstants;
3 import com.genersoft.iot.vmp.conf.DynamicTask; 4 import com.genersoft.iot.vmp.conf.DynamicTask;
4 import com.genersoft.iot.vmp.conf.UserSetting; 5 import com.genersoft.iot.vmp.conf.UserSetting;
5 import com.genersoft.iot.vmp.gb28181.bean.*; 6 import com.genersoft.iot.vmp.gb28181.bean.*;
@@ -45,8 +46,6 @@ public class DeviceServiceImpl implements IDeviceService { @@ -45,8 +46,6 @@ public class DeviceServiceImpl implements IDeviceService {
45 46
46 private final static Logger logger = LoggerFactory.getLogger(DeviceServiceImpl.class); 47 private final static Logger logger = LoggerFactory.getLogger(DeviceServiceImpl.class);
47 48
48 - private final String registerExpireTaskKeyPrefix = "device-register-expire-";  
49 -  
50 @Autowired 49 @Autowired
51 private DynamicTask dynamicTask; 50 private DynamicTask dynamicTask;
52 51
@@ -101,7 +100,10 @@ public class DeviceServiceImpl implements IDeviceService { @@ -101,7 +100,10 @@ public class DeviceServiceImpl implements IDeviceService {
101 redisCatchStorage.clearCatchByDeviceId(device.getDeviceId()); 100 redisCatchStorage.clearCatchByDeviceId(device.getDeviceId());
102 } 101 }
103 device.setUpdateTime(now); 102 device.setUpdateTime(now);
104 - 103 + if (device.getKeepaliveIntervalTime() == 0) {
  104 + // 默认心跳间隔60
  105 + device.setKeepaliveIntervalTime(60);
  106 + }
105 // 第一次上线 或则设备之前是离线状态--进行通道同步和设备信息查询 107 // 第一次上线 或则设备之前是离线状态--进行通道同步和设备信息查询
106 if (device.getCreateTime() == null) { 108 if (device.getCreateTime() == null) {
107 device.setOnline(1); 109 device.setOnline(1);
@@ -116,7 +118,6 @@ public class DeviceServiceImpl implements IDeviceService { @@ -116,7 +118,6 @@ public class DeviceServiceImpl implements IDeviceService {
116 } 118 }
117 sync(device); 119 sync(device);
118 }else { 120 }else {
119 -  
120 if(device.getOnline() == 0){ 121 if(device.getOnline() == 0){
121 device.setOnline(1); 122 device.setOnline(1);
122 device.setCreateTime(now); 123 device.setCreateTime(now);
@@ -153,19 +154,19 @@ public class DeviceServiceImpl implements IDeviceService { @@ -153,19 +154,19 @@ public class DeviceServiceImpl implements IDeviceService {
153 addMobilePositionSubscribe(device); 154 addMobilePositionSubscribe(device);
154 } 155 }
155 // 刷新过期任务 156 // 刷新过期任务
156 - String registerExpireTaskKey = registerExpireTaskKeyPrefix + device.getDeviceId();  
157 - // 增加一个10秒给设备重发消息的机会  
158 - dynamicTask.startDelay(registerExpireTaskKey, ()-> offline(device.getDeviceId()), (device.getExpires() + 10) * 1000); 157 + String registerExpireTaskKey = VideoManagerConstants.REGISTER_EXPIRE_TASK_KEY_PREFIX + device.getDeviceId();
  158 + // 如果第一次注册那么必须在60 * 3时间内收到一个心跳,否则设备离线
  159 + dynamicTask.startDelay(registerExpireTaskKey, ()-> offline(device.getDeviceId()), device.getKeepaliveIntervalTime() * 1000 * 3);
159 } 160 }
160 161
161 @Override 162 @Override
162 public void offline(String deviceId) { 163 public void offline(String deviceId) {
163 - logger.info("[设备离线], device:{}", deviceId); 164 + logger.error("[设备离线], device:{}", deviceId);
164 Device device = deviceMapper.getDeviceByDeviceId(deviceId); 165 Device device = deviceMapper.getDeviceByDeviceId(deviceId);
165 if (device == null) { 166 if (device == null) {
166 return; 167 return;
167 } 168 }
168 - String registerExpireTaskKey = registerExpireTaskKeyPrefix + deviceId; 169 + String registerExpireTaskKey = VideoManagerConstants.REGISTER_EXPIRE_TASK_KEY_PREFIX + deviceId;
169 dynamicTask.stop(registerExpireTaskKey); 170 dynamicTask.stop(registerExpireTaskKey);
170 device.setOnline(0); 171 device.setOnline(0);
171 redisCatchStorage.updateDevice(device); 172 redisCatchStorage.updateDevice(device);
@@ -408,7 +409,7 @@ public class DeviceServiceImpl implements IDeviceService { @@ -408,7 +409,7 @@ public class DeviceServiceImpl implements IDeviceService {
408 if (parentId.length() < 14 ) { 409 if (parentId.length() < 14 ) {
409 return null; 410 return null;
410 } 411 }
411 - List<DeviceChannel> deviceChannels = deviceChannelMapper.queryChannels(deviceId, parentId, null, null, null); 412 + List<DeviceChannel> deviceChannels = deviceChannelMapper.queryChannels(deviceId, parentId, null, null, null,null);
412 List<BaseTree<DeviceChannel>> trees = transportChannelsToTree(deviceChannels, parentId); 413 List<BaseTree<DeviceChannel>> trees = transportChannelsToTree(deviceChannels, parentId);
413 return trees; 414 return trees;
414 } 415 }
@@ -453,7 +454,7 @@ public class DeviceServiceImpl implements IDeviceService { @@ -453,7 +454,7 @@ public class DeviceServiceImpl implements IDeviceService {
453 if (parentId.length() < 14 ) { 454 if (parentId.length() < 14 ) {
454 return null; 455 return null;
455 } 456 }
456 - List<DeviceChannel> deviceChannels = deviceChannelMapper.queryChannels(deviceId, parentId, null, null, null); 457 + List<DeviceChannel> deviceChannels = deviceChannelMapper.queryChannels(deviceId, parentId, null, null, null,null);
457 return deviceChannels; 458 return deviceChannels;
458 } 459 }
459 460
@@ -517,7 +518,7 @@ public class DeviceServiceImpl implements IDeviceService { @@ -517,7 +518,7 @@ public class DeviceServiceImpl implements IDeviceService {
517 } 518 }
518 }else { 519 }else {
519 if (haveChannel) { 520 if (haveChannel) {
520 - List<DeviceChannel> deviceChannels = deviceChannelMapper.queryChannels(deviceId, null, null, null, null); 521 + List<DeviceChannel> deviceChannels = deviceChannelMapper.queryChannels(deviceId, null, null, null, null,null);
521 if (deviceChannels != null && deviceChannels.size() > 0) { 522 if (deviceChannels != null && deviceChannels.size() > 0) {
522 result.addAll(deviceChannels); 523 result.addAll(deviceChannels);
523 } 524 }
src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java
@@ -59,7 +59,7 @@ public interface IVideoManagerStorage { @@ -59,7 +59,7 @@ public interface IVideoManagerStorage {
59 */ 59 */
60 public PageInfo queryChannelsByDeviceId(String deviceId, String query, Boolean hasSubChannel, Boolean online, Boolean catalogUnderDevice, int page, int count); 60 public PageInfo queryChannelsByDeviceId(String deviceId, String query, Boolean hasSubChannel, Boolean online, Boolean catalogUnderDevice, int page, int count);
61 61
62 - public List<DeviceChannel> queryChannelsByDeviceIdWithStartAndLimit(String deviceId, String query, Boolean hasSubChannel, Boolean online, int start, int limit); 62 + public List<DeviceChannel> queryChannelsByDeviceIdWithStartAndLimit(String deviceId, String query, Boolean hasSubChannel, Boolean online, int start, int limit,List<String> channelIds);
63 63
64 64
65 /** 65 /**
@@ -68,7 +68,7 @@ public interface IVideoManagerStorage { @@ -68,7 +68,7 @@ public interface IVideoManagerStorage {
68 * @param deviceId 设备ID 68 * @param deviceId 设备ID
69 * @return 69 * @return
70 */ 70 */
71 - public List<DeviceChannel> queryChannelsByDeviceId(String deviceId); 71 + public List<DeviceChannel> queryChannelsByDeviceId(String deviceId,Boolean online,List<String> channelIds);
72 public List<DeviceChannel> queryOnlineChannelsByDeviceId(String deviceId); 72 public List<DeviceChannel> queryOnlineChannelsByDeviceId(String deviceId);
73 73
74 /** 74 /**
@@ -91,14 +91,14 @@ public interface IVideoManagerStorage { @@ -91,14 +91,14 @@ public interface IVideoManagerStorage {
91 * @param count 每页数量 91 * @param count 每页数量
92 * @return List<Device> 设备对象数组 92 * @return List<Device> 设备对象数组
93 */ 93 */
94 - public PageInfo<Device> queryVideoDeviceList(int page, int count); 94 + public PageInfo<Device> queryVideoDeviceList(int page, int count,Boolean online);
95 95
96 /** 96 /**
97 * 获取多个设备 97 * 获取多个设备
98 * 98 *
99 * @return List<Device> 设备对象数组 99 * @return List<Device> 设备对象数组
100 */ 100 */
101 - public List<Device> queryVideoDeviceList(); 101 + public List<Device> queryVideoDeviceList(Boolean online);
102 102
103 103
104 104
src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java
@@ -76,9 +76,12 @@ public interface DeviceChannelMapper { @@ -76,9 +76,12 @@ public interface DeviceChannelMapper {
76 " <if test='online == false' > AND dc.status=0</if>" + 76 " <if test='online == false' > AND dc.status=0</if>" +
77 " <if test='hasSubChannel == true' > AND dc.subCount > 0 </if>" + 77 " <if test='hasSubChannel == true' > AND dc.subCount > 0 </if>" +
78 " <if test='hasSubChannel == false' > AND dc.subCount = 0 </if>" + 78 " <if test='hasSubChannel == false' > AND dc.subCount = 0 </if>" +
  79 + "<if test='channelIds != null'> AND dc.channelId in <foreach item='item' index='index' collection='channelIds' open='(' separator=',' close=')'>" +
  80 + "#{item} " +
  81 + "</foreach> </if>" +
79 "ORDER BY dc.channelId " + 82 "ORDER BY dc.channelId " +
80 " </script>"}) 83 " </script>"})
81 - List<DeviceChannel> queryChannels(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, Boolean online); 84 + List<DeviceChannel> queryChannels(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, Boolean online,List<String> channelIds);
82 85
83 @Select("SELECT * FROM device_channel WHERE deviceId=#{deviceId} AND channelId=#{channelId}") 86 @Select("SELECT * FROM device_channel WHERE deviceId=#{deviceId} AND channelId=#{channelId}")
84 DeviceChannel queryChannel(String deviceId, String channelId); 87 DeviceChannel queryChannel(String deviceId, String channelId);
@@ -254,11 +257,14 @@ public interface DeviceChannelMapper { @@ -254,11 +257,14 @@ public interface DeviceChannelMapper {
254 " <if test='online == false' > AND dc1.status=0</if>" + 257 " <if test='online == false' > AND dc1.status=0</if>" +
255 " <if test='hasSubChannel == true' > AND dc1.subCount >0</if>" + 258 " <if test='hasSubChannel == true' > AND dc1.subCount >0</if>" +
256 " <if test='hasSubChannel == false' > AND dc1.subCount=0</if>" + 259 " <if test='hasSubChannel == false' > AND dc1.subCount=0</if>" +
  260 + "<if test='channelIds != null'> AND dc1.channelId in <foreach item='item' index='index' collection='channelIds' open='(' separator=',' close=')'>" +
  261 + "#{item} " +
  262 + "</foreach> </if>" +
257 "ORDER BY dc1.channelId ASC " + 263 "ORDER BY dc1.channelId ASC " +
258 "Limit #{limit} OFFSET #{start}" + 264 "Limit #{limit} OFFSET #{start}" +
259 " </script>"}) 265 " </script>"})
260 List<DeviceChannel> queryChannelsByDeviceIdWithStartAndLimit(String deviceId, String parentChannelId, String query, 266 List<DeviceChannel> queryChannelsByDeviceIdWithStartAndLimit(String deviceId, String parentChannelId, String query,
261 - Boolean hasSubChannel, Boolean online, int start, int limit); 267 + Boolean hasSubChannel, Boolean online, int start, int limit,List<String> channelIds);
262 268
263 @Select("SELECT * FROM device_channel WHERE deviceId=#{deviceId} AND status=1") 269 @Select("SELECT * FROM device_channel WHERE deviceId=#{deviceId} AND status=1")
264 List<DeviceChannel> queryOnlineChannelsByDeviceId(String deviceId); 270 List<DeviceChannel> queryOnlineChannelsByDeviceId(String deviceId);
src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceMapper.java
@@ -61,6 +61,7 @@ public interface DeviceMapper { @@ -61,6 +61,7 @@ public interface DeviceMapper {
61 "expires," + 61 "expires," +
62 "registerTime," + 62 "registerTime," +
63 "keepaliveTime," + 63 "keepaliveTime," +
  64 + "keepaliveIntervalTime," +
64 "createTime," + 65 "createTime," +
65 "updateTime," + 66 "updateTime," +
66 "charset," + 67 "charset," +
@@ -88,6 +89,7 @@ public interface DeviceMapper { @@ -88,6 +89,7 @@ public interface DeviceMapper {
88 "#{expires}," + 89 "#{expires}," +
89 "#{registerTime}," + 90 "#{registerTime}," +
90 "#{keepaliveTime}," + 91 "#{keepaliveTime}," +
  92 + "#{keepaliveIntervalTime}," +
91 "#{createTime}," + 93 "#{createTime}," +
92 "#{updateTime}," + 94 "#{updateTime}," +
93 "#{charset}," + 95 "#{charset}," +
@@ -117,12 +119,15 @@ public interface DeviceMapper { @@ -117,12 +119,15 @@ public interface DeviceMapper {
117 "<if test=\"online != null\">, online=#{online}</if>" + 119 "<if test=\"online != null\">, online=#{online}</if>" +
118 "<if test=\"registerTime != null\">, registerTime=#{registerTime}</if>" + 120 "<if test=\"registerTime != null\">, registerTime=#{registerTime}</if>" +
119 "<if test=\"keepaliveTime != null\">, keepaliveTime=#{keepaliveTime}</if>" + 121 "<if test=\"keepaliveTime != null\">, keepaliveTime=#{keepaliveTime}</if>" +
  122 + "<if test=\"keepaliveIntervalTime != null\">, keepaliveIntervalTime=#{keepaliveIntervalTime}</if>" +
120 "<if test=\"expires != null\">, expires=#{expires}</if>" + 123 "<if test=\"expires != null\">, expires=#{expires}</if>" +
121 "WHERE deviceId=#{deviceId}"+ 124 "WHERE deviceId=#{deviceId}"+
122 " </script>"}) 125 " </script>"})
123 int update(Device device); 126 int update(Device device);
124 127
125 - @Select("SELECT " + 128 + @Select(
  129 + " <script>" +
  130 + "SELECT " +
126 "deviceId, " + 131 "deviceId, " +
127 "coalesce(custom_name, name) as name, " + 132 "coalesce(custom_name, name) as name, " +
128 "password, " + 133 "password, " +
@@ -150,8 +155,11 @@ public interface DeviceMapper { @@ -150,8 +155,11 @@ public interface DeviceMapper {
150 "geoCoordSys," + 155 "geoCoordSys," +
151 "treeType," + 156 "treeType," +
152 "online," + 157 "online," +
153 - "(SELECT count(0) FROM device_channel WHERE deviceId=de.deviceId) as channelCount FROM device de")  
154 - List<Device> getDevices(); 158 + "(SELECT count(0) FROM device_channel WHERE deviceId=de.deviceId) as channelCount FROM device de" +
  159 + "<if test=\"online != null\"> where online=${online}</if>"+
  160 + " </script>"
  161 + )
  162 + List<Device> getDevices(Boolean online);
155 163
156 @Delete("DELETE FROM device WHERE deviceId=#{deviceId}") 164 @Delete("DELETE FROM device WHERE deviceId=#{deviceId}")
157 int del(String deviceId); 165 int del(String deviceId);
src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java
@@ -231,31 +231,31 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { @@ -231,31 +231,31 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
231 PageHelper.startPage(page, count); 231 PageHelper.startPage(page, count);
232 List<DeviceChannel> all; 232 List<DeviceChannel> all;
233 if (catalogUnderDevice != null && catalogUnderDevice) { 233 if (catalogUnderDevice != null && catalogUnderDevice) {
234 - all = deviceChannelMapper.queryChannels(deviceId, deviceId, query, hasSubChannel, online); 234 + all = deviceChannelMapper.queryChannels(deviceId, deviceId, query, hasSubChannel, online,null);
235 // 海康设备的parentId是SIP id 235 // 海康设备的parentId是SIP id
236 - List<DeviceChannel> deviceChannels = deviceChannelMapper.queryChannels(deviceId, sipConfig.getId(), query, hasSubChannel, online); 236 + List<DeviceChannel> deviceChannels = deviceChannelMapper.queryChannels(deviceId, sipConfig.getId(), query, hasSubChannel, online,null);
237 all.addAll(deviceChannels); 237 all.addAll(deviceChannels);
238 }else { 238 }else {
239 - all = deviceChannelMapper.queryChannels(deviceId, null, query, hasSubChannel, online); 239 + all = deviceChannelMapper.queryChannels(deviceId, null, query, hasSubChannel, online,null);
240 } 240 }
241 return new PageInfo<>(all); 241 return new PageInfo<>(all);
242 } 242 }
243 243
244 @Override 244 @Override
245 - public List<DeviceChannel> queryChannelsByDeviceIdWithStartAndLimit(String deviceId, String query, Boolean hasSubChannel, Boolean online, int start, int limit) {  
246 - return deviceChannelMapper.queryChannelsByDeviceIdWithStartAndLimit(deviceId, null, query, hasSubChannel, online, start, limit); 245 + public List<DeviceChannel> queryChannelsByDeviceIdWithStartAndLimit(String deviceId, String query, Boolean hasSubChannel, Boolean online, int start, int limit,List<String> channelIds) {
  246 + return deviceChannelMapper.queryChannelsByDeviceIdWithStartAndLimit(deviceId, null, query, hasSubChannel, online, start, limit,channelIds);
247 } 247 }
248 248
249 249
250 @Override 250 @Override
251 - public List<DeviceChannel> queryChannelsByDeviceId(String deviceId) {  
252 - return deviceChannelMapper.queryChannels(deviceId, null,null, null, null); 251 + public List<DeviceChannel> queryChannelsByDeviceId(String deviceId,Boolean online,List<String> channelIds) {
  252 + return deviceChannelMapper.queryChannels(deviceId, null,null, null, online,channelIds);
253 } 253 }
254 254
255 @Override 255 @Override
256 public PageInfo<DeviceChannel> querySubChannels(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, Boolean online, int page, int count) { 256 public PageInfo<DeviceChannel> querySubChannels(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, Boolean online, int page, int count) {
257 PageHelper.startPage(page, count); 257 PageHelper.startPage(page, count);
258 - List<DeviceChannel> all = deviceChannelMapper.queryChannels(deviceId, parentChannelId, query, hasSubChannel, online); 258 + List<DeviceChannel> all = deviceChannelMapper.queryChannels(deviceId, parentChannelId, query, hasSubChannel, online,null);
259 return new PageInfo<>(all); 259 return new PageInfo<>(all);
260 } 260 }
261 261
@@ -278,9 +278,9 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { @@ -278,9 +278,9 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
278 * @return PageInfo<Device> 分页设备对象数组 278 * @return PageInfo<Device> 分页设备对象数组
279 */ 279 */
280 @Override 280 @Override
281 - public PageInfo<Device> queryVideoDeviceList(int page, int count) { 281 + public PageInfo<Device> queryVideoDeviceList(int page, int count,Boolean online) {
282 PageHelper.startPage(page, count); 282 PageHelper.startPage(page, count);
283 - List<Device> all = deviceMapper.getDevices(); 283 + List<Device> all = deviceMapper.getDevices(online);
284 return new PageInfo<>(all); 284 return new PageInfo<>(all);
285 } 285 }
286 286
@@ -290,9 +290,9 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { @@ -290,9 +290,9 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
290 * @return List<Device> 设备对象数组 290 * @return List<Device> 设备对象数组
291 */ 291 */
292 @Override 292 @Override
293 - public List<Device> queryVideoDeviceList() { 293 + public List<Device> queryVideoDeviceList(Boolean online) {
294 294
295 - List<Device> deviceList = deviceMapper.getDevices(); 295 + List<Device> deviceList = deviceMapper.getDevices(online);
296 return deviceList; 296 return deviceList;
297 } 297 }
298 298
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java
@@ -99,7 +99,7 @@ public class DeviceQuery { @@ -99,7 +99,7 @@ public class DeviceQuery {
99 @GetMapping("/devices") 99 @GetMapping("/devices")
100 public PageInfo<Device> devices(int page, int count){ 100 public PageInfo<Device> devices(int page, int count){
101 101
102 - return storager.queryVideoDeviceList(page, count); 102 + return storager.queryVideoDeviceList(page, count,null);
103 } 103 }
104 104
105 /** 105 /**
src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiDeviceController.java
@@ -10,8 +10,10 @@ import com.github.pagehelper.PageInfo; @@ -10,8 +10,10 @@ import com.github.pagehelper.PageInfo;
10 import org.slf4j.Logger; 10 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory; 11 import org.slf4j.LoggerFactory;
12 import org.springframework.beans.factory.annotation.Autowired; 12 import org.springframework.beans.factory.annotation.Autowired;
  13 +import org.springframework.util.StringUtils;
13 import org.springframework.web.bind.annotation.*; 14 import org.springframework.web.bind.annotation.*;
14 15
  16 +import java.util.Arrays;
15 import java.util.List; 17 import java.util.List;
16 18
17 /** 19 /**
@@ -59,10 +61,10 @@ public class ApiDeviceController { @@ -59,10 +61,10 @@ public class ApiDeviceController {
59 JSONObject result = new JSONObject(); 61 JSONObject result = new JSONObject();
60 List<Device> devices; 62 List<Device> devices;
61 if (start == null || limit ==null) { 63 if (start == null || limit ==null) {
62 - devices = storager.queryVideoDeviceList(); 64 + devices = storager.queryVideoDeviceList(online);
63 result.put("DeviceCount", devices.size()); 65 result.put("DeviceCount", devices.size());
64 }else { 66 }else {
65 - PageInfo<Device> deviceList = storager.queryVideoDeviceList(start/limit, limit); 67 + PageInfo<Device> deviceList = storager.queryVideoDeviceList(start/limit, limit,online);
66 result.put("DeviceCount", deviceList.getTotal()); 68 result.put("DeviceCount", deviceList.getTotal());
67 devices = deviceList.getList(); 69 devices = deviceList.getList();
68 } 70 }
@@ -114,12 +116,17 @@ public class ApiDeviceController { @@ -114,12 +116,17 @@ public class ApiDeviceController {
114 return result; 116 return result;
115 } 117 }
116 List<DeviceChannel> deviceChannels; 118 List<DeviceChannel> deviceChannels;
117 - List<DeviceChannel> allDeviceChannelList = storager.queryChannelsByDeviceId(serial); 119 + List<String> channelIds = null;
  120 + if (!StringUtils.isEmpty(code)) {
  121 + String[] split = code.trim().split(",");
  122 + channelIds = Arrays.asList(split);
  123 + }
  124 + List<DeviceChannel> allDeviceChannelList = storager.queryChannelsByDeviceId(serial,online,channelIds);
118 if (start == null || limit ==null) { 125 if (start == null || limit ==null) {
119 deviceChannels = allDeviceChannelList; 126 deviceChannels = allDeviceChannelList;
120 result.put("ChannelCount", deviceChannels.size()); 127 result.put("ChannelCount", deviceChannels.size());
121 }else { 128 }else {
122 - deviceChannels = storager.queryChannelsByDeviceIdWithStartAndLimit(serial, null, null, null,start, limit); 129 + deviceChannels = storager.queryChannelsByDeviceIdWithStartAndLimit(serial, null, null, online,start, limit,channelIds);
123 int total = allDeviceChannelList.size(); 130 int total = allDeviceChannelList.size();
124 result.put("ChannelCount", total); 131 result.put("ChannelCount", total);
125 } 132 }