|
@@ -37,6 +37,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -195,17 +196,20 @@ 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(ruleGroup, ruleBaseList, thresholdJn, indicators, matchData, complianceList);
|
|
|
+ CombinationRule(ruleBaseList, thresholdJn, indicators, matchData, complianceList);
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
boolean isGroup = "group".equals(ruleGroup.getRuleType());
|
|
|
//匹配组合规则
|
|
|
if (isGroup) {
|
|
|
- CombinationRule(ruleGroup, ruleBaseList, thresholdObj, indicators, matchData, complianceList);
|
|
|
+ CombinationRule(ruleBaseList, thresholdObj, indicators, matchData, complianceList);
|
|
|
//匹配单规则
|
|
|
} else {
|
|
|
RuleBase ruleBase = ruleBaseList.get(0);
|
|
|
+ if (Check.isNull(ruleBase)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
//指标对象
|
|
|
JSONObject indicator = indicators.getJSONObject(ruleBase.getIndicatorCode());
|
|
|
//指标阈值
|
|
@@ -220,9 +224,8 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
|
for (int i = 0; i < dimensionData.size(); i++) {
|
|
|
JSONObject obj = dimensionData.getJSONObject(i);
|
|
|
String value = obj.getString(ruleBase.getIndicatorCode());
|
|
|
- if (MatchLogic.matchCondition(indicator.getString("dataType"), ruleBase.getRuleCondition(), threshold, value, obj)) {
|
|
|
+ if (MatchLogic.matchCondition(indicator, ruleBase.getRuleCondition(), threshold, value, obj)) {
|
|
|
complianceList.add(obj);
|
|
|
-// sendMsg(ruleGroup, obj, type, accountName);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -248,7 +251,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
|
* @throws
|
|
|
* @author ZHAOXA
|
|
|
*/
|
|
|
- private void CombinationRule(RuleGroup ruleGroup, List<RuleBase> ruleBaseList, JSONObject thresholdObj, JSONObject indicators, JSONObject matchData, JSONArray complianceList) {
|
|
|
+ private void CombinationRule(List<RuleBase> ruleBaseList, JSONObject thresholdObj, JSONObject indicators, JSONObject matchData, JSONArray complianceList) {
|
|
|
//符合规则的数据集
|
|
|
JSONArray targetDatas = new JSONArray();
|
|
|
JSONArray planDatas = new JSONArray();
|
|
@@ -257,47 +260,114 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
|
for (RuleBase ruleBase : ruleBaseList) {
|
|
|
//指标对象
|
|
|
JSONObject indicator = indicators.getJSONObject(ruleBase.getIndicatorCode());
|
|
|
- //阈值类型
|
|
|
- String dataType = indicator.getString("dataType");
|
|
|
//指标阈值
|
|
|
String threshold = thresholdObj.getString(ruleBase.getId().toString());
|
|
|
//阈值为空时,或者阈值为“unlimited”(不限),不执行该规则
|
|
|
if (Check.isNull(threshold) || "unlimited".equals(threshold)) {
|
|
|
- continue;
|
|
|
+ if (!Check.isNull(accountDatas)) {
|
|
|
+ accountDatas = null;
|
|
|
+ }
|
|
|
+ if (!Check.isNull(planDatas)) {
|
|
|
+ planDatas = null;
|
|
|
+ }
|
|
|
+ if (!Check.isNull(creativeDatas)) {
|
|
|
+ creativeDatas = null;
|
|
|
+ }
|
|
|
+ if (!Check.isNull(targetDatas)) {
|
|
|
+ targetDatas = null;
|
|
|
+ }
|
|
|
+ break;
|
|
|
}
|
|
|
JSONArray dimensionData = matchData.getJSONArray(ruleBase.getRuleDimension());
|
|
|
if (Check.isNull(dimensionData)) {
|
|
|
+ if (!Check.isNull(accountDatas)) {
|
|
|
+ accountDatas = null;
|
|
|
+ }
|
|
|
+ if (!Check.isNull(planDatas)) {
|
|
|
+ planDatas = null;
|
|
|
+ }
|
|
|
+ if (!Check.isNull(creativeDatas)) {
|
|
|
+ creativeDatas = null;
|
|
|
+ }
|
|
|
+ if (!Check.isNull(targetDatas)) {
|
|
|
+ targetDatas = null;
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
//账户维度数据
|
|
|
if (ACCOUNT.equals(ruleBase.getRuleDimension())) {
|
|
|
JSONObject accountEntity = dimensionData.getJSONObject(0);
|
|
|
- if (MatchLogic.matchCondition(dataType, ruleBase.getRuleCondition(), threshold, accountEntity.getString(ruleBase.getIndicatorCode()), accountEntity)) {
|
|
|
- accountDatas.add(accountEntity);
|
|
|
+ if (MatchLogic.matchCondition(indicator, ruleBase.getRuleCondition(), threshold, accountEntity.getString(ruleBase.getIndicatorCode()), accountEntity)) {
|
|
|
+ if (Check.isNull(accountDatas)) {
|
|
|
+ accountDatas.add(accountEntity);
|
|
|
+ }
|
|
|
} else {
|
|
|
- log.warn("匹配规则组({}),账户维度数据不符合直接跳过", ruleGroup.getId());
|
|
|
- break;
|
|
|
- }
|
|
|
- if (Check.isNull(accountDatas)) {
|
|
|
+ if (!Check.isNull(accountDatas)) {
|
|
|
+ accountDatas = null;
|
|
|
+ }
|
|
|
+ if (!Check.isNull(planDatas)) {
|
|
|
+ planDatas = null;
|
|
|
+ }
|
|
|
+ if (!Check.isNull(creativeDatas)) {
|
|
|
+ creativeDatas = null;
|
|
|
+ }
|
|
|
+ if (!Check.isNull(targetDatas)) {
|
|
|
+ targetDatas = null;
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
} else if (PLAN.equals(ruleBase.getRuleDimension())) {
|
|
|
- planDatas = getOKData(planDatas, dimensionData, ruleBase, dataType, threshold);
|
|
|
+ planDatas = getOKData(planDatas, dimensionData, ruleBase, indicator, threshold);
|
|
|
if (Check.isNull(planDatas)) {
|
|
|
+ if (!Check.isNull(accountDatas)) {
|
|
|
+ accountDatas = null;
|
|
|
+ }
|
|
|
+ if (!Check.isNull(planDatas)) {
|
|
|
+ planDatas = null;
|
|
|
+ }
|
|
|
+ if (!Check.isNull(creativeDatas)) {
|
|
|
+ creativeDatas = null;
|
|
|
+ }
|
|
|
+ if (!Check.isNull(targetDatas)) {
|
|
|
+ targetDatas = null;
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
} else if (CREATIVE.equals(ruleBase.getRuleDimension())) {
|
|
|
- creativeDatas = getOKData(creativeDatas, dimensionData, ruleBase, dataType, threshold);
|
|
|
+ creativeDatas = getOKData(creativeDatas, dimensionData, ruleBase, indicator, threshold);
|
|
|
if (Check.isNull(creativeDatas)) {
|
|
|
+ if (!Check.isNull(accountDatas)) {
|
|
|
+ accountDatas = null;
|
|
|
+ }
|
|
|
+ if (!Check.isNull(planDatas)) {
|
|
|
+ planDatas = null;
|
|
|
+ }
|
|
|
+ if (!Check.isNull(creativeDatas)) {
|
|
|
+ creativeDatas = null;
|
|
|
+ }
|
|
|
+ if (!Check.isNull(targetDatas)) {
|
|
|
+ targetDatas = null;
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
} else if ("target".equals(ruleBase.getRuleDimension())) {
|
|
|
- targetDatas = getOKData(targetDatas, dimensionData, ruleBase, dataType, threshold);
|
|
|
+ targetDatas = getOKData(targetDatas, dimensionData, ruleBase, indicator, threshold);
|
|
|
if (Check.isNull(targetDatas)) {
|
|
|
+ if (!Check.isNull(accountDatas)) {
|
|
|
+ accountDatas = null;
|
|
|
+ }
|
|
|
+ if (!Check.isNull(planDatas)) {
|
|
|
+ planDatas = null;
|
|
|
+ }
|
|
|
+ if (!Check.isNull(creativeDatas)) {
|
|
|
+ creativeDatas = null;
|
|
|
+ }
|
|
|
+ if (!Check.isNull(targetDatas)) {
|
|
|
+ targetDatas = null;
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
//获取达标可发送的数据
|
|
|
JSONArray sendData = MatchLogic.getSendData(accountDatas, planDatas, creativeDatas, targetDatas);
|
|
@@ -316,13 +386,13 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
|
* @throws
|
|
|
* @author ZHAOXA
|
|
|
*/
|
|
|
- private JSONArray getOKData(JSONArray ruleDatas, JSONArray dimensionData, RuleBase ruleBase, String type, String threshold) {
|
|
|
+ private JSONArray getOKData(JSONArray ruleDatas, JSONArray dimensionData, RuleBase ruleBase, JSONObject indicator, String threshold) {
|
|
|
if (!Check.isNull(ruleDatas)) {
|
|
|
JSONArray okData = new JSONArray();
|
|
|
for (int i = 0; i < ruleDatas.size(); i++) {
|
|
|
- JSONObject targetEntity = dimensionData.getJSONObject(i);
|
|
|
+ JSONObject targetEntity = ruleDatas.getJSONObject(i);
|
|
|
String value = targetEntity.getString(ruleBase.getIndicatorCode());
|
|
|
- if (MatchLogic.matchCondition(type, ruleBase.getRuleCondition(), threshold, value, targetEntity)) {
|
|
|
+ if (MatchLogic.matchCondition(indicator, ruleBase.getRuleCondition(), threshold, value, targetEntity)) {
|
|
|
okData.add(targetEntity);
|
|
|
}
|
|
|
}
|
|
@@ -331,7 +401,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
|
for (int i = 0; i < dimensionData.size(); i++) {
|
|
|
JSONObject targetEntity = dimensionData.getJSONObject(i);
|
|
|
String value = targetEntity.getString(ruleBase.getIndicatorCode());
|
|
|
- if (MatchLogic.matchCondition(type, ruleBase.getRuleCondition(), threshold, value, targetEntity)) {
|
|
|
+ if (MatchLogic.matchCondition(indicator, ruleBase.getRuleCondition(), threshold, value, targetEntity)) {
|
|
|
ruleDatas.add(targetEntity);
|
|
|
}
|
|
|
}
|
|
@@ -457,17 +527,14 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
|
} else if ("TEL".equals(sendType)) {
|
|
|
|
|
|
} else {
|
|
|
-// for (int i = 0; i < 10000000; i++) {
|
|
|
-// sendMessageService.sendMessage("1b3deb8258e84df994f1371a51cfc14a", msg + i);
|
|
|
-// Thread.sleep(2000);
|
|
|
-// }
|
|
|
+// sendMessageService.sendMessage("1b3deb8258e84df994f1371a51cfc14a", msg);
|
|
|
sendMessageService.sendMessage(user.getString("id"), msg);
|
|
|
Thread.sleep(200);
|
|
|
}
|
|
|
if (!Check.isNull(msg)) {
|
|
|
AlarmEventSend send = new AlarmEventSend();
|
|
|
send.setUserId(user.getString("id"));
|
|
|
- send.setAlarmDetail(msg.replace("<br/>", ""));
|
|
|
+ send.setAlarmDetail(msg.replace("<br/>", ","));
|
|
|
send.setAlarmStatus(NoEn.NO1.valueStr());
|
|
|
send.setGroupId(ruleGroup.getId());
|
|
|
send.setGroupName(ruleGroup.getGroupName());
|
|
@@ -478,6 +545,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
|
} else {
|
|
|
send.setRuleDimension(ACCOUNT);
|
|
|
}
|
|
|
+ send.setCreateTime(new Date());
|
|
|
alarmEventSendMapper.insert(send);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
@@ -722,6 +790,9 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
|
continue;
|
|
|
}
|
|
|
RuleAccountThreshold threshold = new RuleAccountThreshold();
|
|
|
+ if (ruleBase.getVariableType() == 0) {
|
|
|
+ threshold.setThreshold(ruleBase.getThreshold());
|
|
|
+ }
|
|
|
threshold.setAccountId(accountId);
|
|
|
if (isCopy == 1) {
|
|
|
threshold.setBatchNo(batchId);
|