|
@@ -1,18 +1,8 @@
|
|
package cn.com.ctop.alarm.modules.service.impl;
|
|
package cn.com.ctop.alarm.modules.service.impl;
|
|
|
|
|
|
import cn.com.ctop.alarm.modules.constant.MatchLogic;
|
|
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.IRuleAccountTemplateService;
|
|
import cn.com.ctop.alarm.modules.service.IRuleGroupService;
|
|
import cn.com.ctop.alarm.modules.service.IRuleGroupService;
|
|
import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
@@ -34,6 +24,7 @@ import org.springframework.stereotype.Service;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 规则组
|
|
* 规则组
|
|
@@ -83,7 +74,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
//获取规则集
|
|
//获取规则集
|
|
- Map<Long, List<RuleGroup>> ruleGroupMap = getRuleGroupMap();
|
|
|
|
|
|
+ Map<Long, Object> ruleGroupMap = getRuleGroupMap();
|
|
if (Check.isNull(ruleGroupMap)) {
|
|
if (Check.isNull(ruleGroupMap)) {
|
|
log.warn("获取规则集失败");
|
|
log.warn("获取规则集失败");
|
|
return;
|
|
return;
|
|
@@ -95,36 +86,111 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
for (RuleAccountTemplate templates : ruleAccountTemplates) {
|
|
for (RuleAccountTemplate templates : ruleAccountTemplates) {
|
|
- List<RuleGroup> ruleGroups = ruleGroupMap.get(templates.getTemplateId());
|
|
|
|
- matchAlarmRules(ruleGroups, getThreshold(ruleAccountThresholdMapper.selectByAccountId(templates.getAccountId())), indicators, templates.getAccountId());
|
|
|
|
|
|
+ matchAlarmRules(ruleGroupMap, indicators, templates);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 匹配预警规则
|
|
* 匹配预警规则
|
|
*
|
|
*
|
|
- * @param ruleGroups 规则集
|
|
|
|
- * @param thresholdObj 规则id阈值
|
|
|
|
- * @param indicators 指标码
|
|
|
|
|
|
+ * @param ruleGroups 规则数据集
|
|
|
|
+ * @param templates 规则模板
|
|
|
|
+ * @param indicators 指标码
|
|
* @return void
|
|
* @return void
|
|
* @throws
|
|
* @throws
|
|
* @author ZHAOXA
|
|
* @author ZHAOXA
|
|
*/
|
|
*/
|
|
- private void matchAlarmRules(List<RuleGroup> ruleGroups, JSONObject thresholdObj, JSONObject indicators, Long accountId) {
|
|
|
|
|
|
+ private void matchAlarmRules(Map<Long, Object> ruleGroupMap, JSONObject indicators, RuleAccountTemplate templates) {
|
|
userObj = new JSONObject();
|
|
userObj = new JSONObject();
|
|
//查询匹配数据
|
|
//查询匹配数据
|
|
- JSONObject matchData = getRuleData(accountId);
|
|
|
|
|
|
+ JSONObject matchData = getRuleData(templates.getAccountId());
|
|
if (Check.isNull(matchData)) {
|
|
if (Check.isNull(matchData)) {
|
|
log.warn("查询匹配数据失败");
|
|
log.warn("查询匹配数据失败");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- log.info("已获取账户({})的数据,开始匹配规则", accountId);
|
|
|
|
|
|
+ boolean isCopy = false;
|
|
|
|
+ Map<Long, Object> map = (Map<Long, Object>) ruleGroupMap.get(templates.getTemplateId());
|
|
|
|
+ //媒体类型 1:头条2:快手
|
|
|
|
+ Integer type = (Integer) map.get("type");
|
|
|
|
+ //常规规则+阈值
|
|
|
|
+ List<RuleGroup> notCopyGroups = (List<RuleGroup>) map.get("notCopy");
|
|
|
|
+ JSONObject notCopythreshold = getThreshold(templates.getAccountId(), isCopy);
|
|
|
|
+ //可复制规则+阈值
|
|
|
|
+ List<RuleGroup> isCopyGroups = (List<RuleGroup>) map.get("isCopy");
|
|
|
|
+ JSONObject isCopythreshold = new JSONObject();
|
|
|
|
+ if (!Check.isNull(isCopyGroups)) {
|
|
|
|
+ isCopy = true;
|
|
|
|
+ isCopythreshold = getThreshold(templates.getAccountId(), isCopy);
|
|
|
|
+ }
|
|
|
|
+ log.info("已获取账户({})的数据,开始匹配规则", templates.getAccountId());
|
|
try {
|
|
try {
|
|
- for (RuleGroup ruleGroup : ruleGroups) {
|
|
|
|
- List<RuleBase> ruleBaseList = ruleGroup.getRuleBaseList();
|
|
|
|
- if (Check.isNull(ruleBaseList)) {
|
|
|
|
- continue;
|
|
|
|
|
|
+ if (!Check.isNull(notCopyGroups)) {
|
|
|
|
+ checkRuleGroups(notCopyGroups, notCopythreshold, indicators, matchData, type, false);
|
|
|
|
+ }
|
|
|
|
+ if (isCopy && !Check.isNull(isCopythreshold)) {
|
|
|
|
+ checkRuleGroups(isCopyGroups, isCopythreshold, indicators, matchData, type, isCopy);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("匹配规则逻辑异常", e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void checkRuleGroups(List<RuleGroup> ruleGroups, JSONObject thresholdObj, JSONObject indicators, JSONObject matchData, Integer type, boolean isCopy) {
|
|
|
|
+ for (RuleGroup ruleGroup : ruleGroups) {
|
|
|
|
+ List<RuleBase> ruleBaseList = ruleGroup.getRuleBaseList();
|
|
|
|
+ if (Check.isNull(ruleBaseList)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ //复制逻辑
|
|
|
|
+ if (isCopy) {
|
|
|
|
+ JSONObject batchNo = thresholdObj.getJSONObject(ruleGroup.getId().toString());
|
|
|
|
+ for (Map.Entry<String, Object> entry : batchNo.entrySet()) {
|
|
|
|
+ Map<String, String> thresholdMap = (Map<String, String>) entry.getValue();
|
|
|
|
+ //符合规则的数据集
|
|
|
|
+ JSONArray targetDatas = new JSONArray();
|
|
|
|
+ JSONArray planDatas = new JSONArray();
|
|
|
|
+ JSONArray creativeDatas = new JSONArray();
|
|
|
|
+ JSONArray accountDatas = new JSONArray();
|
|
|
|
+ for (RuleBase ruleBase : ruleBaseList) {
|
|
|
|
+ //指标对象
|
|
|
|
+ JSONObject indicator = indicators.getJSONObject(ruleBase.getIndicatorCode());
|
|
|
|
+ //阈值类型
|
|
|
|
+ String dataType = indicator.getString("dataType");
|
|
|
|
+ //指标阈值
|
|
|
|
+ String threshold = thresholdMap.get(ruleBase.getId());
|
|
|
|
+ //阈值为空时,或者阈值为“unlimited”(不限),不执行该规则
|
|
|
|
+ if (Check.isNull(threshold) || "unlimited".equals(threshold)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ JSONArray dimensionData = matchData.getJSONArray(ruleBase.getRuleDimension());
|
|
|
|
+ //账户维度数据
|
|
|
|
+ if ("account".equals(ruleBase.getRuleDimension())) {
|
|
|
|
+ JSONObject accountEntity = dimensionData.getJSONObject(0);
|
|
|
|
+ if (MatchLogic.matchCondition(dataType, ruleBase.getRuleCondition(), threshold, accountEntity.getString(ruleBase.getIndicatorCode()))) {
|
|
|
|
+ accountDatas.add(accountEntity);
|
|
|
|
+ } else {
|
|
|
|
+ log.warn("判断规则组({}),账户规则不符合", ruleGroup.getId());
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ } else if ("plan".equals(ruleBase.getRuleDimension())) {
|
|
|
|
+ planDatas = getOKData(planDatas, dimensionData, ruleBase, dataType, threshold);
|
|
|
|
+ } else if ("creative".equals(ruleBase.getRuleDimension())) {
|
|
|
|
+ creativeDatas = getOKData(creativeDatas, dimensionData, ruleBase, dataType, threshold);
|
|
|
|
+ } else if ("target".equals(ruleBase.getRuleDimension())) {
|
|
|
|
+ targetDatas = getOKData(targetDatas, dimensionData, ruleBase, dataType, threshold);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //获取达标可发送的数据
|
|
|
|
+ JSONArray sendData = MatchLogic.getSendData(accountDatas, planDatas, creativeDatas, targetDatas);
|
|
|
|
+ if (!Check.isNull(sendData)) {
|
|
|
|
+ //执行发送
|
|
|
|
+ for (int i = 0; i < sendData.size(); i++) {
|
|
|
|
+ sendMsg(ruleGroup, sendData.getJSONObject(i));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+ } else {
|
|
boolean isBase = "base".equals(ruleGroup.getRuleType());
|
|
boolean isBase = "base".equals(ruleGroup.getRuleType());
|
|
//匹配单规则
|
|
//匹配单规则
|
|
if (isBase) {
|
|
if (isBase) {
|
|
@@ -151,7 +217,6 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
}
|
|
}
|
|
//匹配组合规则
|
|
//匹配组合规则
|
|
} else {
|
|
} else {
|
|
- boolean flag = false;
|
|
|
|
//符合规则的数据集
|
|
//符合规则的数据集
|
|
JSONArray targetDatas = new JSONArray();
|
|
JSONArray targetDatas = new JSONArray();
|
|
JSONArray planDatas = new JSONArray();
|
|
JSONArray planDatas = new JSONArray();
|
|
@@ -197,11 +262,10 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- } catch (Exception e) {
|
|
|
|
- log.error("匹配规则逻辑异常", e);
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @param ruleDatas 达标数据集
|
|
* @param ruleDatas 达标数据集
|
|
* @param dimensionData 匹配数据
|
|
* @param dimensionData 匹配数据
|
|
@@ -310,20 +374,47 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
}
|
|
}
|
|
|
|
|
|
//整理阈值数据
|
|
//整理阈值数据
|
|
- public JSONObject getThreshold(List<RuleAccountThreshold> thresholdList) {
|
|
|
|
- if (Check.isNull(thresholdList)) {
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
- JSONObject obj = null;
|
|
|
|
|
|
+ public JSONObject getThreshold(Long accountId, boolean isCopy) {
|
|
|
|
+ JSONObject obj = new JSONObject();
|
|
try {
|
|
try {
|
|
- obj = new JSONObject();
|
|
|
|
- for (RuleAccountThreshold threshold : thresholdList) {
|
|
|
|
- obj.put(String.valueOf(threshold.getRuleId()), threshold.getThreshold());
|
|
|
|
|
|
+ if (isCopy) {
|
|
|
|
+ List<Long> groupList = ruleAccountThresholdMapper.selectGroupIdsByAccountId(accountId);
|
|
|
|
+ if (Check.isNull(groupList)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ for (Long groupId : groupList) {
|
|
|
|
+ JSONObject groupIdObj = new JSONObject();
|
|
|
|
+ List<String> batchNos = ruleAccountThresholdMapper.selectbatchNosByGroupIdId(accountId, groupId);
|
|
|
|
+ if (Check.isNull(batchNos)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ for (String batchNo : batchNos) {
|
|
|
|
+ JSONObject batchNoObj = new JSONObject();
|
|
|
|
+ List<RuleAccountThreshold> thresholdList = ruleAccountThresholdMapper.selectCopyThresholdByAccountId(accountId, groupId, batchNo);
|
|
|
|
+ if (Check.isNull(thresholdList)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ for (RuleAccountThreshold threshold : thresholdList) {
|
|
|
|
+ batchNoObj.put(String.valueOf(threshold.getRuleId()), threshold.getThreshold());
|
|
|
|
+ }
|
|
|
|
+ groupIdObj.put(batchNo.toString(), batchNoObj);
|
|
|
|
+ }
|
|
|
|
+ obj.put(groupId.toString(), groupIdObj);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ List<RuleAccountThreshold> thresholdList = ruleAccountThresholdMapper.selectByAccountId(accountId);
|
|
|
|
+ if (Check.isNull(thresholdList)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ for (RuleAccountThreshold threshold : thresholdList) {
|
|
|
|
+ obj.put(String.valueOf(threshold.getRuleId()), threshold.getThreshold());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
log.error("获取账户阈值数据集失败", e);
|
|
log.error("获取账户阈值数据集失败", e);
|
|
}
|
|
}
|
|
return obj;
|
|
return obj;
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
//整理指标数据
|
|
//整理指标数据
|
|
@@ -352,23 +443,36 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
* @throws
|
|
* @throws
|
|
* @author ZHAOXA
|
|
* @author ZHAOXA
|
|
*/
|
|
*/
|
|
- private Map<Long, List<RuleGroup>> getRuleGroupMap() {
|
|
|
|
|
|
+ private Map<Long, Object> getRuleGroupMap() {
|
|
try {
|
|
try {
|
|
- Map<Long, List<RuleGroup>> map = new HashMap<>();
|
|
|
|
|
|
+ Map<Long, Object> returnMap = new HashMap<>();
|
|
List<RuleTemplate> ruleTemplates = ruleTemplateMapper.selectByMap(null);
|
|
List<RuleTemplate> ruleTemplates = ruleTemplateMapper.selectByMap(null);
|
|
ruleTemplates.forEach(tem -> {
|
|
ruleTemplates.forEach(tem -> {
|
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
QueryWrapper<RuleGroup> groupWrapper = new QueryWrapper<>();
|
|
QueryWrapper<RuleGroup> groupWrapper = new QueryWrapper<>();
|
|
groupWrapper.eq("template_id", tem.getId());
|
|
groupWrapper.eq("template_id", tem.getId());
|
|
- List<RuleGroup> ruleGroups = ruleGroupMapper.selectList(groupWrapper);
|
|
|
|
- for (RuleGroup group : ruleGroups) {
|
|
|
|
|
|
+ groupWrapper.eq("is_copy", NoEn.NO1.valueInt());
|
|
|
|
+ List<RuleGroup> copyGroups = ruleGroupMapper.selectList(groupWrapper);
|
|
|
|
+ for (RuleGroup group : copyGroups) {
|
|
QueryWrapper<RuleBase> baseWrapper = new QueryWrapper<>();
|
|
QueryWrapper<RuleBase> baseWrapper = new QueryWrapper<>();
|
|
baseWrapper.eq("group_id", group.getId());
|
|
baseWrapper.eq("group_id", group.getId());
|
|
baseWrapper.orderByDesc("is_unlimited");
|
|
baseWrapper.orderByDesc("is_unlimited");
|
|
group.setRuleBaseList(ruleBaseMapper.selectList(baseWrapper));
|
|
group.setRuleBaseList(ruleBaseMapper.selectList(baseWrapper));
|
|
}
|
|
}
|
|
- map.put(tem.getId(), ruleGroups);
|
|
|
|
|
|
+ map.put("isCopy", copyGroups);
|
|
|
|
+ groupWrapper.eq("is_copy", NoEn.NO0.valueInt());
|
|
|
|
+ List<RuleGroup> notCopyGroups = ruleGroupMapper.selectList(groupWrapper);
|
|
|
|
+ for (RuleGroup group : notCopyGroups) {
|
|
|
|
+ QueryWrapper<RuleBase> baseWrapper = new QueryWrapper<>();
|
|
|
|
+ baseWrapper.eq("group_id", group.getId());
|
|
|
|
+ baseWrapper.orderByDesc("is_unlimited");
|
|
|
|
+ group.setRuleBaseList(ruleBaseMapper.selectList(baseWrapper));
|
|
|
|
+ }
|
|
|
|
+ map.put("notCopy", notCopyGroups);
|
|
|
|
+ map.put("type", tem.getMediaType());
|
|
|
|
+ returnMap.put(tem.getId(), map);
|
|
});
|
|
});
|
|
- return map;
|
|
|
|
|
|
+ return returnMap;
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
log.error("获取模板规则组集合异常", e);
|
|
log.error("获取模板规则组集合异常", e);
|
|
}
|
|
}
|
|
@@ -428,7 +532,15 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
if (Check.isNull(ruleDetail)) {
|
|
if (Check.isNull(ruleDetail)) {
|
|
throw new Exception("规则组下指标不能为空");
|
|
throw new Exception("规则组下指标不能为空");
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ Integer isCopy = groupJson.getInteger("isCopy");
|
|
|
|
+ String batchId = null;
|
|
|
|
+ if (isCopy == 1) {
|
|
|
|
+ batchId = UUID.randomUUID().toString().replace("-", "");
|
|
|
|
+
|
|
|
|
+ }
|
|
JSONArray ruleIds = new JSONArray();
|
|
JSONArray ruleIds = new JSONArray();
|
|
|
|
+ JSONArray thresholdIds = new JSONArray();
|
|
for (int j = 0; j < ruleDetail.size(); j++) {
|
|
for (int j = 0; j < ruleDetail.size(); j++) {
|
|
JSONObject ruleDetailJson = ruleDetail.getJSONObject(j);
|
|
JSONObject ruleDetailJson = ruleDetail.getJSONObject(j);
|
|
RuleBase ruleBase = new RuleBase();
|
|
RuleBase ruleBase = new RuleBase();
|
|
@@ -440,7 +552,8 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
ruleBase.setRuleDimension(ruleDetailJson.getString("ruleDimension"));
|
|
ruleBase.setRuleDimension(ruleDetailJson.getString("ruleDimension"));
|
|
ruleBase.setJudgeFormat(ruleDetailJson.getInteger("judgeFormat"));
|
|
ruleBase.setJudgeFormat(ruleDetailJson.getInteger("judgeFormat"));
|
|
ruleBase.setIsUnlimited(ruleDetailJson.getInteger("isUnlimited"));
|
|
ruleBase.setIsUnlimited(ruleDetailJson.getInteger("isUnlimited"));
|
|
- int insert = ruleBaseMapper.insert(ruleBase); // 添加基础规则
|
|
|
|
|
|
+ int insert = ruleBaseMapper.insert(ruleBase); // 添加基础规则
|
|
|
|
+
|
|
if (insert > 0) {
|
|
if (insert > 0) {
|
|
if (!Check.isNull(accountList)) {
|
|
if (!Check.isNull(accountList)) {
|
|
for (RuleAccountTemplate accountTemplate : accountList) {
|
|
for (RuleAccountTemplate accountTemplate : accountList) {
|
|
@@ -455,8 +568,14 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
}
|
|
}
|
|
RuleAccountThreshold threshold = new RuleAccountThreshold();
|
|
RuleAccountThreshold threshold = new RuleAccountThreshold();
|
|
threshold.setAccountId(accountId);
|
|
threshold.setAccountId(accountId);
|
|
|
|
+ if (isCopy == 1) {
|
|
|
|
+ threshold.setBatchNo(batchId);
|
|
|
|
+ }
|
|
threshold.setRuleId(ruleBase.getId());
|
|
threshold.setRuleId(ruleBase.getId());
|
|
- ruleAccountThresholdMapper.insert(threshold); // 默认将新建的规则同步到已应用的账户下
|
|
|
|
|
|
+ int thresholdInsert = ruleAccountThresholdMapper.insert(threshold);// 默认将新建的规则同步到已应用的账户下
|
|
|
|
+ if (thresholdInsert > 0) {
|
|
|
|
+ thresholdIds.add(threshold.getId());
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
ruleIds.add(ruleBase.getId()); // 获取基本规则集
|
|
ruleIds.add(ruleBase.getId()); // 获取基本规则集
|
|
@@ -473,15 +592,21 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
ruleGroup.setIsRequired(groupJson.getInteger("isRequired"));
|
|
ruleGroup.setIsRequired(groupJson.getInteger("isRequired"));
|
|
boolean save = ruleGroupService.save(ruleGroup); // 新增规则组
|
|
boolean save = ruleGroupService.save(ruleGroup); // 新增规则组
|
|
if (save) {
|
|
if (save) {
|
|
-
|
|
|
|
for (int j = 0; j < ruleIds.size(); j++) {
|
|
for (int j = 0; j < ruleIds.size(); j++) {
|
|
Long ruleId = ruleIds.getLong(j);
|
|
Long ruleId = ruleIds.getLong(j);
|
|
RuleBase updateRuleBase = new RuleBase();
|
|
RuleBase updateRuleBase = new RuleBase();
|
|
updateRuleBase.setId(ruleId);
|
|
updateRuleBase.setId(ruleId);
|
|
updateRuleBase.setGroupId(ruleGroup.getId());
|
|
updateRuleBase.setGroupId(ruleGroup.getId());
|
|
- ruleBaseMapper.updateById(updateRuleBase);
|
|
|
|
|
|
+ ruleBaseMapper.updateById(updateRuleBase); // 组同步成功之后 基础规则关联到组id
|
|
}
|
|
}
|
|
|
|
+ for (int j = 0; j < thresholdIds.size(); j++) {
|
|
|
|
+ Long threshold = thresholdIds.getLong(j);
|
|
|
|
+ RuleAccountThreshold updateThreshold = new RuleAccountThreshold();
|
|
|
|
+ updateThreshold.setId(threshold);
|
|
|
|
+ updateThreshold.setGroupId(ruleGroup.getId());
|
|
|
|
+ ruleAccountThresholdMapper.updateById(updateThreshold); // 同步到阈值之后 阈值关联到组id
|
|
|
|
|
|
|
|
+ }
|
|
JSONArray groupIds = JSONArray.parseArray(template.getGroupIds());
|
|
JSONArray groupIds = JSONArray.parseArray(template.getGroupIds());
|
|
groupIds.add(ruleGroup.getId());
|
|
groupIds.add(ruleGroup.getId());
|
|
template.setGroupIds(groupIds.toJSONString());
|
|
template.setGroupIds(groupIds.toJSONString());
|