Commit e1d476a54a7aa72f429e41e5c2957b77edbeb0a7
1 parent
010e73b0
处理收到redis推动的推流设备信息内容重复的问题
Showing
8 changed files
with
50 additions
and
10 deletions
src/main/java/com/genersoft/iot/vmp/service/IGbStreamService.java
| @@ -7,6 +7,7 @@ import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; | @@ -7,6 +7,7 @@ import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; | ||
| 7 | import com.github.pagehelper.PageInfo; | 7 | import com.github.pagehelper.PageInfo; |
| 8 | 8 | ||
| 9 | import java.util.List; | 9 | import java.util.List; |
| 10 | +import java.util.Map; | ||
| 10 | 11 | ||
| 11 | /** | 12 | /** |
| 12 | * 级联国标平台关联流业务接口 | 13 | * 级联国标平台关联流业务接口 |
| @@ -71,4 +72,7 @@ public interface IGbStreamService { | @@ -71,4 +72,7 @@ public interface IGbStreamService { | ||
| 71 | void delAllPlatformInfo(String platformId, String catalogId); | 72 | void delAllPlatformInfo(String platformId, String catalogId); |
| 72 | 73 | ||
| 73 | List<GbStream> getGbChannelWithGbid(String gbId); | 74 | List<GbStream> getGbChannelWithGbid(String gbId); |
| 75 | + | ||
| 76 | + Map<String, GbStream> getAllGBId(); | ||
| 77 | + | ||
| 74 | } | 78 | } |
src/main/java/com/genersoft/iot/vmp/service/IStreamPushService.java
src/main/java/com/genersoft/iot/vmp/service/impl/GbStreamServiceImpl.java
| @@ -19,11 +19,11 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager; | @@ -19,11 +19,11 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager; | ||
| 19 | import org.springframework.stereotype.Service; | 19 | import org.springframework.stereotype.Service; |
| 20 | import org.springframework.transaction.TransactionDefinition; | 20 | import org.springframework.transaction.TransactionDefinition; |
| 21 | import org.springframework.transaction.TransactionStatus; | 21 | import org.springframework.transaction.TransactionStatus; |
| 22 | -import org.springframework.transaction.annotation.Transactional; | ||
| 23 | import org.springframework.util.ObjectUtils; | 22 | import org.springframework.util.ObjectUtils; |
| 24 | 23 | ||
| 25 | import java.util.ArrayList; | 24 | import java.util.ArrayList; |
| 26 | import java.util.List; | 25 | import java.util.List; |
| 26 | +import java.util.Map; | ||
| 27 | 27 | ||
| 28 | @Service | 28 | @Service |
| 29 | @DS("master") | 29 | @DS("master") |
| @@ -268,4 +268,9 @@ public class GbStreamServiceImpl implements IGbStreamService { | @@ -268,4 +268,9 @@ public class GbStreamServiceImpl implements IGbStreamService { | ||
| 268 | public List<GbStream> getGbChannelWithGbid(String gbId) { | 268 | public List<GbStream> getGbChannelWithGbid(String gbId) { |
| 269 | return gbStreamMapper.selectByGBId(gbId); | 269 | return gbStreamMapper.selectByGBId(gbId); |
| 270 | } | 270 | } |
| 271 | + | ||
| 272 | + @Override | ||
| 273 | + public Map<String, GbStream> getAllGBId() { | ||
| 274 | + return gbStreamMapper.getAllGBId(); | ||
| 275 | + } | ||
| 271 | } | 276 | } |
src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushServiceImpl.java
| @@ -548,4 +548,9 @@ public class StreamPushServiceImpl implements IStreamPushService { | @@ -548,4 +548,9 @@ public class StreamPushServiceImpl implements IStreamPushService { | ||
| 548 | 548 | ||
| 549 | return new ResourceBaseInfo(total, online); | 549 | return new ResourceBaseInfo(total, online); |
| 550 | } | 550 | } |
| 551 | + | ||
| 552 | + @Override | ||
| 553 | + public Map<String, StreamPushItem> getAllAppAndStreamMap() { | ||
| 554 | + return streamPushMapper.getAllAppAndStreamMap(); | ||
| 555 | + } | ||
| 551 | } | 556 | } |
src/main/java/com/genersoft/iot/vmp/service/redisMsg/RedisPushStreamStatusListMsgListener.java
| @@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.service.redisMsg; | @@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.service.redisMsg; | ||
| 2 | 2 | ||
| 3 | import com.alibaba.fastjson2.JSON; | 3 | import com.alibaba.fastjson2.JSON; |
| 4 | import com.alibaba.fastjson2.JSONObject; | 4 | import com.alibaba.fastjson2.JSONObject; |
| 5 | +import com.genersoft.iot.vmp.gb28181.bean.GbStream; | ||
| 5 | import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; | 6 | import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; |
| 6 | import com.genersoft.iot.vmp.service.IGbStreamService; | 7 | import com.genersoft.iot.vmp.service.IGbStreamService; |
| 7 | import com.genersoft.iot.vmp.service.IMediaServerService; | 8 | import com.genersoft.iot.vmp.service.IMediaServerService; |
| @@ -19,6 +20,7 @@ import org.springframework.stereotype.Component; | @@ -19,6 +20,7 @@ import org.springframework.stereotype.Component; | ||
| 19 | import javax.annotation.Resource; | 20 | import javax.annotation.Resource; |
| 20 | import java.util.ArrayList; | 21 | import java.util.ArrayList; |
| 21 | import java.util.List; | 22 | import java.util.List; |
| 23 | +import java.util.Map; | ||
| 22 | import java.util.concurrent.ConcurrentLinkedQueue; | 24 | import java.util.concurrent.ConcurrentLinkedQueue; |
| 23 | 25 | ||
| 24 | /** | 26 | /** |
| @@ -57,7 +59,8 @@ public class RedisPushStreamStatusListMsgListener implements MessageListener { | @@ -57,7 +59,8 @@ public class RedisPushStreamStatusListMsgListener implements MessageListener { | ||
| 57 | try { | 59 | try { |
| 58 | List<StreamPushItem> streamPushItems = JSON.parseArray(new String(msg.getBody()), StreamPushItem.class); | 60 | List<StreamPushItem> streamPushItems = JSON.parseArray(new String(msg.getBody()), StreamPushItem.class); |
| 59 | //查询全部的app+stream 用于判断是添加还是修改 | 61 | //查询全部的app+stream 用于判断是添加还是修改 |
| 60 | - List<String> allAppAndStream = streamPushService.getAllAppAndStream(); | 62 | + Map<String, StreamPushItem> allAppAndStream = streamPushService.getAllAppAndStreamMap(); |
| 63 | + Map<String, GbStream> allGBId = gbStreamService.getAllGBId(); | ||
| 61 | 64 | ||
| 62 | /** | 65 | /** |
| 63 | * 用于存储更具APP+Stream过滤后的数据,可以直接存入stream_push表与gb_stream表 | 66 | * 用于存储更具APP+Stream过滤后的数据,可以直接存入stream_push表与gb_stream表 |
| @@ -67,9 +70,15 @@ public class RedisPushStreamStatusListMsgListener implements MessageListener { | @@ -67,9 +70,15 @@ public class RedisPushStreamStatusListMsgListener implements MessageListener { | ||
| 67 | for (StreamPushItem streamPushItem : streamPushItems) { | 70 | for (StreamPushItem streamPushItem : streamPushItems) { |
| 68 | String app = streamPushItem.getApp(); | 71 | String app = streamPushItem.getApp(); |
| 69 | String stream = streamPushItem.getStream(); | 72 | String stream = streamPushItem.getStream(); |
| 70 | - boolean contains = allAppAndStream.contains(app + stream); | 73 | + boolean contains = allAppAndStream.containsKey(app + stream); |
| 71 | //不存在就添加 | 74 | //不存在就添加 |
| 72 | if (!contains) { | 75 | if (!contains) { |
| 76 | + if (allGBId.containsKey(streamPushItem.getGbId())) { | ||
| 77 | + GbStream gbStream = allGBId.get(streamPushItem.getGbId()); | ||
| 78 | + logger.warn("[REDIS消息-推流设备列表更新] 国标编号重复: {}, 已分配给{}/{}", | ||
| 79 | + streamPushItem.getGbId(), gbStream.getApp(), gbStream.getStream()); | ||
| 80 | + continue; | ||
| 81 | + } | ||
| 73 | streamPushItem.setStreamType("push"); | 82 | streamPushItem.setStreamType("push"); |
| 74 | streamPushItem.setCreateTime(DateUtil.getNow()); | 83 | streamPushItem.setCreateTime(DateUtil.getNow()); |
| 75 | streamPushItem.setMediaServerId(mediaServerService.getDefaultMediaServer().getId()); | 84 | streamPushItem.setMediaServerId(mediaServerService.getDefaultMediaServer().getId()); |
| @@ -77,25 +86,25 @@ public class RedisPushStreamStatusListMsgListener implements MessageListener { | @@ -77,25 +86,25 @@ public class RedisPushStreamStatusListMsgListener implements MessageListener { | ||
| 77 | streamPushItem.setOriginTypeStr("rtsp_push"); | 86 | streamPushItem.setOriginTypeStr("rtsp_push"); |
| 78 | streamPushItem.setTotalReaderCount("0"); | 87 | streamPushItem.setTotalReaderCount("0"); |
| 79 | streamPushItemForSave.add(streamPushItem); | 88 | streamPushItemForSave.add(streamPushItem); |
| 89 | + allGBId.put(streamPushItem.getGbId(), streamPushItem); | ||
| 80 | } else { | 90 | } else { |
| 81 | //存在就只修改 name和gbId | 91 | //存在就只修改 name和gbId |
| 82 | streamPushItemForUpdate.add(streamPushItem); | 92 | streamPushItemForUpdate.add(streamPushItem); |
| 83 | } | 93 | } |
| 84 | } | 94 | } |
| 85 | - if (streamPushItemForSave.size() > 0) { | ||
| 86 | - | 95 | + if (!streamPushItemForSave.isEmpty()) { |
| 87 | logger.info("添加{}条",streamPushItemForSave.size()); | 96 | logger.info("添加{}条",streamPushItemForSave.size()); |
| 88 | logger.info(JSONObject.toJSONString(streamPushItemForSave)); | 97 | logger.info(JSONObject.toJSONString(streamPushItemForSave)); |
| 89 | streamPushService.batchAdd(streamPushItemForSave); | 98 | streamPushService.batchAdd(streamPushItemForSave); |
| 90 | 99 | ||
| 91 | } | 100 | } |
| 92 | - if(streamPushItemForUpdate.size()>0){ | 101 | + if(!streamPushItemForUpdate.isEmpty()){ |
| 93 | logger.info("修改{}条",streamPushItemForUpdate.size()); | 102 | logger.info("修改{}条",streamPushItemForUpdate.size()); |
| 94 | logger.info(JSONObject.toJSONString(streamPushItemForUpdate)); | 103 | logger.info(JSONObject.toJSONString(streamPushItemForUpdate)); |
| 95 | gbStreamService.updateGbIdOrName(streamPushItemForUpdate); | 104 | gbStreamService.updateGbIdOrName(streamPushItemForUpdate); |
| 96 | } | 105 | } |
| 97 | }catch (Exception e) { | 106 | }catch (Exception e) { |
| 98 | - logger.warn("[REDIS消息-推流设备列表更新] 发现未处理的异常, \r\n{}", JSON.toJSONString(message)); | 107 | + logger.warn("[REDIS消息-推流设备列表更新] 发现未处理的异常, \r\n{}", new String(message.getBody())); |
| 99 | logger.error("[REDIS消息-推流设备列表更新] 异常内容: ", e); | 108 | logger.error("[REDIS消息-推流设备列表更新] 异常内容: ", e); |
| 100 | } | 109 | } |
| 101 | } | 110 | } |
src/main/java/com/genersoft/iot/vmp/storager/dao/GbStreamMapper.java
| @@ -10,6 +10,7 @@ import org.apache.ibatis.annotations.Param; | @@ -10,6 +10,7 @@ import org.apache.ibatis.annotations.Param; | ||
| 10 | import org.springframework.stereotype.Repository; | 10 | import org.springframework.stereotype.Repository; |
| 11 | 11 | ||
| 12 | import java.util.List; | 12 | import java.util.List; |
| 13 | +import java.util.Map; | ||
| 13 | 14 | ||
| 14 | @Mapper | 15 | @Mapper |
| 15 | @Repository | 16 | @Repository |
| @@ -170,4 +171,7 @@ public interface GbStreamMapper { | @@ -170,4 +171,7 @@ public interface GbStreamMapper { | ||
| 170 | @Select("SELECT status FROM wvp_stream_push WHERE app=#{app} AND stream=#{stream}") | 171 | @Select("SELECT status FROM wvp_stream_push WHERE app=#{app} AND stream=#{stream}") |
| 171 | Boolean selectStatusForPush(@Param("app") String app, @Param("stream") String stream); | 172 | Boolean selectStatusForPush(@Param("app") String app, @Param("stream") String stream); |
| 172 | 173 | ||
| 174 | + @MapKey("gbId") | ||
| 175 | + @Select("SELECT * from wvp_gb_stream") | ||
| 176 | + Map<String, GbStream> getAllGBId(); | ||
| 173 | } | 177 | } |
src/main/java/com/genersoft/iot/vmp/storager/dao/StreamPushMapper.java
| @@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.*; | @@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.*; | ||
| 7 | import org.springframework.stereotype.Repository; | 7 | import org.springframework.stereotype.Repository; |
| 8 | 8 | ||
| 9 | import java.util.List; | 9 | import java.util.List; |
| 10 | +import java.util.Map; | ||
| 10 | 11 | ||
| 11 | @Mapper | 12 | @Mapper |
| 12 | @Repository | 13 | @Repository |
| @@ -195,4 +196,12 @@ public interface StreamPushMapper { | @@ -195,4 +196,12 @@ public interface StreamPushMapper { | ||
| 195 | "</foreach>" + | 196 | "</foreach>" + |
| 196 | "</script>") | 197 | "</script>") |
| 197 | List<StreamPushItem> getListIn(List<StreamPushItem> streamPushItems); | 198 | List<StreamPushItem> getListIn(List<StreamPushItem> streamPushItems); |
| 199 | + | ||
| 200 | + @MapKey("vhost") | ||
| 201 | + @Select("SELECT CONCAT(wsp.app, wsp.stream) as vhost, wsp.app, wsp.stream, wgs.gb_id, wgs.name " + | ||
| 202 | + " from wvp_stream_push wsp " + | ||
| 203 | + " left join wvp_gb_stream wgs on wgs.app = wsp.app and wgs.stream = wsp.stream") | ||
| 204 | + Map<String, StreamPushItem> getAllAppAndStreamMap(); | ||
| 205 | + | ||
| 206 | + | ||
| 198 | } | 207 | } |
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/gbStream/GbStreamController.java
| @@ -3,10 +3,9 @@ package com.genersoft.iot.vmp.vmanager.gb28181.gbStream; | @@ -3,10 +3,9 @@ package com.genersoft.iot.vmp.vmanager.gb28181.gbStream; | ||
| 3 | import com.genersoft.iot.vmp.conf.exception.ControllerException; | 3 | import com.genersoft.iot.vmp.conf.exception.ControllerException; |
| 4 | import com.genersoft.iot.vmp.conf.security.JwtUtils; | 4 | import com.genersoft.iot.vmp.conf.security.JwtUtils; |
| 5 | import com.genersoft.iot.vmp.gb28181.bean.GbStream; | 5 | import com.genersoft.iot.vmp.gb28181.bean.GbStream; |
| 6 | -import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | ||
| 7 | import com.genersoft.iot.vmp.service.IGbStreamService; | 6 | import com.genersoft.iot.vmp.service.IGbStreamService; |
| 8 | import com.genersoft.iot.vmp.service.IPlatformService; | 7 | import com.genersoft.iot.vmp.service.IPlatformService; |
| 9 | -import com.genersoft.iot.vmp.storager.IVideoManagerStorage; | 8 | +import com.genersoft.iot.vmp.service.IStreamPushService; |
| 10 | import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; | 9 | import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; |
| 11 | import com.genersoft.iot.vmp.vmanager.gb28181.gbStream.bean.GbStreamParam; | 10 | import com.genersoft.iot.vmp.vmanager.gb28181.gbStream.bean.GbStreamParam; |
| 12 | import com.github.pagehelper.PageInfo; | 11 | import com.github.pagehelper.PageInfo; |
| @@ -20,7 +19,6 @@ import org.springframework.beans.factory.annotation.Autowired; | @@ -20,7 +19,6 @@ import org.springframework.beans.factory.annotation.Autowired; | ||
| 20 | import org.springframework.util.ObjectUtils; | 19 | import org.springframework.util.ObjectUtils; |
| 21 | import org.springframework.web.bind.annotation.*; | 20 | import org.springframework.web.bind.annotation.*; |
| 22 | 21 | ||
| 23 | -import java.util.ArrayList; | ||
| 24 | import java.util.List; | 22 | import java.util.List; |
| 25 | 23 | ||
| 26 | @Tag(name = "视频流关联到级联平台") | 24 | @Tag(name = "视频流关联到级联平台") |
| @@ -35,6 +33,9 @@ public class GbStreamController { | @@ -35,6 +33,9 @@ public class GbStreamController { | ||
| 35 | private IGbStreamService gbStreamService; | 33 | private IGbStreamService gbStreamService; |
| 36 | 34 | ||
| 37 | @Autowired | 35 | @Autowired |
| 36 | + private IStreamPushService service; | ||
| 37 | + | ||
| 38 | + @Autowired | ||
| 38 | private IPlatformService platformService; | 39 | private IPlatformService platformService; |
| 39 | 40 | ||
| 40 | 41 |