feat(aiot): 配置推送使用camera_code查询StreamProxy

- 修改 buildFlatConfig 方法,使用 camera_code 查询 StreamProxy
- 注入 StreamProxyMapper 依赖
- 优先使用 StreamProxy 的 srcUrl 作为 rtsp_url
- 添加 camera_code 字段,保留 camera_id 字段向后兼容
- 当 StreamProxy 不存在时,降级使用 MediaServer 构建 URL

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-13 11:09:50 +08:00
parent 6d1e1d0bc3
commit 450afb8112

View File

@@ -15,6 +15,8 @@ import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel;
import com.genersoft.iot.vmp.gb28181.dao.CommonGBChannelMapper;
import com.genersoft.iot.vmp.media.bean.MediaServer;
import com.genersoft.iot.vmp.media.service.IMediaServerService;
import com.genersoft.iot.vmp.streamProxy.bean.StreamProxy;
import com.genersoft.iot.vmp.streamProxy.dao.StreamProxyMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.stream.MapRecord;
@@ -53,6 +55,9 @@ public class AiRedisConfigServiceImpl implements IAiRedisConfigService {
@Autowired
private IMediaServerService mediaServerService;
@Autowired
private StreamProxyMapper streamProxyMapper;
private static final long KEY_EXPIRE_SECONDS = 86400 * 7; // 7天过期
@Override
@@ -486,7 +491,13 @@ public class AiRedisConfigServiceImpl implements IAiRedisConfigService {
for (String cameraId : cameraIds) {
// 摄像头信息
Map<String, Object> cameraMap = new LinkedHashMap<>();
cameraMap.put("camera_id", cameraId);
// cameraId 现在是 camera_code 格式(从 ROI 表)
// 使用 camera_code 查询 StreamProxy 获取详细信息
StreamProxy proxy = streamProxyMapper.selectByCameraCode(cameraId);
cameraMap.put("camera_code", cameraId); // 新字段名
cameraMap.put("camera_id", cameraId); // 保持向后兼容
// 获取 RTSP URL 和摄像头名称
String rtspUrl = "";
@@ -507,20 +518,27 @@ public class AiRedisConfigServiceImpl implements IAiRedisConfigService {
}
}
// 构建 RTSP 代理地址
try {
MediaServer mediaServer = mediaServerService.getDefaultMediaServer();
if (mediaServer != null && mediaServer.getRtspPort() != 0) {
rtspUrl = String.format("rtsp://%s:%s/%s",
mediaServer.getStreamIp() != null ? mediaServer.getStreamIp() : mediaServer.getIp(),
mediaServer.getRtspPort(), cameraId);
} else if (mediaServer != null) {
rtspUrl = String.format("http://%s:%s/%s.live.flv",
mediaServer.getStreamIp() != null ? mediaServer.getStreamIp() : mediaServer.getIp(),
mediaServer.getHttpPort(), cameraId);
// 优先使用 StreamProxy 中的源 URL
if (proxy != null && proxy.getSrcUrl() != null && !proxy.getSrcUrl().isEmpty()) {
rtspUrl = proxy.getSrcUrl();
log.debug("[AiRedis] 使用StreamProxy源URL: cameraCode={}, srcUrl={}", cameraId, rtspUrl);
} else {
// 降级方案:构建 RTSP 代理地址通过ZLM媒体服务器
// cameraId格式为 {app}/{stream}ZLM的RTSP路径直接使用该格式
try {
MediaServer mediaServer = mediaServerService.getDefaultMediaServer();
if (mediaServer != null && mediaServer.getRtspPort() != 0) {
rtspUrl = String.format("rtsp://%s:%s/%s",
mediaServer.getStreamIp() != null ? mediaServer.getStreamIp() : mediaServer.getIp(),
mediaServer.getRtspPort(), cameraId);
} else if (mediaServer != null) {
rtspUrl = String.format("http://%s:%s/%s.live.flv",
mediaServer.getStreamIp() != null ? mediaServer.getStreamIp() : mediaServer.getIp(),
mediaServer.getHttpPort(), cameraId);
}
} catch (Exception e) {
log.warn("[AiRedis] 获取媒体服务器信息失败: {}", e.getMessage());
}
} catch (Exception e) {
log.warn("[AiRedis] 获取媒体服务器信息失败: {}", e.getMessage());
}
cameraMap.put("rtsp_url", rtspUrl);