|
@@ -117,101 +117,157 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
log.warn("查询匹配数据失败");
|
|
log.warn("查询匹配数据失败");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
+ boolean isCopy = false;
|
|
Map<Long, Object> map = (Map<Long, Object>) ruleGroupMap.get(templates.getTemplateId());
|
|
Map<Long, Object> map = (Map<Long, Object>) ruleGroupMap.get(templates.getTemplateId());
|
|
//媒体类型 1:头条2:快手
|
|
//媒体类型 1:头条2:快手
|
|
Integer type = (Integer) map.get("type");
|
|
Integer type = (Integer) map.get("type");
|
|
//常规规则+阈值
|
|
//常规规则+阈值
|
|
List<RuleGroup> notCopyGroups = (List<RuleGroup>) map.get("notCopy");
|
|
List<RuleGroup> notCopyGroups = (List<RuleGroup>) map.get("notCopy");
|
|
- JSONObject notCopythreshold = getThreshold(templates.getAccountId(), false);
|
|
|
|
|
|
+ JSONObject notCopythreshold = getThreshold(templates.getAccountId(), isCopy);
|
|
//可复制规则+阈值
|
|
//可复制规则+阈值
|
|
List<RuleGroup> isCopyGroups = (List<RuleGroup>) map.get("isCopy");
|
|
List<RuleGroup> isCopyGroups = (List<RuleGroup>) map.get("isCopy");
|
|
|
|
+ JSONObject isCopythreshold = new JSONObject();
|
|
if (!Check.isNull(isCopyGroups)) {
|
|
if (!Check.isNull(isCopyGroups)) {
|
|
- JSONObject isCopythreshold = getThreshold(templates.getAccountId(), true);
|
|
|
|
|
|
+ isCopy = true;
|
|
|
|
+ isCopythreshold = getThreshold(templates.getAccountId(), isCopy);
|
|
}
|
|
}
|
|
log.info("已获取账户({})的数据,开始匹配规则", templates.getAccountId());
|
|
log.info("已获取账户({})的数据,开始匹配规则", templates.getAccountId());
|
|
try {
|
|
try {
|
|
if (!Check.isNull(notCopyGroups)) {
|
|
if (!Check.isNull(notCopyGroups)) {
|
|
- checkRuleGroups(notCopyGroups, notCopythreshold, indicators, matchData, type);
|
|
|
|
|
|
+ checkRuleGroups(notCopyGroups, notCopythreshold, indicators, matchData, type, false);
|
|
}
|
|
}
|
|
|
|
+ if (isCopy && !Check.isNull(isCopythreshold)) {
|
|
|
|
+ checkRuleGroups(isCopyGroups, isCopythreshold, indicators, matchData, type, isCopy);
|
|
|
|
+ }
|
|
|
|
+
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
log.error("匹配规则逻辑异常", e);
|
|
log.error("匹配规则逻辑异常", e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void checkRuleGroups(List<RuleGroup> ruleGroups, JSONObject thresholdObj, JSONObject indicators, JSONObject matchData, Integer type) {
|
|
|
|
|
|
+ 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();
|
|
if (Check.isNull(ruleBaseList)) {
|
|
if (Check.isNull(ruleBaseList)) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
- boolean isBase = "base".equals(ruleGroup.getRuleType());
|
|
|
|
- //匹配单规则
|
|
|
|
- if (isBase) {
|
|
|
|
- RuleBase ruleBase = ruleBaseList.get(0);
|
|
|
|
- //指标对象
|
|
|
|
- JSONObject indicator = indicators.getJSONObject(ruleBase.getIndicatorCode());
|
|
|
|
- //指标阈值
|
|
|
|
- String threshold = thresholdObj.getString(ruleBase.getId().toString());
|
|
|
|
- //阈值为空时,或者阈值为“unlimited”(不限),不执行该规则
|
|
|
|
- if (Check.isNull(threshold) || "unlimited".equals(threshold)) {
|
|
|
|
- log.warn("阈值为空/不限,该规则({})不执行", ruleBase.getId());
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- //维度数据
|
|
|
|
- JSONArray dimensionData = matchData.getJSONArray(ruleBase.getRuleDimension());
|
|
|
|
- if (!Check.isNull(dimensionData)) {
|
|
|
|
- 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)) {
|
|
|
|
- sendMsg(ruleGroup, obj);
|
|
|
|
|
|
+ //复制逻辑
|
|
|
|
+ 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 {
|
|
} else {
|
|
- boolean flag = false;
|
|
|
|
- //符合规则的数据集
|
|
|
|
- JSONArray targetDatas = new JSONArray();
|
|
|
|
- JSONArray planDatas = new JSONArray();
|
|
|
|
- JSONArray creativeDatas = new JSONArray();
|
|
|
|
- JSONArray accountDatas = new JSONArray();
|
|
|
|
- for (RuleBase ruleBase : ruleBaseList) {
|
|
|
|
|
|
+ boolean isBase = "base".equals(ruleGroup.getRuleType());
|
|
|
|
+ //匹配单规则
|
|
|
|
+ if (isBase) {
|
|
|
|
+ RuleBase ruleBase = ruleBaseList.get(0);
|
|
//指标对象
|
|
//指标对象
|
|
JSONObject indicator = indicators.getJSONObject(ruleBase.getIndicatorCode());
|
|
JSONObject indicator = indicators.getJSONObject(ruleBase.getIndicatorCode());
|
|
- //阈值类型
|
|
|
|
- String dataType = indicator.getString("dataType");
|
|
|
|
//指标阈值
|
|
//指标阈值
|
|
String threshold = thresholdObj.getString(ruleBase.getId().toString());
|
|
String threshold = thresholdObj.getString(ruleBase.getId().toString());
|
|
//阈值为空时,或者阈值为“unlimited”(不限),不执行该规则
|
|
//阈值为空时,或者阈值为“unlimited”(不限),不执行该规则
|
|
if (Check.isNull(threshold) || "unlimited".equals(threshold)) {
|
|
if (Check.isNull(threshold) || "unlimited".equals(threshold)) {
|
|
|
|
+ log.warn("阈值为空/不限,该规则({})不执行", ruleBase.getId());
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
+ //维度数据
|
|
JSONArray dimensionData = matchData.getJSONArray(ruleBase.getRuleDimension());
|
|
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;
|
|
|
|
|
|
+ if (!Check.isNull(dimensionData)) {
|
|
|
|
+ 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)) {
|
|
|
|
+ sendMsg(ruleGroup, obj);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- } 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);
|
|
|
|
}
|
|
}
|
|
|
|
+ //匹配组合规则
|
|
|
|
+ } 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;
|
|
|
|
+ }
|
|
|
|
+ } 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));
|
|
|
|
|
|
+ }
|
|
|
|
+ //获取达标可发送的数据
|
|
|
|
+ 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));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -331,13 +387,29 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
JSONObject obj = new JSONObject();
|
|
JSONObject obj = new JSONObject();
|
|
try {
|
|
try {
|
|
if (isCopy) {
|
|
if (isCopy) {
|
|
- List<RuleAccountThreshold> copyThresholdList = ruleAccountThresholdMapper.selectBatchNoByAccountId(accountId);
|
|
|
|
- if (Check.isNull(copyThresholdList)) {
|
|
|
|
|
|
+ List<Long> groupList = ruleAccountThresholdMapper.selectGroupIdsByAccountId(accountId);
|
|
|
|
+ if (Check.isNull(groupList)) {
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
- for (RuleAccountThreshold threshold : copyThresholdList) {
|
|
|
|
|
|
+ for (Long groupId : groupList) {
|
|
|
|
+ JSONObject groupIdObj = new JSONObject();
|
|
|
|
+ List<Long> batchNos = ruleAccountThresholdMapper.selectbatchNosByGroupIdId(accountId, groupId);
|
|
|
|
+ if (Check.isNull(batchNos)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ for (Long 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 {
|
|
} else {
|
|
List<RuleAccountThreshold> thresholdList = ruleAccountThresholdMapper.selectByAccountId(accountId);
|
|
List<RuleAccountThreshold> thresholdList = ruleAccountThresholdMapper.selectByAccountId(accountId);
|
|
if (Check.isNull(thresholdList)) {
|
|
if (Check.isNull(thresholdList)) {
|