|
@@ -38,6 +38,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.StringJoiner;
|
|
import java.util.UUID;
|
|
import java.util.UUID;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -107,7 +108,8 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
for (RuleAccountTemplate templates : ruleAccountTemplates) {
|
|
for (RuleAccountTemplate templates : ruleAccountTemplates) {
|
|
- matchAlarmRules(ruleGroupMap, indicators, templates);
|
|
|
|
|
|
+ if (templates.getAccountId() == 1681223758914574l)
|
|
|
|
+ matchAlarmRules(ruleGroupMap, indicators, templates);
|
|
}
|
|
}
|
|
Long endTime = System.currentTimeMillis();
|
|
Long endTime = System.currentTimeMillis();
|
|
log.info("------end------共耗时: {} ms", endTime - startTime);
|
|
log.info("------end------共耗时: {} ms", endTime - startTime);
|
|
@@ -152,7 +154,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
accountName = userAllocations.getAuthName();
|
|
accountName = userAllocations.getAuthName();
|
|
}
|
|
}
|
|
try {
|
|
try {
|
|
- if (!Check.isNull(notCopyGroups)) {
|
|
|
|
|
|
+ if (!Check.isNull(notCopyGroups) && !Check.isNull(notCopythreshold)) {
|
|
checkRuleGroups(notCopyGroups, notCopythreshold, indicators, matchData, type, false, accountName);
|
|
checkRuleGroups(notCopyGroups, notCopythreshold, indicators, matchData, type, false, accountName);
|
|
}
|
|
}
|
|
if (isCopy && !Check.isNull(isCopythreshold)) {
|
|
if (isCopy && !Check.isNull(isCopythreshold)) {
|
|
@@ -179,6 +181,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
*/
|
|
*/
|
|
private void checkRuleGroups(List<RuleGroup> ruleGroups, JSONObject thresholdObj, JSONObject indicators, JSONObject matchData, Integer type, boolean isCopy, String accountName) {
|
|
private void checkRuleGroups(List<RuleGroup> ruleGroups, JSONObject thresholdObj, JSONObject indicators, JSONObject matchData, Integer type, boolean isCopy, String accountName) {
|
|
for (RuleGroup ruleGroup : ruleGroups) {
|
|
for (RuleGroup ruleGroup : ruleGroups) {
|
|
|
|
+ JSONArray complianceList = new JSONArray();
|
|
List<RuleBase> ruleBaseList = ruleGroup.getRuleBaseList();
|
|
List<RuleBase> ruleBaseList = ruleGroup.getRuleBaseList();
|
|
if (Check.isNull(ruleBaseList)) {
|
|
if (Check.isNull(ruleBaseList)) {
|
|
continue;
|
|
continue;
|
|
@@ -187,14 +190,16 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
if (isCopy) {
|
|
if (isCopy) {
|
|
JSONObject batchNo = thresholdObj.getJSONObject(ruleGroup.getId().toString());
|
|
JSONObject batchNo = thresholdObj.getJSONObject(ruleGroup.getId().toString());
|
|
for (Map.Entry<String, Object> entry : batchNo.entrySet()) {
|
|
for (Map.Entry<String, Object> entry : batchNo.entrySet()) {
|
|
- JSONObject thresholdMap = (JSONObject) entry.getValue();
|
|
|
|
- CombinationRule(ruleGroup, ruleBaseList, thresholdMap, indicators, matchData, type, accountName);
|
|
|
|
|
|
+ JSONObject thresholdJn = (JSONObject) entry.getValue();
|
|
|
|
+ if (!Check.isNull(thresholdJn)) {
|
|
|
|
+ CombinationRule(ruleGroup, ruleBaseList, thresholdJn, indicators, matchData, type, accountName, complianceList);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
boolean isGroup = "group".equals(ruleGroup.getRuleType());
|
|
boolean isGroup = "group".equals(ruleGroup.getRuleType());
|
|
//匹配组合规则
|
|
//匹配组合规则
|
|
if (isGroup) {
|
|
if (isGroup) {
|
|
- CombinationRule(ruleGroup, ruleBaseList, thresholdObj, indicators, matchData, type, accountName);
|
|
|
|
|
|
+ CombinationRule(ruleGroup, ruleBaseList, thresholdObj, indicators, matchData, type, accountName, complianceList);
|
|
//匹配单规则
|
|
//匹配单规则
|
|
} else {
|
|
} else {
|
|
RuleBase ruleBase = ruleBaseList.get(0);
|
|
RuleBase ruleBase = ruleBaseList.get(0);
|
|
@@ -203,8 +208,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
//指标阈值
|
|
//指标阈值
|
|
String threshold = thresholdObj.getString(ruleBase.getId().toString());
|
|
String threshold = thresholdObj.getString(ruleBase.getId().toString());
|
|
//阈值为空时,或者阈值为“unlimited”(不限),不执行该规则
|
|
//阈值为空时,或者阈值为“unlimited”(不限),不执行该规则
|
|
- if (Check.isNull(threshold) || "unlimited".equals(threshold)) {
|
|
|
|
- log.warn("阈值为空/不限,该规则({})不执行", ruleBase.getId());
|
|
|
|
|
|
+ if (Check.isNull(threshold) || threshold.contains("unlimited")) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
//维度数据
|
|
//维度数据
|
|
@@ -214,12 +218,15 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
JSONObject obj = dimensionData.getJSONObject(i);
|
|
JSONObject obj = dimensionData.getJSONObject(i);
|
|
String value = obj.getString(ruleBase.getIndicatorCode());
|
|
String value = obj.getString(ruleBase.getIndicatorCode());
|
|
if (MatchLogic.matchCondition(indicator.getString("dataType"), ruleBase.getRuleCondition(), threshold, value, obj)) {
|
|
if (MatchLogic.matchCondition(indicator.getString("dataType"), ruleBase.getRuleCondition(), threshold, value, obj)) {
|
|
- sendMsg(ruleGroup, obj, type, accountName);
|
|
|
|
|
|
+ complianceList.add(obj);
|
|
|
|
+// sendMsg(ruleGroup, obj, type, accountName);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -237,7 +244,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
* @throws
|
|
* @throws
|
|
* @author ZHAOXA
|
|
* @author ZHAOXA
|
|
*/
|
|
*/
|
|
- private void CombinationRule(RuleGroup ruleGroup, List<RuleBase> ruleBaseList, JSONObject thresholdObj, JSONObject indicators, JSONObject matchData, Integer type, String accountName) {
|
|
|
|
|
|
+ private void CombinationRule(RuleGroup ruleGroup, List<RuleBase> ruleBaseList, JSONObject thresholdObj, JSONObject indicators, JSONObject matchData, Integer type, String accountName, JSONArray complianceList) {
|
|
//符合规则的数据集
|
|
//符合规则的数据集
|
|
JSONArray targetDatas = new JSONArray();
|
|
JSONArray targetDatas = new JSONArray();
|
|
JSONArray planDatas = new JSONArray();
|
|
JSONArray planDatas = new JSONArray();
|
|
@@ -255,11 +262,11 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
JSONArray dimensionData = matchData.getJSONArray(ruleBase.getRuleDimension());
|
|
JSONArray dimensionData = matchData.getJSONArray(ruleBase.getRuleDimension());
|
|
|
|
+ if (Check.isNull(dimensionData)) {
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
//账户维度数据
|
|
//账户维度数据
|
|
if ("account".equals(ruleBase.getRuleDimension())) {
|
|
if ("account".equals(ruleBase.getRuleDimension())) {
|
|
- if (Check.isNull(dimensionData)) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
JSONObject accountEntity = dimensionData.getJSONObject(0);
|
|
JSONObject accountEntity = dimensionData.getJSONObject(0);
|
|
if (MatchLogic.matchCondition(dataType, ruleBase.getRuleCondition(), threshold, accountEntity.getString(ruleBase.getIndicatorCode()), accountEntity)) {
|
|
if (MatchLogic.matchCondition(dataType, ruleBase.getRuleCondition(), threshold, accountEntity.getString(ruleBase.getIndicatorCode()), accountEntity)) {
|
|
accountDatas.add(accountEntity);
|
|
accountDatas.add(accountEntity);
|
|
@@ -291,10 +298,11 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
//获取达标可发送的数据
|
|
//获取达标可发送的数据
|
|
JSONArray sendData = MatchLogic.getSendData(accountDatas, planDatas, creativeDatas, targetDatas);
|
|
JSONArray sendData = MatchLogic.getSendData(accountDatas, planDatas, creativeDatas, targetDatas);
|
|
if (!Check.isNull(sendData)) {
|
|
if (!Check.isNull(sendData)) {
|
|
- //执行发送
|
|
|
|
- for (int i = 0; i < sendData.size(); i++) {
|
|
|
|
- sendMsg(ruleGroup, sendData.getJSONObject(i), type, accountName);
|
|
|
|
- }
|
|
|
|
|
|
+ complianceList.addAll(sendData);
|
|
|
|
+// //执行发送
|
|
|
|
+//// for (int i = 0; i < sendData.size(); i++) {
|
|
|
|
+//// sendMsg(ruleGroup, , type, accountName);
|
|
|
|
+//// }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -309,7 +317,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
* @author ZHAOXA
|
|
* @author ZHAOXA
|
|
*/
|
|
*/
|
|
private JSONArray getOKData(JSONArray ruleDatas, JSONArray dimensionData, RuleBase ruleBase, String type, String threshold) {
|
|
private JSONArray getOKData(JSONArray ruleDatas, JSONArray dimensionData, RuleBase ruleBase, String type, String threshold) {
|
|
- if (ruleDatas.size() > 0) {
|
|
|
|
|
|
+ if (!Check.isNull(ruleDatas)) {
|
|
JSONArray okData = new JSONArray();
|
|
JSONArray okData = new JSONArray();
|
|
for (int i = 0; i < ruleDatas.size(); i++) {
|
|
for (int i = 0; i < ruleDatas.size(); i++) {
|
|
JSONObject targetEntity = dimensionData.getJSONObject(i);
|
|
JSONObject targetEntity = dimensionData.getJSONObject(i);
|
|
@@ -330,6 +338,83 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
return ruleDatas;
|
|
return ruleDatas;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void sendMag2(JSONArray complianceList, RuleGroup ruleGroup, String accountName) {
|
|
|
|
+ Long accountId = complianceList.getJSONObject(0).getLong("accountId");
|
|
|
|
+ if (Check.isNull(accountId)) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ JSONObject user = getUserByAccountId(accountId);
|
|
|
|
+ StringJoiner creativeJoiner = new StringJoiner(",");
|
|
|
|
+ StringJoiner planJoiner = new StringJoiner(",");
|
|
|
|
+ StringJoiner isNullCreativeJoiner = new StringJoiner(",");
|
|
|
|
+ StringJoiner isNullPlanJoiner = new StringJoiner(",");
|
|
|
|
+ for (int i = 0; i < complianceList.size(); i++) {
|
|
|
|
+ JSONObject obj = complianceList.getJSONObject(i);
|
|
|
|
+ boolean isNull = obj.getBoolean("isNull");
|
|
|
|
+ if (isNull) {
|
|
|
|
+ if (!Check.isNull(obj.getString("creativeId"))) {
|
|
|
|
+ //字节小于1900时
|
|
|
|
+ if (isNullCreativeJoiner.toString().getBytes().length <= 1900) {
|
|
|
|
+ isNullCreativeJoiner.add(obj.getString("creativeId"));
|
|
|
|
+ } else {
|
|
|
|
+ String message = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, "creative", isNullCreativeJoiner.toString(), false);
|
|
|
|
+ sendMsg(message, ruleGroup, user);
|
|
|
|
+ isNullCreativeJoiner = new StringJoiner(",");
|
|
|
|
+ }
|
|
|
|
+ } else if (!Check.isNull(obj.getLong("planId"))) {
|
|
|
|
+ if (isNullPlanJoiner.toString().getBytes().length <= 1900) {
|
|
|
|
+ isNullPlanJoiner.add(obj.getString("planId"));
|
|
|
|
+ } else {
|
|
|
|
+ String msg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, "plan", isNullPlanJoiner.toString(), false);
|
|
|
|
+ sendMsg(msg, ruleGroup, user);
|
|
|
|
+ isNullPlanJoiner = new StringJoiner(",");
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ String msg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, null, null, false);
|
|
|
|
+ sendMsg(msg, ruleGroup, user);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if (!Check.isNull(obj.getString("creativeId"))) {
|
|
|
|
+ //字节小于1900时
|
|
|
|
+ if (creativeJoiner.toString().getBytes().length <= 1900) {
|
|
|
|
+ creativeJoiner.add(obj.getString("creativeId"));
|
|
|
|
+ } else {
|
|
|
|
+ String message = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, "creative", creativeJoiner.toString(), false);
|
|
|
|
+ sendMsg(message, ruleGroup, user);
|
|
|
|
+ creativeJoiner = new StringJoiner(",");
|
|
|
|
+ }
|
|
|
|
+ } else if (!Check.isNull(obj.getLong("planId"))) {
|
|
|
|
+ if (planJoiner.toString().getBytes().length <= 1900) {
|
|
|
|
+ planJoiner.add(obj.getString("planId"));
|
|
|
|
+ } else {
|
|
|
|
+ String msg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, "plan", planJoiner.toString(), false);
|
|
|
|
+ sendMsg(msg, ruleGroup, user);
|
|
|
|
+ planJoiner = new StringJoiner(",");
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ String msg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, accountName, null, null, false);
|
|
|
|
+ sendMsg(msg, ruleGroup, user);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ String creativeMsg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, "creative", creativeJoiner.toString(), accountName, false);
|
|
|
|
+ if (!Check.isNull(creativeMsg)) {
|
|
|
|
+ sendMsg(creativeMsg, ruleGroup, user);
|
|
|
|
+ }
|
|
|
|
+ String planMsg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, "creative", planJoiner.toString(), accountName, false);
|
|
|
|
+ if (!Check.isNull(planMsg)) {
|
|
|
|
+ sendMsg(planMsg, ruleGroup, user);
|
|
|
|
+ }
|
|
|
|
+ String isNullCreativeMsg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, "creative", isNullCreativeJoiner.toString(), accountName, false);
|
|
|
|
+ if (!Check.isNull(isNullCreativeMsg)) {
|
|
|
|
+ sendMsg(isNullCreativeMsg, ruleGroup, user);
|
|
|
|
+ }
|
|
|
|
+ String isNullPlanMsg = MatchLogic.getMessage(ruleGroup.getGroupName(), accountId, "creative", isNullPlanJoiner.toString(), accountName, false);
|
|
|
|
+ if (!Check.isNull(isNullPlanMsg)) {
|
|
|
|
+ sendMsg(isNullPlanMsg, ruleGroup, user);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 发送消息
|
|
* 发送消息
|
|
*
|
|
*
|
|
@@ -341,11 +426,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
* @throws
|
|
* @throws
|
|
* @author ZHAOXA
|
|
* @author ZHAOXA
|
|
*/
|
|
*/
|
|
- private void sendMsg(RuleGroup ruleGroup, JSONObject obj, Integer type, String accountName) {
|
|
|
|
- Long creativeId = obj.getLong("creativeId");
|
|
|
|
- Long planId = obj.getLong("planId");
|
|
|
|
- Long accountId = obj.getLong("accountId");
|
|
|
|
- JSONObject user = getUserByAccountId(accountId);
|
|
|
|
|
|
+ private void sendMsg(String msg, RuleGroup ruleGroup, JSONObject user) {
|
|
//TODO 关停操作
|
|
//TODO 关停操作
|
|
boolean isPause = false;
|
|
boolean isPause = false;
|
|
/* "PAUSE".equals(ruleGroup.getOperate());
|
|
/* "PAUSE".equals(ruleGroup.getOperate());
|
|
@@ -355,7 +436,12 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
}
|
|
}
|
|
type 1:头条2:快手
|
|
type 1:头条2:快手
|
|
}*/
|
|
}*/
|
|
- String msg = MatchLogic.getMsg(ruleGroup, user, obj, isPause, accountName);
|
|
|
|
|
|
+// String msg = MatchLogic.getMsg(ruleGroup, user, obj, isPause, accountName);
|
|
|
|
+ if (isPause) {
|
|
|
|
+ msg += "现已被关停,请您及时查看并调整!";
|
|
|
|
+ } else {
|
|
|
|
+ msg += "请您及时查看并调整!";
|
|
|
|
+ }
|
|
String sendType = ruleGroup.getSendType();
|
|
String sendType = ruleGroup.getSendType();
|
|
if ("SMS".equals(sendType)) {
|
|
if ("SMS".equals(sendType)) {
|
|
|
|
|
|
@@ -370,12 +456,20 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
sendMessageService.sendMessage("1b3deb8258e84df994f1371a51cfc14a", msg);
|
|
sendMessageService.sendMessage("1b3deb8258e84df994f1371a51cfc14a", msg);
|
|
//113dee46c7df464da78c07a985e92cd1 于蒙
|
|
//113dee46c7df464da78c07a985e92cd1 于蒙
|
|
}
|
|
}
|
|
- log.debug("账户{}的{}预警已发送", accountId, ruleGroup.getGroupName());
|
|
|
|
if (!Check.isNull(msg)) {
|
|
if (!Check.isNull(msg)) {
|
|
AlarmEventSend send = new AlarmEventSend();
|
|
AlarmEventSend send = new AlarmEventSend();
|
|
send.setAlarmDetail(msg);
|
|
send.setAlarmDetail(msg);
|
|
send.setAlarmStatus(NoEn.NO1.valueStr());
|
|
send.setAlarmStatus(NoEn.NO1.valueStr());
|
|
send.setEventRuleId(ruleGroup.getId());
|
|
send.setEventRuleId(ruleGroup.getId());
|
|
|
|
+ if (msg.contains("预警账户")) {
|
|
|
|
+ send.setMetricValueCode("account");
|
|
|
|
+ if (msg.contains("预警计划")) {
|
|
|
|
+ send.setMetricValueCode("plan");
|
|
|
|
+ if (msg.contains("预警创意")) {
|
|
|
|
+ send.setMetricValueCode("creative");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
send.setAlarmCondition(ruleGroup.getGroupName());
|
|
send.setAlarmCondition(ruleGroup.getGroupName());
|
|
send.setUserId(user.getString("id"));
|
|
send.setUserId(user.getString("id"));
|
|
alarmEventSendMapper.insert(send);
|
|
alarmEventSendMapper.insert(send);
|