|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public JsonResult openId(String code) { |
|
|
public JsonResult openId(String code) { |
|
|
if (StringUtils.isEmpty(code)) { |
|
|
if (StringUtils.isEmpty(code)) { |
|
|
|
|
|
log.info("code为空"); |
|
|
return JsonResult.error("code为空"); |
|
|
return JsonResult.error("code为空"); |
|
|
} |
|
|
} |
|
|
String userId = CurrentUserUtil.getUserId(); |
|
|
String userId = CurrentUserUtil.getUserId(); |
|
|
|
|
|
|
|
|
//根据当前登录用户id查询授权表是否存在一条授权数据 |
|
|
//根据当前登录用户id查询授权表是否存在一条授权数据 |
|
|
UserAuthorize beforeUserAuthorize = userAuthorizeMapper.selectOne(Wrappers.<UserAuthorize>lambdaQuery() |
|
|
UserAuthorize beforeUserAuthorize = userAuthorizeMapper.selectOne(Wrappers.<UserAuthorize>lambdaQuery() |
|
|
.eq(UserAuthorize::getUserId, userId) |
|
|
.eq(UserAuthorize::getUserId, userId) |
|
|
.eq(UserAuthorize::getOpenId, code) |
|
|
|
|
|
|
|
|
.eq(UserAuthorize::getOpenId, openid) |
|
|
.eq(UserAuthorize::getMark, MarkEnum.VALID.getCode())); |
|
|
.eq(UserAuthorize::getMark, MarkEnum.VALID.getCode())); |
|
|
if (ObjectUtil.isEmpty(beforeUserAuthorize)) { |
|
|
|
|
|
UserAuthorize userAuthorize = new UserAuthorize(); |
|
|
|
|
|
userAuthorize.setOpenId(openid); |
|
|
|
|
|
userAuthorize.setUserId(userId); |
|
|
|
|
|
userAuthorize.setCreateTime(DateUtils.now()); |
|
|
|
|
|
userAuthorize.setCreateUser(userId); |
|
|
|
|
|
int result = userAuthorizeMapper.insert(userAuthorize); |
|
|
|
|
|
if (result <= 0) { |
|
|
|
|
|
return JsonResult.error("授权数据入库失败"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (ObjectUtil.isNotEmpty(beforeUserAuthorize)) { |
|
|
|
|
|
log.info("该用户已做过授权, openid={}", openid); |
|
|
|
|
|
return JsonResult.error("该用户已做过授权"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
UserAuthorize userAuthorize = new UserAuthorize(); |
|
|
|
|
|
userAuthorize.setOpenId(openid); |
|
|
|
|
|
userAuthorize.setUserId(userId); |
|
|
|
|
|
userAuthorize.setCreateTime(DateUtils.now()); |
|
|
|
|
|
userAuthorize.setCreateUser(userId); |
|
|
|
|
|
int result = userAuthorizeMapper.insert(userAuthorize); |
|
|
|
|
|
if (result <= 0) { |
|
|
|
|
|
return JsonResult.error("授权数据入库失败"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//关联登录用户,已经做过授权 修改授权标识 |
|
|
//关联登录用户,已经做过授权 修改授权标识 |
|
|
User user = CurrentUserUtil.getUserInfo(); |
|
|
User user = CurrentUserUtil.getUserInfo(); |
|
|
if (ObjectUtil.isEmpty(user)) { |
|
|
if (ObjectUtil.isEmpty(user)) { |
|
|
|
|
|
|
|
|
user.setUpdateUser(userId); |
|
|
user.setUpdateUser(userId); |
|
|
int count = userMapper.updateById(user); |
|
|
int count = userMapper.updateById(user); |
|
|
if (count <= 0) { |
|
|
if (count <= 0) { |
|
|
|
|
|
log.info("用户授权标识更新失败, userId={}", userId); |
|
|
return JsonResult.error("用户授权标识更新失败"); |
|
|
return JsonResult.error("用户授权标识更新失败"); |
|
|
} |
|
|
} |
|
|
return JsonResult.success(); |
|
|
return JsonResult.success(); |