Browse Source

等待能耗和设备

soft5566 3 years ago
parent
commit
d502b7ff90

+ 1 - 1
pom.xml

@@ -79,7 +79,7 @@
 	</dependencies>
 	</dependencies>
 
 
 	<build>
 	<build>
-		<finalName>LargeScreenOfTeachingBuilding</finalName>
+		<finalName>largeScreenOfTeachingBuilding</finalName>
 		<plugins>
 		<plugins>
 			<plugin>
 			<plugin>
 				<groupId>org.springframework.boot</groupId>
 				<groupId>org.springframework.boot</groupId>

+ 38 - 15
src/main/java/com/ch/jiaoxuelou_houtai/controller/VideoController.java

@@ -2,6 +2,7 @@ package com.ch.jiaoxuelou_houtai.controller;
 
 
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONException;
 import com.alibaba.fastjson2.JSONObject;
 import com.alibaba.fastjson2.JSONObject;
 import com.ch.jiaoxuelou_houtai.core.ResponseResult;
 import com.ch.jiaoxuelou_houtai.core.ResponseResult;
 import com.ch.jiaoxuelou_houtai.service.VideoService;
 import com.ch.jiaoxuelou_houtai.service.VideoService;
@@ -77,7 +78,7 @@ public class VideoController {
         // 设置请求参数
         // 设置请求参数
         JSONObject jsonParams = new JSONObject();
         JSONObject jsonParams = new JSONObject();
         // 阶梯教室、只有单个摄像头的教室都过滤了
         // 阶梯教室、只有单个摄像头的教室都过滤了
-        jsonParams.put("regularExpression", "^(?!C109|B107|B108|A109|B307)[ABC][0-9]{3}.*");
+        jsonParams.put("regularExpression", "^(?!C109|B107|B108|A109)[ABC][0-9]{3}.*");
         jsonParams.put("curPage", curPage);
         jsonParams.put("curPage", curPage);
         jsonParams.put("pageSize", pageSize * 2); // 每页显示的视频数量 * 2,大屏上一个教室对应2个摄像头
         jsonParams.put("pageSize", pageSize * 2); // 每页显示的视频数量 * 2,大屏上一个教室对应2个摄像头
         jsonParams.put("orderField", "installation_site");
         jsonParams.put("orderField", "installation_site");
@@ -86,19 +87,32 @@ public class VideoController {
         String url = baseUrl + "/camera/list";
         String url = baseUrl + "/camera/list";
         // 调用方法
         // 调用方法
         JSONObject videoList = videoService.getVideoList(url, jsonParams.toString(), headers);
         JSONObject videoList = videoService.getVideoList(url, jsonParams.toString(), headers);
-        Map<String, JSONArray> map = new TreeMap<>();
-        JSONArray jsonArray = new JSONArray();
+        JSONArray map = new JSONArray();
         if (videoList.getBoolean("success")) {
         if (videoList.getBoolean("success")) {
+            JSONArray jsonArray = new JSONArray();
+            String tempRoom = null;
             // 从JSONObject中提取"data"数组
             // 从JSONObject中提取"data"数组
             JSONArray dataArray = videoList.getJSONArray("data");
             JSONArray dataArray = videoList.getJSONArray("data");
             // 遍历"data"数组并提取每个对象的数据
             // 遍历"data"数组并提取每个对象的数据
             for (int i = 0; i < dataArray.size(); i++) {
             for (int i = 0; i < dataArray.size(); i++) {
                 JSONObject dataObject = dataArray.getJSONObject(i);
                 JSONObject dataObject = dataArray.getJSONObject(i);
-                // 提取具体的数据字段:教室摄像头名称,比如A101前
+                // 提取具体的数据字段:教室摄像头名称,比如A101前要获取A101
                 String room = dataObject.getString("installationSite").substring(0, 4);
                 String room = dataObject.getString("installationSite").substring(0, 4);
-                jsonArray.add(dataObject);
+                // 为了达到同一个教室放一组,有的摄像头会离线,会存在教室单个摄像头在线,如果单个摄像头在线就过滤掉
+                if (jsonArray.size() == 0) {
+                    jsonArray.add(dataObject);
+                    tempRoom = room;
+                } else if (jsonArray.size() == 1) {
+                    if (tempRoom != null && tempRoom.equals(room)) {
+                        jsonArray.add(dataObject);
+                    } else {
+                        jsonArray.clear();
+                    }
+                }
+                // 满足2个就不过滤
                 if (jsonArray.size() == 2) {
                 if (jsonArray.size() == 2) {
-                    map.put(room, JSON.parseObject(jsonArray.toString(), JSONArray.class));
+                    String item = "{\"room\":\"" + room + "\",\"arr\":" + JSON.parseObject(jsonArray.toString(), JSONArray.class) + "}";
+                    map.add(JSON.parseObject(item, JSONObject.class));
                     jsonArray.clear();
                     jsonArray.clear();
                 }
                 }
             }
             }
@@ -109,14 +123,15 @@ public class VideoController {
             return ResponseResult.failed("获取教室列表为空!");
             return ResponseResult.failed("获取教室列表为空!");
         }
         }
 
 
+        int total = 110;
         Map<String, Object> returnData = new HashMap<>();
         Map<String, Object> returnData = new HashMap<>();
-        returnData.put("totalCount", 110);
+        returnData.put("totalCount", total);
         returnData.put("currPage", curPage);
         returnData.put("currPage", curPage);
         returnData.put("pageSize", pageSize);
         returnData.put("pageSize", pageSize);
-        if ((110 % pageSize) > 0)
-            returnData.put("totalPage", 110 / pageSize + 1);
+        if ((total % pageSize) > 0)
+            returnData.put("totalPage", total / pageSize + 1);
         else
         else
-            returnData.put("totalPage", 110 / pageSize);
+            returnData.put("totalPage", total / pageSize);
 
 
         returnData.put("list", map);
         returnData.put("list", map);
 
 
@@ -289,13 +304,21 @@ public class VideoController {
         // 拉流接口URL
         // 拉流接口URL
         String url = baseUrl + "/stream/addStreamSource";
         String url = baseUrl + "/stream/addStreamSource";
         // 调用方法
         // 调用方法
-        JSONObject openAddress = videoService.openStreaming(url, jsonObject.toString(), headers);
+        try {
+            JSONObject openAddress = null;
+            openAddress = videoService.openStreaming(url, jsonObject.toString(), headers);
+            if (openAddress.isEmpty()) {
+                return ResponseResult.failed("获取视频流地址失败!");
+            }
 
 
-        if (openAddress.isEmpty()) {
-            return ResponseResult.failed("获取视频流地址失败!");
+            return ResponseResult.success(openAddress);
+        } catch (JSONException e) {
+            System.out.println(url);
+            System.out.println(jsonObject);
+            System.out.println(headers);
+            System.out.println(e.getMessage());
+            return ResponseResult.failed("e.getMessage()");
         }
         }
-
-        return ResponseResult.success(openAddress);
     }
     }
 
 
     /**
     /**

+ 8 - 6
src/main/java/com/ch/jiaoxuelou_houtai/util/JwtUtil.java

@@ -10,25 +10,27 @@ import java.util.Date;
 
 
 @Component
 @Component
 public class JwtUtil {
 public class JwtUtil {
-    private final String secret = "ch!@#123";
+    private final String SECRET_KEY = "ch!@#123";
 
 
     public String generateToken(String username) {
     public String generateToken(String username) {
+        String prefix = "CHUANGHAI ";
+        // 7天的有效期
+        long EXPIRATION_TIME = 7 * 24 * 60 * 60 * 1000;
         Date now = new Date();
         Date now = new Date();
-        Date expiryDate = new Date(now.getTime() + 1000 * 60 * 60 * 24 * 7); // token期限
+        Date expiryDate = new Date(now.getTime() + EXPIRATION_TIME); // token期限
         String token = Jwts.builder()
         String token = Jwts.builder()
                 .setSubject(username)
                 .setSubject(username)
                 .setIssuedAt(now)
                 .setIssuedAt(now)
                 .setExpiration(expiryDate)
                 .setExpiration(expiryDate)
-                .signWith(SignatureAlgorithm.HS512, secret)
+                .signWith(SignatureAlgorithm.HS512, SECRET_KEY)
                 .compact();
                 .compact();
-        String prefix = "CHUANGHAI ";
         return prefix + token;
         return prefix + token;
     }
     }
 
 
     public String getUsernameFromToken(String token) {
     public String getUsernameFromToken(String token) {
         try {
         try {
             return Jwts.parser()
             return Jwts.parser()
-                    .setSigningKey(secret)
+                    .setSigningKey(SECRET_KEY)
                     .parseClaimsJws(token)
                     .parseClaimsJws(token)
                     .getBody()
                     .getBody()
                     .getSubject();
                     .getSubject();
@@ -45,7 +47,7 @@ public class JwtUtil {
     private boolean isTokenExpired(String token) {
     private boolean isTokenExpired(String token) {
         try {
         try {
             Date expiryDate = Jwts.parser()
             Date expiryDate = Jwts.parser()
-                    .setSigningKey(secret)
+                    .setSigningKey(SECRET_KEY)
                     .parseClaimsJws(token)
                     .parseClaimsJws(token)
                     .getBody()
                     .getBody()
                     .getExpiration();
                     .getExpiration();

+ 6 - 6
src/main/resources/application.yml

@@ -7,12 +7,12 @@ server:
 
 
 spring:
 spring:
   datasource:
   datasource:
-    username: root
-    password: 123456
-#    url: jdbc:mysql://172.16.20.77:3306/memdb?allowPublicKeyRetrieval=true&useSSL=false&connectTimeout=10000&socketTimeout=10000&serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull
-#    username: memdb
-#    password: 6RHZJYjrT83Ri88C
-    url: jdbc:mysql://localhost:3306/memdb?allowPublicKeyRetrieval=true&useSSL=false&connectTimeout=10000&socketTimeout=10000&serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull
+#    username: root
+#    password: 123456
+#    url: jdbc:mysql://localhost:3306/memdb?allowPublicKeyRetrieval=true&useSSL=false&connectTimeout=10000&socketTimeout=10000&serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull
+    url: jdbc:mysql://172.16.20.77:3306/memdb?allowPublicKeyRetrieval=true&useSSL=false&connectTimeout=10000&socketTimeout=10000&serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull
+    username: memdb
+    password: 6RHZJYjrT83Ri88C
     driver-class-name: com.mysql.cj.jdbc.Driver
     driver-class-name: com.mysql.cj.jdbc.Driver
     #spring官方推荐 性能最强,没有之一
     #spring官方推荐 性能最强,没有之一
     hikari:
     hikari: