|
|
|
@ -1,16 +1,12 @@
|
|
|
|
|
package com.xydl.cac.task;
|
|
|
|
|
|
|
|
|
|
import com.xydl.cac.comparator.FloatCompare;
|
|
|
|
|
import com.xydl.cac.comparator.IntCompare;
|
|
|
|
|
import com.xydl.cac.entity.ModevTypePoint;
|
|
|
|
|
import com.xydl.cac.entity.NSensor;
|
|
|
|
|
import com.xydl.cac.entity.WarnRule;
|
|
|
|
|
import com.xydl.cac.entity.Warning;
|
|
|
|
|
import com.xydl.cac.entity.constants.Constants;
|
|
|
|
|
import com.xydl.cac.repository.WarnRuleRepository;
|
|
|
|
|
import com.xydl.cac.repository.WarningRepository;
|
|
|
|
|
import com.xydl.cac.service.DataService;
|
|
|
|
|
import com.xydl.cac.service.WarnRuleService;
|
|
|
|
|
import com.xydl.cac.util.DateUtil;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
@ -25,8 +21,6 @@ import java.util.Map;
|
|
|
|
|
@Service
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class RuleCheckTask {
|
|
|
|
|
@Resource
|
|
|
|
|
WarnRuleService ruleService;
|
|
|
|
|
@Resource
|
|
|
|
|
WarnRuleRepository ruleRepository;
|
|
|
|
|
@Resource
|
|
|
|
@ -34,12 +28,11 @@ public class RuleCheckTask {
|
|
|
|
|
@Resource
|
|
|
|
|
WarningRepository warningRepository;
|
|
|
|
|
|
|
|
|
|
@Scheduled(initialDelay = 60000, fixedDelay = 60000)
|
|
|
|
|
@Scheduled(initialDelay = 90000, fixedDelay = 60000)
|
|
|
|
|
private void checkAll() {
|
|
|
|
|
try {
|
|
|
|
|
List<WarnRule> ruleList = ruleService.listAll();
|
|
|
|
|
for (WarnRule rule : ruleList) {
|
|
|
|
|
if (rule.getActive() != null && rule.getActive().intValue() == 1) {
|
|
|
|
|
for (WarnRule rule : CacheTask.rule_Cache.values()) {
|
|
|
|
|
if (rule.canDo()) {
|
|
|
|
|
this.ruleCheck(rule);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -49,19 +42,6 @@ public class RuleCheckTask {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ruleCheck(WarnRule rule) {
|
|
|
|
|
if (Constants.FloatCompare.equalsIgnoreCase(rule.getComparator())) {
|
|
|
|
|
FloatCompare comparat = new FloatCompare();
|
|
|
|
|
comparat.setOperator(rule.getOperator());
|
|
|
|
|
rule.setComparat(comparat);
|
|
|
|
|
} else if (Constants.IntCompare.equalsIgnoreCase(rule.getComparator())) {
|
|
|
|
|
IntCompare comparat = new IntCompare();
|
|
|
|
|
comparat.setOperator(rule.getOperator());
|
|
|
|
|
rule.setComparat(comparat);
|
|
|
|
|
} else {
|
|
|
|
|
log.error("该规则(" + rule.getId() + ")缺少比较器");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
NSensor sensor = rule.getNSensor();
|
|
|
|
|
ModevTypePoint typePoint = rule.getTypePoint();
|
|
|
|
@ -72,7 +52,7 @@ public class RuleCheckTask {
|
|
|
|
|
String str = (String) map.get("acquisitionTime");
|
|
|
|
|
date = DateUtil.parse(str);
|
|
|
|
|
Object value = map.get(typePoint.getField());
|
|
|
|
|
boolean r = rule.getComparat().compare(value, rule.getThreshold());
|
|
|
|
|
boolean r = rule.getActualComp().compare(value, rule.getThreshold());
|
|
|
|
|
if (r) {
|
|
|
|
|
this.sendWarning(rule, date, value);
|
|
|
|
|
}
|
|
|
|
|