优化兼容接口

This commit is contained in:
jiang 2022-12-28 10:58:48 +08:00
parent 92c1ab035f
commit a83ee95e10
8 changed files with 48 additions and 30 deletions

View File

@ -99,7 +99,7 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
HashMap<String, DeviceChannel> channelsInStore = new HashMap<>(); HashMap<String, DeviceChannel> channelsInStore = new HashMap<>();
Device device = deviceMapper.getDeviceByDeviceId(deviceId); Device device = deviceMapper.getDeviceByDeviceId(deviceId);
if (channels != null && channels.size() > 0) { 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) { if (channelList.size() == 0) {
for (DeviceChannel channel : channels) { for (DeviceChannel channel : channels) {
channel.setDeviceId(deviceId); channel.setDeviceId(deviceId);

View File

@ -408,7 +408,7 @@ public class DeviceServiceImpl implements IDeviceService {
if (parentId.length() < 14 ) { if (parentId.length() < 14 ) {
return null; 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); List<BaseTree<DeviceChannel>> trees = transportChannelsToTree(deviceChannels, parentId);
return trees; return trees;
} }
@ -453,7 +453,7 @@ public class DeviceServiceImpl implements IDeviceService {
if (parentId.length() < 14 ) { if (parentId.length() < 14 ) {
return null; 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; return deviceChannels;
} }
@ -517,7 +517,7 @@ public class DeviceServiceImpl implements IDeviceService {
} }
}else { }else {
if (haveChannel) { 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) { if (deviceChannels != null && deviceChannels.size() > 0) {
result.addAll(deviceChannels); result.addAll(deviceChannels);
} }

View File

@ -59,7 +59,7 @@ public interface IVideoManagerStorage {
*/ */
public PageInfo queryChannelsByDeviceId(String deviceId, String query, Boolean hasSubChannel, Boolean online, Boolean catalogUnderDevice, int page, int count); 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 @@ public interface IVideoManagerStorage {
* @param deviceId 设备ID * @param deviceId 设备ID
* @return * @return
*/ */
public List<DeviceChannel> queryChannelsByDeviceId(String deviceId); public List<DeviceChannel> queryChannelsByDeviceId(String deviceId,Boolean online,List<String> channelIds);
public List<DeviceChannel> queryOnlineChannelsByDeviceId(String deviceId); public List<DeviceChannel> queryOnlineChannelsByDeviceId(String deviceId);
/** /**
@ -91,14 +91,14 @@ public interface IVideoManagerStorage {
* @param count 每页数量 * @param count 每页数量
* @return List<Device> 设备对象数组 * @return List<Device> 设备对象数组
*/ */
public PageInfo<Device> queryVideoDeviceList(int page, int count); public PageInfo<Device> queryVideoDeviceList(int page, int count,Boolean online);
/** /**
* 获取多个设备 * 获取多个设备
* *
* @return List<Device> 设备对象数组 * @return List<Device> 设备对象数组
*/ */
public List<Device> queryVideoDeviceList(); public List<Device> queryVideoDeviceList(Boolean online);

View File

@ -76,9 +76,12 @@ public interface DeviceChannelMapper {
" <if test='online == false' > AND dc.status=0</if>" + " <if test='online == false' > AND dc.status=0</if>" +
" <if test='hasSubChannel == true' > AND dc.subCount > 0 </if>" + " <if test='hasSubChannel == true' > AND dc.subCount > 0 </if>" +
" <if test='hasSubChannel == false' > 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 " + "ORDER BY dc.channelId " +
" </script>"}) " </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}") @Select("SELECT * FROM device_channel WHERE deviceId=#{deviceId} AND channelId=#{channelId}")
DeviceChannel queryChannel(String deviceId, String channelId); DeviceChannel queryChannel(String deviceId, String channelId);
@ -254,11 +257,14 @@ public interface DeviceChannelMapper {
" <if test='online == false' > AND dc1.status=0</if>" + " <if test='online == false' > AND dc1.status=0</if>" +
" <if test='hasSubChannel == true' > AND dc1.subCount >0</if>" + " <if test='hasSubChannel == true' > AND dc1.subCount >0</if>" +
" <if test='hasSubChannel == false' > 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 " + "ORDER BY dc1.channelId ASC " +
"Limit #{limit} OFFSET #{start}" + "Limit #{limit} OFFSET #{start}" +
" </script>"}) " </script>"})
List<DeviceChannel> queryChannelsByDeviceIdWithStartAndLimit(String deviceId, String parentChannelId, String query, 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") @Select("SELECT * FROM device_channel WHERE deviceId=#{deviceId} AND status=1")
List<DeviceChannel> queryOnlineChannelsByDeviceId(String deviceId); List<DeviceChannel> queryOnlineChannelsByDeviceId(String deviceId);

View File

@ -122,7 +122,9 @@ public interface DeviceMapper {
" </script>"}) " </script>"})
int update(Device device); int update(Device device);
@Select("SELECT " + @Select(
" <script>" +
"SELECT " +
"deviceId, " + "deviceId, " +
"coalesce(custom_name, name) as name, " + "coalesce(custom_name, name) as name, " +
"password, " + "password, " +
@ -150,8 +152,11 @@ public interface DeviceMapper {
"geoCoordSys," + "geoCoordSys," +
"treeType," + "treeType," +
"online," + "online," +
"(SELECT count(0) FROM device_channel WHERE deviceId=de.deviceId) as channelCount FROM device de") "(SELECT count(0) FROM device_channel WHERE deviceId=de.deviceId) as channelCount FROM device de" +
List<Device> getDevices(); "<if test=\"online != null\"> where online=${online}</if>"+
" </script>"
)
List<Device> getDevices(Boolean online);
@Delete("DELETE FROM device WHERE deviceId=#{deviceId}") @Delete("DELETE FROM device WHERE deviceId=#{deviceId}")
int del(String deviceId); int del(String deviceId);

View File

@ -231,31 +231,31 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
PageHelper.startPage(page, count); PageHelper.startPage(page, count);
List<DeviceChannel> all; List<DeviceChannel> all;
if (catalogUnderDevice != null && catalogUnderDevice) { if (catalogUnderDevice != null && catalogUnderDevice) {
all = deviceChannelMapper.queryChannels(deviceId, deviceId, query, hasSubChannel, online); all = deviceChannelMapper.queryChannels(deviceId, deviceId, query, hasSubChannel, online,null);
// 海康设备的parentId是SIP id // 海康设备的parentId是SIP 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); all.addAll(deviceChannels);
}else { }else {
all = deviceChannelMapper.queryChannels(deviceId, null, query, hasSubChannel, online); all = deviceChannelMapper.queryChannels(deviceId, null, query, hasSubChannel, online,null);
} }
return new PageInfo<>(all); return new PageInfo<>(all);
} }
@Override @Override
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) {
return deviceChannelMapper.queryChannelsByDeviceIdWithStartAndLimit(deviceId, null, query, hasSubChannel, online, start, limit); return deviceChannelMapper.queryChannelsByDeviceIdWithStartAndLimit(deviceId, null, query, hasSubChannel, online, start, limit,channelIds);
} }
@Override @Override
public List<DeviceChannel> queryChannelsByDeviceId(String deviceId) { public List<DeviceChannel> queryChannelsByDeviceId(String deviceId,Boolean online,List<String> channelIds) {
return deviceChannelMapper.queryChannels(deviceId, null,null, null, null); return deviceChannelMapper.queryChannels(deviceId, null,null, null, online,channelIds);
} }
@Override @Override
public PageInfo<DeviceChannel> querySubChannels(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, Boolean online, int page, int count) { public PageInfo<DeviceChannel> querySubChannels(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, Boolean online, int page, int count) {
PageHelper.startPage(page, 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); return new PageInfo<>(all);
} }
@ -278,9 +278,9 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
* @return PageInfo<Device> 分页设备对象数组 * @return PageInfo<Device> 分页设备对象数组
*/ */
@Override @Override
public PageInfo<Device> queryVideoDeviceList(int page, int count) { public PageInfo<Device> queryVideoDeviceList(int page, int count,Boolean online) {
PageHelper.startPage(page, count); PageHelper.startPage(page, count);
List<Device> all = deviceMapper.getDevices(); List<Device> all = deviceMapper.getDevices(online);
return new PageInfo<>(all); return new PageInfo<>(all);
} }
@ -290,9 +290,9 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
* @return List<Device> 设备对象数组 * @return List<Device> 设备对象数组
*/ */
@Override @Override
public List<Device> queryVideoDeviceList() { public List<Device> queryVideoDeviceList(Boolean online) {
List<Device> deviceList = deviceMapper.getDevices(); List<Device> deviceList = deviceMapper.getDevices(online);
return deviceList; return deviceList;
} }

