Commit 89a2e62702b47f163b37aa465a9873a471b5aa34

Authored by 648540858
2 parents 977bab15 042b28b2

Merge remote-tracking branch 'github/wvp-28181-2.0' into wvp-28181-2.0

Showing 64 changed files with 803 additions and 1020 deletions

Too many changes to show.

To preserve performance only 64 of 96 files are displayed.

src/main/java/com/genersoft/iot/vmp/conf/GlobalExceptionHandler.java 0 → 100644
  1 +package com.genersoft.iot.vmp.conf;
  2 +
  3 +import com.genersoft.iot.vmp.conf.exception.ControllerException;
  4 +import com.genersoft.iot.vmp.gb28181.event.alarm.AlarmEventListener;
  5 +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
  6 +import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
  7 +import org.slf4j.Logger;
  8 +import org.slf4j.LoggerFactory;
  9 +import org.springframework.http.HttpStatus;
  10 +import org.springframework.security.authentication.BadCredentialsException;
  11 +import org.springframework.web.bind.annotation.ExceptionHandler;
  12 +import org.springframework.web.bind.annotation.ResponseStatus;
  13 +import org.springframework.web.bind.annotation.RestControllerAdvice;
  14 +
  15 +/**
  16 + * 全局异常处理
  17 + */
  18 +@RestControllerAdvice
  19 +public class GlobalExceptionHandler {
  20 +
  21 + private final static Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
  22 +
  23 + /**
  24 + * 默认异常处理
  25 + * @param e 异常
  26 + * @return 统一返回结果
  27 + */
  28 + @ExceptionHandler(Exception.class)
  29 + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
  30 + public WVPResult<String> exceptionHandler(Exception e) {
  31 + logger.error("[全局异常]: ", e);
  32 + return WVPResult.fail(ErrorCode.ERROR500.getCode(), e.getMessage());
  33 + }
  34 +
  35 + /**
  36 + * 自定义异常处理, 处理controller中返回的错误
  37 + * @param e 异常
  38 + * @return 统一返回结果
  39 + */
  40 + @ExceptionHandler(ControllerException.class)
  41 + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
  42 + public WVPResult<String> exceptionHandler(ControllerException e) {
  43 + return WVPResult.fail(e.getCode(), e.getMsg());
  44 + }
  45 +
  46 + /**
  47 + * 登陆失败
  48 + * @param e 异常
  49 + * @return 统一返回结果
  50 + */
  51 + @ExceptionHandler(BadCredentialsException.class)
  52 + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
  53 + public WVPResult<String> exceptionHandler(BadCredentialsException e) {
  54 + return WVPResult.fail(ErrorCode.ERROR100.getCode(), e.getMessage());
  55 + }
  56 +}
... ...
src/main/java/com/genersoft/iot/vmp/conf/GlobalResponseAdvice.java 0 → 100644
  1 +package com.genersoft.iot.vmp.conf;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
  5 +import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
  6 +import org.jetbrains.annotations.NotNull;
  7 +import org.springframework.core.MethodParameter;
  8 +import org.springframework.http.MediaType;
  9 +import org.springframework.http.converter.HttpMessageConverter;
  10 +import org.springframework.http.server.ServerHttpRequest;
  11 +import org.springframework.http.server.ServerHttpResponse;
  12 +import org.springframework.web.bind.annotation.RestControllerAdvice;
  13 +import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
  14 +
  15 +/**
  16 + * 全局统一返回结果
  17 + * @author lin
  18 + */
  19 +@RestControllerAdvice
  20 +public class GlobalResponseAdvice implements ResponseBodyAdvice<Object> {
  21 +
  22 +
  23 + @Override
  24 + public boolean supports(@NotNull MethodParameter returnType, @NotNull Class<? extends HttpMessageConverter<?>> converterType) {
  25 + return true;
  26 + }
  27 +
  28 + @Override
  29 + public Object beforeBodyWrite(Object body, @NotNull MethodParameter returnType, @NotNull MediaType selectedContentType, @NotNull Class<? extends HttpMessageConverter<?>> selectedConverterType, @NotNull ServerHttpRequest request, @NotNull ServerHttpResponse response) {
  30 + // 排除api文档的接口,这个接口不需要统一
  31 + String[] excludePath = {"/v3/api-docs","/api/v1","/index/hook"};
  32 + for (String path : excludePath) {
  33 + if (request.getURI().getPath().startsWith(path)) {
  34 + return body;
  35 + }
  36 + }
  37 +
  38 + if (body instanceof WVPResult) {
  39 + return body;
  40 + }
  41 +
  42 + if (body instanceof ErrorCode) {
  43 + ErrorCode errorCode = (ErrorCode) body;
  44 + return new WVPResult<>(errorCode.getCode(), errorCode.getMsg(), null);
  45 + }
  46 +
  47 + if (body instanceof String) {
  48 + return JSON.toJSONString(WVPResult.success(body));
  49 + }
  50 +
  51 + return WVPResult.success(body);
  52 + }
  53 +}
... ...
src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java
... ... @@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
4 4 import com.genersoft.iot.vmp.utils.DateUtil;
5 5 import org.springframework.beans.factory.annotation.Value;
6 6 import org.springframework.context.annotation.Configuration;
  7 +import org.springframework.util.ObjectUtils;
