فهرست منبع

定时刷新页面

oyq28 1 سال پیش
والد
کامیت
c800ea1997

+ 3 - 3
src/main/java/com/imcs/admin/business/service/impl/BigScreenDetailServiceImpl.java

@@ -86,9 +86,9 @@ public class BigScreenDetailServiceImpl implements BigScreenDetailService {
 
 
     public void getleftBox(String ip,JSONObject jsonObject,PageParam pageParam){
-        StringBuffer str=new StringBuffer("SELECT ROUND(AVG(device_rate),2) as avg_device_rate,ROUND(100 - AVG(device_rate), 2) AS dif_avg_device_rate\n" +
+        StringBuffer str=new StringBuffer("SELECT ROUND((sum(today_power_on_time)/60)/(16 * count(*)),2) as avg_device_rate, ROUND(100-(sum(today_power_on_time)/60)/(16 * count(*)),2) dif_avg_device_rate\n" +
                 "FROM device_collection_detail\n" +
-                "WHERE MONTH(create_date) = ? and device_ip= ? ");
+                "WHERE DATE_FORMAT(create_date, '%Y-%m') = ? and device_ip= ? ");
         List<Object> detailArgs = new ArrayList<>();
         detailArgs.add(StrUtil.format("{}",DateUtils.getCurrentMonth()));
         detailArgs.add(StrUtil.format("{}",ip));
@@ -108,7 +108,7 @@ public class BigScreenDetailServiceImpl implements BigScreenDetailService {
                 .map(date -> "'" + date + "'")
                 .collect(Collectors.joining(", "));
         StringBuffer str=new StringBuffer("SELECT CONCAT(YEAR(create_date), '-', LPAD(MONTH(create_date), 2, '0')) AS year_month_str,\n" +
-                "       ROUND(AVG(device_rate),2) AS average_value\n" +
+                "       ROUND((sum(today_power_on_time)/60)/(16 * count(*)),2) AS average_value\n" +
                 "FROM device_collection_detail\n" +
                 "where DATE_FORMAT(create_date, '%Y-%m') in ("+collect+") and device_ip = ? " +
                 "GROUP BY CONCAT(YEAR(create_date), '-', LPAD(MONTH(create_date), 2, '0')) order by CONCAT(YEAR(create_date), '-', LPAD(MONTH(create_date), 2, '0')) asc ");

+ 7 - 3
src/main/java/com/imcs/admin/util/DateUtils.java

@@ -2,6 +2,7 @@ package com.imcs.admin.util;
 
 import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
+import java.time.YearMonth;
 import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
 import java.util.Calendar;
@@ -37,9 +38,12 @@ public class DateUtils {
         return dateFormat.format(new Date());
     }
 
-    public static int getCurrentMonth() {
-        Calendar calendar = Calendar.getInstance();
-        return calendar.get(Calendar.MONTH) + 1; // 注意月份是从 0 开始的,所以需要加 1
+    public static String  getCurrentMonth() {
+        YearMonth currentYearMonth = YearMonth.now();
+
+        // 将年份和月份格式化为字符串,例如 "yyyy-MM"
+        String formattedYearMonth = currentYearMonth.format(DateTimeFormatter.ofPattern("yyyy-MM"));
+        return formattedYearMonth;
     }
 
     /**

+ 1 - 1
src/main/resources/static/admin/bigScreenDetail/index.html

@@ -155,7 +155,7 @@
                     <header class="t_b_h">
                         <span>设备状态</span>
                         <img src="img/end.png"></img>
-                        <h3>${data.deviceState}</h3>
+                        <h4>${data.deviceState}</h4>
                     </header>
                     <main class="t_b_m">
                         <img src="img/map.png" alt="">