From f10a9238dce358b197142564259d975358c48cb3 Mon Sep 17 00:00:00 2001
From: panlinlin <648540858@qq.com>
Date: 星期五, 09 四月 2021 17:59:38 +0800
Subject: [PATCH] 规范化api, 进行中。。。

---
 web_src/src/components/devicePosition.vue                                                 |    8 +-
 web_src/src/components/dialog/chooseChannel.vue                                           |    2 
 web_src/src/components/dialog/platformEdit.vue                                            |    6 +-
 src/main/java/com/genersoft/iot/vmp/vmanager/gbStream/GbStreamController.java             |    9 +--
 web_src/src/components/dialog/addStreamTOGB.vue                                           |    2 
 src/main/java/com/genersoft/iot/vmp/vmanager/MobilePosition/MobilePositionController.java |   64 +++++++++++++++++++--
 web_src/src/components/ParentPlatformList.vue                                             |    4 
 src/main/java/com/genersoft/iot/vmp/vmanager/platform/PlatformController.java             |   30 ++++++----
 src/main/java/com/genersoft/iot/vmp/vmanager/media/MediaController.java                   |   18 +++++
 web_src/src/components/dialog/StreamProxyEdit.vue                                         |    2 
 web_src/src/components/dialog/chooseChannelForGb.vue                                      |    8 +-
 web_src/src/components/dialog/chooseChannelForStream.vue                                  |    3 
 12 files changed, 113 insertions(+), 43 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/MobilePosition/MobilePositionController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/MobilePosition/MobilePositionController.java
index 92806b1..c284fe9 100644
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/MobilePosition/MobilePositionController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/MobilePosition/MobilePositionController.java
@@ -12,6 +12,10 @@
 import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
 import com.github.pagehelper.util.StringUtil;
 
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -25,9 +29,13 @@
 import org.springframework.web.bind.annotation.RestController;
 import org.springframework.web.context.request.async.DeferredResult;
 
+/**
+ *  浣嶇疆淇℃伅绠$悊
+ */
+@Api(tags = "浣嶇疆淇℃伅绠$悊")
 @CrossOrigin
 @RestController
-@RequestMapping("/api")
+@RequestMapping("/api/position")
 public class MobilePositionController {
 
     private final static Logger logger = LoggerFactory.getLogger(MobilePositionController.class);
@@ -40,8 +48,21 @@
 	
 	@Autowired
 	private DeferredResultHolder resultHolder;
-	
-    @GetMapping("/positions/{deviceId}/history")
+
+    /**
+     *  鏌ヨ鍘嗗彶杞ㄨ抗
+     * @param deviceId 璁惧ID
+     * @param start 寮�濮嬫椂闂�
+     * @param end 缁撴潫鏃堕棿
+     * @return
+     */
+    @ApiOperation("鏌ヨ鍘嗗彶杞ㄨ抗")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "deviceId", value = "璁惧ID", required = true),
+            @ApiImplicitParam(name = "start", value = "寮�濮嬫椂闂�", required = true),
+            @ApiImplicitParam(name = "end", value = "缁撴潫鏃堕棿", required = true),
+    })
+    @GetMapping("/history/{deviceId}")
     public ResponseEntity<List<MobilePosition>> positions(@PathVariable String deviceId,
                                                     @RequestParam(required = false) String start,
                                                     @RequestParam(required = false) String end) {
@@ -60,7 +81,16 @@
         return new ResponseEntity<>(result, HttpStatus.OK);
     }
 