7 8 import org.springframework.util.StringUtils;
8 9  
9 10 import java.net.InetAddress;
... ... @@ -88,7 +89,7 @@ public class MediaConfig{
88 89 }
89 90  
90 91 public String getHookIp() {
91   - if (StringUtils.isEmpty(hookIp)){
  92 + if (ObjectUtils.isEmpty(hookIp)){
92 93 return sipIp;
93 94 }else {
94 95 return hookIp;
... ... @@ -162,7 +163,7 @@ public class MediaConfig{
162 163 }
163 164  
164 165 public String getSdpIp() {
165   - if (StringUtils.isEmpty(sdpIp)){
  166 + if (ObjectUtils.isEmpty(sdpIp)){
166 167 return ip;
167 168 }else {
168 169 if (isValidIPAddress(sdpIp)) {
... ... @@ -181,7 +182,7 @@ public class MediaConfig{
181 182 }
182 183  
183 184 public String getStreamIp() {
184   - if (StringUtils.isEmpty(streamIp)){
  185 + if (ObjectUtils.isEmpty(streamIp)){
185 186 return ip;
186 187 }else {
187 188 return streamIp;
... ...
src/main/java/com/genersoft/iot/vmp/conf/ProxyServletConfig.java
... ... @@ -14,6 +14,7 @@ import org.springframework.beans.factory.annotation.Value;
14 14 import org.springframework.boot.web.servlet.ServletRegistrationBean;
15 15 import org.springframework.context.annotation.Bean;
16 16 import org.springframework.context.annotation.Configuration;
  17 +import org.springframework.util.ObjectUtils;
17 18 import org.springframework.util.StringUtils;
18 19  
19 20 import javax.servlet.ServletException;
... ... @@ -55,7 +56,7 @@ public class ProxyServletConfig {
55 56 String queryStr = super.rewriteQueryStringFromRequest(servletRequest, queryString);
56 57 MediaServerItem mediaInfo = getMediaInfoByUri(servletRequest.getRequestURI());
57 58 if (mediaInfo != null) {
58   - if (!StringUtils.isEmpty(queryStr)) {
  59 + if (!ObjectUtils.isEmpty(queryStr)) {
59 60 queryStr += "&secret=" + mediaInfo.getSecret();
60 61 }else {
61 62 queryStr = "secret=" + mediaInfo.getSecret();
... ... @@ -146,7 +147,7 @@ public class ProxyServletConfig {
146 147 logger.error("[ZLM服务访问代理],错误:处理url信息时未找到流媒体信息=>{}", requestURI);
147 148 return url;
148 149 }
149   - if (!StringUtils.isEmpty(mediaInfo.getId())) {
  150 + if (!ObjectUtils.isEmpty(mediaInfo.getId())) {
150 151 url = url.replace(mediaInfo.getId() + "/", "");
151 152 }
152 153 return url.replace("default/", "");
... ... @@ -173,7 +174,7 @@ public class ProxyServletConfig {
173 174 MediaServerItem mediaInfo = getMediaInfoByUri(servletRequest.getRequestURI());
174 175 String remoteHost = String.format("http://%s:%s", mediaInfo.getIp(), mediaInfo.getHttpPort());
175 176 if (mediaInfo != null) {
176   - if (!StringUtils.isEmpty(queryStr)) {
  177 + if (!ObjectUtils.isEmpty(queryStr)) {
177 178 queryStr += "&remoteHost=" + remoteHost;
178 179 }else {
179 180 queryStr = "remoteHost=" + remoteHost;
... ... @@ -265,7 +266,7 @@ public class ProxyServletConfig {
265 266 logger.error("[录像服务访问代理],错误:处理url信息时未找到流媒体信息=>{}", requestURI);
266 267 return url;
267 268 }
268   - if (!StringUtils.isEmpty(mediaInfo.getId())) {
  269 + if (!ObjectUtils.isEmpty(mediaInfo.getId())) {
269 270 url = url.replace(mediaInfo.getId() + "/", "");
270 271 }
271 272 return url.replace("default/", "");
... ...
src/main/java/com/genersoft/iot/vmp/conf/exception/ControllerException.java 0 → 100644
  1 +package com.genersoft.iot.vmp.conf.exception;
  2 +
  3 +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
  4 +
  5 +/**
  6 + * 自定义异常,controller出现错误时直接抛出异常由全局异常捕获并返回结果
  7 + */
  8 +public class ControllerException extends RuntimeException{
  9 +
  10 + private int code;
  11 + private String msg;
  12 +
  13 + public ControllerException(int code, String msg) {
  14 + this.code = code;
  15 + this.msg = msg;
  16 + }
  17 + public ControllerException(ErrorCode errorCode) {
  18 + this.code = errorCode.getCode();
  19 + this.msg = errorCode.getMsg();
  20 + }
  21 +
  22 + public int getCode() {
  23 + return code;
  24 + }
  25 +
  26 + public void setCode(int code) {
  27 + this.code = code;
  28 + }
  29 +
  30 + public String getMsg() {
  31 + return msg;
  32 + }
  33 +
  34 + public void setMsg(String msg) {
  35 + this.msg = msg;
  36 + }
  37 +}
... ...
src/main/java/com/genersoft/iot/vmp/conf/security/WebSecurityConfig.java
... ... @@ -91,6 +91,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
91 91 .antMatchers("/webjars/**")
92 92 .antMatchers("/swagger-resources/**")
93 93 .antMatchers("/v3/api-docs/**")
  94 + .antMatchers("/favicon.ico")
94 95 .antMatchers("/js/**");
95 96 List<String> interfaceAuthenticationExcludes = userSetting.getInterfaceAuthenticationExcludes();
96 97 for (String interfaceAuthenticationExclude : interfaceAuthenticationExcludes) {
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java
... ... @@ -37,9 +37,9 @@ public class EventPublisher {
37 37 * @param platformGbId
38 38 */
39 39 public void platformKeepaliveExpireEventPublish(String platformGbId){
40   - PlatformKeepaliveExpireEvent platformNotRegisterEvent = new PlatformKeepaliveExpireEvent(this);
41   - platformNotRegisterEvent.setPlatformGbID(platformGbId);
42   - applicationEventPublisher.publishEvent(platformNotRegisterEvent);
  40 + PlatformKeepaliveExpireEvent platformKeepaliveExpireEvent = new PlatformKeepaliveExpireEvent(this);
  41 + platformKeepaliveExpireEvent.setPlatformGbID(platformGbId);
  42 + applicationEventPublisher.publishEvent(platformKeepaliveExpireEvent);
43 43 }
44 44  
45 45 /**
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEventLister.java
... ... @@ -15,6 +15,7 @@ import org.slf4j.LoggerFactory;
15 15 import org.springframework.beans.factory.annotation.Autowired;
16 16 import org.springframework.context.ApplicationListener;
17 17 import org.springframework.stereotype.Component;
  18 +import org.springframework.util.ObjectUtils;
18 19 import org.springframework.util.StringUtils;
19 20  
20 21 import java.util.*;
... ... @@ -58,7 +59,7 @@ public class CatalogEventLister implements ApplicationListener&lt;CatalogEvent&gt; {
58 59 ParentPlatform parentPlatform = null;
59 60  
60 61 Map<String, List<ParentPlatform>> parentPlatformMap = new HashMap<>();
61   - if (!StringUtils.isEmpty(event.getPlatformId())) {
  62 + if (!ObjectUtils.isEmpty(event.getPlatformId())) {
62 63 subscribe = subscribeHolder.getCatalogSubscribe(event.getPlatformId());
63 64 if (subscribe == null) {
64 65 return;
... ... @@ -81,7 +82,7 @@ public class CatalogEventLister implements ApplicationListener&lt;CatalogEvent&gt; {
81 82 }else if (event.getGbStreams() != null) {
82 83 if (platforms.size() > 0) {
83 84 for (GbStream gbStream : event.getGbStreams()) {
84   - if (gbStream == null || StringUtils.isEmpty(gbStream.getGbId())) {
  85 + if (gbStream == null || ObjectUtils.isEmpty(gbStream.getGbId())) {
85 86 continue;
86 87 }
87 88 List<ParentPlatform> parentPlatformsForGB = storager.queryPlatFormListForStreamWithGBId(gbStream.getApp(),gbStream.getStream(), platforms);
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/session/RecordDataCatch.java
... ... @@ -60,16 +60,12 @@ public class RecordDataCatch {
60 60 // 处理录像数据, 返回给前端
61 61 String msgKey = DeferredResultHolder.CALLBACK_CMD_RECORDINFO + recordInfo.getDeviceId() + recordInfo.getSn();
62 62  
63   - WVPResult<RecordInfo> wvpResult = new WVPResult<>();
64   - wvpResult.setCode(0);
65   - wvpResult.setMsg("success");
66 63 // 对数据进行排序
67 64 Collections.sort(recordInfo.getRecordList());
68   - wvpResult.setData(recordInfo);
69 65  
70 66 RequestMessage msg = new RequestMessage();
71 67 msg.setKey(msgKey);
72   - msg.setData(wvpResult);
  68 + msg.setData(recordInfo);
73 69 deferredResultHolder.invokeAllResult(msg);
74 70 data.remove(key);
75 71 }
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/session/VideoStreamSessionManager.java
... ... @@ -14,6 +14,7 @@ import com.genersoft.iot.vmp.utils.redis.RedisUtil;
14 14 import gov.nist.javax.sip.stack.SIPDialog;
15 15 import org.springframework.beans.factory.annotation.Autowired;
16 16 import org.springframework.stereotype.Component;
  17 +import org.springframework.util.ObjectUtils;
17 18 import org.springframework.util.StringUtils;
18 19  
19 20 /**
... ... @@ -110,16 +111,16 @@ public class VideoStreamSessionManager {
110 111  
111 112 public SsrcTransaction getSsrcTransaction(String deviceId, String channelId, String callId, String stream){
112 113  
113   - if (StringUtils.isEmpty(deviceId)) {
  114 + if (ObjectUtils.isEmpty(deviceId)) {
114 115 deviceId ="*";
115 116 }
116   - if (StringUtils.isEmpty(channelId)) {
  117 + if (ObjectUtils.isEmpty(channelId)) {
117 118 channelId ="*";
118 119 }
119   - if (StringUtils.isEmpty(callId)) {
  120 + if (ObjectUtils.isEmpty(callId)) {
120 121 callId ="*";
121 122 }
122   - if (StringUtils.isEmpty(stream)) {
  123 + if (ObjectUtils.isEmpty(stream)) {
123 124 stream ="*";
124 125 }
125 126 String key = VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + userSetting.getServerId() + "_" + deviceId + "_" + channelId + "_" + callId+ "_" + stream;
... ... @@ -131,16 +132,16 @@ public class VideoStreamSessionManager {
131 132 }
132 133  
133 134 public List<SsrcTransaction> getSsrcTransactionForAll(String deviceId, String channelId, String callId, String stream){
134   - if (StringUtils.isEmpty(deviceId)) {
  135 + if (ObjectUtils.isEmpty(deviceId)) {
135 136 deviceId ="*";
136 137 }
137   - if (StringUtils.isEmpty(channelId)) {
  138 + if (ObjectUtils.isEmpty(channelId)) {
138 139 channelId ="*";
139 140 }
140   - if (StringUtils.isEmpty(callId)) {
  141 + if (ObjectUtils.isEmpty(callId)) {
141 142 callId ="*";
142 143 }
143   - if (StringUtils.isEmpty(stream)) {
  144 + if (ObjectUtils.isEmpty(stream)) {
144 145 stream ="*";
145 146 }
146 147 String key = VideoManagerConstants.MEDIA_TRANSACTION_USED_PREFIX + userSetting.getServerId() + "_" + deviceId + "_" + channelId + "_" + callId+ "_" + stream;
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorObserver.java
... ... @@ -3,8 +3,6 @@ package com.genersoft.iot.vmp.gb28181.transmit;
3 3 import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
4 4 import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
5 5 import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor;
6   -import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.RegisterRequestProcessor;
7   -import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.cmd.KeepaliveNotifyMessageHandler;
8 6 import com.genersoft.iot.vmp.gb28181.transmit.event.response.ISIPResponseProcessor;
9 7 import com.genersoft.iot.vmp.gb28181.transmit.event.timeout.ITimeoutProcessor;
10 8 import org.slf4j.Logger;
... ... @@ -14,13 +12,10 @@ import org.springframework.scheduling.annotation.Async;
14 12 import org.springframework.stereotype.Component;
15 13  
16 14 import javax.sip.*;
17   -import javax.sip.address.SipURI;
18   -import javax.sip.address.URI;
19 15 import javax.sip.header.*;
20 16 import javax.sip.message.Request;
21 17 import javax.sip.message.Response;
22 18 import java.util.Map;
23   -import java.util.Objects;
24 19 import java.util.concurrent.ConcurrentHashMap;
25 20  
26 21 /**
... ... @@ -43,9 +38,6 @@ public class SIPProcessorObserver implements ISIPProcessorObserver {
43 38 @Autowired
44 39 private EventPublisher eventPublisher;
45 40  
46   -
47   -
48   -
49 41 /**
50 42 * 添加 request订阅
51 43 * @param method 方法名
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/callback/DeferredResultHolder.java
... ... @@ -96,7 +96,7 @@ public class DeferredResultHolder {
96 96 if (result == null) {
97 97 return;
98 98 }
99   - result.setResult(new ResponseEntity<>(msg.getData(),HttpStatus.OK));
  99 + result.setResult(msg.getData());
100 100 deferredResultMap.remove(msg.getId());
101 101 if (deferredResultMap.size() == 0) {
102 102 map.remove(msg.getKey());
... ... @@ -118,9 +118,8 @@ public class DeferredResultHolder {
118 118 if (result == null) {
119 119 return;
120 120 }
121   - result.setResult(ResponseEntity.ok().body(msg.getData()));
  121 + result.setResult(msg.getData());
122 122 }
123 123 map.remove(msg.getKey());
124   -
125 124 }
126 125 }
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
... ... @@ -32,6 +32,7 @@ import org.springframework.beans.factory.annotation.Autowired;
32 32 import org.springframework.beans.factory.annotation.Qualifier;
33 33 import org.springframework.context.annotation.DependsOn;
34 34 import org.springframework.stereotype.Component;
  35 +import org.springframework.util.ObjectUtils;
35 36 import org.springframework.util.StringUtils;
36 37  
37 38 import javax.sip.*;
... ... @@ -856,7 +857,7 @@ public class SIPCommander implements ISIPCommander {
856 857 cmdXml.append("<Control>\r\n");
857 858 cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
858 859 cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
859   - if (StringUtils.isEmpty(channelId)) {
  860 + if (ObjectUtils.isEmpty(channelId)) {
860 861 cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
861 862 } else {
862 863 cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
... ... @@ -959,16 +960,16 @@ public class SIPCommander implements ISIPCommander {
959 960 cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
960 961 cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
961 962 cmdXml.append("<AlarmCmd>ResetAlarm</AlarmCmd>\r\n");
962   - if (!StringUtils.isEmpty(alarmMethod) || !StringUtils.isEmpty(alarmType)) {
  963 + if (!ObjectUtils.isEmpty(alarmMethod) || !ObjectUtils.isEmpty(alarmType)) {
963 964 cmdXml.append("<Info>\r\n");
964 965 }
965   - if (!StringUtils.isEmpty(alarmMethod)) {
  966 + if (!ObjectUtils.isEmpty(alarmMethod)) {
966 967 cmdXml.append("<AlarmMethod>" + alarmMethod + "</AlarmMethod>\r\n");
967 968 }
968   - if (!StringUtils.isEmpty(alarmType)) {
  969 + if (!ObjectUtils.isEmpty(alarmType)) {
969 970 cmdXml.append("<AlarmType>" + alarmType + "</AlarmType>\r\n");
970 971 }
971   - if (!StringUtils.isEmpty(alarmMethod) || !StringUtils.isEmpty(alarmType)) {
  972 + if (!ObjectUtils.isEmpty(alarmMethod) || !ObjectUtils.isEmpty(alarmType)) {
972 973 cmdXml.append("</Info>\r\n");
973 974 }
974 975 cmdXml.append("</Control>\r\n");
... ... @@ -1002,7 +1003,7 @@ public class SIPCommander implements ISIPCommander {
1002 1003 cmdXml.append("<Control>\r\n");
1003 1004 cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
1004 1005 cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
1005   - if (StringUtils.isEmpty(channelId)) {
  1006 + if (ObjectUtils.isEmpty(channelId)) {
1006 1007 cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
1007 1008 } else {
1008 1009 cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
... ... @@ -1041,7 +1042,7 @@ public class SIPCommander implements ISIPCommander {
1041 1042 cmdXml.append("<Control>\r\n");
1042 1043 cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
1043 1044 cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
1044   - if (StringUtils.isEmpty(channelId)) {
  1045 + if (ObjectUtils.isEmpty(channelId)) {
1045 1046 cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
1046 1047 } else {
1047 1048 cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
... ... @@ -1110,13 +1111,13 @@ public class SIPCommander implements ISIPCommander {
1110 1111 cmdXml.append("<Control>\r\n");
1111 1112 cmdXml.append("<CmdType>DeviceConfig</CmdType>\r\n");
1112 1113 cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
1113   - if (StringUtils.isEmpty(channelId)) {
  1114 + if (ObjectUtils.isEmpty(channelId)) {
1114 1115 cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
1115 1116 } else {
1116 1117 cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
1117 1118 }
1118 1119 cmdXml.append("<BasicParam>\r\n");
1119   - if (!StringUtils.isEmpty(name)) {
  1120 + if (!ObjectUtils.isEmpty(name)) {
1120 1121 cmdXml.append("<Name>" + name + "</Name>\r\n");
1121 1122 }
1122 1123 if (NumericUtil.isInteger(expiration)) {
... ... @@ -1326,22 +1327,22 @@ public class SIPCommander implements ISIPCommander {
1326 1327 cmdXml.append("<CmdType>Alarm</CmdType>\r\n");
1327 1328 cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
1328 1329 cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
1329   - if (!StringUtils.isEmpty(startPriority)) {
  1330 + if (!ObjectUtils.isEmpty(startPriority)) {
1330 1331 cmdXml.append("<StartAlarmPriority>" + startPriority + "</StartAlarmPriority>\r\n");
1331 1332 }
1332   - if (!StringUtils.isEmpty(endPriority)) {
  1333 + if (!ObjectUtils.isEmpty(endPriority)) {
1333 1334 cmdXml.append("<EndAlarmPriority>" + endPriority + "</EndAlarmPriority>\r\n");
1334 1335 }
1335   - if (!StringUtils.isEmpty(alarmMethod)) {
  1336 + if (!ObjectUtils.isEmpty(alarmMethod)) {
1336 1337 cmdXml.append("<AlarmMethod>" + alarmMethod + "</AlarmMethod>\r\n");
1337 1338 }
1338   - if (!StringUtils.isEmpty(alarmType)) {
  1339 + if (!ObjectUtils.isEmpty(alarmType)) {
1339 1340 cmdXml.append("<AlarmType>" + alarmType + "</AlarmType>\r\n");
1340 1341 }
1341   - if (!StringUtils.isEmpty(startTime)) {
  1342 + if (!ObjectUtils.isEmpty(startTime)) {
1342 1343 cmdXml.append("<StartAlarmTime>" + startTime + "</StartAlarmTime>\r\n");
1343 1344 }
1344   - if (!StringUtils.isEmpty(endTime)) {
  1345 + if (!ObjectUtils.isEmpty(endTime)) {
1345 1346 cmdXml.append("<EndAlarmTime>" + endTime + "</EndAlarmTime>\r\n");
1346 1347 }
1347 1348 cmdXml.append("</Query>\r\n");
... ... @@ -1376,7 +1377,7 @@ public class SIPCommander implements ISIPCommander {
1376 1377 cmdXml.append("<Query>\r\n");
1377 1378 cmdXml.append("<CmdType>ConfigDownload</CmdType>\r\n");
1378 1379 cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
1379   - if (StringUtils.isEmpty(channelId)) {
  1380 + if (ObjectUtils.isEmpty(channelId)) {
1380 1381 cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
1381 1382 } else {
1382 1383 cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
... ... @@ -1412,7 +1413,7 @@ public class SIPCommander implements ISIPCommander {
1412 1413 cmdXml.append("<Query>\r\n");
1413 1414 cmdXml.append("<CmdType>PresetQuery</CmdType>\r\n");
1414 1415 cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
1415   - if (StringUtils.isEmpty(channelId)) {
  1416 + if (ObjectUtils.isEmpty(channelId)) {
1416 1417 cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
1417 1418 } else {
1418 1419 cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
... ... @@ -1543,22 +1544,22 @@ public class SIPCommander implements ISIPCommander {
1543 1544 cmdXml.append("<CmdType>Alarm</CmdType>\r\n");
1544 1545 cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
1545 1546 cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
1546   - if (!StringUtils.isEmpty(startPriority)) {
  1547 + if (!ObjectUtils.isEmpty(startPriority)) {
1547 1548 cmdXml.append("<StartAlarmPriority>" + startPriority + "</StartAlarmPriority>\r\n");
1548 1549 }
1549   - if (!StringUtils.isEmpty(endPriority)) {
  1550 + if (!ObjectUtils.isEmpty(endPriority)) {
1550 1551 cmdXml.append("<EndAlarmPriority>" + endPriority + "</EndAlarmPriority>\r\n");
1551 1552 }
1552   - if (!StringUtils.isEmpty(alarmMethod)) {
  1553 + if (!ObjectUtils.isEmpty(alarmMethod)) {
1553 1554 cmdXml.append("<AlarmMethod>" + alarmMethod + "</AlarmMethod>\r\n");
1554 1555 }
1555   - if (!StringUtils.isEmpty(alarmType)) {
  1556 + if (!ObjectUtils.isEmpty(alarmType)) {
1556 1557 cmdXml.append("<AlarmType>" + alarmType + "</AlarmType>\r\n");
1557 1558 }
1558   - if (!StringUtils.isEmpty(startTime)) {
  1559 + if (!ObjectUtils.isEmpty(startTime)) {
1559 1560 cmdXml.append("<StartAlarmTime>" + startTime + "</StartAlarmTime>\r\n");
1560 1561 }
1561   - if (!StringUtils.isEmpty(endTime)) {
  1562 + if (!ObjectUtils.isEmpty(endTime)) {
1562 1563 cmdXml.append("<EndAlarmTime>" + endTime + "</EndAlarmTime>\r\n");
1563 1564 }
1564 1565 cmdXml.append("</Query>\r\n");
... ... @@ -1639,7 +1640,7 @@ public class SIPCommander implements ISIPCommander {
1639 1640 dragXml.append("<Control>\r\n");
1640 1641 dragXml.append("<CmdType>DeviceControl</CmdType>\r\n");
1641 1642 dragXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
1642   - if (StringUtils.isEmpty(channelId)) {
  1643 + if (ObjectUtils.isEmpty(channelId)) {
1643 1644 dragXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
1644 1645 } else {
1645 1646 dragXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java
... ... @@ -24,6 +24,7 @@ import org.springframework.context.annotation.DependsOn;
24 24 import org.springframework.context.annotation.Lazy;
25 25 import org.springframework.lang.Nullable;
26 26 import org.springframework.stereotype.Component;
  27 +import org.springframework.util.ObjectUtils;
27 28 import org.springframework.util.StringUtils;
28 29  
29 30 import javax.sip.*;
... ... @@ -728,10 +729,10 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
728 729 recordXml.append("<EndTime>" + DateUtil.yyyy_MM_dd_HH_mm_ssToISO8601(recordItem.getEndTime()) + "</EndTime>\r\n");
729 730 recordXml.append("<Secrecy>" + recordItem.getSecrecy() + "</Secrecy>\r\n");
730 731 recordXml.append("<Type>" + recordItem.getType() + "</Type>\r\n");
731   - if (!StringUtils.isEmpty(recordItem.getFileSize())) {
  732 + if (!ObjectUtils.isEmpty(recordItem.getFileSize())) {
732 733 recordXml.append("<FileSize>" + recordItem.getFileSize() + "</FileSize>\r\n");
733 734 }
734   - if (!StringUtils.isEmpty(recordItem.getFilePath())) {
  735 + if (!ObjectUtils.isEmpty(recordItem.getFilePath())) {
735 736 recordXml.append("<FilePath>" + recordItem.getFilePath() + "</FilePath>\r\n");
736 737 }
737 738 }
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java
... ... @@ -29,6 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired;
29 29 import org.springframework.beans.factory.annotation.Qualifier;
30 30 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
31 31 import org.springframework.stereotype.Component;
  32 +import org.springframework.util.ObjectUtils;
32 33 import org.springframework.util.StringUtils;
33 34  
34 35 import javax.sip.InvalidArgumentException;
... ... @@ -157,7 +158,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements
157 158 String channelId = deviceIdElement.getTextTrim().toString();
158 159 Device device = redisCatchStorage.getDevice(deviceId);
159 160 if (device != null) {
160   - if (!StringUtils.isEmpty(device.getName())) {
  161 + if (!ObjectUtils.isEmpty(device.getName())) {
161 162 mobilePosition.setDeviceName(device.getName());
162 163 }
163 164 }
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/RegisterRequestProcessor.java
... ... @@ -19,6 +19,7 @@ import org.slf4j.LoggerFactory;
19 19 import org.springframework.beans.factory.InitializingBean;
20 20 import org.springframework.beans.factory.annotation.Autowired;
21 21 import org.springframework.stereotype.Component;
  22 +import org.springframework.util.ObjectUtils;
22 23 import org.springframework.util.StringUtils;
23 24  
24 25 import javax.sip.InvalidArgumentException;
... ... @@ -81,7 +82,7 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen
81 82 String deviceId = uri.getUser();
82 83  
83 84 AuthorizationHeader authHead = (AuthorizationHeader) request.getHeader(AuthorizationHeader.NAME);
84   - if (authHead == null && !StringUtils.isEmpty(sipConfig.getPassword())) {
  85 + if (authHead == null && !ObjectUtils.isEmpty(sipConfig.getPassword())) {
85 86 logger.info("[注册请求] 未携带授权头 回复401: {}", requestAddress);
86 87 response = getMessageFactory().createResponse(Response.UNAUTHORIZED, request);
87 88 new DigestServerAuthenticationHelper().generateChallenge(getHeaderFactory(), response, sipConfig.getDomain());
... ... @@ -90,7 +91,7 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen
90 91 }
91 92  
92 93 // 校验密码是否正确
93   - passwordCorrect = StringUtils.isEmpty(sipConfig.getPassword()) ||
  94 + passwordCorrect = ObjectUtils.isEmpty(sipConfig.getPassword()) ||
94 95 new DigestServerAuthenticationHelper().doAuthenticatePlainTextPassword(request, sipConfig.getPassword());
95 96  
96 97 if (!passwordCorrect) {
... ... @@ -132,7 +133,7 @@ public class RegisterRequestProcessor extends SIPRequestProcessorParent implemen
132 133 String received = viaHeader.getReceived();
133 134 int rPort = viaHeader.getRPort();
134 135 // 解析本地地址替代
135   - if (StringUtils.isEmpty(received) || rPort == -1) {
  136 + if (ObjectUtils.isEmpty(received) || rPort == -1) {
136 137 received = viaHeader.getHost();
137 138 rPort = viaHeader.getPort();
138 139 }
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/control/cmd/DeviceControlQueryMessageHandler.java
... ... @@ -17,6 +17,7 @@ import org.slf4j.LoggerFactory;
17 17 import org.springframework.beans.factory.InitializingBean;
18 18 import org.springframework.beans.factory.annotation.Autowired;
19 19 import org.springframework.stereotype.Component;
  20 +import org.springframework.util.ObjectUtils;
20 21 import org.springframework.util.StringUtils;
21 22  
22 23 import javax.sip.*;
... ... @@ -64,7 +65,7 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent
64 65 String targetGBId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(ToHeader.NAME)).getAddress().getURI()).getUser();
65 66 String channelId = getText(rootElement, "DeviceID");
66 67 // 远程启动功能
67   - if (!StringUtils.isEmpty(getText(rootElement, "TeleBoot"))) {
  68 + if (!ObjectUtils.isEmpty(getText(rootElement, "TeleBoot"))) {
68 69 if (parentPlatform.getServerGBId().equals(targetGBId)) {
69 70 // 远程启动本平台:需要在重新启动程序后先对SipStack解绑
70 71 logger.info("执行远程启动本平台命令");
... ... @@ -101,7 +102,7 @@ public class DeviceControlQueryMessageHandler extends SIPRequestProcessorParent
101 102 }
102 103 }
103 104 // 云台/前端控制命令
104   - if (!StringUtils.isEmpty(getText(rootElement,"PTZCmd")) && !parentPlatform.getServerGBId().equals(targetGBId)) {
  105 + if (!ObjectUtils.isEmpty(getText(rootElement,"PTZCmd")) && !parentPlatform.getServerGBId().equals(targetGBId)) {
105 106 String cmdString = getText(rootElement,"PTZCmd");
106 107 Device deviceForPlatform = storager.queryVideoDeviceByPlatformIdAndChannelId(parentPlatform.getServerGBId(), channelId);
107 108 if (deviceForPlatform == null) {
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java
... ... @@ -22,6 +22,7 @@ import org.slf4j.LoggerFactory;
22 22 import org.springframework.beans.factory.InitializingBean;
23 23 import org.springframework.beans.factory.annotation.Autowired;
24 24 import org.springframework.stereotype.Component;
  25 +import org.springframework.util.ObjectUtils;
25 26 import org.springframework.util.StringUtils;
26 27  
27 28 import javax.sip.InvalidArgumentException;
... ... @@ -114,7 +115,7 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme
114 115 deviceAlarm.setLatitude(0.00);
115 116 }
116 117  
117   - if (!StringUtils.isEmpty(deviceAlarm.getAlarmMethod())) {
  118 + if (!ObjectUtils.isEmpty(deviceAlarm.getAlarmMethod())) {
118 119 if ( deviceAlarm.getAlarmMethod().contains(DeviceAlarmMethod.GPS.getVal() + "")) {
119 120 MobilePosition mobilePosition = new MobilePosition();
120 121 mobilePosition.setCreateTime(DateUtil.getNow());
... ... @@ -157,7 +158,7 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme
157 158 redisCatchStorage.sendMobilePositionMsg(jsonObject);
158 159 }
159 160 }
160   - if (!StringUtils.isEmpty(deviceAlarm.getDeviceId())) {
  161 + if (!ObjectUtils.isEmpty(deviceAlarm.getDeviceId())) {
161 162 if (deviceAlarm.getAlarmMethod().contains(DeviceAlarmMethod.Video.getVal() + "")) {
162 163 deviceAlarm.setAlarmType(getText(rootElement.element("Info"), "AlarmType"));
163 164 }
... ... @@ -231,7 +232,7 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme
231 232 deviceAlarm.setLatitude(0.00);
232 233 }
233 234  
234   - if (!StringUtils.isEmpty(deviceAlarm.getAlarmMethod())) {
  235 + if (!ObjectUtils.isEmpty(deviceAlarm.getAlarmMethod())) {
235 236  
236 237 if (deviceAlarm.getAlarmMethod().contains(DeviceAlarmMethod.Video.getVal() + "")) {
237 238 deviceAlarm.setAlarmType(getText(rootElement.element("Info"), "AlarmType"));
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/KeepaliveNotifyMessageHandler.java
... ... @@ -16,6 +16,7 @@ import org.slf4j.LoggerFactory;
16 16 import org.springframework.beans.factory.InitializingBean;
17 17 import org.springframework.beans.factory.annotation.Autowired;
18 18 import org.springframework.stereotype.Component;
  19 +import org.springframework.util.ObjectUtils;
19 20 import org.springframework.util.StringUtils;
20 21  
21 22 import javax.sip.InvalidArgumentException;
... ... @@ -58,7 +59,7 @@ public class KeepaliveNotifyMessageHandler extends SIPRequestProcessorParent imp
58 59 String received = viaHeader.getReceived();
59 60 int rPort = viaHeader.getRPort();
60 61 // 解析本地地址替代
61   - if (StringUtils.isEmpty(received) || rPort == -1) {
  62 + if (ObjectUtils.isEmpty(received) || rPort == -1) {
62 63 received = viaHeader.getHost();
63 64 rPort = viaHeader.getPort();
64 65 }
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MobilePositionNotifyMessageHandler.java
... ... @@ -18,6 +18,7 @@ import org.slf4j.LoggerFactory;
18 18 import org.springframework.beans.factory.InitializingBean;
19 19 import org.springframework.beans.factory.annotation.Autowired;
20 20 import org.springframework.stereotype.Component;
  21 +import org.springframework.util.ObjectUtils;
21 22 import org.springframework.util.StringUtils;
22 23  
23 24 import javax.sip.InvalidArgumentException;
... ... @@ -69,7 +70,7 @@ public class MobilePositionNotifyMessageHandler extends SIPRequestProcessorParen
69 70 }
70 71 MobilePosition mobilePosition = new MobilePosition();
71 72 mobilePosition.setCreateTime(DateUtil.getNow());
72   - if (!StringUtils.isEmpty(device.getName())) {
  73 + if (!ObjectUtils.isEmpty(device.getName())) {
73 74 mobilePosition.setDeviceName(device.getName());
74 75 }
75 76 mobilePosition.setDeviceId(device.getDeviceId());
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/DeviceInfoResponseMessageHandler.java
... ... @@ -20,6 +20,7 @@ import org.slf4j.LoggerFactory;
20 20 import org.springframework.beans.factory.InitializingBean;
21 21 import org.springframework.beans.factory.annotation.Autowired;
22 22 import org.springframework.stereotype.Component;
  23 +import org.springframework.util.ObjectUtils;
23 24 import org.springframework.util.StringUtils;
24 25  
25 26 import javax.sip.InvalidArgumentException;
... ... @@ -88,7 +89,7 @@ public class DeviceInfoResponseMessageHandler extends SIPRequestProcessorParent
88 89 device.setManufacturer(getText(rootElement, "Manufacturer"));
89 90 device.setModel(getText(rootElement, "Model"));
90 91 device.setFirmware(getText(rootElement, "Firmware"));
91   - if (StringUtils.isEmpty(device.getStreamMode())) {
  92 + if (ObjectUtils.isEmpty(device.getStreamMode())) {
92 93 device.setStreamMode("UDP");
93 94 }
94 95 deviceService.updateDevice(device);
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/MobilePositionResponseMessageHandler.java
... ... @@ -20,6 +20,7 @@ import org.slf4j.LoggerFactory;
20 20 import org.springframework.beans.factory.InitializingBean;
21 21 import org.springframework.beans.factory.annotation.Autowired;
22 22 import org.springframework.stereotype.Component;
  23 +import org.springframework.util.ObjectUtils;
23 24 import org.springframework.util.StringUtils;
24 25  
25 26 import javax.sip.InvalidArgumentException;
... ... @@ -72,7 +73,7 @@ public class MobilePositionResponseMessageHandler extends SIPRequestProcessorPar
72 73 }
73 74 MobilePosition mobilePosition = new MobilePosition();
74 75 mobilePosition.setCreateTime(DateUtil.getNow());
75   - if (!StringUtils.isEmpty(device.getName())) {
  76 + if (!ObjectUtils.isEmpty(device.getName())) {
76 77 mobilePosition.setDeviceName(device.getName());
77 78 }
78 79 mobilePosition.setDeviceId(device.getDeviceId());
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/RecordInfoResponseMessageHandler.java
... ... @@ -19,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
19 19 import org.springframework.beans.factory.annotation.Qualifier;
20 20 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
21 21 import org.springframework.stereotype.Component;
  22 +import org.springframework.util.ObjectUtils;
22 23 import org.springframework.util.StringUtils;
23 24  
24 25 import javax.sip.InvalidArgumentException;
... ... @@ -93,7 +94,7 @@ public class RecordInfoResponseMessageHandler extends SIPRequestProcessorParent
93 94 recordInfo.setName(getText(rootElementForCharset, "Name"));
94 95 String sumNumStr = getText(rootElementForCharset, "SumNum");
95 96 int sumNum = 0;
96   - if (!StringUtils.isEmpty(sumNumStr)) {
  97 + if (!ObjectUtils.isEmpty(sumNumStr)) {
97 98 sumNum = Integer.parseInt(sumNumStr);
98 99 }
99 100 recordInfo.setSumNum(sumNum);
... ... @@ -172,16 +173,12 @@ public class RecordInfoResponseMessageHandler extends SIPRequestProcessorParent
172 173  
173 174 public void releaseRequest(String deviceId, String sn){
174 175 String key = DeferredResultHolder.CALLBACK_CMD_RECORDINFO + deviceId + sn;
175   - WVPResult<RecordInfo> wvpResult = new WVPResult<>();
176   - wvpResult.setCode(0);
177   - wvpResult.setMsg("success");
178 176 // 对数据进行排序
179 177 Collections.sort(recordDataCatch.getRecordInfo(deviceId, sn).getRecordList());
180   - wvpResult.setData(recordDataCatch.getRecordInfo(deviceId, sn));
181 178  
182 179 RequestMessage msg = new RequestMessage();
183 180 msg.setKey(key);
184   - msg.setData(wvpResult);
  181 + msg.setData(recordDataCatch.getRecordInfo(deviceId, sn));
185 182 deferredResultHolder.invokeAllResult(msg);
186 183 recordDataCatch.remove(deviceId, sn);
187 184 }
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java
... ... @@ -14,6 +14,7 @@ import org.dom4j.Element;
14 14 import org.dom4j.io.SAXReader;
15 15 import org.slf4j.Logger;
16 16 import org.slf4j.LoggerFactory;
  17 +import org.springframework.util.ObjectUtils;
17 18 import org.springframework.util.StringUtils;
18 19  
19 20 import javax.sip.RequestEvent;
... ... @@ -118,12 +119,12 @@ public class XmlUtil {
118 119 // 如果是属性
119 120 for (Object o : element.attributes()) {
120 121 Attribute attr = (Attribute) o;
121   - if (!StringUtils.isEmpty(attr.getValue())) {
  122 + if (!ObjectUtils.isEmpty(attr.getValue())) {
122 123 json.put("@" + attr.getName(), attr.getValue());
123 124 }
124 125 }
125 126 List<Element> chdEl = element.elements();
126   - if (chdEl.isEmpty() && !StringUtils.isEmpty(element.getText())) {// 如果没有子元素,只有一个值
  127 + if (chdEl.isEmpty() && !ObjectUtils.isEmpty(element.getText())) {// 如果没有子元素,只有一个值
127 128 json.put(element.getName(), element.getText());
128 129 }
129 130  
... ... @@ -154,7 +155,7 @@ public class XmlUtil {
154 155 } else { // 子元素没有子元素
155 156 for (Object o : element.attributes()) {
156 157 Attribute attr = (Attribute) o;
157   - if (!StringUtils.isEmpty(attr.getValue())) {
  158 + if (!ObjectUtils.isEmpty(attr.getValue())) {
158 159 json.put("@" + attr.getName(), attr.getValue());
159 160 }
160 161 }
... ... @@ -197,7 +198,7 @@ public class XmlUtil {
197 198 return null;
198 199 }
199 200 String channelId = channdelIdElement.getTextTrim();
200   - if (StringUtils.isEmpty(channelId)) {
  201 + if (ObjectUtils.isEmpty(channelId)) {
201 202 logger.warn("解析Catalog消息时发现缺少 DeviceID");
202 203 return null;
203 204 }
... ... @@ -316,7 +317,7 @@ public class XmlUtil {
316 317 // 识别自带的目录标识
317 318 String parental = XmlUtil.getText(itemDevice, "Parental");
318 319 // 由于海康会错误的发送65535作为这里的取值,所以这里除非是0否则认为是1
319   - if (!StringUtils.isEmpty(parental) && parental.length() == 1 && Integer.parseInt(parental) == 0) {
  320 + if (!ObjectUtils.isEmpty(parental) && parental.length() == 1 && Integer.parseInt(parental) == 0) {
320 321 deviceChannel.setParental(0);
321 322 }else {
322 323 deviceChannel.setParental(1);
... ... @@ -332,14 +333,14 @@ public class XmlUtil {
332 333 deviceChannel.setPassword(XmlUtil.getText(itemDevice, "Password"));
333 334  
334 335 String safetyWay = XmlUtil.getText(itemDevice, "SafetyWay");
335   - if (StringUtils.isEmpty(safetyWay)) {
  336 + if (ObjectUtils.isEmpty(safetyWay)) {
336 337 deviceChannel.setSafetyWay(0);
337 338 } else {
338 339 deviceChannel.setSafetyWay(Integer.parseInt(safetyWay));
339 340 }
340 341  
341 342 String registerWay = XmlUtil.getText(itemDevice, "RegisterWay");
342   - if (StringUtils.isEmpty(registerWay)) {
  343 + if (ObjectUtils.isEmpty(registerWay)) {
343 344 deviceChannel.setRegisterWay(1);
344 345 } else {
345 346 deviceChannel.setRegisterWay(Integer.parseInt(registerWay));
... ...
src/main/java/com/genersoft/iot/vmp/media/zlm/AssistRESTfulUtils.java
... ... @@ -9,6 +9,7 @@ import org.jetbrains.annotations.NotNull;
9 9 import org.slf4j.Logger;
10 10 import org.slf4j.LoggerFactory;
11 11 import org.springframework.stereotype.Component;
  12 +import org.springframework.util.ObjectUtils;
12 13 import org.springframework.util.StringUtils;
13 14  
14 15 import java.io.File;
... ... @@ -49,7 +50,7 @@ public class AssistRESTfulUtils {
49 50 if (mediaServerItem == null) {
50 51 return null;
51 52 }
52   - if (StringUtils.isEmpty(mediaServerItem.getRecordAssistPort())) {
  53 + if (ObjectUtils.isEmpty(mediaServerItem.getRecordAssistPort())) {
53 54 logger.warn("未启用Assist服务");
54 55 return null;
55 56 }
... ...
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
... ... @@ -22,6 +22,7 @@ import org.slf4j.LoggerFactory;
22 22 import org.springframework.beans.factory.annotation.Autowired;
23 23 import org.springframework.http.HttpStatus;
24 24 import org.springframework.http.ResponseEntity;
  25 +import org.springframework.util.ObjectUtils;
25 26 import org.springframework.util.StringUtils;
26 27 import org.springframework.web.bind.annotation.PostMapping;
27 28 import org.springframework.web.bind.annotation.RequestBody;
... ... @@ -633,7 +634,7 @@ public class ZLMHttpHookListener {
633 634  
634 635 private Map<String, String> urlParamToMap(String params) {
635 636 HashMap<String, String> map = new HashMap<>();
636   - if (StringUtils.isEmpty(params)) {
  637 + if (ObjectUtils.isEmpty(params)) {
637 638 return map;
638 639 }
639 640 String[] paramsArray = params.split("&");
... ...
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java
... ... @@ -9,6 +9,7 @@ import org.slf4j.Logger;
9 9 import org.slf4j.LoggerFactory;
10 10 import org.springframework.beans.factory.annotation.Autowired;
11 11 import org.springframework.stereotype.Component;
  12 +import org.springframework.util.ObjectUtils;
12 13 import org.springframework.util.StringUtils;
13 14  
14 15 import java.util.*;
... ... @@ -187,7 +188,7 @@ public class ZLMRTPServerFactory {
187 188  
188 189 // 使用RTPServer 功能找一个可用的端口
189 190 String sendRtpPortRange = serverItem.getSendRtpPortRange();
190   - if (StringUtils.isEmpty(sendRtpPortRange)) {
  191 + if (ObjectUtils.isEmpty(sendRtpPortRange)) {
191 192 return null;
192 193 }
193 194 String[] portRangeStrArray = serverItem.getSendRtpPortRange().split(",");
... ... @@ -229,7 +230,7 @@ public class ZLMRTPServerFactory {
229 230 public SendRtpItem createSendRtpItem(MediaServerItem serverItem, String ip, int port, String ssrc, String platformId, String app, String stream, String channelId, boolean tcp){
230 231 // 使用RTPServer 功能找一个可用的端口
231 232 String sendRtpPortRange = serverItem.getSendRtpPortRange();
232   - if (StringUtils.isEmpty(sendRtpPortRange)) {
  233 + if (ObjectUtils.isEmpty(sendRtpPortRange)) {
233 234 return null;
234 235 }
235 236 String[] portRangeStrArray = serverItem.getSendRtpPortRange().split(",");
... ...
src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaServerItem.java
... ... @@ -4,6 +4,7 @@ package com.genersoft.iot.vmp.media.zlm.dto;
4 4 import com.genersoft.iot.vmp.gb28181.session.SsrcConfig;
5 5 import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig;
6 6 import io.swagger.v3.oas.annotations.media.Schema;
  7 +import org.springframework.util.ObjectUtils;
7 8 import org.springframework.util.StringUtils;
8 9  
9 10 import java.util.HashMap;
... ... @@ -106,9 +107,9 @@ public class MediaServerItem{
106 107 public MediaServerItem(ZLMServerConfig zlmServerConfig, String sipIp) {
107 108 id = zlmServerConfig.getGeneralMediaServerId();
108 109 ip = zlmServerConfig.getIp();
109   - hookIp = StringUtils.isEmpty(zlmServerConfig.getHookIp())? sipIp: zlmServerConfig.getHookIp();
110   - sdpIp = StringUtils.isEmpty(zlmServerConfig.getSdpIp())? zlmServerConfig.getIp(): zlmServerConfig.getSdpIp();
111   - streamIp = StringUtils.isEmpty(zlmServerConfig.getStreamIp())? zlmServerConfig.getIp(): zlmServerConfig.getStreamIp();
  110 + hookIp = ObjectUtils.isEmpty(zlmServerConfig.getHookIp())? sipIp: zlmServerConfig.getHookIp();
  111 + sdpIp = ObjectUtils.isEmpty(zlmServerConfig.getSdpIp())? zlmServerConfig.getIp(): zlmServerConfig.getSdpIp();
  112 + streamIp = ObjectUtils.isEmpty(zlmServerConfig.getStreamIp())? zlmServerConfig.getIp(): zlmServerConfig.getStreamIp();
112 113 httpPort = zlmServerConfig.getHttpPort();
113 114 httpSSlPort = zlmServerConfig.getHttpSSLport();
114 115 rtmpPort = zlmServerConfig.getRtmpPort();
... ...
src/main/java/com/genersoft/iot/vmp/service/IMediaServerService.java
... ... @@ -64,7 +64,7 @@ public interface IMediaServerService {
64 64  
65 65 void clearMediaServerForOnline();
66 66  
67   - WVPResult<String> add(MediaServerItem mediaSerItem);
  67 + void add(MediaServerItem mediaSerItem);
68 68  
69 69 int addToDatabase(MediaServerItem mediaSerItem);
70 70  
... ... @@ -72,7 +72,7 @@ public interface IMediaServerService {
72 72  
73 73 void resetOnlineServerItem(MediaServerItem serverItem);
74 74  
75   - WVPResult<MediaServerItem> checkMediaServer(String ip, int port, String secret);
  75 + MediaServerItem checkMediaServer(String ip, int port, String secret);
76 76  
77 77 boolean checkMediaRecordServer(String ip, int port);
78 78  
... ...
src/main/java/com/genersoft/iot/vmp/service/IPlayService.java
... ... @@ -31,13 +31,13 @@ public interface IPlayService {
31 31  
32 32 void onPublishHandlerForDownload(InviteStreamInfo inviteStreamInfo, String deviceId, String channelId, String toString);
33 33  
34   - DeferredResult<ResponseEntity<String>> playBack(String deviceId, String channelId, String startTime, String endTime, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack);
35   - DeferredResult<ResponseEntity<String>> playBack(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo,String deviceId, String channelId, String startTime, String endTime, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack);
  34 + DeferredResult<String> playBack(String deviceId, String channelId, String startTime, String endTime, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack);
  35 + DeferredResult<String> playBack(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo,String deviceId, String channelId, String startTime, String endTime, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack);
36 36  
37 37 void zlmServerOffline(String mediaServerId);
38 38  
39   - DeferredResult<ResponseEntity<String>> download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack);
40   - DeferredResult<ResponseEntity<String>> download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo,String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack);
  39 + DeferredResult<String> download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack);
  40 + DeferredResult<String> download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo,String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack);
41 41  
42 42 StreamInfo getDownLoadInfo(String deviceId, String channelId, String stream);
43 43  
... ...
src/main/java/com/genersoft/iot/vmp/service/IStreamProxyService.java
... ... @@ -2,12 +2,8 @@ package com.genersoft.iot.vmp.service;
2 2  
3 3 import com.alibaba.fastjson.JSONObject;
4 4 import com.genersoft.iot.vmp.common.StreamInfo;
5   -import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig;
6   -import com.genersoft.iot.vmp.media.zlm.dto.MediaItem;
7 5 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
8 6 import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
9   -import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
10   -import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
11 7 import com.github.pagehelper.PageInfo;
12 8  
13 9 public interface IStreamProxyService {
... ... @@ -16,7 +12,7 @@ public interface IStreamProxyService {
16 12 * 保存视频代理
17 13 * @param param
18 14 */
19   - WVPResult<StreamInfo> save(StreamProxyItem param);
  15 + StreamInfo save(StreamProxyItem param);
20 16  
21 17 /**
22 18 * 添加视频代理到zlm
... ...
src/main/java/com/genersoft/iot/vmp/service/bean/PlayBackResult.java
... ... @@ -4,14 +4,18 @@ import com.alibaba.fastjson.JSONObject;
4 4 import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
5 5 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
6 6  
7   -import javax.sip.RequestEvent;
  7 +import java.util.EventObject;
8 8  
  9 +
  10 +/**
  11 + * @author lin
  12 + */
9 13 public class PlayBackResult<T> {
10 14 private int code;
11 15 private T data;
12 16 private MediaServerItem mediaServerItem;
13 17 private JSONObject response;
14   - private SipSubscribe.EventResult event;
  18 + private SipSubscribe.EventResult<EventObject> event;
15 19  
16 20 public int getCode() {
17 21 return code;
... ... @@ -45,11 +49,11 @@ public class PlayBackResult&lt;T&gt; {
45 49 this.response = response;
46 50 }
47 51  
48   - public SipSubscribe.EventResult getEvent() {
  52 + public SipSubscribe.EventResult<EventObject> getEvent() {
49 53 return event;
50 54 }
51 55  
52   - public void setEvent(SipSubscribe.EventResult event) {
  56 + public void setEvent(SipSubscribe.EventResult<EventObject> event) {
53 57 this.event = event;
54 58 }
55 59 }
... ...
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceServiceImpl.java
... ... @@ -23,6 +23,7 @@ import org.slf4j.LoggerFactory;
23 23 import org.springframework.beans.factory.annotation.Autowired;
24 24 import org.springframework.jdbc.support.incrementer.AbstractIdentityColumnMaxValueIncrementer;
25 25 import org.springframework.stereotype.Service;
  26 +import org.springframework.util.ObjectUtils;
26 27 import org.springframework.util.StringUtils;
27 28  
28 29 import java.time.Instant;
... ... @@ -282,13 +283,13 @@ public class DeviceServiceImpl implements IDeviceService {
282 283 logger.warn("更新设备时未找到设备信息");
283 284 return;
284 285 }
285   - if (!StringUtils.isEmpty(device.getName())) {
  286 + if (!ObjectUtils.isEmpty(device.getName())) {
286 287 deviceInStore.setName(device.getName());
287 288 }
288   - if (!StringUtils.isEmpty(device.getCharset())) {
  289 + if (!ObjectUtils.isEmpty(device.getCharset())) {
289 290 deviceInStore.setCharset(device.getCharset());
290 291 }
291   - if (!StringUtils.isEmpty(device.getMediaServerId())) {
  292 + if (!ObjectUtils.isEmpty(device.getMediaServerId())) {
292 293 deviceInStore.setMediaServerId(device.getMediaServerId());
293 294 }
294 295  
... ...
src/main/java/com/genersoft/iot/vmp/service/impl/GbStreamServiceImpl.java
... ... @@ -18,6 +18,7 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager;
18 18 import org.springframework.stereotype.Service;
19 19 import org.springframework.transaction.TransactionDefinition;
20 20 import org.springframework.transaction.TransactionStatus;
  21 +import org.springframework.util.ObjectUtils;
21 22 import org.springframework.util.StringUtils;
22 23  
23 24 import java.util.ArrayList;
... ... @@ -168,7 +169,7 @@ public class GbStreamServiceImpl implements IGbStreamService {
168 169 public void sendCatalogMsgs(List<GbStream> gbStreams, String type) {
169 170 if (gbStreams.size() > 0) {
170 171 for (GbStream gs : gbStreams) {
171   - if (StringUtils.isEmpty(gs.getGbId())){
  172 + if (ObjectUtils.isEmpty(gs.getGbId())){
172 173 continue;
173 174 }
174 175 List<ParentPlatform> parentPlatforms = platformGbStreamMapper.selectByAppAndStream(gs.getApp(), gs.getStream());
... ...
src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java
... ... @@ -8,6 +8,8 @@ import java.util.List;
8 8 import java.util.Map;
9 9 import java.util.Set;
10 10  
  11 +import com.genersoft.iot.vmp.conf.exception.ControllerException;
  12 +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
11 13 import org.slf4j.Logger;
12 14 import org.slf4j.LoggerFactory;
13 15 import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -16,6 +18,7 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager;
16 18 import org.springframework.stereotype.Service;
17 19 import org.springframework.transaction.TransactionDefinition;
18 20 import org.springframework.transaction.TransactionStatus;
  21 +import org.springframework.util.ObjectUtils;
19 22 import org.springframework.util.StringUtils;
20 23  
21 24 import com.alibaba.fastjson.JSON;
... ... @@ -91,7 +94,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
91 94 public void updateVmServer(List<MediaServerItem> mediaServerItemList) {
92 95 logger.info("[zlm] 缓存初始化 ");
93 96 for (MediaServerItem mediaServerItem : mediaServerItemList) {
94   - if (StringUtils.isEmpty(mediaServerItem.getId())) {
  97 + if (ObjectUtils.isEmpty(mediaServerItem.getId())) {
95 98 continue;
96 99 }
97 100 // 更新
... ... @@ -287,8 +290,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
287 290 }
288 291  
289 292 @Override
290   - public WVPResult<String> add(MediaServerItem mediaServerItem) {
291   - WVPResult<String> result = new WVPResult<>();
  293 + public void add(MediaServerItem mediaServerItem) {
292 294 mediaServerItem.setCreateTime(DateUtil.getNow());
293 295 mediaServerItem.setUpdateTime(DateUtil.getNow());
294 296 mediaServerItem.setHookAliveInterval(120);
... ... @@ -298,26 +300,19 @@ public class MediaServerServiceImpl implements IMediaServerService {
298 300 if (data != null && data.size() > 0) {
299 301 ZLMServerConfig zlmServerConfig= JSON.parseObject(JSON.toJSONString(data.get(0)), ZLMServerConfig.class);
300 302 if (mediaServerMapper.queryOne(zlmServerConfig.getGeneralMediaServerId()) != null) {
301   - result.setCode(-1);
302   - result.setMsg("保存失败,媒体服务ID [ " + zlmServerConfig.getGeneralMediaServerId() + " ] 已存在,请修改媒体服务器配置");
303   - return result;
  303 + throw new ControllerException(ErrorCode.ERROR100.getCode(),"保存失败,媒体服务ID [ " + zlmServerConfig.getGeneralMediaServerId() + " ] 已存在,请修改媒体服务器配置");
304 304 }
305 305 mediaServerItem.setId(zlmServerConfig.getGeneralMediaServerId());
306 306 zlmServerConfig.setIp(mediaServerItem.getIp());
307 307 mediaServerMapper.add(mediaServerItem);
308 308 zlmServerOnline(zlmServerConfig);
309   - result.setCode(0);
310   - result.setMsg("success");
311 309 }else {
312   - result.setCode(-1);
313   - result.setMsg("连接失败");
  310 + throw new ControllerException(ErrorCode.ERROR100.getCode(),"连接失败");
314 311 }
315 312  
316 313 }else {
317   - result.setCode(-1);
318   - result.setMsg("连接失败");
  314 + throw new ControllerException(ErrorCode.ERROR100.getCode(),"连接失败");
319 315 }
320   - return result;
321 316 }
322 317  
323 318 @Override
... ... @@ -385,7 +380,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
385 380 }
386 381 serverItem.setStatus(true);
387 382  
388   - if (StringUtils.isEmpty(serverItem.getId())) {
  383 + if (ObjectUtils.isEmpty(serverItem.getId())) {
389 384 logger.warn("[未注册的zlm] serverItem缺少ID, 无法接入:{}:{}", zlmServerConfig.getIp(),zlmServerConfig.getHttpPort() );
390 385 return;
391 386 }
... ... @@ -520,7 +515,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
520 515 // 最多等待未初始化的Track时间,单位毫秒,超时之后会忽略未初始化的Track, 设置此选项优化那些音频错误的不规范流,
521 516 // 等zlm支持给每个rtpServer设置关闭音频的时候可以不设置此选项
522 517 param.put("general.wait_track_ready_ms", "3000" );
523   - if (mediaServerItem.isRtpEnable() && !StringUtils.isEmpty(mediaServerItem.getRtpPortRange())) {
  518 + if (mediaServerItem.isRtpEnable() && !ObjectUtils.isEmpty(mediaServerItem.getRtpPortRange())) {
524 519 param.put("rtp_proxy.port_range", mediaServerItem.getRtpPortRange().replace(",", "-"));
525 520 }
526 521  
... ... @@ -547,12 +542,9 @@ public class MediaServerServiceImpl implements IMediaServerService {
547 542  
548 543  
549 544 @Override
550   - public WVPResult<MediaServerItem> checkMediaServer(String ip, int port, String secret) {
551   - WVPResult<MediaServerItem> result = new WVPResult<>();
  545 + public MediaServerItem checkMediaServer(String ip, int port, String secret) {
552 546 if (mediaServerMapper.queryOneByHostAndPort(ip, port) != null) {
553   - result.setCode(-1);
554   - result.setMsg("此连接已存在");
555   - return result;
  547 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "此连接已存在");
556 548 }
557 549 MediaServerItem mediaServerItem = new MediaServerItem();
558 550 mediaServerItem.setIp(ip);
... ... @@ -560,21 +552,15 @@ public class MediaServerServiceImpl implements IMediaServerService {
560 552 mediaServerItem.setSecret(secret);
561 553 JSONObject responseJSON = zlmresTfulUtils.getMediaServerConfig(mediaServerItem);
562 554 if (responseJSON == null) {
563   - result.setCode(-1);
564   - result.setMsg("连接失败");
565   - return result;
  555 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "连接失败");
566 556 }
567 557 JSONArray data = responseJSON.getJSONArray("data");
568 558 ZLMServerConfig zlmServerConfig = JSON.parseObject(JSON.toJSONString(data.get(0)), ZLMServerConfig.class);
569 559 if (zlmServerConfig == null) {
570   - result.setCode(-1);
571   - result.setMsg("读取配置失败");
572   - return result;
  560 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "读取配置失败");
573 561 }
574 562 if (mediaServerMapper.queryOne(zlmServerConfig.getGeneralMediaServerId()) != null) {
575   - result.setCode(-1);
576   - result.setMsg("媒体服务ID [" + zlmServerConfig.getGeneralMediaServerId() + " ] 已存在,请修改媒体服务器配置");
577   - return result;
  563 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "媒体服务ID [" + zlmServerConfig.getGeneralMediaServerId() + " ] 已存在,请修改媒体服务器配置");
578 564 }
579 565 mediaServerItem.setHttpSSlPort(zlmServerConfig.getHttpPort());
580 566 mediaServerItem.setRtmpPort(zlmServerConfig.getRtmpPort());
... ... @@ -586,10 +572,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
586 572 mediaServerItem.setHookIp(sipConfig.getIp());
587 573 mediaServerItem.setSdpIp(ip);
588 574 mediaServerItem.setStreamNoneReaderDelayMS(zlmServerConfig.getGeneralStreamNoneReaderDelayMS());
589   - result.setCode(0);
590   - result.setMsg("成功");
591   - result.setData(mediaServerItem);
592   - return result;
  575 + return mediaServerItem;
593 576 }
594 577  
595 578 @Override
... ...
src/main/java/com/genersoft/iot/vmp/service/impl/MediaServiceImpl.java
... ... @@ -15,6 +15,7 @@ import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
15 15 import com.genersoft.iot.vmp.service.IMediaService;
16 16 import org.springframework.beans.factory.annotation.Autowired;
17 17 import org.springframework.stereotype.Service;
  18 +import org.springframework.util.ObjectUtils;
18 19 import org.springframework.util.StringUtils;
19 20  
20 21 @Service
... ... @@ -94,7 +95,7 @@ public class MediaServiceImpl implements IMediaService {
94 95 }
95 96 streamInfoResult.setIp(addr);
96 97 streamInfoResult.setMediaServerId(mediaInfo.getId());
97   - String callIdParam = StringUtils.isEmpty(callId)?"":"?callId=" + callId;
  98 + String callIdParam = ObjectUtils.isEmpty(callId)?"":"?callId=" + callId;
98 99 streamInfoResult.setRtmp(String.format("rtmp://%s:%s/%s/%s%s", addr, mediaInfo.getRtmpPort(), app, stream, callIdParam));
99 100 if (mediaInfo.getRtmpSSlPort() != 0) {
100 101 streamInfoResult.setRtmps(String.format("rtmps://%s:%s/%s/%s%s", addr, mediaInfo.getRtmpSSlPort(), app, stream, callIdParam));
... ... @@ -121,7 +122,7 @@ public class MediaServiceImpl implements IMediaService {
121 122 streamInfoResult.setHttps_ts(String.format("https://%s:%s/%s/%s.live.ts%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam));
122 123 streamInfoResult.setWss_ts(String.format("wss://%s:%s/%s/%s.live.ts%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam));
123 124 streamInfoResult.setWss_ts(String.format("wss://%s:%s/%s/%s.live.ts%s", addr, mediaInfo.getHttpSSlPort(), app, stream, callIdParam));
124   - streamInfoResult.setRtc(String.format("https://%s:%s/index/api/webrtc?app=%s&stream=%s&type=play%s", mediaInfo.getStreamIp(), mediaInfo.getHttpSSlPort(), app, stream, StringUtils.isEmpty(callId)?"":"&callId=" + callId));
  125 + streamInfoResult.setRtc(String.format("https://%s:%s/index/api/webrtc?app=%s&stream=%s&type=play%s", mediaInfo.getStreamIp(), mediaInfo.getHttpSSlPort(), app, stream, ObjectUtils.isEmpty(callId)?"":"&callId=" + callId));
125 126 }
126 127  
127 128 streamInfoResult.setTracks(tracks);
... ...
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
... ... @@ -6,12 +6,12 @@ import java.util.*;
6 6  
7 7 import javax.sip.ResponseEvent;
8 8  
  9 +import com.genersoft.iot.vmp.conf.exception.ControllerException;
  10 +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
9 11 import org.slf4j.Logger;
10 12 import org.slf4j.LoggerFactory;
11 13 import org.springframework.beans.factory.annotation.Autowired;
12 14 import org.springframework.beans.factory.annotation.Qualifier;
13   -import org.springframework.http.HttpStatus;
14   -import org.springframework.http.ResponseEntity;
15 15 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
16 16 import org.springframework.stereotype.Service;
17 17 import org.springframework.web.context.request.async.DeferredResult;
... ... @@ -37,7 +37,6 @@ import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
37 37 import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
38 38 import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory;
39 39 import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange;
40   -import com.genersoft.iot.vmp.media.zlm.dto.HookType;
41 40 import com.genersoft.iot.vmp.utils.DateUtil;
42 41 import com.genersoft.iot.vmp.media.zlm.AssistRESTfulUtils;
43 42 import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe;
... ... @@ -52,7 +51,6 @@ import com.genersoft.iot.vmp.service.bean.PlayBackResult;
52 51 import com.genersoft.iot.vmp.service.bean.SSRCInfo;
53 52 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
54 53 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
55   -import com.genersoft.iot.vmp.utils.DateUtil;
56 54 import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
57 55 import com.genersoft.iot.vmp.vmanager.gb28181.play.bean.PlayResult;
58 56  
... ... @@ -114,6 +112,9 @@ public class PlayServiceImpl implements IPlayService {
114 112 public PlayResult play(MediaServerItem mediaServerItem, String deviceId, String channelId,
115 113 ZLMHttpHookSubscribe.Event hookEvent, SipSubscribe.Event errorEvent,
116 114 Runnable timeoutCallback) {
  115 + if (mediaServerItem == null) {
  116 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到可用的zlm");
  117 + }
117 118 PlayResult playResult = new PlayResult();
118 119 RequestMessage msg = new RequestMessage();
119 120 String key = DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId;
... ... @@ -121,18 +122,11 @@ public class PlayServiceImpl implements IPlayService {
121 122 String uuid = UUID.randomUUID().toString();
122 123 msg.setId(uuid);
123 124 playResult.setUuid(uuid);
124   - DeferredResult<ResponseEntity<String>> result = new DeferredResult<>(userSetting.getPlayTimeout().longValue());
  125 + DeferredResult<WVPResult<String>> result = new DeferredResult<>(userSetting.getPlayTimeout().longValue());
125 126 playResult.setResult(result);
126 127 // 录像查询以channelId作为deviceId查询
127 128 resultHolder.put(key, uuid, result);
128   - if (mediaServerItem == null) {
129   - WVPResult wvpResult = new WVPResult();
130   - wvpResult.setCode(-1);
131   - wvpResult.setMsg("未找到可用的zlm");
132   - msg.setData(wvpResult);
133   - resultHolder.invokeResult(msg);
134   - return playResult;
135   - }
  129 +
136 130 Device device = redisCatchStorage.getDevice(deviceId);
137 131 StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId);
138 132 playResult.setDevice(device);
... ... @@ -143,17 +137,14 @@ public class PlayServiceImpl implements IPlayService {
143 137 // TODO 应该在上流时调用更好,结束也可能是错误结束
144 138 String path = "snap";
145 139 String fileName = deviceId + "_" + channelId + ".jpg";
146   - ResponseEntity responseEntity = (ResponseEntity)result.getResult();
147   - if (responseEntity != null && responseEntity.getStatusCode() == HttpStatus.OK) {
148   - WVPResult wvpResult = (WVPResult)responseEntity.getBody();
149   - if (Objects.requireNonNull(wvpResult).getCode() == 0) {
150   - StreamInfo streamInfoForSuccess = (StreamInfo)wvpResult.getData();
151   - MediaServerItem mediaInfo = mediaServerService.getOne(streamInfoForSuccess.getMediaServerId());
152   - String streamUrl = streamInfoForSuccess.getFmp4();
153   - // 请求截图
154   - logger.info("[请求截图]: " + fileName);
155   - zlmresTfulUtils.getSnap(mediaInfo, streamUrl, 15, 1, path, fileName);
156   - }
  140 + WVPResult wvpResult = (WVPResult)result.getResult();
  141 + if (Objects.requireNonNull(wvpResult).getCode() == 0) {
  142 + StreamInfo streamInfoForSuccess = (StreamInfo)wvpResult.getData();
  143 + MediaServerItem mediaInfo = mediaServerService.getOne(streamInfoForSuccess.getMediaServerId());
  144 + String streamUrl = streamInfoForSuccess.getFmp4();
  145 + // 请求截图
  146 + logger.info("[请求截图]: " + fileName);
  147 + zlmresTfulUtils.getSnap(mediaInfo, streamUrl, 15, 1, path, fileName);
157 148 }
158 149 });
159 150 });
... ... @@ -161,7 +152,7 @@ public class PlayServiceImpl implements IPlayService {
161 152 String streamId = streamInfo.getStream();
162 153 if (streamId == null) {
163 154 WVPResult wvpResult = new WVPResult();
164   - wvpResult.setCode(-1);
  155 + wvpResult.setCode(ErrorCode.ERROR100.getCode());
165 156 wvpResult.setMsg("点播失败, redis缓存streamId等于null");
166 157 msg.setData(wvpResult);
167 158 resultHolder.invokeAllResult(msg);
... ... @@ -175,8 +166,8 @@ public class PlayServiceImpl implements IPlayService {
175 166 if (rtpInfo.getBoolean("exist")) {
176 167  
177 168 WVPResult wvpResult = new WVPResult();
178   - wvpResult.setCode(0);
179   - wvpResult.setMsg("success");
  169 + wvpResult.setCode(ErrorCode.SUCCESS.getCode());
  170 + wvpResult.setMsg(ErrorCode.SUCCESS.getMsg());
180 171 wvpResult.setData(streamInfo);
181 172 msg.setData(wvpResult);
182 173  
... ... @@ -211,7 +202,7 @@ public class PlayServiceImpl implements IPlayService {
211 202 }, event -> {
212 203 // sip error错误
213 204 WVPResult wvpResult = new WVPResult();
214   - wvpResult.setCode(-1);
  205 + wvpResult.setCode(ErrorCode.ERROR100.getCode());
215 206 wvpResult.setMsg(String.format("点播失败, 错误码: %s, %s", event.statusCode, event.msg));
216 207 msg.setData(wvpResult);
217 208 resultHolder.invokeAllResult(msg);
... ... @@ -221,7 +212,7 @@ public class PlayServiceImpl implements IPlayService {
221 212 }, (code, msgStr)->{
222 213 // invite点播超时
223 214 WVPResult wvpResult = new WVPResult();
224   - wvpResult.setCode(-1);
  215 + wvpResult.setCode(ErrorCode.ERROR100.getCode());
225 216 if (code == 0) {
226 217 wvpResult.setMsg("点播超时,请稍候重试");
227 218 }else if (code == 1) {
... ... @@ -361,15 +352,15 @@ public class PlayServiceImpl implements IPlayService {
361 352 redisCatchStorage.startPlay(streamInfo);
362 353  
363 354 WVPResult wvpResult = new WVPResult();
364   - wvpResult.setCode(0);
365   - wvpResult.setMsg("success");
  355 + wvpResult.setCode(ErrorCode.SUCCESS.getCode());
  356 + wvpResult.setMsg(ErrorCode.SUCCESS.getMsg());
366 357 wvpResult.setData(streamInfo);
367 358 msg.setData(wvpResult);
368 359  
369 360 resultHolder.invokeAllResult(msg);
370 361 } else {
371 362 logger.warn("设备预览API调用失败!");
372   - msg.setData("设备预览API调用失败!");
  363 + msg.setData(WVPResult.fail(ErrorCode.ERROR100.getCode(), "设备预览API调用失败!"));
373 364 resultHolder.invokeAllResult(msg);
374 365 }
375 366 }
... ... @@ -393,7 +384,7 @@ public class PlayServiceImpl implements IPlayService {
393 384 }
394 385  
395 386 @Override
396   - public DeferredResult<ResponseEntity<String>> playBack(String deviceId, String channelId, String startTime,
  387 + public DeferredResult<String> playBack(String deviceId, String channelId, String startTime,
397 388 String endTime,InviteStreamCallback inviteStreamCallback,
398 389 PlayBackCallback callback) {
399 390 Device device = storager.queryVideoDevice(deviceId);
... ... @@ -407,7 +398,7 @@ public class PlayServiceImpl implements IPlayService {
407 398 }
408 399  
409 400 @Override
410   - public DeferredResult<ResponseEntity<String>> playBack(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo,
  401 + public DeferredResult<String> playBack(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo,
411 402 String deviceId, String channelId, String startTime,
412 403 String endTime, InviteStreamCallback infoCallBack,
413 404 PlayBackCallback playBackCallback) {
... ... @@ -416,24 +407,21 @@ public class PlayServiceImpl implements IPlayService {
416 407 }
417 408 String uuid = UUID.randomUUID().toString();
418 409 String key = DeferredResultHolder.CALLBACK_CMD_PLAYBACK + deviceId + channelId;
419   - DeferredResult<ResponseEntity<String>> result = new DeferredResult<>(30000L);
420 410 Device device = storager.queryVideoDevice(deviceId);
421 411 if (device == null) {
422   - result.setResult(new ResponseEntity<>(HttpStatus.BAD_REQUEST));
423   - return result;
  412 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "设备: " + deviceId + "不存在");
424 413 }
425   -
  414 + DeferredResult<String> result = new DeferredResult<>(30000L);
426 415 resultHolder.put(DeferredResultHolder.CALLBACK_CMD_PLAYBACK + deviceId + channelId, uuid, result);
427   - RequestMessage msg = new RequestMessage();
428   - msg.setId(uuid);
429   - msg.setKey(key);
  416 + RequestMessage requestMessage = new RequestMessage();
  417 + requestMessage.setId(uuid);
  418 + requestMessage.setKey(key);
430 419 PlayBackResult<RequestMessage> playBackResult = new PlayBackResult<>();
431   - String playBackTimeOutTaskKey = UUID.randomUUID().toString();
  420 + String playBackTimeOutTaskKey = UUID.randomUUID().toString();
432 421 dynamicTask.startDelay(playBackTimeOutTaskKey, ()->{
433 422 logger.warn(String.format("设备回放超时,deviceId:%s ,channelId:%s", deviceId, channelId));
434 423 playBackResult.setCode(-1);
435   - playBackResult.setData(msg);
436   - playBackCallback.call(playBackResult);
  424 + playBackResult.setData(requestMessage);
437 425 SIPDialog dialog = streamSession.getDialogByStream(deviceId, channelId, ssrcInfo.getStream());
438 426 // 点播超时回复BYE 同时释放ssrc以及此次点播的资源
439 427 if (dialog != null) {
... ... @@ -456,24 +444,23 @@ public class PlayServiceImpl implements IPlayService {
456 444 StreamInfo streamInfo = onPublishHandler(inviteStreamInfo.getMediaServerItem(), inviteStreamInfo.getResponse(), deviceId, channelId);
457 445 if (streamInfo == null) {
458 446 logger.warn("设备回放API调用失败!");
459   - msg.setData("设备回放API调用失败!");
460 447 playBackResult.setCode(-1);
461   - playBackResult.setData(msg);
462 448 playBackCallback.call(playBackResult);
463 449 return;
464 450 }
465 451 redisCatchStorage.startPlayback(streamInfo, inviteStreamInfo.getCallId());
466   - msg.setData(JSON.toJSONString(streamInfo));
  452 + WVPResult<StreamInfo> success = WVPResult.success(streamInfo);
  453 + requestMessage.setData(success);
467 454 playBackResult.setCode(0);
468   - playBackResult.setData(msg);
  455 + playBackResult.setData(requestMessage);
469 456 playBackResult.setMediaServerItem(inviteStreamInfo.getMediaServerItem());
470 457 playBackResult.setResponse(inviteStreamInfo.getResponse());
471 458 playBackCallback.call(playBackResult);
472 459 }, event -> {
473 460 dynamicTask.stop(playBackTimeOutTaskKey);
474   - msg.setData(String.format("回放失败, 错误码: %s, %s", event.statusCode, event.msg));
  461 + requestMessage.setData(WVPResult.fail(ErrorCode.ERROR100.getCode(), String.format("回放失败, 错误码: %s, %s", event.statusCode, event.msg)));
475 462 playBackResult.setCode(-1);
476   - playBackResult.setData(msg);
  463 + playBackResult.setData(requestMessage);
477 464 playBackResult.setEvent(event);
478 465 playBackCallback.call(playBackResult);
479 466 streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream());
... ... @@ -482,7 +469,7 @@ public class PlayServiceImpl implements IPlayService {
482 469 }
483 470  
484 471 @Override
485   - public DeferredResult<ResponseEntity<String>> download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack) {
  472 + public DeferredResult<String> download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack) {
486 473 Device device = storager.queryVideoDevice(deviceId);
487 474 if (device == null) {
488 475 return null;
... ... @@ -494,32 +481,31 @@ public class PlayServiceImpl implements IPlayService {
494 481 }
495 482  
496 483 @Override
497   - public DeferredResult<ResponseEntity<String>> download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack) {
  484 + public DeferredResult<String> download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack) {
498 485 if (mediaServerItem == null || ssrcInfo == null) {
499 486 return null;
500 487 }
501 488 String uuid = UUID.randomUUID().toString();
502 489 String key = DeferredResultHolder.CALLBACK_CMD_DOWNLOAD + deviceId + channelId;
503   - DeferredResult<ResponseEntity<String>> result = new DeferredResult<>(30000L);
  490 + DeferredResult<String> result = new DeferredResult<>(30000L);
504 491 Device device = storager.queryVideoDevice(deviceId);
505 492 if (device == null) {
506   - result.setResult(new ResponseEntity<>(HttpStatus.BAD_REQUEST));
507   - return result;
  493 + throw new ControllerException(ErrorCode.ERROR400.getCode(), "设备:" + deviceId + "不存在");
508 494 }
509 495  
510 496 resultHolder.put(key, uuid, result);
511   - RequestMessage msg = new RequestMessage();
512   - msg.setId(uuid);
513   - msg.setKey(key);
  497 + RequestMessage requestMessage = new RequestMessage();
  498 + requestMessage.setId(uuid);
  499 + requestMessage.setKey(key);
514 500 WVPResult<StreamInfo> wvpResult = new WVPResult<>();
515   - msg.setData(wvpResult);
  501 + requestMessage.setData(wvpResult);
516 502 PlayBackResult<RequestMessage> downloadResult = new PlayBackResult<>();
517   - downloadResult.setData(msg);
  503 + downloadResult.setData(requestMessage);
518 504  
519 505 String downLoadTimeOutTaskKey = UUID.randomUUID().toString();
520 506 dynamicTask.startDelay(downLoadTimeOutTaskKey, ()->{
521 507 logger.warn(String.format("录像下载请求超时,deviceId:%s ,channelId:%s", deviceId, channelId));
522   - wvpResult.setCode(-1);
  508 + wvpResult.setCode(ErrorCode.ERROR100.getCode());
523 509 wvpResult.setMsg("录像下载请求超时");
524 510 downloadResult.setCode(-1);
525 511 hookCallBack.call(downloadResult);
... ... @@ -545,8 +531,8 @@ public class PlayServiceImpl implements IPlayService {
545 531 streamInfo.setStartTime(startTime);
546 532 streamInfo.setEndTime(endTime);
547 533 redisCatchStorage.startDownload(streamInfo, inviteStreamInfo.getCallId());
548   - wvpResult.setCode(0);
549   - wvpResult.setMsg("success");
  534 + wvpResult.setCode(ErrorCode.SUCCESS.getCode());
  535 + wvpResult.setMsg(ErrorCode.SUCCESS.getMsg());
550 536 wvpResult.setData(streamInfo);
551 537 downloadResult.setCode(0);
552 538 downloadResult.setMediaServerItem(inviteStreamInfo.getMediaServerItem());
... ... @@ -555,7 +541,7 @@ public class PlayServiceImpl implements IPlayService {
555 541 }, event -> {
556 542 dynamicTask.stop(downLoadTimeOutTaskKey);
557 543 downloadResult.setCode(-1);
558   - wvpResult.setCode(-1);
  544 + wvpResult.setCode(ErrorCode.ERROR100.getCode());
559 545 wvpResult.setMsg(String.format("录像下载失败, 错误码: %s, %s", event.statusCode, event.msg));
560 546 downloadResult.setEvent(event);
561 547 hookCallBack.call(downloadResult);
... ... @@ -616,7 +602,7 @@ public class PlayServiceImpl implements IPlayService {
616 602 resultHolder.invokeResult(msg);
617 603 } else {
618 604 logger.warn("设备预览API调用失败!");
619   - msg.setData("设备预览API调用失败!");
  605 + msg.setData(WVPResult.fail(ErrorCode.ERROR100.getCode(), "设备预览API调用失败!"));
620 606 resultHolder.invokeResult(msg);
621 607 }
622 608 }
... ...
src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java
... ... @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONArray;
4 4 import com.alibaba.fastjson.JSONObject;
5 5 import com.genersoft.iot.vmp.common.StreamInfo;
6 6 import com.genersoft.iot.vmp.conf.UserSetting;
  7 +import com.genersoft.iot.vmp.conf.exception.ControllerException;
7 8 import com.genersoft.iot.vmp.gb28181.bean.GbStream;
8 9 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
9 10 import com.genersoft.iot.vmp.gb28181.bean.TreeType;
... ... @@ -24,6 +25,7 @@ import com.genersoft.iot.vmp.storager.dao.PlatformGbStreamMapper;
24 25 import com.genersoft.iot.vmp.storager.dao.StreamProxyMapper;
25 26 import com.genersoft.iot.vmp.service.IStreamProxyService;
26 27 import com.genersoft.iot.vmp.utils.DateUtil;
  28 +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
27 29 import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
28 30 import com.github.pagehelper.PageInfo;
29 31 import org.slf4j.Logger;
... ... @@ -33,6 +35,7 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager;
33 35 import org.springframework.stereotype.Service;
34 36 import org.springframework.transaction.TransactionDefinition;
35 37 import org.springframework.transaction.TransactionStatus;
  38 +import org.springframework.util.ObjectUtils;
36 39 import org.springframework.util.StringUtils;
37 40  
38 41 import java.net.InetAddress;
... ... @@ -93,10 +96,8 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
93 96  
94 97  
95 98 @Override
96   - public WVPResult<StreamInfo> save(StreamProxyItem param) {
  99 + public StreamInfo save(StreamProxyItem param) {
97 100 MediaServerItem mediaInfo;
98   - WVPResult<StreamInfo> wvpResult = new WVPResult<>();
99   - wvpResult.setCode(0);
100 101 if (param.getMediaServerId() == null || "auto".equals(param.getMediaServerId())){
101 102 mediaInfo = mediaServerService.getMediaServerForMinimumLoad();
102 103 }else {
... ... @@ -104,14 +105,12 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
104 105 }
105 106 if (mediaInfo == null) {
106 107 logger.warn("保存代理未找到在线的ZLM...");
107   - wvpResult.setMsg("保存失败");
108   - return wvpResult;
  108 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "保存代理未找到在线的ZLM");
109 109 }
110   -
111 110 String dstUrl = String.format("rtmp://%s:%s/%s/%s", "127.0.0.1", mediaInfo.getRtmpPort(), param.getApp(),
112 111 param.getStream() );
113 112 param.setDst_url(dstUrl);
114   - StringBuffer result = new StringBuffer();
  113 + StringBuffer resultMsg = new StringBuffer();
115 114 boolean streamLive = false;
116 115 param.setMediaServerId(mediaInfo.getId());
117 116 boolean saveResult;
... ... @@ -121,43 +120,47 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
121 120 }else { // 新增
122 121 saveResult = addStreamProxy(param);
123 122 }
124   - if (saveResult) {
125   - result.append("保存成功");
126   - if (param.isEnable()) {
127   - JSONObject jsonObject = addStreamProxyToZlm(param);
128   - if (jsonObject == null || jsonObject.getInteger("code") != 0) {
129   - streamLive = false;
130   - result.append(", 但是启用失败,请检查流地址是否可用");
131   - param.setEnable(false);
132   - // 直接移除
133   - if (param.isEnable_remove_none_reader()) {
134   - del(param.getApp(), param.getStream());
135   - }else {
136   - updateStreamProxy(param);
137   - }
138   -
  123 + if (!saveResult) {
  124 + throw new ControllerException(ErrorCode.ERROR100.getCode(),"保存失败");
  125 + }
  126 + StreamInfo resultForStreamInfo = null;
  127 + resultMsg.append("保存成功");
  128 + if (param.isEnable()) {
  129 + JSONObject jsonObject = addStreamProxyToZlm(param);
  130 + if (jsonObject == null || jsonObject.getInteger("code") != 0) {
  131 + streamLive = false;
  132 + resultMsg.append(", 但是启用失败,请检查流地址是否可用");
  133 + param.setEnable(false);
  134 + // 直接移除
  135 + if (param.isEnable_remove_none_reader()) {
  136 + del(param.getApp(), param.getStream());
139 137 }else {
140   - streamLive = true;
141   - StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream(
142   - mediaInfo, param.getApp(), param.getStream(), null, null);
143   - wvpResult.setData(streamInfo);
144   -
  138 + updateStreamProxy(param);
145 139 }
  140 +
  141 +
  142 + }else {
  143 + streamLive = true;
  144 + resultForStreamInfo = mediaService.getStreamInfoByAppAndStream(
  145 + mediaInfo, param.getApp(), param.getStream(), null, null);
  146 +
146 147 }
147   - }else {
148   - result.append("保存失败");
149 148 }
150   - if ( !StringUtils.isEmpty(param.getPlatformGbId()) && streamLive) {
  149 + if ( !ObjectUtils.isEmpty(param.getPlatformGbId()) && streamLive) {
151 150 List<GbStream> gbStreams = new ArrayList<>();
152 151 gbStreams.add(param);
153 152 if (gbStreamService.addPlatformInfo(gbStreams, param.getPlatformGbId(), param.getCatalogId())){
154   - result.append(", 关联国标平台[ " + param.getPlatformGbId() + " ]成功");
  153 + return resultForStreamInfo;
155 154 }else {
156   - result.append(", 关联国标平台[ " + param.getPlatformGbId() + " ]失败");
  155 + resultMsg.append(", 关联国标平台[ " + param.getPlatformGbId() + " ]失败");
  156 + throw new ControllerException(ErrorCode.ERROR100.getCode(), resultMsg.toString());
  157 + }
  158 + }else {
  159 + if (!streamLive) {
  160 + throw new ControllerException(ErrorCode.ERROR100.getCode(), resultMsg.toString());
157 161 }
158 162 }
159   - wvpResult.setMsg(result.toString());
160   - return wvpResult;
  163 + return resultForStreamInfo;
161 164 }
162 165  
163 166 /**
... ... @@ -174,7 +177,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
174 177 streamProxyItem.setCreateTime(now);
175 178 try {
176 179 if (streamProxyMapper.add(streamProxyItem) > 0) {
177   - if (!StringUtils.isEmpty(streamProxyItem.getGbId())) {
  180 + if (!ObjectUtils.isEmpty(streamProxyItem.getGbId())) {
178 181 if (gbStreamMapper.add(streamProxyItem) < 0) {
179 182 //事务回滚
180 183 dataSourceTransactionManager.rollback(transactionStatus);
... ... @@ -209,7 +212,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
209 212 streamProxyItem.setStreamType("proxy");
210 213 try {
211 214 if (streamProxyMapper.update(streamProxyItem) > 0) {
212   - if (!StringUtils.isEmpty(streamProxyItem.getGbId())) {
  215 + if (!ObjectUtils.isEmpty(streamProxyItem.getGbId())) {
213 216 if (gbStreamMapper.updateByAppAndStream(streamProxyItem) == 0) {
214 217 //事务回滚
215 218 dataSourceTransactionManager.rollback(transactionStatus);
... ...
src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushServiceImpl.java
... ... @@ -27,6 +27,7 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager;
27 27 import org.springframework.stereotype.Service;
28 28 import org.springframework.transaction.TransactionDefinition;
29 29 import org.springframework.transaction.TransactionStatus;
  30 +import org.springframework.util.ObjectUtils;
30 31 import org.springframework.util.StringUtils;
31 32  
32 33 import java.util.*;
... ... @@ -208,7 +209,7 @@ public class StreamPushServiceImpl implements IStreamPushService {
208 209 Map<String, MediaItem> streamInfoPushItemMap = new HashMap<>();
209 210 if (pushList.size() > 0) {
210 211 for (StreamPushItem streamPushItem : pushList) {
211   - if (StringUtils.isEmpty(streamPushItem.getGbId())) {
  212 + if (ObjectUtils.isEmpty(streamPushItem.getGbId())) {
212 213 pushItemMap.put(streamPushItem.getApp() + streamPushItem.getStream(), streamPushItem);
213 214 }
214 215 }
... ... @@ -492,7 +493,7 @@ public class StreamPushServiceImpl implements IStreamPushService {
492 493 TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
493 494 try {
494 495 int addStreamResult = streamPushMapper.add(stream);
495   - if (!StringUtils.isEmpty(stream.getGbId())) {
  496 + if (!ObjectUtils.isEmpty(stream.getGbId())) {
496 497 stream.setStreamType("push");
497 498 gbStreamMapper.add(stream);
498 499 }
... ...
src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushUploadFileHandler.java
... ... @@ -8,6 +8,7 @@ import com.genersoft.iot.vmp.utils.DateUtil;
8 8 import com.genersoft.iot.vmp.vmanager.bean.StreamPushExcelDto;
9 9 import com.google.common.collect.BiMap;
10 10 import com.google.common.collect.HashBiMap;
  11 +import org.springframework.util.ObjectUtils;
11 12 import org.springframework.util.StringUtils;
12 13  
13 14 import java.util.*;
... ... @@ -82,9 +83,9 @@ public class StreamPushUploadFileHandler extends AnalysisEventListener&lt;StreamPus
82 83  
83 84 @Override
84 85 public void invoke(StreamPushExcelDto streamPushExcelDto, AnalysisContext analysisContext) {
85   - if (StringUtils.isEmpty(streamPushExcelDto.getApp())
86   - || StringUtils.isEmpty(streamPushExcelDto.getStream())
87   - || StringUtils.isEmpty(streamPushExcelDto.getGbId())) {
  86 + if (ObjectUtils.isEmpty(streamPushExcelDto.getApp())
  87 + || ObjectUtils.isEmpty(streamPushExcelDto.getStream())
  88 + || ObjectUtils.isEmpty(streamPushExcelDto.getGbId())) {
88 89 return;
89 90 }
90 91  
... ... @@ -130,7 +131,7 @@ public class StreamPushUploadFileHandler extends AnalysisEventListener&lt;StreamPus
130 131 streamPushItems.add(streamPushItem);
131 132 streamPushItemForSave.put(streamPushItem.getApp() + streamPushItem.getStream(), streamPushItem);
132 133  
133   - if (!StringUtils.isEmpty(streamPushExcelDto.getPlatformId())) {
  134 + if (!ObjectUtils.isEmpty(streamPushExcelDto.getPlatformId())) {
134 135 List<String[]> platformList = streamPushItemsForPlatform.get(streamPushItem.getApp() + streamPushItem.getStream());
135 136 if (platformList == null) {
136 137 platformList = new ArrayList<>();
... ... @@ -138,7 +139,7 @@ public class StreamPushUploadFileHandler extends AnalysisEventListener&lt;StreamPus
138 139 }
139 140 String platformId = streamPushExcelDto.getPlatformId();
140 141 String catalogId = streamPushExcelDto.getCatalogId();
141   - if (StringUtils.isEmpty(streamPushExcelDto.getCatalogId())) {
  142 + if (ObjectUtils.isEmpty(streamPushExcelDto.getCatalogId())) {
142 143 catalogId = null;
143 144 }
144 145 String[] platFormInfoArray = new String[]{platformId, catalogId};
... ...
src/main/java/com/genersoft/iot/vmp/service/impl/UserServiceImpl.java
... ... @@ -7,6 +7,7 @@ import com.github.pagehelper.PageHelper;
7 7 import com.github.pagehelper.PageInfo;
8 8 import org.springframework.beans.factory.annotation.Autowired;
9 9 import org.springframework.stereotype.Service;
  10 +import org.springframework.util.ObjectUtils;
10 11 import org.springframework.util.StringUtils;
11 12  
12 13 import java.util.List;
... ... @@ -60,7 +61,7 @@ public class UserServiceImpl implements IUserService {
60 61  
61 62 @Override
62 63 public boolean checkPushAuthority(String callId, String sign) {
63   - if (StringUtils.isEmpty(callId)) {
  64 + if (ObjectUtils.isEmpty(callId)) {
64 65 return userMapper.checkPushAuthorityByCallId(sign).size() > 0;
65 66 }else {
66 67 return userMapper.checkPushAuthorityByCallIdAndSign(callId, sign).size() > 0;
... ...
src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java
... ... @@ -26,6 +26,7 @@ import org.springframework.transaction.TransactionDefinition;
26 26 import org.springframework.transaction.TransactionStatus;
27 27 import org.springframework.transaction.annotation.Transactional;
28 28 import org.springframework.util.CollectionUtils;
  29 +import org.springframework.util.ObjectUtils;
29 30 import org.springframework.util.StringUtils;
30 31  
31 32 import java.util.*;
... ... @@ -132,7 +133,7 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
132 133 deviceChannel.setStreamId(allChannelMapInPlay.get(deviceChannel.getChannelId()).getStreamId());
133 134 }
134 135 channels.add(deviceChannel);
135   - if (!StringUtils.isEmpty(deviceChannel.getParentId())) {
  136 + if (!ObjectUtils.isEmpty(deviceChannel.getParentId())) {
136 137 if (subContMap.get(deviceChannel.getParentId()) == null) {
137 138 subContMap.put(deviceChannel.getParentId(), 1);
138 139 }else {
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/bean/ErrorCode.java 0 → 100644
  1 +package com.genersoft.iot.vmp.vmanager.bean;
  2 +
  3 +import io.swagger.v3.oas.annotations.media.Schema;
  4 +
  5 +/**
  6 + * 全局错误码
  7 + */
  8 +public enum ErrorCode {
  9 + SUCCESS(0, "成功"),
  10 + ERROR100(100, "失败"),
  11 + ERROR400(400, "参数不全或者错误"),
  12 + ERROR403(403, "无权限操作"),
  13 + ERROR401(401, "请登录后重新请求"),
  14 + ERROR500(500, "系统异常");
  15 +
  16 + private final int code;
  17 + private final String msg;
  18 +
  19 + ErrorCode(int code, String msg) {
  20 + this.code = code;
  21 + this.msg = msg;
  22 + }
  23 +
  24 + public int getCode() {
  25 + return code;
  26 + }
  27 +
  28 + public String getMsg() {
  29 + return msg;
  30 + }
  31 +}
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/session/PlayTypeEnum.java renamed to src/main/java/com/genersoft/iot/vmp/vmanager/bean/PlayTypeEnum.java
1   -package com.genersoft.iot.vmp.vmanager.gb28181.session;
  1 +package com.genersoft.iot.vmp.vmanager.bean;
2 2  
3 3 public enum PlayTypeEnum {
4 4  
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/bean/WVPResult.java
... ... @@ -23,23 +23,21 @@ public class WVPResult&lt;T&gt; {
23 23 @Schema(description = "数据")
24 24 private T data;
25 25  
26   - private static final Integer SUCCESS = 200;
27   - private static final Integer FAILED = 400;
28 26  
29   - public static <T> WVPResult<T> Data(T t, String msg) {
30   - return new WVPResult<>(SUCCESS, msg, t);
  27 + public static <T> WVPResult<T> success(T t, String msg) {
  28 + return new WVPResult<>(ErrorCode.SUCCESS.getCode(), msg, t);
31 29 }
32 30  
33   - public static <T> WVPResult<T> Data(T t) {
34   - return Data(t, "成功");
  31 + public static <T> WVPResult<T> success(T t) {
  32 + return success(t, ErrorCode.SUCCESS.getMsg());
35 33 }
36 34  
37 35 public static <T> WVPResult<T> fail(int code, String msg) {
38 36 return new WVPResult<>(code, msg, null);
39 37 }
40 38  
41   - public static <T> WVPResult<T> fail(String msg) {
42   - return fail(FAILED, msg);
  39 + public static <T> WVPResult<T> fail(ErrorCode errorCode) {
  40 + return fail(errorCode.getCode(), errorCode.getMsg());
43 41 }
44 42  
45 43 public int getCode() {
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/MobilePosition/MobilePositionController.java
... ... @@ -65,7 +65,7 @@ public class MobilePositionController {
65 65 @Parameter(name = "start", description = "开始时间")
66 66 @Parameter(name = "end", description = "结束时间")
67 67 @GetMapping("/history/{deviceId}")
68   - public ResponseEntity<WVPResult<List<MobilePosition>>> positions(@PathVariable String deviceId,
  68 + public List<MobilePosition> positions(@PathVariable String deviceId,
69 69 @RequestParam(required = false) String channelId,
70 70 @RequestParam(required = false) String start,
71 71 @RequestParam(required = false) String end) {
... ... @@ -76,11 +76,7 @@ public class MobilePositionController {
76 76 if (StringUtil.isEmpty(end)) {
77 77 end = null;
78 78 }
79   - WVPResult<List<MobilePosition>> wvpResult = new WVPResult<>();
80   - wvpResult.setCode(0);
81   - List<MobilePosition> result = storager.queryMobilePositions(deviceId, channelId, start, end);
82   - wvpResult.setData(result);
83   - return new ResponseEntity<>(wvpResult, HttpStatus.OK);
  79 + return storager.queryMobilePositions(deviceId, channelId, start, end);
84 80 }
85 81  
86 82 /**
... ... @@ -91,9 +87,8 @@ public class MobilePositionController {
91 87 @Operation(summary = "查询设备最新位置")
92 88 @Parameter(name = "deviceId", description = "设备国标编号", required = true)
93 89 @GetMapping("/latest/{deviceId}")
94   - public ResponseEntity<MobilePosition> latestPosition(@PathVariable String deviceId) {
95   - MobilePosition result = storager.queryLatestPosition(deviceId);
96   - return new ResponseEntity<>(result, HttpStatus.OK);
  90 + public MobilePosition latestPosition(@PathVariable String deviceId) {
  91 + return storager.queryLatestPosition(deviceId);
97 92 }
98 93  
99 94 /**
... ... @@ -104,7 +99,7 @@ public class MobilePositionController {
104 99 @Operation(summary = "获取移动位置信息")
105 100 @Parameter(name = "deviceId", description = "设备国标编号", required = true)
106 101 @GetMapping("/realtime/{deviceId}")
107   - public DeferredResult<ResponseEntity<MobilePosition>> realTimePosition(@PathVariable String deviceId) {
  102 + public DeferredResult<MobilePosition> realTimePosition(@PathVariable String deviceId) {
108 103 Device device = storager.queryVideoDevice(deviceId);
109 104 String uuid = UUID.randomUUID().toString();
110 105 String key = DeferredResultHolder.CALLBACK_CMD_MOBILEPOSITION + deviceId;
... ... @@ -115,7 +110,7 @@ public class MobilePositionController {
115 110 msg.setData(String.format("获取移动位置信息失败,错误码: %s, %s", event.statusCode, event.msg));
116 111 resultHolder.invokeResult(msg);
117 112 });
118   - DeferredResult<ResponseEntity<MobilePosition>> result = new DeferredResult<ResponseEntity<MobilePosition>>(5*1000L);
  113 + DeferredResult<MobilePosition> result = new DeferredResult<MobilePosition>(5*1000L);
119 114 result.onTimeout(()->{
120 115 logger.warn(String.format("获取移动位置信息超时"));
121 116 // 释放rtpserver
... ... @@ -141,7 +136,7 @@ public class MobilePositionController {
141 136 @Parameter(name = "expires", description = "订阅超时时间", required = true)
142 137 @Parameter(name = "interval", description = "上报时间间隔", required = true)
143 138 @GetMapping("/subscribe/{deviceId}")
144   - public ResponseEntity<String> positionSubscribe(@PathVariable String deviceId,
  139 + public String positionSubscribe(@PathVariable String deviceId,
145 140 @RequestParam String expires,
146 141 @RequestParam String interval) {
147 142 String msg = ((expires.equals("0")) ? "取消" : "") + "订阅设备" + deviceId + "的移动位置";
... ... @@ -163,6 +158,6 @@ public class MobilePositionController {
163 158 result += ",失败";
164 159 }
165 160  
166   - return new ResponseEntity<>(result, HttpStatus.OK);
  161 + return result;
167 162 }
168 163 }
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java
1 1 package com.genersoft.iot.vmp.vmanager.gb28181.alarm;
2 2  
  3 +import com.genersoft.iot.vmp.conf.exception.ControllerException;
3 4 import com.genersoft.iot.vmp.gb28181.bean.Device;
4 5 import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm;
5 6 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
... ... @@ -8,14 +9,17 @@ import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
8 9 import com.genersoft.iot.vmp.service.IDeviceAlarmService;
9 10 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
10 11 import com.genersoft.iot.vmp.utils.DateUtil;
  12 +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
11 13 import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
12 14 import com.github.pagehelper.PageInfo;
13 15 import io.swagger.v3.oas.annotations.Operation;
14 16 import io.swagger.v3.oas.annotations.Parameter;
  17 +import io.swagger.v3.oas.annotations.responses.ApiResponse;
15 18 import io.swagger.v3.oas.annotations.tags.Tag;
16 19 import org.springframework.beans.factory.annotation.Autowired;
17 20 import org.springframework.http.HttpStatus;
18 21 import org.springframework.http.ResponseEntity;
  22 +import org.springframework.util.ObjectUtils;
19 23 import org.springframework.util.StringUtils;
20 24 import org.springframework.web.bind.annotation.*;
21 25  
... ... @@ -55,22 +59,22 @@ public class AlarmController {
55 59 @Parameter(name = "id", description = "ID")
56 60 @Parameter(name = "deviceIds", description = "多个设备id,逗号分隔")
57 61 @Parameter(name = "time", description = "结束时间")
58   - public ResponseEntity<WVPResult<String>> delete(
  62 + public Integer delete(
59 63 @RequestParam(required = false) Integer id,
60 64 @RequestParam(required = false) String deviceIds,
61 65 @RequestParam(required = false) String time
62 66 ) {
63   - if (StringUtils.isEmpty(id)) {
  67 + if (ObjectUtils.isEmpty(id)) {
64 68 id = null;
65 69 }
66   - if (StringUtils.isEmpty(deviceIds)) {
  70 + if (ObjectUtils.isEmpty(deviceIds)) {
67 71 deviceIds = null;
68 72 }
69   - if (StringUtils.isEmpty(time)) {
  73 + if (ObjectUtils.isEmpty(time)) {
70 74 time = null;
71 75 }
72 76 if (!DateUtil.verification(time, DateUtil.formatter) ){
73   - return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
  77 + return null;
74 78 }
75 79 List<String> deviceIdList = null;
76 80 if (deviceIds != null) {
... ... @@ -78,12 +82,7 @@ public class AlarmController {
78 82 deviceIdList = Arrays.asList(deviceIdArray);
79 83 }
80 84  
81   - int count = deviceAlarmService.clearAlarmBeforeTime(id, deviceIdList, time);
82   - WVPResult wvpResult = new WVPResult();
83   - wvpResult.setCode(0);
84   - wvpResult.setMsg("success");
85   - wvpResult.setData(count);
86   - return new ResponseEntity<WVPResult<String>>(wvpResult, HttpStatus.OK);
  85 + return deviceAlarmService.clearAlarmBeforeTime(id, deviceIdList, time);
87 86 }
88 87  
89 88 /**
... ... @@ -95,12 +94,7 @@ public class AlarmController {
95 94 @GetMapping("/test/notify/alarm")
96 95 @Operation(summary = "测试向上级/设备发送模拟报警通知")
97 96 @Parameter(name = "deviceId", description = "设备国标编号")
98   - public ResponseEntity<WVPResult<String>> delete(
99   - @RequestParam(required = false) String deviceId
100   - ) {
101   - if (StringUtils.isEmpty(deviceId)) {
102   - return new ResponseEntity<>(HttpStatus.NOT_FOUND);
103   - }
  97 + public void delete(@RequestParam String deviceId) {
104 98 Device device = storage.queryVideoDevice(deviceId);
105 99 ParentPlatform platform = storage.queryParentPlatByServerGBId(deviceId);
106 100 DeviceAlarm deviceAlarm = new DeviceAlarm();
... ... @@ -118,16 +112,9 @@ public class AlarmController {
118 112 }else if (device == null && platform != null){
119 113 commanderForPlatform.sendAlarmMessage(platform, deviceAlarm);
120 114 }else {
121   - WVPResult wvpResult = new WVPResult();
122   - wvpResult.setCode(0);
123   - wvpResult.setMsg("无法确定" + deviceId + "是平台还是设备");
124   - return new ResponseEntity<WVPResult<String>>(wvpResult, HttpStatus.OK);
  115 + throw new ControllerException(ErrorCode.ERROR100.getCode(),"无法确定" + deviceId + "是平台还是设备");
125 116 }
126 117  
127   - WVPResult wvpResult = new WVPResult();
128   - wvpResult.setCode(0);
129   - wvpResult.setMsg("success");
130   - return new ResponseEntity<WVPResult<String>>(wvpResult, HttpStatus.OK);
131 118 }
132 119  
133 120 /**
... ... @@ -153,7 +140,7 @@ public class AlarmController {
153 140 @Parameter(name = "startTime",description = "开始时间")
154 141 @Parameter(name = "endTime",description = "结束时间")
155 142 @GetMapping("/all")
156   - public ResponseEntity<PageInfo<DeviceAlarm>> getAll(
  143 + public PageInfo<DeviceAlarm> getAll(
157 144 @RequestParam int page,
158 145 @RequestParam int count,
159 146 @RequestParam(required = false) String deviceId,
... ... @@ -163,31 +150,28 @@ public class AlarmController {
163 150 @RequestParam(required = false) String startTime,
164 151 @RequestParam(required = false) String endTime
165 152 ) {
166   - if (StringUtils.isEmpty(alarmPriority)) {
  153 + if (ObjectUtils.isEmpty(alarmPriority)) {
167 154 alarmPriority = null;
168 155 }
169   - if (StringUtils.isEmpty(alarmMethod)) {
  156 + if (ObjectUtils.isEmpty(alarmMethod)) {
170 157 alarmMethod = null;
171 158 }
172   - if (StringUtils.isEmpty(alarmType)) {
  159 + if (ObjectUtils.isEmpty(alarmType)) {
173 160 alarmType = null;
174 161 }
175   - if (StringUtils.isEmpty(startTime)) {
  162 + if (ObjectUtils.isEmpty(startTime)) {
176 163 startTime = null;
177 164 }
178   - if (StringUtils.isEmpty(endTime)) {
  165 + if (ObjectUtils.isEmpty(endTime)) {
179 166 endTime = null;
180 167 }
181 168  
182 169  
183 170 if (!DateUtil.verification(startTime, DateUtil.formatter) || !DateUtil.verification(endTime, DateUtil.formatter)){
184   - return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
  171 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "开始时间或结束时间格式有误");
185 172 }
186 173  
187   - PageInfo<DeviceAlarm> allAlarm = deviceAlarmService.getAllAlarm(page, count, deviceId, alarmPriority, alarmMethod,
  174 + return deviceAlarmService.getAllAlarm(page, count, deviceId, alarmPriority, alarmMethod,
188 175 alarmType, startTime, endTime);
189   - return new ResponseEntity<>(allAlarm, HttpStatus.OK);
190 176 }
191   -
192   -
193 177 }
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceConfig.java
... ... @@ -21,6 +21,7 @@ import org.slf4j.Logger;
21 21 import org.slf4j.LoggerFactory;
22 22 import org.springframework.beans.factory.annotation.Autowired;
23 23 import org.springframework.http.ResponseEntity;
  24 +import org.springframework.util.ObjectUtils;
24 25 import org.springframework.util.StringUtils;
25 26 import org.springframework.web.bind.annotation.*;
26 27 import org.springframework.web.context.request.async.DeferredResult;
... ... @@ -62,7 +63,7 @@ public class DeviceConfig {
62 63 @Parameter(name = "expiration", description = "到期时间")
63 64 @Parameter(name = "heartBeatInterval", description = "心跳间隔")
64 65 @Parameter(name = "heartBeatCount", description = "心跳计数")
65   - public DeferredResult<ResponseEntity<String>> homePositionApi(@PathVariable String deviceId,
  66 + public DeferredResult<String> homePositionApi(@PathVariable String deviceId,
66 67 String channelId,
67 68 @RequestParam(required = false) String name,
68 69 @RequestParam(required = false) String expiration,
... ... @@ -81,7 +82,7 @@ public class DeviceConfig {
81 82 msg.setData(String.format("设备配置操作失败,错误码: %s, %s", event.statusCode, event.msg));
82 83 resultHolder.invokeResult(msg);
83 84 });
84   - DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L);
  85 + DeferredResult<String> result = new DeferredResult<String>(3 * 1000L);
85 86 result.onTimeout(() -> {
86 87 logger.warn(String.format("设备配置操作超时, 设备未返回应答指令"));
87 88 // 释放rtpserver
... ... @@ -111,13 +112,13 @@ public class DeviceConfig {
111 112 @Parameter(name = "channelId", description = "通道国标编号", required = true)
112 113 @Parameter(name = "configType", description = "配置类型")
113 114 @GetMapping("/query/{deviceId}/{configType}")
114   - public DeferredResult<ResponseEntity<String>> configDownloadApi(@PathVariable String deviceId,
  115 + public DeferredResult<String> configDownloadApi(@PathVariable String deviceId,
115 116 @PathVariable String configType,
116 117 @RequestParam(required = false) String channelId) {
117 118 if (logger.isDebugEnabled()) {
118 119 logger.debug("设备状态查询API调用");
119 120 }
120   - String key = DeferredResultHolder.CALLBACK_CMD_CONFIGDOWNLOAD + (StringUtils.isEmpty(channelId) ? deviceId : channelId);
  121 + String key = DeferredResultHolder.CALLBACK_CMD_CONFIGDOWNLOAD + (ObjectUtils.isEmpty(channelId) ? deviceId : channelId);
121 122 String uuid = UUID.randomUUID().toString();
122 123 Device device = storager.queryVideoDevice(deviceId);
123 124 cmder.deviceConfigQuery(device, channelId, configType, event -> {
... ... @@ -127,7 +128,7 @@ public class DeviceConfig {
127 128 msg.setData(String.format("获取设备配置失败,错误码: %s, %s", event.statusCode, event.msg));
128 129 resultHolder.invokeResult(msg);
129 130 });
130   - DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String >> (3 * 1000L);
  131 + DeferredResult<String> result = new DeferredResult<String > (3 * 1000L);
131 132 result.onTimeout(()->{
132 133 logger.warn(String.format("获取设备配置超时"));
133 134 // 释放rtpserver
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceControl.java
... ... @@ -8,12 +8,14 @@
8 8 package com.genersoft.iot.vmp.vmanager.gb28181.device;
9 9  
10 10 import com.alibaba.fastjson.JSONObject;
  11 +import com.genersoft.iot.vmp.conf.exception.ControllerException;
11 12 import com.genersoft.iot.vmp.gb28181.bean.Device;
12 13 import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
13 14 import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
14 15 import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
15 16 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
16 17  
  18 +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
17 19 import io.swagger.v3.oas.annotations.Operation;
18 20 import io.swagger.v3.oas.annotations.Parameter;
19 21 import io.swagger.v3.oas.annotations.tags.Tag;
... ... @@ -22,6 +24,7 @@ import org.slf4j.LoggerFactory;
22 24 import org.springframework.beans.factory.annotation.Autowired;
23 25 import org.springframework.http.HttpStatus;
24 26 import org.springframework.http.ResponseEntity;
  27 +import org.springframework.util.ObjectUtils;
25 28 import org.springframework.util.StringUtils;
26 29 import org.springframework.web.bind.annotation.*;
27 30 import org.springframework.web.context.request.async.DeferredResult;
... ... @@ -50,14 +53,10 @@ public class DeviceControl {
50 53 *
51 54 * @param deviceId 设备ID
52 55 */
53   -// //@ApiOperation("远程启动控制命令")
54   -// @ApiImplicitParams({
55   -// @ApiImplicitParam(name = "deviceId", value ="设备ID", required = true, dataTypeClass = String.class),
56   -// })
57 56 @Operation(summary = "远程启动控制命令")
58 57 @Parameter(name = "deviceId", description = "设备国标编号", required = true)
59 58 @GetMapping("/teleboot/{deviceId}")
60   - public ResponseEntity<String> teleBootApi(@PathVariable String deviceId) {
  59 + public String teleBootApi(@PathVariable String deviceId) {
61 60 if (logger.isDebugEnabled()) {
62 61 logger.debug("设备远程启动API调用");
63 62 }
... ... @@ -67,10 +66,10 @@ public class DeviceControl {
67 66 JSONObject json = new JSONObject();
68 67 json.put("DeviceID", deviceId);
69 68 json.put("Result", "OK");
70   - return new ResponseEntity<>(json.toJSONString(), HttpStatus.OK);
  69 + return json.toJSONString();
71 70 } else {
72 71 logger.warn("设备远程启动API调用失败!");
73   - return new ResponseEntity<String>("设备远程启动API调用失败!", HttpStatus.INTERNAL_SERVER_ERROR);
  72 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "设备远程启动API调用失败!");
74 73 }
75 74 }
76 75  
... ... @@ -255,7 +254,7 @@ public class DeviceControl {
255 254 if (logger.isDebugEnabled()) {
256 255 logger.debug("报警复位API调用");
257 256 }
258   - String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + (StringUtils.isEmpty(channelId) ? deviceId : channelId);
  257 + String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + (ObjectUtils.isEmpty(channelId) ? deviceId : channelId);
259 258 String uuid = UUID.randomUUID().toString();
260 259 Device device = storager.queryVideoDevice(deviceId);
261 260 cmder.homePositionCmd(device, channelId, enabled, resetTime, presetIndex, event -> {
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java
... ... @@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.vmanager.gb28181.device;
2 2  
3 3 import com.alibaba.fastjson.JSONObject;
4 4 import com.genersoft.iot.vmp.conf.DynamicTask;
  5 +import com.genersoft.iot.vmp.conf.exception.ControllerException;
5 6 import com.genersoft.iot.vmp.gb28181.bean.Device;
6 7 import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
7 8 import com.genersoft.iot.vmp.gb28181.bean.SubscribeHolder;
... ... @@ -17,6 +18,7 @@ import com.genersoft.iot.vmp.service.IDeviceService;
17 18 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
18 19 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
19 20 import com.genersoft.iot.vmp.vmanager.bean.BaseTree;
  21 +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
20 22 import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
21 23 import com.github.pagehelper.PageInfo;
22 24 import io.swagger.v3.oas.annotations.Operation;
... ... @@ -30,6 +32,7 @@ import org.springframework.beans.factory.annotation.Autowired;
30 32 import org.springframework.http.HttpStatus;
31 33 import org.springframework.http.MediaType;
32 34 import org.springframework.http.ResponseEntity;
  35 +import org.springframework.util.ObjectUtils;
33 36 import org.springframework.util.StringUtils;
34 37 import org.springframework.web.bind.annotation.*;
35 38 import org.springframework.web.context.request.async.DeferredResult;
... ... @@ -81,10 +84,9 @@ public class DeviceQuery {
81 84 @Operation(summary = "查询国标设备")
82 85 @Parameter(name = "deviceId", description = "设备国标编号", required = true)
83 86 @GetMapping("/devices/{deviceId}")
84   - public ResponseEntity<Device> devices(@PathVariable String deviceId){
  87 + public Device devices(@PathVariable String deviceId){
85 88  
86   - Device device = storager.queryVideoDevice(deviceId);
87   - return new ResponseEntity<>(device,HttpStatus.OK);
  89 + return storager.queryVideoDevice(deviceId);
88 90 }
89 91  
90 92 /**
... ... @@ -123,18 +125,17 @@ public class DeviceQuery {
123 125 @Parameter(name = "online", description = "是否在线")
124 126 @Parameter(name = "channelType", description = "设备/子目录-> false/true")
125 127 @Parameter(name = "catalogUnderDevice", description = "是否直属与设备的目录")
126   - public ResponseEntity<PageInfo> channels(@PathVariable String deviceId,
  128 + public PageInfo channels(@PathVariable String deviceId,
127 129 int page, int count,
128 130 @RequestParam(required = false) String query,
129 131 @RequestParam(required = false) Boolean online,
130 132 @RequestParam(required = false) Boolean channelType,
131 133 @RequestParam(required = false) Boolean catalogUnderDevice) {
132   - if (StringUtils.isEmpty(query)) {
  134 + if (ObjectUtils.isEmpty(query)) {
133 135 query = null;
134 136 }
135 137  
136   - PageInfo pageResult = storager.queryChannelsByDeviceId(deviceId, query, channelType, online, catalogUnderDevice, page, count);
137   - return new ResponseEntity<>(pageResult,HttpStatus.OK);
  138 + return storager.queryChannelsByDeviceId(deviceId, query, channelType, online, catalogUnderDevice, page, count);
138 139 }
139 140  
140 141 /**
... ... @@ -154,11 +155,8 @@ public class DeviceQuery {
154 155 boolean status = deviceService.isSyncRunning(deviceId);
155 156 // 已存在则返回进度
156 157 if (status) {
157   - WVPResult<SyncStatus> wvpResult = new WVPResult<>();
158   - wvpResult.setCode(0);
159 158 SyncStatus channelSyncStatus = deviceService.getChannelSyncStatus(deviceId);
160   - wvpResult.setData(channelSyncStatus);
161   - return wvpResult;
  159 + return WVPResult.success(channelSyncStatus);
162 160 }
163 161 deviceService.sync(device);
164 162  
... ... @@ -176,7 +174,7 @@ public class DeviceQuery {
176 174 @Operation(summary = "移除设备")
177 175 @Parameter(name = "deviceId", description = "设备国标编号", required = true)
178 176 @DeleteMapping("/devices/{deviceId}/delete")
179   - public ResponseEntity<String> delete(@PathVariable String deviceId){
  177 + public String delete(@PathVariable String deviceId){
180 178  
181 179 if (logger.isDebugEnabled()) {
182 180 logger.debug("设备信息删除API调用,deviceId:" + deviceId);
... ... @@ -200,10 +198,10 @@ public class DeviceQuery {
200 198 }
201 199 JSONObject json = new JSONObject();
202 200 json.put("deviceId", deviceId);
203   - return new ResponseEntity<>(json.toString(),HttpStatus.OK);
  201 + return json.toString();
204 202 } else {
205 203 logger.warn("设备信息删除API调用失败!");
206   - return new ResponseEntity<String>("设备信息删除API调用失败!", HttpStatus.INTERNAL_SERVER_ERROR);
  204 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "设备信息删除API调用失败!");
207 205 }
208 206 }
209 207  
... ... @@ -402,7 +400,8 @@ public class DeviceQuery {
402 400 wvpResult.setCode(-1);
403 401 wvpResult.setMsg("同步尚未开始");
404 402 }else {
405   - wvpResult.setCode(0);
  403 + wvpResult.setCode(ErrorCode.SUCCESS.getCode());
  404 + wvpResult.setMsg(ErrorCode.SUCCESS.getMsg());
406 405 wvpResult.setData(channelSyncStatus);
407 406 if (channelSyncStatus.getErrorMsg() != null) {
408 407 wvpResult.setMsg(channelSyncStatus.getErrorMsg());
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/gbStream/GbStreamController.java
... ... @@ -11,6 +11,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
11 11 import org.slf4j.Logger;
12 12 import org.slf4j.LoggerFactory;
13 13 import org.springframework.beans.factory.annotation.Autowired;
  14 +import org.springframework.util.ObjectUtils;
14 15 import org.springframework.util.StringUtils;
15 16 import org.springframework.web.bind.annotation.*;
16 17  
... ... @@ -51,13 +52,13 @@ public class GbStreamController {
51 52 @RequestParam(required = false)String catalogId,
52 53 @RequestParam(required = false)String query,
53 54 @RequestParam(required = false)String mediaServerId){
54   - if (StringUtils.isEmpty(catalogId)) {
  55 + if (ObjectUtils.isEmpty(catalogId)) {
55 56 catalogId = null;
56 57 }
57   - if (StringUtils.isEmpty(query)) {
  58 + if (ObjectUtils.isEmpty(query)) {
58 59 query = null;
59 60 }
60   - if (StringUtils.isEmpty(mediaServerId)) {
  61 + if (ObjectUtils.isEmpty(mediaServerId)) {
61 62 mediaServerId = null;
62 63 }
63 64  
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/media/MediaController.java
1 1 package com.genersoft.iot.vmp.vmanager.gb28181.media;
2 2  
3 3 import com.genersoft.iot.vmp.common.StreamInfo;
  4 +import com.genersoft.iot.vmp.conf.exception.ControllerException;
4 5 import com.genersoft.iot.vmp.conf.security.SecurityUtils;
5 6 import com.genersoft.iot.vmp.conf.security.dto.LoginUser;
6 7 import com.genersoft.iot.vmp.media.zlm.dto.StreamAuthorityInfo;
7 8 import com.genersoft.iot.vmp.service.IStreamProxyService;
8 9 import com.genersoft.iot.vmp.service.IMediaService;
9 10 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
  11 +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
10 12 import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
11 13 import io.swagger.v3.oas.annotations.Operation;
12 14 import io.swagger.v3.oas.annotations.Parameter;
... ... @@ -51,7 +53,7 @@ public class MediaController {
51 53 @Parameter(name = "useSourceIpAsStreamIp", description = "是否使用请求IP作为返回的地址IP")
52 54 @GetMapping(value = "/stream_info_by_app_and_stream")
53 55 @ResponseBody
54   - public WVPResult<StreamInfo> getStreamInfoByAppAndStream(HttpServletRequest request, @RequestParam String app,
  56 + public StreamInfo getStreamInfoByAppAndStream(HttpServletRequest request, @RequestParam String app,
55 57 @RequestParam String stream,
56 58 @RequestParam(required = false) String mediaServerId,
57 59 @RequestParam(required = false) String callId,
... ... @@ -63,10 +65,7 @@ public class MediaController {
63 65 if (streamAuthorityInfo.getCallId().equals(callId)) {
64 66 authority = true;
65 67 }else {
66   - WVPResult<StreamInfo> result = new WVPResult<>();
67   - result.setCode(401);
68   - result.setMsg("fail");
69   - return result;
  68 + throw new ControllerException(ErrorCode.ERROR400);
70 69 }
71 70 }else {
72 71 // 是否登陆用户, 登陆用户返回完整信息
... ... @@ -89,9 +88,7 @@ public class MediaController {
89 88  
90 89 WVPResult<StreamInfo> result = new WVPResult<>();
91 90 if (streamInfo != null){
92   - result.setCode(0);
93   - result.setMsg("scccess");
94   - result.setData(streamInfo);
  91 + return streamInfo;
95 92 }else {
96 93 //获取流失败,重启拉流后重试一次
97 94 streamProxyService.stop(app,stream);
... ... @@ -110,14 +107,10 @@ public class MediaController {
110 107 streamInfo = mediaService.getStreamInfoByAppAndStreamWithCheck(app, stream, mediaServerId, authority);
111 108 }
112 109 if (streamInfo != null){
113   - result.setCode(0);
114   - result.setMsg("scccess");
115   - result.setData(streamInfo);
  110 + return streamInfo;
116 111 }else {
117   - result.setCode(-1);
118   - result.setMsg("fail");
  112 + throw new ControllerException(ErrorCode.ERROR100);
119 113 }
120 114 }
121   - return result;
122 115 }
123 116 }
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java
... ... @@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
5 5 import com.genersoft.iot.vmp.common.VideoManagerConstants;
6 6 import com.genersoft.iot.vmp.conf.DynamicTask;
7 7 import com.genersoft.iot.vmp.conf.UserSetting;
  8 +import com.genersoft.iot.vmp.conf.exception.ControllerException;
8 9 import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
9 10 import com.genersoft.iot.vmp.gb28181.bean.PlatformCatalog;
10 11 import com.genersoft.iot.vmp.gb28181.bean.SubscribeHolder;
... ... @@ -14,6 +15,7 @@ import com.genersoft.iot.vmp.service.IPlatformChannelService;
14 15 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
15 16 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
16 17 import com.genersoft.iot.vmp.utils.DateUtil;
  18 +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
17 19 import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
18 20 import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce;
19 21 import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.UpdateChannelParam;
... ... @@ -26,6 +28,7 @@ import org.slf4j.LoggerFactory;
26 28 import org.springframework.beans.factory.annotation.Autowired;
27 29 import org.springframework.http.HttpStatus;
28 30 import org.springframework.http.ResponseEntity;
  31 +import org.springframework.util.ObjectUtils;
29 32 import org.springframework.util.StringUtils;
30 33 import org.springframework.web.bind.annotation.*;
31 34 import com.genersoft.iot.vmp.conf.SipConfig;
... ... @@ -74,13 +77,13 @@ public class PlatformController {
74 77 */
75 78 @Operation(summary = "获取国标服务的配置")
76 79 @GetMapping("/server_config")
77   - public ResponseEntity<JSONObject> serverConfig() {
  80 + public JSONObject serverConfig() {
78 81 JSONObject result = new JSONObject();
79 82 result.put("deviceIp", sipConfig.getIp());
80 83 result.put("devicePort", sipConfig.getPort());
81 84 result.put("username", sipConfig.getId());
82 85 result.put("password", sipConfig.getPassword());
83   - return new ResponseEntity<>(result, HttpStatus.OK);
  86 + return result;
84 87 }
85 88  
86 89 /**
... ... @@ -91,18 +94,14 @@ public class PlatformController {
91 94 @Operation(summary = "获取级联服务器信息")
92 95 @Parameter(name = "id", description = "平台国标编号", required = true)
93 96 @GetMapping("/info/{id}")
94   - public ResponseEntity<WVPResult<ParentPlatform>> getPlatform(@PathVariable String id) {
  97 + public ParentPlatform getPlatform(@PathVariable String id) {
95 98 ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(id);
96 99 WVPResult<ParentPlatform> wvpResult = new WVPResult<>();
97 100 if (parentPlatform != null) {
98   - wvpResult.setCode(0);
99   - wvpResult.setMsg("success");
100   - wvpResult.setData(parentPlatform);
  101 + return parentPlatform;
101 102 } else {
102   - wvpResult.setCode(-1);
103   - wvpResult.setMsg("未查询到此平台");
  103 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "未查询到此平台");
104 104 }
105   - return new ResponseEntity<>(wvpResult, HttpStatus.OK);
106 105 }
107 106  
108 107 /**
... ... @@ -137,38 +136,31 @@ public class PlatformController {
137 136 @Operation(summary = "添加上级平台信息")
138 137 @PostMapping("/add")
139 138 @ResponseBody
140   - public ResponseEntity<WVPResult<String>> addPlatform(@RequestBody ParentPlatform parentPlatform) {
  139 + public String addPlatform(@RequestBody ParentPlatform parentPlatform) {
141 140  
142 141 if (logger.isDebugEnabled()) {
143 142 logger.debug("保存上级平台信息API调用");
144 143 }
145   - WVPResult<String> wvpResult = new WVPResult<>();
146   - if (StringUtils.isEmpty(parentPlatform.getName())
147   - || StringUtils.isEmpty(parentPlatform.getServerGBId())
148   - || StringUtils.isEmpty(parentPlatform.getServerGBDomain())
149   - || StringUtils.isEmpty(parentPlatform.getServerIP())
150   - || StringUtils.isEmpty(parentPlatform.getServerPort())
151   - || StringUtils.isEmpty(parentPlatform.getDeviceGBId())
152   - || StringUtils.isEmpty(parentPlatform.getExpires())
153   - || StringUtils.isEmpty(parentPlatform.getKeepTimeout())
154   - || StringUtils.isEmpty(parentPlatform.getTransport())
155   - || StringUtils.isEmpty(parentPlatform.getCharacterSet())
  144 + if (ObjectUtils.isEmpty(parentPlatform.getName())
  145 + || ObjectUtils.isEmpty(parentPlatform.getServerGBId())
  146 + || ObjectUtils.isEmpty(parentPlatform.getServerGBDomain())
  147 + || ObjectUtils.isEmpty(parentPlatform.getServerIP())
  148 + || ObjectUtils.isEmpty(parentPlatform.getServerPort())
  149 + || ObjectUtils.isEmpty(parentPlatform.getDeviceGBId())
  150 + || ObjectUtils.isEmpty(parentPlatform.getExpires())
  151 + || ObjectUtils.isEmpty(parentPlatform.getKeepTimeout())
  152 + || ObjectUtils.isEmpty(parentPlatform.getTransport())
  153 + || ObjectUtils.isEmpty(parentPlatform.getCharacterSet())
156 154 ) {
157   - wvpResult.setCode(-1);
158   - wvpResult.setMsg("missing parameters");
159   - return new ResponseEntity<>(wvpResult, HttpStatus.BAD_REQUEST);
  155 + throw new ControllerException(ErrorCode.ERROR400);
160 156 }
161 157 if (parentPlatform.getServerPort() < 0 || parentPlatform.getServerPort() > 65535) {
162   - wvpResult.setCode(-1);
163   - wvpResult.setMsg("error severPort");
164   - return new ResponseEntity<>(wvpResult, HttpStatus.BAD_REQUEST);
  158 + throw new ControllerException(ErrorCode.ERROR400.getCode(), "error severPort");
165 159 }
166 160  
167 161 ParentPlatform parentPlatformOld = storager.queryParentPlatByServerGBId(parentPlatform.getServerGBId());
168 162 if (parentPlatformOld != null) {
169   - wvpResult.setCode(-1);
170   - wvpResult.setMsg("平台 " + parentPlatform.getServerGBId() + " 已存在");
171   - return new ResponseEntity<>(wvpResult, HttpStatus.OK);
  163 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "平台 " + parentPlatform.getServerGBId() + " 已存在");
172 164 }
173 165 parentPlatform.setCreateTime(DateUtil.getNow());
174 166 parentPlatform.setUpdateTime(DateUtil.getNow());
... ... @@ -190,13 +182,9 @@ public class PlatformController {
190 182 } else if (parentPlatformOld != null && parentPlatformOld.isEnable() && !parentPlatform.isEnable()) { // 关闭启用时注销
191 183 commanderForPlatform.unregister(parentPlatform, null, null);
192 184 }
193   - wvpResult.setCode(0);
194   - wvpResult.setMsg("success");
195   - return new ResponseEntity<>(wvpResult, HttpStatus.OK);
  185 + return null;
196 186 } else {
197   - wvpResult.setCode(-1);
198   - wvpResult.setMsg("写入数据库失败");
199   - return new ResponseEntity<>(wvpResult, HttpStatus.OK);
  187 + throw new ControllerException(ErrorCode.ERROR100.getCode(),"写入数据库失败");
200 188 }
201 189 }
202 190  
... ... @@ -209,26 +197,23 @@ public class PlatformController {
209 197 @Operation(summary = "保存上级平台信息")
210 198 @PostMapping("/save")
211 199 @ResponseBody
212   - public ResponseEntity<WVPResult<String>> savePlatform(@RequestBody ParentPlatform parentPlatform) {
  200 + public String savePlatform(@RequestBody ParentPlatform parentPlatform) {
213 201  
214 202 if (logger.isDebugEnabled()) {
215 203 logger.debug("保存上级平台信息API调用");
216 204 }
217   - WVPResult<String> wvpResult = new WVPResult<>();
218   - if (StringUtils.isEmpty(parentPlatform.getName())
219   - || StringUtils.isEmpty(parentPlatform.getServerGBId())
220   - || StringUtils.isEmpty(parentPlatform.getServerGBDomain())
221   - || StringUtils.isEmpty(parentPlatform.getServerIP())
222   - || StringUtils.isEmpty(parentPlatform.getServerPort())
223   - || StringUtils.isEmpty(parentPlatform.getDeviceGBId())
224   - || StringUtils.isEmpty(parentPlatform.getExpires())
225   - || StringUtils.isEmpty(parentPlatform.getKeepTimeout())
226   - || StringUtils.isEmpty(parentPlatform.getTransport())
227   - || StringUtils.isEmpty(parentPlatform.getCharacterSet())
  205 + if (ObjectUtils.isEmpty(parentPlatform.getName())
  206 + || ObjectUtils.isEmpty(parentPlatform.getServerGBId())
  207 + || ObjectUtils.isEmpty(parentPlatform.getServerGBDomain())
  208 + || ObjectUtils.isEmpty(parentPlatform.getServerIP())
  209 + || ObjectUtils.isEmpty(parentPlatform.getServerPort())
  210 + || ObjectUtils.isEmpty(parentPlatform.getDeviceGBId())
  211 + || ObjectUtils.isEmpty(parentPlatform.getExpires())
  212 + || ObjectUtils.isEmpty(parentPlatform.getKeepTimeout())
  213 + || ObjectUtils.isEmpty(parentPlatform.getTransport())
  214 + || ObjectUtils.isEmpty(parentPlatform.getCharacterSet())
228 215 ) {
229   - wvpResult.setCode(-1);
230   - wvpResult.setMsg("missing parameters");
231   - return new ResponseEntity<>(wvpResult, HttpStatus.BAD_REQUEST);
  216 + throw new ControllerException(ErrorCode.ERROR400);
232 217 }
233 218 parentPlatform.setCharacterSet(parentPlatform.getCharacterSet().toUpperCase());
234 219 ParentPlatform parentPlatformOld = storager.queryParentPlatByServerGBId(parentPlatform.getServerGBId());
... ... @@ -262,13 +247,9 @@ public class PlatformController {
262 247 // 停止订阅相关的定时任务
263 248 subscribeHolder.removeAllSubscribe(parentPlatform.getServerGBId());
264 249 }
265   - wvpResult.setCode(0);
266   - wvpResult.setMsg("success");
267   - return new ResponseEntity<>(wvpResult, HttpStatus.OK);
  250 + return null;
268 251 } else {
269   - wvpResult.setCode(0);
270   - wvpResult.setMsg("写入数据库失败");
271   - return new ResponseEntity<>(wvpResult, HttpStatus.OK);
  252 + throw new ControllerException(ErrorCode.ERROR100.getCode(),"写入数据库失败");
272 253 }
273 254 }
274 255  
... ... @@ -282,18 +263,18 @@ public class PlatformController {
282 263 @Parameter(name = "serverGBId", description = "上级平台的国标编号")
283 264 @DeleteMapping("/delete/{serverGBId}")
284 265 @ResponseBody
285   - public ResponseEntity<String> deletePlatform(@PathVariable String serverGBId) {
  266 + public String deletePlatform(@PathVariable String serverGBId) {
286 267  
287 268 if (logger.isDebugEnabled()) {
288 269 logger.debug("删除上级平台API调用");
289 270 }
290   - if (StringUtils.isEmpty(serverGBId)
  271 + if (ObjectUtils.isEmpty(serverGBId)
291 272 ) {
292   - return new ResponseEntity<>("missing parameters", HttpStatus.BAD_REQUEST);
  273 + throw new ControllerException(ErrorCode.ERROR400);
293 274 }
294 275 ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(serverGBId);
295 276 if (parentPlatform == null) {
296   - return new ResponseEntity<>("fail", HttpStatus.OK);
  277 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "平台不存在");
297 278 }
298 279 // 发送离线消息,无论是否成功都删除缓存
299 280 commanderForPlatform.unregister(parentPlatform, (event -> {
... ... @@ -317,9 +298,9 @@ public class PlatformController {
317 298 // 删除缓存的订阅信息
318 299 subscribeHolder.removeAllSubscribe(parentPlatform.getServerGBId());
319 300 if (deleteResult) {
320   - return new ResponseEntity<>("success", HttpStatus.OK);
  301 + return null;
321 302 } else {
322   - return new ResponseEntity<>("fail", HttpStatus.OK);
  303 + throw new ControllerException(ErrorCode.ERROR100);
323 304 }
324 305 }
325 306  
... ... @@ -333,10 +314,10 @@ public class PlatformController {
333 314 @Parameter(name = "serverGBId", description = "上级平台的国标编号")
334 315 @GetMapping("/exit/{serverGBId}")
335 316 @ResponseBody
336   - public ResponseEntity<String> exitPlatform(@PathVariable String serverGBId) {
  317 + public Boolean exitPlatform(@PathVariable String serverGBId) {
337 318  
338 319 ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(serverGBId);
339   - return new ResponseEntity<>(String.valueOf(parentPlatform != null), HttpStatus.OK);
  320 + return parentPlatform != null;
340 321 }
341 322  
342 323 /**
... ... @@ -367,13 +348,13 @@ public class PlatformController {
367 348 @RequestParam(required = false) Boolean online,
368 349 @RequestParam(required = false) Boolean channelType) {
369 350  
370   - if (StringUtils.isEmpty(platformId)) {
  351 + if (ObjectUtils.isEmpty(platformId)) {
371 352 platformId = null;
372 353 }
373   - if (StringUtils.isEmpty(query)) {
  354 + if (ObjectUtils.isEmpty(query)) {
374 355 query = null;
375 356 }
376   - if (StringUtils.isEmpty(platformId) || StringUtils.isEmpty(catalogId)) {
  357 + if (ObjectUtils.isEmpty(platformId) || ObjectUtils.isEmpty(catalogId)) {
377 358 catalogId = null;
378 359 }
379 360 PageInfo<ChannelReduce> channelReduces = storager.queryAllChannelList(page, count, query, online, channelType, platformId, catalogId);
... ... @@ -390,14 +371,15 @@ public class PlatformController {
390 371 @Operation(summary = "向上级平台添加国标通道")
391 372 @PostMapping("/update_channel_for_gb")
392 373 @ResponseBody
393   - public ResponseEntity<String> updateChannelForGB(@RequestBody UpdateChannelParam param) {
  374 + public void updateChannelForGB(@RequestBody UpdateChannelParam param) {
394 375  
395 376 if (logger.isDebugEnabled()) {
396 377 logger.debug("给上级平台添加国标通道API调用");
397 378 }
398 379 int result = platformChannelService.updateChannelForGB(param.getPlatformId(), param.getChannelReduces(), param.getCatalogId());
399   -
400   - return new ResponseEntity<>(String.valueOf(result > 0), HttpStatus.OK);
  380 + if (result <= 0) {
  381 + throw new ControllerException(ErrorCode.ERROR100);
  382 + }
401 383 }
402 384  
403 385 /**
... ... @@ -409,14 +391,16 @@ public class PlatformController {
409 391 @Operation(summary = "从上级平台移除国标通道")
410 392 @DeleteMapping("/del_channel_for_gb")
411 393 @ResponseBody
412   - public ResponseEntity<String> delChannelForGB(@RequestBody UpdateChannelParam param) {
  394 + public void delChannelForGB(@RequestBody UpdateChannelParam param) {
413 395  
414 396 if (logger.isDebugEnabled()) {
415 397 logger.debug("给上级平台删除国标通道API调用");
416 398 }
417 399 int result = storager.delChannelForGB(param.getPlatformId(), param.getChannelReduces());
418 400  
419   - return new ResponseEntity<>(String.valueOf(result > 0), HttpStatus.OK);
  401 + if (result <= 0) {
  402 + throw new ControllerException(ErrorCode.ERROR100);
  403 + }
420 404 }
421 405  
422 406 /**
... ... @@ -431,25 +415,20 @@ public class PlatformController {
431 415 @Parameter(name = "parentId", description = "父级目录的国标编号", required = true)
432 416 @GetMapping("/catalog")
433 417 @ResponseBody
434   - public ResponseEntity<WVPResult<List<PlatformCatalog>>> getCatalogByPlatform(String platformId, String parentId) {
  418 + public List<PlatformCatalog> getCatalogByPlatform(String platformId, String parentId) {
435 419  
436 420 if (logger.isDebugEnabled()) {
437 421 logger.debug("查询目录,platformId: {}, parentId: {}", platformId, parentId);
438 422 }
439 423 ParentPlatform platform = storager.queryParentPlatByServerGBId(platformId);
440 424 if (platform == null) {
441   - return new ResponseEntity<>(new WVPResult<>(400, "平台未找到", null), HttpStatus.OK);
  425 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "平台未找到");
442 426 }
443 427 if (platformId.equals(parentId)) {
444 428 parentId = platform.getDeviceGBId();
445 429 }
446   - List<PlatformCatalog> platformCatalogList = storager.getChildrenCatalogByPlatform(platformId, parentId);
447 430  
448   - WVPResult<List<PlatformCatalog>> result = new WVPResult<>();
449   - result.setCode(0);
450   - result.setMsg("success");
451   - result.setData(platformCatalogList);
452   - return new ResponseEntity<>(result, HttpStatus.OK);
  431 + return storager.getChildrenCatalogByPlatform(platformId, parentId);
453 432 }
454 433  
455 434 /**
... ... @@ -461,28 +440,19 @@ public class PlatformController {
461 440 @Operation(summary = "添加目录")
462 441 @PostMapping("/catalog/add")
463 442 @ResponseBody
464   - public ResponseEntity<WVPResult<List<PlatformCatalog>>> addCatalog(@RequestBody PlatformCatalog platformCatalog) {
  443 + public void addCatalog(@RequestBody PlatformCatalog platformCatalog) {
465 444  
466 445 if (logger.isDebugEnabled()) {
467 446 logger.debug("添加目录,{}", JSON.toJSONString(platformCatalog));
468 447 }
469 448 PlatformCatalog platformCatalogInStore = storager.getCatalog(platformCatalog.getId());
470   - WVPResult<List<PlatformCatalog>> result = new WVPResult<>();
471 449  
472 450 if (platformCatalogInStore != null) {
473   - result.setCode(-1);
474   - result.setMsg(platformCatalog.getId() + " already exists");
475   - return new ResponseEntity<>(result, HttpStatus.OK);
  451 + throw new ControllerException(ErrorCode.ERROR100.getCode(), platformCatalog.getId() + " already exists");
476 452 }
477 453 int addResult = storager.addCatalog(platformCatalog);
478   - if (addResult > 0) {
479   - result.setCode(0);
480   - result.setMsg("success");
481   - return new ResponseEntity<>(result, HttpStatus.OK);
482   - } else {
483   - result.setCode(-500);
484   - result.setMsg("save error");
485   - return new ResponseEntity<>(result, HttpStatus.OK);
  454 + if (addResult <= 0) {
  455 + throw new ControllerException(ErrorCode.ERROR100);
486 456 }
487 457 }
488 458  
... ... @@ -495,26 +465,19 @@ public class PlatformController {
495 465 @Operation(summary = "编辑目录")
496 466 @PostMapping("/catalog/edit")
497 467 @ResponseBody
498   - public ResponseEntity<WVPResult<List<PlatformCatalog>>> editCatalog(@RequestBody PlatformCatalog platformCatalog) {
  468 + public void editCatalog(@RequestBody PlatformCatalog platformCatalog) {
499 469  
500 470 if (logger.isDebugEnabled()) {
501 471 logger.debug("编辑目录,{}", JSON.toJSONString(platformCatalog));
502 472 }
503 473 PlatformCatalog platformCatalogInStore = storager.getCatalog(platformCatalog.getId());
504   - WVPResult<List<PlatformCatalog>> result = new WVPResult<>();
505   - result.setCode(0);
506 474  
507 475 if (platformCatalogInStore == null) {
508   - result.setMsg(platformCatalog.getId() + " not exists");
509   - return new ResponseEntity<>(result, HttpStatus.OK);
  476 + throw new ControllerException(ErrorCode.ERROR100.getCode(), platformCatalog.getId() + " not exists");
510 477 }
511 478 int addResult = storager.updateCatalog(platformCatalog);
512   - if (addResult > 0) {
513   - result.setMsg("success");
514   - return new ResponseEntity<>(result, HttpStatus.OK);
515   - } else {
516   - result.setMsg("save error");
517   - return new ResponseEntity<>(result, HttpStatus.OK);
  479 + if (addResult <= 0) {
  480 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "写入数据库失败");
518 481 }
519 482 }
520 483  
... ... @@ -530,19 +493,15 @@ public class PlatformController {
530 493 @Parameter(name = "platformId", description = "平台Id", required = true)
531 494 @DeleteMapping("/catalog/del")
532 495 @ResponseBody
533   - public ResponseEntity<WVPResult<String>> delCatalog(String id, String platformId) {
  496 + public void delCatalog(String id, String platformId) {
534 497  
535 498 if (logger.isDebugEnabled()) {
536 499 logger.debug("删除目录,{}", id);
537 500 }
538   - WVPResult<String> result = new WVPResult<>();
539 501  
540   - if (StringUtils.isEmpty(id) || StringUtils.isEmpty(platformId)) {
541   - result.setCode(-1);
542   - result.setMsg("param error");
543   - return new ResponseEntity<>(result, HttpStatus.BAD_REQUEST);
  502 + if (ObjectUtils.isEmpty(id) || ObjectUtils.isEmpty(platformId)) {
  503 + throw new ControllerException(ErrorCode.ERROR400);
544 504 }
545   - result.setCode(0);
546 505  
547 506 int delResult = storager.delCatalog(id);
548 507 // 如果删除的是默认目录则根目录设置为默认目录
... ... @@ -551,16 +510,10 @@ public class PlatformController {
551 510 // 默认节点被移除
552 511 if (parentPlatform == null) {
553 512 storager.setDefaultCatalog(platformId, platformId);
554   - result.setData(platformId);
555 513 }
556 514  
557   -
558   - if (delResult > 0) {
559   - result.setMsg("success");
560   - return new ResponseEntity<>(result, HttpStatus.OK);
561   - } else {
562   - result.setMsg("save error");
563   - return new ResponseEntity<>(result, HttpStatus.OK);
  515 + if (delResult <= 0) {
  516 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "写入数据库失败");
564 517 }
565 518 }
566 519  
... ... @@ -573,21 +526,15 @@ public class PlatformController {
573 526 @Operation(summary = "删除关联")
574 527 @DeleteMapping("/catalog/relation/del")
575 528 @ResponseBody
576   - public ResponseEntity<WVPResult<List<PlatformCatalog>>> delRelation(@RequestBody PlatformCatalog platformCatalog) {
  529 + public void delRelation(@RequestBody PlatformCatalog platformCatalog) {
577 530  
578 531 if (logger.isDebugEnabled()) {
579 532 logger.debug("删除关联,{}", JSON.toJSONString(platformCatalog));
580 533 }
581 534 int delResult = storager.delRelation(platformCatalog);
582   - WVPResult<List<PlatformCatalog>> result = new WVPResult<>();
583   - result.setCode(0);
584 535  
585   - if (delResult > 0) {
586   - result.setMsg("success");
587   - return new ResponseEntity<>(result, HttpStatus.OK);
588   - } else {
589   - result.setMsg("save error");
590   - return new ResponseEntity<>(result, HttpStatus.OK);
  536 + if (delResult <= 0) {
  537 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "写入数据库失败");
591 538 }
592 539 }
593 540  
... ... @@ -604,21 +551,15 @@ public class PlatformController {
604 551 @Parameter(name = "platformId", description = "平台Id", required = true)
605 552 @PostMapping("/catalog/default/update")
606 553 @ResponseBody
607   - public ResponseEntity<WVPResult<String>> setDefaultCatalog(String platformId, String catalogId) {
  554 + public void setDefaultCatalog(String platformId, String catalogId) {
608 555  
609 556 if (logger.isDebugEnabled()) {
610 557 logger.debug("修改默认目录,{},{}", platformId, catalogId);
611 558 }
612 559 int updateResult = storager.setDefaultCatalog(platformId, catalogId);
613   - WVPResult<String> result = new WVPResult<>();
614   - result.setCode(0);
615 560  
616   - if (updateResult > 0) {
617   - result.setMsg("success");
618   - return new ResponseEntity<>(result, HttpStatus.OK);
619   - } else {
620   - result.setMsg("save error");
621   - return new ResponseEntity<>(result, HttpStatus.OK);
  561 + if (updateResult <= 0) {
  562 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "写入数据库失败");
622 563 }
623 564 }
624 565  
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java
... ... @@ -2,6 +2,7 @@ package com.genersoft.iot.vmp.vmanager.gb28181.play;
2 2  
3 3 import com.alibaba.fastjson.JSONArray;
4 4 import com.genersoft.iot.vmp.common.StreamInfo;
  5 +import com.genersoft.iot.vmp.conf.exception.ControllerException;
5 6 import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction;
6 7 import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
7 8 import com.genersoft.iot.vmp.gb28181.bean.Device;
... ... @@ -11,6 +12,7 @@ import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
11 12 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
12 13 import com.genersoft.iot.vmp.service.IMediaServerService;
13 14 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
  15 +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
14 16 import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
15 17 import com.genersoft.iot.vmp.vmanager.gb28181.play.bean.PlayResult;
16 18 import com.genersoft.iot.vmp.service.IMediaService;
... ... @@ -22,8 +24,6 @@ import io.swagger.v3.oas.annotations.tags.Tag;
22 24 import org.slf4j.Logger;
23 25 import org.slf4j.LoggerFactory;
24 26 import org.springframework.beans.factory.annotation.Autowired;
25   -import org.springframework.http.HttpStatus;
26   -import org.springframework.http.ResponseEntity;
27 27 import org.springframework.web.bind.annotation.CrossOrigin;
28 28 import org.springframework.web.bind.annotation.GetMapping;
29 29 import org.springframework.web.bind.annotation.PathVariable;
... ... @@ -78,7 +78,7 @@ public class PlayController {
78 78 @Parameter(name = "deviceId", description = "设备国标编号", required = true)
79 79 @Parameter(name = "channelId", description = "通道国标编号", required = true)
80 80 @GetMapping("/start/{deviceId}/{channelId}")
81   - public DeferredResult<ResponseEntity<String>> play(@PathVariable String deviceId,
  81 + public DeferredResult<WVPResult<String>> play(@PathVariable String deviceId,
82 82 @PathVariable String channelId) {
83 83  
84 84 // 获取可用的zlm
... ... @@ -94,169 +94,115 @@ public class PlayController {
94 94 @Parameter(name = "deviceId", description = "设备国标编号", required = true)
95 95 @Parameter(name = "channelId", description = "通道国标编号", required = true)
96 96 @GetMapping("/stop/{deviceId}/{channelId}")
97   - public DeferredResult<ResponseEntity<String>> playStop(@PathVariable String deviceId, @PathVariable String channelId) {
  97 + public JSONObject playStop(@PathVariable String deviceId, @PathVariable String channelId) {
98 98  
99 99 logger.debug(String.format("设备预览/回放停止API调用,streamId:%s_%s", deviceId, channelId ));
100 100  
101   - String uuid = UUID.randomUUID().toString();
102   - DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>();
  101 + if (deviceId == null || channelId == null) {
  102 + throw new ControllerException(ErrorCode.ERROR400);
  103 + }
103 104  
104   - // 录像查询以channelId作为deviceId查询
105   - String key = DeferredResultHolder.CALLBACK_CMD_STOP + deviceId + channelId;
106   - resultHolder.put(key, uuid, result);
107 105 StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId);
108 106 if (streamInfo == null) {
109   - RequestMessage msg = new RequestMessage();
110   - msg.setId(uuid);
111   - msg.setKey(key);
112   - msg.setData("点播未找到");
113   - resultHolder.invokeAllResult(msg);
114   - storager.stopPlay(deviceId, channelId);
115   - return result;
  107 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "点播未找到");
116 108 }
117   - cmder.streamByeCmd(deviceId, channelId, streamInfo.getStream(), null, eventResult -> {
118   - redisCatchStorage.stopPlay(streamInfo);
119   - storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
120   - RequestMessage msgForSuccess = new RequestMessage();
121   - msgForSuccess.setId(uuid);
122   - msgForSuccess.setKey(key);
123   - msgForSuccess.setData(String.format("success"));
124   - resultHolder.invokeAllResult(msgForSuccess);
125   - });
126 109  
127   - if (deviceId != null || channelId != null) {
128   - JSONObject json = new JSONObject();
129   - json.put("deviceId", deviceId);
130   - json.put("channelId", channelId);
131   - RequestMessage msg = new RequestMessage();
132   - msg.setId(uuid);
133   - msg.setKey(key);
134   - msg.setData(json.toString());
135   - resultHolder.invokeAllResult(msg);
136   - } else {
137   - logger.warn("设备预览/回放停止API调用失败!");
138   - RequestMessage msg = new RequestMessage();
139   - msg.setId(uuid);
140   - msg.setKey(key);
141   - msg.setData("streamId null");
142   - resultHolder.invokeAllResult(msg);
143   - }
  110 + cmder.streamByeCmd(deviceId, channelId, streamInfo.getStream(), null, null);
  111 + redisCatchStorage.stopPlay(streamInfo);
  112 +
  113 + storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
  114 + JSONObject json = new JSONObject();
  115 + json.put("deviceId", deviceId);
  116 + json.put("channelId", channelId);
  117 + return json;
144 118  
145   - // 超时处理
146   - result.onTimeout(()->{
147   - logger.warn(String.format("设备预览/回放停止超时,deviceId/channelId:%s_%s ", deviceId, channelId));
148   - redisCatchStorage.stopPlay(streamInfo);
149   - storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
150   - RequestMessage msg = new RequestMessage();
151   - msg.setId(uuid);
152   - msg.setKey(key);
153   - msg.setData("Timeout");
154   - resultHolder.invokeAllResult(msg);
155   - });
156   - return result;
157 119 }
158 120  
159 121 /**
160 122 * 将不是h264的视频通过ffmpeg 转码为h264 + aac
161 123 * @param streamId 流ID
162   - * @return
163 124 */
164 125 @Operation(summary = "将不是h264的视频通过ffmpeg 转码为h264 + aac")
165 126 @Parameter(name = "streamId", description = "视频流ID", required = true)
166 127 @PostMapping("/convert/{streamId}")
167   - public ResponseEntity<String> playConvert(@PathVariable String streamId) {
  128 + public JSONObject playConvert(@PathVariable String streamId) {
168 129 StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId);
169 130 if (streamInfo == null) {
170 131 streamInfo = redisCatchStorage.queryPlayback(null, null, streamId, null);
171 132 }
172 133 if (streamInfo == null) {
173 134 logger.warn("视频转码API调用失败!, 视频流已经停止!");
174   - return new ResponseEntity<String>("未找到视频流信息, 视频流可能已经停止", HttpStatus.OK);
  135 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到视频流信息, 视频流可能已经停止");
175 136 }
176 137 MediaServerItem mediaInfo = mediaServerService.getOne(streamInfo.getMediaServerId());
177 138 JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(mediaInfo, streamId);
178 139 if (!rtpInfo.getBoolean("exist")) {
179 140 logger.warn("视频转码API调用失败!, 视频流已停止推流!");
180   - return new ResponseEntity<String>("推流信息在流媒体中不存在, 视频流可能已停止推流", HttpStatus.OK);
  141 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到视频流信息, 视频流可能已停止推流");
181 142 } else {
182 143 String dstUrl = String.format("rtmp://%s:%s/convert/%s", "127.0.0.1", mediaInfo.getRtmpPort(),
183 144 streamId );
184 145 String srcUrl = String.format("rtsp://%s:%s/rtp/%s", "127.0.0.1", mediaInfo.getRtspPort(), streamId);
185 146 JSONObject jsonObject = zlmresTfulUtils.addFFmpegSource(mediaInfo, srcUrl, dstUrl, "1000000", true, false, null);
186 147 logger.info(jsonObject.toJSONString());
187   - JSONObject result = new JSONObject();
188 148 if (jsonObject != null && jsonObject.getInteger("code") == 0) {
189   - result.put("code", 0);
190 149 JSONObject data = jsonObject.getJSONObject("data");
191 150 if (data != null) {
192   - result.put("key", data.getString("key"));
  151 + JSONObject result = new JSONObject();
  152 + result.put("key", data.getString("key"));
193 153 StreamInfo streamInfoResult = mediaService.getStreamInfoByAppAndStreamWithCheck("convert", streamId, mediaInfo.getId(), false);
194   - result.put("data", streamInfoResult);
  154 + result.put("StreamInfo", streamInfoResult);
  155 + return result;
  156 + }else {
  157 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "转码失败");
195 158 }
196 159 }else {
197   - result.put("code", 1);
198   - result.put("msg", "cover fail");
  160 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "转码失败");
199 161 }
200   - return new ResponseEntity<String>( result.toJSONString(), HttpStatus.OK);
201 162 }
202 163 }
203 164  
204 165 /**
205 166 * 结束转码
206   - * @param key
207   - * @return
208 167 */
209 168 @Operation(summary = "结束转码")
210 169 @Parameter(name = "key", description = "视频流key", required = true)
211 170 @Parameter(name = "mediaServerId", description = "流媒体服务ID", required = true)
212 171 @PostMapping("/convertStop/{key}")
213   - public ResponseEntity<String> playConvertStop(@PathVariable String key, String mediaServerId) {
214   - JSONObject result = new JSONObject();
  172 + public void playConvertStop(@PathVariable String key, String mediaServerId) {
215 173 if (mediaServerId == null) {
216   - result.put("code", 400);
217   - result.put("msg", "mediaServerId is null");
218   - return new ResponseEntity<String>( result.toJSONString(), HttpStatus.BAD_REQUEST);
  174 + throw new ControllerException(ErrorCode.ERROR400.getCode(), "流媒体:" + mediaServerId + "不存在" );
219 175 }
220 176 MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId);
221 177 if (mediaInfo == null) {
222   - result.put("code", 0);
223   - result.put("msg", "使用的流媒体已经停止运行");
224   - return new ResponseEntity<String>( result.toJSONString(), HttpStatus.OK);
  178 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "使用的流媒体已经停止运行" );
225 179 }else {
226 180 JSONObject jsonObject = zlmresTfulUtils.delFFmpegSource(mediaInfo, key);
227 181 logger.info(jsonObject.toJSONString());
228 182 if (jsonObject != null && jsonObject.getInteger("code") == 0) {
229   - result.put("code", 0);
230 183 JSONObject data = jsonObject.getJSONObject("data");
231   - if (data != null && data.getBoolean("flag")) {
232   - result.put("code", "0");
233   - result.put("msg", "success");
234   - }else {
235   -
  184 + if (data == null || data.getBoolean("flag") == null || !data.getBoolean("flag")) {
  185 + throw new ControllerException(ErrorCode.ERROR100 );
236 186 }
237 187 }else {
238   - result.put("code", 1);
239   - result.put("msg", "delFFmpegSource fail");
  188 + throw new ControllerException(ErrorCode.ERROR100 );
240 189 }
241   - return new ResponseEntity<String>( result.toJSONString(), HttpStatus.OK);
242 190 }
243   -
244   -
245 191 }
246 192  
247 193 @Operation(summary = "语音广播命令")
248 194 @Parameter(name = "deviceId", description = "设备国标编号", required = true)
249 195 @GetMapping("/broadcast/{deviceId}")
250 196 @PostMapping("/broadcast/{deviceId}")
251   - public DeferredResult<ResponseEntity<String>> broadcastApi(@PathVariable String deviceId) {
  197 + public DeferredResult<String> broadcastApi(@PathVariable String deviceId) {
252 198 if (logger.isDebugEnabled()) {
253 199 logger.debug("语音广播API调用");
254 200 }
255 201 Device device = storager.queryVideoDevice(deviceId);
256   - DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L);
  202 + DeferredResult<String> result = new DeferredResult<>(3 * 1000L);
257 203 String key = DeferredResultHolder.CALLBACK_CMD_BROADCAST + deviceId;
258 204 if (resultHolder.exist(key, null)) {
259   - result.setResult(new ResponseEntity<>("设备使用中",HttpStatus.OK));
  205 + result.setResult("设备使用中");
260 206 return result;
261 207 }
262 208 String uuid = UUID.randomUUID().toString();
... ... @@ -289,7 +235,7 @@ public class PlayController {
289 235 });
290 236  
291 237 result.onTimeout(() -> {
292   - logger.warn(String.format("语音广播操作超时, 设备未返回应答指令"));
  238 + logger.warn("语音广播操作超时, 设备未返回应答指令");
293 239 RequestMessage msg = new RequestMessage();
294 240 msg.setKey(key);
295 241 msg.setId(uuid);
... ... @@ -307,7 +253,7 @@ public class PlayController {
307 253  
308 254 @Operation(summary = "获取所有的ssrc")
309 255 @GetMapping("/ssrc")
310   - public WVPResult<JSONObject> getSSRC() {
  256 + public JSONObject getSSRC() {
311 257 if (logger.isDebugEnabled()) {
312 258 logger.debug("获取所有的ssrc");
313 259 }
... ... @@ -322,14 +268,10 @@ public class PlayController {
322 268 objects.add(jsonObject);
323 269 }
324 270  
325   - WVPResult<JSONObject> result = new WVPResult<>();
326   - result.setCode(0);
327   - result.setMsg("success");
328 271 JSONObject jsonObject = new JSONObject();
329 272 jsonObject.put("data", objects);
330 273 jsonObject.put("count", objects.size());
331   - result.setData(jsonObject);
332   - return result;
  274 + return jsonObject;
333 275 }
334 276  
335 277 }
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/bean/PlayResult.java
1 1 package com.genersoft.iot.vmp.vmanager.gb28181.play.bean;
2 2  
3 3 import com.genersoft.iot.vmp.gb28181.bean.Device;
  4 +import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
4 5 import org.springframework.http.ResponseEntity;
5 6 import org.springframework.web.context.request.async.DeferredResult;
6 7  
7 8 public class PlayResult {
8 9  
9   - private DeferredResult<ResponseEntity<String>> result;
  10 + private DeferredResult<WVPResult<String>> result;
10 11 private String uuid;
11 12  
12 13 private Device device;
13 14  
14   - public DeferredResult<ResponseEntity<String>> getResult() {
  15 + public DeferredResult<WVPResult<String>> getResult() {
15 16 return result;
16 17 }
17 18  
18   - public void setResult(DeferredResult<ResponseEntity<String>> result) {
  19 + public void setResult(DeferredResult<WVPResult<String>> result) {
19 20 this.result = result;
20 21 }
21 22  
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/playback/PlaybackController.java
1 1 package com.genersoft.iot.vmp.vmanager.gb28181.playback;
2 2  
3 3 import com.genersoft.iot.vmp.common.StreamInfo;
  4 +import com.genersoft.iot.vmp.conf.exception.ControllerException;
4 5 import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
5   -import com.genersoft.iot.vmp.service.IMediaServerService;
6 6 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
7 7 import com.genersoft.iot.vmp.service.IPlayService;
  8 +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
8 9 import io.swagger.v3.oas.annotations.Operation;
9 10 import io.swagger.v3.oas.annotations.Parameter;
10 11 import io.swagger.v3.oas.annotations.tags.Tag;
11 12 import org.slf4j.Logger;
12 13 import org.slf4j.LoggerFactory;
13 14 import org.springframework.beans.factory.annotation.Autowired;
14   -import org.springframework.http.HttpStatus;
15   -import org.springframework.http.ResponseEntity;
16   -import org.springframework.util.StringUtils;
  15 +import org.springframework.util.ObjectUtils;
17 16 import org.springframework.web.bind.annotation.CrossOrigin;
18 17 import org.springframework.web.bind.annotation.GetMapping;
19 18 import org.springframework.web.bind.annotation.PathVariable;
... ... @@ -26,6 +25,9 @@ import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
26 25 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
27 26 import org.springframework.web.context.request.async.DeferredResult;
28 27  
  28 +/**
  29 + * @author lin
  30 + */
29 31 @Tag(name = "视频回放")
30 32 @CrossOrigin
31 33 @RestController
... ... @@ -55,18 +57,16 @@ public class PlaybackController {
55 57 @Parameter(name = "startTime", description = "开始时间", required = true)
56 58 @Parameter(name = "endTime", description = "结束时间", required = true)
57 59 @GetMapping("/start/{deviceId}/{channelId}")
58   - public DeferredResult<ResponseEntity<String>> play(@PathVariable String deviceId, @PathVariable String channelId,
  60 + public DeferredResult<String> play(@PathVariable String deviceId, @PathVariable String channelId,
59 61 String startTime,String endTime) {
60 62  
61 63 if (logger.isDebugEnabled()) {
62 64 logger.debug(String.format("设备回放 API调用,deviceId:%s ,channelId:%s", deviceId, channelId));
63 65 }
64 66  
65   - DeferredResult<ResponseEntity<String>> result = playService.playBack(deviceId, channelId, startTime, endTime, null, wvpResult->{
66   - resultHolder.invokeResult(wvpResult.getData());
67   - });
68 67  
69   - return result;
  68 + return playService.playBack(deviceId, channelId, startTime, endTime, null,
  69 + playBackResult->resultHolder.invokeResult(playBackResult.getData()));
70 70 }
71 71  
72 72  
... ... @@ -75,67 +75,44 @@ public class PlaybackController {
75 75 @Parameter(name = "channelId", description = "通道国标编号", required = true)
76 76 @Parameter(name = "stream", description = "流ID", required = true)
77 77 @GetMapping("/stop/{deviceId}/{channelId}/{stream}")
78   - public ResponseEntity<String> playStop(
  78 + public void playStop(
79 79 @PathVariable String deviceId,
80 80 @PathVariable String channelId,
81 81 @PathVariable String stream) {
82   -
83   - cmder.streamByeCmd(deviceId, channelId, stream, null);
84   -
85   - if (logger.isDebugEnabled()) {
86   - logger.debug(String.format("设备录像回放停止 API调用,deviceId/channelId:%s/%s", deviceId, channelId));
87   - }
88   - if (StringUtils.isEmpty(deviceId) || StringUtils.isEmpty(channelId) || StringUtils.isEmpty(stream)) {
89   - return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
90   - }
91   -
92   - if (deviceId != null && channelId != null) {
93   - JSONObject json = new JSONObject();
94   - json.put("deviceId", deviceId);
95   - json.put("channelId", channelId);
96   - return new ResponseEntity<>(json.toString(), HttpStatus.OK);
97   - } else {
98   - logger.warn("设备录像回放停止API调用失败!");
99   - return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
  82 + if (ObjectUtils.isEmpty(deviceId) || ObjectUtils.isEmpty(channelId) || ObjectUtils.isEmpty(stream)) {
  83 + throw new ControllerException(ErrorCode.ERROR400);
100 84 }
  85 + cmder.streamByeCmd(deviceId, channelId, stream, null);
101 86 }
102 87  
103 88  
104 89 @Operation(summary = "回放暂停")
105 90 @Parameter(name = "streamId", description = "回放流ID", required = true)
106 91 @GetMapping("/pause/{streamId}")
107   - public ResponseEntity<String> playPause(@PathVariable String streamId) {
  92 + public void playPause(@PathVariable String streamId) {
108 93 logger.info("playPause: "+streamId);
109   - JSONObject json = new JSONObject();
110 94 StreamInfo streamInfo = redisCatchStorage.queryPlayback(null, null, streamId, null);
111 95 if (null == streamInfo) {
112   - json.put("msg", "streamId不存在");
113 96 logger.warn("streamId不存在!");
114   - return new ResponseEntity<String>(json.toString(), HttpStatus.BAD_REQUEST);
  97 + throw new ControllerException(ErrorCode.ERROR400.getCode(), "streamId不存在");
115 98 }
116 99 Device device = storager.queryVideoDevice(streamInfo.getDeviceID());
117 100 cmder.playPauseCmd(device, streamInfo);
118   - json.put("msg", "ok");
119   - return new ResponseEntity<String>(json.toString(), HttpStatus.OK);
120 101 }
121 102  
122 103  
123 104 @Operation(summary = "回放恢复")
124 105 @Parameter(name = "streamId", description = "回放流ID", required = true)
125 106 @GetMapping("/resume/{streamId}")
126   - public ResponseEntity<String> playResume(@PathVariable String streamId) {
  107 + public void playResume(@PathVariable String streamId) {
127 108 logger.info("playResume: "+streamId);
128   - JSONObject json = new JSONObject();
129 109 StreamInfo streamInfo = redisCatchStorage.queryPlayback(null, null, streamId, null);
130 110 if (null == streamInfo) {
131   - json.put("msg", "streamId不存在");
132 111 logger.warn("streamId不存在!");
133   - return new ResponseEntity<String>(json.toString(), HttpStatus.BAD_REQUEST);
  112 + throw new ControllerException(ErrorCode.ERROR400.getCode(), "streamId不存在");
134 113 }
135 114 Device device = storager.queryVideoDevice(streamInfo.getDeviceID());
136 115 cmder.playResumeCmd(device, streamInfo);
137   - json.put("msg", "ok");
138   - return new ResponseEntity<String>(json.toString(), HttpStatus.OK);
139 116 }
140 117  
141 118  
... ... @@ -143,43 +120,33 @@ public class PlaybackController {
143 120 @Parameter(name = "streamId", description = "回放流ID", required = true)
144 121 @Parameter(name = "seekTime", description = "拖动偏移量,单位s", required = true)
145 122 @GetMapping("/seek/{streamId}/{seekTime}")
146   - public ResponseEntity<String> playSeek(@PathVariable String streamId, @PathVariable long seekTime) {
  123 + public void playSeek(@PathVariable String streamId, @PathVariable long seekTime) {
147 124 logger.info("playSeek: "+streamId+", "+seekTime);
148   - JSONObject json = new JSONObject();
149 125 StreamInfo streamInfo = redisCatchStorage.queryPlayback(null, null, streamId, null);
150 126 if (null == streamInfo) {
151   - json.put("msg", "streamId不存在");
152 127 logger.warn("streamId不存在!");
153   - return new ResponseEntity<String>(json.toString(), HttpStatus.BAD_REQUEST);
  128 + throw new ControllerException(ErrorCode.ERROR400.getCode(), "streamId不存在");
154 129 }
155 130 Device device = storager.queryVideoDevice(streamInfo.getDeviceID());
156 131 cmder.playSeekCmd(device, streamInfo, seekTime);
157   - json.put("msg", "ok");
158   - return new ResponseEntity<String>(json.toString(), HttpStatus.OK);
159 132 }
160 133  
161 134 @Operation(summary = "回放倍速播放")
162 135 @Parameter(name = "streamId", description = "回放流ID", required = true)
163 136 @Parameter(name = "speed", description = "倍速0.25 0.5 1、2、4", required = true)
164 137 @GetMapping("/speed/{streamId}/{speed}")
165   - public ResponseEntity<String> playSpeed(@PathVariable String streamId, @PathVariable Double speed) {
  138 + public void playSpeed(@PathVariable String streamId, @PathVariable Double speed) {
166 139 logger.info("playSpeed: "+streamId+", "+speed);
167   - JSONObject json = new JSONObject();
168 140 StreamInfo streamInfo = redisCatchStorage.queryPlayback(null, null, streamId, null);
169 141 if (null == streamInfo) {
170   - json.put("msg", "streamId不存在");
171 142 logger.warn("streamId不存在!");
172   - return new ResponseEntity<String>(json.toString(), HttpStatus.BAD_REQUEST);
  143 + throw new ControllerException(ErrorCode.ERROR400.getCode(), "streamId不存在");
173 144 }
174 145 if(speed != 0.25 && speed != 0.5 && speed != 1 && speed != 2.0 && speed != 4.0) {
175   - json.put("msg", "不支持的speed(0.25 0.5 1、2、4)");
176 146 logger.warn("不支持的speed: " + speed);
177   - return new ResponseEntity<String>(json.toString(), HttpStatus.BAD_REQUEST);
  147 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "不支持的speed(0.25 0.5 1、2、4)");
178 148 }
179 149 Device device = storager.queryVideoDevice(streamInfo.getDeviceID());
180 150 cmder.playSpeedCmd(device, streamInfo, speed);
181   - json.put("msg", "ok");
182   - return new ResponseEntity<String>(json.toString(), HttpStatus.OK);
183 151 }
184   -
185 152 }
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/ptz/PtzController.java
... ... @@ -7,8 +7,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
7 7 import org.slf4j.Logger;
8 8 import org.slf4j.LoggerFactory;
9 9 import org.springframework.beans.factory.annotation.Autowired;
10   -import org.springframework.http.HttpStatus;
11   -import org.springframework.http.ResponseEntity;
  10 +import org.springframework.util.ObjectUtils;
12 11 import org.springframework.util.StringUtils;
13 12 import org.springframework.web.bind.annotation.*;
14 13 import org.springframework.web.context.request.async.DeferredResult;
... ... @@ -46,7 +45,6 @@ public class PtzController {
46 45 * @param horizonSpeed 水平移动速度
47 46 * @param verticalSpeed 垂直移动速度
48 47 * @param zoomSpeed 缩放速度
49   - * @return String 控制结果
50 48 */
51 49  
52 50 @Operation(summary = "云台控制")
... ... @@ -57,7 +55,7 @@ public class PtzController {
57 55 @Parameter(name = "verticalSpeed", description = "垂直速度", required = true)
58 56 @Parameter(name = "zoomSpeed", description = "缩放速度", required = true)
59 57 @PostMapping("/control/{deviceId}/{channelId}")
60   - public ResponseEntity<String> ptz(@PathVariable String deviceId,@PathVariable String channelId, String command, int horizonSpeed, int verticalSpeed, int zoomSpeed){
  58 + public void ptz(@PathVariable String deviceId,@PathVariable String channelId, String command, int horizonSpeed, int verticalSpeed, int zoomSpeed){
61 59  
62 60 if (logger.isDebugEnabled()) {
63 61 logger.debug(String.format("设备云台控制 API调用,deviceId:%s ,channelId:%s ,command:%s ,horizonSpeed:%d ,verticalSpeed:%d ,zoomSpeed:%d",deviceId, channelId, command, horizonSpeed, verticalSpeed, zoomSpeed));
... ... @@ -96,13 +94,11 @@ public class PtzController {
96 94 cmdCode = 32;
97 95 break;
98 96 case "stop":
99   - cmdCode = 0;
100 97 break;
101 98 default:
102 99 break;
103 100 }
104 101 cmder.frontEndCmd(device, channelId, cmdCode, horizonSpeed, verticalSpeed, zoomSpeed);
105   - return new ResponseEntity<String>("success",HttpStatus.OK);
106 102 }
107 103  
108 104  
... ... @@ -114,7 +110,7 @@ public class PtzController {
114 110 @Parameter(name = "parameter2", description = "数据二", required = true)
115 111 @Parameter(name = "combindCode2", description = "组合码二", required = true)
116 112 @PostMapping("/front_end_command/{deviceId}/{channelId}")
117   - public ResponseEntity<String> frontEndCommand(@PathVariable String deviceId,@PathVariable String channelId,int cmdCode, int parameter1, int parameter2, int combindCode2){
  113 + public void frontEndCommand(@PathVariable String deviceId,@PathVariable String channelId,int cmdCode, int parameter1, int parameter2, int combindCode2){
118 114  
119 115 if (logger.isDebugEnabled()) {
120 116 logger.debug(String.format("设备云台控制 API调用,deviceId:%s ,channelId:%s ,cmdCode:%d parameter1:%d parameter2:%d",deviceId, channelId, cmdCode, parameter1, parameter2));
... ... @@ -122,7 +118,6 @@ public class PtzController {
122 118 Device device = storager.queryVideoDevice(deviceId);
123 119  
124 120 cmder.frontEndCmd(device, channelId, cmdCode, parameter1, parameter2, combindCode2);
125   - return new ResponseEntity<String>("success",HttpStatus.OK);
126 121 }
127 122  
128 123  
... ... @@ -130,14 +125,14 @@ public class PtzController {
130 125 @Parameter(name = "deviceId", description = "设备国标编号", required = true)
131 126 @Parameter(name = "channelId", description = "通道国标编号", required = true)
132 127 @GetMapping("/preset/query/{deviceId}/{channelId}")
133   - public DeferredResult<ResponseEntity<String>> presetQueryApi(@PathVariable String deviceId, @PathVariable String channelId) {
  128 + public DeferredResult<String> presetQueryApi(@PathVariable String deviceId, @PathVariable String channelId) {
134 129 if (logger.isDebugEnabled()) {
135 130 logger.debug("设备预置位查询API调用");
136 131 }
137 132 Device device = storager.queryVideoDevice(deviceId);
138 133 String uuid = UUID.randomUUID().toString();
139   - String key = DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + (StringUtils.isEmpty(channelId) ? deviceId : channelId);
140   - DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String >> (3 * 1000L);
  134 + String key = DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + (ObjectUtils.isEmpty(channelId) ? deviceId : channelId);
  135 + DeferredResult<String> result = new DeferredResult<String> (3 * 1000L);
141 136 result.onTimeout(()->{
142 137 logger.warn(String.format("获取设备预置位超时"));
143 138 // 释放rtpserver
... ... @@ -158,7 +153,6 @@ public class PtzController {
158 153 msg.setData(String.format("获取设备预置位失败,错误码: %s, %s", event.statusCode, event.msg));
159 154 resultHolder.invokeResult(msg);
160 155 });
161   -
162 156 return result;
163 157 }
164 158 }
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/record/GBRecordController.java
... ... @@ -2,10 +2,12 @@ package com.genersoft.iot.vmp.vmanager.gb28181.record;
2 2  
3 3 import com.alibaba.fastjson.JSONObject;
4 4 import com.genersoft.iot.vmp.common.StreamInfo;
  5 +import com.genersoft.iot.vmp.conf.exception.ControllerException;
5 6 import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
6 7 import com.genersoft.iot.vmp.service.IMediaServerService;
7 8 import com.genersoft.iot.vmp.service.IPlayService;
8 9 import com.genersoft.iot.vmp.utils.DateUtil;
  10 +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
9 11 import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
10 12  
11 13 import io.swagger.v3.oas.annotations.Operation;
... ... @@ -58,28 +60,17 @@ public class GBRecordController {
58 60 @Parameter(name = "startTime", description = "开始时间", required = true)
59 61 @Parameter(name = "endTime", description = "结束时间", required = true)
60 62 @GetMapping("/query/{deviceId}/{channelId}")
61   - public DeferredResult<ResponseEntity<WVPResult<RecordInfo>>> recordinfo(@PathVariable String deviceId, @PathVariable String channelId, String startTime, String endTime){
  63 + public DeferredResult<WVPResult<RecordInfo>> recordinfo(@PathVariable String deviceId, @PathVariable String channelId, String startTime, String endTime){
62 64  
63 65 if (logger.isDebugEnabled()) {
64 66 logger.debug(String.format("录像信息查询 API调用,deviceId:%s ,startTime:%s, endTime:%s",deviceId, startTime, endTime));
65 67 }
66   - DeferredResult<ResponseEntity<WVPResult<RecordInfo>>> result = new DeferredResult<>();
  68 + DeferredResult<WVPResult<RecordInfo>> result = new DeferredResult<>();
67 69 if (!DateUtil.verification(startTime, DateUtil.formatter)){
68   - WVPResult<RecordInfo> wvpResult = new WVPResult<>();
69   - wvpResult.setCode(-1);
70   - wvpResult.setMsg("startTime error, format is " + DateUtil.PATTERN);
71   -
72   - ResponseEntity<WVPResult<RecordInfo>> resultResponseEntity = new ResponseEntity<>(wvpResult, HttpStatus.OK);
73   - result.setResult(resultResponseEntity);
74   - return result;
  70 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "startTime error, format is " + DateUtil.PATTERN);
75 71 }
76 72 if (!DateUtil.verification(endTime, DateUtil.formatter)){
77   - WVPResult<RecordInfo> wvpResult = new WVPResult<>();
78   - wvpResult.setCode(-1);
79   - wvpResult.setMsg("endTime error, format is " + DateUtil.PATTERN);
80   - ResponseEntity<WVPResult<RecordInfo>> resultResponseEntity = new ResponseEntity<>(wvpResult, HttpStatus.OK);
81   - result.setResult(resultResponseEntity);
82   - return result;
  73 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "endTime error, format is " + DateUtil.PATTERN);
83 74 }
84 75  
85 76 Device device = storager.queryVideoDevice(deviceId);
... ... @@ -92,7 +83,7 @@ public class GBRecordController {
92 83 msg.setKey(key);
93 84 cmder.recordInfoQuery(device, channelId, startTime, endTime, sn, null, null, null, (eventResult -> {
94 85 WVPResult<RecordInfo> wvpResult = new WVPResult<>();
95   - wvpResult.setCode(-1);
  86 + wvpResult.setCode(ErrorCode.ERROR100.getCode());
96 87 wvpResult.setMsg("查询录像失败, status: " + eventResult.statusCode + ", message: " + eventResult.msg);
97 88 msg.setData(wvpResult);
98 89 resultHolder.invokeResult(msg);
... ... @@ -103,7 +94,7 @@ public class GBRecordController {
103 94 result.onTimeout(()->{
104 95 msg.setData("timeout");
105 96 WVPResult<RecordInfo> wvpResult = new WVPResult<>();
106   - wvpResult.setCode(-1);
  97 + wvpResult.setCode(ErrorCode.ERROR100.getCode());
107 98 wvpResult.setMsg("timeout");
108 99 msg.setData(wvpResult);
109 100 resultHolder.invokeResult(msg);
... ... @@ -119,59 +110,14 @@ public class GBRecordController {
119 110 @Parameter(name = "endTime", description = "结束时间", required = true)
120 111 @Parameter(name = "downloadSpeed", description = "下载倍速", required = true)
121 112 @GetMapping("/download/start/{deviceId}/{channelId}")
122   - public DeferredResult<ResponseEntity<String>> download(@PathVariable String deviceId, @PathVariable String channelId,
  113 + public DeferredResult<String> download(@PathVariable String deviceId, @PathVariable String channelId,
123 114 String startTime, String endTime, String downloadSpeed) {
124 115  
125 116 if (logger.isDebugEnabled()) {
126 117 logger.debug(String.format("历史媒体下载 API调用,deviceId:%s,channelId:%s,downloadSpeed:%s", deviceId, channelId, downloadSpeed));
127 118 }
128   -// String key = DeferredResultHolder.CALLBACK_CMD_DOWNLOAD + deviceId + channelId;
129   -// String uuid = UUID.randomUUID().toString();
130   -// DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(30000L);
131   -// // 超时处理
132   -// result.onTimeout(()->{
133   -// logger.warn(String.format("设备下载响应超时,deviceId:%s ,channelId:%s", deviceId, channelId));
134   -// RequestMessage msg = new RequestMessage();
135   -// msg.setId(uuid);
136   -// msg.setKey(key);
137   -// msg.setData("Timeout");
138   -// resultHolder.invokeAllResult(msg);
139   -// });
140   -// if(resultHolder.exist(key, null)) {
141   -// return result;
142   -// }
143   -// resultHolder.put(key, uuid, result);
144   -// Device device = storager.queryVideoDevice(deviceId);
145   -//
146   -// MediaServerItem newMediaServerItem = playService.getNewMediaServerItem(device);
147   -// if (newMediaServerItem == null) {
148   -// logger.warn(String.format("设备下载响应超时,deviceId:%s ,channelId:%s", deviceId, channelId));
149   -// RequestMessage msg = new RequestMessage();
150   -// msg.setId(uuid);
151   -// msg.setKey(key);
152   -// msg.setData("Timeout");
153   -// resultHolder.invokeAllResult(msg);
154   -// return result;
155   -// }
156   -//
157   -// SSRCInfo ssrcInfo = mediaServerService.openRTPServer(newMediaServerItem, null, true);
158   -//
159   -// cmder.downloadStreamCmd(newMediaServerItem, ssrcInfo, device, channelId, startTime, endTime, downloadSpeed, (InviteStreamInfo inviteStreamInfo) -> {
160   -// logger.info("收到订阅消息: " + inviteStreamInfo.getResponse().toJSONString());
161   -// playService.onPublishHandlerForDownload(inviteStreamInfo, deviceId, channelId, uuid);
162   -// }, event -> {
163   -// RequestMessage msg = new RequestMessage();
164   -// msg.setId(uuid);
165   -// msg.setKey(key);
166   -// msg.setData(String.format("回放失败, 错误码: %s, %s", event.statusCode, event.msg));
167   -// resultHolder.invokeAllResult(msg);
168   -// });
169 119  
170   - if (logger.isDebugEnabled()) {
171   - logger.debug(String.format("设备回放 API调用,deviceId:%s ,channelId:%s", deviceId, channelId));
172   - }
173   -
174   - DeferredResult<ResponseEntity<String>> result = playService.download(deviceId, channelId, startTime, endTime, Integer.parseInt(downloadSpeed), null, hookCallBack->{
  120 + DeferredResult<String> result = playService.download(deviceId, channelId, startTime, endTime, Integer.parseInt(downloadSpeed), null, hookCallBack->{
175 121 resultHolder.invokeResult(hookCallBack.getData());
176 122 });
177 123  
... ... @@ -183,7 +129,7 @@ public class GBRecordController {
183 129 @Parameter(name = "channelId", description = "通道国标编号", required = true)
184 130 @Parameter(name = "stream", description = "流ID", required = true)
185 131 @GetMapping("/download/stop/{deviceId}/{channelId}/{stream}")
186   - public ResponseEntity<String> playStop(@PathVariable String deviceId, @PathVariable String channelId, @PathVariable String stream) {
  132 + public void playStop(@PathVariable String deviceId, @PathVariable String channelId, @PathVariable String stream) {
187 133  
188 134 cmder.streamByeCmd(deviceId, channelId, stream, null);
189 135  
... ... @@ -191,14 +137,8 @@ public class GBRecordController {
191 137 logger.debug(String.format("设备历史媒体下载停止 API调用,deviceId/channelId:%s_%s", deviceId, channelId));
192 138 }
193 139  
194   - if (deviceId != null && channelId != null) {
195   - JSONObject json = new JSONObject();
196   - json.put("deviceId", deviceId);
197   - json.put("channelId", channelId);
198   - return new ResponseEntity<String>(json.toString(), HttpStatus.OK);
199   - } else {
200   - logger.warn("设备历史媒体下载停止API调用失败!");
201   - return new ResponseEntity<String>(HttpStatus.INTERNAL_SERVER_ERROR);
  140 + if (deviceId == null || channelId == null) {
  141 + throw new ControllerException(ErrorCode.ERROR100);
202 142 }
203 143 }
204 144  
... ... @@ -207,9 +147,7 @@ public class GBRecordController {
207 147 @Parameter(name = "channelId", description = "通道国标编号", required = true)
208 148 @Parameter(name = "stream", description = "流ID", required = true)
209 149 @GetMapping("/download/progress/{deviceId}/{channelId}/{stream}")
210   - public ResponseEntity<StreamInfo> getProgress(@PathVariable String deviceId, @PathVariable String channelId, @PathVariable String stream) {
211   -
212   - StreamInfo streamInfo = playService.getDownLoadInfo(deviceId, channelId, stream);
213   - return new ResponseEntity<>(streamInfo, HttpStatus.OK);
  150 + public StreamInfo getProgress(@PathVariable String deviceId, @PathVariable String channelId, @PathVariable String stream) {
  151 + return playService.getDownLoadInfo(deviceId, channelId, stream);
214 152 }
215 153 }
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java
1 1 package com.genersoft.iot.vmp.vmanager.log;
2 2  
3 3 import com.genersoft.iot.vmp.conf.UserSetting;
  4 +import com.genersoft.iot.vmp.conf.exception.ControllerException;
4 5 import com.genersoft.iot.vmp.service.ILogService;
5 6 import com.genersoft.iot.vmp.storager.dao.dto.LogDto;
6 7 import com.genersoft.iot.vmp.utils.DateUtil;
  8 +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
7 9 import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
8 10 import com.github.pagehelper.PageInfo;
9 11  
... ... @@ -15,6 +17,7 @@ import org.slf4j.LoggerFactory;
15 17 import org.springframework.beans.factory.annotation.Autowired;
16 18 import org.springframework.http.HttpStatus;
17 19 import org.springframework.http.ResponseEntity;
  20 +import org.springframework.util.ObjectUtils;
18 21 import org.springframework.util.StringUtils;
19 22 import org.springframework.web.bind.annotation.*;
20 23  
... ... @@ -53,7 +56,7 @@ public class LogController {
53 56 @Parameter(name = "type", description = "类型", required = true)
54 57 @Parameter(name = "startTime", description = "开始时间", required = true)
55 58 @Parameter(name = "endTime", description = "结束时间", required = true)
56   - public ResponseEntity<PageInfo<LogDto>> getAll(
  59 + public PageInfo<LogDto> getAll(
57 60 @RequestParam int page,
58 61 @RequestParam int count,
59 62 @RequestParam(required = false) String query,
... ... @@ -61,13 +64,13 @@ public class LogController {
61 64 @RequestParam(required = false) String startTime,
62 65 @RequestParam(required = false) String endTime
63 66 ) {
64   - if (StringUtils.isEmpty(query)) {
  67 + if (ObjectUtils.isEmpty(query)) {
65 68 query = null;
66 69 }
67   - if (StringUtils.isEmpty(startTime)) {
  70 + if (ObjectUtils.isEmpty(startTime)) {
68 71 startTime = null;
69 72 }
70   - if (StringUtils.isEmpty(endTime)) {
  73 + if (ObjectUtils.isEmpty(endTime)) {
71 74 endTime = null;
72 75 }
73 76 if (!userSetting.getLogInDatebase()) {
... ... @@ -75,11 +78,10 @@ public class LogController {
75 78 }
76 79  
77 80 if (!DateUtil.verification(startTime, DateUtil.formatter) || !DateUtil.verification(endTime, DateUtil.formatter)){
78   - return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
  81 + throw new ControllerException(ErrorCode.ERROR400);
79 82 }
80 83  
81   - PageInfo<LogDto> allLog = logService.getAll(page, count, query, type, startTime, endTime);
82   - return new ResponseEntity<>(allLog, HttpStatus.OK);
  84 + return logService.getAll(page, count, query, type, startTime, endTime);
83 85 }
84 86  
85 87 /**
... ... @@ -88,14 +90,8 @@ public class LogController {
88 90 */
89 91 @Operation(summary = "停止视频回放")
90 92 @DeleteMapping("/clear")
91   - public ResponseEntity<WVPResult<String>> clear() {
92   -
93   - int count = logService.clear();
94   - WVPResult wvpResult = new WVPResult();
95   - wvpResult.setCode(0);
96   - wvpResult.setMsg("success");
97   - wvpResult.setData(count);
98   - return new ResponseEntity<WVPResult<String>>(wvpResult, HttpStatus.OK);
  93 + public void clear() {
  94 + logService.clear();
99 95 }
100 96  
101 97 }
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/server/ServerController.java
... ... @@ -4,24 +4,27 @@ import com.alibaba.fastjson.JSON;
4 4 import com.alibaba.fastjson.JSONObject;
5 5 import com.genersoft.iot.vmp.VManageBootstrap;
6 6 import com.genersoft.iot.vmp.common.VersionPo;
7   -import com.genersoft.iot.vmp.conf.DynamicTask;
8 7 import com.genersoft.iot.vmp.conf.SipConfig;
9 8 import com.genersoft.iot.vmp.conf.UserSetting;
10 9 import com.genersoft.iot.vmp.conf.VersionInfo;
  10 +import com.genersoft.iot.vmp.conf.exception.ControllerException;
11 11 import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe;
12 12 import com.genersoft.iot.vmp.media.zlm.dto.IHookSubscribe;
13 13 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
14 14 import com.genersoft.iot.vmp.service.IMediaServerService;
15 15 import com.genersoft.iot.vmp.utils.SpringBeanFactory;
  16 +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
16 17 import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
17 18 import gov.nist.javax.sip.SipStackImpl;
18 19  
19 20 import io.swagger.v3.oas.annotations.Operation;
20 21 import io.swagger.v3.oas.annotations.Parameter;
21 22 import io.swagger.v3.oas.annotations.tags.Tag;
  23 +import org.ehcache.xml.model.ThreadPoolsType;
22 24 import org.springframework.beans.factory.annotation.Autowired;
23 25 import org.springframework.beans.factory.annotation.Value;
24   -import org.springframework.context.ConfigurableApplicationContext;
  26 +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
  27 +import org.springframework.util.ObjectUtils;
25 28 import org.springframework.util.StringUtils;
26 29 import org.springframework.web.bind.annotation.*;
27 30  
... ... @@ -30,7 +33,6 @@ import javax.sip.ObjectInUseException;
30 33 import javax.sip.SipProvider;
31 34 import java.util.Iterator;
32 35 import java.util.List;
33   -import java.util.Set;
34 36  
35 37 @SuppressWarnings("rawtypes")
36 38 @Tag(name = "服务控制")
... ... @@ -54,45 +56,34 @@ public class ServerController {
54 56 @Autowired
55 57 private UserSetting userSetting;
56 58  
57   - @Autowired
58   - private DynamicTask dynamicTask;
59   -
60 59 @Value("${server.port}")
61 60 private int serverPort;
62 61  
63 62  
  63 + @Autowired
  64 + private ThreadPoolTaskExecutor taskExecutor;
  65 +
  66 +
64 67 @GetMapping(value = "/media_server/list")
65 68 @ResponseBody
66 69 @Operation(summary = "流媒体服务列表")
67   - public WVPResult<List<MediaServerItem>> getMediaServerList() {
68   - WVPResult<List<MediaServerItem>> result = new WVPResult<>();
69   - result.setCode(0);
70   - result.setMsg("success");
71   - result.setData(mediaServerService.getAll());
72   - return result;
  70 + public List<MediaServerItem> getMediaServerList() {
  71 + return mediaServerService.getAll();
73 72 }
74 73  
75 74 @GetMapping(value = "/media_server/online/list")
76 75 @ResponseBody
77 76 @Operation(summary = "在线流媒体服务列表")
78   - public WVPResult<List<MediaServerItem>> getOnlineMediaServerList() {
79   - WVPResult<List<MediaServerItem>> result = new WVPResult<>();
80   - result.setCode(0);
81   - result.setMsg("success");
82   - result.setData(mediaServerService.getAllOnline());
83   - return result;
  77 + public List<MediaServerItem> getOnlineMediaServerList() {
  78 + return mediaServerService.getAllOnline();
84 79 }
85 80  
86 81 @GetMapping(value = "/media_server/one/{id}")
87 82 @ResponseBody
88 83 @Operation(summary = "停止视频回放")
89 84 @Parameter(name = "id", description = "流媒体服务ID", required = true)
90   - public WVPResult<MediaServerItem> getMediaServer(@PathVariable String id) {
91   - WVPResult<MediaServerItem> result = new WVPResult<>();
92   - result.setCode(0);
93   - result.setMsg("success");
94   - result.setData(mediaServerService.getOne(id));
95   - return result;
  85 + public MediaServerItem getMediaServer(@PathVariable String id) {
  86 + return mediaServerService.getOne(id);
96 87 }
97 88  
98 89 @Operation(summary = "测试流媒体服务")
... ... @@ -101,7 +92,7 @@ public class ServerController {
101 92 @Parameter(name = "secret", description = "流媒体服务secret", required = true)
102 93 @GetMapping(value = "/media_server/check")
103 94 @ResponseBody
104   - public WVPResult<MediaServerItem> checkMediaServer(@RequestParam String ip, @RequestParam int port, @RequestParam String secret) {
  95 + public MediaServerItem checkMediaServer(@RequestParam String ip, @RequestParam int port, @RequestParam String secret) {
105 96 return mediaServerService.checkMediaServer(ip, port, secret);
106 97 }
107 98  
... ... @@ -110,122 +101,87 @@ public class ServerController {
110 101 @Parameter(name = "port", description = "流媒体服务HTT端口", required = true)
111 102 @GetMapping(value = "/media_server/record/check")
112 103 @ResponseBody
113   - public WVPResult<String> checkMediaRecordServer(@RequestParam String ip, @RequestParam int port) {
  104 + public void checkMediaRecordServer(@RequestParam String ip, @RequestParam int port) {
114 105 boolean checkResult = mediaServerService.checkMediaRecordServer(ip, port);
115   - WVPResult<String> result = new WVPResult<>();
116   - if (checkResult) {
117   - result.setCode(0);
118   - result.setMsg("success");
119   -
120   - } else {
121   - result.setCode(-1);
122   - result.setMsg("连接失败");
  106 + if (!checkResult) {
  107 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "连接失败");
123 108 }
124   - return result;
125 109 }
126 110  
127 111 @Operation(summary = "保存流媒体服务")
128 112 @Parameter(name = "mediaServerItem", description = "流媒体信息", required = true)
129 113 @PostMapping(value = "/media_server/save")
130 114 @ResponseBody
131   - public WVPResult<String> saveMediaServer(@RequestBody MediaServerItem mediaServerItem) {
  115 + public void saveMediaServer(@RequestBody MediaServerItem mediaServerItem) {
132 116 MediaServerItem mediaServerItemInDatabase = mediaServerService.getOne(mediaServerItem.getId());
133 117  
134 118 if (mediaServerItemInDatabase != null) {
135   - if (StringUtils.isEmpty(mediaServerItemInDatabase.getSendRtpPortRange()) && StringUtils.isEmpty(mediaServerItem.getSendRtpPortRange())) {
  119 + if (ObjectUtils.isEmpty(mediaServerItemInDatabase.getSendRtpPortRange()) && ObjectUtils.isEmpty(mediaServerItem.getSendRtpPortRange())) {
136 120 mediaServerItem.setSendRtpPortRange("30000,30500");
137 121 }
138 122 mediaServerService.update(mediaServerItem);
139 123 } else {
140   - if (StringUtils.isEmpty(mediaServerItem.getSendRtpPortRange())) {
  124 + if (ObjectUtils.isEmpty(mediaServerItem.getSendRtpPortRange())) {
141 125 mediaServerItem.setSendRtpPortRange("30000,30500");
142 126 }
143   - return mediaServerService.add(mediaServerItem);
  127 + mediaServerService.add(mediaServerItem);
144 128 }
145   -
146   - WVPResult<String> result = new WVPResult<>();
147   - result.setCode(0);
148   - result.setMsg("success");
149   - return result;
150 129 }
151 130  
152 131 @Operation(summary = "移除流媒体服务")
153 132 @Parameter(name = "id", description = "流媒体ID", required = true)
154 133 @DeleteMapping(value = "/media_server/delete")
155 134 @ResponseBody
156   - public WVPResult<String> deleteMediaServer(@RequestParam String id) {
157   - if (mediaServerService.getOne(id) != null) {
158   - mediaServerService.delete(id);
159   - mediaServerService.deleteDb(id);
160   - } else {
161   - WVPResult<String> result = new WVPResult<>();
162   - result.setCode(-1);
163   - result.setMsg("未找到此节点");
164   - return result;
  135 + public void deleteMediaServer(@RequestParam String id) {
  136 + if (mediaServerService.getOne(id) == null) {
  137 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到此节点");
165 138 }
166   - WVPResult<String> result = new WVPResult<>();
167   - result.setCode(0);
168   - result.setMsg("success");
169   - return result;
  139 + mediaServerService.delete(id);
  140 + mediaServerService.deleteDb(id);
170 141 }
171 142  
172 143  
173 144 @Operation(summary = "重启服务")
174 145 @GetMapping(value = "/restart")
175 146 @ResponseBody
176   - public Object restart() {
177   - Thread restartThread = new Thread(new Runnable() {
178   - @Override
179   - public void run() {
180   - try {
181   - Thread.sleep(3000);
182   - SipProvider up = (SipProvider) SpringBeanFactory.getBean("udpSipProvider");
183   - SipStackImpl stack = (SipStackImpl) up.getSipStack();
184   - stack.stop();
185   - Iterator listener = stack.getListeningPoints();
186   - while (listener.hasNext()) {
187   - stack.deleteListeningPoint((ListeningPoint) listener.next());
188   - }
189   - Iterator providers = stack.getSipProviders();
190   - while (providers.hasNext()) {
191   - stack.deleteSipProvider((SipProvider) providers.next());
192   - }
193   - VManageBootstrap.restart();
194   - } catch (InterruptedException ignored) {
195   - } catch (ObjectInUseException e) {
196   - e.printStackTrace();
  147 + public void restart() {
  148 + taskExecutor.execute(()-> {
  149 + try {
  150 + Thread.sleep(3000);
  151 + SipProvider up = (SipProvider) SpringBeanFactory.getBean("udpSipProvider");
  152 + SipStackImpl stack = (SipStackImpl) up.getSipStack();
  153 + stack.stop();
  154 + Iterator listener = stack.getListeningPoints();
  155 + while (listener.hasNext()) {
  156 + stack.deleteListeningPoint((ListeningPoint) listener.next());
  157 + }
  158 + Iterator providers = stack.getSipProviders();
  159 + while (providers.hasNext()) {
  160 + stack.deleteSipProvider((SipProvider) providers.next());
197 161 }
  162 + VManageBootstrap.restart();
  163 + } catch (InterruptedException | ObjectInUseException e) {
  164 + throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage());
198 165 }
199 166 });
200   -
201   - restartThread.setDaemon(false);
202   - restartThread.start();
203   - return "success";
204   - }
  167 + };
205 168  
206 169 @Operation(summary = "获取版本信息")
207 170 @GetMapping(value = "/version")
208 171 @ResponseBody
209   - public WVPResult<VersionPo> getVersion() {
210   - WVPResult<VersionPo> result = new WVPResult<>();
211   - result.setCode(0);
212   - result.setMsg("success");
213   - result.setData(versionInfo.getVersion());
214   - return result;
  172 + public VersionPo VersionPogetVersion() {
  173 + return versionInfo.getVersion();
215 174 }
216 175  
217 176 @GetMapping(value = "/config")
218 177 @Operation(summary = "获取配置信息")
219 178 @Parameter(name = "type", description = "配置类型(sip, base)", required = true)
220 179 @ResponseBody
221   - public WVPResult<JSONObject> getVersion(String type) {
222   - WVPResult<JSONObject> result = new WVPResult<>();
223   - result.setCode(0);
224   - result.setMsg("success");
  180 + public JSONObject getVersion(String type) {
225 181  
226 182 JSONObject jsonObject = new JSONObject();
227 183 jsonObject.put("server.port", serverPort);
228   - if (StringUtils.isEmpty(type)) {
  184 + if (ObjectUtils.isEmpty(type)) {
229 185 jsonObject.put("sip", JSON.toJSON(sipConfig));
230 186 jsonObject.put("base", JSON.toJSON(userSetting));
231 187 } else {
... ... @@ -240,50 +196,13 @@ public class ServerController {
240 196 break;
241 197 }
242 198 }
243   - result.setData(jsonObject);
244   - return result;
  199 + return jsonObject;
245 200 }
246 201  
247 202 @GetMapping(value = "/hooks")
248 203 @ResponseBody
249 204 @Operation(summary = "获取当前所有hook")
250   - public WVPResult<List<IHookSubscribe>> getHooks() {
251   - WVPResult<List<IHookSubscribe>> result = new WVPResult<>();
252   - result.setCode(0);
253   - result.setMsg("success");
254   - List<IHookSubscribe> all = zlmHttpHookSubscribe.getAll();
255   - result.setData(all);
256   - return result;
  205 + public List<IHookSubscribe> getHooks() {
  206 + return zlmHttpHookSubscribe.getAll();
257 207 }
258   -
259   -// //@ApiOperation("当前进行中的动态任务")
260   -// @GetMapping(value = "/dynamicTask")
261   -// @ResponseBody
262   -// public WVPResult<JSONObject> getDynamicTask(){
263   -// WVPResult<JSONObject> result = new WVPResult<>();
264   -// result.setCode(0);
265   -// result.setMsg("success");
266   -//
267   -// JSONObject jsonObject = new JSONObject();
268   -//
269   -// Set<String> allKeys = dynamicTask.getAllKeys();
270   -// jsonObject.put("server.port", serverPort);
271   -// if (StringUtils.isEmpty(type)) {
272   -// jsonObject.put("sip", JSON.toJSON(sipConfig));
273   -// jsonObject.put("base", JSON.toJSON(userSetting));
274   -// }else {
275   -// switch (type){
276   -// case "sip":
277   -// jsonObject.put("sip", sipConfig);
278   -// break;
279   -// case "base":
280   -// jsonObject.put("base", userSetting);
281   -// break;
282   -// default:
283   -// break;
284   -// }
285   -// }
286   -// result.setData(jsonObject);
287   -// return result;
288   -// }
289 208 }
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java
... ... @@ -2,12 +2,14 @@ package com.genersoft.iot.vmp.vmanager.streamProxy;
2 2  
3 3 import com.alibaba.fastjson.JSONObject;
4 4 import com.genersoft.iot.vmp.common.StreamInfo;
  5 +import com.genersoft.iot.vmp.conf.exception.ControllerException;
5 6 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
6 7 import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
7 8 import com.genersoft.iot.vmp.service.IMediaServerService;
8 9 import com.genersoft.iot.vmp.service.IMediaService;
9 10 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
10 11 import com.genersoft.iot.vmp.service.IStreamProxyService;
  12 +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
11 13 import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
12 14 import com.github.pagehelper.PageInfo;
13 15 import io.swagger.v3.oas.annotations.Operation;
... ... @@ -18,6 +20,7 @@ import org.slf4j.Logger;
18 20 import org.slf4j.LoggerFactory;
19 21 import org.springframework.beans.factory.annotation.Autowired;
20 22 import org.springframework.stereotype.Controller;
  23 +import org.springframework.util.ObjectUtils;
21 24 import org.springframework.util.StringUtils;
22 25 import org.springframework.web.bind.annotation.*;
23 26  
... ... @@ -34,10 +37,6 @@ public class StreamProxyController {
34 37 private final static Logger logger = LoggerFactory.getLogger(StreamProxyController.class);
35 38  
36 39 @Autowired
37   - private IRedisCatchStorage redisCatchStorage;
38   -
39   -
40   - @Autowired
41 40 private IMediaServerService mediaServerService;
42 41  
43 42 @Autowired
... ... @@ -64,35 +63,32 @@ public class StreamProxyController {
64 63 })
65 64 @PostMapping(value = "/save")
66 65 @ResponseBody
67   - public WVPResult save(@RequestBody StreamProxyItem param){
  66 + public StreamInfo save(@RequestBody StreamProxyItem param){
68 67 logger.info("添加代理: " + JSONObject.toJSONString(param));
69   - if (StringUtils.isEmpty(param.getMediaServerId())) {
  68 + if (ObjectUtils.isEmpty(param.getMediaServerId())) {
70 69 param.setMediaServerId("auto");
71 70 }
72   - if (StringUtils.isEmpty(param.getType())) {
  71 + if (ObjectUtils.isEmpty(param.getType())) {
73 72 param.setType("default");
74 73 }
75   - if (StringUtils.isEmpty(param.getGbId())) {
  74 + if (ObjectUtils.isEmpty(param.getGbId())) {
76 75 param.setGbId(null);
77 76 }
78   - WVPResult<StreamInfo> result = streamProxyService.save(param);
79   - return result;
  77 + return streamProxyService.save(param);
80 78 }
81 79  
82 80 @GetMapping(value = "/ffmpeg_cmd/list")
83 81 @ResponseBody
84 82 @Operation(summary = "获取ffmpeg.cmd模板")
85 83 @Parameter(name = "mediaServerId", description = "流媒体ID", required = true)
86   - public WVPResult getFFmpegCMDs(@RequestParam String mediaServerId){
  84 + public JSONObject getFFmpegCMDs(@RequestParam String mediaServerId){
87 85 logger.debug("获取节点[ {} ]ffmpeg.cmd模板", mediaServerId );
88 86  
89 87 MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId);
90   - JSONObject data = streamProxyService.getFFmpegCMDs(mediaServerItem);
91   - WVPResult<JSONObject> result = new WVPResult<>();
92   - result.setCode(0);
93   - result.setMsg("success");
94   - result.setData(data);
95   - return result;
  88 + if (mediaServerItem == null) {
  89 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "流媒体: " + mediaServerId + "未找到");
  90 + }
  91 + return streamProxyService.getFFmpegCMDs(mediaServerItem);
96 92 }
97 93  
98 94 @DeleteMapping(value = "/del")
... ... @@ -100,18 +96,13 @@ public class StreamProxyController {
100 96 @Operation(summary = "移除代理")
101 97 @Parameter(name = "app", description = "应用名", required = true)
102 98 @Parameter(name = "stream", description = "流id", required = true)
103   - public WVPResult del(@RequestParam String app, @RequestParam String stream){
  99 + public void del(@RequestParam String app, @RequestParam String stream){
104 100 logger.info("移除代理: " + app + "/" + stream);
105   - WVPResult<Object> result = new WVPResult<>();
106 101 if (app == null || stream == null) {
107   - result.setCode(400);
108   - result.setMsg(app == null ?"app不能为null":"stream不能为null");
  102 + throw new ControllerException(ErrorCode.ERROR400.getCode(), app == null ?"app不能为null":"stream不能为null");
109 103 }else {
110 104 streamProxyService.del(app, stream);
111   - result.setCode(0);
112   - result.setMsg("success");
113 105 }
114   - return result;
115 106 }
116 107  
117 108 @GetMapping(value = "/start")
... ... @@ -119,13 +110,13 @@ public class StreamProxyController {
119 110 @Operation(summary = "启用代理")
120 111 @Parameter(name = "app", description = "应用名", required = true)
121 112 @Parameter(name = "stream", description = "流id", required = true)
122   - public Object start(String app, String stream){
  113 + public void start(String app, String stream){
123 114 logger.info("启用代理: " + app + "/" + stream);
124 115 boolean result = streamProxyService.start(app, stream);
125 116 if (!result) {
126 117 logger.info("启用代理失败: " + app + "/" + stream);
  118 + throw new ControllerException(ErrorCode.ERROR100);
127 119 }
128   - return result?"success":"fail";
129 120 }
130 121  
131 122 @GetMapping(value = "/stop")
... ... @@ -133,9 +124,12 @@ public class StreamProxyController {
133 124 @Operation(summary = "停用代理")
134 125 @Parameter(name = "app", description = "应用名", required = true)
135 126 @Parameter(name = "stream", description = "流id", required = true)
136   - public Object stop(String app, String stream){
  127 + public void stop(String app, String stream){
137 128 logger.info("停用代理: " + app + "/" + stream);
138 129 boolean result = streamProxyService.stop(app, stream);
139   - return result?"success":"fail";
  130 + if (!result) {
  131 + logger.info("停用代理失败: " + app + "/" + stream);
  132 + throw new ControllerException(ErrorCode.ERROR100);
  133 + }
140 134 }
141 135 }
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/streamPush/StreamPushController.java
... ... @@ -31,6 +31,7 @@ import org.springframework.beans.factory.annotation.Autowired;
31 31 import org.springframework.http.HttpStatus;
32 32 import org.springframework.http.ResponseEntity;
33 33 import org.springframework.stereotype.Controller;
  34 +import org.springframework.util.ObjectUtils;
34 35 import org.springframework.util.StringUtils;
35 36 import org.springframework.web.bind.annotation.*;
36 37 import org.springframework.web.context.request.async.DeferredResult;
... ... @@ -81,10 +82,10 @@ public class StreamPushController {
81 82 @RequestParam(required = false)Boolean pushing,
82 83 @RequestParam(required = false)String mediaServerId ){
83 84  
84   - if (StringUtils.isEmpty(query)) {
  85 + if (ObjectUtils.isEmpty(query)) {
85 86 query = null;
86 87 }
87   - if (StringUtils.isEmpty(mediaServerId)) {
  88 + if (ObjectUtils.isEmpty(mediaServerId)) {
88 89 mediaServerId = null;
89 90 }
90 91 PageInfo<StreamPushItem> pushList = streamPushService.getPushList(page, count, query, pushing, mediaServerId);
... ... @@ -285,11 +286,11 @@ public class StreamPushController {
285 286 @ResponseBody
286 287 @Operation(summary = "停止视频回放")
287 288 public WVPResult<StreamInfo> add(@RequestBody StreamPushItem stream){
288   - if (StringUtils.isEmpty(stream.getGbId())) {
  289 + if (ObjectUtils.isEmpty(stream.getGbId())) {
289 290  
290 291 return new WVPResult<>(400, "国标ID不可为空", null);
291 292 }
292   - if (StringUtils.isEmpty(stream.getApp()) && StringUtils.isEmpty(stream.getStream())) {
  293 + if (ObjectUtils.isEmpty(stream.getApp()) && ObjectUtils.isEmpty(stream.getStream())) {
293 294 return new WVPResult<>(400, "app或stream不可为空", null);
294 295 }
295 296 stream.setStatus(false);
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/user/RoleController.java
1 1 package com.genersoft.iot.vmp.vmanager.user;
2 2  
  3 +import com.genersoft.iot.vmp.conf.exception.ControllerException;
3 4 import com.genersoft.iot.vmp.conf.security.SecurityUtils;
4 5 import com.genersoft.iot.vmp.service.IRoleService;
5 6 import com.genersoft.iot.vmp.storager.dao.dto.Role;
6 7 import com.genersoft.iot.vmp.utils.DateUtil;
  8 +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
7 9 import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
8 10  
9 11 import io.swagger.v3.oas.annotations.Operation;
... ... @@ -29,16 +31,13 @@ public class RoleController {
29 31 @Operation(summary = "添加角色")
30 32 @Parameter(name = "name", description = "角色名", required = true)
31 33 @Parameter(name = "authority", description = "权限(自行定义内容,目前未使用)", required = true)
32   - public ResponseEntity<WVPResult<Integer>> add(@RequestParam String name,
  34 + public void add(@RequestParam String name,
33 35 @RequestParam(required = false) String authority){
34   - WVPResult<Integer> result = new WVPResult<>();
35 36 // 获取当前登录用户id
36 37 int currenRoleId = SecurityUtils.getUserInfo().getRole().getId();
37 38 if (currenRoleId != 1) {
38 39 // 只用角色id为1才可以删除和添加用户
39   - result.setCode(-1);
40   - result.setMsg("用户无权限");
41   - return new ResponseEntity<>(result, HttpStatus.FORBIDDEN);
  40 + throw new ControllerException(ErrorCode.ERROR403);
42 41 }
43 42  
44 43 Role role = new Role();
... ... @@ -48,42 +47,33 @@ public class RoleController {
48 47 role.setUpdateTime(DateUtil.getNow());
49 48  
50 49 int addResult = roleService.add(role);
51   -
52   - result.setCode(addResult > 0 ? 0 : -1);
53   - result.setMsg(addResult > 0 ? "success" : "fail");
54   - result.setData(addResult);
55   - return new ResponseEntity<>(result, HttpStatus.OK);
  50 + if (addResult <= 0) {
  51 + throw new ControllerException(ErrorCode.ERROR100);
  52 + }
56 53 }
57 54  
58 55 @DeleteMapping("/delete")
59 56 @Operation(summary = "删除角色")
60 57 @Parameter(name = "id", description = "用户Id", required = true)
61   - public ResponseEntity<WVPResult<String>> delete(@RequestParam Integer id){
  58 + public void delete(@RequestParam Integer id){
62 59 // 获取当前登录用户id
63 60 int currenRoleId = SecurityUtils.getUserInfo().getRole().getId();
64   - WVPResult<String> result = new WVPResult<>();
65 61 if (currenRoleId != 1) {
66 62 // 只用角色id为0才可以删除和添加用户
67   - result.setCode(-1);
68   - result.setMsg("用户无权限");
69   - return new ResponseEntity<>(result, HttpStatus.FORBIDDEN);
  63 + throw new ControllerException(ErrorCode.ERROR403);
70 64 }
71 65 int deleteResult = roleService.delete(id);
72 66  
73   - result.setCode(deleteResult>0? 0 : -1);
74   - result.setMsg(deleteResult>0? "success" : "fail");
75   - return new ResponseEntity<>(result, HttpStatus.OK);
  67 + if (deleteResult <= 0) {
  68 + throw new ControllerException(ErrorCode.ERROR100);
  69 + }
76 70 }
77 71  
78 72 @GetMapping("/all")
79 73 @Operation(summary = "查询角色")
80   - public ResponseEntity<WVPResult<List<Role>>> all(){
  74 + public List<Role> all(){
81 75 // 获取当前登录用户id
82 76 List<Role> allRoles = roleService.getAll();
83   - WVPResult<List<Role>> result = new WVPResult<>();
84   - result.setCode(0);
85   - result.setMsg("success");
86   - result.setData(allRoles);
87   - return new ResponseEntity<>(result, HttpStatus.OK);
  77 + return roleService.getAll();
88 78 }
89 79 }
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java
1 1 package com.genersoft.iot.vmp.vmanager.user;
2 2  
  3 +import com.genersoft.iot.vmp.conf.exception.ControllerException;
3 4 import com.genersoft.iot.vmp.conf.security.SecurityUtils;
4 5 import com.genersoft.iot.vmp.conf.security.dto.LoginUser;
5 6 import com.genersoft.iot.vmp.service.IRoleService;
... ... @@ -7,6 +8,7 @@ import com.genersoft.iot.vmp.service.IUserService;
7 8 import com.genersoft.iot.vmp.storager.dao.dto.Role;
8 9 import com.genersoft.iot.vmp.storager.dao.dto.User;
9 10 import com.genersoft.iot.vmp.utils.DateUtil;
  11 +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
10 12 import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
11 13 import com.github.pagehelper.PageInfo;
12 14  
... ... @@ -18,6 +20,7 @@ import org.springframework.http.HttpStatus;
18 20 import org.springframework.http.ResponseEntity;
19 21 import org.springframework.security.authentication.AuthenticationManager;
20 22 import org.springframework.util.DigestUtils;
  23 +import org.springframework.util.ObjectUtils;
21 24 import org.springframework.util.StringUtils;
22 25 import org.springframework.web.bind.annotation.*;
23 26  
... ... @@ -43,25 +46,17 @@ public class UserController {
43 46 @Operation(summary = "登录")
44 47 @Parameter(name = "username", description = "用户名", required = true)
45 48 @Parameter(name = "password", description = "密码(32位md5加密)", required = true)
46   - public WVPResult<LoginUser> login(@RequestParam String username, @RequestParam String password){
  49 + public LoginUser login(@RequestParam String username, @RequestParam String password){
47 50 LoginUser user = null;
48   - WVPResult<LoginUser> result = new WVPResult<>();
49 51 try {
50 52 user = SecurityUtils.login(username, password, authenticationManager);
51 53 } catch (AuthenticationException e) {
52   - e.printStackTrace();
53   - result.setCode(-1);
54   - result.setMsg("fail");
  54 + throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage());
55 55 }
56   - if (user != null) {
57   - result.setCode(0);
58   - result.setMsg("success");
59   - result.setData(user);
60   - }else {
61   - result.setCode(-1);
62   - result.setMsg("fail");
  56 + if (user == null) {
  57 + throw new ControllerException(ErrorCode.ERROR100.getCode(), "用户名或密码错误");
63 58 }
64   - return result;
  59 + return user;
65 60 }
66 61  
67 62 @PostMapping("/changePassword")
... ... @@ -69,27 +64,27 @@ public class UserController {
69 64 @Parameter(name = "username", description = "用户名", required = true)
70 65 @Parameter(name = "oldpassword", description = "旧密码(已md5加密的密码)", required = true)
71 66 @Parameter(name = "password", description = "新密码(未md5加密的密码)", required = true)
72   - public String changePassword(@RequestParam String oldPassword, @RequestParam String password){
  67 + public void changePassword(@RequestParam String oldPassword, @RequestParam String password){
73 68 // 获取当前登录用户id
74 69 LoginUser userInfo = SecurityUtils.getUserInfo();
75 70 if (userInfo== null) {
76   - return "fail";
  71 + throw new ControllerException(ErrorCode.ERROR100);
77 72 }
78 73 String username = userInfo.getUsername();
79 74 LoginUser user = null;
80 75 try {
81 76 user = SecurityUtils.login(username, oldPassword, authenticationManager);
82   - if (user != null) {
83   - int userId = SecurityUtils.getUserId();
84   - boolean result = userService.changePassword(userId, DigestUtils.md5DigestAsHex(password.getBytes()));
85   - if (result) {
86   - return "success";
87   - }
  77 + if (user == null) {
  78 + throw new ControllerException(ErrorCode.ERROR100);
  79 + }
  80 + int userId = SecurityUtils.getUserId();
  81 + boolean result = userService.changePassword(userId, DigestUtils.md5DigestAsHex(password.getBytes()));
  82 + if (!result) {
  83 + throw new ControllerException(ErrorCode.ERROR100);
88 84 }
89 85 } catch (AuthenticationException e) {
90   - e.printStackTrace();
  86 + throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage());
91 87 }
92   - return "fail";
93 88 }
94 89  
95 90  
... ... @@ -98,22 +93,17 @@ public class UserController {
98 93 @Parameter(name = "username", description = "用户名", required = true)
99 94 @Parameter(name = "password", description = "密码(未md5加密的密码)", required = true)
100 95 @Parameter(name = "roleId", description = "角色ID", required = true)
101   - public ResponseEntity<WVPResult<Integer>> add(@RequestParam String username,
  96 + public void add(@RequestParam String username,
102 97 @RequestParam String password,
103 98 @RequestParam Integer roleId){
104   - WVPResult<Integer> result = new WVPResult<>();
105   - if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password) || roleId == null) {
106   - result.setCode(-1);
107   - result.setMsg("参数不可为空");
108   - return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
  99 + if (ObjectUtils.isEmpty(username) || ObjectUtils.isEmpty(password) || roleId == null) {
  100 + throw new ControllerException(ErrorCode.ERROR400.getCode(), "参数不可为空");
109 101 }
110 102 // 获取当前登录用户id
111 103 int currenRoleId = SecurityUtils.getUserInfo().getRole().getId();
112 104 if (currenRoleId != 1) {
113 105 // 只用角色id为1才可以删除和添加用户
114   - result.setCode(-1);
115   - result.setMsg("用户无权限");
116   - return new ResponseEntity<>(result, HttpStatus.FORBIDDEN);
  106 + throw new ControllerException(ErrorCode.ERROR400.getCode(), "用户无权限");
117 107 }
118 108 User user = new User();
119 109 user.setUsername(username);
... ... @@ -123,53 +113,38 @@ public class UserController {
123 113 Role role = roleService.getRoleById(roleId);
124 114  
125 115 if (role == null) {
126   - result.setCode(-1);
127   - result.setMsg("roleId is not found");
128   - // 角色不存在
129   - return new ResponseEntity<>(result, HttpStatus.OK);
  116 + throw new ControllerException(ErrorCode.ERROR400.getCode(), "角色不存在");
130 117 }
131 118 user.setRole(role);
132 119 user.setCreateTime(DateUtil.getNow());
133 120 user.setUpdateTime(DateUtil.getNow());
134 121 int addResult = userService.addUser(user);
135   -
136   -
137   - result.setCode(addResult > 0 ? 0 : -1);
138   - result.setMsg(addResult > 0 ? "success" : "fail");
139   - result.setData(addResult);
140   - return new ResponseEntity<>(result, HttpStatus.OK);
  122 + if (addResult <= 0) {
  123 + throw new ControllerException(ErrorCode.ERROR100);
  124 + }
141 125 }
142 126  
143 127 @DeleteMapping("/删除用户")
144 128 @Operation(summary = "停止视频回放")
145 129 @Parameter(name = "id", description = "用户Id", required = true)
146   - public ResponseEntity<WVPResult<String>> delete(@RequestParam Integer id){
  130 + public void delete(@RequestParam Integer id){
147 131 // 获取当前登录用户id
148 132 int currenRoleId = SecurityUtils.getUserInfo().getRole().getId();
149   - WVPResult<String> result = new WVPResult<>();
150 133 if (currenRoleId != 1) {
151 134 // 只用角色id为0才可以删除和添加用户
152   - result.setCode(-1);
153   - result.setMsg("用户无权限");
154   - return new ResponseEntity<>(result, HttpStatus.FORBIDDEN);
  135 + throw new ControllerException(ErrorCode.ERROR400.getCode(), "用户无权限");
155 136 }
156 137 int deleteResult = userService.deleteUser(id);
157   -
158   - result.setCode(deleteResult>0? 0 : -1);
159   - result.setMsg(deleteResult>0? "success" : "fail");
160   - return new ResponseEntity<>(result, HttpStatus.OK);
  138 + if (deleteResult <= 0) {
  139 + throw new ControllerException(ErrorCode.ERROR100);
  140 + }
161 141 }
162 142  
163 143 @GetMapping("/all")
164 144 @Operation(summary = "查询用户")
165   - public ResponseEntity<WVPResult<List<User>>> all(){
  145 + public List<User> all(){
166 146 // 获取当前登录用户id
167   - List<User> allUsers = userService.getAllUsers();
168   - WVPResult<List<User>> result = new WVPResult<>();
169   - result.setCode(0);
170   - result.setMsg("success");
171   - result.setData(allUsers);
172   - return new ResponseEntity<>(result, HttpStatus.OK);
  147 + return userService.getAllUsers();
173 148 }
174 149  
175 150 /**
... ... @@ -191,21 +166,18 @@ public class UserController {
191 166 @Operation(summary = "修改pushkey")
192 167 @Parameter(name = "userId", description = "用户Id", required = true)
193 168 @Parameter(name = "pushKey", description = "新的pushKey", required = true)
194   - public ResponseEntity<WVPResult<String>> changePushKey(@RequestParam Integer userId,@RequestParam String pushKey) {
  169 + public void changePushKey(@RequestParam Integer userId,@RequestParam String pushKey) {
195 170 // 获取当前登录用户id
196 171 int currenRoleId = SecurityUtils.getUserInfo().getRole().getId();
197 172 WVPResult<String> result = new WVPResult<>();
198 173 if (currenRoleId != 1) {
199 174 // 只用角色id为0才可以删除和添加用户
200   - result.setCode(-1);
201   - result.setMsg("用户无权限");
202   - return new ResponseEntity<>(result, HttpStatus.FORBIDDEN);
  175 + throw new ControllerException(ErrorCode.ERROR400.getCode(), "用户无权限");
203 176 }
204 177 int resetPushKeyResult = userService.changePushKey(userId,pushKey);
205   -
206   - result.setCode(resetPushKeyResult > 0 ? 0 : -1);
207   - result.setMsg(resetPushKeyResult > 0 ? "success" : "fail");
208   - return new ResponseEntity<>(result, HttpStatus.OK);
  178 + if (resetPushKeyResult <= 0) {
  179 + throw new ControllerException(ErrorCode.ERROR100);
  180 + }
209 181 }
210 182  
211 183 @PostMapping("/changePasswordForAdmin")
... ... @@ -213,20 +185,18 @@ public class UserController {
213 185 @Parameter(name = "adminId", description = "管理员id", required = true)
214 186 @Parameter(name = "userId", description = "用户id", required = true)
215 187 @Parameter(name = "password", description = "新密码(未md5加密的密码)", required = true)
216   - public String changePasswordForAdmin(@RequestParam int userId, @RequestParam String password) {
  188 + public void changePasswordForAdmin(@RequestParam int userId, @RequestParam String password) {
217 189 // 获取当前登录用户id
218 190 LoginUser userInfo = SecurityUtils.getUserInfo();
219 191 if (userInfo == null) {
220   - return "fail";
  192 + throw new ControllerException(ErrorCode.ERROR100);
221 193 }
222 194 Role role = userInfo.getRole();
223 195 if (role != null && role.getId() == 1) {
224 196 boolean result = userService.changePassword(userId, DigestUtils.md5DigestAsHex(password.getBytes()));
225   - if (result) {
226   - return "success";
  197 + if (!result) {
  198 + throw new ControllerException(ErrorCode.ERROR100);
227 199 }
228 200 }
229   -
230   - return "fail";
231 201 }
232 202 }
... ...