Commit 8f77d0c25cdd37d4cc96c923b46ae28607bae51d
1 parent
b67841b3
根据redis消息更新推流列表
Showing
9 changed files
with
130 additions
and
2 deletions
src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java
| @@ -91,6 +91,10 @@ public class VideoManagerConstants { | @@ -91,6 +91,10 @@ public class VideoManagerConstants { | ||
| 91 | * 接收推流设备的GPS变化通知 | 91 | * 接收推流设备的GPS变化通知 |
| 92 | */ | 92 | */ |
| 93 | public static final String VM_MSG_PUSH_STREAM_STATUS_CHANGE = "VM_MSG_PUSH_STREAM_STATUS_CHANGE"; | 93 | public static final String VM_MSG_PUSH_STREAM_STATUS_CHANGE = "VM_MSG_PUSH_STREAM_STATUS_CHANGE"; |
| 94 | + /** | ||
| 95 | + * 接收推流设备列表更新变化通知 | ||
| 96 | + */ | ||
| 97 | + public static final String VM_MSG_PUSH_STREAM_LIST_CHANGE = "VM_MSG_PUSH_STREAM_LIST_CHANGE"; | ||
| 94 | 98 | ||
| 95 | /** | 99 | /** |
| 96 | * redis 消息通知设备推流到平台 | 100 | * redis 消息通知设备推流到平台 |
src/main/java/com/genersoft/iot/vmp/conf/RedisConfig.java
| @@ -43,6 +43,9 @@ public class RedisConfig extends CachingConfigurerSupport { | @@ -43,6 +43,9 @@ public class RedisConfig extends CachingConfigurerSupport { | ||
| 43 | @Autowired | 43 | @Autowired |
| 44 | private RedisPushStreamStatusMsgListener redisPushStreamStatusMsgListener; | 44 | private RedisPushStreamStatusMsgListener redisPushStreamStatusMsgListener; |
| 45 | 45 | ||
| 46 | + @Autowired | ||
| 47 | + private RedisPushStreamListMsgListener redisPushStreamListMsgListener; | ||
| 48 | + | ||
| 46 | @Bean | 49 | @Bean |
| 47 | public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) { | 50 | public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) { |
| 48 | RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>(); | 51 | RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>(); |
| @@ -80,6 +83,7 @@ public class RedisConfig extends CachingConfigurerSupport { | @@ -80,6 +83,7 @@ public class RedisConfig extends CachingConfigurerSupport { | ||
| 80 | container.addMessageListener(redisStreamMsgListener, new PatternTopic(VideoManagerConstants.WVP_MSG_STREAM_CHANGE_PREFIX + "PUSH")); | 83 | container.addMessageListener(redisStreamMsgListener, new PatternTopic(VideoManagerConstants.WVP_MSG_STREAM_CHANGE_PREFIX + "PUSH")); |
| 81 | container.addMessageListener(redisGbPlayMsgListener, new PatternTopic(RedisGbPlayMsgListener.WVP_PUSH_STREAM_KEY)); | 84 | container.addMessageListener(redisGbPlayMsgListener, new PatternTopic(RedisGbPlayMsgListener.WVP_PUSH_STREAM_KEY)); |
| 82 | container.addMessageListener(redisPushStreamStatusMsgListener, new PatternTopic(VideoManagerConstants.VM_MSG_PUSH_STREAM_STATUS_CHANGE)); | 85 | container.addMessageListener(redisPushStreamStatusMsgListener, new PatternTopic(VideoManagerConstants.VM_MSG_PUSH_STREAM_STATUS_CHANGE)); |
| 86 | + container.addMessageListener(redisPushStreamListMsgListener, new PatternTopic(VideoManagerConstants.VM_MSG_PUSH_STREAM_LIST_CHANGE)); | ||
| 83 | return container; | 87 | return container; |
| 84 | } | 88 | } |
| 85 | 89 |
src/main/java/com/genersoft/iot/vmp/service/IGbStreamService.java
| @@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.service; | @@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.service; | ||
| 3 | import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; | 3 | import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; |
| 4 | import com.genersoft.iot.vmp.gb28181.bean.GbStream; | 4 | import com.genersoft.iot.vmp.gb28181.bean.GbStream; |
| 5 | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | 5 | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
| 6 | +import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; | ||
| 6 | import com.github.pagehelper.PageInfo; | 7 | import com.github.pagehelper.PageInfo; |
| 7 | 8 | ||
| 8 | import java.util.List; | 9 | import java.util.List; |
| @@ -45,4 +46,11 @@ public interface IGbStreamService { | @@ -45,4 +46,11 @@ public interface IGbStreamService { | ||
| 45 | 46 | ||
| 46 | void sendCatalogMsg(GbStream gbStream, String type); | 47 | void sendCatalogMsg(GbStream gbStream, String type); |
| 47 | void sendCatalogMsgs(List<GbStream> gbStreams, String type); | 48 | void sendCatalogMsgs(List<GbStream> gbStreams, String type); |
| 49 | + | ||
| 50 | + /** | ||
| 51 | + * 修改gbId或name | ||
| 52 | + * @param streamPushItemForUpdate | ||
| 53 | + * @return | ||
| 54 | + */ | ||
| 55 | + int updateGbIdOrName(List<StreamPushItem> streamPushItemForUpdate); | ||
| 48 | } | 56 | } |
src/main/java/com/genersoft/iot/vmp/service/IStreamPushService.java
| @@ -100,4 +100,10 @@ public interface IStreamPushService { | @@ -100,4 +100,10 @@ public interface IStreamPushService { | ||
| 100 | * 增加推流 | 100 | * 增加推流 |
| 101 | */ | 101 | */ |
| 102 | boolean add(StreamPushItem stream); | 102 | boolean add(StreamPushItem stream); |
| 103 | + | ||
| 104 | + /** | ||
| 105 | + * 获取全部的app+Streanm 用于判断推流列表是新增还是修改 | ||
| 106 | + * @return | ||
| 107 | + */ | ||
| 108 | + List<String> getAllAppAndStream(); | ||
| 103 | } | 109 | } |
src/main/java/com/genersoft/iot/vmp/service/impl/GbStreamServiceImpl.java
| 1 | package com.genersoft.iot.vmp.service.impl; | 1 | package com.genersoft.iot.vmp.service.impl; |
| 2 | 2 | ||
| 3 | -import com.genersoft.iot.vmp.conf.SipConfig; | ||
| 4 | import com.genersoft.iot.vmp.gb28181.bean.*; | 3 | import com.genersoft.iot.vmp.gb28181.bean.*; |
| 5 | import com.genersoft.iot.vmp.gb28181.event.EventPublisher; | 4 | import com.genersoft.iot.vmp.gb28181.event.EventPublisher; |
| 6 | import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; | 5 | import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; |
| 7 | -import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; | 6 | +import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; |
| 8 | import com.genersoft.iot.vmp.storager.dao.GbStreamMapper; | 7 | import com.genersoft.iot.vmp.storager.dao.GbStreamMapper; |
| 9 | import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper; | 8 | import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper; |
| 10 | import com.genersoft.iot.vmp.storager.dao.PlatformCatalogMapper; | 9 | import com.genersoft.iot.vmp.storager.dao.PlatformCatalogMapper; |
| @@ -183,4 +182,9 @@ public class GbStreamServiceImpl implements IGbStreamService { | @@ -183,4 +182,9 @@ public class GbStreamServiceImpl implements IGbStreamService { | ||
| 183 | } | 182 | } |
| 184 | } | 183 | } |
| 185 | } | 184 | } |
| 185 | + | ||
| 186 | + @Override | ||
| 187 | + public int updateGbIdOrName(List<StreamPushItem> streamPushItemForUpdate) { | ||
| 188 | + return gbStreamMapper.updateGbIdOrName(streamPushItemForUpdate); | ||
| 189 | + } | ||
| 186 | } | 190 | } |
src/main/java/com/genersoft/iot/vmp/service/impl/RedisPushStreamListMsgListener.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.service.impl; | ||
| 2 | + | ||
| 3 | +import com.alibaba.fastjson.JSON; | ||
| 4 | +import com.alibaba.fastjson.JSONObject; | ||
| 5 | +import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; | ||
| 6 | +import com.genersoft.iot.vmp.service.IGbStreamService; | ||
| 7 | +import com.genersoft.iot.vmp.service.IMediaServerService; | ||
| 8 | +import com.genersoft.iot.vmp.service.IStreamPushService; | ||
| 9 | +import com.genersoft.iot.vmp.utils.DateUtil; | ||
| 10 | +import org.slf4j.Logger; | ||
| 11 | +import org.slf4j.LoggerFactory; | ||
| 12 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 13 | +import org.springframework.data.redis.connection.Message; | ||
| 14 | +import org.springframework.data.redis.connection.MessageListener; | ||
| 15 | +import org.springframework.stereotype.Component; | ||
| 16 | + | ||
| 17 | +import javax.annotation.Resource; | ||
| 18 | +import java.util.*; | ||
| 19 | + | ||
| 20 | +/** | ||
| 21 | + * @Auther: JiangFeng | ||
| 22 | + * @Date: 2022/8/16 11:32 | ||
| 23 | + * @Description: 接收redis发送的推流设备列表更新通知 | ||
| 24 | + */ | ||
| 25 | +@Component | ||
| 26 | +public class RedisPushStreamListMsgListener implements MessageListener { | ||
| 27 | + | ||
| 28 | + private final static Logger logger = LoggerFactory.getLogger(RedisPushStreamListMsgListener.class); | ||
| 29 | + @Resource | ||
| 30 | + private IMediaServerService mediaServerService; | ||
| 31 | + | ||
| 32 | + @Resource | ||
| 33 | + private IStreamPushService streamPushService; | ||
| 34 | + @Resource | ||
| 35 | + private IGbStreamService gbStreamService; | ||
| 36 | + | ||
| 37 | + @Override | ||
| 38 | + public void onMessage(Message message, byte[] bytes) { | ||
| 39 | + // | ||
| 40 | + logger.warn("[REDIS消息-推流设备列表更新]: {}", new String(message.getBody())); | ||
| 41 | + List<StreamPushItem> streamPushItems = JSON.parseArray(new String(message.getBody()), StreamPushItem.class); | ||
| 42 | + //查询全部的app+stream 用于判断是添加还是修改 | ||
| 43 | + List<String> allAppAndStream = streamPushService.getAllAppAndStream(); | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * 用于存储更具APP+Stream过滤后的数据,可以直接存入stream_push表与gb_stream表 | ||
| 47 | + */ | ||
| 48 | + List<StreamPushItem> streamPushItemForSave = new ArrayList<>(); | ||
| 49 | + List<StreamPushItem> streamPushItemForUpdate = new ArrayList<>(); | ||
| 50 | + for (StreamPushItem streamPushItem : streamPushItems) { | ||
| 51 | + String app = streamPushItem.getApp(); | ||
| 52 | + String stream = streamPushItem.getStream(); | ||
| 53 | + boolean contains = allAppAndStream.contains(app + stream); | ||
| 54 | + //不存在就添加 | ||
| 55 | + if (!contains) { | ||
| 56 | + streamPushItem.setStatus(false); | ||
| 57 | + streamPushItem.setStreamType("push"); | ||
| 58 | + streamPushItem.setCreateTime(DateUtil.getNow()); | ||
| 59 | + streamPushItem.setMediaServerId(mediaServerService.getDefaultMediaServer().getId()); | ||
| 60 | + streamPushItem.setOriginType(2); | ||
| 61 | + streamPushItem.setOriginTypeStr("rtsp_push"); | ||
| 62 | + streamPushItem.setTotalReaderCount("0"); | ||
| 63 | + streamPushItemForSave.add(streamPushItem); | ||
| 64 | + } else { | ||
| 65 | + //存在就只修改 name和gbId | ||
| 66 | + streamPushItemForUpdate.add(streamPushItem); | ||
| 67 | + } | ||
| 68 | + } | ||
| 69 | + if (streamPushItemForSave.size() > 0) { | ||
| 70 | + | ||
| 71 | + logger.info("添加{}条",streamPushItemForSave.size()); | ||
| 72 | + logger.info(JSONObject.toJSONString(streamPushItemForSave)); | ||
| 73 | + streamPushService.batchAdd(streamPushItemForSave); | ||
| 74 | + | ||
| 75 | + } | ||
| 76 | + if(streamPushItemForUpdate.size()>0){ | ||
| 77 | + logger.info("修改{}条",streamPushItemForUpdate.size()); | ||
| 78 | + logger.info(JSONObject.toJSONString(streamPushItemForUpdate)); | ||
| 79 | + gbStreamService.updateGbIdOrName(streamPushItemForUpdate); | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + } | ||
| 83 | +} |
src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushServiceImpl.java
| @@ -340,6 +340,7 @@ public class StreamPushServiceImpl implements IStreamPushService { | @@ -340,6 +340,7 @@ public class StreamPushServiceImpl implements IStreamPushService { | ||
| 340 | gbStreamMapper.batchAdd(streamPushItems); | 340 | gbStreamMapper.batchAdd(streamPushItems); |
| 341 | } | 341 | } |
| 342 | 342 | ||
| 343 | + | ||
| 343 | @Override | 344 | @Override |
| 344 | public void batchAddForUpload(List<StreamPushItem> streamPushItems, Map<String, List<String[]>> streamPushItemsForAll ) { | 345 | public void batchAddForUpload(List<StreamPushItem> streamPushItems, Map<String, List<String[]>> streamPushItemsForAll ) { |
| 345 | // 存储数据到stream_push表 | 346 | // 存储数据到stream_push表 |
| @@ -503,4 +504,9 @@ public class StreamPushServiceImpl implements IStreamPushService { | @@ -503,4 +504,9 @@ public class StreamPushServiceImpl implements IStreamPushService { | ||
| 503 | } | 504 | } |
| 504 | return result; | 505 | return result; |
| 505 | } | 506 | } |
| 507 | + | ||
| 508 | + @Override | ||
| 509 | + public List<String> getAllAppAndStream() { | ||
| 510 | + return streamPushMapper.getAllAppAndStream(); | ||
| 511 | + } | ||
| 506 | } | 512 | } |
src/main/java/com/genersoft/iot/vmp/storager/dao/GbStreamMapper.java
| @@ -148,4 +148,14 @@ public interface GbStreamMapper { | @@ -148,4 +148,14 @@ public interface GbStreamMapper { | ||
| 148 | "SET mediaServerId=#{mediaServerId}" + | 148 | "SET mediaServerId=#{mediaServerId}" + |
| 149 | "WHERE app=#{app} AND stream=#{stream}") | 149 | "WHERE app=#{app} AND stream=#{stream}") |
| 150 | void updateMediaServer(String app, String stream, String mediaServerId); | 150 | void updateMediaServer(String app, String stream, String mediaServerId); |
| 151 | + | ||
| 152 | + @Update("<script> "+ | ||
| 153 | + " <foreach collection='list' item='item' index='index' separator=';'>"+ | ||
| 154 | + "UPDATE gb_stream " + | ||
| 155 | + " SET name=#{item.name},"+ | ||
| 156 | + " gbId=#{item.gbId}"+ | ||
| 157 | + " WHERE app=#{item.app} and stream=#{item.stream}"+ | ||
| 158 | + "</foreach>"+ | ||
| 159 | + "</script>") | ||
| 160 | + int updateGbIdOrName(List<StreamPushItem> streamPushItemForUpdate); | ||
| 151 | } | 161 | } |
src/main/java/com/genersoft/iot/vmp/storager/dao/StreamPushMapper.java
| @@ -168,4 +168,7 @@ public interface StreamPushMapper { | @@ -168,4 +168,7 @@ public interface StreamPushMapper { | ||
| 168 | 168 | ||
| 169 | @Update("UPDATE stream_push SET status=0") | 169 | @Update("UPDATE stream_push SET status=0") |
| 170 | void setAllStreamOffline(); | 170 | void setAllStreamOffline(); |
| 171 | + | ||
| 172 | + @Select("SELECT CONCAT(app,stream) FROM gb_stream") | ||
| 173 | + List<String> getAllAppAndStream(); | ||
| 171 | } | 174 | } |