|
@@ -1,7 +1,18 @@
|
|
|
package cn.com.ctop.alarm.modules.service.impl;
|
|
|
|
|
|
-import cn.com.ctop.alarm.modules.entity.*;
|
|
|
-import cn.com.ctop.alarm.modules.mapper.*;
|
|
|
+import cn.com.ctop.alarm.modules.constant.MatchLogic;
|
|
|
+import cn.com.ctop.alarm.modules.entity.RuleAccountTemplate;
|
|
|
+import cn.com.ctop.alarm.modules.entity.RuleAccountThreshold;
|
|
|
+import cn.com.ctop.alarm.modules.entity.RuleBase;
|
|
|
+import cn.com.ctop.alarm.modules.entity.RuleGroup;
|
|
|
+import cn.com.ctop.alarm.modules.entity.RuleIndicator;
|
|
|
+import cn.com.ctop.alarm.modules.entity.RuleTemplate;
|
|
|
+import cn.com.ctop.alarm.modules.mapper.RuleAccountTemplateMapper;
|
|
|
+import cn.com.ctop.alarm.modules.mapper.RuleAccountThresholdMapper;
|
|
|
+import cn.com.ctop.alarm.modules.mapper.RuleBaseMapper;
|
|
|
+import cn.com.ctop.alarm.modules.mapper.RuleGroupMapper;
|
|
|
+import cn.com.ctop.alarm.modules.mapper.RuleIndicatorMapper;
|
|
|
+import cn.com.ctop.alarm.modules.mapper.RuleTemplateMapper;
|
|
|
import cn.com.ctop.alarm.modules.service.IRuleAccountTemplateService;
|
|
|
import cn.com.ctop.alarm.modules.service.IRuleGroupService;
|
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
@@ -9,10 +20,10 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -25,6 +36,7 @@ import java.util.Map;
|
|
|
* @version V1.0
|
|
|
* @date 2020-11-15
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@Service
|
|
|
public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup> implements IRuleGroupService {
|
|
|
|
|
@@ -94,27 +106,51 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
|
*/
|
|
|
private void matchAlarmRules(List<RuleGroup> ruleGroups, JSONObject thresholdObj, JSONObject matchData, JSONObject indicators) {
|
|
|
for (RuleGroup ruleGroup : ruleGroups) {
|
|
|
- String sendType = ruleGroup.getSendType();
|
|
|
- boolean isPause = "PAUSE".equals(ruleGroup.getOperate());
|
|
|
boolean isAllTrue = "and".equals(ruleGroup.getRuleRelationship());
|
|
|
boolean flag = true;
|
|
|
List<RuleBase> ruleBaseList = ruleGroup.getRuleBaseList();
|
|
|
for (RuleBase ruleBase : ruleBaseList) {
|
|
|
+ //指标阈值
|
|
|
+ String threshold = thresholdObj.getString(ruleBase.getId().toString());
|
|
|
+ String value = matchData.getString(ruleBase.getIndicatorCode());
|
|
|
+ //指标对象
|
|
|
+ JSONObject indicator = indicators.getJSONObject(ruleBase.getIndicatorCode());
|
|
|
//and关系,全部匹配规则
|
|
|
if (isAllTrue) {
|
|
|
if (flag) {
|
|
|
- //指标阈值
|
|
|
- String threshold = thresholdObj.getString(ruleBase.getId().toString());
|
|
|
- //指标对象
|
|
|
- JSONObject indicator = indicators.getJSONObject(ruleBase.getIndicatorCode());
|
|
|
- flag = checkThreshold(threshold, ruleBase, indicator);
|
|
|
+ flag = MatchLogic.matchCondition(indicator.getString("dataType"), ruleBase.getRuleCondition(), threshold, value);
|
|
|
}
|
|
|
} else {
|
|
|
+ //or关系,任一阈值匹配,则跳出循环
|
|
|
+ flag = MatchLogic.matchCondition(indicator.getString("dataType"), ruleBase.getRuleCondition(), threshold, value);
|
|
|
+ if (flag) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //执行发送
|
|
|
+ if (flag) {
|
|
|
+// MatchLogic.getMsg()
|
|
|
+ boolean isPause = "PAUSE".equals(ruleGroup.getOperate());
|
|
|
+ String sendType = ruleGroup.getSendType();
|
|
|
+ if(isPause){
|
|
|
+ //关停操作 TODO
|
|
|
+
|
|
|
+ }
|
|
|
+ if ("SMS".equals(sendType)) {
|
|
|
+
|
|
|
+ } else if ("WeChat".equals(sendType)) {
|
|
|
+
|
|
|
+ } else if ("EMAIL".equals(sendType)) {
|
|
|
+
|
|
|
+ } else if ("TEL".equals(sendType)) {
|
|
|
+
|
|
|
+ } else {
|
|
|
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
private boolean checkThreshold(String threshold, RuleBase ruleBase, JSONObject indicator) {
|
|
@@ -128,50 +164,6 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- private boolean check(String type, String condition, String threshold, String value) {
|
|
|
- if ("number".equals(type)) {
|
|
|
- BigDecimal bigThr = new BigDecimal(threshold);
|
|
|
- BigDecimal bigVal = new BigDecimal(value);
|
|
|
- if ("equal".equals(condition))
|
|
|
- return bigVal.compareTo(bigThr) == 0;
|
|
|
- else if ("not_equal".equals(condition))
|
|
|
- return bigVal.compareTo(bigThr) != 0;
|
|
|
- else if ("greater".equals(condition))
|
|
|
- return bigVal.compareTo(bigThr) > 0;
|
|
|
- else if ("less".equals(condition))
|
|
|
- return bigVal.compareTo(bigThr) < 0;
|
|
|
- else if ("greater_equal".equals(condition))
|
|
|
- return bigVal.compareTo(bigThr) >= 0;
|
|
|
- else if ("less_equal".equals(condition))
|
|
|
- return bigVal.compareTo(bigThr) <= 0;
|
|
|
- } else if ("string".equals(type)) {
|
|
|
- if ("equal".equals(condition))
|
|
|
- return value.equals(threshold);
|
|
|
- else if ("not_equal".equals(condition))
|
|
|
- return !value.equals(threshold);
|
|
|
- else if ("contain".equals(condition))
|
|
|
- return !value.contains(threshold);
|
|
|
- else if ("no_contain".equals(condition))
|
|
|
- return !value.contains(threshold);
|
|
|
- } else {
|
|
|
- String[] strings = threshold.split(",");
|
|
|
- if ("contain".equals(condition)) {
|
|
|
- for (String string : strings) {
|
|
|
- if (value.contains(string)) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- for (String string : strings) {
|
|
|
- if (!value.contains(string)) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
//整理阈值数据
|
|
|
public JSONObject getThreshold(List<RuleAccountThreshold> thresholdList) {
|