Commit 55b15f8ba657aac29929c6441baccf052311410c

Authored by 648540858
2 parents 654599b6 cf8a1261

Merge branch '2.6.9' into wvp-28181-2.0

src/main/java/com/genersoft/iot/vmp/media/zlm/AssistRESTfulUtils.java
@@ -2,7 +2,9 @@ package com.genersoft.iot.vmp.media.zlm; @@ -2,7 +2,9 @@ package com.genersoft.iot.vmp.media.zlm;
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.conf.exception.ControllerException;
5 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; 6 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
  7 +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
6 import okhttp3.*; 8 import okhttp3.*;
7 import okhttp3.logging.HttpLoggingInterceptor; 9 import okhttp3.logging.HttpLoggingInterceptor;
8 import org.jetbrains.annotations.NotNull; 10 import org.jetbrains.annotations.NotNull;
@@ -13,7 +15,9 @@ import org.springframework.util.ObjectUtils; @@ -13,7 +15,9 @@ import org.springframework.util.ObjectUtils;
13 15
14 import java.io.IOException; 16 import java.io.IOException;
15 import java.net.ConnectException; 17 import java.net.ConnectException;
  18 +import java.net.MalformedURLException;
16 import java.net.SocketTimeoutException; 19 import java.net.SocketTimeoutException;
  20 +import java.net.URL;