-    @GetMapping("/positions/{deviceId}/latest")
+    /**
+     *  鏌ヨ璁惧鏈�鏂颁綅缃�
+     * @param deviceId 璁惧ID
+     * @return
+     */
+    @ApiOperation("鏌ヨ璁惧鏈�鏂颁綅缃�")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "deviceId", value = "璁惧ID", required = true),
+    })
+    @GetMapping("/latest/{deviceId}")
     public ResponseEntity<MobilePosition> latestPosition(@PathVariable String deviceId) {
         if (logger.isDebugEnabled()) {
             logger.debug("鏌ヨ璁惧" + deviceId + "鐨勬渶鏂颁綅缃�");
@@ -69,7 +99,16 @@
         return new ResponseEntity<>(result, HttpStatus.OK);
     }
 
-    @GetMapping("/positions/{deviceId}/realtime")
+    /**
+     *  鑾峰彇绉诲姩浣嶇疆淇℃伅
+     * @param deviceId 璁惧ID
+     * @return
+     */
+    @ApiOperation("鑾峰彇绉诲姩浣嶇疆淇℃伅")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "deviceId", value = "璁惧ID", required = true),
+    })
+    @GetMapping("/realtime/{deviceId}")
     public DeferredResult<ResponseEntity<MobilePosition>> realTimePosition(@PathVariable String deviceId) {
         Device device = storager.queryVideoDevice(deviceId);
         cmder.mobilePostitionQuery(device, event -> {
@@ -92,7 +131,20 @@
         return result;
     }
 
-    @GetMapping("/positions/{deviceId}/subscribe")
+    /**
+     * 璁㈤槄浣嶇疆淇℃伅
+     * @param deviceId 璁惧ID
+     * @param expires 璁㈤槄瓒呮椂鏃堕棿
+     * @param interval 涓婃姤鏃堕棿闂撮殧
+     * @return true = 鍛戒护鍙戦�佹垚鍔�
+     */
+    @ApiOperation("璁㈤槄浣嶇疆淇℃伅")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "deviceId", value = "璁惧ID", required = true),
+            @ApiImplicitParam(name = "expires", value = "璁㈤槄瓒呮椂鏃堕棿"),
+            @ApiImplicitParam(name = "interval", value = "涓婃姤鏃堕棿闂撮殧"),
+    })
+    @GetMapping("/subscribe/{deviceId}")
     public ResponseEntity<String> positionSubscribe(@PathVariable String deviceId,
                                                     @RequestParam String expires,
                                                     @RequestParam String interval) {
diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gbStream/GbStreamController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gbStream/GbStreamController.java
index c61b62f..64e4567 100644
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/gbStream/GbStreamController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gbStream/GbStreamController.java
@@ -75,15 +75,12 @@
      * @return
      */
     @ApiOperation("淇濆瓨鍥芥爣鍏宠仈")
-//    @ApiImplicitParams({
-//            @ApiImplicitParam(name = "app", value = "瑙嗛娴佸簲鐢ㄥ悕", required = true ),
-//            @ApiImplicitParam(name = "gbId", value = "鍥芥爣ID", required = true ),
-//    })
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "gbStreamParam", value = "GbStreamParam", required = true ),
+    })
     @PostMapping(value = "/add")
     @ResponseBody
     public Object add(@RequestBody GbStreamParam gbStreamParam){
-        System.out.println(3333);
-        System.out.println(gbStreamParam.getGbStreams().size());
         if (gbStreamService.addPlatformInfo(gbStreamParam.getGbStreams(), gbStreamParam.getPlatformId())) {
             return "success";
         }else {
diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/media/MediaController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/media/MediaController.java
index e01b06e..a195cc9 100644
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/media/MediaController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/media/MediaController.java
@@ -9,6 +9,10 @@
 import com.genersoft.iot.vmp.service.IMediaService;
 import com.genersoft.iot.vmp.service.IStreamProxyService;
 import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -16,6 +20,7 @@
 import org.springframework.web.bind.annotation.*;
 
 
+@Api(tags = "濯掍綋娴佺浉鍏�")
 @Controller
 @CrossOrigin
 @RequestMapping(value = "/api/media")
@@ -33,8 +38,17 @@
     private IMediaService mediaService;
 
 
-
-
+    /**
+     * 鏍规嵁搴旂敤鍚嶅拰娴乮d鑾峰彇鎾斁鍦板潃
+     * @param app 搴旂敤鍚�
+     * @param stream 娴乮d
+     * @return
+     */
+    @ApiOperation("鏍规嵁搴旂敤鍚嶅拰娴乮d鑾峰彇鎾斁鍦板潃")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "app", value = "搴旂敤鍚�"),
+            @ApiImplicitParam(name = "stream", value = "娴乮d"),
+    })
     @RequestMapping(value = "/getStreamInfoByAppAndStream")
     @ResponseBody
     public StreamInfo getStreamInfoByAppAndStream(String app, String stream){
diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/platform/PlatformController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/platform/PlatformController.java
index 279a031..834c00b 100644
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/platform/PlatformController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/platform/PlatformController.java
@@ -8,6 +8,7 @@
 import com.genersoft.iot.vmp.vmanager.platform.bean.ChannelReduce;
 import com.genersoft.iot.vmp.vmanager.platform.bean.UpdateChannelParam;
 import com.github.pagehelper.PageInfo;
+import io.swagger.annotations.Api;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -17,9 +18,13 @@
 import org.springframework.web.bind.annotation.*;
 import com.genersoft.iot.vmp.conf.SipConfig;
 
+/**
+ * 绾ц仈骞冲彴绠$悊
+ */
+@Api("绾ц仈骞冲彴绠$悊")
 @CrossOrigin
 @RestController
-@RequestMapping("/api")
+@RequestMapping("/api/platform")
 public class PlatformController {
 
     private final static Logger logger = LoggerFactory.getLogger(PlatformController.class);
@@ -36,7 +41,7 @@
 	@Autowired
 	private SipConfig sipConfig;
 
-    @GetMapping("/platforms/serverconfig")
+    @GetMapping("/server_config")
     public ResponseEntity<JSONObject> serverConfig() {
         JSONObject result = new JSONObject();
         result.put("deviceIp", sipConfig.getSipIp());
@@ -46,7 +51,7 @@
         return new ResponseEntity<>(result, HttpStatus.OK);
     }
 
-    @GetMapping("/platforms/{count}/{page}")
+    @GetMapping("/query/{count}/{page}")
     public PageInfo<ParentPlatform> platforms(@PathVariable int page, @PathVariable int count){
 
         if (logger.isDebugEnabled()) {
@@ -55,7 +60,7 @@
         return storager.queryParentPlatformList(page, count);
     }
 
-    @RequestMapping("/platforms/save")
+    @PostMapping("/save")
     @ResponseBody
     public ResponseEntity<String> savePlatform(@RequestBody ParentPlatform parentPlatform){
 
@@ -98,18 +103,19 @@
         }
     }
 
-    @RequestMapping("/platforms/delete")
+    @DeleteMapping("/delete/{serverGBId}")
     @ResponseBody
-    public ResponseEntity<String> deletePlatform(@RequestBody ParentPlatform parentPlatform){
+    public ResponseEntity<String> deletePlatform(@PathVariable String serverGBId){
 
         if (logger.isDebugEnabled()) {
             logger.debug("鍒犻櫎涓婄骇骞冲彴API璋冪敤");
         }
-        if (StringUtils.isEmpty(parentPlatform.getServerGBId())
+        if (StringUtils.isEmpty(serverGBId)
         ){
             return new ResponseEntity<>("missing parameters", HttpStatus.BAD_REQUEST);
         }
-
+        ParentPlatform parentPlatform = storager.queryParentPlatById(serverGBId);
+        if (parentPlatform == null) return new ResponseEntity<>("fail", HttpStatus.OK);
         // 鍙戦�佺绾挎秷鎭�,鏃犺鏄惁鎴愬姛閮藉垹闄ょ紦瀛�
         commanderForPlatform.unregister(parentPlatform, (event -> {
             // 娓呯┖redis缂撳瓨
@@ -133,7 +139,7 @@
         }
     }
 
-    @RequestMapping("/platforms/exit/{deviceGbId}")
+    @GetMapping("/exit/{deviceGbId}")
     @ResponseBody
     public ResponseEntity<String> exitPlatform(@PathVariable String deviceGbId){
 
@@ -144,7 +150,7 @@
         return new ResponseEntity<>(String.valueOf(parentPlatform != null), HttpStatus.OK);
     }
 
-    @RequestMapping("/platforms/channelList")
+    @GetMapping("/channel_list")
     @ResponseBody
     public PageInfo<ChannelReduce> channelList(int page, int count,
                                               @RequestParam(required = false) String platformId,
@@ -167,7 +173,7 @@
     }
 
 
-    @RequestMapping("/platforms/updateChannelForGB")
+    @PostMapping("/update_channel_for_gb")
     @ResponseBody
     public ResponseEntity<String> updateChannelForGB(@RequestBody UpdateChannelParam param){
 
@@ -179,7 +185,7 @@
         return new ResponseEntity<>(String.valueOf(result > 0), HttpStatus.OK);
     }
 
-    @RequestMapping("/platforms/delChannelForGB")
+    @DeleteMapping("/del_channel_for_gb")
     @ResponseBody
     public ResponseEntity<String> delChannelForGB(@RequestBody UpdateChannelParam param){
 
diff --git a/web_src/src/components/ParentPlatformList.vue b/web_src/src/components/ParentPlatformList.vue
index 1121f6e..ee0d342 100644
--- a/web_src/src/components/ParentPlatformList.vue
+++ b/web_src/src/components/ParentPlatformList.vue
@@ -121,7 +121,7 @@
     },
     deletePlatformCommit: function(platform) {
         var that = this;
-        that.$axios.post(`/api/platforms/delete`, platform)
+        that.$axios.delete(`/api/platform/delete/${platform.serverGBId}`)
             .then(function (res) {
                 if (res.data == "success") {
                     that.$message({
@@ -155,7 +155,7 @@
     getPlatformList: function() {
       let that = this;
 
-      this.$axios.get(`/api/platforms/${that.count}/${that.currentPage}`)
+      this.$axios.get(`/api/platform/query/${that.count}/${that.currentPage}`)
         .then(function (res) {
           that.total = res.data.total;
           that.platformList = res.data.list;
diff --git a/web_src/src/components/devicePosition.vue b/web_src/src/components/devicePosition.vue
index 4a52c74..dfee0b1 100644
--- a/web_src/src/components/devicePosition.vue
+++ b/web_src/src/components/devicePosition.vue
@@ -171,7 +171,7 @@
                 this.endTime = null;
             }
             let self = this;
-            this.$axios.get(`/api/positions/${this.deviceId}/history`, {
+            this.$axios.get(`/api/position/history/${this.deviceId}`, {
                 params: {
                     start: self.startTime,
                     end: self.endTime,
@@ -202,7 +202,7 @@
             this.mapPointList = [];
             this.mobilePositionList = [];
             let self = this;
-            this.$axios.get(`/api/positions/${this.deviceId}/latest`)
+            this.$axios.get(`/api/position/latest/${this.deviceId}`)
             .then(function (res) {
                 console.log(res.data);
                 self.total = res.data.length;
@@ -226,7 +226,7 @@
         },
         subscribeMobilePosition: function() {
             let self = this;
-            this.$axios.get(`/api/positions/${this.deviceId}/subscribe`, {
+            this.$axios.get(`/api/position/subscribe/${this.deviceId}`, {
                 params: {
                     expires: self.expired,
                     interval: self.interval,
@@ -241,7 +241,7 @@
         },
         unSubscribeMobilePosition: function() {
             let self = this;
-            this.$axios.get(`/api/positions/${this.deviceId}/subscribe`, {
+            this.$axios.get(`/api/position/subscribe/${this.deviceId}`, {
                 params: {
                     expires: 0,
                     interval: self.interval,
diff --git a/web_src/src/components/dialog/StreamProxyEdit.vue b/web_src/src/components/dialog/StreamProxyEdit.vue
index 63a7bf6..bdde9db 100644
--- a/web_src/src/components/dialog/StreamProxyEdit.vue
+++ b/web_src/src/components/dialog/StreamProxyEdit.vue
@@ -176,7 +176,7 @@
       var result = false;
       var that = this;
       await that.$axios
-        .post(`/api/platforms/exit/${deviceGbId}`)
+        .post(`/api/platform/exit/${deviceGbId}`)
         .then(function (res) {
           result = res.data;
         })
diff --git a/web_src/src/components/dialog/addStreamTOGB.vue b/web_src/src/components/dialog/addStreamTOGB.vue
index 0b908f8..d5373fb 100644
--- a/web_src/src/components/dialog/addStreamTOGB.vue
+++ b/web_src/src/components/dialog/addStreamTOGB.vue
@@ -119,7 +119,7 @@
       var result = false;
       var that = this;
       await that.$axios
-        .post(`/api/platforms/exit/${deviceGbId}`)
+        .post(`/api/platform/exit/${deviceGbId}`)
         .then(function (res) {
           result = res.data;
         })
diff --git a/web_src/src/components/dialog/chooseChannel.vue b/web_src/src/components/dialog/chooseChannel.vue
index 31ef4b7..a6b9b44 100644
--- a/web_src/src/components/dialog/chooseChannel.vue
+++ b/web_src/src/components/dialog/chooseChannel.vue
@@ -72,7 +72,7 @@
 
             this.$axios({
                 method:"post",
-                url:"/api/platforms/updateChannelForGB",
+                url:"/api/platform/update_channel_for_gb",
                 data:{
                     platformId:  that.platformId,
                     channelReduces:  that.chooseData
diff --git a/web_src/src/components/dialog/chooseChannelForGb.vue b/web_src/src/components/dialog/chooseChannelForGb.vue
index 22b6032..28b3d58 100644
--- a/web_src/src/components/dialog/chooseChannelForGb.vue
+++ b/web_src/src/components/dialog/chooseChannelForGb.vue
@@ -149,7 +149,7 @@
             if (Object.keys(addData).length >0) {
                 that.$axios({
                     method:"post",
-                    url:"/api/platforms/updateChannelForGB",
+                    url:"/api/platform/update_channel_for_gb",
                     data:{
                         platformId:  that.platformId,
                         channelReduces: addData
@@ -162,8 +162,8 @@
             }
             if (Object.keys(delData).length >0) {
                  that.$axios({
-                    method:"post",
-                    url:"/api/platforms/delChannelForGB",
+                    method:"delete",
+                    url:"/api/platform/del_channel_for_gb",
                     data:{
                         platformId:  that.platformId,
                         channelReduces: delData
@@ -182,7 +182,7 @@
         getChannelList: function () {
             let that = this;
 
-            this.$axios.get(`/api/platforms/channelList`, {
+            this.$axios.get(`/api/platform/channel_list`, {
                     params: {
                         page: that.currentPage,
                         count: that.count,
diff --git a/web_src/src/components/dialog/chooseChannelForStream.vue b/web_src/src/components/dialog/chooseChannelForStream.vue
index ff65532..514ac3e 100644
--- a/web_src/src/components/dialog/chooseChannelForStream.vue
+++ b/web_src/src/components/dialog/chooseChannelForStream.vue
@@ -142,7 +142,7 @@
             if (Object.keys(delData).length >0) {
                 console.log(delData)
                  that.$axios({
-                    method:"post",
+                    method:"delete",
                     url:"/api/gbStream/del",
                     data:{
                         gbStreams:  delData,
@@ -152,6 +152,7 @@
                 }).catch(function (error) {
                     console.log(error);
                 });
+
             }
 
         },
diff --git a/web_src/src/components/dialog/platformEdit.vue b/web_src/src/components/dialog/platformEdit.vue
index c3c5ac9..34ee27d 100644
--- a/web_src/src/components/dialog/platformEdit.vue
+++ b/web_src/src/components/dialog/platformEdit.vue
@@ -164,7 +164,7 @@
     openDialog: function (platform, callback) {
       var that = this;
       this.$axios
-        .get(`/api/platforms/serverconfig`)
+        .get(`/api/platform/server_config`)
         .then(function (res) {
           console.log(res);
           that.platform.deviceGBId = res.data.username;
@@ -189,7 +189,7 @@
       console.log("onSubmit");
       var that = this;
       that.$axios
-        .post(`/api/platforms/save`, that.platform)
+        .post(`/api/platform/save`, that.platform)
         .then(function (res) {
           console.log(res);
           console.log(res.data == "success");
@@ -219,7 +219,7 @@
       var result = false;
       var that = this;
       await that.$axios
-        .post(`/api/platforms/exit/${deviceGbId}`)
+        .post(`/api/platform/exit/${deviceGbId}`)
         .then(function (res) {
           result = res.data;
         })

--
Gitblit v1.8.0