perf: 设置一天只发一个触发

dev
huangfeng 12 months ago
parent ac83b310cb
commit 5504168578

@ -1,18 +1,24 @@
package com.xydl.cac.comparator; package com.xydl.cac.comparator;
import com.xydl.cac.exception.BusinessException;
import java.util.Date; import java.util.Date;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
public class MissCompare extends Comparator { public class MissCompare extends Comparator {
// 一天触发一次
boolean done = false;
@Override @Override
public boolean compare(Object source, String threshold, Date lastDTime) { public boolean compare(Object source, String threshold, Date lastDTime) {
if (source == null && lastDTime != null) { if (!done && source == null && lastDTime != null) {
long t2 = Long.parseLong(threshold); long t2 = Long.parseLong(threshold);
long last = System.currentTimeMillis() - lastDTime.getTime(); long last = System.currentTimeMillis() - lastDTime.getTime();
hours = last / 1000 / 60 / 60; hours = last / 1000 / 60 / 60;
if (hours >= t2) { if (hours >= t2) {
done = true;
return true; return true;
} }
} }
@ -28,6 +34,10 @@ public class MissCompare extends Comparator {
@Override @Override
public void valid(String operator, String threshold) throws Exception { public void valid(String operator, String threshold) throws Exception {
Integer hours = Integer.parseInt(threshold);
if (hours <= 1) {
throw new BusinessException("阈值必须大于1");
}
} }
} }

@ -27,7 +27,7 @@ public class CacheTask {
public static List<Zsb> zsb_Cache = null; public static List<Zsb> zsb_Cache = null;
public static ConcurrentHashMap<Integer, WarnRule> rule_Cache = new ConcurrentHashMap<>(); public static ConcurrentHashMap<Integer, WarnRule> rule_Cache = new ConcurrentHashMap<>();
@Scheduled(cron = "0 1 * * * ?") @Scheduled(cron = "0 9 * * * ?")
private void clearCache() { private void clearCache() {
unit_Cache.clear(); unit_Cache.clear();
modevType_Cache = null; modevType_Cache = null;

Loading…
Cancel
Save