From 42a2772d1aa7493bcc4fac3e24ee8eda4eebc23d Mon Sep 17 00:00:00 2001
From: xubinbin <1323875150@qq.com>
Date: 星期二, 12 十二月 2023 17:09:04 +0800
Subject: [PATCH] bugfix:请求头带token, SecurityUtils 获取用户id 一直为0 #1195

---
 src/main/java/com/genersoft/iot/vmp/vmanager/streamPush/StreamPushController.java |   88 +++++++++++++++-----------------------------
 1 files changed, 30 insertions(+), 58 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/streamPush/StreamPushController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/streamPush/StreamPushController.java
old mode 100644
new mode 100755
index d8a87d7..5c8bf36
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/streamPush/StreamPushController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/streamPush/StreamPushController.java
@@ -5,26 +5,22 @@
 import com.alibaba.excel.read.metadata.ReadSheet;
 import com.genersoft.iot.vmp.common.StreamInfo;
 import com.genersoft.iot.vmp.conf.UserSetting;
+import com.genersoft.iot.vmp.conf.exception.ControllerException;
 import com.genersoft.iot.vmp.conf.security.SecurityUtils;
 import com.genersoft.iot.vmp.conf.security.dto.LoginUser;
 import com.genersoft.iot.vmp.gb28181.bean.GbStream;
 import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
 import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
-import com.genersoft.iot.vmp.media.zlm.dto.StreamAuthorityInfo;
 import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
 import com.genersoft.iot.vmp.service.IMediaServerService;
 import com.genersoft.iot.vmp.service.IMediaService;
 import com.genersoft.iot.vmp.service.IStreamPushService;
 import com.genersoft.iot.vmp.service.impl.StreamPushUploadFileHandler;
-import com.genersoft.iot.vmp.vmanager.bean.BatchGBStreamParam;
-import com.genersoft.iot.vmp.vmanager.bean.StreamPushExcelDto;
-import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
+import com.genersoft.iot.vmp.vmanager.bean.*;
 import com.github.pagehelper.PageInfo;
-
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
 import io.swagger.v3.oas.annotations.tags.Tag;
-import org.apache.poi.sl.usermodel.Sheet;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -32,12 +28,10 @@
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Controller;
 import org.springframework.util.ObjectUtils;
-import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.context.request.async.DeferredResult;
 import org.springframework.web.multipart.MultipartFile;
 
-import javax.servlet.http.HttpServletRequest;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.HashMap;
@@ -47,7 +41,7 @@
 
 @Tag(name  = "鎺ㄦ祦淇℃伅绠$悊")
 @Controller
