fix: 如果采集的时间小于2000年,忽略该条数据

main
huangfeng 6 months ago
parent e596b56222
commit 02db7284cb

@ -131,6 +131,9 @@ public class IEDCollectService {
String time = timeNode.getValueString(); String time = timeNode.getValueString();
log.info("采集到" + fc + " " + paramindexNew + "=" + value + ", t=" + time); log.info("采集到" + fc + " " + paramindexNew + "=" + value + ", t=" + time);
time = DateUtil.fromZoneUTCToLocal(time); time = DateUtil.fromZoneUTCToLocal(time);
if (time == null) {
return;
}
time = this.makeSameTime(rpt.getEqmid(), time); time = this.makeSameTime(rpt.getEqmid(), time);
_dataService.insertData(rpt.getTablename(), rpt.getEqmid(), time, rpt.getColname(), value); _dataService.insertData(rpt.getTablename(), rpt.getEqmid(), time, rpt.getColname(), value);

@ -76,6 +76,9 @@ public class StaticVariable {
value = bda.getValueString(); value = bda.getValueString();
if ("acquisitionTime".equals(colname)) { if ("acquisitionTime".equals(colname)) {
value = DateUtil.fromZoneUTCToLocal(value); value = DateUtil.fromZoneUTCToLocal(value);
if (value == null) {
return;
}
} }
updateLastData(eqmid, colname, value, null); updateLastData(eqmid, colname, value, null);
} }

@ -1,5 +1,7 @@
package com.xydl.cac.util; package com.xydl.cac.util;
import lombok.extern.slf4j.Slf4j;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.*; import java.time.*;
@ -8,6 +10,7 @@ import java.time.temporal.ChronoUnit;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
@Slf4j
public class DateUtil { public class DateUtil {
public final static String defaultDatePattern = "yyyy-MM-dd HH:mm:ss"; public final static String defaultDatePattern = "yyyy-MM-dd HH:mm:ss";
public static DateTimeFormatter defaultFormatter = DateTimeFormatter.ofPattern(defaultDatePattern); public static DateTimeFormatter defaultFormatter = DateTimeFormatter.ofPattern(defaultDatePattern);
@ -109,6 +112,10 @@ public class DateUtil {
Date date = parse(time); Date date = parse(time);
time = format(date); time = format(date);
LocalDateTime localtime = LocalDateTime.parse(time, defaultFormatter); LocalDateTime localtime = LocalDateTime.parse(time, defaultFormatter);
if (localtime.getYear() < 2000) {
log.warn("该时间小于2000年: " + str);
return null;
}
ZonedDateTime zonedDateTime = localtime.atZone(ZoneOffset.UTC); ZonedDateTime zonedDateTime = localtime.atZone(ZoneOffset.UTC);
ZonedDateTime convertedDateTime = zonedDateTime.withZoneSameInstant(ZoneId.systemDefault()); ZonedDateTime convertedDateTime = zonedDateTime.withZoneSameInstant(ZoneId.systemDefault());
String result = convertedDateTime.format(defaultFormatter); String result = convertedDateTime.format(defaultFormatter);

Loading…
Cancel
Save