update 优化 三方登录接口代码逻辑

feature/model
疯狂的狮子Li 1 year ago
parent 9448782f45
commit b7c0e76da2

@ -175,13 +175,15 @@ public class SysLoginService {
return R.fail("对不起,授权信息验证不通过,请退出重试!");
}
AuthUser authUserData = authUser.getData();
SysSocialVo user = sysSocialService.selectByAuthId(authUserData.getSource() + authUserData.getUuid());
if (ObjectUtil.isNotNull(user)) {
SysSocialVo social = sysSocialService.selectByAuthId(authUserData.getSource() + authUserData.getUuid());
if (ObjectUtil.isNotNull(social)) {
SysUser user = userMapper.selectOne(new LambdaQueryWrapper<SysUser>()
.eq(SysUser::getUserId, social.getUserId()));
// 执行登录和记录登录信息操作
return loginAndRecord(user.getTenantId(), user.getUserName(), authUserData);
} else {
// 判断是否已登录
if (LoginHelper.getUserId() == null) {
if (!StpUtil.isLogin()) {
return R.fail("授权失败,请先登录才能绑定");
}
SysSocialBo bo = new SysSocialBo();
@ -211,10 +213,10 @@ public class SysLoginService {
*/
private R<String> loginAndRecord(String tenantId, String userName, AuthUser authUser) {
checkTenant(tenantId);
SysUserVo dbUser = loadUserByUsername(tenantId, userName);
LoginHelper.loginByDevice(buildLoginUser(dbUser), DeviceType.SOCIAL);
recordLogininfor(dbUser.getTenantId(), userName, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"));
recordLoginInfo(dbUser.getUserId());
SysUserVo user = loadUserByUsername(tenantId, userName);
LoginHelper.loginByDevice(buildLoginUser(user), DeviceType.SOCIAL);
recordLogininfor(user.getTenantId(), userName, Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success"));
recordLoginInfo(user.getUserId());
return R.ok(StpUtil.getTokenValue());
}

@ -27,6 +27,11 @@ public class SysSocial extends TenantEntity {
@TableId(value = "id")
private Long id;
/**
* ID
*/
private Long userId;
/**
* ID
*/
@ -57,11 +62,6 @@ public class SysSocial extends TenantEntity {
*/
private String openId;
/**
* ID
*/
private Long userId;
/**
*
*/

@ -29,6 +29,12 @@ public class SysSocialVo implements Serializable {
@ExcelProperty(value = "主键")
private Long id;
/**
* ID
*/
@ExcelProperty(value = "用户ID")
private Long userId;
/**
* ID
*/
@ -70,12 +76,6 @@ public class SysSocialVo implements Serializable {
@ExcelProperty(value = "用户的 open id")
private String openId;
/**
* ID
*/
@ExcelProperty(value = "用户的 ID")
private Long userId;
/**
*
*/

@ -11,12 +11,4 @@ import org.dromara.system.domain.vo.SysSocialVo;
*/
public interface SysSocialMapper extends BaseMapperPlus<SysSocial, SysSocialVo> {
/**
* authId SysSocial SysUser SysSocialAuthResult
*
* @param authId ID
* @return SysSocial
*/
SysSocialVo selectByAuthId(String authId);
}

@ -86,12 +86,12 @@ public class SysSocialServiceImpl implements ISysSocialService {
/**
* authId
*
* @param authId id
* @return
* @param authId id
* @return
*/
@Override
public SysSocialVo selectByAuthId(String authId) {
return baseMapper.selectByAuthId(authId);
return baseMapper.selectVoOne(new LambdaQueryWrapper<SysSocial>().eq(SysSocial::getAuthId, authId));
}
}

@ -4,20 +4,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.dromara.system.mapper.SysSocialMapper">
<resultMap type="org.dromara.system.domain.vo.SysSocialVo" id="SysSocialAuthResult">
<id property="id" column="id"/>
</resultMap>
<select id="selectByAuthId" parameterType="String" resultMap="SysSocialAuthResult">
select b.user_id,
b.tenant_id,
b.user_name,
b.password,
a.auth_id,
a.source
from sys_social a
left join sys_user b on a.user_id = b.user_id
where a.auth_id = #{authId}
</select>
</mapper>

Loading…
Cancel
Save