|
@@ -1,18 +1,8 @@
|
|
|
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;
|
|
@@ -254,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");
|
|
|
}
|
|
@@ -292,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); // 默认将新建的规则同步到已应用的账户下
|
|
|
}
|
|
|
}
|
|
@@ -305,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());
|