From 985082d33930868c3cc1723f28fd9aaae9013a8f Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期三, 16 八月 2023 09:11:22 +0800
Subject: [PATCH] 添加缺少的内容

---
 src/main/java/com/genersoft/iot/vmp/vmanager/server/ServerController.java |  322 ++++++++++++++++++++++++++++-------------------------
 1 files changed, 170 insertions(+), 152 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/server/ServerController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/server/ServerController.java
old mode 100644
new mode 100755
index a0e7a73..72641be
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/server/ServerController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/server/ServerController.java
@@ -1,240 +1,210 @@
 package com.genersoft.iot.vmp.vmanager.server;
 
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
-import com.genersoft.iot.vmp.VManageBootstrap;
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
+import com.genersoft.iot.vmp.common.SystemAllInfo;
 import com.genersoft.iot.vmp.common.VersionPo;
 import com.genersoft.iot.vmp.conf.SipConfig;
 import com.genersoft.iot.vmp.conf.UserSetting;
 import com.genersoft.iot.vmp.conf.VersionInfo;
+import com.genersoft.iot.vmp.conf.exception.ControllerException;
+import com.genersoft.iot.vmp.media.zlm.SendRtpPortManager;
+import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe;
+import com.genersoft.iot.vmp.media.zlm.dto.IHookSubscribe;
 import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
-import com.genersoft.iot.vmp.service.IMediaServerService;
-import com.genersoft.iot.vmp.utils.SpringBeanFactory;
-import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
-import gov.nist.javax.sip.SipStackImpl;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiImplicitParam;
-import io.swagger.annotations.ApiImplicitParams;
-import io.swagger.annotations.ApiOperation;
+import com.genersoft.iot.vmp.service.*;
+import com.genersoft.iot.vmp.service.bean.MediaServerLoad;
+import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
+import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
+import com.genersoft.iot.vmp.vmanager.bean.ResourceBaseInfo;
+import com.genersoft.iot.vmp.vmanager.bean.ResourceInfo;
+import com.genersoft.iot.vmp.vmanager.bean.SystemConfigInfo;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.ConfigurableApplicationContext;
-import org.springframework.util.StringUtils;
+import org.springframework.util.ObjectUtils;
 import org.springframework.web.bind.annotation.*;
 
-import javax.sip.ListeningPoint;
-import javax.sip.ObjectInUseException;
-import javax.sip.SipProvider;
-import java.util.Iterator;
+import java.util.ArrayList;
 import java.util.List;
 
 @SuppressWarnings("rawtypes")
