From 3146e63fc05fddf91e6df086e363a4f5584c1d6b Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Thu, 1 Sep 2022 17:53:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=BC=82=E5=B8=B8=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/vmp/conf/GlobalExceptionHandler.java | 1 + .../iot/vmp/conf/GlobalResponseAdvice.java | 16 ++++++++++++++++ .../gb28181/transmit/SIPProcessorObserver.java | 4 +++- .../iot/vmp/media/zlm/ZLMHttpHookListener.java | 9 ++++++--- .../iot/vmp/service/impl/MediaServiceImpl.java | 7 ++++--- .../service/impl/StreamProxyServiceImpl.java | 2 +- .../iot/vmp/storager/dao/StreamPushMapper.java | 4 ++-- .../MobilePositionController.java | 17 +++++------------ .../vmanager/gb28181/device/DeviceControl.java | 14 ++++---------- .../gb28181/platform/PlatformController.java | 6 ++---- web_src/config/index.js | 4 ++-- web_src/src/components/StreamProxyList.vue | 2 +- 12 files changed, 47 insertions(+), 39 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/conf/GlobalExceptionHandler.java b/src/main/java/com/genersoft/iot/vmp/conf/GlobalExceptionHandler.java index f5dff678..0c7c3d2f 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/GlobalExceptionHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/GlobalExceptionHandler.java @@ -32,6 +32,7 @@ public class GlobalExceptionHandler { return WVPResult.fail(ErrorCode.ERROR500.getCode(), e.getMessage()); } + /** * 自定义异常处理, 处理controller中返回的错误 * @param e 异常 diff --git a/src/main/java/com/genersoft/iot/vmp/conf/GlobalResponseAdvice.java b/src/main/java/com/genersoft/iot/vmp/conf/GlobalResponseAdvice.java index e1088e56..bfe344da 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/GlobalResponseAdvice.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/GlobalResponseAdvice.java @@ -1,17 +1,23 @@ package com.genersoft.iot.vmp.conf; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; import com.genersoft.iot.vmp.vmanager.bean.WVPResult; import org.jetbrains.annotations.NotNull; +import org.springframework.boot.autoconfigure.http.HttpMessageConverters; +import org.springframework.context.annotation.Bean; import org.springframework.core.MethodParameter; import org.springframework.http.MediaType; import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.http.server.ServerHttpRequest; import org.springframework.http.server.ServerHttpResponse; import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice; +import java.util.List; + /** * 全局统一返回结果 * @author lin @@ -25,6 +31,7 @@ public class GlobalResponseAdvice implements ResponseBodyAdvice { return true; } + @Override public Object beforeBodyWrite(Object body, @NotNull MethodParameter returnType, @NotNull MediaType selectedContentType, @NotNull Class> selectedConverterType, @NotNull ServerHttpRequest request, @NotNull ServerHttpResponse response) { // 排除api文档的接口,这个接口不需要统一 @@ -50,4 +57,13 @@ public class GlobalResponseAdvice implements ResponseBodyAdvice { return WVPResult.success(body); } + + /** + * 防止返回string时出错 + * @return + */ + @Bean + public HttpMessageConverters custHttpMessageConverter() { + return new HttpMessageConverters(new FastJsonHttpMessageConverter()); + } } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorObserver.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorObserver.java index 13f04b6d..71944f90 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorObserver.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorObserver.java @@ -151,7 +151,9 @@ public class SIPProcessorObserver implements ISIPProcessorObserver { logger.info("[发送错误订阅]"); SipSubscribe.Event subscribe = sipSubscribe.getErrorSubscribe(callIdHeader.getCallId()); SipSubscribe.EventResult eventResult = new SipSubscribe.EventResult(timeoutEvent); - subscribe.response(eventResult); + if (subscribe != null){ + subscribe.response(eventResult); + } sipSubscribe.removeOkSubscribe(callIdHeader.getCallId()); sipSubscribe.removeErrorSubscribe(callIdHeader.getCallId()); } diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java index 87271a30..ce463934 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java @@ -184,8 +184,7 @@ public class ZLMHttpHookListener { if (!"rtp".equals(param.getApp())) { Map paramMap = urlParamToMap(param.getParams()); StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(param.getApp(), param.getStream()); - if (streamAuthorityInfo == null - || (streamAuthorityInfo.getCallId() != null && !streamAuthorityInfo.getCallId().equals(paramMap.get("callId")))) { + if (streamAuthorityInfo != null && streamAuthorityInfo.getCallId() != null && !streamAuthorityInfo.getCallId().equals(paramMap.get("callId"))) { ret.put("code", 401); ret.put("msg", "Unauthorized"); return new ResponseEntity<>(ret.toString(),HttpStatus.OK); @@ -476,8 +475,12 @@ public class ZLMHttpHookListener { if (mediaServerItem != null){ if (regist) { StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(app, stream); + String callId = null; + if (streamAuthorityInfo != null) { + callId = streamAuthorityInfo.getCallId(); + } StreamInfo streamInfoByAppAndStream = mediaService.getStreamInfoByAppAndStream(mediaServerItem, - app, stream, tracks, streamAuthorityInfo.getCallId()); + app, stream, tracks, callId); item.setStreamInfo(streamInfoByAppAndStream); redisCatchStorage.addStream(mediaServerItem, type, app, stream, item); if (item.getOriginType() == OriginType.RTSP_PUSH.ordinal() diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java index ab1fd55b..6288a164 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java @@ -54,9 +54,10 @@ public class MediaServiceImpl implements IMediaService { if (mediaInfo == null) { return null; } + String calld = null; StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(app, stream); - if (streamAuthorityInfo == null) { - return null; + if (streamAuthorityInfo != null) { + calld = streamAuthorityInfo.getCallId(); } JSONObject mediaList = zlmresTfulUtils.getMediaList(mediaInfo, app, stream); if (mediaList != null) { @@ -68,7 +69,7 @@ public class MediaServiceImpl implements IMediaService { JSONObject mediaJSON = JSON.parseObject(JSON.toJSONString(data.get(0)), JSONObject.class); JSONArray tracks = mediaJSON.getJSONArray("tracks"); if (authority) { - streamInfo = getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks, addr,streamAuthorityInfo.getCallId()); + streamInfo = getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks, addr, calld); }else { streamInfo = getStreamInfoByAppAndStream(mediaInfo, app, stream, tracks, addr,null); } 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 e217ca96..aa197efa 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 @@ -296,7 +296,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService { public boolean start(String app, String stream) { boolean result = false; StreamProxyItem streamProxy = videoManagerStorager.queryStreamProxy(app, stream); - if (!streamProxy.isEnable() ) { + if (streamProxy != null && !streamProxy.isEnable() ) { JSONObject jsonObject = addStreamProxyToZlm(streamProxy); if (jsonObject == null) { return false; diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/StreamPushMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/StreamPushMapper.java index 706de93e..abff3eb9 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/StreamPushMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/StreamPushMapper.java @@ -76,8 +76,8 @@ public interface StreamPushMapper { "WHERE " + "1=1 " + " AND (st.app LIKE '%${query}%' OR st.stream LIKE '%${query}%' OR gs.gbId LIKE '%${query}%' OR gs.name LIKE '%${query}%') " + - " AND (gs.gbId is null OR st.status=1)" + - " AND st.status=0" + + " AND (gs.gbId is null OR st.pushIng=1)" + + " AND st.pushIng=0" + " AND st.mediaServerId=#{mediaServerId} " + "order by st.createTime desc" + " "}) diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/MobilePosition/MobilePositionController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/MobilePosition/MobilePositionController.java index 6b24f99c..e5d928a1 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/MobilePosition/MobilePositionController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/MobilePosition/MobilePositionController.java @@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.vmanager.gb28181.MobilePosition; import java.util.List; import java.util.UUID; +import com.genersoft.iot.vmp.conf.exception.ControllerException; import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.MobilePosition; import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; @@ -10,6 +11,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; import com.genersoft.iot.vmp.service.IDeviceService; import com.genersoft.iot.vmp.storager.IVideoManagerStorage; +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; import com.genersoft.iot.vmp.vmanager.bean.WVPResult; import com.github.pagehelper.util.StringUtil; @@ -136,13 +138,9 @@ public class MobilePositionController { @Parameter(name = "expires", description = "订阅超时时间", required = true) @Parameter(name = "interval", description = "上报时间间隔", required = true) @GetMapping("/subscribe/{deviceId}") - public String positionSubscribe(@PathVariable String deviceId, + public void positionSubscribe(@PathVariable String deviceId, @RequestParam String expires, @RequestParam String interval) { - String msg = ((expires.equals("0")) ? "取消" : "") + "订阅设备" + deviceId + "的移动位置"; - if (logger.isDebugEnabled()) { - logger.debug(msg); - } if (StringUtil.isEmpty(interval)) { interval = "5"; @@ -151,13 +149,8 @@ public class MobilePositionController { device.setSubscribeCycleForMobilePosition(Integer.parseInt(expires)); device.setMobilePositionSubmissionInterval(Integer.parseInt(interval)); deviceService.updateDevice(device); - String result = msg; - if (deviceService.removeMobilePositionSubscribe(device)) { - result += ",成功"; - } else { - result += ",失败"; + if (!deviceService.removeMobilePositionSubscribe(device)) { + throw new ControllerException(ErrorCode.ERROR100); } - - return result; } } diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceControl.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceControl.java index 30320e6d..fe363a6e 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceControl.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceControl.java @@ -56,20 +56,14 @@ public class DeviceControl { @Operation(summary = "远程启动控制命令") @Parameter(name = "deviceId", description = "设备国标编号", required = true) @GetMapping("/teleboot/{deviceId}") - public String teleBootApi(@PathVariable String deviceId) { + public void teleBootApi(@PathVariable String deviceId) { if (logger.isDebugEnabled()) { logger.debug("设备远程启动API调用"); } Device device = storager.queryVideoDevice(deviceId); - boolean sucsess = cmder.teleBootCmd(device); - if (sucsess) { - JSONObject json = new JSONObject(); - json.put("DeviceID", deviceId); - json.put("Result", "OK"); - return json.toJSONString(); - } else { - logger.warn("设备远程启动API调用失败!"); - throw new ControllerException(ErrorCode.ERROR100.getCode(), "设备远程启动API调用失败!"); + if (!cmder.teleBootCmd(device)) { + logger.warn("设备远程启动API调用失败!"); + throw new ControllerException(ErrorCode.ERROR100); } } diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java index bf421894..fa1de004 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java @@ -244,7 +244,7 @@ public class PlatformController { @Parameter(name = "serverGBId", description = "上级平台的国标编号") @DeleteMapping("/delete/{serverGBId}") @ResponseBody - public String deletePlatform(@PathVariable String serverGBId) { + public void deletePlatform(@PathVariable String serverGBId) { if (logger.isDebugEnabled()) { logger.debug("删除上级平台API调用"); @@ -278,9 +278,7 @@ public class PlatformController { dynamicTask.stop(key); // 删除缓存的订阅信息 subscribeHolder.removeAllSubscribe(parentPlatform.getServerGBId()); - if (deleteResult) { - return null; - } else { + if (!deleteResult) { throw new ControllerException(ErrorCode.ERROR100); } } diff --git a/web_src/config/index.js b/web_src/config/index.js index b1e1cbe1..c5a74528 100644 --- a/web_src/config/index.js +++ b/web_src/config/index.js @@ -12,14 +12,14 @@ module.exports = { assetsPublicPath: '/', proxyTable: { '/debug': { - target: 'http://localhost:18080', + target: 'http://localhost:38080', changeOrigin: true, pathRewrite: { '^/debug': '/' } }, '/static/snap': { - target: 'http://localhost:18080', + target: 'http://localhost:38080', changeOrigin: true, // pathRewrite: { // '^/static/snap': '/static/snap' diff --git a/web_src/src/components/StreamProxyList.vue b/web_src/src/components/StreamProxyList.vue index 99b2226f..5eff9d50 100644 --- a/web_src/src/components/StreamProxyList.vue +++ b/web_src/src/components/StreamProxyList.vue @@ -220,7 +220,7 @@ this.getListLoading = true; this.$axios({ method: 'get', - url:`/api/media/stream_info_by_app_and_stream`, + url:`/api/push/getPlayUrl`, params: { app: row.app, stream: row.stream,