|
@@ -1,19 +1,26 @@
|
|
package cn.com.ctop.alarm.modules.service.impl;
|
|
package cn.com.ctop.alarm.modules.service.impl;
|
|
|
|
|
|
|
|
+import cn.com.ctop.alarm.modules.constant.MatchLogic;
|
|
import cn.com.ctop.alarm.modules.entity.*;
|
|
import cn.com.ctop.alarm.modules.entity.*;
|
|
import cn.com.ctop.alarm.modules.mapper.*;
|
|
import cn.com.ctop.alarm.modules.mapper.*;
|
|
import cn.com.ctop.alarm.modules.service.IRuleAccountTemplateService;
|
|
import cn.com.ctop.alarm.modules.service.IRuleAccountTemplateService;
|
|
import cn.com.ctop.alarm.modules.service.IRuleGroupService;
|
|
import cn.com.ctop.alarm.modules.service.IRuleGroupService;
|
|
|
|
+import cn.com.ctop.common.module.entity.CtopOauthToken;
|
|
|
|
+import cn.com.ctop.common.module.mapper.SysUserMapper;
|
|
|
|
+import cn.com.ctop.common.module.service.ICtopOauthTokenService;
|
|
|
|
+import cn.com.ctop.common.module.service.IRuleDataAccountService;
|
|
|
|
+import cn.com.ctop.common.module.service.ISendMessageService;
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
import cn.com.ctop.common.module.utils.Check;
|
|
|
|
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaiShouUpdateService;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.xxl.job.core.enums.NoEn;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
@@ -25,6 +32,7 @@ import java.util.Map;
|
|
* @version V1.0
|
|
* @version V1.0
|
|
* @date 2020-11-15
|
|
* @date 2020-11-15
|
|
*/
|
|
*/
|
|
|
|
+@Slf4j
|
|
@Service
|
|
@Service
|
|
public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup> implements IRuleGroupService {
|
|
public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup> implements IRuleGroupService {
|
|
|
|
|
|
@@ -41,9 +49,20 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
@Autowired
|
|
@Autowired
|
|
private RuleTemplateMapper ruleTemplateMapper;
|
|
private RuleTemplateMapper ruleTemplateMapper;
|
|
@Autowired
|
|
@Autowired
|
|
|
|
+ private SysUserMapper sysUserMapper;
|
|
|
|
+ @Autowired
|
|
private IRuleGroupService ruleGroupService;
|
|
private IRuleGroupService ruleGroupService;
|
|
@Autowired
|
|
@Autowired
|
|
private IRuleAccountTemplateService ruleAccountTemplateService;
|
|
private IRuleAccountTemplateService ruleAccountTemplateService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ISendMessageService sendMessageService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IKuaiShouUpdateService kuaiShouUpdateService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ICtopOauthTokenService oauthTokenService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IRuleDataAccountService ruleDataAccountService;
|
|
|
|
+ private JSONObject userObj = null;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void checkRules() {
|
|
public void checkRules() {
|
|
@@ -53,12 +72,6 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
log.warn("查询账户绑定过的规则模板失败");
|
|
log.warn("查询账户绑定过的规则模板失败");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- //查询匹配数据
|
|
|
|
- List<JSONObject> dataList = getData();
|
|
|
|
- if (Check.isNull(dataList)) {
|
|
|
|
- log.warn("查询匹配数据失败");
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
//获取规则集
|
|
//获取规则集
|
|
Map<Long, List<RuleGroup>> ruleGroupMap = getRuleGroupMap();
|
|
Map<Long, List<RuleGroup>> ruleGroupMap = getRuleGroupMap();
|
|
if (Check.isNull(ruleGroupMap)) {
|
|
if (Check.isNull(ruleGroupMap)) {
|
|
@@ -72,12 +85,8 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
for (RuleAccountTemplate templates : ruleAccountTemplates) {
|
|
for (RuleAccountTemplate templates : ruleAccountTemplates) {
|
|
- for (JSONObject matchData : dataList) {
|
|
|
|
- if (templates.getAccountId() == matchData.getLong("accountId")) {
|
|
|
|
- List<RuleGroup> ruleGroups = ruleGroupMap.get(templates.getTemplateId());
|
|
|
|
- matchAlarmRules(ruleGroups, getThreshold(ruleAccountThresholdMapper.selectByAccountId(templates.getAccountId())), matchData, indicators);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ List<RuleGroup> ruleGroups = ruleGroupMap.get(templates.getTemplateId());
|
|
|
|
+ matchAlarmRules(ruleGroups, getThreshold(ruleAccountThresholdMapper.selectByAccountId(templates.getAccountId())), indicators, templates.getAccountId());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -86,92 +95,195 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
*
|
|
*
|
|
* @param ruleGroups 规则集
|
|
* @param ruleGroups 规则集
|
|
* @param thresholdObj 规则id阈值
|
|
* @param thresholdObj 规则id阈值
|
|
- * @param matchData 匹配数据
|
|
|
|
* @param indicators 指标码
|
|
* @param indicators 指标码
|
|
* @return void
|
|
* @return void
|
|
* @throws
|
|
* @throws
|
|
* @author ZHAOXA
|
|
* @author ZHAOXA
|
|
*/
|
|
*/
|
|
- private void matchAlarmRules(List<RuleGroup> ruleGroups, JSONObject thresholdObj, JSONObject matchData, JSONObject indicators) {
|
|
|
|
|
|
+ private void matchAlarmRules(List<RuleGroup> ruleGroups, JSONObject thresholdObj, JSONObject indicators, Long accountId) {
|
|
|
|
+ userObj = new JSONObject();
|
|
|
|
+ //查询匹配数据
|
|
|
|
+ JSONObject matchData = getRuleData(accountId);
|
|
|
|
+ if (Check.isNull(matchData)) {
|
|
|
|
+ log.warn("查询匹配数据失败");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ log.info("已获取账户({})的数据,开始匹配规则", accountId);
|
|
for (RuleGroup ruleGroup : ruleGroups) {
|
|
for (RuleGroup ruleGroup : ruleGroups) {
|
|
- String sendType = ruleGroup.getSendType();
|
|
|
|
- boolean isPause = "PAUSE".equals(ruleGroup.getOperate());
|
|
|
|
- boolean isAllTrue = "and".equals(ruleGroup.getRuleRelationship());
|
|
|
|
- boolean flag = true;
|
|
|
|
List<RuleBase> ruleBaseList = ruleGroup.getRuleBaseList();
|
|
List<RuleBase> ruleBaseList = ruleGroup.getRuleBaseList();
|
|
- for (RuleBase ruleBase : ruleBaseList) {
|
|
|
|
- //and关系,全部匹配规则
|
|
|
|
- if (isAllTrue) {
|
|
|
|
- if (flag) {
|
|
|
|
- //指标阈值
|
|
|
|
- String threshold = thresholdObj.getString(ruleBase.getId().toString());
|
|
|
|
- //指标对象
|
|
|
|
- JSONObject indicator = indicators.getJSONObject(ruleBase.getIndicatorCode());
|
|
|
|
- flag = checkThreshold(threshold, ruleBase, indicator);
|
|
|
|
|
|
+ if (Check.isNull(ruleBaseList)) {
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //匹配组合规则
|
|
|
|
+ } else {
|
|
|
|
+ boolean flag = false;
|
|
|
|
+ //符合规则的数据集
|
|
|
|
+ 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);
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+ //获取达标可发送的数据
|
|
|
|
+ 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));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * @param ruleDatas 达标数据集
|
|
|
|
+ * @param dimensionData 匹配数据
|
|
|
|
+ * @param ruleBase 规则
|
|
|
|
+ * @param type 数据类型
|
|
|
|
+ * @param threshold 阈值
|
|
|
|
+ * @return void
|
|
|
|
+ * @throws
|
|
|
|
+ * @author ZHAOXA
|
|
|
|
+ */
|
|
|
|
+ private JSONArray getOKData(JSONArray ruleDatas, JSONArray dimensionData, RuleBase ruleBase, String type, String threshold) {
|
|
|
|
+ if (ruleDatas.size() > 0) {
|
|
|
|
+ JSONArray okData = new JSONArray();
|
|
|
|
+ for (int i = 0; i < ruleDatas.size(); i++) {
|
|
|
|
+ JSONObject targetEntity = dimensionData.getJSONObject(i);
|
|
|
|
+ String value = targetEntity.getString(ruleBase.getIndicatorCode());
|
|
|
|
+ if (MatchLogic.matchCondition(type, ruleBase.getRuleCondition(), threshold, value)) {
|
|
|
|
+ okData.add(targetEntity);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return okData;
|
|
|
|
+ }
|
|
|
|
+ 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)) {
|
|
|
|
+ ruleDatas.add(targetEntity);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return ruleDatas;
|
|
}
|
|
}
|
|
|
|
|
|
- private boolean checkThreshold(String threshold, RuleBase ruleBase, JSONObject indicator) {
|
|
|
|
- //条件
|
|
|
|
- String condition = ruleBase.getRuleCondition();
|
|
|
|
- //指标
|
|
|
|
- String indicatorCode = ruleBase.getIndicatorCode();
|
|
|
|
- //维度
|
|
|
|
- String ruleDimension = ruleBase.getRuleDimension();
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 发送消息
|
|
|
|
+ *
|
|
|
|
+ * @param
|
|
|
|
+ * @return void
|
|
|
|
+ * @throws
|
|
|
|
+ * @author ZHAOXA
|
|
|
|
+ */
|
|
|
|
+ private void sendMsg(RuleGroup ruleGroup, JSONObject obj) {
|
|
|
|
+ Long creativeId = obj.getLong("creativeId");
|
|
|
|
+ Long planId = obj.getLong("planId");
|
|
|
|
+ Long accountId = obj.getLong("accountId");
|
|
|
|
+ JSONObject user = getUserByAccountId(accountId);
|
|
|
|
+ boolean isPause = "PAUSE".equals(ruleGroup.getOperate());
|
|
|
|
+ if (isPause) {
|
|
|
|
+ if (shutDown(accountId, planId, creativeId, user.getString("id"))) {
|
|
|
|
+ isPause = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ String msg = MatchLogic.getMsg(ruleGroup, user, accountId, planId, creativeId, isPause);
|
|
|
|
+ String sendType = ruleGroup.getSendType();
|
|
|
|
+ if ("SMS".equals(sendType)) {
|
|
|
|
+
|
|
|
|
+ } else if ("EMAIL".equals(sendType)) {
|
|
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
|
|
+ } else if ("TEL".equals(sendType)) {
|
|
|
|
|
|
- private boolean check(String type, String condition, String threshold, String value) {
|
|
|
|
- if ("number".equals(type)) {
|
|
|
|
- BigDecimal bigThr = new BigDecimal(threshold);
|
|
|
|
- BigDecimal bigVal = new BigDecimal(value);
|
|
|
|
- if ("equal".equals(condition))
|
|
|
|
- return bigVal.compareTo(bigThr) == 0;
|
|
|
|
- else if ("not_equal".equals(condition))
|
|
|
|
- return bigVal.compareTo(bigThr) != 0;
|
|
|
|
- else if ("greater".equals(condition))
|
|
|
|
- return bigVal.compareTo(bigThr) > 0;
|
|
|
|
- else if ("less".equals(condition))
|
|
|
|
- return bigVal.compareTo(bigThr) < 0;
|
|
|
|
- else if ("greater_equal".equals(condition))
|
|
|
|
- return bigVal.compareTo(bigThr) >= 0;
|
|
|
|
- else if ("less_equal".equals(condition))
|
|
|
|
- return bigVal.compareTo(bigThr) <= 0;
|
|
|
|
- } else if ("string".equals(type)) {
|
|
|
|
- if ("equal".equals(condition))
|
|
|
|
- return value.equals(threshold);
|
|
|
|
- else if ("not_equal".equals(condition))
|
|
|
|
- return !value.equals(threshold);
|
|
|
|
- else if ("contain".equals(condition))
|
|
|
|
- return !value.contains(threshold);
|
|
|
|
- else if ("no_contain".equals(condition))
|
|
|
|
- return !value.contains(threshold);
|
|
|
|
} else {
|
|
} else {
|
|
- String[] strings = threshold.split(",");
|
|
|
|
- if ("contain".equals(condition)) {
|
|
|
|
- for (String string : strings) {
|
|
|
|
- if (value.contains(string)) {
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- for (String string : strings) {
|
|
|
|
- if (!value.contains(string)) {
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ sendMessageService.sendMessage(user.getString("id"), msg);
|
|
}
|
|
}
|
|
- return false;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private JSONObject getUserByAccountId(Long accountId) {
|
|
|
|
+ JSONObject obj = userObj.getJSONObject(accountId.toString());
|
|
|
|
+ if (Check.isNull(obj)) {
|
|
|
|
+ JSONObject user = sysUserMapper.selectUserByAccount(accountId);
|
|
|
|
+ obj.put(accountId.toString(), user);
|
|
|
|
+ return user;
|
|
|
|
+ }
|
|
|
|
+ return obj;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 关停操作
|
|
|
|
+ *
|
|
|
|
+ * @param
|
|
|
|
+ * @return boolean
|
|
|
|
+ * @throws
|
|
|
|
+ * @author ZHAOXA
|
|
|
|
+ */
|
|
|
|
+ private boolean shutDown(Long accountId, Long planId, Long creativeId, String userId) {
|
|
|
|
+ CtopOauthToken token = oauthTokenService.getTokenByAccountId(accountId);
|
|
|
|
+ Map<String, Object> updateMap = new HashMap<>();
|
|
|
|
+ if (!Check.isNull(token)) {
|
|
|
|
+ if (!Check.isNull(creativeId)) {
|
|
|
|
+ updateMap = kuaiShouUpdateService.updateCreativeStatus(token.getAccessToken(), accountId, creativeId, NoEn.NO2.valueInt(), userId);
|
|
|
|
+ log.info("---------规则关停创意:{}", creativeId);
|
|
|
|
+ } else if (!Check.isNull(planId) && Check.isNull(creativeId)) {
|
|
|
|
+ updateMap = kuaiShouUpdateService.updateCampaignStatus(token.getAccessToken(), accountId, planId, NoEn.NO2.valueInt(), userId);
|
|
|
|
+ log.info("---------规则关停计划:{}", planId);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return (boolean) updateMap.get("success");
|
|
|
|
+ }
|
|
|
|
|
|
//整理阈值数据
|
|
//整理阈值数据
|
|
public JSONObject getThreshold(List<RuleAccountThreshold> thresholdList) {
|
|
public JSONObject getThreshold(List<RuleAccountThreshold> thresholdList) {
|
|
@@ -211,44 +323,31 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
Map<Long, List<RuleGroup>> map = new HashMap<>();
|
|
Map<Long, List<RuleGroup>> map = new HashMap<>();
|
|
List<RuleTemplate> ruleTemplates = ruleTemplateMapper.selectByMap(null);
|
|
List<RuleTemplate> ruleTemplates = ruleTemplateMapper.selectByMap(null);
|
|
ruleTemplates.forEach(tem -> {
|
|
ruleTemplates.forEach(tem -> {
|
|
- List<String> groupIds = strToList(tem.getGroupIds());
|
|
|
|
- if (!Check.isNull(groupIds)) {
|
|
|
|
- List<RuleGroup> ruleGroups = ruleGroupMapper.selectBatchIds(groupIds);
|
|
|
|
- for (RuleGroup group : ruleGroups) {
|
|
|
|
- List<String> ruleIds = strToList(group.getRuleIds());
|
|
|
|
- if (!Check.isNull(ruleIds)) {
|
|
|
|
- group.setRuleBaseList(ruleBaseMapper.selectBatchIds(ruleIds));
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- map.put(tem.getId(), ruleGroups);
|
|
|
|
|
|
+ QueryWrapper<RuleGroup> groupWrapper = new QueryWrapper<>();
|
|
|
|
+ groupWrapper.eq("template_id", tem.getId());
|
|
|
|
+ List<RuleGroup> ruleGroups = ruleGroupMapper.selectList(groupWrapper);
|
|
|
|
+ for (RuleGroup group : ruleGroups) {
|
|
|
|
+ QueryWrapper<RuleBase> baseWrapper = new QueryWrapper<>();
|
|
|
|
+ baseWrapper.eq("group_id", group.getId());
|
|
|
|
+ baseWrapper.orderByDesc("is_unlimited");
|
|
|
|
+ group.setRuleBaseList(ruleBaseMapper.selectList(baseWrapper));
|
|
}
|
|
}
|
|
|
|
+ map.put(tem.getId(), ruleGroups);
|
|
});
|
|
});
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
- //拆分逗号拼接数据
|
|
|
|
- private List<String> strToList(String strings) {
|
|
|
|
- if (Check.isNull(strings)) {
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
- List<String> ids = new ArrayList<>();
|
|
|
|
- String[] idArray = strings.split(",");
|
|
|
|
- for (String id : idArray) {
|
|
|
|
- ids.add(id);
|
|
|
|
- }
|
|
|
|
- return ids;
|
|
|
|
- }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
- * TODO 获取指标数据
|
|
|
|
|
|
+ * 获取指标数据
|
|
*
|
|
*
|
|
* @param
|
|
* @param
|
|
* @return java.util.List<org.json.JSONObject>
|
|
* @return java.util.List<org.json.JSONObject>
|
|
* @throws
|
|
* @throws
|
|
* @author ZHAOXA
|
|
* @author ZHAOXA
|
|
*/
|
|
*/
|
|
- private List<JSONObject> getData() {
|
|
|
|
- return null;
|
|
|
|
|
|
+ private JSONObject getRuleData(Long accountId) {
|
|
|
|
+ return ruleDataAccountService.getRuleDataByAccountId(accountId);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -263,7 +362,7 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
public JSONObject createRuleGroup(com.alibaba.fastjson.JSONObject requestJson) {
|
|
public JSONObject createRuleGroup(com.alibaba.fastjson.JSONObject requestJson) {
|
|
JSONObject returnJson = new JSONObject();
|
|
JSONObject returnJson = new JSONObject();
|
|
try {
|
|
try {
|
|
- String templateId = requestJson.getString("templateId");
|
|
|
|
|
|
+ Long templateId = requestJson.getLong("templateId");
|
|
if (Check.isNull(templateId)) {
|
|
if (Check.isNull(templateId)) {
|
|
throw new Exception("请选择需要创建的规则模板id");
|
|
throw new Exception("请选择需要创建的规则模板id");
|
|
}
|
|
}
|
|
@@ -296,15 +395,24 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
ruleBase.setThreshold(ruleDetailJson.getString("threshold"));
|
|
ruleBase.setThreshold(ruleDetailJson.getString("threshold"));
|
|
ruleBase.setVariableType(ruleDetailJson.getInteger("variableType"));
|
|
ruleBase.setVariableType(ruleDetailJson.getInteger("variableType"));
|
|
ruleBase.setRuleDimension(ruleDetailJson.getString("ruleDimension"));
|
|
ruleBase.setRuleDimension(ruleDetailJson.getString("ruleDimension"));
|
|
|
|
+ ruleBase.setJudgeFormat(ruleDetailJson.getInteger("judgeFormat"));
|
|
|
|
+ ruleBase.setIsUnlimited(ruleDetailJson.getInteger("isUnlimited"));
|
|
int insert = ruleBaseMapper.insert(ruleBase); // 添加基础规则
|
|
int insert = ruleBaseMapper.insert(ruleBase); // 添加基础规则
|
|
if (insert > 0) {
|
|
if (insert > 0) {
|
|
if (!Check.isNull(accountList)) {
|
|
if (!Check.isNull(accountList)) {
|
|
for (RuleAccountTemplate accountTemplate : accountList) {
|
|
for (RuleAccountTemplate accountTemplate : accountList) {
|
|
Long accountId = accountTemplate.getAccountId();
|
|
Long accountId = accountTemplate.getAccountId();
|
|
|
|
+ QueryWrapper<RuleAccountThreshold> thresholdQueryWrapper = new QueryWrapper<>();
|
|
|
|
+ thresholdQueryWrapper.eq("account_id", accountId);
|
|
|
|
+ thresholdQueryWrapper.eq("rule_id", ruleBase.getId());
|
|
|
|
+ thresholdQueryWrapper.last("limit 1");
|
|
|
|
+ RuleAccountThreshold accountThreshold = ruleAccountThresholdMapper.selectOne(thresholdQueryWrapper);
|
|
|
|
+ if (!Check.isNull(accountThreshold)) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
RuleAccountThreshold threshold = new RuleAccountThreshold();
|
|
RuleAccountThreshold threshold = new RuleAccountThreshold();
|
|
threshold.setAccountId(accountId);
|
|
threshold.setAccountId(accountId);
|
|
threshold.setRuleId(ruleBase.getId());
|
|
threshold.setRuleId(ruleBase.getId());
|
|
- // threshold.setThreshoId(ruleDetailJson.getString("threshold"));
|
|
|
|
ruleAccountThresholdMapper.insert(threshold); // 默认将新建的规则同步到已应用的账户下
|
|
ruleAccountThresholdMapper.insert(threshold); // 默认将新建的规则同步到已应用的账户下
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -314,11 +422,23 @@ public class RuleGroupServiceImpl extends ServiceImpl<RuleGroupMapper, RuleGroup
|
|
RuleGroup ruleGroup = new RuleGroup();
|
|
RuleGroup ruleGroup = new RuleGroup();
|
|
ruleGroup.setRuleIds(ruleIds.toJSONString());
|
|
ruleGroup.setRuleIds(ruleIds.toJSONString());
|
|
ruleGroup.setRuleType(groupJson.getString("ruleType"));
|
|
ruleGroup.setRuleType(groupJson.getString("ruleType"));
|
|
|
|
+ ruleGroup.setTemplateId(templateId);
|
|
ruleGroup.setRuleRelationship(groupJson.getString("ruleRelationship"));
|
|
ruleGroup.setRuleRelationship(groupJson.getString("ruleRelationship"));
|
|
ruleGroup.setGroupName(groupJson.getString("groupName"));
|
|
ruleGroup.setGroupName(groupJson.getString("groupName"));
|
|
ruleGroup.setRemark(groupJson.getString("remark"));
|
|
ruleGroup.setRemark(groupJson.getString("remark"));
|
|
|
|
+ ruleGroup.setIsCopy(groupJson.getInteger("isCopy"));
|
|
|
|
+ ruleGroup.setIsRequired(groupJson.getInteger("isRequired"));
|
|
boolean save = ruleGroupService.save(ruleGroup); // 新增规则组
|
|
boolean save = ruleGroupService.save(ruleGroup); // 新增规则组
|
|
if (save) {
|
|
if (save) {
|
|
|
|
+
|
|
|
|
+ for (int j = 0; j < ruleIds.size(); j++) {
|
|
|
|
+ Long ruleId = ruleIds.getLong(j);
|
|
|
|
+ RuleBase updateRuleBase = new RuleBase();
|
|
|
|
+ updateRuleBase.setId(ruleId);
|
|
|
|
+ updateRuleBase.setGroupId(ruleGroup.getId());
|
|
|
|
+ ruleBaseMapper.updateById(updateRuleBase);
|
|
|
|
+ }
|
|
|
|
+
|
|
JSONArray groupIds = JSONArray.parseArray(template.getGroupIds());
|
|
JSONArray groupIds = JSONArray.parseArray(template.getGroupIds());
|
|
groupIds.add(ruleGroup.getId());
|
|
groupIds.add(ruleGroup.getId());
|
|
template.setGroupIds(groupIds.toJSONString());
|
|
template.setGroupIds(groupIds.toJSONString());
|