Commit abb60593cb77e9e9b6e67e8276fc416c2aede43f
1 parent
ddb36e54
优化级联平台GPS订阅
Showing
9 changed files
with
100 additions
and
5 deletions
src/main/java/com/genersoft/iot/vmp/gb28181/task/GPSSubscribeTask.java
| @@ -45,10 +45,21 @@ public class GPSSubscribeTask implements Runnable{ | @@ -45,10 +45,21 @@ public class GPSSubscribeTask implements Runnable{ | ||
| 45 | for (GbStream gbStream : gbStreams) { | 45 | for (GbStream gbStream : gbStreams) { |
| 46 | String gbId = gbStream.getGbId(); | 46 | String gbId = gbStream.getGbId(); |
| 47 | GPSMsgInfo gpsMsgInfo = redisCatchStorage.getGpsMsgInfo(gbId); | 47 | GPSMsgInfo gpsMsgInfo = redisCatchStorage.getGpsMsgInfo(gbId); |
| 48 | - if (gpsMsgInfo != null && gbStream.isStatus()) { | ||
| 49 | - // 发送GPS消息 | ||
| 50 | - sipCommanderForPlatform.sendMobilePosition(parentPlatform, gpsMsgInfo, subscribe); | 48 | + if (gbStream.isStatus()) { |
| 49 | + if (gpsMsgInfo != null) { | ||
| 50 | + // 发送GPS消息 | ||
| 51 | + sipCommanderForPlatform.sendMobilePosition(parentPlatform, gpsMsgInfo, subscribe); | ||
| 52 | + }else { | ||
| 53 | + // 没有在redis找到新的消息就使用数据库的消息 | ||
| 54 | + gpsMsgInfo = new GPSMsgInfo(); | ||
| 55 | + gpsMsgInfo.setId(gbId); | ||
| 56 | + gpsMsgInfo.setLat(gbStream.getLongitude()); | ||
| 57 | + gpsMsgInfo.setLng(gbStream.getLongitude()); | ||
| 58 | + // 发送GPS消息 | ||
| 59 | + sipCommanderForPlatform.sendMobilePosition(parentPlatform, gpsMsgInfo, subscribe); | ||
| 60 | + } | ||
| 51 | } | 61 | } |
| 62 | + | ||
| 52 | } | 63 | } |
| 53 | } | 64 | } |
| 54 | } | 65 | } |
src/main/java/com/genersoft/iot/vmp/service/StreamGPSSubscribeTask.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.service; | ||
| 2 | + | ||
| 3 | +import com.genersoft.iot.vmp.service.bean.GPSMsgInfo; | ||
| 4 | +import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | ||
| 5 | +import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | ||
| 6 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 7 | +import org.springframework.scheduling.annotation.Scheduled; | ||
| 8 | +import org.springframework.stereotype.Component; | ||
| 9 | + | ||
| 10 | +import java.util.List; | ||
| 11 | + | ||
| 12 | + | ||
| 13 | +/** | ||
| 14 | + * 定时查找redis中的GPS推送消息,并保存到对应的流中 | ||
| 15 | + */ | ||
| 16 | +@Component | ||
| 17 | +public class StreamGPSSubscribeTask { | ||
| 18 | + | ||
| 19 | + @Autowired | ||
| 20 | + private IRedisCatchStorage redisCatchStorage; | ||
| 21 | + | ||
| 22 | + @Autowired | ||
| 23 | + private IVideoManagerStorager storager; | ||
| 24 | + | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + @Scheduled(fixedRate = 30 * 1000) //每30秒执行一次 | ||
| 28 | + public void execute(){ | ||
| 29 | + List<GPSMsgInfo> gpsMsgInfo = redisCatchStorage.getAllGpsMsgInfo(); | ||
| 30 | + if (gpsMsgInfo.size() > 0) { | ||
| 31 | + storager.updateStreamGPS(gpsMsgInfo); | ||
| 32 | + for (GPSMsgInfo msgInfo : gpsMsgInfo) { | ||
| 33 | + msgInfo.setStored(true); | ||
| 34 | + redisCatchStorage.updateGpsMsgInfo(msgInfo); | ||
| 35 | + } | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + } | ||
| 39 | +} |
src/main/java/com/genersoft/iot/vmp/service/bean/GPSMsgInfo.java
| @@ -37,6 +37,8 @@ public class GPSMsgInfo { | @@ -37,6 +37,8 @@ public class GPSMsgInfo { | ||
| 37 | */ | 37 | */ |
| 38 | private String altitude; | 38 | private String altitude; |
| 39 | 39 | ||
| 40 | + private boolean stored; | ||
| 41 | + | ||
| 40 | 42 | ||
| 41 | public String getId() { | 43 | public String getId() { |
| 42 | return id; | 44 | return id; |
| @@ -93,4 +95,12 @@ public class GPSMsgInfo { | @@ -93,4 +95,12 @@ public class GPSMsgInfo { | ||
| 93 | public void setAltitude(String altitude) { | 95 | public void setAltitude(String altitude) { |
| 94 | this.altitude = altitude; | 96 | this.altitude = altitude; |
| 95 | } | 97 | } |
| 98 | + | ||
| 99 | + public boolean isStored() { | ||
| 100 | + return stored; | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + public void setStored(boolean stored) { | ||
| 104 | + this.stored = stored; | ||
| 105 | + } | ||
| 96 | } | 106 | } |
src/main/java/com/genersoft/iot/vmp/service/impl/RedisGPSMsgListener.java
| @@ -17,7 +17,6 @@ public class RedisGPSMsgListener implements MessageListener { | @@ -17,7 +17,6 @@ public class RedisGPSMsgListener implements MessageListener { | ||
| 17 | @Override | 17 | @Override |
| 18 | public void onMessage(Message message, byte[] bytes) { | 18 | public void onMessage(Message message, byte[] bytes) { |
| 19 | GPSMsgInfo gpsMsgInfo = JSON.parseObject(message.getBody(), GPSMsgInfo.class); | 19 | GPSMsgInfo gpsMsgInfo = JSON.parseObject(message.getBody(), GPSMsgInfo.class); |
| 20 | - System.out.println(JSON.toJSON(gpsMsgInfo)); | ||
| 21 | redisCatchStorage.updateGpsMsgInfo(gpsMsgInfo); | 20 | redisCatchStorage.updateGpsMsgInfo(gpsMsgInfo); |
| 22 | } | 21 | } |
| 23 | } | 22 | } |
src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java
| @@ -195,6 +195,7 @@ public interface IRedisCatchStorage { | @@ -195,6 +195,7 @@ public interface IRedisCatchStorage { | ||
| 195 | void updateGpsMsgInfo(GPSMsgInfo gpsMsgInfo); | 195 | void updateGpsMsgInfo(GPSMsgInfo gpsMsgInfo); |
| 196 | 196 | ||
| 197 | GPSMsgInfo getGpsMsgInfo(String gbId); | 197 | GPSMsgInfo getGpsMsgInfo(String gbId); |
| 198 | + List<GPSMsgInfo> getAllGpsMsgInfo(); | ||
| 198 | 199 | ||
| 199 | Long getSN(String method); | 200 | Long getSN(String method); |
| 200 | 201 |
src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorager.java
| @@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.gb28181.bean.*; | @@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.gb28181.bean.*; | ||
| 4 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; | 4 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| 5 | import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; | 5 | import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; |
| 6 | import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; | 6 | import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; |
| 7 | +import com.genersoft.iot.vmp.service.bean.GPSMsgInfo; | ||
| 7 | import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce; | 8 | import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce; |
| 8 | import com.github.pagehelper.PageInfo; | 9 | import com.github.pagehelper.PageInfo; |
| 9 | 10 | ||
| @@ -456,4 +457,6 @@ public interface IVideoManagerStorager { | @@ -456,4 +457,6 @@ public interface IVideoManagerStorager { | ||
| 456 | List<PlatformCatalog> queryCatalogInPlatform(String serverGBId); | 457 | List<PlatformCatalog> queryCatalogInPlatform(String serverGBId); |
| 457 | 458 | ||
| 458 | int delRelation(PlatformCatalog platformCatalog); | 459 | int delRelation(PlatformCatalog platformCatalog); |
| 460 | + | ||
| 461 | + int updateStreamGPS(List<GPSMsgInfo> gpsMsgInfo); | ||
| 459 | } | 462 | } |
src/main/java/com/genersoft/iot/vmp/storager/dao/GbStreamMapper.java
| @@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.storager.dao; | @@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.storager.dao; | ||
| 3 | import com.genersoft.iot.vmp.gb28181.bean.GbStream; | 3 | import com.genersoft.iot.vmp.gb28181.bean.GbStream; |
| 4 | import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; | 4 | import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; |
| 5 | import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; | 5 | import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; |
| 6 | +import com.genersoft.iot.vmp.service.bean.GPSMsgInfo; | ||
| 6 | import org.apache.ibatis.annotations.*; | 7 | import org.apache.ibatis.annotations.*; |
| 7 | import org.springframework.stereotype.Repository; | 8 | import org.springframework.stereotype.Repository; |
| 8 | 9 | ||
| @@ -94,4 +95,13 @@ public interface GbStreamMapper { | @@ -94,4 +95,13 @@ public interface GbStreamMapper { | ||
| 94 | void batchAdd(List<StreamPushItem> subList); | 95 | void batchAdd(List<StreamPushItem> subList); |
| 95 | 96 | ||
| 96 | 97 | ||
| 98 | + @Update({"<script>" + | ||
| 99 | + "<foreach collection='gpsMsgInfos' item='item' separator=';'>" + | ||
| 100 | + " UPDATE" + | ||
| 101 | + " gb_stream" + | ||
| 102 | + " SET longitude=${item.lng}, latitude=${item.lat} " + | ||
| 103 | + "WHERE gbId=#{item.id}"+ | ||
| 104 | + "</foreach>" + | ||
| 105 | + "</script>"}) | ||
| 106 | + int updateStreamGPS(List<GPSMsgInfo> gpsMsgInfos); | ||
| 97 | } | 107 | } |
src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
| @@ -453,7 +453,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | @@ -453,7 +453,7 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | ||
| 453 | @Override | 453 | @Override |
| 454 | public void updateGpsMsgInfo(GPSMsgInfo gpsMsgInfo) { | 454 | public void updateGpsMsgInfo(GPSMsgInfo gpsMsgInfo) { |
| 455 | String key = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + userSetup.getServerId() + "_" + gpsMsgInfo.getId(); | 455 | String key = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + userSetup.getServerId() + "_" + gpsMsgInfo.getId(); |
| 456 | - redis.set(key, gpsMsgInfo); | 456 | + redis.set(key, gpsMsgInfo, 60); // 默认GPS消息保存1分钟 |
| 457 | } | 457 | } |
| 458 | 458 | ||
| 459 | @Override | 459 | @Override |
| @@ -476,4 +476,20 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | @@ -476,4 +476,20 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | ||
| 476 | public void delSubscribe(String key) { | 476 | public void delSubscribe(String key) { |
| 477 | redis.del(key); | 477 | redis.del(key); |
| 478 | } | 478 | } |
| 479 | + | ||
| 480 | + @Override | ||
| 481 | + public List<GPSMsgInfo> getAllGpsMsgInfo() { | ||
| 482 | + String scanKey = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + userSetup.getServerId() + "_*"; | ||
| 483 | + List<GPSMsgInfo> result = new ArrayList<>(); | ||
| 484 | + List<Object> keys = redis.scan(scanKey); | ||
| 485 | + for (int i = 0; i < keys.size(); i++) { | ||
| 486 | + String key = (String) keys.get(i); | ||
| 487 | + GPSMsgInfo gpsMsgInfo = (GPSMsgInfo) redis.get(key); | ||
| 488 | + if (!gpsMsgInfo.isStored()) { // 只取没有存过得 | ||
| 489 | + result.add((GPSMsgInfo)redis.get(key)); | ||
| 490 | + } | ||
| 491 | + } | ||
| 492 | + | ||
| 493 | + return result; | ||
| 494 | + } | ||
| 479 | } | 495 | } |
src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java
| @@ -6,6 +6,7 @@ import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; | @@ -6,6 +6,7 @@ import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; | ||
| 6 | import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; | 6 | import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; |
| 7 | import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; | 7 | import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; |
| 8 | import com.genersoft.iot.vmp.service.IGbStreamService; | 8 | import com.genersoft.iot.vmp.service.IGbStreamService; |
| 9 | +import com.genersoft.iot.vmp.service.bean.GPSMsgInfo; | ||
| 9 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | 10 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 10 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | 11 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| 11 | import com.genersoft.iot.vmp.storager.dao.*; | 12 | import com.genersoft.iot.vmp.storager.dao.*; |
| @@ -898,4 +899,9 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager { | @@ -898,4 +899,9 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager { | ||
| 898 | } | 899 | } |
| 899 | return 0; | 900 | return 0; |
| 900 | } | 901 | } |
| 902 | + | ||
| 903 | + @Override | ||
| 904 | + public int updateStreamGPS(List<GPSMsgInfo> gpsMsgInfos) { | ||
| 905 | + return gbStreamMapper.updateStreamGPS(gpsMsgInfos); | ||
| 906 | + } | ||
| 901 | } | 907 | } |