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 | 91 | * 接收推流设备的GPS变化通知 |
| 92 | 92 | */ |
| 93 | 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 | 100 | * redis 消息通知设备推流到平台 | ... | ... |
src/main/java/com/genersoft/iot/vmp/conf/RedisConfig.java
| ... | ... | @@ -43,6 +43,9 @@ public class RedisConfig extends CachingConfigurerSupport { |
| 43 | 43 | @Autowired |
| 44 | 44 | private RedisPushStreamStatusMsgListener redisPushStreamStatusMsgListener; |
| 45 | 45 | |
| 46 | + @Autowired | |
| 47 | + private RedisPushStreamListMsgListener redisPushStreamListMsgListener; | |
| 48 | + | |
| 46 | 49 | @Bean |
| 47 | 50 | public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) { |
| 48 | 51 | RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>(); |
| ... | ... | @@ -80,6 +83,7 @@ public class RedisConfig extends CachingConfigurerSupport { |
| 80 | 83 | container.addMessageListener(redisStreamMsgListener, new PatternTopic(VideoManagerConstants.WVP_MSG_STREAM_CHANGE_PREFIX + "PUSH")); |
| 81 | 84 | container.addMessageListener(redisGbPlayMsgListener, new PatternTopic(RedisGbPlayMsgListener.WVP_PUSH_STREAM_KEY)); |
| 82 | 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 | 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 | 3 | import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; |
| 4 | 4 | import com.genersoft.iot.vmp.gb28181.bean.GbStream; |
| 5 | 5 | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
| 6 | +import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; | |
| 6 | 7 | import com.github.pagehelper.PageInfo; |
| 7 | 8 | |
| 8 | 9 | import java.util.List; |
| ... | ... | @@ -45,4 +46,11 @@ public interface IGbStreamService { |
| 45 | 46 | |
| 46 | 47 | void sendCatalogMsg(GbStream gbStream, String type); |
| 47 | 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
src/main/java/com/genersoft/iot/vmp/service/impl/GbStreamServiceImpl.java
| 1 | 1 | package com.genersoft.iot.vmp.service.impl; |
| 2 | 2 | |
| 3 | -import com.genersoft.iot.vmp.conf.SipConfig; | |
| 4 | 3 | import com.genersoft.iot.vmp.gb28181.bean.*; |
| 5 | 4 | import com.genersoft.iot.vmp.gb28181.event.EventPublisher; |
| 6 | 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 | 7 | import com.genersoft.iot.vmp.storager.dao.GbStreamMapper; |
| 9 | 8 | import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper; |
| 10 | 9 | import com.genersoft.iot.vmp.storager.dao.PlatformCatalogMapper; |
| ... | ... | @@ -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 | 340 | gbStreamMapper.batchAdd(streamPushItems); |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | + | |
| 343 | 344 | @Override |
| 344 | 345 | public void batchAddForUpload(List<StreamPushItem> streamPushItems, Map<String, List<String[]>> streamPushItemsForAll ) { |
| 345 | 346 | // 存储数据到stream_push表 |
| ... | ... | @@ -503,4 +504,9 @@ public class StreamPushServiceImpl implements IStreamPushService { |
| 503 | 504 | } |
| 504 | 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 | 148 | "SET mediaServerId=#{mediaServerId}" + |
| 149 | 149 | "WHERE app=#{app} AND stream=#{stream}") |
| 150 | 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