update 优化 SysLoginService#socialRegister 判断是否已经绑定用户 ;

fix 修正 SysSocialServiceImpl#selectByAuthId 重复数据报错问题 ;
feature/model
zlyx 1 year ago
parent 359ec45b05
commit c92c99c8da

@ -26,6 +26,7 @@ import org.dromara.common.tenant.exception.TenantException;
import org.dromara.common.tenant.helper.TenantHelper; import org.dromara.common.tenant.helper.TenantHelper;
import org.dromara.system.domain.SysUser; import org.dromara.system.domain.SysUser;
import org.dromara.system.domain.bo.SysSocialBo; import org.dromara.system.domain.bo.SysSocialBo;
import org.dromara.system.domain.vo.SysSocialVo;
import org.dromara.system.domain.vo.SysTenantVo; import org.dromara.system.domain.vo.SysTenantVo;
import org.dromara.system.domain.vo.SysUserVo; import org.dromara.system.domain.vo.SysUserVo;
import org.dromara.system.mapper.SysUserMapper; import org.dromara.system.mapper.SysUserMapper;
@ -69,14 +70,20 @@ public class SysLoginService {
* @return * @return
*/ */
public void socialRegister(AuthUser authUserData) { public void socialRegister(AuthUser authUserData) {
SysSocialBo bo = BeanUtil.toBean(authUserData, SysSocialBo.class); String authId = authUserData.getSource() + authUserData.getUuid();
BeanUtil.copyProperties(authUserData.getToken(), bo); // 查询是否已经绑定用户
bo.setUserId(LoginHelper.getUserId()); SysSocialVo vo = sysSocialService.selectByAuthId(authId);
bo.setAuthId(authUserData.getSource() + authUserData.getUuid()); if (ObjectUtil.isEmpty(vo)) {
bo.setOpenId(authUserData.getUuid()); // 没有绑定用户, 新增用户信息
bo.setUserName(authUserData.getUsername()); SysSocialBo bo = BeanUtil.toBean(authUserData, SysSocialBo.class);
bo.setNickName(authUserData.getNickname()); BeanUtil.copyProperties(authUserData.getToken(), bo);
sysSocialService.insertByBo(bo); bo.setUserId(LoginHelper.getUserId());
bo.setAuthId(authId);
bo.setOpenId(authUserData.getUuid());
bo.setUserName(authUserData.getUsername());
bo.setNickName(authUserData.getNickname());
sysSocialService.insertByBo(bo);
}
} }

@ -3,6 +3,7 @@ package org.dromara.system.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.mybatis.core.domain.BaseEntity;
import org.dromara.system.domain.SysSocial; import org.dromara.system.domain.SysSocial;
import org.dromara.system.domain.bo.SysSocialBo; import org.dromara.system.domain.bo.SysSocialBo;
import org.dromara.system.domain.vo.SysSocialVo; import org.dromara.system.domain.vo.SysSocialVo;
@ -91,7 +92,11 @@ public class SysSocialServiceImpl implements ISysSocialService {
*/ */
@Override @Override
public SysSocialVo selectByAuthId(String authId) { public SysSocialVo selectByAuthId(String authId) {
return baseMapper.selectVoOne(new LambdaQueryWrapper<SysSocial>().eq(SysSocial::getAuthId, authId)); return baseMapper.selectVoOne(
new LambdaQueryWrapper<SysSocial>()
.eq(SysSocial::getAuthId, authId)
.orderByDesc(BaseEntity::getCreateTime)
.last("limit 1"));
} }
} }

Loading…
Cancel
Save