From 0a404e23896b566a4dc017431951f8b73578ed73 Mon Sep 17 00:00:00 2001
From: 百鸣 <94030128+ixingqiao@users.noreply.github.com>
Date: 星期五, 26 八月 2022 11:49:43 +0800
Subject: [PATCH] Merge branch '648540858:wvp-28181-2.0' into wvp-28181-2.0
---
src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java | 99 +++++++++++++++++++++----------------------------
1 files changed, 42 insertions(+), 57 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java
index 6d699cf..8fabbda 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java
@@ -4,6 +4,7 @@
import com.alibaba.fastjson.JSONObject;
import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.conf.UserSetting;
+import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
import com.genersoft.iot.vmp.gb28181.bean.TreeType;
@@ -24,6 +25,7 @@
import com.genersoft.iot.vmp.storager.dao.StreamProxyMapper;
import com.genersoft.iot.vmp.service.IStreamProxyService;
import com.genersoft.iot.vmp.utils.DateUtil;
+import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
@@ -33,6 +35,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
+import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.net.InetAddress;
@@ -93,10 +96,8 @@
@Override
- public WVPResult<StreamInfo> save(StreamProxyItem param) {
+ public StreamInfo save(StreamProxyItem param) {
MediaServerItem mediaInfo;
- WVPResult<StreamInfo> wvpResult = new WVPResult<>();
- wvpResult.setCode(0);
if (param.getMediaServerId() == null || "auto".equals(param.getMediaServerId())){
mediaInfo = mediaServerService.getMediaServerForMinimumLoad();
}else {
@@ -104,14 +105,12 @@
}
if (mediaInfo == null) {
logger.warn("淇濆瓨浠g悊鏈壘鍒板湪绾跨殑ZLM...");
- wvpResult.setMsg("淇濆瓨澶辫触");
- return wvpResult;
+ throw new ControllerException(ErrorCode.ERROR100.getCode(), "淇濆瓨浠g悊鏈壘鍒板湪绾跨殑ZLM");
}
-
String dstUrl = String.format("rtmp://%s:%s/%s/%s", "127.0.0.1", mediaInfo.getRtmpPort(), param.getApp(),
param.getStream() );
param.setDst_url(dstUrl);
- StringBuffer result = new StringBuffer();
+ StringBuffer resultMsg = new StringBuffer();
boolean streamLive = false;
param.setMediaServerId(mediaInfo.getId());
boolean saveResult;
@@ -121,61 +120,47 @@
}else { // 鏂板
saveResult = addStreamProxy(param);
}
- if (saveResult) {
- result.append("淇濆瓨鎴愬姛");
- if (param.isEnable()) {
- JSONObject jsonObject = addStreamProxyToZlm(param);
- if (jsonObject == null || jsonObject.getInteger("code") != 0) {
- streamLive = false;
- result.append(", 浣嗘槸鍚敤澶辫触锛岃妫�鏌ユ祦鍦板潃鏄惁鍙敤");
- param.setEnable(false);
- // 鐩存帴绉婚櫎
- if (param.isEnable_remove_none_reader()) {
- del(param.getApp(), param.getStream());
- }else {
- updateStreamProxy(param);
- }
-
- }else {
- streamLive = true;
- StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream(
- mediaInfo, param.getApp(), param.getStream(), null, null);
- wvpResult.setData(streamInfo);
-
- }
- }
- }else {
- result.append("淇濆瓨澶辫触");
+ if (!saveResult) {
+ throw new ControllerException(ErrorCode.ERROR100.getCode(),"淇濆瓨澶辫触");
}
- if ( !StringUtils.isEmpty(param.getPlatformGbId()) && streamLive) {
+ StreamInfo resultForStreamInfo = null;
+ resultMsg.append("淇濆瓨鎴愬姛");
+ if (param.isEnable()) {
+ JSONObject jsonObject = addStreamProxyToZlm(param);
+ if (jsonObject == null || jsonObject.getInteger("code") != 0) {
+ streamLive = false;
+ resultMsg.append(", 浣嗘槸鍚敤澶辫触锛岃妫�鏌ユ祦鍦板潃鏄惁鍙敤");
+ param.setEnable(false);
+ // 鐩存帴绉婚櫎
+ if (param.isEnable_remove_none_reader()) {
+ del(param.getApp(), param.getStream());
+ }else {
+ updateStreamProxy(param);
+ }
+
+
+ }else {
+ streamLive = true;
+ resultForStreamInfo = mediaService.getStreamInfoByAppAndStream(
+ mediaInfo, param.getApp(), param.getStream(), null, null);
+
+ }
+ }
+ if ( !ObjectUtils.isEmpty(param.getPlatformGbId()) && streamLive) {
List<GbStream> gbStreams = new ArrayList<>();
gbStreams.add(param);
if (gbStreamService.addPlatformInfo(gbStreams, param.getPlatformGbId(), param.getCatalogId())){
- result.append(", 鍏宠仈鍥芥爣骞冲彴[ " + param.getPlatformGbId() + " ]鎴愬姛");
+ return resultForStreamInfo;
}else {
- result.append(", 鍏宠仈鍥芥爣骞冲彴[ " + param.getPlatformGbId() + " ]澶辫触");
+ resultMsg.append(", 鍏宠仈鍥芥爣骞冲彴[ " + param.getPlatformGbId() + " ]澶辫触");
+ throw new ControllerException(ErrorCode.ERROR100.getCode(), resultMsg.toString());
+ }
+ }else {
+ if (!streamLive) {
+ throw new ControllerException(ErrorCode.ERROR100.getCode(), resultMsg.toString());
}
}
- if (!StringUtils.isEmpty(param.getGbId())) {
- // 鏌ユ壘寮�鍚簡鍏ㄩ儴鐩存挱娴佸叡浜殑涓婄骇骞冲彴
- List<ParentPlatform> parentPlatforms = parentPlatformMapper.selectAllAhareAllLiveStream();
- if (parentPlatforms.size() > 0) {
- for (ParentPlatform parentPlatform : parentPlatforms) {
- param.setPlatformId(parentPlatform.getServerGBId());
- param.setCatalogId(parentPlatform.getCatalogId());
-
- String stream = param.getStream();
- StreamProxyItem streamProxyItems = platformGbStreamMapper.selectOne(param.getApp(), stream, parentPlatform.getServerGBId());
- if (streamProxyItems == null) {
- platformGbStreamMapper.add(param);
- eventPublisher.catalogEventPublishForStream(parentPlatform.getServerGBId(), param, CatalogEvent.ADD);
- }
- }
- }
- }
-
- wvpResult.setMsg(result.toString());
- return wvpResult;
+ return resultForStreamInfo;
}
/**
@@ -192,7 +177,7 @@
streamProxyItem.setCreateTime(now);
try {
if (streamProxyMapper.add(streamProxyItem) > 0) {
- if (!StringUtils.isEmpty(streamProxyItem.getGbId())) {
+ if (!ObjectUtils.isEmpty(streamProxyItem.getGbId())) {
if (gbStreamMapper.add(streamProxyItem) < 0) {
//浜嬪姟鍥炴粴
dataSourceTransactionManager.rollback(transactionStatus);
@@ -227,7 +212,7 @@
streamProxyItem.setStreamType("proxy");
try {
if (streamProxyMapper.update(streamProxyItem) > 0) {
- if (!StringUtils.isEmpty(streamProxyItem.getGbId())) {
+ if (!ObjectUtils.isEmpty(streamProxyItem.getGbId())) {
if (gbStreamMapper.updateByAppAndStream(streamProxyItem) == 0) {
//浜嬪姟鍥炴粴
dataSourceTransactionManager.rollback(transactionStatus);
--
Gitblit v1.8.0