perf: 一轮采集时间相差3秒内用第一个时间

main
huangfeng 7 months ago
parent dc45bf3d00
commit 9a49f77476

@ -34,7 +34,7 @@ public class IEDCollectService {
BizConfig _bizConfig;
String folder = "/record";
String sameTime;
String firstOneTime;
public IEDCollectService(IcdConfigTypeRepository configRepository, IcdConfigTypeAttRepository attRepository,
IcdConfigTypeInstRepository instRepository, RptparamindexRepository rptparamindexRepository,
@ -71,7 +71,7 @@ public class IEDCollectService {
try {
log.info("61850开始采集数据, ied=" + ied.getName() + ", ip=" + ied.getIp() + ", port=" + ied.getPort());
this.connect();
sameTime = null;
firstOneTime = null;
if (!CollectionUtils.isEmpty(rptList)) {
this.doCollectAndSave(configTypeList, rptList);
}
@ -136,14 +136,19 @@ public class IEDCollectService {
}
private String makeSameTime(String time) {
if (sameTime == null) {
sameTime = time;
if (firstOneTime == null) {
firstOneTime = time;
} else {
if (!sameTime.equals(time)) {
if (!firstOneTime.equals(time)) {
long sec = DateUtil.secondDiff(firstOneTime, time);
if (sec >= 0 && sec < 3) {
} else {
return time;
}
}
}
return sameTime;
return firstOneTime;
}
private Rptparamindex findRpt(List<Rptparamindex> rptList, String paramindex) {

@ -115,4 +115,22 @@ public class DateUtil {
return result;
}
public static long secondDiff(String str1, String str2) {
try {
Date date1 = parse(str1);
Date date2 = parse(str2);
long sec1 = date1.getTime();
long sec2 = date2.getTime();
if (sec1 >= sec2) {
long sec = sec1 - sec2;
return sec / 1000;
} else {
long sec = sec2 - sec1;
return sec / 1000;
}
} catch (Exception e) {
return -1;
}
}
}

Loading…
Cancel
Save