From da8328c2f9d836b14f08a65f7b29b98fa09283f2 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期五, 19 五月 2023 10:41:37 +0800
Subject: [PATCH] 1

---
 src/main/resources/mapping/QxshMapper.xml   |   12 +++++++++++-
 src/main/java/com/yssh/dao/QxshMapper.java  |    3 +++
 src/main/java/com/yssh/utils/DateUtils.java |   22 ++++++++++++++++++----
 3 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/yssh/dao/QxshMapper.java b/src/main/java/com/yssh/dao/QxshMapper.java
index 2ce717b..e658653 100644
--- a/src/main/java/com/yssh/dao/QxshMapper.java
+++ b/src/main/java/com/yssh/dao/QxshMapper.java
@@ -2,6 +2,7 @@
 
 import com.yssh.entity.Qxsh;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -15,4 +16,6 @@
     public List<Qxsh> selectByTime(String time);
 
     public List<Qxsh> selectMonthTop10(String time);
+
+    public List<Qxsh> select3Hours(@Param("times") List<String> times);
 }
diff --git a/src/main/java/com/yssh/utils/DateUtils.java b/src/main/java/com/yssh/utils/DateUtils.java
index 58c1e92..0e771f4 100644
--- a/src/main/java/com/yssh/utils/DateUtils.java
+++ b/src/main/java/com/yssh/utils/DateUtils.java
@@ -3,10 +3,7 @@
 import java.lang.management.ManagementFactory;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.LinkedHashMap;
-import java.util.Map;
+import java.util.*;
 
 import org.apache.commons.lang3.time.DateFormatUtils;
 
@@ -177,6 +174,23 @@
 		calendar.add(dateType, day);
 		return calendar.getTime();
 	}
+
+	public static List<String> get3Hours() {
+		List<String> times = new ArrayList<>();
+		SimpleDateFormat ymdh = new SimpleDateFormat(YYYYMMDDHH);
+
+		Calendar calendar = Calendar.getInstance();
+		calendar.add(Calendar.HOUR_OF_DAY, 1);
+
+		for (int i = 0; i < 3; i++) {
+			calendar.add(Calendar.HOUR_OF_DAY, -1);
+			String time = ymdh.format(calendar.getTime());
+			// times.add(time);
+			times.add(0, time);
+		}
+
+		return times;
+	}
 	
 	/**
 	 */
diff --git a/src/main/resources/mapping/QxshMapper.xml b/src/main/resources/mapping/QxshMapper.xml
index 162fbd6..69df436 100644
--- a/src/main/resources/mapping/QxshMapper.xml
+++ b/src/main/resources/mapping/QxshMapper.xml
@@ -9,10 +9,20 @@
     </select>
 
     <select id="selectMonthTop10" resultType="com.yssh.entity.Qxsh">
-        select id, name, format(value, 2) "value", time
+        select id, name, format(value, 3) "value", time
         from yssh_qxsh
         where time like #{time} and name like 'AI-%'
         order by value desc
         limit 10;
     </select>
+
+    <select id="select3Hours" resultType="com.yssh.entity.Qxsh">
+        select id, name, format(value, 3) "value", time
+        from yssh_qxsh
+        where name like 'AI-%' and time in
+            <foreach collection="times" item="time" open="(" separator="," close=")">
+                #{time}
+            </foreach>
+        order by name, time;
+    </select>
 </mapper>
\ No newline at end of file

--
Gitblit v1.9.3