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