-@CrossOrigin
+
 @RequestMapping(value = "/api/push")
 public class StreamPushController {
 
@@ -95,11 +89,9 @@
     @PostMapping(value = "/save_to_gb")
     @ResponseBody
     @Operation(summary = "灏嗘帹娴佹坊鍔犲埌鍥芥爣")
-    public Object saveToGB(@RequestBody GbStream stream){
-        if (streamPushService.saveToGB(stream)){
-            return "success";
-        }else {
-            return "fail";
+    public void saveToGB(@RequestBody GbStream stream){
+        if (!streamPushService.saveToGB(stream)){
+           throw new ControllerException(ErrorCode.ERROR100);
         }
     }
 
@@ -107,11 +99,9 @@
     @DeleteMapping(value = "/remove_form_gb")
     @ResponseBody
     @Operation(summary = "灏嗘帹娴佺Щ鍑哄埌鍥芥爣")
-    public Object removeFormGB(@RequestBody GbStream stream){
-        if (streamPushService.removeFromGB(stream)){
-            return "success";
-        }else {
-            return "fail";
+    public void removeFormGB(@RequestBody GbStream stream){
+        if (!streamPushService.removeFromGB(stream)){
+            throw new ControllerException(ErrorCode.ERROR100);
         }
     }
 
@@ -121,25 +111,21 @@
     @Operation(summary = "涓涓�涓帹娴�")
     @Parameter(name = "app", description = "搴旂敤鍚�", required = true)
     @Parameter(name = "stream", description = "娴乮d", required = true)
-    public Object stop(String app, String streamId){
-        if (streamPushService.stop(app, streamId)){
-            return "success";
-        }else {
-            return "fail";
+    public void stop(String app, String streamId){
+        if (!streamPushService.stop(app, streamId)){
+            throw new ControllerException(ErrorCode.ERROR100);
         }
     }
 
     @DeleteMapping(value = "/batchStop")
     @ResponseBody
     @Operation(summary = "涓澶氫釜鎺ㄦ祦")
-    public Object batchStop(@RequestBody BatchGBStreamParam batchGBStreamParam){
+    public void batchStop(@RequestBody BatchGBStreamParam batchGBStreamParam){
         if (batchGBStreamParam.getGbStreams().size() == 0) {
-            return "fail";
+            throw new ControllerException(ErrorCode.ERROR100);
         }
-        if (streamPushService.batchStop(batchGBStreamParam.getGbStreams())){
-            return "success";
-        }else {
-            return "fail";
+        if (!streamPushService.batchStop(batchGBStreamParam.getGbStreams())){
+            throw new ControllerException(ErrorCode.ERROR100);
         }
     }
 
@@ -195,7 +181,7 @@
             String name = file.getName();
             inputStream = file.getInputStream();
         } catch (IOException e) {
-            e.printStackTrace();
+            logger.error("鏈鐞嗙殑寮傚父 ", e);
         }
         try {
             //浼犲叆鍙傛暟
@@ -249,60 +235,46 @@
     @Parameter(name = "app", description = "搴旂敤鍚�", required = true)
     @Parameter(name = "stream", description = "娴乮d", required = true)
     @Parameter(name = "mediaServerId", description = "濯掍綋鏈嶅姟鍣╥d")
-    public WVPResult<StreamInfo> getPlayUrl(@RequestParam String app,@RequestParam String stream,
-                                            @RequestParam(required = false) String mediaServerId){
+    public StreamContent getPlayUrl(@RequestParam String app, @RequestParam String stream,
+                                    @RequestParam(required = false) String mediaServerId){
         boolean authority = false;
         // 鏄惁鐧婚檰鐢ㄦ埛, 鐧婚檰鐢ㄦ埛杩斿洖瀹屾暣淇℃伅
         LoginUser userInfo = SecurityUtils.getUserInfo();
         if (userInfo!= null) {
             authority = true;
         }
-        WVPResult<StreamInfo> result = new WVPResult<>();
         StreamPushItem push = streamPushService.getPush(app, stream);
         if (push != null && !push.isSelf()) {
-            result.setCode(-1);
-            result.setMsg("鏉ヨ嚜鍏朵粬骞冲彴鐨勬帹娴佷俊鎭�");
-            return result;
+            throw new ControllerException(ErrorCode.ERROR100.getCode(), "鏉ヨ嚜鍏朵粬骞冲彴鐨勬帹娴佷俊鎭�");
         }
         StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStreamWithCheck(app, stream, mediaServerId, authority);
-        if (streamInfo != null){
-            result.setCode(0);
-            result.setMsg("success");
-            result.setData(streamInfo);
-        }else {
-            result.setCode(-1);
-            result.setMsg("鑾峰彇鎾斁鍦板潃澶辫触");
+        if (streamInfo == null){
+            throw new ControllerException(ErrorCode.ERROR100.getCode(), "鑾峰彇鎾斁鍦板潃澶辫触");
         }
-
-        return result;
+        return new StreamContent(streamInfo);
     }
 
     /**
-     * 鑾峰彇鎺ㄦ祦鎾斁鍦板潃
+     * 娣诲姞鎺ㄦ祦淇℃伅
      * @param stream 鎺ㄦ祦淇℃伅
      * @return
      */
     @PostMapping(value = "/add")
     @ResponseBody
-    @Operation(summary = "鍋滄瑙嗛鍥炴斁")
-    public WVPResult<StreamInfo> add(@RequestBody StreamPushItem stream){
+    @Operation(summary = "娣诲姞鎺ㄦ祦淇℃伅")
+    public void add(@RequestBody StreamPushItem stream){
         if (ObjectUtils.isEmpty(stream.getGbId())) {
-
-            return new WVPResult<>(400, "鍥芥爣ID涓嶅彲涓虹┖", null);
+            throw new ControllerException(ErrorCode.ERROR400.getCode(), "鍥芥爣ID涓嶅彲涓虹┖");
         }
         if (ObjectUtils.isEmpty(stream.getApp()) && ObjectUtils.isEmpty(stream.getStream())) {
-            return new WVPResult<>(400, "app鎴杝tream涓嶅彲涓虹┖", null);
+            throw new ControllerException(ErrorCode.ERROR400.getCode(), "app鎴杝tream涓嶅彲涓虹┖");
         }
         stream.setStatus(false);
         stream.setPushIng(false);
         stream.setAliveSecond(0L);
         stream.setTotalReaderCount("0");
-        boolean result = streamPushService.add(stream);
-
-        if (result) {
-            return new WVPResult<>(0, "success", null);
-        }else {
-            return new WVPResult<>(-1, "fail", null);
+        if (!streamPushService.add(stream)) {
+            throw new ControllerException(ErrorCode.ERROR100);
         }
     }
 }

--
Gitblit v1.8.0