| | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.lock.annotation.Lock4j; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import me.zhyd.oauth.model.AuthUser; |
| | |
| | | * 绑定第三方用户 |
| | | * |
| | | * @param authUserData 授权响应实体 |
| | | * @return 统一响应实体 |
| | | */ |
| | | @Lock4j |
| | | public void socialRegister(AuthUser authUserData) { |
| | | String authId = authUserData.getSource() + authUserData.getUuid(); |
| | | // 第三方用户信息 |
| | | SysSocialBo bo = BeanUtil.toBean(authUserData, SysSocialBo.class); |
| | | BeanUtil.copyProperties(authUserData.getToken(), bo); |
| | | bo.setUserId(LoginHelper.getUserId()); |
| | | Long userId = LoginHelper.getUserId(); |
| | | bo.setUserId(userId); |
| | | bo.setAuthId(authId); |
| | | bo.setOpenId(authUserData.getUuid()); |
| | | bo.setUserName(authUserData.getUsername()); |
| | | bo.setNickName(authUserData.getNickname()); |
| | | // 查询是否已经绑定用户 |
| | | List<SysSocialVo> list = sysSocialService.selectByAuthId(authId); |
| | | SysSocialBo params = new SysSocialBo(); |
| | | params.setUserId(userId); |
| | | params.setSource(bo.getSource()); |
| | | List<SysSocialVo> list = sysSocialService.queryList(params); |
| | | if (CollUtil.isEmpty(list)) { |
| | | // 没有绑定用户, 新增用户信息 |
| | | sysSocialService.insertByBo(bo); |
| | |
| | | // 更新用户信息 |
| | | bo.setId(list.get(0).getId()); |
| | | sysSocialService.updateByBo(bo); |
| | | // 如果要绑定的平台账号已经被绑定过了 是否抛异常自行决断 |
| | | // throw new ServiceException("此平台账号已经被绑定!"); |
| | | } |
| | | } |
| | | |