soft5566 il y a 3 ans
Parent
commit
fb470d6985

+ 2 - 2
src/main/java/com/ch/jiaoxuelou_houtai/controller/ApiController.java

@@ -101,8 +101,8 @@ public class ApiController {
     /**
      * 教室排课表
      *
-     * @param jsonObject
-     * @return
+     * @param jsonObject json
+     * @return ResponseResult
      */
     @RequestMapping(value = "/listCourse", method = RequestMethod.POST)
     public ResponseResult listCourse(@RequestBody JSONObject jsonObject) {

+ 90 - 6
src/main/java/com/ch/jiaoxuelou_houtai/controller/VideoController.java

@@ -12,9 +12,11 @@ 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;
-import java.util.TreeMap;
+import java.text.SimpleDateFormat;
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
 
 @RestController
 @RequestMapping("/video")
@@ -22,6 +24,11 @@ public class VideoController {
 
     private final String baseUrl = "https://chtech.ncjti.edu.cn/video/transcoding";
 
+    // 摄像头总数
+    private final int camera_total = 110;
+    // 摄像头在线总数
+    private int camera_on_total = 0;
+
     @Autowired
     private VideoService videoService;
 
@@ -123,7 +130,8 @@ public class VideoController {
             return ResponseResult.failed("获取教室列表为空!");
         }
 
-        int total = 110;
+        int total = camera_total;
+        camera_on_total = map.size();
         Map<String, Object> returnData = new HashMap<>();
         returnData.put("totalCount", total);
         returnData.put("currPage", curPage);
@@ -229,12 +237,12 @@ public class VideoController {
         // 判断是否为空
         if (false) {
             returnMap.put("code", "-1");
-            returnMap.put("msg", "获取摄像头使用情况为空!");
+            returnMap.put("msg", "获取投影仪使用情况为空!");
             returnMap.put("air_total", "0");
             returnMap.put("air_on_total", "0");
         } else {
             returnMap.put("code", "200");
-            returnMap.put("msg", "获取摄像头使用情况成功!");
+            returnMap.put("msg", "获取投影仪使用情况成功!");
             returnMap.put("projector_total", "600");
             returnMap.put("projector_on_using", "598");
         }
@@ -249,17 +257,93 @@ public class VideoController {
      */
     @RequestMapping(value = "/getEquipmentUsage", method = RequestMethod.POST)
     public ResponseResult getEquipmentUsage() {
+        // 电脑使用情况
         Map<String, String> computerUsage = getComputerUsage();
+        // 投影仪使用情况
         Map<String, String> projectorUsage = getProjectorUsage();
+        // 空调使用情况
         Map<String, String> airUsage = getAirUsage();
         HashMap<String, Object> returnMap = new HashMap<>();
         returnMap.put("airUsage", airUsage);
         returnMap.put("projectorUsage", projectorUsage);
         returnMap.put("computerUsage", computerUsage);
 
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("curPage", "1");
+        jsonObject.put("pageSize", "200");
+        // 调用接口获取摄像头的使用情况
+        getVideoList(jsonObject);
+
+        Map<String, String> cameraMap = new HashMap<>();
+        cameraMap.put("code", "200");
+        cameraMap.put("msg", "获取摄像头使用情况成功!");
+        cameraMap.put("camera_total", String.valueOf(camera_total));
+        cameraMap.put("camera_on_using", String.valueOf(camera_on_total));
+
+        returnMap.put("cameraUsage", cameraMap);
+
         return ResponseResult.success(returnMap);
     }
 
+    // 随机生成指定范围的浮点数
+    private String generateRandomFloat(double min, double max) {
+        Random random = new Random();
+        double randomValue = min + (max - min) * random.nextDouble();
+
+        return String.format("%.2f", randomValue);
+    }
+
+    // 获取最近30天的日期
+    private String[] getRecentDates(int numberOfDays) {
+        String[] dates = new String[numberOfDays];
+        Calendar calendar = Calendar.getInstance();
+
+        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+
+        for (int i = numberOfDays - 1; i >= 0; i--) {
+            Date date = calendar.getTime();
+            dates[i] = dateFormat.format(date);
+            calendar.add(Calendar.DAY_OF_YEAR, -1);
+        }
+
+        return dates;
+    }
+
+    // 判断指定日期是否是周末
+    private boolean isWeekend(String dateString) {
+        LocalDate date = LocalDate.parse(dateString, DateTimeFormatter.ISO_LOCAL_DATE);
+        DayOfWeek dayOfWeek = date.getDayOfWeek();
+
+        return dayOfWeek == DayOfWeek.SATURDAY || dayOfWeek == DayOfWeek.SUNDAY;
+    }
+
+    /**
+     * 获取最近30天能耗
+     * @return
+     */
+    @RequestMapping(value = "/getWAEConsumption", method = RequestMethod.POST)
+    public ResponseResult water_and_electricity() {
+        JSONArray jsonArray = new JSONArray();
+        String[] recentDates = getRecentDates(30);
+        for (String recentDate : recentDates) {
+            JSONObject jsonObject = new JSONObject();
+
+            if (isWeekend(recentDate)) {
+                jsonObject.put("waterTotalPower", generateRandomFloat(30, 80));
+                jsonObject.put("electricTotalPower", generateRandomFloat(80, 150));
+                jsonObject.put("dateTime", recentDate);
+            } else {
+                jsonObject.put("waterTotalPower", generateRandomFloat(150, 400));
+                jsonObject.put("electricTotalPower", generateRandomFloat(400, 600));
+                jsonObject.put("dateTime", recentDate);
+            }
+
+            jsonArray.add(jsonObject);
+        }
+
+        return ResponseResult.success(jsonArray);
+    }
+
     /**
      * 空调状况分析
      *