|
@@ -145,6 +145,19 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 组合规则匹配逻辑
|
|
|
|
+ *
|
|
|
|
+ * @param ruleGroups 规则组集
|
|
|
|
+ * @param thresholdObj 阈值数据
|
|
|
|
+ * @param indicators 指标数据
|
|
|
|
+ * @param matchData 匹配数据
|
|
|
|
+ * @param type 媒体类型 1:头条2:快手
|
|
|
|
+ * @param isCopy 是否复制规则
|
|
|
|
+ * @return void
|
|
|
|
+ * @throws
|
|
|
|
+ * @author ZHAOXA
|
|
|
|
+ */
|
|
private void checkRuleGroups(List<RuleGroup> ruleGroups, JSONObject thresholdObj, JSONObject indicators, JSONObject matchData, Integer type, boolean isCopy) {
|
|
private void checkRuleGroups(List<RuleGroup> ruleGroups, JSONObject thresholdObj, JSONObject indicators, JSONObject matchData, Integer type, boolean isCopy) {
|
|
for (RuleGroup ruleGroup : ruleGroups) {
|
|
for (RuleGroup ruleGroup : ruleGroups) {
|
|
List<RuleBase> ruleBaseList = ruleGroup.getRuleBaseList();
|
|
List<RuleBase> ruleBaseList = ruleGroup.getRuleBaseList();
|
|
@@ -155,54 +168,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()) {
|
|
- 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));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ JSONObject thresholdMap = (JSONObject) entry.getValue();
|
|
|
|
+ CombinationRule(ruleGroup, ruleBaseList, thresholdMap, indicators, matchData, type);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- boolean isBase = "base".equals(ruleGroup.getRuleType());
|
|
|
|
- //匹配单规则
|
|
|
|
- if (isBase) {
|
|
|
|
|
|
+ boolean isGroup = "group".equals(ruleGroup.getRuleType());
|
|
|
|
+ //匹配组合规则
|
|
|
|
+ if (isGroup) {
|
|
|
|
+ CombinationRule(ruleGroup, ruleBaseList, thresholdObj, indicators, matchData, type);
|
|
|
|
+ //匹配单规则
|
|
|
|
+ } else {
|
|
RuleBase ruleBase = ruleBaseList.get(0);
|
|
RuleBase ruleBase = ruleBaseList.get(0);
|
|
//指标对象
|
|
//指标对象
|
|
JSONObject indicator = indicators.getJSONObject(ruleBase.getIndicatorCode());
|
|
JSONObject indicator = indicators.getJSONObject(ruleBase.getIndicatorCode());
|
|
@@ -220,53 +195,8 @@ 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)) {
|
|
if (MatchLogic.matchCondition(indicator.getString("dataType"), ruleBase.getRuleCondition(), threshold, value)) {
|
|
- sendMsg(ruleGroup, obj);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- //匹配组合规则
|
|
|
|
- } else {
|
|
|
|
- //符合规则的数据集
|
|
|
|
- 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 = thresholdObj.getString(ruleBase.getId().toString());
|
|
|
|
- //阈值为空时,或者阈值为“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;
|
|
|
|
|
|
+ sendMsg(ruleGroup, obj, type);
|
|
}
|
|
}
|
|
- } 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));
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -274,6 +204,64 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 组合规则匹配逻辑
|
|
|
|
+ *
|
|
|
|
+ * @param ruleGroup 规则组对象
|
|
|
|
+ * @param ruleBaseList 单条规则数据集
|
|
|
|
+ * @param thresholdObj 阈值数据
|
|
|
|
+ * @param indicators 指标数据
|
|
|
|
+ * @param matchData 匹配数据
|
|
|
|
+ * @param type 媒体类型 1:头条2:快手
|
|
|
|
+ * @return void
|
|
|
|
+ * @throws
|
|
|
|
+ * @author ZHAOXA
|
|
|
|
+ */
|
|
|
|
+ private void CombinationRule(RuleGroup ruleGroup, List<RuleBase> ruleBaseList, JSONObject thresholdObj, JSONObject indicators, JSONObject matchData, Integer type) {
|
|
|
|
+ //符合规则的数据集
|
|
|
|
+ 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 = thresholdObj.getString(ruleBase.getId().toString());
|
|
|
|
+ //阈值为空时,或者阈值为“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), type);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
/**
|
|
* @param ruleDatas 达标数据集
|
|
* @param ruleDatas 达标数据集
|
|
@@ -310,12 +298,14 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
/**
|
|
/**
|
|
* 发送消息
|
|
* 发送消息
|
|
*
|
|
*
|
|
- * @param
|
|
|
|
|
|
+ * @param ruleGroup 达标的规则组对象
|
|
|
|
+ * @param obj 达标数据对象
|
|
|
|
+ * @param type 1:头条2:快手
|
|
* @return void
|
|
* @return void
|
|
* @throws
|
|
* @throws
|
|
* @author ZHAOXA
|
|
* @author ZHAOXA
|
|
*/
|
|
*/
|
|
- private void sendMsg(RuleGroup ruleGroup, JSONObject obj) {
|
|
|
|
|
|
+ private void sendMsg(RuleGroup ruleGroup, JSONObject obj, Integer type) {
|
|
Long creativeId = obj.getLong("creativeId");
|
|
Long creativeId = obj.getLong("creativeId");
|
|
Long planId = obj.getLong("planId");
|
|
Long planId = obj.getLong("planId");
|
|
Long accountId = obj.getLong("accountId");
|
|
Long accountId = obj.getLong("accountId");
|
|
@@ -327,6 +317,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
if (shutDown(accountId, planId, creativeId, user.getString("id"))) {
|
|
if (shutDown(accountId, planId, creativeId, user.getString("id"))) {
|
|
isPause = true;
|
|
isPause = true;
|
|
}
|
|
}
|
|
|
|
+ type 1:头条2:快手
|
|
}*/
|
|
}*/
|
|
String msg = MatchLogic.getMsg(ruleGroup, user, accountId, planId, creativeId, isPause);
|
|
String msg = MatchLogic.getMsg(ruleGroup, user, accountId, planId, creativeId, isPause);
|
|
String sendType = ruleGroup.getSendType();
|
|
String sendType = ruleGroup.getSendType();
|
|
@@ -344,7 +335,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
/**
|
|
/**
|
|
* 根据accountId获取人员对象
|
|
* 根据accountId获取人员对象
|
|
*
|
|
*
|
|
- * @param
|
|
|
|
|
|
+ * @param accountId 账户ID
|
|
* @return com.alibaba.fastjson.JSONObject
|
|
* @return com.alibaba.fastjson.JSONObject
|
|
* @throws
|
|
* @throws
|
|
* @author ZHAOXA
|
|
* @author ZHAOXA
|