|
@@ -1,5 +1,6 @@
|
|
|
package com.ytpm.adage.controller;
|
|
package com.ytpm.adage.controller;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
@@ -23,9 +24,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
@@ -61,30 +64,55 @@ public class VisitorController {
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Result<YtDyzUser> visitorLogin(@RequestBody WxLoginParam param, HttpServletRequest request) {
|
|
public Result<YtDyzUser> visitorLogin(@RequestBody WxLoginParam param, HttpServletRequest request) {
|
|
|
param.setLoginIp(getClientIp(request));
|
|
param.setLoginIp(getClientIp(request));
|
|
|
- YtDyzUser old = appUserMapper.getByDeviceAndDitch(param.getDeviceId(),param.getDitchId());
|
|
|
|
|
- //当前设备在该渠道未曾注册
|
|
|
|
|
- if(Objects.isNull(old)){
|
|
|
|
|
|
|
+ //获取该设备最后一次注册的用户信息
|
|
|
|
|
+ YtDyzUser registryUser = appUserMapper.getLastRegistryUser(param.getDeviceId());
|
|
|
|
|
+ //该设备未注册过用户
|
|
|
|
|
+ YtDyzUser old;
|
|
|
|
|
+ if(Objects.isNull(registryUser)) {
|
|
|
old = new YtDyzUser();
|
|
old = new YtDyzUser();
|
|
|
registerUser(param, old);
|
|
registerUser(param, old);
|
|
|
}else{
|
|
}else{
|
|
|
- //当前设备已注册该渠道
|
|
|
|
|
- if(!old.getUserStatus().equals(UserStatusEnum.NORMAL.getCode())){
|
|
|
|
|
- return new Result<>(StatusCode.ACCESS_ERR,getTipsMsg());
|
|
|
|
|
|
|
+ //查询当前设备当前渠道是否存在该用户
|
|
|
|
|
+ old = appUserMapper.getByDeviceAndDitch(param.getDeviceId(), param.getDitchId());
|
|
|
|
|
+ //不存在则说明该渠道为新注册用户,需要风控校验注册是否在规则允许范围内
|
|
|
|
|
+ if(Objects.isNull(old)) {
|
|
|
|
|
+ Result<?> result = riskFeign.checkRegRisk(registryUser);
|
|
|
|
|
+ if(result.getCode()!=200){
|
|
|
|
|
+ return new Result<>(StatusCode.ACCESS_ERR,result.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ old = new YtDyzUser();
|
|
|
|
|
+ registerUser(param, old);
|
|
|
|
|
+ }else{//当前渠道已有用户,校验用户是否处于风控中 & 更新用户信息
|
|
|
|
|
+ if(!old.getUserStatus().equals(UserStatusEnum.NORMAL.getCode())){
|
|
|
|
|
+ return new Result<>(StatusCode.ACCESS_ERR,getTipsMsg());
|
|
|
|
|
+ }
|
|
|
|
|
+ deadWithUserCrud(old,param);
|
|
|
}
|
|
}
|
|
|
- deadWithUserCrud(old,param);
|
|
|
|
|
}
|
|
}
|
|
|
//设置最后一次答题问题ID、今日答题数、历史答题数
|
|
//设置最后一次答题问题ID、今日答题数、历史答题数
|
|
|
setExtInfo(old);
|
|
setExtInfo(old);
|
|
|
- // 添加用户登录记录
|
|
|
|
|
- addLoginRecord(param,old.getUserId());
|
|
|
|
|
- //校验游客风控
|
|
|
|
|
|
|
+ //校验指定时间内登录的渠道数
|
|
|
Result<?> result = riskFeign.checkLoginRisk(old);
|
|
Result<?> result = riskFeign.checkLoginRisk(old);
|
|
|
if(result.getCode()!=200){
|
|
if(result.getCode()!=200){
|
|
|
- return new Result<>(StatusCode.ACCESS_ERR,result.getMessage());
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 添加用户登录记录
|
|
|
|
|
+ addLoginRecord(param,old.getUserId());
|
|
|
|
|
+ return new Result<>(StatusCode.ACCESS_ERR,result.getMessage());
|
|
|
|
|
+ }
|
|
|
return Result.resultObjOk(old);
|
|
return Result.resultObjOk(old);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @ApiOperation("设备在指定时间内注册的渠道")
|
|
|
|
|
+ @GetMapping("/getDitchCount")
|
|
|
|
|
+ public int getDitchCount(@RequestParam("deviceId")String deviceId,@RequestParam("hours")Integer hours) {
|
|
|
|
|
+ return appUserMapper.countDitch(deviceId,hours);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @ApiOperation("设备在指定时间内注册的渠道")
|
|
|
|
|
+ @GetMapping("/getLoginDitchCount")
|
|
|
|
|
+ public int getLoginDitchCount(@RequestParam("deviceId")String deviceId,@RequestParam("hours")Integer hours) {
|
|
|
|
|
+ return appUserMapper.countLoginDitch(deviceId,hours);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 注册用户
|
|
* 注册用户
|
|
|
*/
|
|
*/
|
|
@@ -109,6 +137,9 @@ public class VisitorController {
|
|
|
old.setSignDays(0);
|
|
old.setSignDays(0);
|
|
|
old.setAppId(param.getAppId());
|
|
old.setAppId(param.getAppId());
|
|
|
old.setUserStatus(UserStatusEnum.NORMAL.getCode());
|
|
old.setUserStatus(UserStatusEnum.NORMAL.getCode());
|
|
|
|
|
+ String platformId = appUserMapper.getPlatformByDeviceId(param.getDeviceId());
|
|
|
|
|
+ old.setPlatformId(StrUtil.isBlank(platformId)?
|
|
|
|
|
+ (StrConstant.PLATFORM_ID_PREFIX + IdUtil.getSnowflakeNextIdStr()):platformId);
|
|
|
appUserMapper.addOne(old);
|
|
appUserMapper.addOne(old);
|
|
|
return old;
|
|
return old;
|
|
|
}
|
|
}
|