Commit e1d476a54a7aa72f429e41e5c2957b77edbeb0a7

Authored by 648540858
1 parent 010e73b0

处理收到redis推动的推流设备信息内容重复的问题

src/main/java/com/genersoft/iot/vmp/service/IGbStreamService.java
... ... @@ -7,6 +7,7 @@ import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
7 7 import com.github.pagehelper.PageInfo;
8 8  
9 9 import java.util.List;
  10 +import java.util.Map;
10 11  
11 12 /**
12 13 * 级联国标平台关联流业务接口
... ... @@ -71,4 +72,7 @@ public interface IGbStreamService {
71 72 void delAllPlatformInfo(String platformId, String catalogId);
72 73  
73 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
... ... @@ -115,4 +115,7 @@ public interface IStreamPushService {
115 115 */
116 116 ResourceBaseInfo getOverview();
117 117  
  118 + Map<String, StreamPushItem> getAllAppAndStreamMap();
  119 +
  120 +
118 121 }
... ...
src/main/java/com/genersoft/iot/vmp/service/impl/GbStreamServiceImpl.java
... ... @@ -19,11 +19,11 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager;
19 19 import org.springframework.stereotype.Service;
20 20 import org.springframework.transaction.TransactionDefinition;
21 21 import org.springframework.transaction.TransactionStatus;
22   -import org.springframework.transaction.annotation.Transactional;
23 22 import org.springframework.util.ObjectUtils;
24 23  
25 24 import java.util.ArrayList;
26 25 import java.util.List;
  26 +import java.util.Map;
27 27  
28 28 @Service
29 29 @DS("master")
... ... @@ -268,4 +268,9 @@ public class GbStreamServiceImpl implements IGbStreamService {
268 268 public List<GbStream> getGbChannelWithGbid(String gbId) {
269 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 548  
549 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 2  
3 3 import com.alibaba.fastjson2.JSON;
4 4 import com.alibaba.fastjson2.JSONObject;
  5 +import com.genersoft.iot.vmp.gb28181.bean.GbStream;
5 6 import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
6 7 import com.genersoft.iot.vmp.service.IGbStreamService;
7 8 import com.genersoft.iot.vmp.service.IMediaServerService;
... ... @@ -19,6 +20,7 @@ import org.springframework.stereotype.Component;
19 20 import javax.annotation.Resource;
20 21 import java.util.ArrayList;
21 22 import java.util.List;
  23 +import java.util.Map;
22 24 import java.util.concurrent.ConcurrentLinkedQueue;
23 25  
24 26 /**
... ... @@ -57,7 +59,8 @@ public class RedisPushStreamStatusListMsgListener implements MessageListener {
57 59 try {
58 60 List<StreamPushItem> streamPushItems = JSON.parseArray(new String(msg.getBody()), StreamPushItem.class);
59 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 66 * 用于存储更具APP+Stream过滤后的数据,可以直接存入stream_push表与gb_stream表
... ... @@ -67,9 +70,15 @@ public class RedisPushStreamStatusListMsgListener implements MessageListener {
67 70 for (StreamPushItem streamPushItem : streamPushItems) {
68 71 String app = streamPushItem.getApp();
69 72 String stream = streamPushItem.getStream();
70   - boolean contains = allAppAndStream.contains(app + stream);
  73 + boolean contains = allAppAndStream.containsKey(app + stream);
71 74 //不存在就添加
72 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 82 streamPushItem.setStreamType("push");
74 83 streamPushItem.setCreateTime(DateUtil.getNow());
75 84 streamPushItem.setMediaServerId(mediaServerService.getDefaultMediaServer().getId());
... ... @@ -77,25 +86,25 @@ public class RedisPushStreamStatusListMsgListener implements MessageListener {
77 86 streamPushItem.setOriginTypeStr("rtsp_push");
78 87 streamPushItem.setTotalReaderCount("0");
79 88 streamPushItemForSave.add(streamPushItem);
  89 + allGBId.put(streamPushItem.getGbId(), streamPushItem);
80 90 } else {
81 91 //存在就只修改 name和gbId
82 92 streamPushItemForUpdate.add(streamPushItem);
83 93 }
84 94 }
85   - if (streamPushItemForSave.size() > 0) {
86   -
  95 + if (!streamPushItemForSave.isEmpty()) {
87 96 logger.info("添加{}条",streamPushItemForSave.size());
88 97 logger.info(JSONObject.toJSONString(streamPushItemForSave));
89 98 streamPushService.batchAdd(streamPushItemForSave);
90 99  
91 100 }
92   - if(streamPushItemForUpdate.size()>0){
  101 + if(!streamPushItemForUpdate.isEmpty()){
93 102 logger.info("修改{}条",streamPushItemForUpdate.size());
94 103 logger.info(JSONObject.toJSONString(streamPushItemForUpdate));
95 104 gbStreamService.updateGbIdOrName(streamPushItemForUpdate);
96 105 }
97 106 }catch (Exception e) {
98   - logger.warn("[REDIS消息-推流设备列表更新] 发现未处理的异常, \r\n{}", JSON.toJSONString(message));
  107 + logger.warn("[REDIS消息-推流设备列表更新] 发现未处理的异常, \r\n{}", new String(message.getBody()));
99 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 10 import org.springframework.stereotype.Repository;
11 11  
12 12 import java.util.List;
  13 +import java.util.Map;
13 14  
14 15 @Mapper
15 16 @Repository
... ... @@ -170,4 +171,7 @@ public interface GbStreamMapper {
170 171 @Select("SELECT status FROM wvp_stream_push WHERE app=#{app} AND stream=#{stream}")
171 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 7 import org.springframework.stereotype.Repository;
8 8  
9 9 import java.util.List;
  10 +import java.util.Map;
10 11  
11 12 @Mapper
12 13 @Repository
... ... @@ -195,4 +196,12 @@ public interface StreamPushMapper {
195 196 "</foreach>" +
196 197 "</script>")
197 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 3 import com.genersoft.iot.vmp.conf.exception.ControllerException;
4 4 import com.genersoft.iot.vmp.conf.security.JwtUtils;
5 5 import com.genersoft.iot.vmp.gb28181.bean.GbStream;
6   -import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
7 6 import com.genersoft.iot.vmp.service.IGbStreamService;
8 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 9 import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
11 10 import com.genersoft.iot.vmp.vmanager.gb28181.gbStream.bean.GbStreamParam;
12 11 import com.github.pagehelper.PageInfo;
... ... @@ -20,7 +19,6 @@ import org.springframework.beans.factory.annotation.Autowired;
20 19 import org.springframework.util.ObjectUtils;
21 20 import org.springframework.web.bind.annotation.*;
22 21  
23   -import java.util.ArrayList;
24 22 import java.util.List;
25 23  
26 24 @Tag(name = "视频流关联到级联平台")
... ... @@ -35,6 +33,9 @@ public class GbStreamController {
35 33 private IGbStreamService gbStreamService;
36 34  
37 35 @Autowired
  36 + private IStreamPushService service;
  37 +
  38 + @Autowired
38 39 private IPlatformService platformService;
39 40  
40 41  
... ...