17 import java.util.HashMap; 21 import java.util.HashMap;
18 import java.util.List; 22 import java.util.List;
19 import java.util.Map; 23 import java.util.Map;
@@ -148,13 +152,14 @@ public class AssistRESTfulUtils { @@ -148,13 +152,14 @@ public class AssistRESTfulUtils {
148 return responseJSON; 152 return responseJSON;
149 } 153 }
150 154
151 - public JSONObject sendPost(MediaServerItem mediaServerItem, String api, JSONObject param, ZLMRESTfulUtils.RequestCallback callback, Integer readTimeOut) { 155 + public JSONObject sendPost(MediaServerItem mediaServerItem, String url,
  156 + JSONObject param, ZLMRESTfulUtils.RequestCallback callback,
  157 + Integer readTimeOut) {
152 OkHttpClient client = getClient(readTimeOut); 158 OkHttpClient client = getClient(readTimeOut);
153 159
154 if (mediaServerItem == null) { 160 if (mediaServerItem == null) {
155 return null; 161 return null;
156 } 162 }
157 - String url = String.format("http://%s:%s/%s", mediaServerItem.getIp(), mediaServerItem.getRecordAssistPort(), api);  
158 JSONObject responseJSON = new JSONObject(); 163 JSONObject responseJSON = new JSONObject();
159 //-2自定义流媒体 调用错误码 164 //-2自定义流媒体 调用错误码
160 responseJSON.put("code",-2); 165 responseJSON.put("code",-2);
@@ -253,8 +258,8 @@ public class AssistRESTfulUtils { @@ -253,8 +258,8 @@ public class AssistRESTfulUtils {
253 if (!ObjectUtils.isEmpty(remoteHost)) { 258 if (!ObjectUtils.isEmpty(remoteHost)) {
254 videoTaskInfoJSON.put("remoteHost", remoteHost); 259 videoTaskInfoJSON.put("remoteHost", remoteHost);
255 } 260 }
256 -  
257 - return sendPost(mediaServerItem, "api/record/file/download/task/add", videoTaskInfoJSON, null, 30); 261 + String urlStr = String.format("%s/api/record/file/download/task/add", remoteHost);;
  262 + return sendPost(mediaServerItem, urlStr, videoTaskInfoJSON, null, 30);
258 } 263 }
259 264
260 public JSONObject queryTaskList(MediaServerItem mediaServerItem, String app, String stream, String callId, String taskId, Boolean isEnd) { 265 public JSONObject queryTaskList(MediaServerItem mediaServerItem, String app, String stream, String callId, String taskId, Boolean isEnd) {
src/main/java/com/genersoft/iot/vmp/service/ICloudRecordService.java
@@ -33,7 +33,7 @@ public interface ICloudRecordService { @@ -33,7 +33,7 @@ public interface ICloudRecordService {
33 /** 33 /**
34 * 添加合并任务 34 * 添加合并任务
35 */ 35 */
36 - String addTask(String app, String stream, String mediaServerId, String startTime, String endTime, String callId, String remoteHost); 36 + String addTask(String app, String stream, MediaServerItem mediaServerItem, String startTime, String endTime, String callId, String remoteHost);
37 37
38 38
39 /** 39 /**
src/main/java/com/genersoft/iot/vmp/service/impl/CloudRecordServiceImpl.java
@@ -109,23 +109,10 @@ public class CloudRecordServiceImpl implements ICloudRecordService { @@ -109,23 +109,10 @@ public class CloudRecordServiceImpl implements ICloudRecordService {
109 } 109 }
110 110
111 @Override 111 @Override
112 - public String addTask(String app, String stream, String mediaServerId, String startTime, String endTime, String callId, String remoteHost) { 112 + public String addTask(String app, String stream, MediaServerItem mediaServerItem, String startTime, String endTime, String callId, String remoteHost) {
113 // 参数校验 113 // 参数校验
114 assert app != null; 114 assert app != null;
115 assert stream != null; 115 assert stream != null;
116 - MediaServerItem mediaServerItem = null;  
117 - if (mediaServerId == null) {  
118 - mediaServerItem = mediaServerService.getDefaultMediaServer();  
119 - }else {  
120 - mediaServerItem = mediaServerService.getOne(mediaServerId);  
121 - }  
122 - if (mediaServerItem == null) {  
123 - throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到可用的流媒体");  
124 - }else {  
125 - if (remoteHost == null) {  
126 - remoteHost = "http://" + mediaServerItem.getStreamIp() + ":" + mediaServerItem.getRecordAssistPort();  
127 - }  
128 - }  
129 if (mediaServerItem.getRecordAssistPort() == 0) { 116 if (mediaServerItem.getRecordAssistPort() == 0) {
130 throw new ControllerException(ErrorCode.ERROR100.getCode(), "为配置Assist服务"); 117 throw new ControllerException(ErrorCode.ERROR100.getCode(), "为配置Assist服务");
131 } 118 }
@@ -165,7 +152,7 @@ public class CloudRecordServiceImpl implements ICloudRecordService { @@ -165,7 +152,7 @@ public class CloudRecordServiceImpl implements ICloudRecordService {
165 } 152 }
166 JSONObject result = assistRESTfulUtils.queryTaskList(mediaServerItem, app, stream, callId, taskId, isEnd); 153 JSONObject result = assistRESTfulUtils.queryTaskList(mediaServerItem, app, stream, callId, taskId, isEnd);
167 if (result == null || result.getInteger("code") != 0) { 154 if (result == null || result.getInteger("code") != 0) {
168 - throw new ControllerException(ErrorCode.ERROR100.getCode(), result.getString("msg")); 155 + throw new ControllerException(ErrorCode.ERROR100.getCode(), result == null ? "查询任务列表失败" : result.getString("msg"));
169 } 156 }
170 return result.getJSONArray("data"); 157 return result.getJSONArray("data");
171 } 158 }
src/main/java/com/genersoft/iot/vmp/vmanager/cloudRecord/CloudRecordController.java
@@ -25,6 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -25,6 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.data.redis.core.RedisTemplate; 25 import org.springframework.data.redis.core.RedisTemplate;
26 import org.springframework.web.bind.annotation.*; 26 import org.springframework.web.bind.annotation.*;
27 27
  28 +import javax.servlet.http.HttpServletRequest;
28 import java.util.ArrayList; 29 import java.util.ArrayList;
29 import java.util.Calendar; 30 import java.util.Calendar;
30 import java.util.List; 31 import java.util.List;
@@ -157,6 +158,7 @@ public class CloudRecordController { @@ -157,6 +158,7 @@ public class CloudRecordController {
157 @Parameter(name = "callId", description = "鉴权ID", required = false) 158 @Parameter(name = "callId", description = "鉴权ID", required = false)
158 @Parameter(name = "remoteHost", description = "返回地址时的远程地址", required = false) 159 @Parameter(name = "remoteHost", description = "返回地址时的远程地址", required = false)
159 public String addTask( 160 public String addTask(
  161 + HttpServletRequest request,
160 @RequestParam(required = false) String app, 162 @RequestParam(required = false) String app,
161 @RequestParam(required = false) String stream, 163 @RequestParam(required = false) String stream,
162 @RequestParam(required = false) String mediaServerId, 164 @RequestParam(required = false) String mediaServerId,
@@ -165,7 +167,24 @@ public class CloudRecordController { @@ -165,7 +167,24 @@ public class CloudRecordController {
165 @RequestParam(required = false) String callId, 167 @RequestParam(required = false) String callId,
166 @RequestParam(required = false) String remoteHost 168 @RequestParam(required = false) String remoteHost
167 ){ 169 ){
168 - return cloudRecordService.addTask(app, stream, mediaServerId, startTime, endTime, callId, remoteHost); 170 + System.out.println(request.getScheme());
  171 + System.out.println(request.getLocalAddr());
  172 + System.out.println(request.getRemoteAddr());
  173 + System.out.println(request.getRequestURI());
  174 + MediaServerItem mediaServerItem;
  175 + if (mediaServerId == null) {
  176 + mediaServerItem = mediaServerService.getDefaultMediaServer();
  177 + }else {
  178 + mediaServerItem = mediaServerService.getOne(mediaServerId);
  179 + }
  180 + if (mediaServerItem == null) {
  181 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到可用的流媒体");
  182 + }else {
  183 + if (remoteHost == null) {
  184 + remoteHost = request.getScheme() + "://" + request.getLocalAddr() + ":" + mediaServerItem.getRecordAssistPort();
  185 + }
  186 + }
  187 + return cloudRecordService.addTask(app, stream, mediaServerItem, startTime, endTime, callId, remoteHost);
169 } 188 }
170 189
171 @ResponseBody 190 @ResponseBody