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

pull/1371/head
648540858 2024-03-13 15:24:09 +08:00
parent 010e73b0c7
commit e1d476a54a
8 changed files with 50 additions and 10 deletions

View File

@ -7,6 +7,7 @@ import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* *
@ -71,4 +72,7 @@ public interface IGbStreamService {
void delAllPlatformInfo(String platformId, String catalogId); void delAllPlatformInfo(String platformId, String catalogId);
List<GbStream> getGbChannelWithGbid(String gbId); List<GbStream> getGbChannelWithGbid(String gbId);
Map<String, GbStream> getAllGBId();
} }

View File

@ -115,4 +115,7 @@ public interface IStreamPushService {
*/ */
ResourceBaseInfo getOverview(); ResourceBaseInfo getOverview();
Map<String, StreamPushItem> getAllAppAndStreamMap();
} }

View File

@ -19,11 +19,11 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
@Service @Service
@DS("master") @DS("master")
@ -268,4 +268,9 @@ public class GbStreamServiceImpl implements IGbStreamService {
public List<GbStream> getGbChannelWithGbid(String gbId) { public List<GbStream> getGbChannelWithGbid(String gbId) {
return gbStreamMapper.selectByGBId(gbId); return gbStreamMapper.selectByGBId(gbId);
} }
@Override
public Map<String, GbStream> getAllGBId() {
return gbStreamMapper.getAllGBId();
}
} }

View File

@ -548,4 +548,9 @@ public class StreamPushServiceImpl implements IStreamPushService {
return new ResourceBaseInfo(total, online); return new ResourceBaseInfo(total, online);
} }
@Override
public Map<String, StreamPushItem> getAllAppAndStreamMap() {
return streamPushMapper.getAllAppAndStreamMap();
}
} }

View File

