|
@@ -1,20 +1,11 @@
|
|
|
package cn.com.ctop.alarm.modules.service.impl;
|
|
|
|
|
|
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.entity.*;
|
|
|
+import cn.com.ctop.alarm.modules.mapper.*;
|
|
|
import cn.com.ctop.alarm.modules.service.IRuleAccountTemplateService;
|
|
|
import cn.com.ctop.alarm.modules.service.IRuleGroupService;
|
|
|
+import cn.com.ctop.common.module.service.ISendMessageService;
|
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
@@ -56,6 +47,8 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
|
private IRuleGroupService ruleGroupService;
|
|
|
@Autowired
|
|
|
private IRuleAccountTemplateService ruleAccountTemplateService;
|
|
|
+ @Autowired
|
|
|
+ private ISendMessageService sendMessageService;
|
|
|
|
|
|
@Override
|
|
|
public void checkRules() {
|
|
@@ -130,17 +123,18 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
|
}
|
|
|
//执行发送
|
|
|
if (flag) {
|
|
|
-// MatchLogic.getMsg()
|
|
|
boolean isPause = "PAUSE".equals(ruleGroup.getOperate());
|
|
|
- String sendType = ruleGroup.getSendType();
|
|
|
- if(isPause){
|
|
|
+ if (isPause) {
|
|
|
//关停操作 TODO
|
|
|
|
|
|
}
|
|
|
+ //TODO
|
|
|
+ String msg = MatchLogic.getMsg(null, null, null, null);
|
|
|
+ String sendType = ruleGroup.getSendType();
|
|
|
if ("SMS".equals(sendType)) {
|
|
|
|
|
|
} else if ("WeChat".equals(sendType)) {
|
|
|
-
|
|
|
+ sendMessageService.sendMessage("", msg);
|
|
|
} else if ("EMAIL".equals(sendType)) {
|
|
|
|
|
|
} else if ("TEL".equals(sendType)) {
|
|
@@ -153,18 +147,6 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private boolean checkThreshold(String threshold, RuleBase ruleBase, JSONObject indicator) {
|
|
|
- //条件
|
|
|
- String condition = ruleBase.getRuleCondition();
|
|
|
- //指标
|
|
|
- String indicatorCode = ruleBase.getIndicatorCode();
|
|
|
- //维度
|
|
|
- String ruleDimension = ruleBase.getRuleDimension();
|
|
|
-
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
//整理阈值数据
|
|
|
public JSONObject getThreshold(List<RuleAccountThreshold> thresholdList) {
|
|
|
if (Check.isNull(thresholdList)) {
|
|
@@ -220,13 +202,20 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
|
|
|
|
//拆分逗号拼接数据
|
|
|
private List<String> strToList(String strings) {
|
|
|
- if (Check.isNull(strings)) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- List<String> ids = new ArrayList<>();
|
|
|
- String[] idArray = strings.split(",");
|
|
|
- for (String id : idArray) {
|
|
|
- ids.add(id);
|
|
|
+ List<String> ids = null;
|
|
|
+ try {
|
|
|
+ if (Check.isNull(strings)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ JSONObject job = new JSONObject();
|
|
|
+ job.put("list", strings);
|
|
|
+ ids = new ArrayList<>();
|
|
|
+ JSONArray idList = job.getJSONArray("list");
|
|
|
+ for (Object id : idList) {
|
|
|
+ ids.add(String.valueOf(id));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("ids格式转换异常", e);
|
|
|
}
|
|
|
return ids;
|
|
|
}
|
|
@@ -255,7 +244,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
|
public JSONObject createRuleGroup(com.alibaba.fastjson.JSONObject requestJson) {
|
|
|
JSONObject returnJson = new JSONObject();
|
|
|
try {
|
|
|
- String templateId = requestJson.getString("templateId");
|
|
|
+ Long templateId = requestJson.getLong("templateId");
|
|
|
if (Check.isNull(templateId)) {
|
|
|
throw new Exception("请选择需要创建的规则模板id");
|
|
|
}
|
|
@@ -293,10 +282,17 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
|
if (!Check.isNull(accountList)) {
|
|
|
for (RuleAccountTemplate accountTemplate : accountList) {
|
|
|
Long accountId = accountTemplate.getAccountId();
|
|
|
+ QueryWrapper<RuleAccountThreshold> thresholdQueryWrapper = new QueryWrapper<>();
|
|
|
+ thresholdQueryWrapper.eq("account_id", accountId);
|
|
|
+ thresholdQueryWrapper.eq("rule_id", ruleBase.getId());
|
|
|
+ thresholdQueryWrapper.last("limit 1");
|
|
|
+ RuleAccountThreshold accountThreshold = ruleAccountThresholdMapper.selectOne(thresholdQueryWrapper);
|
|
|
+ if (!Check.isNull(accountThreshold)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
RuleAccountThreshold threshold = new RuleAccountThreshold();
|
|
|
threshold.setAccountId(accountId);
|
|
|
threshold.setRuleId(ruleBase.getId());
|
|
|
- // threshold.setThreshoId(ruleDetailJson.getString("threshold"));
|
|
|
ruleAccountThresholdMapper.insert(threshold); // 默认将新建的规则同步到已应用的账户下
|
|
|
}
|
|
|
}
|
|
@@ -306,11 +302,21 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
|
RuleGroup ruleGroup = new RuleGroup();
|
|
|
ruleGroup.setRuleIds(ruleIds.toJSONString());
|
|
|
ruleGroup.setRuleType(groupJson.getString("ruleType"));
|
|
|
+ ruleGroup.setTemplateId(templateId);
|
|
|
ruleGroup.setRuleRelationship(groupJson.getString("ruleRelationship"));
|
|
|
ruleGroup.setGroupName(groupJson.getString("groupName"));
|
|
|
ruleGroup.setRemark(groupJson.getString("remark"));
|
|
|
boolean save = ruleGroupService.save(ruleGroup); // 新增规则组
|
|
|
if (save) {
|
|
|
+
|
|
|
+ for (int j = 0; j < ruleIds.size(); j++) {
|
|
|
+ Long ruleId = ruleIds.getLong(j);
|
|
|
+ RuleBase updateRuleBase = new RuleBase();
|
|
|
+ updateRuleBase.setId(ruleId);
|
|
|
+ updateRuleBase.setGroupId(ruleGroup.getId());
|
|
|
+ ruleBaseMapper.updateById(updateRuleBase);
|
|
|
+ }
|
|
|
+
|
|
|
JSONArray groupIds = JSONArray.parseArray(template.getGroupIds());
|
|
|
groupIds.add(ruleGroup.getId());
|
|
|
template.setGroupIds(groupIds.toJSONString());
|