Commit 809e4c98c5c801b05ad22116a69728f8d3751abb

Authored by 648540858
2 parents a82b831b 37e97394

Merge remote-tracking branch 'gitee.com/wvp-28181-2.0' into wvp-28181-2.0

src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java
... ... @@ -99,7 +99,7 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
99 99 HashMap<String, DeviceChannel> channelsInStore = new HashMap<>();
100 100 Device device = deviceMapper.getDeviceByDeviceId(deviceId);
101 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 103 if (channelList.size() == 0) {
104 104 for (DeviceChannel channel : channels) {
105 105 channel.setDeviceId(deviceId);
... ...
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
... ... @@ -409,7 +409,7 @@ public class DeviceServiceImpl implements IDeviceService {
409 409 if (parentId.length() < 14 ) {
410 410 return null;
411 411 }
412   - List<DeviceChannel> deviceChannels = deviceChannelMapper.queryChannels(deviceId, parentId, null, null, null);
  412 + List<DeviceChannel> deviceChannels = deviceChannelMapper.queryChannels(deviceId, parentId, null, null, null,null);
413 413 List<BaseTree<DeviceChannel>> trees = transportChannelsToTree(deviceChannels, parentId);
414 414 return trees;
415 415 }
... ... @@ -454,7 +454,7 @@ public class DeviceServiceImpl implements IDeviceService {
454 454 if (parentId.length() < 14 ) {
455 455 return null;
456 456 }
457   - List<DeviceChannel> deviceChannels = deviceChannelMapper.queryChannels(deviceId, parentId, null, null, null);
  457 + List<DeviceChannel> deviceChannels = deviceChannelMapper.queryChannels(deviceId, parentId, null, null, null,null);
458 458 return deviceChannels;
459 459 }
460 460  
... ... @@ -518,7 +518,7 @@ public class DeviceServiceImpl implements IDeviceService {
518 518 }
519 519 }else {
520 520 if (haveChannel) {
521   - List<DeviceChannel> deviceChannels = deviceChannelMapper.queryChannels(deviceId, null, null, null, null);
  521 + List<DeviceChannel> deviceChannels = deviceChannelMapper.queryChannels(deviceId, null, null, null, null,null);
522 522 if (deviceChannels != null && deviceChannels.size() > 0) {
523 523 result.addAll(deviceChannels);
524 524 }
... ...
src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java
... ... @@ -59,7 +59,7 @@ public interface IVideoManagerStorage {
59 59 */
60 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 68 * @param deviceId 设备ID
69 69 * @return
70 70 */
71   - public List<DeviceChannel> queryChannelsByDeviceId(String deviceId);
  71 + public List<DeviceChannel> queryChannelsByDeviceId(String deviceId,Boolean online,List<String> channelIds);
72 72 public List<DeviceChannel> queryOnlineChannelsByDeviceId(String deviceId);
73 73  
74 74 /**
... ... @@ -91,14 +91,14 @@ public interface IVideoManagerStorage {
91 91 * @param count 每页数量
92 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 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 76 " <if test='online == false' > AND dc.status=0</if>" +
77 77 " <if test='hasSubChannel == true' > AND dc.subCount > 0 </if>" +
78 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 82 "ORDER BY dc.channelId " +
80 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 86 @Select("SELECT * FROM device_channel WHERE deviceId=#{deviceId} AND channelId=#{channelId}")
84 87 DeviceChannel queryChannel(String deviceId, String channelId);
... ... @@ -254,11 +257,14 @@ public interface DeviceChannelMapper {
254 257 " <if test='online == false' > AND dc1.status=0</if>" +
255 258 " <if test='hasSubChannel == true' > AND dc1.subCount >0</if>" +
256 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 263 "ORDER BY dc1.channelId ASC " +
258 264 "Limit #{limit} OFFSET #{start}" +
259 265 " </script>"})
260 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 269 @Select("SELECT * FROM device_channel WHERE deviceId=#{deviceId} AND status=1")
264 270 List<DeviceChannel> queryOnlineChannelsByDeviceId(String deviceId);
... ...
src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceMapper.java
... ... @@ -125,7 +125,9 @@ public interface DeviceMapper {
125 125 " </script>"})
126 126 int update(Device device);
127 127  
128   - @Select("SELECT " +
  128 + @Select(
  129 + " <script>" +
  130 + "SELECT " +
129 131 "deviceId, " +
130 132 "coalesce(custom_name, name) as name, " +
131 133 "password, " +
... ... @@ -153,8 +155,11 @@ public interface DeviceMapper {
153 155 "geoCoordSys," +
154 156 "treeType," +
155 157 "online," +
156   - "(SELECT count(0) FROM device_channel WHERE deviceId=de.deviceId) as channelCount FROM device de")
157   - 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);
158 163  
159 164 @Delete("DELETE FROM device WHERE deviceId=#{deviceId}")
160 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 231 PageHelper.startPage(page, count);
232 232 List<DeviceChannel> all;
233 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 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 237 all.addAll(deviceChannels);
238 238 }else {
239   - all = deviceChannelMapper.queryChannels(deviceId, null, query, hasSubChannel, online);
  239 + all = deviceChannelMapper.queryChannels(deviceId, null, query, hasSubChannel, online,null);
240 240 }
241 241 return new PageInfo<>(all);
242 242 }
243 243  
244 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 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 255 @Override
256 256 public PageInfo<DeviceChannel> querySubChannels(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, Boolean online, int page, int count) {
257 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 259 return new PageInfo<>(all);
260 260 }
261 261  
... ... @@ -278,9 +278,9 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
278 278 * @return PageInfo<Device> 分页设备对象数组
279 279 */
280 280 @Override
281   - public PageInfo<Device> queryVideoDeviceList(int page, int count) {
  281 + public PageInfo<Device> queryVideoDeviceList(int page, int count,Boolean online) {
282 282 PageHelper.startPage(page, count);
283   - List<Device> all = deviceMapper.getDevices();
  283 + List<Device> all = deviceMapper.getDevices(online);
284 284 return new PageInfo<>(all);
285 285 }
286 286  
... ... @@ -290,9 +290,9 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
290 290 * @return List<Device> 设备对象数组
291 291 */
292 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 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 99 @GetMapping("/devices")
100 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 10 import org.slf4j.Logger;
11 11 import org.slf4j.LoggerFactory;
12 12 import org.springframework.beans.factory.annotation.Autowired;
  13 +import org.springframework.util.StringUtils;
13 14 import org.springframework.web.bind.annotation.*;
14 15  
  16 +import java.util.Arrays;
15 17 import java.util.List;
16 18  
17 19 /**
... ... @@ -59,10 +61,10 @@ public class ApiDeviceController {
59 61 JSONObject result = new JSONObject();
60 62 List<Device> devices;
61 63 if (start == null || limit ==null) {
62   - devices = storager.queryVideoDeviceList();
  64 + devices = storager.queryVideoDeviceList(online);
63 65 result.put("DeviceCount", devices.size());
64 66 }else {
65   - PageInfo<Device> deviceList = storager.queryVideoDeviceList(start/limit, limit);
  67 + PageInfo<Device> deviceList = storager.queryVideoDeviceList(start/limit, limit,online);
66 68 result.put("DeviceCount", deviceList.getTotal());
67 69 devices = deviceList.getList();
68 70 }
... ... @@ -114,12 +116,17 @@ public class ApiDeviceController {
114 116 return result;
115 117 }
116 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 125 if (start == null || limit ==null) {
119 126 deviceChannels = allDeviceChannelList;
120 127 result.put("ChannelCount", deviceChannels.size());
121 128 }else {
122   - deviceChannels = storager.queryChannelsByDeviceIdWithStartAndLimit(serial, null, null, null,start, limit);
  129 + deviceChannels = storager.queryChannelsByDeviceIdWithStartAndLimit(serial, null, null, online,start, limit,channelIds);
123 130 int total = allDeviceChannelList.size();
124 131 result.put("ChannelCount", total);
125 132 }
... ...