pom.xml
@@ -45,9 +45,6 @@ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <!-- 依赖版本 --> <mapper.version>4.1.5</mapper.version> <mybatis.version>3.5.5</mybatis.version> <mybatis.spring.version>2.0.5</mybatis.spring.version> <pagehelper.version>5.2.0</pagehelper.version> <snippetsDirectory>${project.build.directory}/generated-snippets</snippetsDirectory> <asciidoctor.input.directory>${project.basedir}/docs/asciidoc</asciidoctor.input.directory> @@ -59,30 +56,16 @@ <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </dependency> <!-- redis --> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-redis</artifactId> </dependency> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>3.3.0</version> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.1.4</version> </dependency> <!-- druid数据库连接池 --> @@ -106,36 +89,18 @@ <version>3.32.3.2</version> </dependency> <!--Mybatis --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>${mybatis.version}</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>${mybatis.spring.version}</version> </dependency> <!--分页插件 --> <!--Mybatis分页插件 --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>${pagehelper.version}</version> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.10</version> </dependency> <!--通用Mapper --> <dependency> <groupId>tk.mybatis</groupId> <artifactId>mapper</artifactId> <version>${mapper.version}</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.11</version> </dependency> <!-- <dependency>--> <!-- <groupId>org.apache.commons</groupId>--> <!-- <artifactId>commons-lang3</artifactId>--> <!-- <version>3.11</version>--> <!-- </dependency>--> <!--Swagger2 --> <!--在线文档 --> src/main/java/com/genersoft/iot/vmp/common/PageResult.java
File was deleted src/main/java/com/genersoft/iot/vmp/gb28181/bean/Device.java
@@ -1,16 +1,7 @@ package com.genersoft.iot.vmp.gb28181.bean; import java.util.Date; import java.util.List; import java.util.Map; public class Device { /** * 数据库存储ID */ private int id; /** * 设备Id @@ -52,9 +43,19 @@ private String streamMode; /** * wan地址_ip */ private String ip; /** * wan地址_port */ private int port; /** * wan地址 */ private Host host; private String hostAddress; /** * 在线 @@ -71,14 +72,6 @@ * 通道个数 */ private int channelCount; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getDeviceId() { return deviceId; @@ -136,12 +129,28 @@ this.streamMode = streamMode; } public Host getHost() { return host; public String getIp() { return ip; } public void setHost(Host host) { this.host = host; public void setIp(String ip) { this.ip = ip; } public int getPort() { return port; } public void setPort(int port) { this.port = port; } public String getHostAddress() { return hostAddress; } public void setHostAddress(String hostAddress) { this.hostAddress = hostAddress; } public int getOnline() { src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java
@@ -44,9 +44,8 @@ public Request createMessageRequest(Device device, String content, String viaTag, String fromTag, String toTag) throws ParseException, InvalidArgumentException, PeerUnavailableException { Request request = null; Host host = device.getHost(); // sipuri SipURI requestURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), host.getAddress()); SipURI requestURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), device.getHostAddress()); // via ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>(); ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getSipIp(), sipConfig.getSipPort(), @@ -79,12 +78,11 @@ public Request createInviteRequest(Device device, String channelId, String content, String viaTag, String fromTag, String toTag, String ssrc) throws ParseException, InvalidArgumentException, PeerUnavailableException { Request request = null; Host host = device.getHost(); //请求行 SipURI requestLine = sipFactory.createAddressFactory().createSipURI(channelId, host.getAddress()); SipURI requestLine = sipFactory.createAddressFactory().createSipURI(channelId, device.getHostAddress()); //via ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>(); ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(device.getHost().getIp(), device.getHost().getPort(), device.getTransport(), viaTag); ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(device.getIp(), device.getPort(), device.getTransport(), viaTag); viaHeader.setRPort(); viaHeaders.add(viaHeader); @@ -126,12 +124,11 @@ public Request createPlaybackInviteRequest(Device device, String channelId, String content, String viaTag, String fromTag, String toTag) throws ParseException, InvalidArgumentException, PeerUnavailableException { Request request = null; Host host = device.getHost(); //请求行 SipURI requestLine = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), host.getAddress()); SipURI requestLine = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), device.getHostAddress()); // via ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>(); ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(device.getHost().getIp(), device.getHost().getPort(), device.getTransport(), viaTag); ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(device.getIp(), device.getPort(), device.getTransport(), viaTag); viaHeader.setRPort(); viaHeaders.add(viaHeader); //from src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/RegisterRequestProcessor.java
@@ -107,17 +107,15 @@ rPort = viaHeader.getPort(); } // Host host = new Host(); host.setIp(received); host.setPort(rPort); host.setAddress(received.concat(":").concat(String.valueOf(rPort))); AddressImpl address = (AddressImpl) fromHeader.getAddress(); SipUri uri = (SipUri) address.getURI(); String deviceId = uri.getUser(); device = new Device(); device.setStreamMode("UDP"); device.setDeviceId(deviceId); device.setHost(host); device.setIp(received); device.setPort(rPort); device.setHostAddress(received.concat(":").concat(String.valueOf(rPort))); // 注销成功 if (expiresHeader != null && expiresHeader.getExpires() == 0) { registerFlag = 2; src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorager.java
@@ -1,14 +1,10 @@ package com.genersoft.iot.vmp.storager; import java.util.List; import java.util.Map; import com.alibaba.fastjson.JSONObject; import com.genersoft.iot.vmp.common.PageResult; import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.conf.MediaServerConfig; import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; import com.github.pagehelper.PageInfo; /** * @Description:视频设备数据存储接口 @@ -65,7 +61,7 @@ * @param count 每页数量 * @return */ public PageResult queryChannelsByDeviceId(String deviceId, String query, Boolean hasSubChannel, String online, int page, int count); public PageInfo queryChannelsByDeviceId(String deviceId, String query, Boolean hasSubChannel, Boolean online, int page, int count); /** * 获取某个设备的通道列表 @@ -82,13 +78,13 @@ */ public DeviceChannel queryChannel(String deviceId, String channelId); /** /** * 获取多个设备 * * @param deviceIds 设备ID数组 * @param page 当前页数 * @param count 每页数量 * @return List<Device> 设备对象数组 */ public PageResult<Device> queryVideoDeviceList(String[] deviceIds, int page, int count); public PageInfo<Device> queryVideoDeviceList(int page, int count); /** * 获取多个设备 @@ -131,7 +127,7 @@ * @param count * @return */ PageResult querySubChannels(String deviceId, String channelId, String query, Boolean hasSubChannel, String online, int page, int count); PageInfo querySubChannels(String deviceId, String channelId, String query, Boolean hasSubChannel, String online, int page, int count); /** src/main/java/com/genersoft/iot/vmp/storager/VodeoMannagerTask.java
File was deleted src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java
@@ -1,20 +1,50 @@ package com.genersoft.iot.vmp.storager.dao; import com.genersoft.iot.vmp.common.PageResult; import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.*; import java.util.List; /** * 用于存储设备通道信息 */ @Mapper public interface DeviceChannelMapper { @Insert("INSERT INTO device_channel (channelId, deviceId, name, manufacture, model, owner, civilCode, block, " + "address, parental, parentId, safetyWay, registerWay, certNum, certifiable, errCode, secrecy, " + "ipAddress, port, password, PTZType, status) " + "VALUES ('${channelId}', '${deviceId}', '${name}', '${manufacture}', '${model}', '${owner}', '${civilCode}', '${block}'," + "'${address}', ${parental}, '${parentId}', ${safetyWay}, ${registerWay}, '${certNum}', ${certifiable}, ${errCode}, '${secrecy}', " + "'${ipAddress}', ${port}, '${password}', ${PTZType}, ${status})") int add(DeviceChannel channel); @Update("UPDATE device_channel " + "SET name=#{name}, manufacture=#{manufacture}, model=#{model}, owner=#{owner}, civilCode=#{civilCode}, " + "block=#{block}, address=#{address}, parental=#{parental}, parentId=#{parentId}, safetyWay=#{safetyWay}, " + "registerWay=#{registerWay}, certNum=#{certNum}, certifiable=#{certifiable}, errCode=#{errCode}, secrecy=#{secrecy}, " + "ipAddress=#{ipAddress}, port=#{port}, password=#{password}, PTZType=#{PTZType}, status=#{status} " + "WHERE deviceId=#{deviceId} AND channelId=#{channelId}") int update(DeviceChannel channel); List<DeviceChannel> queryChannelsByDeviceId(String deviceId); @Select(value = {" <script>" + "SELECT * FROM ( "+ " SELECT * , (SELECT count(0) FROM device_channel WHERE parentId=dc.channelId) as subCount FROM device_channel dc " + " WHERE dc.deviceId=#{deviceId} " + " <if test=\"query != null\"> AND (dc.channelId LIKE '%${query}%' OR dc.name LIKE '%${query}%' OR dc.name LIKE '%${query}%')</if> " + " <if test=\"parentChannelId != null\"> AND dc.parentId=#{parentChannelId} </if> " + " <if test=\"online == true\" > AND dc.status=1</if>" + " <if test=\"online == false\" > AND dc.status=0</if>) dcr" + " WHERE 1=1 " + " <if test=\"hasSubChannel == true\" > AND subCount >0</if>" + " <if test=\"hasSubChannel == false\" > AND subCount=0</if>" + " </script>"}) List<DeviceChannel> queryChannelsByDeviceId(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, Boolean online); List<DeviceChannel> queryChannelsByDeviceId(String deviceId, String parentChannelId); @Select("SELECT * FROM device_channel WHERE deviceId=#{deviceId} AND channelId=#{channelId}") DeviceChannel queryChannel(String deviceId, String channelId); @Delete("DELETE FROM device_channel WHERE deviceId=#{deviceId}") int cleanChannelsByDeviceId(String deviceId); } src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceMapper.java
@@ -1,24 +1,66 @@ package com.genersoft.iot.vmp.storager.dao; import com.genersoft.iot.vmp.gb28181.bean.Device; import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.*; import org.springframework.stereotype.Repository; import java.util.List; /** * 用于存储设备信息 */ @Mapper @Repository public interface DeviceMapper { @Select("SELECT * FROM device WHERE deviceId = #{deviceId}") Device getDeviceByDeviceId(String deviceId); @Insert("SELECT * FROM device WHERE deviceId = #{deviceId}") @Insert("INSERT INTO device (" + "deviceId, " + "name, " + "manufacturer, " + "model, " + "firmware, " + "transport," + "streamMode," + "ip," + "port," + "hostAddress," + "online" + ") VALUES (" + "#{deviceId}," + "#{name}," + "#{manufacturer}," + "#{model}," + "#{firmware}," + "#{transport}," + "#{streamMode}," + "#{ip}," + "#{port}," + "#{hostAddress}," + "#{online}" + ")") int add(Device device); @Update("UPDATE device " + "SET name=#{name}, " + "manufacturer=#{manufacturer}," + "model=#{model}," + "firmware=#{firmware}, " + "transport=#{transport}," + "streamMode=#{streamMode}, " + "ip=#{ip}, " + "port=#{port}, " + "hostAddress=#{hostAddress}, " + "online=#{online} " + "WHERE deviceId=#{deviceId}") int update(Device device); @Select("SELECT *, (SELECT count(0) FROM device_channel WHERE deviceId=de.deviceId) as channelCount FROM device de") List<Device> getDevices(); @Delete("DELETE FROM device WHERE deviceId=#{deviceId}") int del(String deviceId); } src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
@@ -6,7 +6,6 @@ import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper; import com.genersoft.iot.vmp.storager.dao.DeviceMapper; import com.genersoft.iot.vmp.utils.redis.RedisUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -21,9 +20,6 @@ @Autowired private RedisUtil redis; @Autowired private DeviceMapper deviceMapper; @Autowired private DeviceChannelMapper deviceChannelMapper; src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java
@@ -2,19 +2,17 @@ import java.util.*; import com.genersoft.iot.vmp.common.PageResult; import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.conf.MediaServerConfig; import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper; import com.genersoft.iot.vmp.storager.dao.DeviceMapper; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import io.swagger.models.auth.In; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import com.genersoft.iot.vmp.common.VideoManagerConstants; import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.storager.IVideoManagerStorager; import com.genersoft.iot.vmp.utils.redis.RedisUtil; import org.springframework.util.StringUtils; /** @@ -50,7 +48,7 @@ * @return true:创建成功 false:创建失败 */ @Override public boolean create(Device device) { public synchronized boolean create(Device device) { return deviceMapper.add(device) > 0; } @@ -63,69 +61,26 @@ * @return true:更新成功 false:更新失败 */ @Override public boolean updateDevice(Device device) { // if (deviceMap.get(device.getDeviceId()) == null) { // deviceMap.put(device.getDeviceId(), new HashMap<String, HashSet<String>>()); // } // 更新device中的通道数量 // device.setChannelCount(deviceMap.get(device.getDeviceId()).size()); int result = deviceMapper.update(device); // 存储device return result > 0; public synchronized boolean updateDevice(Device device) { Device deviceByDeviceId = deviceMapper.getDeviceByDeviceId(device.getDeviceId()); if (deviceByDeviceId == null) { return deviceMapper.add(device) > 0; }else { return deviceMapper.update(device) > 0; } } @Override public void updateChannel(String deviceId, DeviceChannel channel) { public synchronized void updateChannel(String deviceId, DeviceChannel channel) { String channelId = channel.getChannelId(); channel.setDeviceId(deviceId); deviceChannelMapper.update(channel); // HashMap<String, HashSet<String>> channelMap = deviceMap.get(deviceId); // if (channelMap == null) return; // // 作为父设备, 确定自己的子节点数 // if (channelMap.get(channelId) == null) { // channelMap.put(channelId, new HashSet<String>()); // }else if (channelMap.get(channelId).size() > 0) { // channel.setSubCount(channelMap.get(channelId).size()); // } // // // 存储通道 // redis.set(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + // "_" + channel.getChannelId() + // "_" + (channel.getStatus() == 1 ? "on":"off") + // "_" + (channelMap.get(channelId).size() > 0)+ // "_" + (StringUtils.isEmpty(channel.getParentId())?null:channel.getParentId()), // channel); // // 更新device中的通道数量 // Device device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceId); // device.setChannelCount(deviceMap.get(deviceId).size()); // redis.set(VideoManagerConstants.DEVICE_PREFIX+device.getDeviceId(), device); // // // // 如果有父设备,更新父设备内子节点数 // String parentId = channel.getParentId(); // if (!StringUtils.isEmpty(parentId) && !parentId.equals(deviceId)) { // // if (channelMap.get(parentId) == null) { // channelMap.put(parentId, new HashSet<String>()); // } // channelMap.get(parentId).add(channelId); // // DeviceChannel deviceChannel = queryChannel(deviceId, parentId); // if (deviceChannel != null) { // deviceChannel.setSubCount(channelMap.get(parentId).size()); // redis.set(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + // "_" + deviceChannel.getChannelId() + // "_" + (deviceChannel.getStatus() == 1 ? "on":"off") + // "_" + (channelMap.get(deviceChannel.getChannelId()).size() > 0)+ // "_" + (StringUtils.isEmpty(deviceChannel.getParentId())?null:deviceChannel.getParentId()), // deviceChannel); // // } // } DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(deviceId, channelId); if (deviceChannel == null) { deviceChannelMapper.add(channel); }else { deviceChannelMapper.update(channel); } } /** @@ -140,179 +95,45 @@ } @Override public PageResult queryChannelsByDeviceId(String deviceId, String query, Boolean hasSubChannel, String online, int page, int count) { public PageInfo queryChannelsByDeviceId(String deviceId, String query, Boolean hasSubChannel, Boolean online, int page, int count) { // 获取到所有正在播放的流 List<DeviceChannel> result = new ArrayList<>(); PageResult pageResult = new PageResult<DeviceChannel>(); deviceChannelMapper.queryChannelsByDeviceId(deviceId); // String queryContent = "*"; // if (!StringUtils.isEmpty(query)) queryContent = String.format("*%S*",query); // String queryHasSubChannel = "*"; // if (hasSubChannel != null) queryHasSubChannel = hasSubChannel?"true":"false"; // String queryOnline = "*"; // if (!StringUtils.isEmpty(online)) queryOnline = online; // String queryStr = VideoManagerConstants.CACHEKEY_PREFIX + deviceId + // "_" + queryContent + // 搜索编号和名称 // "_" + queryOnline + // 搜索是否在线 // "_" + queryHasSubChannel + // 搜索是否含有子节点 // "_" + "*"; // List<Object> deviceChannelList = redis.scan(queryStr); // //对查询结果排序,避免出现通道排列顺序乱序的情况 // Collections.sort(deviceChannelList,new Comparator<Object>(){ // @Override // public int compare(Object o1, Object o2) { // return o1.toString().compareToIgnoreCase(o2.toString()); // } // }); // pageResult.setPage(page); // pageResult.setCount(count); // pageResult.setTotal(deviceChannelList.size()); // int maxCount = (page + 1 ) * count; // if (deviceChannelList != null && deviceChannelList.size() > 0 ) { // for (int i = page * count; i < (pageResult.getTotal() > maxCount ? maxCount : pageResult.getTotal() ); i++) { // DeviceChannel deviceChannel = (DeviceChannel)redis.get((String)deviceChannelList.get(i)); // StreamInfo streamInfo = stringStreamInfoMap.get(deviceId + "_" + deviceChannel.getChannelId()); // deviceChannel.setPlay(streamInfo != null); // if (streamInfo != null) deviceChannel.setStreamId(streamInfo.getStreamId()); // result.add(deviceChannel); // } // pageResult.setData(result); // } return pageResult; PageHelper.startPage(page, count); List<DeviceChannel> all = deviceChannelMapper.queryChannelsByDeviceId(deviceId, null, query, hasSubChannel, online); return new PageInfo<>(all); } @Override public List<DeviceChannel> queryChannelsByDeviceId(String deviceId) { // List<DeviceChannel> result = new ArrayList<>(); //// List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*"); // List<Object> deviceChannelList = redis.scan(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*"); // // if (deviceChannelList != null && deviceChannelList.size() > 0 ) { // for (int i = 0; i < deviceChannelList.size(); i++) { // result.add((DeviceChannel)redis.get((String) deviceChannelList.get(i))); // } // } return deviceChannelMapper.queryChannelsByDeviceId(deviceId); return deviceChannelMapper.queryChannelsByDeviceId(deviceId, null,null, null, null); } @Override public PageResult querySubChannels(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, String online, int page, int count) { deviceChannelMapper.queryChannelsByDeviceId(deviceId, parentChannelId); // List<DeviceChannel> allDeviceChannels = new ArrayList<>(); // String queryContent = "*"; // if (!StringUtils.isEmpty(query)) queryContent = String.format("*%S*",query); // String queryHasSubChannel = "*"; // if (hasSubChannel != null) queryHasSubChannel = hasSubChannel?"true":"false"; // String queryOnline = "*"; // if (!StringUtils.isEmpty(online)) queryOnline = online; // String queryStr = VideoManagerConstants.CACHEKEY_PREFIX + deviceId + // "_" + queryContent + // 搜索编号和名称 // "_" + queryOnline + // 搜索是否在线 // "_" + queryHasSubChannel + // 搜索是否含有子节点 // "_" + parentChannelId; // //// List<Object> deviceChannelList = redis.keys(queryStr); // List<Object> deviceChannelList = redis.scan(queryStr); // // if (deviceChannelList != null && deviceChannelList.size() > 0 ) { // for (int i = 0; i < deviceChannelList.size(); i++) { // DeviceChannel deviceChannel = (DeviceChannel)redis.get((String)deviceChannelList.get(i)); // if (deviceChannel.getParentId() != null && deviceChannel.getParentId().equals(parentChannelId)) { // allDeviceChannels.add(deviceChannel); // } // } // } // int maxCount = (page + 1 ) * count; PageResult pageResult = new PageResult<DeviceChannel>(); // pageResult.setPage(page); // pageResult.setCount(count); // pageResult.setTotal(allDeviceChannels.size()); // // if (allDeviceChannels.size() > 0) { // pageResult.setData(allDeviceChannels.subList( // page * count, pageResult.getTotal() > maxCount ? maxCount : pageResult.getTotal() // )); // } return pageResult; } public List<DeviceChannel> querySubChannels(String deviceId, String parentChannelId) { List<DeviceChannel> allDeviceChannels = new ArrayList<>(); // List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*"); // List<Object> deviceChannelList = redis.scan(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*"); // // if (deviceChannelList != null && deviceChannelList.size() > 0 ) { // for (int i = 0; i < deviceChannelList.size(); i++) { // DeviceChannel deviceChannel = (DeviceChannel)redis.get((String)deviceChannelList.get(i)); // if (deviceChannel.getParentId() != null && deviceChannel.getParentId().equals(parentChannelId)) { // allDeviceChannels.add(deviceChannel); // } // } // } return allDeviceChannels; public PageInfo<DeviceChannel> querySubChannels(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, String online, int page, int count) { PageHelper.startPage(page, count); List<DeviceChannel> all = deviceChannelMapper.queryChannelsByDeviceId(deviceId, parentChannelId, null, null, null); return new PageInfo<>(all); } @Override public DeviceChannel queryChannel(String deviceId, String channelId) { DeviceChannel deviceChannel = null; return deviceChannelMapper.queryChannel(deviceId, channelId); //// List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + // List<Object> deviceChannelList = redis.scan(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + // "_" + channelId + "*"); // if (deviceChannelList != null && deviceChannelList.size() > 0 ) { // deviceChannel = (DeviceChannel)redis.get((String)deviceChannelList.get(0)); // } // return deviceChannel; } /** * 获取多个设备 * * @param deviceIds 设备ID数组 * @return List<Device> 设备对象数组 * @param page 当前页数 * @param count 每页数量 * @return PageInfo<Device> 分页设备对象数组 */ @Override public PageResult<Device> queryVideoDeviceList(String[] deviceIds, int page, int count) { List<Device> devices = new ArrayList<>(); PageResult pageResult = new PageResult<Device>(); // pageResult.setPage(page); // pageResult.setCount(count); // Device device = null; // // if (deviceIds == null || deviceIds.length == 0) { // //// List<Object> deviceIdList = redis.keys(VideoManagerConstants.DEVICE_PREFIX+"*"); // List<Object> deviceIdList = redis.scan(VideoManagerConstants.DEVICE_PREFIX+"*"); // pageResult.setTotal(deviceIdList.size()); // int maxCount = (page + 1)* count; // for (int i = page * count; i < (pageResult.getTotal() > maxCount ? maxCount : pageResult.getTotal() ); i++) { // // devices.add((Device)redis.get((String)deviceIdList.get(i))); // device =(Device)redis.get((String)deviceIdList.get(i)); // if (redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX+device.getDeviceId()).size() == 0){ // // outline(device.getDeviceId()); // } // devices.add(device); // } // } else { // for (int i = 0; i < deviceIds.length; i++) { // // devices.add((Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceIds[i])); // device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceIds[i]); // if (redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX+device.getDeviceId()).size() == 0){ // // outline(device.getDeviceId()); // } // devices.add(device); // } // } // pageResult.setData(devices); return pageResult; public PageInfo<Device> queryVideoDeviceList(int page, int count) { PageHelper.startPage(page, count); List<Device> all = deviceMapper.getDevices(); return new PageInfo<>(all); } /** @@ -322,26 +143,6 @@ */ @Override public List<Device> queryVideoDeviceList() { // if (deviceIds == null || deviceIds.length == 0) { //// List<Object> deviceIdList = redis.keys(VideoManagerConstants.DEVICE_PREFIX+"*"); // List<Object> deviceIdList = redis.scan(VideoManagerConstants.DEVICE_PREFIX+"*"); // for (int i = 0; i < deviceIdList.size(); i++) { // device =(Device)redis.get((String)deviceIdList.get(i)); // if (redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX+device.getDeviceId()).size() == 0){ // outline(device.getDeviceId()); // } // devices.add(device); // } // } else { // for (int i = 0; i < deviceIds.length; i++) { // device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceIds[i]); // if (redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX+device.getDeviceId()).size() == 0){ // outline(device.getDeviceId()); // } // devices.add(device); // } // } List<Device> deviceList = deviceMapper.getDevices(); return deviceList; @@ -367,9 +168,13 @@ * @return true:更新成功 false:更新失败 */ @Override public boolean online(String deviceId) { public synchronized boolean online(String deviceId) { Device device = deviceMapper.getDeviceByDeviceId(deviceId); device.setOnline(1); System.out.println("更新设备在线"); if (device == null) { return false; } return deviceMapper.update(device) > 0; } @@ -380,14 +185,10 @@ * @return true:更新成功 false:更新失败 */ @Override public boolean outline(String deviceId) { // Device device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceId); // if (device == null) return false; // device.setOnline(0); // return redis.set(VideoManagerConstants.DEVICE_PREFIX+device.getDeviceId(), device); public synchronized boolean outline(String deviceId) { Device device = deviceMapper.getDeviceByDeviceId(deviceId); device.setOnline(0); System.out.println("更新设备离线"); return deviceMapper.update(device) > 0; } src/main/java/com/genersoft/iot/vmp/vmanager/device/DeviceController.java
@@ -1,15 +1,14 @@ package com.genersoft.iot.vmp.vmanager.device; import java.util.List; import com.genersoft.iot.vmp.common.PageResult; import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; import com.github.pagehelper.PageInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; import org.springframework.web.context.request.async.DeferredResult; @@ -53,13 +52,13 @@ } @GetMapping("/devices") public PageResult<Device> devices(int page, int count){ public PageInfo<Device> devices(int page, int count){ if (logger.isDebugEnabled()) { logger.debug("查询所有视频设备API调用"); } return storager.queryVideoDeviceList(null, page, count); return storager.queryVideoDeviceList(page, count); } /** @@ -69,18 +68,33 @@ * @param count 每页条数 * @return 通道列表 */ /** * 分页查询通道数 * * @param deviceId 设备id * @param page 当前页 * @param count 每页条数 * @param query 查询内容 * @param online 是否在线 在线 true / 离线 false * @param channelType 设备 false/子目录 true * @return 通道列表 */ @GetMapping("/devices/{deviceId}/channels") public ResponseEntity<PageResult> channels(@PathVariable String deviceId, public ResponseEntity<PageInfo> channels(@PathVariable String deviceId, int page, int count, @RequestParam(required = false) String query, @RequestParam(required = false) String online, @RequestParam(required = false) Boolean online, @RequestParam(required = false) Boolean channelType ){ if (logger.isDebugEnabled()) { logger.debug("查询所有视频设备API调用"); } PageResult pageResult = storager.queryChannelsByDeviceId(deviceId, query, channelType, online, page, count); if (StringUtils.isEmpty(query)) { query = null; } PageInfo pageResult = storager.queryChannelsByDeviceId(deviceId, query, channelType, online, page, count); return new ResponseEntity<>(pageResult,HttpStatus.OK); } @@ -141,7 +155,7 @@ * @return 子通道列表 */ @GetMapping("/subChannels/{deviceId}/{channelId}/channels") public ResponseEntity<PageResult> subChannels(@PathVariable String deviceId, public ResponseEntity<PageInfo> subChannels(@PathVariable String deviceId, @PathVariable String channelId, int page, int count, @@ -154,23 +168,23 @@ } DeviceChannel deviceChannel = storager.queryChannel(deviceId,channelId); if (deviceChannel == null) { PageResult<DeviceChannel> deviceChannelPageResult = new PageResult<>(); PageInfo<DeviceChannel> deviceChannelPageResult = new PageInfo<>(); return new ResponseEntity<>(deviceChannelPageResult,HttpStatus.OK); } PageResult pageResult = storager.querySubChannels(deviceId, channelId, query, channelType, online, page, count); PageInfo pageResult = storager.querySubChannels(deviceId, channelId, query, channelType, online, page, count); return new ResponseEntity<>(pageResult,HttpStatus.OK); } @PostMapping("/channel/update/{deviceId}") public ResponseEntity<PageResult> updateChannel(@PathVariable String deviceId,DeviceChannel channel){ public ResponseEntity<PageInfo> updateChannel(@PathVariable String deviceId,DeviceChannel channel){ storager.updateChannel(deviceId, channel); return new ResponseEntity<>(null,HttpStatus.OK); } @GetMapping("/devices/{deviceId}/transport/{streamMode}") @PostMapping("/devices/{deviceId}/transport/{streamMode}") public ResponseEntity<PageResult> updateTransport(@PathVariable String deviceId, @PathVariable String streamMode){ public ResponseEntity<PageInfo> updateTransport(@PathVariable String deviceId, @PathVariable String streamMode){ Device device = storager.queryVideoDevice(deviceId); device.setStreamMode(streamMode); storager.updateDevice(device); src/main/java/com/genersoft/iot/vmp/vmanager/device/entity/Device.java
File was deleted src/main/java/com/genersoft/iot/vmp/vmanager/device/entity/DeviceChannel.java
File was deleted src/main/java/com/genersoft/iot/vmp/web/ApiDeviceController.java
@@ -1,22 +1,17 @@ package com.genersoft.iot.vmp.web; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.genersoft.iot.vmp.common.PageResult; import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector; import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; import com.genersoft.iot.vmp.storager.IVideoManagerStorager; import com.genersoft.iot.vmp.vmanager.device.DeviceController; import com.github.pagehelper.PageInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -68,9 +63,9 @@ devices = storager.queryVideoDeviceList(); result.put("DeviceCount", devices.size()); }else { PageResult<Device> deviceList = storager.queryVideoDeviceList(null, start/limit, limit); PageInfo<Device> deviceList = storager.queryVideoDeviceList(start/limit, limit); result.put("DeviceCount", deviceList.getTotal()); devices = deviceList.getData(); devices = deviceList.getList(); } JSONArray deviceJSONList = new JSONArray(); @@ -86,8 +81,8 @@ deviceJsonObject.put("Online", device.getOnline() == 1); deviceJsonObject.put("Password", ""); deviceJsonObject.put("MediaTransport", device.getTransport()); deviceJsonObject.put("RemoteIP", device.getHost().getIp()); deviceJsonObject.put("RemotePort", device.getHost().getPort()); deviceJsonObject.put("RemoteIP", device.getIp()); deviceJsonObject.put("RemotePort", device.getPort()); deviceJsonObject.put("LastRegisterAt", ""); deviceJsonObject.put("LastKeepaliveAt", ""); deviceJsonObject.put("UpdatedAt", ""); @@ -123,9 +118,9 @@ deviceChannels = storager.queryChannelsByDeviceId(serial); result.put("ChannelCount", deviceChannels.size()); }else { PageResult<DeviceChannel> pageResult = storager.queryChannelsByDeviceId(serial, null, null, null,start/limit, limit); PageInfo<DeviceChannel> pageResult = storager.queryChannelsByDeviceId(serial, null, null, null,start/limit, limit); result.put("ChannelCount", pageResult.getTotal()); deviceChannels = pageResult.getData(); deviceChannels = pageResult.getList(); } JSONArray channleJSONList = new JSONArray(); src/main/resources/application-dev.yml
@@ -27,6 +27,7 @@ type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.jdbc.Driver # [可选] WVP监听的HTTP端口, 网页和接口调用都是这个端口 server: port: 18080 src/main/resources/application.yml
@@ -1,3 +1,3 @@ spring: profiles: active: dev active: local src/main/resources/wvp.sqliteBinary files differ
web_src/src/components/channelList.vue
@@ -21,8 +21,8 @@ </el-select> 在线状态: <el-select size="mini" @change="search" v-model="online" placeholder="请选择" default-first-option> <el-option label="全部" value=""></el-option> <el-option label="在线" value="on"></el-option> <el-option label="离线" value="off"></el-option> <el-option label="在线" value="true"></el-option> <el-option label="离线" value="false"></el-option> </el-select> </div> @@ -161,7 +161,7 @@ .then(function (res) { console.log(res); that.total = res.data.total; that.deviceChannelList = res.data.data; that.deviceChannelList = res.data.list; // 防止出现表格错位 that.$nextTick(() => { that.$refs.channelListTable.doLayout(); web_src/src/components/videoList.vue
@@ -21,7 +21,7 @@ <el-table-column label="地址" width="180" align="center"> <template slot-scope="scope"> <div slot="reference" class="name-wrapper"> <el-tag size="medium">{{ scope.row.host.address }}</el-tag> <el-tag size="medium">{{ scope.row.hostAddress }}</el-tag> </div> </template> </el-table-column> @@ -140,8 +140,9 @@ } ) .then(function (res) { console.log(res); console.log(res.data.list); that.total = res.data.total; that.deviceList = res.data.data; that.deviceList = res.data.list; that.getDeviceListLoading = false; }) .catch(function (error) {