|
|
@@ -3,6 +3,7 @@ package com.ytpm.service.impl;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.text.CharSequenceUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
@@ -97,7 +98,25 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
|
|
|
List<RiskConfigView> configList = new ArrayList<RiskConfigView>();
|
|
|
try{
|
|
|
for (AgentAppClassView view : viewList) {
|
|
|
- addConfigItem(Class.forName(view.getFullName()).getDeclaredFields(),configList);
|
|
|
+ addConfigItem(Class.forName(view.getFullName()).getDeclaredFields(),configList,null);
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error(e.getMessage());
|
|
|
+ throw new CustomerException(e.getMessage());
|
|
|
+ }
|
|
|
+ return ResultTable.resultTableOk(new PageInfo<RiskConfigView>(configList));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据业务节点查询配置项
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResultTable<RiskConfigView> getFieldConfigByNode(Integer effectNode) {
|
|
|
+ List<AgentAppClassView> viewList = configMapper.getAppClazz("");
|
|
|
+ List<RiskConfigView> configList = new ArrayList<RiskConfigView>();
|
|
|
+ try{
|
|
|
+ for (AgentAppClassView view : viewList) {
|
|
|
+ addConfigItem(Class.forName(view.getFullName()).getDeclaredFields(),configList,effectNode);
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
log.error(e.getMessage());
|
|
|
@@ -109,14 +128,15 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
|
|
|
/**
|
|
|
* 添加配置项
|
|
|
*/
|
|
|
- private void addConfigItem(Field[] fields, List<RiskConfigView> configList) {
|
|
|
+ private void addConfigItem(Field[] fields, List<RiskConfigView> configList, Integer effectNode) {
|
|
|
RiskConfigView view;
|
|
|
for (Field field : fields) {
|
|
|
field.setAccessible(true);
|
|
|
+ if(Objects.nonNull(effectNode) && field.getAnnotation(CustomField.class).node() != effectNode)continue;
|
|
|
if(!field.isAnnotationPresent(CustomField.class))continue;
|
|
|
view = new RiskConfigView();
|
|
|
view.setFieldName(field.getName());
|
|
|
- if(StrUtil.isNotBlank(field.getAnnotation(CustomField.class).value())){
|
|
|
+ if(CharSequenceUtil.isNotBlank(field.getAnnotation(CustomField.class).value())){
|
|
|
view.setDictList(dictMapper.getByTypeCode(field.getAnnotation(CustomField.class).value()));
|
|
|
}
|
|
|
view.setFieldDesc(field.getAnnotation(ApiModelProperty.class).value());
|
|
|
@@ -143,7 +163,7 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
|
|
|
BeanUtil.copyProperties(listVO, config);
|
|
|
config.setChannelId(param.getChannelId());
|
|
|
String format = String.format(config.getFieldDesc(), config.getConfigVal());
|
|
|
- if(StrUtil.isNotBlank(format)){
|
|
|
+ if(CharSequenceUtil.isNotBlank(format)&&configList.indexOf(listVO)!= (configList.size() - 1)){
|
|
|
content.append(format).append(",");
|
|
|
}
|
|
|
configs.add(config);
|
|
|
@@ -196,6 +216,7 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
|
|
|
param.setBannedReason(BannedTypeEnum.CHANNEL.getDesc()+"禁止登录");
|
|
|
param.setOperatorName(userInfo.getNickName());
|
|
|
param.setOperator(userInfo.getUserId());
|
|
|
+ param.setAgentId(userInfo.getUserId());
|
|
|
param.setBannedType(BannedTypeEnum.CHANNEL.getCode());
|
|
|
addBannedRecord(Collections.singletonList(user.getUserId()),param);
|
|
|
return Result.resultOk(RepMessage.LOCK_USER_SUCCESS);
|
|
|
@@ -405,7 +426,12 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
|
|
|
@Override
|
|
|
public Result<?> checkRisk(YtDyzUser dyzUser) {
|
|
|
RiskTemplateView view = configMapper.getByCode(dyzUser.getRiskCode());
|
|
|
- checkDefaultRiskConfig(dyzUser, view.getConfigList());
|
|
|
+ //如果启用了该配置 校验默认的风控配置
|
|
|
+ if(1==view.getEnabled()){
|
|
|
+ checkDefaultRiskConfig(dyzUser, view.getConfigList());
|
|
|
+ }
|
|
|
+ //查询用户所在app是否配置其他风控规则
|
|
|
+
|
|
|
return Result.resultOk(RepMessage.QUERY_SUCCESS);
|
|
|
}
|
|
|
|
|
|
@@ -438,7 +464,7 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
|
|
|
}
|
|
|
int ipSameCount = Integer.parseInt(configMap.get("ipSameCount"));
|
|
|
if(intCount > ipSameCount){//校验同IP登录次数大于预设值,锁定用户
|
|
|
- riskLockUser(dyzUser.getUserId(), dyzUser.getAppId(),"313","系统判定登录IP限制","当前用户已被风控!");
|
|
|
+ riskLockUser(dyzUser,"313","系统判定登录IP限制","当前用户已被风控!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -462,8 +488,8 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
|
|
|
* 校验广告的默认风控配置
|
|
|
*/
|
|
|
@Override
|
|
|
- public Result<?> checkAdRisk(String userId,String appId) {
|
|
|
- ResultTable<YtDyzAdRecord> table = appFeign.adRecords(userId);
|
|
|
+ public Result<?> checkAdRisk(YtDyzUser dyzUser) {
|
|
|
+ ResultTable<YtDyzAdRecord> table = appFeign.adRecords(dyzUser.getUserId());
|
|
|
List<YtDyzAdRecord> records = table.getData();
|
|
|
if(records.isEmpty()){
|
|
|
return Result.resultOk(RepMessage.QUERY_SUCCESS);
|
|
|
@@ -476,10 +502,10 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
|
|
|
).sorted(Comparator.comparing(YtDyzAdRecord::getFinishTime)).collect(Collectors.toList());
|
|
|
//校验风控742规则
|
|
|
RiskTemplateView ecpmLimit= configMapper.getByCode("742");
|
|
|
- checkRisk742(ecpmLimit,userId,appId,records);
|
|
|
+ checkRisk742(ecpmLimit,dyzUser,records);
|
|
|
//校验风控746规则
|
|
|
if(!records.isEmpty() && records.size()>1){
|
|
|
- checkRisk746(userId,appId,records);
|
|
|
+ checkRisk746(dyzUser,records);
|
|
|
}
|
|
|
return Result.resultOk(RepMessage.QUERY_SUCCESS);
|
|
|
}
|
|
|
@@ -487,8 +513,9 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
|
|
|
/**
|
|
|
* 校验默认风控规则746
|
|
|
*/
|
|
|
- private void checkRisk746(String userId,String appId, List<YtDyzAdRecord> records) {
|
|
|
+ private void checkRisk746(YtDyzUser dyzUser, List<YtDyzAdRecord> records) {
|
|
|
RiskTemplateView revenue = configMapper.getByCode("746");
|
|
|
+ if(revenue.getEnabled()!=1)return;
|
|
|
Map<String, String> revenueMap = revenue.getConfigList().stream().collect(
|
|
|
Collectors.toMap(RiskConfigView::getFieldName, RiskConfigView::getConfigVal));
|
|
|
List<YtDyzAdRecord> revenues = records.stream().filter(
|
|
|
@@ -502,7 +529,7 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
|
|
|
//获取最先的两条
|
|
|
BigDecimal reduce = revenues.stream().map(YtDyzAdRecord::getRevenue).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
if(reduce.compareTo(income)<0){
|
|
|
- riskLockUser(userId,appId, "746","系统判定小于最低收益限制","用户已被风控,风控编码:746");
|
|
|
+ riskLockUser(dyzUser, "746","系统判定小于最低收益限制","用户已被风控,风控编码:746");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -510,7 +537,8 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
|
|
|
/**
|
|
|
* 校验默认风控规则742
|
|
|
*/
|
|
|
- private void checkRisk742(RiskTemplateView ecpmLimit,String userId,String appId,List<YtDyzAdRecord> records) {
|
|
|
+ private void checkRisk742(RiskTemplateView ecpmLimit,YtDyzUser dyzUser,List<YtDyzAdRecord> records) {
|
|
|
+ if(ecpmLimit.getEnabled()!=1)return;
|
|
|
Map<String, String> limitMap = ecpmLimit.getConfigList().stream().collect(
|
|
|
Collectors.toMap(RiskConfigView::getFieldName, RiskConfigView::getConfigVal));
|
|
|
int adCount = 0;
|
|
|
@@ -527,7 +555,7 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
|
|
|
//判断小于预设值的视频数超出预设次数
|
|
|
int haveCount = Integer.parseInt(limitMap.get("haveCount"));
|
|
|
if(exact>haveCount){
|
|
|
- riskLockUser(userId, appId,"742","系统判定激励视频ecpm值过低","用户已被风控,风控编码:742");
|
|
|
+ riskLockUser(dyzUser,"742","系统判定激励视频ecpm值过低","用户已被风控,风控编码:742");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -535,21 +563,23 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
|
|
|
/**
|
|
|
* 风控锁定用户
|
|
|
*/
|
|
|
- private void riskLockUser(String userId,String appId, String riskCode, String tempName, String errMsg) {
|
|
|
+ private void riskLockUser(YtDyzUser dyzUser, String riskCode, String tempName, String errMsg) {
|
|
|
//增加用户风控记录
|
|
|
RiskBannedParam param = new RiskBannedParam();
|
|
|
- param.setUserId(userId);
|
|
|
- param.setAppId(appId);
|
|
|
+ param.setUserId(dyzUser.getUserId());
|
|
|
+ param.setAppId(dyzUser.getAppId());
|
|
|
+ param.setDitChId(dyzUser.getDitchId());
|
|
|
param.setBannedLimit(24);
|
|
|
param.setOperator("系统风控");
|
|
|
param.setBannedReason(tempName);
|
|
|
param.setOperatorName("系统风控");
|
|
|
- addBannedRecord(Collections.singletonList(userId),param);
|
|
|
+ param.setAgentId(configMapper.getApplicationOwner(dyzUser.getAppId()));
|
|
|
+ addBannedRecord(Collections.singletonList(dyzUser.getUserId()),param);
|
|
|
//懒得引入mq,因而利用线程池创建延迟定时任务修改用户状态,主线程继续执行,避免循环调用产生的死锁
|
|
|
ScheduledExecutorService scheduled = Executors.newSingleThreadScheduledExecutor();
|
|
|
scheduled.schedule(()->{
|
|
|
YtDyzUser next = new YtDyzUser();
|
|
|
- next.setUserId(userId);
|
|
|
+ next.setUserId(dyzUser.getUserId());
|
|
|
next.setUserStatus(UserStatusEnum.LOCK.getCode());
|
|
|
next.setRiskCode(riskCode);
|
|
|
next.setRiskReason(tempName);
|
|
|
@@ -558,7 +588,7 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
|
|
|
//创建一次性定时任务用于24小时后解锁用户
|
|
|
scheduled.schedule(()->{
|
|
|
YtDyzUser user = new YtDyzUser();
|
|
|
- user.setUserId(userId);
|
|
|
+ user.setUserId(dyzUser.getUserId());
|
|
|
user.setUserStatus(UserStatusEnum.NORMAL.getCode());
|
|
|
appFeign.updateUserInfo(user);
|
|
|
scheduled.shutdown();
|
|
|
@@ -587,8 +617,7 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
|
|
|
default: //解禁
|
|
|
YtPlatformBanned banned = riskManageMapper.getLastBanned(user.getUserId());
|
|
|
if(Objects.nonNull(banned)){
|
|
|
- addDeblockingRecord(banned.getBannedId(),banned.getAppId(),user.getUserId(),param.getOperator()
|
|
|
- ,param.getReason(),param.getOperatorName());
|
|
|
+ addDeblockingRecord(banned,param);
|
|
|
}
|
|
|
}
|
|
|
appFeign.updateUserInfo(appUser);
|
|
|
@@ -597,17 +626,17 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
|
|
|
/**
|
|
|
* 增加解禁记录
|
|
|
*/
|
|
|
- private void addDeblockingRecord(String bannedId, String appId, String userId, String operator, String reason, String operatorName) {
|
|
|
+ private void addDeblockingRecord(YtPlatformBanned banned, RiskUserStatusParam param) {
|
|
|
YtPlatformDeblocking deblocking = new YtPlatformDeblocking();
|
|
|
deblocking.setDeblockingId(IdUtil.fastSimpleUUID());
|
|
|
- deblocking.setUserId(userId);
|
|
|
- deblocking.setAppId(appId);
|
|
|
- deblocking.setOperator(operator);
|
|
|
- deblocking.setOperatorName(operatorName);
|
|
|
- deblocking.setBannedId(bannedId);
|
|
|
- deblocking.setDeblockingReason(reason);
|
|
|
+ deblocking.setUserId(banned.getUserId());
|
|
|
+ deblocking.setAppId(banned.getAppId());
|
|
|
+ deblocking.setAgentId(param.getAgentId());
|
|
|
+ deblocking.setOperator(param.getOperator());
|
|
|
+ deblocking.setOperatorName(param.getOperatorName());
|
|
|
+ deblocking.setBannedId(banned.getBannedId());
|
|
|
+ deblocking.setDeblockingReason(param.getReason());
|
|
|
deblocking.setDeblockingTime(new Date());
|
|
|
- deblocking.setChannelId(operator);
|
|
|
riskManageMapper.addDeblockingRecord(deblocking);
|
|
|
}
|
|
|
|
|
|
@@ -621,7 +650,10 @@ public class RiskServiceImpl extends ReflectUtil implements RiskService {
|
|
|
banned.setBannedId(IdUtil.fastSimpleUUID());
|
|
|
banned.setUserId(userId);
|
|
|
banned.setAppId(param.getAppId());
|
|
|
- banned.setChannelId(param.getOperator());
|
|
|
+ banned.setAgentId(param.getAgentId());
|
|
|
+ if(Objects.nonNull(param.getDitChId())){
|
|
|
+ banned.setChannelId(param.getDitChId().toString());
|
|
|
+ }
|
|
|
banned.setBannedLimit(Objects.isNull(param.getBannedLimit())?defaultLimit:param.getBannedLimit());
|
|
|
banned.setBannedReason(StrUtil.isBlank(param.getBannedReason())?defaultReason:param.getBannedReason());
|
|
|
banned.setBannedType(BannedTypeEnum.CHANNEL.getCode());
|