|
@@ -22,11 +22,13 @@ import com.ytpm.handle.CustomerException;
|
|
|
import com.ytpm.app.model.YtDyzLoginRecord;
|
|
import com.ytpm.app.model.YtDyzLoginRecord;
|
|
|
import com.ytpm.app.model.YtDyzPowerRecord;
|
|
import com.ytpm.app.model.YtDyzPowerRecord;
|
|
|
import com.ytpm.app.model.YtDyzUser;
|
|
import com.ytpm.app.model.YtDyzUser;
|
|
|
|
|
+import com.ytpm.service.AppUserService;
|
|
|
import com.ytpm.util.RedisService;
|
|
import com.ytpm.util.RedisService;
|
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
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.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
@@ -47,20 +49,16 @@ import java.util.Objects;
|
|
|
@RequestMapping("/wx")
|
|
@RequestMapping("/wx")
|
|
|
public class WxController {
|
|
public class WxController {
|
|
|
private final static String GRANT_TYPE = "authorization_code";
|
|
private final static String GRANT_TYPE = "authorization_code";
|
|
|
- @Resource
|
|
|
|
|
- private RedisService redisService;
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private AppUserMapper appUserMapper;
|
|
private AppUserMapper appUserMapper;
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- private LoginRecordMapper loginRecordMapper;
|
|
|
|
|
- @Autowired
|
|
|
|
|
- private QuestionMapper questionMapper;
|
|
|
|
|
- @Autowired
|
|
|
|
|
private RiskFeign riskFeign;
|
|
private RiskFeign riskFeign;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private AppUserService appUserService;
|
|
|
|
|
|
|
|
@PostMapping("/login")
|
|
@PostMapping("/login")
|
|
|
@ApiOperation("微信登录")
|
|
@ApiOperation("微信登录")
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
|
|
+ @Transactional
|
|
|
public Result<YtDyzUser> wxLogin(@RequestBody WxLoginParam param) {
|
|
public Result<YtDyzUser> wxLogin(@RequestBody WxLoginParam param) {
|
|
|
//根据应用获取配置调用微信接口登录
|
|
//根据应用获取配置调用微信接口登录
|
|
|
WxDefaultConfig defaultConfig = appUserMapper.getDefaultConfig(param.getAppType());
|
|
WxDefaultConfig defaultConfig = appUserMapper.getDefaultConfig(param.getAppType());
|
|
@@ -76,43 +74,16 @@ public class WxController {
|
|
|
if(Objects.isNull(wxUserInfo)) {
|
|
if(Objects.isNull(wxUserInfo)) {
|
|
|
throw new CustomerException("微信用户登录失败");
|
|
throw new CustomerException("微信用户登录失败");
|
|
|
}
|
|
}
|
|
|
- //处理用户注册或登录更新信息
|
|
|
|
|
- YtDyzUser old = appUserMapper.getYtAppUser(loginResult.getOpenid(), param.getDitchId());
|
|
|
|
|
- if(Objects.isNull(old)) {
|
|
|
|
|
- old = new YtDyzUser();
|
|
|
|
|
- registryUser(param,wxUserInfo,loginResult, old);
|
|
|
|
|
- }else{
|
|
|
|
|
- deadWithUserCrud(old,wxUserInfo,param);
|
|
|
|
|
- }
|
|
|
|
|
- //设置最后一次答题问题ID、今日答题数、历史答题数
|
|
|
|
|
- setExtInfo(old,wxUserInfo.getHeadimgurl());
|
|
|
|
|
|
|
+ YtDyzUser old = appUserService.crudForNewTrans(param,wxUserInfo,loginResult);
|
|
|
//调用风控服务校验默认风控配置
|
|
//调用风控服务校验默认风控配置
|
|
|
old.setRiskCode("313");
|
|
old.setRiskCode("313");
|
|
|
Result<?> result = riskFeign.checkRisk(old);
|
|
Result<?> result = riskFeign.checkRisk(old);
|
|
|
if(result.getCode()!=200){
|
|
if(result.getCode()!=200){
|
|
|
throw new CustomerException(result.getMessage());
|
|
throw new CustomerException(result.getMessage());
|
|
|
}
|
|
}
|
|
|
- // 添加用户登录记录
|
|
|
|
|
- addLoginRecord(param,old.getUserId());
|
|
|
|
|
return Result.resultOk(RepMessage.LOGIN_SUCCESS, old);
|
|
return Result.resultOk(RepMessage.LOGIN_SUCCESS, old);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 处理用户数据
|
|
|
|
|
- */
|
|
|
|
|
- private void deadWithUserCrud(YtDyzUser old, WxUserInfo wxUserInfo, WxLoginParam param) {
|
|
|
|
|
- //处于风控状态的用户不允许登录
|
|
|
|
|
- if(!old.getUserStatus().equals(UserStatusEnum.NORMAL.getCode())){
|
|
|
|
|
- throw new CustomerException("当前用户处于"+UserStatusEnum.getByCode(old.getUserStatus())+"中,无法登录");
|
|
|
|
|
- }
|
|
|
|
|
- YtDyzUser newUser = new YtDyzUser();
|
|
|
|
|
- newUser.setNickName(wxUserInfo.getNickname());
|
|
|
|
|
- newUser.setHeadImg(wxUserInfo.getHeadimgurl());
|
|
|
|
|
- newUser.setLastLoginTime(new Date());
|
|
|
|
|
- newUser.setLastLoginIp(param.getLoginIp());
|
|
|
|
|
- newUser.setLoginDays(old.getLoginDays()+1);
|
|
|
|
|
- appUserMapper.updateUser(newUser);
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取微信用户信息
|
|
* 获取微信用户信息
|
|
@@ -146,62 +117,6 @@ public class WxController {
|
|
|
return loginResult;
|
|
return loginResult;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 设置扩展信息
|
|
|
|
|
- */
|
|
|
|
|
- private void setExtInfo(YtDyzUser old, String headimgurl) {
|
|
|
|
|
- old.setHeadImg(headimgurl);
|
|
|
|
|
- old.setLastQuestionId(questionMapper.getLastQuestionId(old.getUserId()));
|
|
|
|
|
- old.setTodayAnswerCount(questionMapper.getAnswerCount(old.getUserId(),1));
|
|
|
|
|
- old.setHistoryAnswerCount(questionMapper.getAnswerCount(old.getUserId(),2));
|
|
|
|
|
- old.setAnswerRecordList(questionMapper.getAnswerRecords(old.getUserId()));
|
|
|
|
|
- old.setLoginRecordList(loginRecordMapper.getLoginRecords(old.getUserId()));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 增加用户登录记录
|
|
|
|
|
- */
|
|
|
|
|
- private void addLoginRecord(WxLoginParam param,String userId) {
|
|
|
|
|
- YtDyzLoginRecord loginRecord = new YtDyzLoginRecord();
|
|
|
|
|
- loginRecord.setRecordId(IdUtil.fastSimpleUUID());
|
|
|
|
|
- loginRecord.setUserId(userId);
|
|
|
|
|
- loginRecord.setLoginTime(new Date());
|
|
|
|
|
- loginRecord.setDeviceBrand(param.getBrand());
|
|
|
|
|
- loginRecord.setDeviceModel(param.getModel());
|
|
|
|
|
- loginRecord.setLoginIp(param.getLoginIp());
|
|
|
|
|
- loginRecord.setOperator(param.getIpOperator());
|
|
|
|
|
- loginRecord.setIpAddr(param.getLoginIp());
|
|
|
|
|
- loginRecordMapper.insertOne(loginRecord);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 注册用户
|
|
|
|
|
- */
|
|
|
|
|
- private void registryUser(WxLoginParam param,WxUserInfo wxUserInfo,WxLoginResult loginResult, YtDyzUser old) {
|
|
|
|
|
- old.setUserId(redisService.getAppUserId());
|
|
|
|
|
- old.setNickName(wxUserInfo.getNickname());
|
|
|
|
|
- old.setLastLoginTime(new Date());
|
|
|
|
|
- old.setRegistryTime(new Date());
|
|
|
|
|
- old.setLastLoginIp(param.getLoginIp());
|
|
|
|
|
- old.setLoginDays(1);
|
|
|
|
|
- old.setPower(0);
|
|
|
|
|
- old.setTotalVideo(0);
|
|
|
|
|
- old.setTotalIncome(BigDecimal.ZERO);
|
|
|
|
|
- old.setRedPacketAmount(BigDecimal.ZERO);
|
|
|
|
|
- old.setRedPacketBalance(BigDecimal.ZERO);
|
|
|
|
|
- old.setPointsBalance(BigDecimal.ZERO);
|
|
|
|
|
- old.setPointsTotal(BigDecimal.ZERO);
|
|
|
|
|
- old.setWithdrawTotal(BigDecimal.ZERO);
|
|
|
|
|
- old.setDitchId(param.getDitchId());
|
|
|
|
|
- old.setSignDays(0);
|
|
|
|
|
- old.setAppId(param.getAppId());
|
|
|
|
|
- old.setUserStatus(UserStatusEnum.NORMAL.getCode());
|
|
|
|
|
- old.setWxOpenId(loginResult.getOpenid());
|
|
|
|
|
- old.setHeadImg(wxUserInfo.getHeadimgurl());
|
|
|
|
|
- old.setPlatformId(StrConstant.PLATFORM_ID_PREFIX + IdUtil.getSnowflakeNextIdStr());
|
|
|
|
|
- appUserMapper.addOne(old);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
@ApiOperation("获取微信默认配置项")
|
|
@ApiOperation("获取微信默认配置项")
|
|
|
@GetMapping("/defaultConfig")
|
|
@GetMapping("/defaultConfig")
|
|
|
public Result<String> getWxDefaultConfig(int appType) {
|
|
public Result<String> getWxDefaultConfig(int appType) {
|