|
@@ -2,6 +2,7 @@ package com.ytpm.service.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
+import cn.hutool.core.date.DateUnit;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.text.CharSequenceUtil;
|
|
import cn.hutool.core.text.CharSequenceUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
import cn.hutool.core.util.IdUtil;
|
|
@@ -30,6 +31,7 @@ import com.ytpm.general.Result;
|
|
|
import com.ytpm.general.ResultTable;
|
|
import com.ytpm.general.ResultTable;
|
|
|
import com.ytpm.handle.CustomerException;
|
|
import com.ytpm.handle.CustomerException;
|
|
|
import com.ytpm.risk.enums.BannedTypeEnum;
|
|
import com.ytpm.risk.enums.BannedTypeEnum;
|
|
|
|
|
+import com.ytpm.risk.enums.EffectNodeEnum;
|
|
|
import com.ytpm.risk.model.YtRiskConfig;
|
|
import com.ytpm.risk.model.YtRiskConfig;
|
|
|
import com.ytpm.risk.model.YtRiskTemplate;
|
|
import com.ytpm.risk.model.YtRiskTemplate;
|
|
|
import com.ytpm.risk.param.RiskBannedListParam;
|
|
import com.ytpm.risk.param.RiskBannedListParam;
|
|
@@ -66,6 +68,7 @@ import java.util.Date;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
|
|
|
+import java.util.Set;
|
|
|
import java.util.concurrent.Executors;
|
|
import java.util.concurrent.Executors;
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
@@ -95,7 +98,7 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
|
|
|
@Override
|
|
@Override
|
|
|
public ResultTable<RiskConfigView> getRiskConfig(String appIds) {
|
|
public ResultTable<RiskConfigView> getRiskConfig(String appIds) {
|
|
|
List<AgentAppClassView> viewList = configMapper.getAppClazz(appIds);
|
|
List<AgentAppClassView> viewList = configMapper.getAppClazz(appIds);
|
|
|
- List<RiskConfigView> configList = new ArrayList<RiskConfigView>();
|
|
|
|
|
|
|
+ List<RiskConfigView> configList = new ArrayList<>();
|
|
|
try{
|
|
try{
|
|
|
for (AgentAppClassView view : viewList) {
|
|
for (AgentAppClassView view : viewList) {
|
|
|
addConfigItem(Class.forName(view.getFullName()).getDeclaredFields(),configList,null);
|
|
addConfigItem(Class.forName(view.getFullName()).getDeclaredFields(),configList,null);
|
|
@@ -113,10 +116,11 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
|
|
|
@Override
|
|
@Override
|
|
|
public ResultTable<RiskConfigView> getFieldConfigByNode(Integer effectNode) {
|
|
public ResultTable<RiskConfigView> getFieldConfigByNode(Integer effectNode) {
|
|
|
List<AgentAppClassView> viewList = configMapper.getAppClazz("");
|
|
List<AgentAppClassView> viewList = configMapper.getAppClazz("");
|
|
|
- List<RiskConfigView> configList = new ArrayList<RiskConfigView>();
|
|
|
|
|
|
|
+ List<RiskConfigView> configList = new ArrayList<>();
|
|
|
|
|
+ Set<String> clazzSet = viewList.stream().map(AgentAppClassView::getFullName).collect(Collectors.toSet());
|
|
|
try{
|
|
try{
|
|
|
- for (AgentAppClassView view : viewList) {
|
|
|
|
|
- addConfigItem(Class.forName(view.getFullName()).getDeclaredFields(),configList,effectNode);
|
|
|
|
|
|
|
+ for (String fullName : clazzSet) {
|
|
|
|
|
+ addConfigItem(Class.forName(fullName).getDeclaredFields(),configList,effectNode);
|
|
|
}
|
|
}
|
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
|
log.error(e.getMessage());
|
|
log.error(e.getMessage());
|
|
@@ -132,8 +136,10 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
|
|
|
RiskConfigView view;
|
|
RiskConfigView view;
|
|
|
for (Field field : fields) {
|
|
for (Field field : fields) {
|
|
|
field.setAccessible(true);
|
|
field.setAccessible(true);
|
|
|
- if(Objects.nonNull(effectNode) && field.getAnnotation(CustomField.class).node() != effectNode)continue;
|
|
|
|
|
- if(!field.isAnnotationPresent(CustomField.class))continue;
|
|
|
|
|
|
|
+ if((Objects.nonNull(effectNode) && field.getAnnotation(CustomField.class).node()!=99 &&
|
|
|
|
|
+ field.getAnnotation(CustomField.class).node() != effectNode)||
|
|
|
|
|
+ !field.isAnnotationPresent(CustomField.class)
|
|
|
|
|
+ )continue;
|
|
|
view = new RiskConfigView();
|
|
view = new RiskConfigView();
|
|
|
view.setFieldName(field.getName());
|
|
view.setFieldName(field.getName());
|
|
|
if(CharSequenceUtil.isNotBlank(field.getAnnotation(CustomField.class).value())){
|
|
if(CharSequenceUtil.isNotBlank(field.getAnnotation(CustomField.class).value())){
|
|
@@ -163,8 +169,11 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
|
|
|
BeanUtil.copyProperties(listVO, config);
|
|
BeanUtil.copyProperties(listVO, config);
|
|
|
config.setChannelId(param.getChannelId());
|
|
config.setChannelId(param.getChannelId());
|
|
|
String format = String.format(config.getFieldDesc(), config.getConfigVal());
|
|
String format = String.format(config.getFieldDesc(), config.getConfigVal());
|
|
|
- if(CharSequenceUtil.isNotBlank(format)&&configList.indexOf(listVO)!= (configList.size() - 1)){
|
|
|
|
|
- content.append(format).append(",");
|
|
|
|
|
|
|
+ if(CharSequenceUtil.isNotBlank(format)){
|
|
|
|
|
+ content.append(format);
|
|
|
|
|
+ if(configList.indexOf(listVO)!= (configList.size() - 1)){
|
|
|
|
|
+ content.append(",");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
configs.add(config);
|
|
configs.add(config);
|
|
|
}
|
|
}
|
|
@@ -406,7 +415,7 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
|
|
|
config.setConfigVal(listParam.getConfigVal());
|
|
config.setConfigVal(listParam.getConfigVal());
|
|
|
configMapper.updateConfigVal(config);
|
|
configMapper.updateConfigVal(config);
|
|
|
String format = String.format(listParam.getFieldDesc(), listParam.getConfigVal());
|
|
String format = String.format(listParam.getFieldDesc(), listParam.getConfigVal());
|
|
|
- if(StrUtil.isNotBlank(format)){
|
|
|
|
|
|
|
+ if(CharSequenceUtil.isNotBlank(format)){
|
|
|
content.append(format).append(",");
|
|
content.append(format).append(",");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -430,11 +439,39 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
|
|
|
if(1==view.getEnabled()){
|
|
if(1==view.getEnabled()){
|
|
|
checkDefaultRiskConfig(dyzUser, view.getConfigList());
|
|
checkDefaultRiskConfig(dyzUser, view.getConfigList());
|
|
|
}
|
|
}
|
|
|
|
|
+ checkRisk322(dyzUser);
|
|
|
//查询用户所在app是否配置其他风控规则
|
|
//查询用户所在app是否配置其他风控规则
|
|
|
-
|
|
|
|
|
|
|
+// checkCustomRisk(dyzUser,EffectNodeEnum.LOGIN.getNode(),null);
|
|
|
return Result.resultOk(RepMessage.QUERY_SUCCESS);
|
|
return Result.resultOk(RepMessage.QUERY_SUCCESS);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 校验风控规则322
|
|
|
|
|
+ */
|
|
|
|
|
+ private void checkRisk322(YtDyzUser dyzUser) {
|
|
|
|
|
+ RiskTemplateView view = configMapper.getByCode("322");
|
|
|
|
|
+ //根据openid查询用户信息
|
|
|
|
|
+ List<YtDyzUser> dyzUsers = appFeign.queryByOpenid(dyzUser.getWxOpenId());
|
|
|
|
|
+ List<RiskConfigView> configList = view.getConfigList();
|
|
|
|
|
+ Map<String, String> configMap = configList.stream().collect(
|
|
|
|
|
+ Collectors.toMap(RiskConfigView::getFieldName, RiskConfigView::getConfigVal));
|
|
|
|
|
+ //判断同应用 UID生成数如果不小于配置数则触发规则校验
|
|
|
|
|
+ int uidCount = Integer.parseInt(configMap.get("uidCount"));
|
|
|
|
|
+ if(dyzUsers.size()<uidCount)return;
|
|
|
|
|
+ //获取配置天数以判断 同应用多渠道账号注册时间间隔不得低于配置时间
|
|
|
|
|
+ int days = Integer.parseInt(configMap.get("days"));
|
|
|
|
|
+ List<Date> regDateList = dyzUsers.stream().map(YtDyzUser::getRegistryTime).collect(Collectors.toList());
|
|
|
|
|
+ Date first = regDateList.get(0);
|
|
|
|
|
+ long interval;
|
|
|
|
|
+ for (int i = 1; i < regDateList.size(); i++) {
|
|
|
|
|
+ interval = DateUtil.between(first, regDateList.get(i), DateUnit.DAY);
|
|
|
|
|
+ if(days > interval){
|
|
|
|
|
+ riskLockUser(dyzUser,"322","系统判定重复刷单用户限制","当前用户已被风控!");
|
|
|
|
|
+ }
|
|
|
|
|
+ first = regDateList.get(i);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 校验默认风控配置, 固定配置值不改
|
|
* 校验默认风控配置, 固定配置值不改
|
|
|
* days ?天内为1
|
|
* days ?天内为1
|
|
@@ -505,9 +542,31 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
|
|
|
if(!records.isEmpty() && records.size()>1){
|
|
if(!records.isEmpty() && records.size()>1){
|
|
|
checkRisk746(dyzUser,records);
|
|
checkRisk746(dyzUser,records);
|
|
|
}
|
|
}
|
|
|
|
|
+ //查询用户所在app是否配置其他风控规则
|
|
|
|
|
+// checkCustomRisk(dyzUser,EffectNodeEnum.ADSOURCE.getNode(),table.getData());
|
|
|
return Result.resultOk(RepMessage.QUERY_SUCCESS);
|
|
return Result.resultOk(RepMessage.QUERY_SUCCESS);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 校验用户自定义风控规则
|
|
|
|
|
+ */
|
|
|
|
|
+ private void checkCustomRisk(YtDyzUser dyzUser, Integer node, List<YtDyzAdRecord> data) {
|
|
|
|
|
+ List<RiskTemplateView> templateList = configMapper.getCustomTempConfig(
|
|
|
|
|
+ dyzUser.getAppId(), node);
|
|
|
|
|
+ if(CollUtil.isNotEmpty(templateList)){
|
|
|
|
|
+ //校验用户的其他规则配置
|
|
|
|
|
+ for (RiskTemplateView templateView : templateList) {
|
|
|
|
|
+ if(EffectNodeEnum.LOGIN.getNode().equals(node)){
|
|
|
|
|
+ checkCondition(dyzUser, templateView);
|
|
|
|
|
+ }else{
|
|
|
|
|
+ for (YtDyzAdRecord datum : data) {
|
|
|
|
|
+ checkCondition(datum, templateView);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 校验默认风控规则746
|
|
* 校验默认风控规则746
|
|
|
*/
|
|
*/
|
|
@@ -604,6 +663,7 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
|
|
|
switch (param.getUserStatus()){
|
|
switch (param.getUserStatus()){
|
|
|
case 2:
|
|
case 2:
|
|
|
appUser.setRiskReason(param.getReason());
|
|
appUser.setRiskReason(param.getReason());
|
|
|
|
|
+ break;
|
|
|
case 3: //增加封禁记录
|
|
case 3: //增加封禁记录
|
|
|
RiskBannedParam bannedParam = new RiskBannedParam();
|
|
RiskBannedParam bannedParam = new RiskBannedParam();
|
|
|
BeanUtil.copyProperties(param, bannedParam);
|
|
BeanUtil.copyProperties(param, bannedParam);
|
|
@@ -688,10 +748,15 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
|
|
|
try{
|
|
try{
|
|
|
//多选校验值包含 单选校验值相等
|
|
//多选校验值包含 单选校验值相等
|
|
|
Object o = conditionField.get(obj);
|
|
Object o = conditionField.get(obj);
|
|
|
- if(2==vo.getMulty()){
|
|
|
|
|
- checkSameVal(o, vo.getConfigVal(), vo.getFieldDesc());
|
|
|
|
|
- }else{
|
|
|
|
|
- checkContainsVal(o,vo.getConfigVal(), vo.getFieldDesc());
|
|
|
|
|
|
|
+ switch (vo.getMulty()){
|
|
|
|
|
+ case 1:
|
|
|
|
|
+ checkContainsVal(o,vo.getConfigVal(), vo.getFieldDesc());
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 2:
|
|
|
|
|
+ checkSameVal(o, vo.getConfigVal(), vo.getFieldDesc());
|
|
|
|
|
+ break;
|
|
|
|
|
+ default:
|
|
|
|
|
+ checkCompareVal(o, vo.getConfigVal(),vo.getFieldDesc(),vo.getMulty());
|
|
|
}
|
|
}
|
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
|
throw new CustomerException(e.getMessage());
|
|
throw new CustomerException(e.getMessage());
|
|
@@ -700,6 +765,24 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 校验值大于
|
|
|
|
|
+ * @param o 校验对象值
|
|
|
|
|
+ * @param configVal 配置值
|
|
|
|
|
+ * @param fieldDesc 字段描述
|
|
|
|
|
+ * @param type 3- o > configVal 4- o < configVal
|
|
|
|
|
+ */
|
|
|
|
|
+ private void checkCompareVal(Object o, String configVal, String fieldDesc, int type) {
|
|
|
|
|
+ BigDecimal a = new BigDecimal(o.toString());
|
|
|
|
|
+ BigDecimal b = new BigDecimal(configVal);
|
|
|
|
|
+ if(type == 3 && a.compareTo(b) < 1){
|
|
|
|
|
+ throw new CustomerException(fieldDesc+"不符合准入条件!");
|
|
|
|
|
+ }
|
|
|
|
|
+ if(type == 4 && b.compareTo(a) < 1){
|
|
|
|
|
+ throw new CustomerException(fieldDesc+"不符合准入条件!");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 校验值包含
|
|
* 校验值包含
|
|
|
*/
|
|
*/
|
|
@@ -736,7 +819,7 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
|
|
|
}
|
|
}
|
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
try {
|
|
try {
|
|
|
- if(o instanceof Date && !format.parse(configVal).equals((Date)o)){
|
|
|
|
|
|
|
+ if(o instanceof Date && !format.parse(configVal).equals(o)){
|
|
|
throw new CustomerException(desc+"不符合准入条件!");
|
|
throw new CustomerException(desc+"不符合准入条件!");
|
|
|
}
|
|
}
|
|
|
} catch (ParseException e) {
|
|
} catch (ParseException e) {
|
|
@@ -746,7 +829,6 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public List<YtPlatformBanned> queryBannedRecord(Date startTime, Date endTime) {
|
|
public List<YtPlatformBanned> queryBannedRecord(Date startTime, Date endTime) {
|
|
|
- List<YtPlatformBanned> ytPlatformBanneds = riskManageMapper.queryBannedRecord(startTime, endTime);
|
|
|
|
|
- return ytPlatformBanneds;
|
|
|
|
|
|
|
+ return riskManageMapper.queryBannedRecord(startTime, endTime);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|