-@Api(tags = "鏈嶅姟鎺у埗")
-@CrossOrigin
+@Tag(name = "鏈嶅姟鎺у埗")
+
 @RestController
 @RequestMapping("/api/server")
 public class ServerController {
 
     @Autowired
-    private ConfigurableApplicationContext context;
+    private ZlmHttpHookSubscribe zlmHttpHookSubscribe;
 
     @Autowired
     private IMediaServerService mediaServerService;
 
     @Autowired
-    VersionInfo versionInfo;
+    private VersionInfo versionInfo;
 
     @Autowired
-    SipConfig sipConfig;
+    private SipConfig sipConfig;
 
     @Autowired
-    UserSetting userSetting;
+    private UserSetting userSetting;
+
+    @Autowired
+    private IDeviceService deviceService;
+
+    @Autowired
+    private IDeviceChannelService channelService;
+
+    @Autowired
+    private IStreamPushService pushService;
+
+
+    @Autowired
+    private IStreamProxyService proxyService;
+
 
     @Value("${server.port}")
     private int serverPort;
 
 
-    @ApiOperation("娴佸獟浣撴湇鍔″垪琛�")
+    @Autowired
+    private IRedisCatchStorage redisCatchStorage;
+
+    @Autowired
+    private SendRtpPortManager sendRtpPortManager;
+
+
     @GetMapping(value = "/media_server/list")
     @ResponseBody
-    public WVPResult<List<MediaServerItem>> getMediaServerList(boolean detail){
-        WVPResult<List<MediaServerItem>> result = new WVPResult<>();
-        result.setCode(0);
-        result.setMsg("success");
-        result.setData(mediaServerService.getAll());
-        return result;
+    @Operation(summary = "娴佸獟浣撴湇鍔″垪琛�")
+    public List<MediaServerItem> getMediaServerList() {
+        return mediaServerService.getAll();
     }
 
-    @ApiOperation("鍦ㄧ嚎娴佸獟浣撴湇鍔″垪琛�")
     @GetMapping(value = "/media_server/online/list")
     @ResponseBody
-    public WVPResult<List<MediaServerItem>> getOnlineMediaServerList(){
-        WVPResult<List<MediaServerItem>> result = new WVPResult<>();
-        result.setCode(0);
-        result.setMsg("success");
-        result.setData(mediaServerService.getAllOnline());
-        return result;
+    @Operation(summary = "鍦ㄧ嚎娴佸獟浣撴湇鍔″垪琛�")
+    public List<MediaServerItem> getOnlineMediaServerList() {
+        return mediaServerService.getAllOnline();
     }
 
-    @ApiOperation("鑾峰彇娴佸獟浣撴湇鍔�")
     @GetMapping(value = "/media_server/one/{id}")
     @ResponseBody
-    public WVPResult<MediaServerItem> getMediaServer(@PathVariable String id){
-        WVPResult<MediaServerItem> result = new WVPResult<>();
-        result.setCode(0);
-        result.setMsg("success");
-        result.setData(mediaServerService.getOne(id));
-        return result;
+    @Operation(summary = "鍋滄瑙嗛鍥炴斁")
+    @Parameter(name = "id", description = "娴佸獟浣撴湇鍔D", required = true)
+    public MediaServerItem getMediaServer(@PathVariable String id) {
+        return mediaServerService.getOne(id);
     }
 
-    @ApiOperation("娴嬭瘯娴佸獟浣撴湇鍔�")
-    @ApiImplicitParams({
-            @ApiImplicitParam(name="ip", value = "娴佸獟浣撴湇鍔P", dataTypeClass = String.class),
-            @ApiImplicitParam(name="port", value = "娴佸獟浣撴湇鍔TT绔彛", dataTypeClass = Integer.class),
-            @ApiImplicitParam(name="secret", value = "娴佸獟浣撴湇鍔ecret", dataTypeClass = String.class),
-    })
+    @Operation(summary = "娴嬭瘯娴佸獟浣撴湇鍔�")
+    @Parameter(name = "ip", description = "娴佸獟浣撴湇鍔P", required = true)
+    @Parameter(name = "port", description = "娴佸獟浣撴湇鍔TT绔彛", required = true)
+    @Parameter(name = "secret", description = "娴佸獟浣撴湇鍔ecret", required = true)
     @GetMapping(value = "/media_server/check")
     @ResponseBody
-    public WVPResult<MediaServerItem> checkMediaServer(@RequestParam String ip, @RequestParam int port, @RequestParam String secret){
+    public MediaServerItem checkMediaServer(@RequestParam String ip, @RequestParam int port, @RequestParam String secret) {
         return mediaServerService.checkMediaServer(ip, port, secret);
     }
 
-    @ApiOperation("娴嬭瘯娴佸獟浣撳綍鍍忕鐞嗘湇鍔�")
-    @ApiImplicitParams({
-            @ApiImplicitParam(name="ip", value = "娴佸獟浣撴湇鍔P", dataTypeClass = String.class),
-            @ApiImplicitParam(name="port", value = "娴佸獟浣撴湇鍔TT绔彛", dataTypeClass = Integer.class),
-            @ApiImplicitParam(name="secret", value = "娴佸獟浣撴湇鍔ecret", dataTypeClass = String.class),
-    })
+    @Operation(summary = "娴嬭瘯娴佸獟浣撳綍鍍忕鐞嗘湇鍔�")
+    @Parameter(name = "ip", description = "娴佸獟浣撴湇鍔P", required = true)
+    @Parameter(name = "port", description = "娴佸獟浣撴湇鍔TT绔彛", required = true)
     @GetMapping(value = "/media_server/record/check")
     @ResponseBody
-    public WVPResult<String> checkMediaRecordServer(@RequestParam String ip, @RequestParam int port){
+    public void checkMediaRecordServer(@RequestParam String ip, @RequestParam int port) {
         boolean checkResult = mediaServerService.checkMediaRecordServer(ip, port);
-        WVPResult<String> result = new WVPResult<>();
-        if (checkResult) {
-            result.setCode(0);
-            result.setMsg("success");
-
-        }else {
-            result.setCode(-1);
-            result.setMsg("杩炴帴澶辫触");
+        if (!checkResult) {
+            throw new ControllerException(ErrorCode.ERROR100.getCode(), "杩炴帴澶辫触");
         }
-        return result;
     }
 
-    @ApiOperation("淇濆瓨娴佸獟浣撴湇鍔�")
-    @ApiImplicitParams({
-            @ApiImplicitParam(name="mediaServerItem", value = "娴佸獟浣撲俊鎭�", dataTypeClass = MediaServerItem.class)
-    })
+    @Operation(summary = "淇濆瓨娴佸獟浣撴湇鍔�")
+    @Parameter(name = "mediaServerItem", description = "娴佸獟浣撲俊鎭�", required = true)
     @PostMapping(value = "/media_server/save")
     @ResponseBody
-    public WVPResult<String> saveMediaServer(@RequestBody  MediaServerItem mediaServerItem){
+    public void saveMediaServer(@RequestBody MediaServerItem mediaServerItem) {
         MediaServerItem mediaServerItemInDatabase = mediaServerService.getOne(mediaServerItem.getId());
 
         if (mediaServerItemInDatabase != null) {
-            if (StringUtils.isEmpty(mediaServerItemInDatabase.getSendRtpPortRange())
-                    && StringUtils.isEmpty(mediaServerItem.getSendRtpPortRange())){
-                mediaServerItem.setSendRtpPortRange("30000,30500");
-            }
-           mediaServerService.update(mediaServerItem);
-        }else {
-            if (StringUtils.isEmpty(mediaServerItem.getSendRtpPortRange())){
-                mediaServerItem.setSendRtpPortRange("30000,30500");
-            }
-            return mediaServerService.add(mediaServerItem);
+            mediaServerService.update(mediaServerItem);
+        } else {
+            mediaServerService.add(mediaServerItem);
         }
-
-        WVPResult<String> result = new WVPResult<>();
-        result.setCode(0);
-        result.setMsg("success");
-        return result;
     }
 
-    @ApiOperation("绉婚櫎娴佸獟浣撴湇鍔�")
-    @ApiImplicitParams({
-            @ApiImplicitParam(name="id", value = "娴佸獟浣揑D", dataTypeClass = String.class)
-    })
+    @Operation(summary = "绉婚櫎娴佸獟浣撴湇鍔�")
+    @Parameter(name = "id", description = "娴佸獟浣揑D", required = true)
     @DeleteMapping(value = "/media_server/delete")
     @ResponseBody
-    public WVPResult<String> deleteMediaServer(@RequestParam  String id){
-        if (mediaServerService.getOne(id) != null) {
-            mediaServerService.delete(id);
-            mediaServerService.deleteDb(id);
-        }else {
-            WVPResult<String> result = new WVPResult<>();
-            result.setCode(-1);
-            result.setMsg("鏈壘鍒版鑺傜偣");
-            return result;
+    public void deleteMediaServer(@RequestParam String id) {
+        if (mediaServerService.getOne(id) == null) {
+            throw new ControllerException(ErrorCode.ERROR100.getCode(), "鏈壘鍒版鑺傜偣");
         }
-        WVPResult<String> result = new WVPResult<>();
-        result.setCode(0);
-        result.setMsg("success");
-        return result;
+        mediaServerService.delete(id);
+        mediaServerService.deleteDb(id);
     }
 
 
-
-    @ApiOperation("閲嶅惎鏈嶅姟")
+    @Operation(summary = "閲嶅惎鏈嶅姟")
     @GetMapping(value = "/restart")
     @ResponseBody
-    public Object restart(){
-        Thread restartThread = new Thread(new Runnable() {
-            @Override
-            public void run() {
-                try {
-                    Thread.sleep(3000);
-                    SipProvider up = (SipProvider) SpringBeanFactory.getBean("udpSipProvider");
-                    SipStackImpl stack = (SipStackImpl)up.getSipStack();
-                    stack.stop();
-                    Iterator listener = stack.getListeningPoints();
-                    while (listener.hasNext()) {
-                        stack.deleteListeningPoint((ListeningPoint) listener.next());
-                    }
-                    Iterator providers = stack.getSipProviders();
-                    while (providers.hasNext()) {
-                        stack.deleteSipProvider((SipProvider) providers.next());
-                    }
-                    VManageBootstrap.restart();
-                } catch (InterruptedException ignored) {
-                } catch (ObjectInUseException e) {
-                    e.printStackTrace();
-                }
-            }
-        });
+    public void restart() {
+//        taskExecutor.execute(()-> {
+//            try {
+//                Thread.sleep(3000);
+//                SipProvider up = (SipProvider) SpringBeanFactory.getBean("udpSipProvider");
+//                SipStackImpl stack = (SipStackImpl) up.getSipStack();
+//                stack.stop();
+//                Iterator listener = stack.getListeningPoints();
+//                while (listener.hasNext()) {
+//                    stack.deleteListeningPoint((ListeningPoint) listener.next());
+//                }
+//                Iterator providers = stack.getSipProviders();
+//                while (providers.hasNext()) {
+//                    stack.deleteSipProvider((SipProvider) providers.next());
+//                }
+//                VManageBootstrap.restart();
+//            } catch (InterruptedException | ObjectInUseException e) {
+//                throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage());
+//            }
+//        });
+    };
 
-        restartThread.setDaemon(false);
-        restartThread.start();
-        return "success";
+    @Operation(summary = "鑾峰彇绯荤粺淇℃伅淇℃伅")
+    @GetMapping(value = "/system/configInfo")
+    @ResponseBody
+    public SystemConfigInfo getConfigInfo() {
+        SystemConfigInfo systemConfigInfo = new SystemConfigInfo();
+        systemConfigInfo.setVersion(versionInfo.getVersion());
+        systemConfigInfo.setSip(sipConfig);
+        systemConfigInfo.setAddOn(userSetting);
+        systemConfigInfo.setServerPort(serverPort);
+        return systemConfigInfo;
     }
 
-    @ApiOperation("鐗堟湰淇℃伅")
+    @Operation(summary = "鑾峰彇鐗堟湰淇℃伅")
     @GetMapping(value = "/version")
     @ResponseBody
-    public WVPResult<VersionPo> getVersion(){
-        WVPResult<VersionPo> result = new WVPResult<>();
-        result.setCode(0);
-        result.setMsg("success");
-        result.setData(versionInfo.getVersion());
-        return result;
+    public VersionPo VersionPogetVersion() {
+        return versionInfo.getVersion();
     }
 
-    @ApiOperation("閰嶇疆淇℃伅")
     @GetMapping(value = "/config")
-    @ApiImplicitParams({
-            @ApiImplicitParam(name="type", value = "閰嶇疆绫诲瀷锛坰ip, base锛�", dataTypeClass = String.class),
-    })
+    @Operation(summary = "鑾峰彇閰嶇疆淇℃伅")
+    @Parameter(name = "type", description = "閰嶇疆绫诲瀷锛坰ip, base锛�", required = true)
     @ResponseBody
-    public WVPResult<JSONObject> getVersion(String type){
-        WVPResult<JSONObject> result = new WVPResult<>();
-        result.setCode(0);
-        result.setMsg("success");
+    public JSONObject getVersion(String type) {
 
         JSONObject jsonObject = new JSONObject();
         jsonObject.put("server.port", serverPort);
-        if (StringUtils.isEmpty(type)) {
+        if (ObjectUtils.isEmpty(type)) {
             jsonObject.put("sip", JSON.toJSON(sipConfig));
             jsonObject.put("base", JSON.toJSON(userSetting));
-        }else {
-            switch (type){
+        } else {
+            switch (type) {
                 case "sip":
                     jsonObject.put("sip", sipConfig);
                     break;
@@ -245,7 +215,55 @@
                     break;
             }
         }
-        result.setData(jsonObject);
+        return jsonObject;
+    }
+
+    @GetMapping(value = "/hooks")
+    @ResponseBody
+    @Operation(summary = "鑾峰彇褰撳墠鎵�鏈塰ook")
+    public List<IHookSubscribe> getHooks() {
+        return zlmHttpHookSubscribe.getAll();
+    }
+
+    @GetMapping(value = "/system/info")
+    @ResponseBody
+    @Operation(summary = "鑾峰彇绯荤粺淇℃伅")
+    public SystemAllInfo getSystemInfo() {
+        SystemAllInfo systemAllInfo = redisCatchStorage.getSystemInfo();
+
+        return systemAllInfo;
+    }
+
+    @GetMapping(value = "/media_server/load")
+    @ResponseBody
+    @Operation(summary = "鑾峰彇璐熻浇淇℃伅")
+    public List<MediaServerLoad> getMediaLoad() {
+        List<MediaServerLoad> result = new ArrayList<>();
+        List<MediaServerItem> allOnline = mediaServerService.getAllOnline();
+        if (allOnline.size() == 0) {
+            return result;
+        }else {
+            for (MediaServerItem mediaServerItem : allOnline) {
+                result.add(mediaServerService.getLoad(mediaServerItem));
+            }
+        }
+        return result;
+    }
+
+    @GetMapping(value = "/resource/info")
+    @ResponseBody
+    @Operation(summary = "鑾峰彇璐熻浇淇℃伅")
+    public ResourceInfo getResourceInfo() {
+        ResourceInfo result = new ResourceInfo();
+        ResourceBaseInfo deviceInfo = deviceService.getOverview();
+        result.setDevice(deviceInfo);
+        ResourceBaseInfo channelInfo = channelService.getOverview();
+        result.setChannel(channelInfo);
+        ResourceBaseInfo pushInfo = pushService.getOverview();
+        result.setPush(pushInfo);
+        ResourceBaseInfo proxyInfo = proxyService.getOverview();
+        result.setProxy(proxyInfo);
+
         return result;
     }
 }

--
Gitblit v1.8.0