|
@@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.text.CharSequenceUtil;
|
|
import cn.hutool.core.text.CharSequenceUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
|
|
+import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
@@ -89,7 +90,7 @@ public class RiskServiceImpl implements RiskService {
|
|
|
@Override
|
|
@Override
|
|
|
public Result<?> lockUser(AgentUserInfo curUser, String userId, String appId) {
|
|
public Result<?> lockUser(AgentUserInfo curUser, String userId, String appId) {
|
|
|
redisService.setTimeOutStr("lock_"+userId,appId,1000);
|
|
redisService.setTimeOutStr("lock_"+userId,appId,1000);
|
|
|
- addBannedRecord(userId,curUser,appId,24);
|
|
|
|
|
|
|
+ addBannedRecord(userId,curUser,appId,24,BannedTypeEnum.CHANNEL.getDesc()+"禁止登录");
|
|
|
return Result.resultOk(RepMessage.LOCK_USER_SUCCESS);
|
|
return Result.resultOk(RepMessage.LOCK_USER_SUCCESS);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -99,12 +100,57 @@ public class RiskServiceImpl implements RiskService {
|
|
|
@Override
|
|
@Override
|
|
|
public Result<?> banned(RiskBannedParam param,AgentUserInfo curUser) {
|
|
public Result<?> banned(RiskBannedParam param,AgentUserInfo curUser) {
|
|
|
redisService.setTimeOutStr("lock_"+param.getUserId(),param.getAppId(),1000);
|
|
redisService.setTimeOutStr("lock_"+param.getUserId(),param.getAppId(),1000);
|
|
|
- addBannedRecord(param.getUserId(),curUser,param.getAppId(),param.getBannedLimit()*24 );
|
|
|
|
|
|
|
+ addBannedRecord(param.getUserId(),curUser,param.getAppId(),param.getBannedLimit()*24,param.getBannedReason());
|
|
|
//预设24小时过期key 用于解锁用户
|
|
//预设24小时过期key 用于解锁用户
|
|
|
redisService.setTimeOutHoursStr("unlock_"+param.getUserId(),param.getAppId(),param.getBannedLimit() * 24L);
|
|
redisService.setTimeOutHoursStr("unlock_"+param.getUserId(),param.getAppId(),param.getBannedLimit() * 24L);
|
|
|
return Result.resultOk(RepMessage.ALREADY_RISK_USER);
|
|
return Result.resultOk(RepMessage.ALREADY_RISK_USER);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 风控批量封禁用户
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public Result<?> batchBanned(RiskBannedParam param,AgentUserInfo curUser) {
|
|
|
|
|
+ if(StrUtil.isBlank(param.getUserIds())){
|
|
|
|
|
+ return Result.resultErr("请选择封禁用户");
|
|
|
|
|
+ }
|
|
|
|
|
+ String[] split = param.getUserIds().split(",");
|
|
|
|
|
+ for (String userId : split) { // 为避免大量解锁的key再同一时间过期, 这里采用随机数
|
|
|
|
|
+ redisService.setTimeOutStr("lock_"+userId,param.getAppId(),RandomUtil.randomInt(500, 2000));
|
|
|
|
|
+ addBannedRecord(userId,curUser,param.getAppId(),param.getBannedLimit()*24, param.getBannedReason());
|
|
|
|
|
+ //预设20-24小时过期key 用于解锁用户
|
|
|
|
|
+ redisService.setTimeOutHoursStr("unlock_"+userId,param.getAppId(),param.getBannedLimit() * RandomUtil.randomLong(20, 24));
|
|
|
|
|
+ }
|
|
|
|
|
+ return Result.resultOk(RepMessage.ALREADY_RISK_USER);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 批量解禁用户
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Result<?> batchDeblock(RiskDeblockingListParam param, AgentUserInfo curUser) {
|
|
|
|
|
+ if(StrUtil.isBlank(param.getUserIds())){
|
|
|
|
|
+ return Result.resultErr("请选择解禁用户");
|
|
|
|
|
+ }
|
|
|
|
|
+ String[] split = param.getUserIds().split(",");
|
|
|
|
|
+ RiskUserStatusParam riskUserStatusParam;
|
|
|
|
|
+ for (String userId : split) {
|
|
|
|
|
+ //批量解封用户并增加解封记录
|
|
|
|
|
+ redisService.setTimeOutStr("unlock_"+userId,param.getAppId(),RandomUtil.randomInt(500, 2000));
|
|
|
|
|
+ YtPlatformBanned lastBanned = riskMapper.getLastBanned(userId);
|
|
|
|
|
+ riskUserStatusParam = new RiskUserStatusParam();
|
|
|
|
|
+ riskUserStatusParam.setAgentId(curUser.getUserId());
|
|
|
|
|
+ riskUserStatusParam.setOperator(curUser.getUserId());
|
|
|
|
|
+ riskUserStatusParam.setOperatorName(curUser.getNickName());
|
|
|
|
|
+ riskUserStatusParam.setReason(param.getDeblockingReason());
|
|
|
|
|
+ addDeblockingRecord(lastBanned,riskUserStatusParam);
|
|
|
|
|
+ //查询用户id 在redis中是否存在未处理的 lock_ 清除掉
|
|
|
|
|
+ redisService.del("lock_"+userId);
|
|
|
|
|
+ }
|
|
|
|
|
+ return Result.resultOk(RepMessage.PROCESS_SUCCESS);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 风控配置列表
|
|
* 风控配置列表
|
|
|
*/
|
|
*/
|
|
@@ -366,7 +412,7 @@ public class RiskServiceImpl implements RiskService {
|
|
|
break;
|
|
break;
|
|
|
case 3: //增加封禁记录
|
|
case 3: //增加封禁记录
|
|
|
appUser.setRiskReason(param.getReason());
|
|
appUser.setRiskReason(param.getReason());
|
|
|
- addBannedRecord(userId,curUser,param.getAppId(),param.getBannedLimit()*24);
|
|
|
|
|
|
|
+ addBannedRecord(userId,curUser,param.getAppId(),param.getBannedLimit()*24, param.getReason());
|
|
|
//1s锁定用户,并设置 24小时后进行解锁
|
|
//1s锁定用户,并设置 24小时后进行解锁
|
|
|
redisService.setTimeOutStr("lock_"+userId,param.getAppId(),1000);
|
|
redisService.setTimeOutStr("lock_"+userId,param.getAppId(),1000);
|
|
|
redisService.setTimeOutHoursStr("unlock_"+userId,param.getAppId(),param.getBannedLimit()*24L);
|
|
redisService.setTimeOutHoursStr("unlock_"+userId,param.getAppId(),param.getBannedLimit()*24L);
|
|
@@ -460,14 +506,14 @@ public class RiskServiceImpl implements RiskService {
|
|
|
/**
|
|
/**
|
|
|
* 增加封禁记录
|
|
* 增加封禁记录
|
|
|
*/
|
|
*/
|
|
|
- private void addBannedRecord(String userId, AgentUserInfo curUser,String appId,Integer limit) {
|
|
|
|
|
|
|
+ private void addBannedRecord(String userId, AgentUserInfo curUser,String appId,Integer limit,String bannedReason) {
|
|
|
YtPlatformBanned banned = new YtPlatformBanned();
|
|
YtPlatformBanned banned = new YtPlatformBanned();
|
|
|
banned.setBannedId(IdUtil.fastSimpleUUID());
|
|
banned.setBannedId(IdUtil.fastSimpleUUID());
|
|
|
banned.setUserId(userId);
|
|
banned.setUserId(userId);
|
|
|
banned.setAppId(curUser.getUserId());
|
|
banned.setAppId(curUser.getUserId());
|
|
|
banned.setAgentId(curUser.getUserId());
|
|
banned.setAgentId(curUser.getUserId());
|
|
|
banned.setBannedLimit(limit);
|
|
banned.setBannedLimit(limit);
|
|
|
- banned.setBannedReason(BannedTypeEnum.CHANNEL.getDesc()+"禁止登录");
|
|
|
|
|
|
|
+ banned.setBannedReason(bannedReason);
|
|
|
banned.setBannedType(BannedTypeEnum.CHANNEL.getCode());
|
|
banned.setBannedType(BannedTypeEnum.CHANNEL.getCode());
|
|
|
banned.setBannedTime(new Date());
|
|
banned.setBannedTime(new Date());
|
|
|
banned.setOperator(curUser.getUserId());
|
|
banned.setOperator(curUser.getUserId());
|