|
|
@@ -0,0 +1,177 @@
|
|
|
+package com.ch.jiaoxuelou_houtai.controller;
|
|
|
+
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.ch.jiaoxuelou_houtai.core.ResponseResult;
|
|
|
+import com.ch.jiaoxuelou_houtai.service.VideoService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/video")
|
|
|
+public class VideoController {
|
|
|
+
|
|
|
+ private final String baseUrl = "https://chtech.ncjti.edu.cn/video/transcoding";
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private VideoService videoService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 登录视频中台
|
|
|
+ *
|
|
|
+ * @return 成功 true 失败 false
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/login", method = RequestMethod.POST)
|
|
|
+ public String login() {
|
|
|
+ // 请求头
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
+ // 请求参数
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("username", "admin");
|
|
|
+ jsonObject.put("password", "jAYArls3XOUU6auwkGjmtMSgwgWxXFw2KRiuGrbszO0wKT5prodiYnReaROaq" +
|
|
|
+ "CX1XGKLNhTJOtJch9ipji9QrTep3zEzBJTVFt9vfqS2FYBtB2iRkNgR0egY/OvoGGOQ" +
|
|
|
+ "jFioepN9o1sNPahzdQutZ7mg9L/+TEtT0NK+VtnI1Fo=");
|
|
|
+
|
|
|
+ String url = baseUrl + "/videoAdmin/login";
|
|
|
+ JSONObject login = videoService.login(url, jsonObject.toString(), headers);
|
|
|
+ Boolean success = login.getBoolean("success");
|
|
|
+ if (success) {
|
|
|
+ // 获取登录成功后的token
|
|
|
+ return login.getJSONObject("data").getString("token");
|
|
|
+ }
|
|
|
+
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取教室视频列表
|
|
|
+ *
|
|
|
+ * @param jsonObject
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/getVideoList", method = RequestMethod.GET)
|
|
|
+ public ResponseResult getVideoList(@RequestBody JSONObject jsonObject) {
|
|
|
+ // 先登录,获取token
|
|
|
+ String admin_token = login();
|
|
|
+ if ("".equals(admin_token)) {
|
|
|
+ return ResponseResult.failed("视频登录失败!");
|
|
|
+ }
|
|
|
+ // 请求头
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
+ headers.put("admin_token", admin_token);
|
|
|
+ // 设置请求参数
|
|
|
+ JSONObject jsonParams = new JSONObject();
|
|
|
+ jsonParams.put("regularExpression", "^[A|B|C]{1}[0-9]{3}.*");
|
|
|
+ jsonParams.put("curPage", jsonObject.getString("curPage"));
|
|
|
+ jsonParams.put("pageSize", jsonObject.getString("pageSize"));
|
|
|
+ jsonParams.put("orderField", "installation_site");
|
|
|
+ jsonParams.put("order", "asc");
|
|
|
+ // 视频列表接口URL
|
|
|
+ String url = baseUrl + "/camera/list";
|
|
|
+ // 调用方法
|
|
|
+ JSONObject videoList = videoService.getVideoList(url, jsonParams.toString(), headers);
|
|
|
+ // 判断视频列表是否为空
|
|
|
+ if (videoList.isEmpty()) {
|
|
|
+ return ResponseResult.failed("获取教室列表失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ return ResponseResult.success(videoList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取空调超时预警
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/getAirOverTime", method = RequestMethod.GET)
|
|
|
+ public ResponseResult getAirOverTime() {
|
|
|
+ // 视频列表接口URL
|
|
|
+ String url = "https://chtech.ncjti.edu.cn/air-conditioner-control/airManage/firstqueryOverTime.action";
|
|
|
+ // 请求头
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Admin-Name", "admin");
|
|
|
+ headers.put("X-Token", "admin_token");
|
|
|
+ // 请求数据formdata
|
|
|
+ Map<String, String> formData = new HashMap<>();
|
|
|
+ formData.put("page", "1");
|
|
|
+ formData.put("rows", "10");
|
|
|
+ // 调用方法
|
|
|
+ JSONObject airOverTime = videoService.getAirOverTime(url, formData, headers);
|
|
|
+ // 判断视频列表是否为空
|
|
|
+ if (airOverTime.isEmpty()) {
|
|
|
+ return ResponseResult.failed("获取教室列表失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ return ResponseResult.success(airOverTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 拉流,获取视频流地址
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/openStreaming", method = RequestMethod.POST)
|
|
|
+ public ResponseResult openStreaming(@RequestBody JSONObject jsonObject) {
|
|
|
+ // 先登录,获取token
|
|
|
+ String admin_token = login();
|
|
|
+ if ("".equals(admin_token)) {
|
|
|
+ return ResponseResult.failed("视频登录失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 请求头
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
+ headers.put("admin_token", admin_token);
|
|
|
+
|
|
|
+ // 拉流接口URL
|
|
|
+ String url = baseUrl + "/stream/addStreamSource";
|
|
|
+ // 调用方法
|
|
|
+ JSONObject openAddress = videoService.openStreaming(url, jsonObject.toString(), headers);
|
|
|
+
|
|
|
+ if (openAddress.isEmpty()) {
|
|
|
+ return ResponseResult.failed("获取视频流地址失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ return ResponseResult.success(openAddress);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 关闭视频流地址
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/closeStreaming", method = RequestMethod.POST)
|
|
|
+ public ResponseResult closeStreaming(@RequestBody JSONObject jsonObject) {
|
|
|
+ // 先登录,获取token
|
|
|
+ String admin_token = login();
|
|
|
+ if ("".equals(admin_token)) {
|
|
|
+ return ResponseResult.failed("视频登录失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 请求头
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Content-Type", "application/json");
|
|
|
+ headers.put("admin_token", admin_token);
|
|
|
+
|
|
|
+ // 关闭流接口URL
|
|
|
+ String url = baseUrl + "/stream/delStreamSource";
|
|
|
+ // 调用方法
|
|
|
+ JSONObject closeStreaming = videoService.closeStreaming(url, jsonObject.toString(), headers);
|
|
|
+
|
|
|
+ if (closeStreaming.isEmpty()) {
|
|
|
+ return ResponseResult.failed("关闭视频流失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ return ResponseResult.success(closeStreaming);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|