@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.service.redisMsg;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem; import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
import com.genersoft.iot.vmp.service.IGbStreamService; import com.genersoft.iot.vmp.service.IGbStreamService;
import com.genersoft.iot.vmp.service.IMediaServerService; import com.genersoft.iot.vmp.service.IMediaServerService;
@ -19,6 +20,7 @@ import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
/** /**
@ -57,7 +59,8 @@ public class RedisPushStreamStatusListMsgListener implements MessageListener {
try { try {
List<StreamPushItem> streamPushItems = JSON.parseArray(new String(msg.getBody()), StreamPushItem.class); List<StreamPushItem> streamPushItems = JSON.parseArray(new String(msg.getBody()), StreamPushItem.class);
//查询全部的app+stream 用于判断是添加还是修改 //查询全部的app+stream 用于判断是添加还是修改
List<String> allAppAndStream = streamPushService.getAllAppAndStream(); Map<String, StreamPushItem> allAppAndStream = streamPushService.getAllAppAndStreamMap();
Map<String, GbStream> allGBId = gbStreamService.getAllGBId();
/** /**
* APP+Streamstream_pushgb_stream * APP+Streamstream_pushgb_stream
@ -67,9 +70,15 @@ public class RedisPushStreamStatusListMsgListener implements MessageListener {
for (StreamPushItem streamPushItem : streamPushItems) { for (StreamPushItem streamPushItem : streamPushItems) {
String app = streamPushItem.getApp(); String app = streamPushItem.getApp();
String stream = streamPushItem.getStream(); String stream = streamPushItem.getStream();
boolean contains = allAppAndStream.contains(app + stream); boolean contains = allAppAndStream.containsKey(app + stream);
//不存在就添加 //不存在就添加
if (!contains) { if (!contains) {
if (allGBId.containsKey(streamPushItem.getGbId())) {
GbStream gbStream = allGBId.get(streamPushItem.getGbId());
logger.warn("[REDIS消息-推流设备列表更新] 国标编号重复: {}, 已分配给{}/{}",
streamPushItem.getGbId(), gbStream.getApp(), gbStream.getStream());
continue;
}
streamPushItem.setStreamType("push"); streamPushItem.setStreamType("push");
streamPushItem.setCreateTime(DateUtil.getNow()); streamPushItem.setCreateTime(DateUtil.getNow());
streamPushItem.setMediaServerId(mediaServerService.getDefaultMediaServer().getId()); streamPushItem.setMediaServerId(mediaServerService.getDefaultMediaServer().getId());
@ -77,25 +86,25 @@ public class RedisPushStreamStatusListMsgListener implements MessageListener {
streamPushItem.setOriginTypeStr("rtsp_push"); streamPushItem.setOriginTypeStr("rtsp_push");
streamPushItem.setTotalReaderCount("0"); streamPushItem.setTotalReaderCount("0");
streamPushItemForSave.add(streamPushItem); streamPushItemForSave.add(streamPushItem);
allGBId.put(streamPushItem.getGbId(), streamPushItem);
} else { } else {
//存在就只修改 name和gbId //存在就只修改 name和gbId
streamPushItemForUpdate.add(streamPushItem); streamPushItemForUpdate.add(streamPushItem);
} }
} }
if (streamPushItemForSave.size() > 0) { if (!streamPushItemForSave.isEmpty()) {
logger.info("添加{}条",streamPushItemForSave.size()); logger.info("添加{}条",streamPushItemForSave.size());
logger.info(JSONObject.toJSONString(streamPushItemForSave)); logger.info(JSONObject.toJSONString(streamPushItemForSave));
streamPushService.batchAdd(streamPushItemForSave); streamPushService.batchAdd(streamPushItemForSave);
} }
if(streamPushItemForUpdate.size()>0){ if(!streamPushItemForUpdate.isEmpty()){
logger.info("修改{}条",streamPushItemForUpdate.size()); logger.info("修改{}条",streamPushItemForUpdate.size());
logger.info(JSONObject.toJSONString(streamPushItemForUpdate)); logger.info(JSONObject.toJSONString(streamPushItemForUpdate));
gbStreamService.updateGbIdOrName(streamPushItemForUpdate); gbStreamService.updateGbIdOrName(streamPushItemForUpdate);
} }
}catch (Exception e) { }catch (Exception e) {
logger.warn("[REDIS消息-推流设备列表更新] 发现未处理的异常, \r\n{}", JSON.toJSONString(message)); logger.warn("[REDIS消息-推流设备列表更新] 发现未处理的异常, \r\n{}", new String(message.getBody()));
logger.error("[REDIS消息-推流设备列表更新] 异常内容: ", e); logger.error("[REDIS消息-推流设备列表更新] 异常内容: ", e);
} }
} }

View File

@ -10,6 +10,7 @@ import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
import java.util.Map;
@Mapper @Mapper
@Repository @Repository
@ -170,4 +171,7 @@ public interface GbStreamMapper {
@Select("SELECT status FROM wvp_stream_push WHERE app=#{app} AND stream=#{stream}") @Select("SELECT status FROM wvp_stream_push WHERE app=#{app} AND stream=#{stream}")
Boolean selectStatusForPush(@Param("app") String app, @Param("stream") String stream); Boolean selectStatusForPush(@Param("app") String app, @Param("stream") String stream);
@MapKey("gbId")
@Select("SELECT * from wvp_gb_stream")
Map<String, GbStream> getAllGBId();
} }

View File

@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
import java.util.Map;
@Mapper @Mapper
@Repository @Repository
@ -195,4 +196,12 @@ public interface StreamPushMapper {
"</foreach>" + "</foreach>" +
"</script>") "</script>")
List<StreamPushItem> getListIn(List<StreamPushItem> streamPushItems); List<StreamPushItem> getListIn(List<StreamPushItem> streamPushItems);
@MapKey("vhost")
@Select("SELECT CONCAT(wsp.app, wsp.stream) as vhost, wsp.app, wsp.stream, wgs.gb_id, wgs.name " +
" from wvp_stream_push wsp " +
" left join wvp_gb_stream wgs on wgs.app = wsp.app and wgs.stream = wsp.stream")
Map<String, StreamPushItem> getAllAppAndStreamMap();
} }

View File

@ -3,10 +3,9 @@ package com.genersoft.iot.vmp.vmanager.gb28181.gbStream;
import com.genersoft.iot.vmp.conf.exception.ControllerException; import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.conf.security.JwtUtils; import com.genersoft.iot.vmp.conf.security.JwtUtils;
import com.genersoft.iot.vmp.gb28181.bean.GbStream; import com.genersoft.iot.vmp.gb28181.bean.GbStream;
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
import com.genersoft.iot.vmp.service.IGbStreamService; import com.genersoft.iot.vmp.service.IGbStreamService;
import com.genersoft.iot.vmp.service.IPlatformService; import com.genersoft.iot.vmp.service.IPlatformService;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage; import com.genersoft.iot.vmp.service.IStreamPushService;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.genersoft.iot.vmp.vmanager.gb28181.gbStream.bean.GbStreamParam; import com.genersoft.iot.vmp.vmanager.gb28181.gbStream.bean.GbStreamParam;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
@ -20,7 +19,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@Tag(name = "视频流关联到级联平台") @Tag(name = "视频流关联到级联平台")
@ -34,6 +32,9 @@ public class GbStreamController {
@Autowired @Autowired
private IGbStreamService gbStreamService; private IGbStreamService gbStreamService;
@Autowired
private IStreamPushService service;
@Autowired @Autowired
private IPlatformService platformService; private IPlatformService platformService;