|
@@ -2,12 +2,14 @@ package cn.com.ctop.alarm.modules.service.impl;
|
|
|
|
|
|
import cn.com.ctop.alarm.modules.constant.MatchLogic;
|
|
|
import cn.com.ctop.alarm.modules.entity.AlarmEventSend;
|
|
|
+import cn.com.ctop.alarm.modules.entity.AlarmRuleRecord;
|
|
|
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.enums.ConditEnum;
|
|
|
import cn.com.ctop.alarm.modules.mapper.AlarmEventSendMapper;
|
|
|
import cn.com.ctop.alarm.modules.mapper.RuleAccountTemplateMapper;
|
|
|
import cn.com.ctop.alarm.modules.mapper.RuleAccountThresholdMapper;
|
|
@@ -15,6 +17,7 @@ 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.IAlarmRuleRecordService;
|
|
|
import cn.com.ctop.alarm.modules.service.IRuleAccountTemplateService;
|
|
|
import cn.com.ctop.alarm.modules.service.IRuleGroupService;
|
|
|
import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
@@ -95,6 +98,8 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
|
@Autowired
|
|
|
private IByteDanceCreativeService byteDanceCreativeService;
|
|
|
@Autowired
|
|
|
+ private IAlarmRuleRecordService alarmRuleRecordService;
|
|
|
+ @Autowired
|
|
|
private ICtopOauthTokenService tokenService;
|
|
|
|
|
|
private JSONObject userObj = null;
|
|
@@ -221,14 +226,14 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
|
for (Map.Entry<String, Object> entry : batchNo.entrySet()) {
|
|
|
JSONObject thresholdJn = (JSONObject) entry.getValue();
|
|
|
if (!Check.isNull(thresholdJn)) {
|
|
|
- CombinationRule(ruleBaseList, thresholdJn, indicators, matchData, complianceList, type);
|
|
|
+ CombinationRule(ruleGroup, thresholdJn, indicators, matchData, complianceList, type);
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
boolean isGroup = "group".equals(ruleGroup.getRuleType());
|
|
|
//匹配组合规则
|
|
|
if (isGroup) {
|
|
|
- CombinationRule(ruleBaseList, thresholdObj, indicators, matchData, complianceList, type);
|
|
|
+ CombinationRule(ruleGroup, thresholdObj, indicators, matchData, complianceList, type);
|
|
|
//匹配单规则
|
|
|
} else {
|
|
|
RuleBase ruleBase = ruleBaseList.get(0);
|
|
@@ -250,6 +255,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
|
JSONObject obj = dimensionData.getJSONObject(i);
|
|
|
String value = obj.getString(ruleBase.getIndicatorCode());
|
|
|
if (MatchLogic.matchCondition(indicator, ruleBase.getRuleCondition(), threshold, value, obj, ruleBase.getIndicatorCode())) {
|
|
|
+ alarmRuleRecord(obj, ruleGroup, ruleBase, indicator, type, threshold);
|
|
|
complianceList.add(obj);
|
|
|
}
|
|
|
}
|
|
@@ -263,6 +269,48 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 添加预警规则记录
|
|
|
+ *
|
|
|
+ * @param
|
|
|
+ * @return void
|
|
|
+ * @throws
|
|
|
+ * @author ZHAOXA
|
|
|
+ */
|
|
|
+ private void alarmRuleRecord(JSONObject obj, RuleGroup ruleGroup, RuleBase ruleBase, JSONObject indicator, Integer mediaType, String threshold) {
|
|
|
+ try {
|
|
|
+ Long planId = obj.getLong("planId");
|
|
|
+ Long unidId = null;
|
|
|
+ Long creativeId = null;
|
|
|
+ String mediaTypeName = "快手";
|
|
|
+ if ((NoEn.NO1.valueInt() == mediaType || NoEn.NO3.valueInt() == mediaType)) {
|
|
|
+ mediaTypeName = "头条";
|
|
|
+ creativeId = obj.getLong("creativeId");
|
|
|
+ } else {
|
|
|
+ unidId = obj.getLong("unitId");
|
|
|
+ }
|
|
|
+ AlarmRuleRecord alarmRuleRecord = new AlarmRuleRecord();
|
|
|
+ alarmRuleRecord.setBaseId(ruleBase.getId());
|
|
|
+ alarmRuleRecord.setAccountId(obj.getLong("accountId"));
|
|
|
+ alarmRuleRecord.setPlanId(planId);
|
|
|
+ alarmRuleRecord.setUnitId(unidId);
|
|
|
+ alarmRuleRecord.setCreativeId(creativeId);
|
|
|
+ alarmRuleRecord.setGroupId(ruleGroup.getId());
|
|
|
+ alarmRuleRecord.setIndicatorCode(indicator.getString("code"));
|
|
|
+ alarmRuleRecord.setIndicatorName(indicator.getString("name"));
|
|
|
+ alarmRuleRecord.setGroupName(ruleGroup.getGroupName());
|
|
|
+ alarmRuleRecord.setThreshold(threshold);
|
|
|
+ alarmRuleRecord.setRuleCondition(ConditEnum.getEnumByCode(ruleBase.getRuleCondition()).getName());
|
|
|
+ alarmRuleRecord.setDataValue(obj.getString(ruleBase.getIndicatorCode()));
|
|
|
+ alarmRuleRecord.setValueTime(obj.getDate("createTime"));
|
|
|
+ alarmRuleRecord.setOperate("PAUSE".equals(ruleGroup.getOperate()) ? "关停" : "仅发送");
|
|
|
+ alarmRuleRecord.setMediaType(mediaTypeName);
|
|
|
+ alarmRuleRecordService.save(alarmRuleRecord);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("insert ctop_alarm_rule_record error ", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 组合规则匹配逻辑
|
|
|
*
|
|
|
* @param ruleGroup 规则组对象
|
|
@@ -276,7 +324,8 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
|
* @throws
|
|
|
* @author ZHAOXA
|
|
|
*/
|
|
|
- private void CombinationRule(List<RuleBase> ruleBaseList, JSONObject thresholdObj, JSONObject indicators, JSONObject matchData, JSONArray complianceList, Integer type) {
|
|
|
+ private void CombinationRule(RuleGroup ruleGroup, JSONObject thresholdObj, JSONObject indicators, JSONObject matchData, JSONArray complianceList, Integer type) {
|
|
|
+ List<RuleBase> ruleBaseList = ruleGroup.getRuleBaseList();
|
|
|
//符合规则的数据集
|
|
|
JSONArray groupDatas = new JSONArray();
|
|
|
JSONArray targetDatas = new JSONArray();
|
|
@@ -331,6 +380,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
|
JSONObject accountEntity = dimensionData.getJSONObject(0);
|
|
|
if (MatchLogic.matchCondition(indicator, ruleBase.getRuleCondition(), threshold, accountEntity.getString(ruleBase.getIndicatorCode()), accountEntity, ruleBase.getIndicatorCode())) {
|
|
|
if (Check.isNull(accountDatas)) {
|
|
|
+ alarmRuleRecord(accountEntity, ruleGroup, ruleBase, indicator, type, threshold);
|
|
|
accountDatas.add(accountEntity);
|
|
|
}
|
|
|
} else {
|
|
@@ -352,7 +402,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
|
break;
|
|
|
}
|
|
|
} else if (PLAN.equals(ruleBase.getRuleDimension())) {
|
|
|
- planDatas = getOKData(planDatas, dimensionData, ruleBase, indicator, threshold);
|
|
|
+ planDatas = getOKData(planDatas, dimensionData, ruleBase, indicator, threshold, ruleGroup, type);
|
|
|
if (Check.isNull(planDatas)) {
|
|
|
if (!Check.isNull(accountDatas)) {
|
|
|
accountDatas = null;
|
|
@@ -372,7 +422,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
|
break;
|
|
|
}
|
|
|
} else if (CREATIVE.equals(ruleBase.getRuleDimension())) {
|
|
|
- creativeDatas = getOKData(creativeDatas, dimensionData, ruleBase, indicator, threshold);
|
|
|
+ creativeDatas = getOKData(creativeDatas, dimensionData, ruleBase, indicator, threshold, ruleGroup, type);
|
|
|
if (Check.isNull(creativeDatas)) {
|
|
|
if (!Check.isNull(accountDatas)) {
|
|
|
accountDatas = null;
|
|
@@ -392,7 +442,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
|
break;
|
|
|
}
|
|
|
} else if ("target".equals(ruleBase.getRuleDimension())) {
|
|
|
- targetDatas = getOKData(targetDatas, dimensionData, ruleBase, indicator, threshold);
|
|
|
+ targetDatas = getOKData(targetDatas, dimensionData, ruleBase, indicator, threshold, ruleGroup, type);
|
|
|
if (Check.isNull(targetDatas)) {
|
|
|
if (!Check.isNull(accountDatas)) {
|
|
|
accountDatas = null;
|
|
@@ -412,7 +462,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
|
break;
|
|
|
}
|
|
|
} else if (UNIT.equals(ruleBase.getRuleDimension())) {
|
|
|
- groupDatas = getOKData(groupDatas, dimensionData, ruleBase, indicator, threshold);
|
|
|
+ groupDatas = getOKData(groupDatas, dimensionData, ruleBase, indicator, threshold, ruleGroup, type);
|
|
|
if (Check.isNull(groupDatas)) {
|
|
|
if (!Check.isNull(accountDatas)) {
|
|
|
accountDatas = null;
|
|
@@ -455,23 +505,25 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
|
* @throws
|
|
|
* @author ZHAOXA
|
|
|
*/
|
|
|
- private JSONArray getOKData(JSONArray ruleDatas, JSONArray dimensionData, RuleBase ruleBase, JSONObject indicator, String threshold) {
|
|
|
+ private JSONArray getOKData(JSONArray ruleDatas, JSONArray dimensionData, RuleBase ruleBase, JSONObject indicator, String threshold, RuleGroup ruleGroup, Integer type) {
|
|
|
if (!Check.isNull(ruleDatas)) {
|
|
|
JSONArray okData = new JSONArray();
|
|
|
for (int i = 0; i < ruleDatas.size(); i++) {
|
|
|
- JSONObject targetEntity = ruleDatas.getJSONObject(i);
|
|
|
- String value = targetEntity.getString(ruleBase.getIndicatorCode());
|
|
|
- if (MatchLogic.matchCondition(indicator, ruleBase.getRuleCondition(), threshold, value, targetEntity, ruleBase.getIndicatorCode())) {
|
|
|
- okData.add(targetEntity);
|
|
|
+ JSONObject obj = ruleDatas.getJSONObject(i);
|
|
|
+ String value = obj.getString(ruleBase.getIndicatorCode());
|
|
|
+ if (MatchLogic.matchCondition(indicator, ruleBase.getRuleCondition(), threshold, value, obj, ruleBase.getIndicatorCode())) {
|
|
|
+ alarmRuleRecord(obj, ruleGroup, ruleBase, indicator, type, threshold);
|
|
|
+ okData.add(obj);
|
|
|
}
|
|
|
}
|
|
|
return okData;
|
|
|
}
|
|
|
for (int i = 0; i < dimensionData.size(); i++) {
|
|
|
- JSONObject targetEntity = dimensionData.getJSONObject(i);
|
|
|
- String value = targetEntity.getString(ruleBase.getIndicatorCode());
|
|
|
- if (MatchLogic.matchCondition(indicator, ruleBase.getRuleCondition(), threshold, value, targetEntity, ruleBase.getIndicatorCode())) {
|
|
|
- ruleDatas.add(targetEntity);
|
|
|
+ JSONObject obj = dimensionData.getJSONObject(i);
|
|
|
+ String value = obj.getString(ruleBase.getIndicatorCode());
|
|
|
+ if (MatchLogic.matchCondition(indicator, ruleBase.getRuleCondition(), threshold, value, obj, ruleBase.getIndicatorCode())) {
|
|
|
+ alarmRuleRecord(obj, ruleGroup, ruleBase, indicator, type, threshold);
|
|
|
+ ruleDatas.add(obj);
|
|
|
}
|
|
|
}
|
|
|
return ruleDatas;
|