From c92c99c8da92fd9d7dc4af9534419d0679fcc207 Mon Sep 17 00:00:00 2001 From: zlyx <1242874891@qq.com> Date: Wed, 2 Aug 2023 14:21:12 +0800 Subject: [PATCH 1/2] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20SysLoginServi?= =?UTF-8?q?ce#socialRegister=20=E5=88=A4=E6=96=AD=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E5=B7=B2=E7=BB=8F=E7=BB=91=E5=AE=9A=E7=94=A8=E6=88=B7=20;=20fi?= =?UTF-8?q?x=20=E4=BF=AE=E6=AD=A3=20SysSocialServiceImpl#selectByAuthId=20?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E6=95=B0=E6=8D=AE=E6=8A=A5=E9=94=99=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dromara/web/service/SysLoginService.java | 23 ++++++++++++------- .../service/impl/SysSocialServiceImpl.java | 7 +++++- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/ruoyi-admin/src/main/java/org/dromara/web/service/SysLoginService.java b/ruoyi-admin/src/main/java/org/dromara/web/service/SysLoginService.java index c2392d38..ba5840ab 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/service/SysLoginService.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/service/SysLoginService.java @@ -26,6 +26,7 @@ import org.dromara.common.tenant.exception.TenantException; import org.dromara.common.tenant.helper.TenantHelper; import org.dromara.system.domain.SysUser; 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.SysUserVo; import org.dromara.system.mapper.SysUserMapper; @@ -69,14 +70,20 @@ public class SysLoginService { * @return 统一响应实体 */ public void socialRegister(AuthUser authUserData) { - SysSocialBo bo = BeanUtil.toBean(authUserData, SysSocialBo.class); - BeanUtil.copyProperties(authUserData.getToken(), bo); - bo.setUserId(LoginHelper.getUserId()); - bo.setAuthId(authUserData.getSource() + authUserData.getUuid()); - bo.setOpenId(authUserData.getUuid()); - bo.setUserName(authUserData.getUsername()); - bo.setNickName(authUserData.getNickname()); - sysSocialService.insertByBo(bo); + String authId = authUserData.getSource() + authUserData.getUuid(); + // 查询是否已经绑定用户 + SysSocialVo vo = sysSocialService.selectByAuthId(authId); + if (ObjectUtil.isEmpty(vo)) { + // 没有绑定用户, 新增用户信息 + SysSocialBo bo = BeanUtil.toBean(authUserData, SysSocialBo.class); + BeanUtil.copyProperties(authUserData.getToken(), bo); + bo.setUserId(LoginHelper.getUserId()); + bo.setAuthId(authId); + bo.setOpenId(authUserData.getUuid()); + bo.setUserName(authUserData.getUsername()); + bo.setNickName(authUserData.getNickname()); + sysSocialService.insertByBo(bo); + } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysSocialServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysSocialServiceImpl.java index 065dea0d..14ad9340 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysSocialServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysSocialServiceImpl.java @@ -3,6 +3,7 @@ package org.dromara.system.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import lombok.RequiredArgsConstructor; 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.bo.SysSocialBo; import org.dromara.system.domain.vo.SysSocialVo; @@ -91,7 +92,11 @@ public class SysSocialServiceImpl implements ISysSocialService { */ @Override public SysSocialVo selectByAuthId(String authId) { - return baseMapper.selectVoOne(new LambdaQueryWrapper().eq(SysSocial::getAuthId, authId)); + return baseMapper.selectVoOne( + new LambdaQueryWrapper() + .eq(SysSocial::getAuthId, authId) + .orderByDesc(BaseEntity::getCreateTime) + .last("limit 1")); } } From bbe672208fa862b3a01473336e5711b679279293 Mon Sep 17 00:00:00 2001 From: zlyx <1242874891@qq.com> Date: Wed, 2 Aug 2023 14:51:23 +0800 Subject: [PATCH 2/2] =?UTF-8?q?add=20=E6=96=B0=E5=A2=9E=20SysSocialService?= =?UTF-8?q?Impl#updateByBo=20=E6=9B=B4=E6=96=B0=E7=A4=BE=E4=BC=9A=E5=8C=96?= =?UTF-8?q?=E5=85=B3=E7=B3=BB=20;=20update=20=E4=BC=98=E5=8C=96=20SysLogin?= =?UTF-8?q?Service#socialRegister=20=E5=AF=B9=E5=B7=B2=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=BF=9B=E8=A1=8C=E6=9B=B4=E6=96=B0=20;=20re?= =?UTF-8?q?set=20=E5=9B=9E=E6=BB=9A=E4=B8=8A=E4=B8=80=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E4=B8=AD=20SysSocialServiceImpl#selectByAuthId=20=E4=BC=9A?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E5=A4=9A=E7=A7=8D=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E4=B8=8D=E5=85=BC=E5=AE=B9=20;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dromara/web/service/SysLoginService.java | 19 ++++++++++++------- .../system/service/ISysSocialService.java | 4 ++++ .../service/impl/SysSocialServiceImpl.java | 16 ++++++++++------ 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/ruoyi-admin/src/main/java/org/dromara/web/service/SysLoginService.java b/ruoyi-admin/src/main/java/org/dromara/web/service/SysLoginService.java index ba5840ab..ad8a41e3 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/service/SysLoginService.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/service/SysLoginService.java @@ -71,18 +71,23 @@ public class SysLoginService { */ 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()); + bo.setAuthId(authId); + bo.setOpenId(authUserData.getUuid()); + bo.setUserName(authUserData.getUsername()); + bo.setNickName(authUserData.getNickname()); // 查询是否已经绑定用户 SysSocialVo vo = sysSocialService.selectByAuthId(authId); if (ObjectUtil.isEmpty(vo)) { // 没有绑定用户, 新增用户信息 - SysSocialBo bo = BeanUtil.toBean(authUserData, SysSocialBo.class); - BeanUtil.copyProperties(authUserData.getToken(), bo); - bo.setUserId(LoginHelper.getUserId()); - bo.setAuthId(authId); - bo.setOpenId(authUserData.getUuid()); - bo.setUserName(authUserData.getUsername()); - bo.setNickName(authUserData.getNickname()); sysSocialService.insertByBo(bo); + } else { + // 更新用户信息 + bo.setId(vo.getId()); + sysSocialService.updateByBo(bo); } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysSocialService.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysSocialService.java index 9c8275ef..5f2014d9 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysSocialService.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysSocialService.java @@ -33,6 +33,10 @@ public interface ISysSocialService { */ Boolean insertByBo(SysSocialBo bo); + /** + * 更新社会化关系 + */ + Boolean updateByBo(SysSocialBo bo); /** * 删除社会化关系信息 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysSocialServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysSocialServiceImpl.java index 14ad9340..bd7248f3 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysSocialServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysSocialServiceImpl.java @@ -3,7 +3,6 @@ package org.dromara.system.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import lombok.RequiredArgsConstructor; 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.bo.SysSocialBo; import org.dromara.system.domain.vo.SysSocialVo; @@ -66,6 +65,15 @@ public class SysSocialServiceImpl implements ISysSocialService { return flag; } + /** + * 更新社会化关系 + */ + @Override + public Boolean updateByBo(SysSocialBo bo) { + SysSocial update = MapstructUtils.convert(bo, SysSocial.class); + validEntityBeforeSave(update); + return baseMapper.updateById(update) > 0; + } /** * 保存前的数据校验 @@ -92,11 +100,7 @@ public class SysSocialServiceImpl implements ISysSocialService { */ @Override public SysSocialVo selectByAuthId(String authId) { - return baseMapper.selectVoOne( - new LambdaQueryWrapper() - .eq(SysSocial::getAuthId, authId) - .orderByDesc(BaseEntity::getCreateTime) - .last("limit 1")); + return baseMapper.selectVoOne(new LambdaQueryWrapper().eq(SysSocial::getAuthId, authId)); } }