|
@@ -17,6 +17,8 @@ import org.springframework.stereotype.Component;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.time.format.DateTimeFormatterBuilder;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
@@ -171,7 +173,7 @@ public class TsdbUtils extends InfluxDbUtils {
|
|
|
if(columns.get(i).equals("time")){
|
|
|
Date time = null;
|
|
|
try {
|
|
|
- time = simpleDateFormat1.parse(value.get(i).toString());
|
|
|
+ time = simpleDateFormat1.parse(padMilliseconds(value.get(i).toString()));
|
|
|
} catch (ParseException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -180,7 +182,7 @@ public class TsdbUtils extends InfluxDbUtils {
|
|
|
} else if(columns.get(i).equals("timestamp")){
|
|
|
Date time = null;
|
|
|
try {
|
|
|
- time = simpleDateFormat1.parse(value.get(i).toString());
|
|
|
+ time = simpleDateFormat1.parse(padMilliseconds(value.get(i).toString()));
|
|
|
} catch (ParseException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -199,6 +201,14 @@ public class TsdbUtils extends InfluxDbUtils {
|
|
|
return results;
|
|
|
}
|
|
|
|
|
|
+ private static String padMilliseconds(String timeStr) {
|
|
|
+ // 检查是否缺少毫秒部分(格式: YYYY-MM-DDTHH:MM:SSZ)
|
|
|
+ if (timeStr.matches("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}[+-]\\d{2}:\\d{2}")) {
|
|
|
+ return timeStr.replace("+08:00", ".000+08:00");
|
|
|
+ }
|
|
|
+ return timeStr; // 已有毫秒部分,直接返回
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 查询,返回Map集合
|
|
|
*
|
|
@@ -224,7 +234,7 @@ public class TsdbUtils extends InfluxDbUtils {
|
|
|
if(!value.get(i).equals("1970-01-01T00:00:00Z")){
|
|
|
Date time = null;
|
|
|
try {
|
|
|
- time = simpleDateFormat1.parse(value.get(i).toString());
|
|
|
+ time = simpleDateFormat1.parse(padMilliseconds(value.get(i).toString()));
|
|
|
} catch (ParseException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
@@ -235,7 +245,7 @@ public class TsdbUtils extends InfluxDbUtils {
|
|
|
} else if(columns.get(i).equals("timestamp")){
|
|
|
Date time = null;
|
|
|
try {
|
|
|
- time = simpleDateFormat1.parse(value.get(i).toString());
|
|
|
+ time = simpleDateFormat1.parse(padMilliseconds(value.get(i).toString()));
|
|
|
} catch (ParseException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|