View File

@ -99,7 +99,7 @@ public class DeviceQuery {
@GetMapping("/devices") @GetMapping("/devices")
public PageInfo<Device> devices(int page, int count){ public PageInfo<Device> devices(int page, int count){
return storager.queryVideoDeviceList(page, count); return storager.queryVideoDeviceList(page, count,null);
} }
/** /**

View File

@ -10,8 +10,10 @@ import com.github.pagehelper.PageInfo;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List; import java.util.List;
/** /**
@ -59,10 +61,10 @@ public class ApiDeviceController {
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
List<Device> devices; List<Device> devices;
if (start == null || limit ==null) { if (start == null || limit ==null) {
devices = storager.queryVideoDeviceList(); devices = storager.queryVideoDeviceList(online);
result.put("DeviceCount", devices.size()); result.put("DeviceCount", devices.size());
}else { }else {
PageInfo<Device> deviceList = storager.queryVideoDeviceList(start/limit, limit); PageInfo<Device> deviceList = storager.queryVideoDeviceList(start/limit, limit,online);
result.put("DeviceCount", deviceList.getTotal()); result.put("DeviceCount", deviceList.getTotal());
devices = deviceList.getList(); devices = deviceList.getList();
} }
@ -114,12 +116,17 @@ public class ApiDeviceController {
return result; return result;
} }
List<DeviceChannel> deviceChannels; 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) { if (start == null || limit ==null) {
deviceChannels = allDeviceChannelList; deviceChannels = allDeviceChannelList;
result.put("ChannelCount", deviceChannels.size()); result.put("ChannelCount", deviceChannels.size());
}else { }else {
deviceChannels = storager.queryChannelsByDeviceIdWithStartAndLimit(serial, null, null, null,start, limit); deviceChannels = storager.queryChannelsByDeviceIdWithStartAndLimit(serial, null, null, online,start, limit,channelIds);
int total = allDeviceChannelList.size(); int total = allDeviceChannelList.size();
result.put("ChannelCount", total); result.put("ChannelCount", total);
} }