|
|
@@ -1,10 +1,11 @@
|
|
|
package com.ch.jiaoxuelou_houtai.controller;
|
|
|
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
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;
|
|
|
@@ -12,6 +13,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
+import java.util.TreeMap;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/video")
|
|
|
@@ -67,23 +69,58 @@ public class VideoController {
|
|
|
Map<String, String> headers = new HashMap<>();
|
|
|
headers.put("Content-Type", "application/json");
|
|
|
headers.put("admin_token", admin_token);
|
|
|
+
|
|
|
+ // 每页显示的视频数量
|
|
|
+ int pageSize = jsonObject.getInteger("pageSize");
|
|
|
+ // 当前页
|
|
|
+ int curPage = jsonObject.getInteger("curPage");
|
|
|
// 设置请求参数
|
|
|
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("regularExpression", "^(?!C109|B107|B108|A109|B307)[ABC][0-9]{3}.*");
|
|
|
+ jsonParams.put("curPage", curPage);
|
|
|
+ jsonParams.put("pageSize", pageSize * 2); // 每页显示的视频数量 * 2,大屏上一个教室对应2个摄像头
|
|
|
jsonParams.put("orderField", "installation_site");
|
|
|
jsonParams.put("order", "asc");
|
|
|
// 视频列表接口URL
|
|
|
String url = baseUrl + "/camera/list";
|
|
|
// 调用方法
|
|
|
JSONObject videoList = videoService.getVideoList(url, jsonParams.toString(), headers);
|
|
|
+ Map<String, JSONArray> map = new TreeMap<>();
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
+ if (videoList.getBoolean("success")) {
|
|
|
+ // 从JSONObject中提取"data"数组
|
|
|
+ JSONArray dataArray = videoList.getJSONArray("data");
|
|
|
+ // 遍历"data"数组并提取每个对象的数据
|
|
|
+ for (int i = 0; i < dataArray.size(); i++) {
|
|
|
+ JSONObject dataObject = dataArray.getJSONObject(i);
|
|
|
+ // 提取具体的数据字段:教室摄像头名称,比如A101前
|
|
|
+ String room = dataObject.getString("installationSite").substring(0, 4);
|
|
|
+ jsonArray.add(dataObject);
|
|
|
+ if (jsonArray.size() == 2) {
|
|
|
+ map.put(room, JSON.parseObject(jsonArray.toString(), JSONArray.class));
|
|
|
+ jsonArray.clear();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 判断视频列表是否为空
|
|
|
- if (videoList.isEmpty()) {
|
|
|
- return ResponseResult.failed("获取教室列表失败!");
|
|
|
+ if (map.isEmpty()) {
|
|
|
+ return ResponseResult.failed("获取教室列表为空!");
|
|
|
}
|
|
|
|
|
|
- return ResponseResult.success(videoList);
|
|
|
+ Map<String, Object> returnData = new HashMap<>();
|
|
|
+ returnData.put("totalCount", 110);
|
|
|
+ returnData.put("currPage", curPage);
|
|
|
+ returnData.put("pageSize", pageSize);
|
|
|
+ if ((110 % pageSize) > 0)
|
|
|
+ returnData.put("totalPage", 110 / pageSize + 1);
|
|
|
+ else
|
|
|
+ returnData.put("totalPage", 110 / pageSize);
|
|
|
+
|
|
|
+ returnData.put("list", map);
|
|
|
+
|
|
|
+ return ResponseResult.success(returnData);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -115,6 +152,7 @@ public class VideoController {
|
|
|
|
|
|
/**
|
|
|
* 获取空调总数和在线数
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
private Map<String, String> getAirUsage() {
|
|
|
@@ -145,6 +183,7 @@ public class VideoController {
|
|
|
|
|
|
/**
|
|
|
* 电脑使用情况
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
private Map<String, String> getComputerUsage() {
|
|
|
@@ -167,6 +206,7 @@ public class VideoController {
|
|
|
|
|
|
/**
|
|
|
* 摄像头使用情况
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
private Map<String, String> getProjectorUsage() {
|
|
|
@@ -189,6 +229,7 @@ public class VideoController {
|
|
|
|
|
|
/**
|
|
|
* 设备使用情况
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "/getEquipmentUsage", method = RequestMethod.POST)
|
|
|
@@ -206,23 +247,25 @@ public class VideoController {
|
|
|
|
|
|
/**
|
|
|
* 空调状况分析
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "/getAirConditionAnalysis", method = RequestMethod.POST)
|
|
|
public ResponseResult airConditionAnalysis() {
|
|
|
- // 数量
|
|
|
- int num_of_online = 200;
|
|
|
- int num_of_offline = 100;
|
|
|
- int num_of_alarms = 20;
|
|
|
- int total_equipment = num_of_online + num_of_alarms + num_of_offline;
|
|
|
-
|
|
|
- Map<String, String> map = new HashMap<>();
|
|
|
- map.put("num_of_online", String.valueOf(num_of_online));
|
|
|
- map.put("num_of_offline", String.valueOf(num_of_offline));
|
|
|
- map.put("num_of_alarms", String.valueOf(num_of_alarms));
|
|
|
- map.put("total_equipment", String.valueOf(total_equipment));
|
|
|
-
|
|
|
- return ResponseResult.success(map);
|
|
|
+ // 接口URL
|
|
|
+ String url = "https://chtech.ncjti.edu.cn/air-conditioner-control/airManage/firstnormal_t.action";
|
|
|
+ // 请求头
|
|
|
+ Map<String, String> headers = new HashMap<>();
|
|
|
+ headers.put("Admin-Name", "admin");
|
|
|
+ headers.put("X-Token", "admin_token");
|
|
|
+ // 调用方法
|
|
|
+ JSONObject airConditionAnalysis = videoService.getAirConditionAnalysis(url, headers);
|
|
|
+ // 判断是否为空
|
|
|
+ if (airConditionAnalysis.isEmpty()) {
|
|
|
+ return ResponseResult.failed("获取教室列表失败!");
|
|
|
+ }
|
|
|
+
|
|
|
+ return ResponseResult.success(airConditionAnalysis.getJSONArray("data"));
|
|
|
}
|
|
|
|
|
|
/**
|