From 37e973949fa14d01d9ad030973a4974e2f4fef2d Mon Sep 17 00:00:00 2001
From: jiang <893224616@qq.com>
Date: 星期三, 28 十二月 2022 10:58:48 +0800
Subject: [PATCH] 优化兼容接口
---
src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceMapper.java | 11 ++++-
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java | 6 +-
src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java | 8 ++--
src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java | 24 ++++++------
src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiDeviceController.java | 15 +++++--
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java | 2
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java | 2
src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java | 10 ++++-
8 files changed, 48 insertions(+), 30 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java
index 9db2d68..880b697 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java
@@ -99,7 +99,7 @@
HashMap<String, DeviceChannel> channelsInStore = new HashMap<>();
Device device = deviceMapper.getDeviceByDeviceId(deviceId);
if (channels != null && channels.size() > 0) {
- List<DeviceChannel> channelList = channelMapper.queryChannels(deviceId, null, null, null, null);
+ List<DeviceChannel> channelList = channelMapper.queryChannels(deviceId, null, null, null, null,null);
if (channelList.size() == 0) {
for (DeviceChannel channel : channels) {
channel.setDeviceId(deviceId);
diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
index a47e244..ac32918 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
@@ -408,7 +408,7 @@
if (parentId.length() < 14 ) {
return null;
}
- List<DeviceChannel> deviceChannels = deviceChannelMapper.queryChannels(deviceId, parentId, null, null, null);
+ List<DeviceChannel> deviceChannels = deviceChannelMapper.queryChannels(deviceId, parentId, null, null, null,null);
List<BaseTree<DeviceChannel>> trees = transportChannelsToTree(deviceChannels, parentId);
return trees;
}
@@ -453,7 +453,7 @@
if (parentId.length() < 14 ) {
return null;
}
- List<DeviceChannel> deviceChannels = deviceChannelMapper.queryChannels(deviceId, parentId, null, null, null);
+ List<DeviceChannel> deviceChannels = deviceChannelMapper.queryChannels(deviceId, parentId, null, null, null,null);
return deviceChannels;
}
@@ -517,7 +517,7 @@
}
}else {
if (haveChannel) {
- List<DeviceChannel> deviceChannels = deviceChannelMapper.queryChannels(deviceId, null, null, null, null);
+ List<DeviceChannel> deviceChannels = deviceChannelMapper.queryChannels(deviceId, null, null, null, null,null);
if (deviceChannels != null && deviceChannels.size() > 0) {
result.addAll(deviceChannels);
}
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java b/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java
index ab43746..b4644bf 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java
@@ -59,7 +59,7 @@
*/
public PageInfo queryChannelsByDeviceId(String deviceId, String query, Boolean hasSubChannel, Boolean online, Boolean catalogUnderDevice, int page, int count);
- public List<DeviceChannel> queryChannelsByDeviceIdWithStartAndLimit(String deviceId, String query, Boolean hasSubChannel, Boolean online, int start, int limit);
+ public List<DeviceChannel> queryChannelsByDeviceIdWithStartAndLimit(String deviceId, String query, Boolean hasSubChannel, Boolean online, int start, int limit,List<String> channelIds);
/**
@@ -68,7 +68,7 @@
* @param deviceId 璁惧ID
* @return
*/
- public List<DeviceChannel> queryChannelsByDeviceId(String deviceId);
+ public List<DeviceChannel> queryChannelsByDeviceId(String deviceId,Boolean online,List<String> channelIds);
public List<DeviceChannel> queryOnlineChannelsByDeviceId(String deviceId);
/**
@@ -91,14 +91,14 @@
* @param count 姣忛〉鏁伴噺
* @return List<Device> 璁惧瀵硅薄鏁扮粍
*/
- public PageInfo<Device> queryVideoDeviceList(int page, int count);
+ public PageInfo<Device> queryVideoDeviceList(int page, int count,Boolean online);
/**
* 鑾峰彇澶氫釜璁惧
*
* @return List<Device> 璁惧瀵硅薄鏁扮粍
*/
- public List<Device> queryVideoDeviceList();
+ public List<Device> queryVideoDeviceList(Boolean online);
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java
index 53072b2..386cce3 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java
@@ -76,9 +76,12 @@
" <if test='online == false' > AND dc.status=0</if>" +
" <if test='hasSubChannel == true' > AND dc.subCount > 0 </if>" +
" <if test='hasSubChannel == false' > AND dc.subCount = 0 </if>" +
+ "<if test='channelIds != null'> AND dc.channelId in <foreach item='item' index='index' collection='channelIds' open='(' separator=',' close=')'>" +
+ "#{item} " +
+ "</foreach> </if>" +
"ORDER BY dc.channelId " +
" </script>"})
- List<DeviceChannel> queryChannels(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, Boolean online);
+ List<DeviceChannel> queryChannels(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, Boolean online,List<String> channelIds);
@Select("SELECT * FROM device_channel WHERE deviceId=#{deviceId} AND channelId=#{channelId}")
DeviceChannel queryChannel(String deviceId, String channelId);
@@ -254,11 +257,14 @@
" <if test='online == false' > AND dc1.status=0</if>" +
" <if test='hasSubChannel == true' > AND dc1.subCount >0</if>" +
" <if test='hasSubChannel == false' > AND dc1.subCount=0</if>" +
+ "<if test='channelIds != null'> AND dc1.channelId in <foreach item='item' index='index' collection='channelIds' open='(' separator=',' close=')'>" +
+ "#{item} " +
+ "</foreach> </if>" +
"ORDER BY dc1.channelId ASC " +
"Limit #{limit} OFFSET #{start}" +
" </script>"})
List<DeviceChannel> queryChannelsByDeviceIdWithStartAndLimit(String deviceId, String parentChannelId, String query,
- Boolean hasSubChannel, Boolean online, int start, int limit);
+ Boolean hasSubChannel, Boolean online, int start, int limit,List<String> channelIds);
@Select("SELECT * FROM device_channel WHERE deviceId=#{deviceId} AND status=1")
List<DeviceChannel> queryOnlineChannelsByDeviceId(String deviceId);
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceMapper.java
index 0e61692..b9a5817 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceMapper.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceMapper.java
@@ -122,7 +122,9 @@
" </script>"})
int update(Device device);
- @Select("SELECT " +
+ @Select(
+ " <script>" +
+ "SELECT " +
"deviceId, " +
"coalesce(custom_name, name) as name, " +
"password, " +
@@ -150,8 +152,11 @@
"geoCoordSys," +
"treeType," +
"online," +
- "(SELECT count(0) FROM device_channel WHERE deviceId=de.deviceId) as channelCount FROM device de")
- List<Device> getDevices();
+ "(SELECT count(0) FROM device_channel WHERE deviceId=de.deviceId) as channelCount FROM device de" +
+ "<if test=\"online != null\"> where online=${online}</if>"+
+ " </script>"
+ )
+ List<Device> getDevices(Boolean online);
@Delete("DELETE FROM device WHERE deviceId=#{deviceId}")
int del(String deviceId);
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java
index 377b20f..c773036 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java
@@ -231,31 +231,31 @@
PageHelper.startPage(page, count);
List<DeviceChannel> all;
if (catalogUnderDevice != null && catalogUnderDevice) {
- all = deviceChannelMapper.queryChannels(deviceId, deviceId, query, hasSubChannel, online);
+ all = deviceChannelMapper.queryChannels(deviceId, deviceId, query, hasSubChannel, online,null);
// 娴峰悍璁惧鐨刾arentId鏄疭IP id
- List<DeviceChannel> deviceChannels = deviceChannelMapper.queryChannels(deviceId, sipConfig.getId(), query, hasSubChannel, online);
+ List<DeviceChannel> deviceChannels = deviceChannelMapper.queryChannels(deviceId, sipConfig.getId(), query, hasSubChannel, online,null);
all.addAll(deviceChannels);
}else {
- all = deviceChannelMapper.queryChannels(deviceId, null, query, hasSubChannel, online);
+ all = deviceChannelMapper.queryChannels(deviceId, null, query, hasSubChannel, online,null);
}
return new PageInfo<>(all);
}
@Override
- public List<DeviceChannel> queryChannelsByDeviceIdWithStartAndLimit(String deviceId, String query, Boolean hasSubChannel, Boolean online, int start, int limit) {
- return deviceChannelMapper.queryChannelsByDeviceIdWithStartAndLimit(deviceId, null, query, hasSubChannel, online, start, limit);
+ public List<DeviceChannel> queryChannelsByDeviceIdWithStartAndLimit(String deviceId, String query, Boolean hasSubChannel, Boolean online, int start, int limit,List<String> channelIds) {
+ return deviceChannelMapper.queryChannelsByDeviceIdWithStartAndLimit(deviceId, null, query, hasSubChannel, online, start, limit,channelIds);
}
@Override
- public List<DeviceChannel> queryChannelsByDeviceId(String deviceId) {
- return deviceChannelMapper.queryChannels(deviceId, null,null, null, null);
+ public List<DeviceChannel> queryChannelsByDeviceId(String deviceId,Boolean online,List<String> channelIds) {
+ return deviceChannelMapper.queryChannels(deviceId, null,null, null, online,channelIds);
}
@Override
public PageInfo<DeviceChannel> querySubChannels(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, Boolean online, int page, int count) {
PageHelper.startPage(page, count);
- List<DeviceChannel> all = deviceChannelMapper.queryChannels(deviceId, parentChannelId, query, hasSubChannel, online);
+ List<DeviceChannel> all = deviceChannelMapper.queryChannels(deviceId, parentChannelId, query, hasSubChannel, online,null);
return new PageInfo<>(all);
}
@@ -278,9 +278,9 @@
* @return PageInfo<Device> 鍒嗛〉璁惧瀵硅薄鏁扮粍
*/
@Override
- public PageInfo<Device> queryVideoDeviceList(int page, int count) {
+ public PageInfo<Device> queryVideoDeviceList(int page, int count,Boolean online) {
PageHelper.startPage(page, count);
- List<Device> all = deviceMapper.getDevices();
+ List<Device> all = deviceMapper.getDevices(online);
return new PageInfo<>(all);
}
@@ -290,9 +290,9 @@
* @return List<Device> 璁惧瀵硅薄鏁扮粍
*/
@Override
- public List<Device> queryVideoDeviceList() {
+ public List<Device> queryVideoDeviceList(Boolean online) {
- List<Device> deviceList = deviceMapper.getDevices();
+ List<Device> deviceList = deviceMapper.getDevices(online);
return deviceList;
}
diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java
index d4694c5..11bc621 100644
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java
@@ -99,7 +99,7 @@
@GetMapping("/devices")
public PageInfo<Device> devices(int page, int count){
- return storager.queryVideoDeviceList(page, count);
+ return storager.queryVideoDeviceList(page, count,null);
}
/**
diff --git a/src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiDeviceController.java b/src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiDeviceController.java
index a5458b0..e5f4227 100644
--- a/src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiDeviceController.java
+++ b/src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiDeviceController.java
@@ -10,8 +10,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
+import java.util.Arrays;
import java.util.List;
/**
@@ -59,10 +61,10 @@
JSONObject result = new JSONObject();
List<Device> devices;
if (start == null || limit ==null) {
- devices = storager.queryVideoDeviceList();
+ devices = storager.queryVideoDeviceList(online);
result.put("DeviceCount", devices.size());
}else {
- PageInfo<Device> deviceList = storager.queryVideoDeviceList(start/limit, limit);
+ PageInfo<Device> deviceList = storager.queryVideoDeviceList(start/limit, limit,online);
result.put("DeviceCount", deviceList.getTotal());
devices = deviceList.getList();
}
@@ -114,12 +116,17 @@
return result;
}
List<DeviceChannel> deviceChannels;
- List<DeviceChannel> allDeviceChannelList = storager.queryChannelsByDeviceId(serial);
+ List<String> channelIds = null;
+ if (!StringUtils.isEmpty(code)) {
+ String[] split = code.trim().split(",");
+ channelIds = Arrays.asList(split);
+ }
+ List<DeviceChannel> allDeviceChannelList = storager.queryChannelsByDeviceId(serial,online,channelIds);
if (start == null || limit ==null) {
deviceChannels = allDeviceChannelList;
result.put("ChannelCount", deviceChannels.size());
}else {
- deviceChannels = storager.queryChannelsByDeviceIdWithStartAndLimit(serial, null, null, null,start, limit);
+ deviceChannels = storager.queryChannelsByDeviceIdWithStartAndLimit(serial, null, null, online,start, limit,channelIds);
int total = allDeviceChannelList.size();
result.put("ChannelCount", total);
}
--
Gitblit v1.8.0