|
|
@@ -12,6 +12,7 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import com.ytpm.advertise.enums.AdSourceTypeEnum;
|
|
|
@@ -27,6 +28,8 @@ import com.ytpm.app.enums.LoginType;
|
|
|
import com.ytpm.app.model.YtDyzAdRecord;
|
|
|
import com.ytpm.app.model.YtDyzLoginRecord;
|
|
|
import com.ytpm.app.model.YtDyzUser;
|
|
|
+import com.ytpm.app.param.LoginRiskYtDyzUserParam;
|
|
|
+import com.ytpm.app.view.RiskYtDyzUserView;
|
|
|
import com.ytpm.custom.CustomField;
|
|
|
import com.ytpm.dao.AppMapper;
|
|
|
import com.ytpm.dao.DictMapper;
|
|
|
@@ -407,15 +410,54 @@ public class RiskServiceImpl implements RiskService {
|
|
|
if(1==view.getEnabled()){
|
|
|
checkDefaultRiskConfig(dyzUser, view.getConfigList());
|
|
|
}
|
|
|
- checkRisk322(dyzUser);
|
|
|
- // 风控
|
|
|
- checkRisk334(dyzUser);
|
|
|
+ // 风控 尝试聚合查询
|
|
|
+ List<YtDyzUser> dyzUsers = null;
|
|
|
+ Integer userCount = null;
|
|
|
+ RiskTemplateView riskTempView334 = configMapper.getByCode(dyzUser.getAppId() + "-334");
|
|
|
+ RiskTemplateView riskTempView322 = configMapper.getByCode("322");
|
|
|
+ if (riskTempView334 != null && riskTempView334.getEnabled() == 1
|
|
|
+ || riskTempView322 != null && riskTempView322.getEnabled() == 1) {
|
|
|
+ YtApp ytApp = appMapper.selectRiskApp(dyzUser.getAppId());
|
|
|
+ YtPlatformUserApp userApp = appMapper.selectParentApp(ytApp.getSuperiorId());
|
|
|
+ if (ytApp.getAppType() == 2) {
|
|
|
+ LoginRiskYtDyzUserParam param = new LoginRiskYtDyzUserParam();
|
|
|
+ param.setIosId(dyzUser.getIosId());
|
|
|
+ param.setAppId(dyzUser.getAppId());
|
|
|
+ if (riskTempView334 != null && riskTempView334.getEnabled() == 1) {
|
|
|
+ param.setLastLoginIp(dyzUser.getLastLoginIp());
|
|
|
+ List<RiskConfigView> configList = riskTempView334.getConfigList();
|
|
|
+ Map<String, String> configMap = configList.stream().collect(
|
|
|
+ Collectors.toMap(RiskConfigView::getFieldName, RiskConfigView::getConfigVal));
|
|
|
+ int limitHour = Integer.parseInt(configMap.get("limitHour"));
|
|
|
+ param.setLimitHour(limitHour);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Object object = feignInvoker.invoke(userApp.getServiceName(), "queryUserByParam", param);
|
|
|
+ if (object != null) {
|
|
|
+ RiskYtDyzUserView riskYtDyzUserView = JSONObject.parseObject(JSON.toJSONString(object), RiskYtDyzUserView.class);
|
|
|
+ dyzUsers = riskYtDyzUserView.getUserList();
|
|
|
+ userCount = riskYtDyzUserView.getUserCount();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn(StringUtils.format("feign调用{}.queryUserByParam失败:{}",
|
|
|
+ userApp.getServiceName(), e.getMessage()), e);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ checkRisk322(dyzUser, dyzUsers);
|
|
|
+ checkRisk334(dyzUser, userCount);
|
|
|
//查询用户所在app是否配置其他风控规则
|
|
|
// checkCustomRisk(dyzUser,EffectNodeEnum.LOGIN.getNode(),null);
|
|
|
return Result.resultOk(RepMessage.QUERY_SUCCESS);
|
|
|
}
|
|
|
|
|
|
- private void checkRisk334(YtDyzUser dyzUser) {
|
|
|
+ private void checkRisk334(YtDyzUser dyzUser, Integer userCount) {
|
|
|
+ // 白名单放行
|
|
|
+ if (checkDyzUserIp(dyzUser)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
RiskTemplateView riskTempView = configMapper.getByCode(dyzUser.getAppId() + "-334");
|
|
|
if (riskTempView == null || riskTempView.getEnabled() != 1) {
|
|
|
return;
|
|
|
@@ -426,10 +468,6 @@ public class RiskServiceImpl implements RiskService {
|
|
|
if (ytApp.getAppType() != 2) {
|
|
|
return;
|
|
|
}
|
|
|
- // 白名单放行
|
|
|
- if (checkDyzUserIp(dyzUser)) {
|
|
|
- return;
|
|
|
- }
|
|
|
// 已通过的用户放行
|
|
|
String passkey = StrUtil.format("riskPass:334:{}:{}", userApp.getAppId(), dyzUser.getLastLoginIp());
|
|
|
if (redisService.hasKey(passkey) && StrUtil.equals(dyzUser.getUserId(), redisService.getStr(passkey))) {
|
|
|
@@ -440,11 +478,14 @@ public class RiskServiceImpl implements RiskService {
|
|
|
Collectors.toMap(RiskConfigView::getFieldName, RiskConfigView::getConfigVal));
|
|
|
int limitCount = Integer.parseInt(configMap.get("limitCount"));
|
|
|
int limitHour = Integer.parseInt(configMap.get("limitHour"));
|
|
|
- int userCount = 0;
|
|
|
- Object object = feignInvoker.invoke(userApp.getServiceName(), "queryCountByIpTime", dyzUser.getAppId(), lastLoginIp, limitHour);
|
|
|
- JSONObject jsonObject = object == null ? null : JSON.parseObject(JSON.toJSONString(object));
|
|
|
- if (jsonObject != null && jsonObject.get("data") != null) {
|
|
|
- userCount = Integer.parseInt(jsonObject.get("data").toString());
|
|
|
+ if (userCount == null) {
|
|
|
+ userCount = 0;
|
|
|
+ Object object = feignInvoker.invoke(userApp.getServiceName(), "queryCountByIpTime",
|
|
|
+ dyzUser.getAppId(), lastLoginIp, limitHour);
|
|
|
+ JSONObject jsonObject = object == null ? null : JSON.parseObject(JSON.toJSONString(object));
|
|
|
+ if (jsonObject != null && jsonObject.get("data") != null) {
|
|
|
+ userCount = Integer.parseInt(jsonObject.get("data").toString());
|
|
|
+ }
|
|
|
}
|
|
|
if (redisService.hasKey(passkey) && limitCount <= userCount) {
|
|
|
log.warn(StrUtil.format("[risk 334] superiorId:{} appId:{} userId:{} limitCount:{}",
|
|
|
@@ -465,23 +506,24 @@ public class RiskServiceImpl implements RiskService {
|
|
|
/**
|
|
|
* 校验风控规则322
|
|
|
*/
|
|
|
- private void checkRisk322(YtDyzUser dyzUser) {
|
|
|
+ private void checkRisk322(YtDyzUser dyzUser, List<YtDyzUser> dyzUsers) {
|
|
|
// ip白名单用户直接放行
|
|
|
if (checkDyzUserIp(dyzUser)) {
|
|
|
return;
|
|
|
}
|
|
|
RiskTemplateView view = configMapper.getByCode("322");
|
|
|
//根据用户所属应用查询该应用母包openid查询用户信息
|
|
|
- YtApp ytApp = appMapper.selectRiskApp(dyzUser.getAppId());
|
|
|
- YtPlatformUserApp userApp = appMapper.selectParentApp(ytApp.getSuperiorId());
|
|
|
- Object o;
|
|
|
- if (dyzUser.getIosId() != null) {
|
|
|
- o = feignInvoker.invoke(userApp.getServiceName(),"queryByIosId",dyzUser.getIosId());
|
|
|
- } else {
|
|
|
- o = feignInvoker.invoke(userApp.getServiceName(),"queryByOpenid",dyzUser.getWxOpenId());
|
|
|
+ if (dyzUsers == null) {
|
|
|
+ YtApp ytApp = appMapper.selectRiskApp(dyzUser.getAppId());
|
|
|
+ YtPlatformUserApp userApp = appMapper.selectParentApp(ytApp.getSuperiorId());
|
|
|
+ Object o;
|
|
|
+ if (dyzUser.getIosId() != null) {
|
|
|
+ o = feignInvoker.invoke(userApp.getServiceName(),"queryByIosId",dyzUser.getIosId());
|
|
|
+ } else {
|
|
|
+ o = feignInvoker.invoke(userApp.getServiceName(),"queryByOpenid",dyzUser.getWxOpenId());
|
|
|
+ }
|
|
|
+ dyzUsers = JSONArray.parseArray(JSON.toJSONString(o), YtDyzUser.class);
|
|
|
}
|
|
|
- List<YtDyzUser> dyzUsers = JSONArray.parseArray(JSON.toJSONString(o), YtDyzUser.class);
|
|
|
-
|
|
|
List<RiskConfigView> configList = view.getConfigList();
|
|
|
Map<String, String> configMap = configList.stream().collect(
|
|
|
Collectors.toMap(RiskConfigView::getFieldName, RiskConfigView::getConfigVal));
|