Commit 57fd18cd7c842a821bd03fafe2a954c605e387f6
1 parent
764daa8a
增加分页,搜索,等
Showing
13 changed files
with
534 additions
and
320 deletions
.idea/encodings.xml
| @@ -3,5 +3,6 @@ | @@ -3,5 +3,6 @@ | ||
| 3 | <component name="Encoding"> | 3 | <component name="Encoding"> |
| 4 | <file url="file://$PROJECT_DIR$" charset="UTF-8" /> | 4 | <file url="file://$PROJECT_DIR$" charset="UTF-8" /> |
| 5 | <file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" /> | 5 | <file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" /> |
| 6 | + <file url="file://$PROJECT_DIR$/src/main/java/com/genersoft/iot/vmp/storager/redis/VideoManagerRedisStoragerImpl.java" charset="UTF-8" /> | ||
| 6 | </component> | 7 | </component> |
| 7 | </project> | 8 | </project> |
| 8 | \ No newline at end of file | 9 | \ No newline at end of file |
README.md
| @@ -6,38 +6,25 @@ WEB VIDEO PLATFORM譏ッ荳荳ェ蝓コ莠雑B28181-2016譬螳樒鴫逧ス醍サ懆ァ「大ケウ蜿ー | @@ -6,38 +6,25 @@ WEB VIDEO PLATFORM譏ッ荳荳ェ蝓コ莠雑B28181-2016譬螳樒鴫逧ス醍サ懆ァ「大ケウ蜿ー | ||
| 6 | ### fork閾ェ [swwheihei/wvp-GB28181](https://github.com/swwheihei/wvp-GB28181) | 6 | ### fork閾ェ [swwheihei/wvp-GB28181](https://github.com/swwheihei/wvp-GB28181) |
| 7 | 7 | ||
| 8 | # 蠎皮畑蝨コ譎ッ | 8 | # 蠎皮畑蝨コ譎ッ |
| 9 | -荳サ隕∝コ皮畑蝨ィIPC遲芽ョセ螟イ。譛牙崋螳唔P蝨ー蝮御ス怙隕∝惠莠定#鄂台クュ隗ら恚逧惻譎ッ縲 | ||
| 10 | -隕∵アPC隶セ螟庄莉・隶ソ髣ョ莠定#鄂托シ梧怏莠第恪蜉。蝎ィ逕ィ莠朱Κ鄂イ譛ャ譛榊苅縲 | ||
| 11 | -鬚ョ。7譛亥庄莉・霎セ蛻ー蝠畑郤ァ蛻ォ逧枚譯」諤ァ | 9 | +蜴滄。ケ逶ョ豈碑セセァ驥榊黒荳ェ鞫ワ譛コ逧磁蜈・悟ス灘燕霑吩クェ譖エ萓ァ驥榊ケウ蜿ー謗・蜈・悟ス鍋┯檎峩謗・謗・鞫ワ譛コ荵滓弍豐。譛蛾琉鬚倡噪縲 |
| 12 | 10 | ||
| 13 | # 謾ッ謖∫音諤ァ | 11 | # 謾ッ謖∫音諤ァ |
| 14 | 1縲∬ァ「鷹「ァ | 12 | 1縲∬ァ「鷹「ァ |
| 15 | 2縲∽コ大床謗ァ蛻カ域婿蜷代∫シゥ謾セ謗ァ蛻カ | 13 | 2縲∽コ大床謗ァ蛻カ域婿蜷代∫シゥ謾セ謗ァ蛻カ |
| 16 | 3縲∬ァ「題ョセ螟ソ。諱ッ蜷梧ュ・ | 14 | 3縲∬ァ「題ョセ螟ソ。諱ッ蜷梧ュ・ |
| 17 | -4縲∫ヲサ蝨ィ郤ソ逶第而 | ||
| 18 | -5縲∝ス募ワ譟・隸「荳主屓謾セ亥渕莠晒VR\DVR梧嘯荳肴髪謖∝ソォ霑帙《eek謫堺ス懶シ | ||
| 19 | -6縲∵裏莠コ隗ら恚閾ェ蜉ィ譁ュ豬 | ||
| 20 | - | ||
| 21 | -# 2020霍ッ郤ソ蝗セ | ||
| 22 | -5譛井クュ譌ャ-蠖募ワ蝗樊叛亥渕莠晒VR\DVR峨∬ョセ螟ョ、隸シ亥渕莠主ッシ | ||
| 23 | -5譛井ク区流-隶セ螟冠隴ヲ | ||
| 24 | -6譛井ク頑流-豬∝ェ剃ス楢ョ、隸シLM謗ィ豬√∝叙豬シ | ||
| 25 | -6譛井ク区流-隸ュ髻ウ蟇ケ隶イ縲、ndroid Deme\iOS Demo | ||
| 26 | -7譛井ク区流-隶セ螟ョ、隸シ亥渕莠取焚蟄苓ッ∽ケヲ峨寔鄒、驛ィ鄂イ | ||
| 27 | -8譛井ク区流-莠醍ォッ蠖募ワ荳主屓謾セ | ||
| 28 | -9譛井ク区流-Onvif蜊剰ョョ謾ッ謖 | ||
| 29 | -10譛井ク区流-GB28181-2011迚郁ョセ螟る | 15 | +4縲∫ヲサ蝨ィ郤ソ逶第而 |
| 16 | +5縲∵裏莠コ隗ら恚閾ェ蜉ィ譁ュ豬 | ||
| 17 | + | ||
| 18 | +# 蠕ョ樒鴫 | ||
| 19 | +蠖募ワ譟・隸「荳主屓謾セ亥渕莠晒VR\DVR梧嘯荳肴髪謖∝ソォ霑帙《eek謫堺ス懶シ | ||
| 30 | 12譛亥コ-荳顔コァ郤ァ閨斐∵慮髣エ蜷梧ュ・縲∝莉門嵜譬蜉 | 20 | 12譛亥コ-荳顔コァ郤ァ閨斐∵慮髣エ蜷梧ュ・縲∝莉門嵜譬蜉 |
| 31 | 21 | ||
| 32 | # 鬘ケ逶ョ驛ィ鄂イ | 22 | # 鬘ケ逶ョ驛ィ鄂イ |
| 33 | -蜿りヘiki隸エ譏 | 23 | + |
| 34 | 24 | ||
| 35 | # 菴ソ逕ィ蟶ョ蜉ゥ | 25 | # 菴ソ逕ィ蟶ョ蜉ゥ |
| 36 | -蜿りヘiki隸エ譏 | 26 | + |
| 37 | 27 | ||
| 38 | # 閾エ隹「 | 28 | # 閾エ隹「 |
| 39 | 諢溯ー「菴懆螟乗・咯(https://github.com/xiongziliang) 謠蝉セ幄ソ吩ケ域」堤噪蠑貅先オ∝ェ剃ス捺恪蜉。譯楔 | 29 | 諢溯ー「菴懆螟乗・咯(https://github.com/xiongziliang) 謠蝉セ幄ソ吩ケ域」堤噪蠑貅先オ∝ェ剃ス捺恪蜉。譯楔 |
| 40 | -諢溯ー「菴懆kkkkk5G](https://gitee.com/kkkkk5G) 謠蝉セ幄ソ吩ケ域」堤噪蜑咲ォッUI | ||
| 41 | - | ||
| 42 | - | ||
| 43 | -[]: https://github.com/swwheihei/wvp-GB28181 | ||
| 44 | \ No newline at end of file | 30 | \ No newline at end of file |
| 31 | +諢溯ー「菴懆kkkkk5G](https://gitee.com/kkkkk5G) 謠蝉セ幄ソ吩ケ域」堤噪蜑咲ォッUI | ||
| 45 | \ No newline at end of file | 32 | \ No newline at end of file |
src/main/java/com/genersoft/iot/vmp/conf/VManagerConfig.java
src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceChannel.java
| @@ -129,6 +129,11 @@ public class DeviceChannel { | @@ -129,6 +129,11 @@ public class DeviceChannel { | ||
| 129 | private double latitude; | 129 | private double latitude; |
| 130 | 130 | ||
| 131 | /** | 131 | /** |
| 132 | + * 子设备数 | ||
| 133 | + */ | ||
| 134 | + private int subCount; | ||
| 135 | + | ||
| 136 | + /** | ||
| 132 | * 流唯一编号,存在表示正在直播 | 137 | * 流唯一编号,存在表示正在直播 |
| 133 | */ | 138 | */ |
| 134 | private String ssrc; | 139 | private String ssrc; |
| @@ -332,4 +337,12 @@ public class DeviceChannel { | @@ -332,4 +337,12 @@ public class DeviceChannel { | ||
| 332 | public void setSsrc(String ssrc) { | 337 | public void setSsrc(String ssrc) { |
| 333 | this.ssrc = ssrc; | 338 | this.ssrc = ssrc; |
| 334 | } | 339 | } |
| 340 | + | ||
| 341 | + public int getSubCount() { | ||
| 342 | + return subCount; | ||
| 343 | + } | ||
| 344 | + | ||
| 345 | + public void setSubCount(int subCount) { | ||
| 346 | + this.subCount = subCount; | ||
| 347 | + } | ||
| 335 | } | 348 | } |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorFactory.java
| @@ -7,6 +7,7 @@ import javax.sip.header.CSeqHeader; | @@ -7,6 +7,7 @@ import javax.sip.header.CSeqHeader; | ||
| 7 | import javax.sip.message.Request; | 7 | import javax.sip.message.Request; |
| 8 | import javax.sip.message.Response; | 8 | import javax.sip.message.Response; |
| 9 | 9 | ||
| 10 | +import com.alibaba.fastjson.JSON; | ||
| 10 | import org.slf4j.Logger; | 11 | import org.slf4j.Logger; |
| 11 | import org.slf4j.LoggerFactory; | 12 | import org.slf4j.LoggerFactory; |
| 12 | import org.springframework.beans.factory.annotation.Autowired; | 13 | import org.springframework.beans.factory.annotation.Autowired; |
| @@ -126,6 +127,7 @@ public class SIPProcessorFactory { | @@ -126,6 +127,7 @@ public class SIPProcessorFactory { | ||
| 126 | processor.setRequestEvent(evt); | 127 | processor.setRequestEvent(evt); |
| 127 | return processor; | 128 | return processor; |
| 128 | } else if (Request.MESSAGE.equals(method)) { | 129 | } else if (Request.MESSAGE.equals(method)) { |
| 130 | + | ||
| 129 | MessageRequestProcessor processor = new MessageRequestProcessor(); | 131 | MessageRequestProcessor processor = new MessageRequestProcessor(); |
| 130 | processor.setRequestEvent(evt); | 132 | processor.setRequestEvent(evt); |
| 131 | processor.setTcpSipProvider(getTcpSipProvider()); | 133 | processor.setTcpSipProvider(getTcpSipProvider()); |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java
| @@ -144,6 +144,7 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -144,6 +144,7 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 144 | private void processMessageCatalogList(RequestEvent evt) { | 144 | private void processMessageCatalogList(RequestEvent evt) { |
| 145 | try { | 145 | try { |
| 146 | Element rootElement = getRootElement(evt); | 146 | Element rootElement = getRootElement(evt); |
| 147 | + String s = rootElement.toString(); | ||
| 147 | Element deviceIdElement = rootElement.element("DeviceID"); | 148 | Element deviceIdElement = rootElement.element("DeviceID"); |
| 148 | String deviceId = deviceIdElement.getText().toString(); | 149 | String deviceId = deviceIdElement.getText().toString(); |
| 149 | Element deviceListElement = rootElement.element("DeviceList"); | 150 | Element deviceListElement = rootElement.element("DeviceList"); |
| @@ -171,10 +172,10 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -171,10 +172,10 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 171 | DeviceChannel deviceChannel = new DeviceChannel(); | 172 | DeviceChannel deviceChannel = new DeviceChannel(); |
| 172 | deviceChannel.setName(channelName); | 173 | deviceChannel.setName(channelName); |
| 173 | deviceChannel.setChannelId(channelDeviceId); | 174 | deviceChannel.setChannelId(channelDeviceId); |
| 174 | - if(status.equals("ON")) { | 175 | + if(status.equals("ON") || status.equals("On")) { |
| 175 | deviceChannel.setStatus(1); | 176 | deviceChannel.setStatus(1); |
| 176 | } | 177 | } |
| 177 | - if(status.equals("OFF")) { | 178 | + if(status.equals("OFF") || status.equals("Off")) { |
| 178 | deviceChannel.setStatus(0); | 179 | deviceChannel.setStatus(0); |
| 179 | } | 180 | } |
| 180 | 181 | ||
| @@ -185,7 +186,7 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | @@ -185,7 +186,7 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 185 | deviceChannel.setBlock(XmlUtil.getText(itemDevice,"Block")); | 186 | deviceChannel.setBlock(XmlUtil.getText(itemDevice,"Block")); |
| 186 | deviceChannel.setAddress(XmlUtil.getText(itemDevice,"Address")); | 187 | deviceChannel.setAddress(XmlUtil.getText(itemDevice,"Address")); |
| 187 | deviceChannel.setParental(itemDevice.element("Parental") == null? 0:Integer.parseInt(XmlUtil.getText(itemDevice,"Parental"))); | 188 | deviceChannel.setParental(itemDevice.element("Parental") == null? 0:Integer.parseInt(XmlUtil.getText(itemDevice,"Parental"))); |
| 188 | - deviceChannel.setParentId(XmlUtil.getText(itemDevice,"ParentId")); | 189 | + deviceChannel.setParentId(XmlUtil.getText(itemDevice,"ParentID")); |
| 189 | deviceChannel.setSafetyWay(itemDevice.element("SafetyWay") == null? 0:Integer.parseInt(XmlUtil.getText(itemDevice,"SafetyWay"))); | 190 | deviceChannel.setSafetyWay(itemDevice.element("SafetyWay") == null? 0:Integer.parseInt(XmlUtil.getText(itemDevice,"SafetyWay"))); |
| 190 | deviceChannel.setRegisterWay(itemDevice.element("RegisterWay") == null? 1:Integer.parseInt(XmlUtil.getText(itemDevice,"RegisterWay"))); | 191 | deviceChannel.setRegisterWay(itemDevice.element("RegisterWay") == null? 1:Integer.parseInt(XmlUtil.getText(itemDevice,"RegisterWay"))); |
| 191 | deviceChannel.setCertNum(XmlUtil.getText(itemDevice,"CertNum")); | 192 | deviceChannel.setCertNum(XmlUtil.getText(itemDevice,"CertNum")); |
src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorager.java
| @@ -77,7 +77,7 @@ public interface IVideoManagerStorager { | @@ -77,7 +77,7 @@ public interface IVideoManagerStorager { | ||
| 77 | * @param count 每页数量 | 77 | * @param count 每页数量 |
| 78 | * @return | 78 | * @return |
| 79 | */ | 79 | */ |
| 80 | - public PageResult queryChannelsByDeviceId(String deviceId, int page, int count); | 80 | + public PageResult queryChannelsByDeviceId(String deviceId, String query, Boolean hasSubChannel, String online, int page, int count); |
| 81 | 81 | ||
| 82 | /** | 82 | /** |
| 83 | * 获取某个设备的通道列表 | 83 | * 获取某个设备的通道列表 |
| @@ -161,6 +161,19 @@ public interface IVideoManagerStorager { | @@ -161,6 +161,19 @@ public interface IVideoManagerStorager { | ||
| 161 | */ | 161 | */ |
| 162 | public StreamInfo queryPlay(String deviceId, String channelId); | 162 | public StreamInfo queryPlay(String deviceId, String channelId); |
| 163 | 163 | ||
| 164 | + /** | ||
| 165 | + * 查询子设备 | ||
| 166 | + * | ||
| 167 | + * @param deviceId | ||
| 168 | + * @param channelId | ||
| 169 | + * @param page | ||
| 170 | + * @param count | ||
| 171 | + * @return | ||
| 172 | + */ | ||
| 173 | + PageResult querySubChannels(String deviceId, String channelId, String query, Boolean hasSubChannel, String online, int page, int count); | ||
| 164 | 174 | ||
| 165 | - | 175 | + /** |
| 176 | + * 更新缓存 | ||
| 177 | + */ | ||
| 178 | + public void updateCatch(); | ||
| 166 | } | 179 | } |
src/main/java/com/genersoft/iot/vmp/storager/VodeoMannagerTask.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.storager; | ||
| 2 | + | ||
| 3 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 4 | +import org.springframework.boot.CommandLineRunner; | ||
| 5 | +import org.springframework.stereotype.Component; | ||
| 6 | + | ||
| 7 | +@Component | ||
| 8 | +public class VodeoMannagerTask implements CommandLineRunner { | ||
| 9 | + | ||
| 10 | + @Autowired | ||
| 11 | + private IVideoManagerStorager storager; | ||
| 12 | + | ||
| 13 | + @Override | ||
| 14 | + public void run(String... strings) throws Exception { | ||
| 15 | + storager.updateCatch(); | ||
| 16 | + } | ||
| 17 | +} |
src/main/java/com/genersoft/iot/vmp/storager/jdbc/VideoManagerJdbcStoragerImpl.java
| @@ -79,10 +79,11 @@ public class VideoManagerJdbcStoragerImpl implements IVideoManagerStorager { | @@ -79,10 +79,11 @@ public class VideoManagerJdbcStoragerImpl implements IVideoManagerStorager { | ||
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | @Override | 81 | @Override |
| 82 | - public PageResult queryChannelsByDeviceId(String deviceId, int page, int count) { | 82 | + public PageResult queryChannelsByDeviceId(String deviceId, String query, Boolean hasSubChannel, String online, int page, int count) { |
| 83 | return null; | 83 | return null; |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | + | ||
| 86 | @Override | 87 | @Override |
| 87 | public List<DeviceChannel> queryChannelsByDeviceId(String deviceId) { | 88 | public List<DeviceChannel> queryChannelsByDeviceId(String deviceId) { |
| 88 | return null; | 89 | return null; |
| @@ -161,4 +162,13 @@ public class VideoManagerJdbcStoragerImpl implements IVideoManagerStorager { | @@ -161,4 +162,13 @@ public class VideoManagerJdbcStoragerImpl implements IVideoManagerStorager { | ||
| 161 | return null; | 162 | return null; |
| 162 | } | 163 | } |
| 163 | 164 | ||
| 165 | + @Override | ||
| 166 | + public PageResult querySubChannels(String deviceId, String channelId, String query, Boolean hasSubChannel, String online, int page, int count) { | ||
| 167 | + return null; | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + @Override | ||
| 171 | + public void updateCatch() { | ||
| 172 | + | ||
| 173 | + } | ||
| 164 | } | 174 | } |
src/main/java/com/genersoft/iot/vmp/storager/redis/VideoManagerRedisStoragerImpl.java
| 1 | -package com.genersoft.iot.vmp.storager.redis; | ||
| 2 | - | ||
| 3 | -import java.util.ArrayList; | ||
| 4 | -import java.util.List; | ||
| 5 | - | ||
| 6 | -import com.alibaba.fastjson.JSON; | ||
| 7 | -import com.alibaba.fastjson.JSONObject; | ||
| 8 | -import com.genersoft.iot.vmp.common.PageResult; | ||
| 9 | -import com.genersoft.iot.vmp.common.StreamInfo; | ||
| 10 | -import com.genersoft.iot.vmp.conf.MediaServerConfig; | ||
| 11 | -import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; | ||
| 12 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 13 | -import org.springframework.stereotype.Component; | ||
| 14 | - | ||
| 15 | -import com.genersoft.iot.vmp.common.VideoManagerConstants; | ||
| 16 | -import com.genersoft.iot.vmp.gb28181.bean.Device; | ||
| 17 | -import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | ||
| 18 | -import com.genersoft.iot.vmp.utils.redis.RedisUtil; | ||
| 19 | - | ||
| 20 | -/** | ||
| 21 | - * @Description:视频设备数据存储-redis实现 | ||
| 22 | - * @author: swwheihei | ||
| 23 | - * @date: 2020年5月6日 下午2:31:42 | ||
| 24 | - */ | ||
| 25 | -@Component("redisStorager") | ||
| 26 | -public class VideoManagerRedisStoragerImpl implements IVideoManagerStorager { | ||
| 27 | - | ||
| 28 | - @Autowired | ||
| 29 | - private RedisUtil redis; | ||
| 30 | - | ||
| 31 | - | ||
| 32 | - /** | ||
| 33 | - * 根据设备ID判断设备是否存在 | ||
| 34 | - * | ||
| 35 | - * @param deviceId 设备ID | ||
| 36 | - * @return true:存在 false:不存在 | ||
| 37 | - */ | ||
| 38 | - @Override | ||
| 39 | - public boolean exists(String deviceId) { | ||
| 40 | - return redis.hasKey(VideoManagerConstants.DEVICE_PREFIX+deviceId); | ||
| 41 | - } | ||
| 42 | - | ||
| 43 | - /** | ||
| 44 | - * 视频设备创建 | ||
| 45 | - * | ||
| 46 | - * @param device 设备对象 | ||
| 47 | - * @return true:创建成功 false:创建失败 | ||
| 48 | - */ | ||
| 49 | - @Override | ||
| 50 | - public boolean create(Device device) { | ||
| 51 | - return redis.set(VideoManagerConstants.DEVICE_PREFIX+device.getDeviceId(), device); | ||
| 52 | - } | ||
| 53 | - | ||
| 54 | - | ||
| 55 | - | ||
| 56 | - /** | ||
| 57 | - * 视频设备更新 | ||
| 58 | - * | ||
| 59 | - * @param device 设备对象 | ||
| 60 | - * @return true:更新成功 false:更新失败 | ||
| 61 | - */ | ||
| 62 | - @Override | ||
| 63 | - public boolean updateDevice(Device device) { | ||
| 64 | - List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + device.getDeviceId() + "_" + "*"); | ||
| 65 | - // 更新device中的通道数量 | ||
| 66 | - device.setChannelCount(deviceChannelList.size()); | ||
| 67 | - // 存储device | ||
| 68 | - return redis.set(VideoManagerConstants.DEVICE_PREFIX+device.getDeviceId(), device); | ||
| 69 | - | ||
| 70 | - | ||
| 71 | - } | ||
| 72 | - | ||
| 73 | - @Override | ||
| 74 | - public void updateChannel(String deviceId, DeviceChannel channel) { | ||
| 75 | - // 存储通道 | ||
| 76 | - redis.set(VideoManagerConstants.CACHEKEY_PREFIX+deviceId + "_" + channel.getChannelId(), | ||
| 77 | - channel); | ||
| 78 | - List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*"); | ||
| 79 | - // 更新device中的通道数量 | ||
| 80 | - Device device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceId); | ||
| 81 | - device.setChannelCount(deviceChannelList.size()); | ||
| 82 | - redis.set(VideoManagerConstants.DEVICE_PREFIX+device.getDeviceId(), device); | ||
| 83 | - } | ||
| 84 | - | ||
| 85 | - /** | ||
| 86 | - * 获取设备 | ||
| 87 | - * | ||
| 88 | - * @param deviceId 设备ID | ||
| 89 | - * @return Device 设备对象 | ||
| 90 | - */ | ||
| 91 | - @Override | ||
| 92 | - public Device queryVideoDevice(String deviceId) { | ||
| 93 | - return (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceId); | ||
| 94 | - } | ||
| 95 | - | ||
| 96 | - @Override | ||
| 97 | - public PageResult queryChannelsByDeviceId(String deviceId, int page, int count) { | ||
| 98 | - List<DeviceChannel> result = new ArrayList<>(); | ||
| 99 | - PageResult pageResult = new PageResult<DeviceChannel>(); | ||
| 100 | - List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*"); | ||
| 101 | - pageResult.setPage(page); | ||
| 102 | - pageResult.setCount(count); | ||
| 103 | - pageResult.setTotal(deviceChannelList.size()); | ||
| 104 | - int maxCount = (page + 1 ) * count; | ||
| 105 | - if (deviceChannelList != null && deviceChannelList.size() > 0 ) { | ||
| 106 | - for (int i = page * count; i < (pageResult.getTotal() > maxCount ? maxCount : pageResult.getTotal() ); i++) { | ||
| 107 | - result.add((DeviceChannel)redis.get((String)deviceChannelList.get(i))); | ||
| 108 | - } | ||
| 109 | - pageResult.setData(result); | ||
| 110 | - } | ||
| 111 | - | ||
| 112 | - return pageResult; | ||
| 113 | - } | ||
| 114 | - | ||
| 115 | - @Override | ||
| 116 | - public List<DeviceChannel> queryChannelsByDeviceId(String deviceId) { | ||
| 117 | - List<DeviceChannel> result = new ArrayList<>(); | ||
| 118 | - List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*"); | ||
| 119 | - if (deviceChannelList != null && deviceChannelList.size() > 0 ) { | ||
| 120 | - for (int i = 0; i < deviceChannelList.size(); i++) { | ||
| 121 | - result.add((DeviceChannel)redis.get((String)deviceChannelList.get(i))); | ||
| 122 | - } | ||
| 123 | - } | ||
| 124 | - return result; | ||
| 125 | - } | ||
| 126 | - | ||
| 127 | - @Override | ||
| 128 | - public DeviceChannel queryChannel(String deviceId, String channelId) { | ||
| 129 | - return (DeviceChannel)redis.get(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + channelId); | ||
| 130 | - } | ||
| 131 | - | ||
| 132 | - | ||
| 133 | - /** | ||
| 134 | - * 获取多个设备 | ||
| 135 | - * | ||
| 136 | - * @param deviceIds 设备ID数组 | ||
| 137 | - * @return List<Device> 设备对象数组 | ||
| 138 | - */ | ||
| 139 | - @Override | ||
| 140 | - public PageResult<Device> queryVideoDeviceList(String[] deviceIds, int page, int count) { | ||
| 141 | - List<Device> devices = new ArrayList<>(); | ||
| 142 | - PageResult pageResult = new PageResult<Device>(); | ||
| 143 | - pageResult.setPage(page); | ||
| 144 | - pageResult.setCount(count); | ||
| 145 | - | ||
| 146 | - if (deviceIds == null || deviceIds.length == 0) { | ||
| 147 | - | ||
| 148 | - List<Object> deviceIdList = redis.keys(VideoManagerConstants.DEVICE_PREFIX+"*"); | ||
| 149 | - pageResult.setTotal(deviceIdList.size()); | ||
| 150 | - int maxCount = (page + 1)* count; | ||
| 151 | - for (int i = page * count; i < (pageResult.getTotal() > maxCount ? maxCount : pageResult.getTotal() ); i++) { | ||
| 152 | - devices.add((Device)redis.get((String)deviceIdList.get(i))); | ||
| 153 | - } | ||
| 154 | - } else { | ||
| 155 | - for (int i = 0; i < deviceIds.length; i++) { | ||
| 156 | - devices.add((Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceIds[i])); | ||
| 157 | - } | ||
| 158 | - } | ||
| 159 | - pageResult.setData(devices); | ||
| 160 | - return pageResult; | ||
| 161 | - } | ||
| 162 | - | ||
| 163 | - /** | ||
| 164 | - * 获取多个设备 | ||
| 165 | - * | ||
| 166 | - * @param deviceIds 设备ID数组 | ||
| 167 | - * @return List<Device> 设备对象数组 | ||
| 168 | - */ | ||
| 169 | - @Override | ||
| 170 | - public List<Device> queryVideoDeviceList(String[] deviceIds) { | ||
| 171 | - List<Device> devices = new ArrayList<>(); | ||
| 172 | - | ||
| 173 | - if (deviceIds == null || deviceIds.length == 0) { | ||
| 174 | - List<Object> deviceIdList = redis.keys(VideoManagerConstants.DEVICE_PREFIX+"*"); | ||
| 175 | - for (int i = 0; i < deviceIdList.size(); i++) { | ||
| 176 | - devices.add((Device)redis.get((String)deviceIdList.get(i))); | ||
| 177 | - } | ||
| 178 | - } else { | ||
| 179 | - for (int i = 0; i < deviceIds.length; i++) { | ||
| 180 | - devices.add((Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceIds[i])); | ||
| 181 | - } | ||
| 182 | - } | ||
| 183 | - return devices; | ||
| 184 | - } | ||
| 185 | - | ||
| 186 | - /** | ||
| 187 | - * 删除设备 | ||
| 188 | - * | ||
| 189 | - * @param deviceId 设备ID | ||
| 190 | - * @return true:删除成功 false:删除失败 | ||
| 191 | - */ | ||
| 192 | - @Override | ||
| 193 | - public boolean delete(String deviceId) { | ||
| 194 | - return redis.del(VideoManagerConstants.DEVICE_PREFIX+deviceId); | ||
| 195 | - } | ||
| 196 | - | ||
| 197 | - /** | ||
| 198 | - * 更新设备在线 | ||
| 199 | - * | ||
| 200 | - * @param deviceId 设备ID | ||
| 201 | - * @return true:更新成功 false:更新失败 | ||
| 202 | - */ | ||
| 203 | - @Override | ||
| 204 | - public boolean online(String deviceId) { | ||
| 205 | - Device device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceId); | ||
| 206 | - device.setOnline(1); | ||
| 207 | - return redis.set(VideoManagerConstants.DEVICE_PREFIX+device.getDeviceId(), device); | ||
| 208 | - } | ||
| 209 | - | ||
| 210 | - /** | ||
| 211 | - * 更新设备离线 | ||
| 212 | - * | ||
| 213 | - * @param deviceId 设备ID | ||
| 214 | - * @return true:更新成功 false:更新失败 | ||
| 215 | - */ | ||
| 216 | - @Override | ||
| 217 | - public boolean outline(String deviceId) { | ||
| 218 | - Device device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceId); | ||
| 219 | - if (device == null) return false; | ||
| 220 | - device.setOnline(0); | ||
| 221 | - return redis.set(VideoManagerConstants.DEVICE_PREFIX+device.getDeviceId(), device); | ||
| 222 | - } | ||
| 223 | - | ||
| 224 | - /** | ||
| 225 | - * 开始播放时将流存入redis | ||
| 226 | - * | ||
| 227 | - * @param deviceId 设备ID | ||
| 228 | - * @param channelId 通道ID | ||
| 229 | - * @return | ||
| 230 | - */ | ||
| 231 | - @Override | ||
| 232 | - public boolean startPlay(String deviceId, String channelId, StreamInfo stream) { | ||
| 233 | - return redis.set(String.format("%S_%s_%s", VideoManagerConstants.PLAYER_PREFIX, deviceId, channelId), | ||
| 234 | - stream); | ||
| 235 | - } | ||
| 236 | - | ||
| 237 | - /** | ||
| 238 | - * 停止播放时从redis删除 | ||
| 239 | - * | ||
| 240 | - * @param deviceId 设备ID | ||
| 241 | - * @param channelId 通道ID | ||
| 242 | - * @return | ||
| 243 | - */ | ||
| 244 | - @Override | ||
| 245 | - public boolean stopPlay(String deviceId, String channelId) { | ||
| 246 | - return redis.del(String.format("%S_%s_%s", VideoManagerConstants.PLAYER_PREFIX, deviceId, channelId)); | ||
| 247 | - } | ||
| 248 | - | ||
| 249 | - /** | ||
| 250 | - * 查询播放列表 | ||
| 251 | - * @param deviceId 设备ID | ||
| 252 | - * @param channelId 通道ID | ||
| 253 | - * @return | ||
| 254 | - */ | ||
| 255 | - @Override | ||
| 256 | - public StreamInfo queryPlay(String deviceId, String channelId) { | ||
| 257 | - return (StreamInfo)redis.get(String.format("%S_%s_%s", VideoManagerConstants.PLAYER_PREFIX, deviceId, channelId)); | ||
| 258 | - } | ||
| 259 | - | ||
| 260 | - /** | ||
| 261 | - * 更新流媒体信息 | ||
| 262 | - * @param mediaServerConfig | ||
| 263 | - * @return | ||
| 264 | - */ | ||
| 265 | - @Override | ||
| 266 | - public boolean updateMediaInfo(MediaServerConfig mediaServerConfig) { | ||
| 267 | - return redis.set(VideoManagerConstants.MEDIA_SERVER_PREFIX,mediaServerConfig); | ||
| 268 | - } | ||
| 269 | - | ||
| 270 | - /** | ||
| 271 | - * 获取流媒体信息 | ||
| 272 | - * @return | ||
| 273 | - */ | ||
| 274 | - @Override | ||
| 275 | - public MediaServerConfig getMediaInfo() { | ||
| 276 | - return (MediaServerConfig)redis.get(VideoManagerConstants.MEDIA_SERVER_PREFIX); | ||
| 277 | - } | ||
| 278 | -} | 1 | +package com.genersoft.iot.vmp.storager.redis; |
| 2 | + | ||
| 3 | +import java.util.*; | ||
| 4 | + | ||
| 5 | +import com.alibaba.fastjson.JSON; | ||
| 6 | +import com.alibaba.fastjson.JSONObject; | ||
| 7 | +import com.genersoft.iot.vmp.common.PageResult; | ||
| 8 | +import com.genersoft.iot.vmp.common.StreamInfo; | ||
| 9 | +import com.genersoft.iot.vmp.conf.MediaServerConfig; | ||
| 10 | +import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; | ||
| 11 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 12 | +import org.springframework.stereotype.Component; | ||
| 13 | + | ||
| 14 | +import com.genersoft.iot.vmp.common.VideoManagerConstants; | ||
| 15 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | ||
| 16 | +import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | ||
| 17 | +import com.genersoft.iot.vmp.utils.redis.RedisUtil; | ||
| 18 | +import org.springframework.util.StringUtils; | ||
| 19 | + | ||
| 20 | +/** | ||
| 21 | + * @Description:视频设备数据存储-redis实现 | ||
| 22 | + * @author: swwheihei | ||
| 23 | + * @date: 2020年5月6日 下午2:31:42 | ||
| 24 | + */ | ||
| 25 | +@Component("redisStorager") | ||
| 26 | +public class VideoManagerRedisStoragerImpl implements IVideoManagerStorager { | ||
| 27 | + | ||
| 28 | + @Autowired | ||
| 29 | + private RedisUtil redis; | ||
| 30 | + | ||
| 31 | + private HashMap<String, HashMap<String, HashSet<String>>> deviceMap = new HashMap<>(); | ||
| 32 | + | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * 根据设备ID判断设备是否存在 | ||
| 36 | + * | ||
| 37 | + * @param deviceId 设备ID | ||
| 38 | + * @return true:存在 false:不存在 | ||
| 39 | + */ | ||
| 40 | + @Override | ||
| 41 | + public boolean exists(String deviceId) { | ||
| 42 | + return redis.hasKey(VideoManagerConstants.DEVICE_PREFIX+deviceId); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * 视频设备创建 | ||
| 47 | + * | ||
| 48 | + * @param device 设备对象 | ||
| 49 | + * @return true:创建成功 false:创建失败 | ||
| 50 | + */ | ||
| 51 | + @Override | ||
| 52 | + public boolean create(Device device) { | ||
| 53 | + return redis.set(VideoManagerConstants.DEVICE_PREFIX+device.getDeviceId(), device); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + | ||
| 57 | + | ||
| 58 | + /** | ||
| 59 | + * 视频设备更新 | ||
| 60 | + * | ||
| 61 | + * @param device 设备对象 | ||
| 62 | + * @return true:更新成功 false:更新失败 | ||
| 63 | + */ | ||
| 64 | + @Override | ||
| 65 | + public boolean updateDevice(Device device) { | ||
| 66 | + if (deviceMap.get(device.getDeviceId()) == null) { | ||
| 67 | + deviceMap.put(device.getDeviceId(), new HashMap<String, HashSet<String>>()); | ||
| 68 | + } | ||
| 69 | +// List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + device.getDeviceId() + "_" + "*"); | ||
| 70 | + // 更新device中的通道数量 | ||
| 71 | + device.setChannelCount(deviceMap.get(device.getDeviceId()).size()); | ||
| 72 | + // 存储device | ||
| 73 | + return redis.set(VideoManagerConstants.DEVICE_PREFIX+device.getDeviceId(), device); | ||
| 74 | + | ||
| 75 | + | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + @Override | ||
| 79 | + public void updateChannel(String deviceId, DeviceChannel channel) { | ||
| 80 | + String channelId = channel.getChannelId(); | ||
| 81 | + HashMap<String, HashSet<String>> channelMap = deviceMap.get(deviceId); | ||
| 82 | + if (channelMap == null) return; | ||
| 83 | + | ||
| 84 | + // 作为父设备, 确定自己的子节点数 | ||
| 85 | + if (channelMap.get(channelId) == null) { | ||
| 86 | + channelMap.put(channelId, new HashSet<String>()); | ||
| 87 | + }else if (channelMap.get(channelId).size()> 0) { | ||
| 88 | + channel.setSubCount(channelMap.get(channelId).size()); | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + // 存储通道 | ||
| 92 | + redis.set(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + | ||
| 93 | + "_" + channel.getChannelId() + | ||
| 94 | + ":" + channel.getName() + | ||
| 95 | + "_" + (channel.getStatus() == 1 ? "on":"off") + | ||
| 96 | + "_" + (channelMap.get(channelId).size() > 0)+ | ||
| 97 | + "_" + channel.getParentId(), | ||
| 98 | + channel); | ||
| 99 | + // 更新device中的通道数量 | ||
| 100 | + Device device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceId); | ||
| 101 | + device.setChannelCount(deviceMap.get(deviceId).size()); | ||
| 102 | + redis.set(VideoManagerConstants.DEVICE_PREFIX+device.getDeviceId(), device); | ||
| 103 | + | ||
| 104 | + | ||
| 105 | + // 如果有父设备,更新父设备内子节点数 | ||
| 106 | + String parentId = channel.getParentId(); | ||
| 107 | + if (!StringUtils.isEmpty(parentId)) { | ||
| 108 | + | ||
| 109 | + if (channelMap.get(parentId) == null) { | ||
| 110 | + channelMap.put(parentId, new HashSet<>()); | ||
| 111 | + } | ||
| 112 | + channelMap.get(parentId).add(channelId); | ||
| 113 | + | ||
| 114 | + DeviceChannel deviceChannel = queryChannel(deviceId, parentId); | ||
| 115 | + if (deviceChannel != null) { | ||
| 116 | + deviceChannel.setSubCount(channelMap.get(parentId).size()); | ||
| 117 | + redis.set(VideoManagerConstants.CACHEKEY_PREFIX+deviceId + "_" + deviceChannel.getChannelId(), | ||
| 118 | + deviceChannel); | ||
| 119 | + | ||
| 120 | + } | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + /** | ||
| 126 | + * 获取设备 | ||
| 127 | + * | ||
| 128 | + * @param deviceId 设备ID | ||
| 129 | + * @return Device 设备对象 | ||
| 130 | + */ | ||
| 131 | + @Override | ||
| 132 | + public Device queryVideoDevice(String deviceId) { | ||
| 133 | + return (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceId); | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + @Override | ||
| 137 | + public PageResult queryChannelsByDeviceId(String deviceId, String query, Boolean hasSubChannel, String online, int page, int count) { | ||
| 138 | + List<DeviceChannel> result = new ArrayList<>(); | ||
| 139 | + PageResult pageResult = new PageResult<DeviceChannel>(); | ||
| 140 | + String queryContent = "*"; | ||
| 141 | + if (!StringUtils.isEmpty(query)) queryContent = String.format("*%S*",query); | ||
| 142 | + String queryHasSubChannel = "*"; | ||
| 143 | + if (hasSubChannel != null) queryHasSubChannel = hasSubChannel?"true":"false"; | ||
| 144 | + String queryOnline = "*"; | ||
| 145 | + if (!StringUtils.isEmpty(online)) queryOnline = online; | ||
| 146 | + String queryStr = VideoManagerConstants.CACHEKEY_PREFIX + deviceId + | ||
| 147 | + "_" + queryContent + // 搜索编号和名称 | ||
| 148 | + "_" + queryOnline + // 搜索是否在线 | ||
| 149 | + "_" + queryHasSubChannel + // 搜索是否含有子节点 | ||
| 150 | + "_" + "*"; | ||
| 151 | + List<Object> deviceChannelList = redis.keys(queryStr); | ||
| 152 | + pageResult.setPage(page); | ||
| 153 | + pageResult.setCount(count); | ||
| 154 | + pageResult.setTotal(deviceChannelList.size()); | ||
| 155 | + int maxCount = (page + 1 ) * count; | ||
| 156 | + if (deviceChannelList != null && deviceChannelList.size() > 0 ) { | ||
| 157 | + for (int i = page * count; i < (pageResult.getTotal() > maxCount ? maxCount : pageResult.getTotal() ); i++) { | ||
| 158 | + result.add((DeviceChannel)redis.get((String)deviceChannelList.get(i))); | ||
| 159 | + } | ||
| 160 | + pageResult.setData(result); | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + return pageResult; | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + @Override | ||
| 167 | + public List<DeviceChannel> queryChannelsByDeviceId(String deviceId) { | ||
| 168 | + List<DeviceChannel> result = new ArrayList<>(); | ||
| 169 | + List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*"); | ||
| 170 | + if (deviceChannelList != null && deviceChannelList.size() > 0 ) { | ||
| 171 | + for (int i = 0; i < deviceChannelList.size(); i++) { | ||
| 172 | + result.add((DeviceChannel)redis.get((String)deviceChannelList.get(i))); | ||
| 173 | + } | ||
| 174 | + } | ||
| 175 | + return result; | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | + @Override | ||
| 179 | + public PageResult querySubChannels(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, String online, int page, int count) { | ||
| 180 | + List<DeviceChannel> allDeviceChannels = new ArrayList<>(); | ||
| 181 | + String queryContent = "*"; | ||
| 182 | + if (!StringUtils.isEmpty(query)) queryContent = String.format("*%S*",query); | ||
| 183 | + String queryHasSubChannel = "*"; | ||
| 184 | + if (hasSubChannel != null) queryHasSubChannel = hasSubChannel?"true":"false"; | ||
| 185 | + String queryOnline = "*"; | ||
| 186 | + if (!StringUtils.isEmpty(online)) queryOnline = online; | ||
| 187 | + String queryStr = VideoManagerConstants.CACHEKEY_PREFIX + deviceId + | ||
| 188 | + "_" + queryContent + // 搜索编号和名称 | ||
| 189 | + "_" + queryOnline + // 搜索是否在线 | ||
| 190 | + "_" + queryHasSubChannel + // 搜索是否含有子节点 | ||
| 191 | + "_" + parentChannelId; | ||
| 192 | + | ||
| 193 | + List<Object> deviceChannelList = redis.keys(queryStr); | ||
| 194 | + | ||
| 195 | + if (deviceChannelList != null && deviceChannelList.size() > 0 ) { | ||
| 196 | + for (int i = 0; i < deviceChannelList.size(); i++) { | ||
| 197 | + DeviceChannel deviceChannel = (DeviceChannel)redis.get((String)deviceChannelList.get(i)); | ||
| 198 | + if (deviceChannel.getParentId() != null && deviceChannel.getParentId().equals(parentChannelId)) { | ||
| 199 | + allDeviceChannels.add(deviceChannel); | ||
| 200 | + } | ||
| 201 | + } | ||
| 202 | + } | ||
| 203 | + int maxCount = (page + 1 ) * count; | ||
| 204 | + PageResult pageResult = new PageResult<DeviceChannel>(); | ||
| 205 | + pageResult.setPage(page); | ||
| 206 | + pageResult.setCount(count); | ||
| 207 | + pageResult.setTotal(allDeviceChannels.size()); | ||
| 208 | + | ||
| 209 | + if (allDeviceChannels.size() > 0) { | ||
| 210 | + pageResult.setData(allDeviceChannels.subList( | ||
| 211 | + page * count, pageResult.getTotal() > maxCount ? maxCount : pageResult.getTotal() | ||
| 212 | + )); | ||
| 213 | + } | ||
| 214 | + return pageResult; | ||
| 215 | + } | ||
| 216 | + | ||
| 217 | + public List<DeviceChannel> querySubChannels(String deviceId, String parentChannelId) { | ||
| 218 | + List<DeviceChannel> allDeviceChannels = new ArrayList<>(); | ||
| 219 | + List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + "*"); | ||
| 220 | + | ||
| 221 | + if (deviceChannelList != null && deviceChannelList.size() > 0 ) { | ||
| 222 | + for (int i = 0; i < deviceChannelList.size(); i++) { | ||
| 223 | + DeviceChannel deviceChannel = (DeviceChannel)redis.get((String)deviceChannelList.get(i)); | ||
| 224 | + if (deviceChannel.getParentId() != null && deviceChannel.getParentId().equals(parentChannelId)) { | ||
| 225 | + allDeviceChannels.add(deviceChannel); | ||
| 226 | + } | ||
| 227 | + } | ||
| 228 | + } | ||
| 229 | + | ||
| 230 | + return allDeviceChannels; | ||
| 231 | + } | ||
| 232 | + | ||
| 233 | + @Override | ||
| 234 | + public DeviceChannel queryChannel(String deviceId, String channelId) { | ||
| 235 | + return (DeviceChannel)redis.get(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + "_" + channelId + "_"); | ||
| 236 | + } | ||
| 237 | + | ||
| 238 | + | ||
| 239 | + /** | ||
| 240 | + * 获取多个设备 | ||
| 241 | + * | ||
| 242 | + * @param deviceIds 设备ID数组 | ||
| 243 | + * @return List<Device> 设备对象数组 | ||
| 244 | + */ | ||
| 245 | + @Override | ||
| 246 | + public PageResult<Device> queryVideoDeviceList(String[] deviceIds, int page, int count) { | ||
| 247 | + List<Device> devices = new ArrayList<>(); | ||
| 248 | + PageResult pageResult = new PageResult<Device>(); | ||
| 249 | + pageResult.setPage(page); | ||
| 250 | + pageResult.setCount(count); | ||
| 251 | + | ||
| 252 | + if (deviceIds == null || deviceIds.length == 0) { | ||
| 253 | + | ||
| 254 | + List<Object> deviceIdList = redis.keys(VideoManagerConstants.DEVICE_PREFIX+"*"); | ||
| 255 | + pageResult.setTotal(deviceIdList.size()); | ||
| 256 | + int maxCount = (page + 1)* count; | ||
| 257 | + for (int i = page * count; i < (pageResult.getTotal() > maxCount ? maxCount : pageResult.getTotal() ); i++) { | ||
| 258 | + devices.add((Device)redis.get((String)deviceIdList.get(i))); | ||
| 259 | + } | ||
| 260 | + } else { | ||
| 261 | + for (int i = 0; i < deviceIds.length; i++) { | ||
| 262 | + devices.add((Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceIds[i])); | ||
| 263 | + } | ||
| 264 | + } | ||
| 265 | + pageResult.setData(devices); | ||
| 266 | + return pageResult; | ||
| 267 | + } | ||
| 268 | + | ||
| 269 | + /** | ||
| 270 | + * 获取多个设备 | ||
| 271 | + * | ||
| 272 | + * @param deviceIds 设备ID数组 | ||
| 273 | + * @return List<Device> 设备对象数组 | ||
| 274 | + */ | ||
| 275 | + @Override | ||
| 276 | + public List<Device> queryVideoDeviceList(String[] deviceIds) { | ||
| 277 | + List<Device> devices = new ArrayList<>(); | ||
| 278 | + | ||
| 279 | + if (deviceIds == null || deviceIds.length == 0) { | ||
| 280 | + List<Object> deviceIdList = redis.keys(VideoManagerConstants.DEVICE_PREFIX+"*"); | ||
| 281 | + for (int i = 0; i < deviceIdList.size(); i++) { | ||
| 282 | + devices.add((Device)redis.get((String)deviceIdList.get(i))); | ||
| 283 | + } | ||
| 284 | + } else { | ||
| 285 | + for (int i = 0; i < deviceIds.length; i++) { | ||
| 286 | + devices.add((Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceIds[i])); | ||
| 287 | + } | ||
| 288 | + } | ||
| 289 | + return devices; | ||
| 290 | + } | ||
| 291 | + | ||
| 292 | + /** | ||
| 293 | + * 删除设备 | ||
| 294 | + * | ||
| 295 | + * @param deviceId 设备ID | ||
| 296 | + * @return true:删除成功 false:删除失败 | ||
| 297 | + */ | ||
| 298 | + @Override | ||
| 299 | + public boolean delete(String deviceId) { | ||
| 300 | + return redis.del(VideoManagerConstants.DEVICE_PREFIX+deviceId); | ||
| 301 | + } | ||
| 302 | + | ||
| 303 | + /** | ||
| 304 | + * 更新设备在线 | ||
| 305 | + * | ||
| 306 | + * @param deviceId 设备ID | ||
| 307 | + * @return true:更新成功 false:更新失败 | ||
| 308 | + */ | ||
| 309 | + @Override | ||
| 310 | + public boolean online(String deviceId) { | ||
| 311 | + Device device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceId); | ||
| 312 | + device.setOnline(1); | ||
| 313 | + return redis.set(VideoManagerConstants.DEVICE_PREFIX+device.getDeviceId(), device); | ||
| 314 | + } | ||
| 315 | + | ||
| 316 | + /** | ||
| 317 | + * 更新设备离线 | ||
| 318 | + * | ||
| 319 | + * @param deviceId 设备ID | ||
| 320 | + * @return true:更新成功 false:更新失败 | ||
| 321 | + */ | ||
| 322 | + @Override | ||
| 323 | + public boolean outline(String deviceId) { | ||
| 324 | + Device device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceId); | ||
| 325 | + if (device == null) return false; | ||
| 326 | + device.setOnline(0); | ||
| 327 | + return redis.set(VideoManagerConstants.DEVICE_PREFIX+device.getDeviceId(), device); | ||
| 328 | + } | ||
| 329 | + | ||
| 330 | + /** | ||
| 331 | + * 开始播放时将流存入redis | ||
| 332 | + * | ||
| 333 | + * @param deviceId 设备ID | ||
| 334 | + * @param channelId 通道ID | ||
| 335 | + * @return | ||
| 336 | + */ | ||
| 337 | + @Override | ||
| 338 | + public boolean startPlay(String deviceId, String channelId, StreamInfo stream) { | ||
| 339 | + return redis.set(String.format("%S_%s_%s", VideoManagerConstants.PLAYER_PREFIX, deviceId, channelId), | ||
| 340 | + stream); | ||
| 341 | + } | ||
| 342 | + | ||
| 343 | + /** | ||
| 344 | + * 停止播放时从redis删除 | ||
| 345 | + * | ||
| 346 | + * @param deviceId 设备ID | ||
| 347 | + * @param channelId 通道ID | ||
| 348 | + * @return | ||
| 349 | + */ | ||
| 350 | + @Override | ||
| 351 | + public boolean stopPlay(String deviceId, String channelId) { | ||
| 352 | + return redis.del(String.format("%S_%s_%s", VideoManagerConstants.PLAYER_PREFIX, deviceId, channelId)); | ||
| 353 | + } | ||
| 354 | + | ||
| 355 | + /** | ||
| 356 | + * 查询播放列表 | ||
| 357 | + * @param deviceId 设备ID | ||
| 358 | + * @param channelId 通道ID | ||
| 359 | + * @return | ||
| 360 | + */ | ||
| 361 | + @Override | ||
| 362 | + public StreamInfo queryPlay(String deviceId, String channelId) { | ||
| 363 | + return (StreamInfo)redis.get(String.format("%S_%s_%s", VideoManagerConstants.PLAYER_PREFIX, deviceId, channelId)); | ||
| 364 | + } | ||
| 365 | + | ||
| 366 | + | ||
| 367 | + | ||
| 368 | + /** | ||
| 369 | + * 更新流媒体信息 | ||
| 370 | + * @param mediaServerConfig | ||
| 371 | + * @return | ||
| 372 | + */ | ||
| 373 | + @Override | ||
| 374 | + public boolean updateMediaInfo(MediaServerConfig mediaServerConfig) { | ||
| 375 | + return redis.set(VideoManagerConstants.MEDIA_SERVER_PREFIX,mediaServerConfig); | ||
| 376 | + } | ||
| 377 | + | ||
| 378 | + /** | ||
| 379 | + * 获取流媒体信息 | ||
| 380 | + * @return | ||
| 381 | + */ | ||
| 382 | + @Override | ||
| 383 | + public MediaServerConfig getMediaInfo() { | ||
| 384 | + return (MediaServerConfig)redis.get(VideoManagerConstants.MEDIA_SERVER_PREFIX); | ||
| 385 | + } | ||
| 386 | + | ||
| 387 | + @Override | ||
| 388 | + public void updateCatch() { | ||
| 389 | + deviceMap = new HashMap<>(); | ||
| 390 | + // 更新设备 | ||
| 391 | + List<Device> devices = queryVideoDeviceList(null); | ||
| 392 | + if (devices == null && devices.size() == 0) return; | ||
| 393 | + for (Device device : devices) { | ||
| 394 | + // 更新设备下的通道 | ||
| 395 | + HashMap<String, HashSet<String>> channelMap = new HashMap<String, HashSet<String>>(); | ||
| 396 | + List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + | ||
| 397 | + device.getDeviceId() + "_" + "*"); | ||
| 398 | + if (deviceChannelList != null && deviceChannelList.size() > 0 ) { | ||
| 399 | + for (int i = 0; i < deviceChannelList.size(); i++) { | ||
| 400 | + String key = (String)deviceChannelList.get(i); | ||
| 401 | + String[] s = key.split("_"); | ||
| 402 | + String channelId = s[3]; | ||
| 403 | + HashSet<String> subChannel = channelMap.get(channelId); | ||
| 404 | + if (subChannel == null) { | ||
| 405 | + subChannel = new HashSet<>(); | ||
| 406 | + } | ||
| 407 | + if (s.length > 4) { | ||
| 408 | + subChannel.add(s[4]); | ||
| 409 | + } | ||
| 410 | + channelMap.put(channelId, subChannel); | ||
| 411 | + System.out.println(); | ||
| 412 | + } | ||
| 413 | + } | ||
| 414 | + deviceMap.put(device.getDeviceId(),channelMap); | ||
| 415 | + } | ||
| 416 | + } | ||
| 417 | +} |
src/main/java/com/genersoft/iot/vmp/vmanager/device/DeviceController.java
| @@ -9,12 +9,7 @@ import org.slf4j.LoggerFactory; | @@ -9,12 +9,7 @@ import org.slf4j.LoggerFactory; | ||
| 9 | import org.springframework.beans.factory.annotation.Autowired; | 9 | import org.springframework.beans.factory.annotation.Autowired; |
| 10 | import org.springframework.http.HttpStatus; | 10 | import org.springframework.http.HttpStatus; |
| 11 | import org.springframework.http.ResponseEntity; | 11 | import org.springframework.http.ResponseEntity; |
| 12 | -import org.springframework.web.bind.annotation.CrossOrigin; | ||
| 13 | -import org.springframework.web.bind.annotation.GetMapping; | ||
| 14 | -import org.springframework.web.bind.annotation.PathVariable; | ||
| 15 | -import org.springframework.web.bind.annotation.PostMapping; | ||
| 16 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
| 17 | -import org.springframework.web.bind.annotation.RestController; | 12 | +import org.springframework.web.bind.annotation.*; |
| 18 | import org.springframework.web.context.request.async.DeferredResult; | 13 | import org.springframework.web.context.request.async.DeferredResult; |
| 19 | 14 | ||
| 20 | import com.alibaba.fastjson.JSONObject; | 15 | import com.alibaba.fastjson.JSONObject; |
| @@ -72,12 +67,17 @@ public class DeviceController { | @@ -72,12 +67,17 @@ public class DeviceController { | ||
| 72 | * @return 通道列表 | 67 | * @return 通道列表 |
| 73 | */ | 68 | */ |
| 74 | @GetMapping("devices/{deviceId}/channels") | 69 | @GetMapping("devices/{deviceId}/channels") |
| 75 | - public ResponseEntity<PageResult> channels(@PathVariable String deviceId, int page, int count){ | 70 | + public ResponseEntity<PageResult> channels(@PathVariable String deviceId, |
| 71 | + int page, int count, | ||
| 72 | + @RequestParam(required = false) String query, | ||
| 73 | + @RequestParam(required = false) String online, | ||
| 74 | + @RequestParam(required = false) Boolean channelType | ||
| 75 | + ){ | ||
| 76 | 76 | ||
| 77 | if (logger.isDebugEnabled()) { | 77 | if (logger.isDebugEnabled()) { |
| 78 | logger.debug("查询所有视频设备API调用"); | 78 | logger.debug("查询所有视频设备API调用"); |
| 79 | } | 79 | } |
| 80 | - PageResult pageResult = storager.queryChannelsByDeviceId(deviceId, page, count); | 80 | + PageResult pageResult = storager.queryChannelsByDeviceId(deviceId, query, channelType, online, page, count); |
| 81 | return new ResponseEntity<>(pageResult,HttpStatus.OK); | 81 | return new ResponseEntity<>(pageResult,HttpStatus.OK); |
| 82 | } | 82 | } |
| 83 | 83 | ||
| @@ -115,4 +115,33 @@ public class DeviceController { | @@ -115,4 +115,33 @@ public class DeviceController { | ||
| 115 | return new ResponseEntity<String>("设备预览API调用失败!", HttpStatus.INTERNAL_SERVER_ERROR); | 115 | return new ResponseEntity<String>("设备预览API调用失败!", HttpStatus.INTERNAL_SERVER_ERROR); |
| 116 | } | 116 | } |
| 117 | } | 117 | } |
| 118 | + | ||
| 119 | + /** | ||
| 120 | + * 分页查询通道数 | ||
| 121 | + * @param channelId 通道id | ||
| 122 | + * @param page 当前页 | ||
| 123 | + * @param count 每页条数 | ||
| 124 | + * @return 子通道列表 | ||
| 125 | + */ | ||
| 126 | + @GetMapping("subChannels/{deviceId}/{channelId}/channels") | ||
| 127 | + public ResponseEntity<PageResult> subChannels(@PathVariable String deviceId, | ||
| 128 | + @PathVariable String channelId, | ||
| 129 | + int page, | ||
| 130 | + int count, | ||
| 131 | + @RequestParam(required = false) String query, | ||
| 132 | + @RequestParam(required = false) String online, | ||
| 133 | + @RequestParam(required = false) Boolean channelType){ | ||
| 134 | + | ||
| 135 | + if (logger.isDebugEnabled()) { | ||
| 136 | + logger.debug("查询所有视频设备API调用"); | ||
| 137 | + } | ||
| 138 | + DeviceChannel deviceChannel = storager.queryChannel(deviceId,channelId); | ||
| 139 | + if (deviceChannel == null) { | ||
| 140 | + PageResult<DeviceChannel> deviceChannelPageResult = new PageResult<>(); | ||
| 141 | + new ResponseEntity<>(deviceChannelPageResult,HttpStatus.OK); | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + PageResult pageResult = storager.querySubChannels(deviceId, channelId, query, channelType, online, page, count); | ||
| 145 | + return new ResponseEntity<>(pageResult,HttpStatus.OK); | ||
| 146 | + } | ||
| 118 | } | 147 | } |
src/main/java/com/genersoft/iot/vmp/web/ApiDeviceController.java
| @@ -68,7 +68,7 @@ public class ApiDeviceController { | @@ -68,7 +68,7 @@ public class ApiDeviceController { | ||
| 68 | devices = storager.queryVideoDeviceList(null); | 68 | devices = storager.queryVideoDeviceList(null); |
| 69 | result.put("DeviceCount", devices.size()); | 69 | result.put("DeviceCount", devices.size()); |
| 70 | }else { | 70 | }else { |
| 71 | - PageResult<Device> deviceList = storager.queryVideoDeviceList(null, start, limit); | 71 | + PageResult<Device> deviceList = storager.queryVideoDeviceList(null, start/limit, limit); |
| 72 | result.put("DeviceCount", deviceList.getTotal()); | 72 | result.put("DeviceCount", deviceList.getTotal()); |
| 73 | devices = deviceList.getData(); | 73 | devices = deviceList.getData(); |
| 74 | } | 74 | } |
| @@ -123,7 +123,7 @@ public class ApiDeviceController { | @@ -123,7 +123,7 @@ public class ApiDeviceController { | ||
| 123 | deviceChannels = storager.queryChannelsByDeviceId(serial); | 123 | deviceChannels = storager.queryChannelsByDeviceId(serial); |
| 124 | result.put("ChannelCount", deviceChannels.size()); | 124 | result.put("ChannelCount", deviceChannels.size()); |
| 125 | }else { | 125 | }else { |
| 126 | - PageResult<DeviceChannel> pageResult = storager.queryChannelsByDeviceId(serial, start, limit); | 126 | + PageResult<DeviceChannel> pageResult = storager.queryChannelsByDeviceId(serial, null, null, null,start/limit, limit); |
| 127 | result.put("ChannelCount", pageResult.getTotal()); | 127 | result.put("ChannelCount", pageResult.getTotal()); |
| 128 | deviceChannels = pageResult.getData(); | 128 | deviceChannels = pageResult.getData(); |
| 129 | } | 129 | } |
| @@ -139,7 +139,7 @@ public class ApiDeviceController { | @@ -139,7 +139,7 @@ public class ApiDeviceController { | ||
| 139 | deviceJOSNChannel.put("Name", deviceChannel.getName()); | 139 | deviceJOSNChannel.put("Name", deviceChannel.getName()); |
| 140 | deviceJOSNChannel.put("Custom", false); | 140 | deviceJOSNChannel.put("Custom", false); |
| 141 | deviceJOSNChannel.put("CustomName", ""); | 141 | deviceJOSNChannel.put("CustomName", ""); |
| 142 | - deviceJOSNChannel.put("SubCount", 0); // TODO ? 子节点数, SubCount > 0 表示该通道为子目录 | 142 | + deviceJOSNChannel.put("SubCount", deviceChannel.getSubCount()); // TODO ? 子节点数, SubCount > 0 表示该通道为子目录 |
| 143 | deviceJOSNChannel.put("SnapURL", ""); | 143 | deviceJOSNChannel.put("SnapURL", ""); |
| 144 | deviceJOSNChannel.put("Manufacturer ", deviceChannel.getManufacture()); | 144 | deviceJOSNChannel.put("Manufacturer ", deviceChannel.getManufacture()); |
| 145 | deviceJOSNChannel.put("Model", deviceChannel.getModel()); | 145 | deviceJOSNChannel.put("Model", deviceChannel.getModel()); |
src/main/resources/application.yml
| @@ -12,7 +12,7 @@ spring: | @@ -12,7 +12,7 @@ spring: | ||
| 12 | port: 6379 | 12 | port: 6379 |
| 13 | database: 6 | 13 | database: 6 |
| 14 | #访问密码,若你的redis服务器没有设置密码,就不需要用密码去连接 | 14 | #访问密码,若你的redis服务器没有设置密码,就不需要用密码去连接 |
| 15 | - password: | 15 | + password: 4767cb971b40a1300fa09b7f87b09d1c |
| 16 | #超时时间 | 16 | #超时时间 |
| 17 | timeout: 10000 | 17 | timeout: 10000 |
| 18 | datasource: | 18 | datasource: |
| @@ -31,8 +31,8 @@ sip: | @@ -31,8 +31,8 @@ sip: | ||
| 31 | # 根据国标6.1.2中规定,domain宜采用ID统一编码的前十位编码。国标附录D中定义前8位为中心编码(由省级、市级、区级、基层编号组成,参照GB/T 2260-2007) | 31 | # 根据国标6.1.2中规定,domain宜采用ID统一编码的前十位编码。国标附录D中定义前8位为中心编码(由省级、市级、区级、基层编号组成,参照GB/T 2260-2007) |
| 32 | # 后两位为行业编码,定义参照附录D.3 | 32 | # 后两位为行业编码,定义参照附录D.3 |
| 33 | # 3701020049标识山东济南历下区 信息行业接入 | 33 | # 3701020049标识山东济南历下区 信息行业接入 |
| 34 | - domain: 3701020049 | ||
| 35 | - id: 37010200492000000001 | 34 | + domain: 3402000000 |
| 35 | + id: 34020000002000000001 | ||
| 36 | # 默认设备认证密码,后续扩展使用设备单独密码 | 36 | # 默认设备认证密码,后续扩展使用设备单独密码 |
| 37 | password: 12345678 | 37 | password: 12345678 |
| 38 | media: | 38 | media: |