From 294e2a328e6507e34f2e6a4ece1f58f37d8cd34a Mon Sep 17 00:00:00 2001 From: zccbbg Date: Fri, 12 Jul 2024 14:54:14 +0800 Subject: [PATCH] =?UTF-8?q?update:=20userMapper=20sql=20=E7=AE=80=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/system/mapper/SysUserMapper.java | 31 --------- .../ruoyi/system/service/SysLoginService.java | 26 +++---- .../ruoyi/system/service/SysUserService.java | 4 +- .../resources/mapper/system/SysUserMapper.xml | 68 ------------------- 4 files changed, 11 insertions(+), 118 deletions(-) diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java index 4f7726a..59ce990 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysUserMapper.java @@ -62,37 +62,6 @@ public interface SysUserMapper extends BaseMapperPlus { }) Page selectUnallocatedList(@Param("page") Page page, @Param(Constants.WRAPPER) Wrapper queryWrapper); - /** - * 通过用户名查询用户 - * - * @param userName 用户名 - * @return 用户对象信息 - */ - SysUserVo selectUserByUserName(String userName); - - /** - * 通过手机号查询用户 - * - * @param phonenumber 手机号 - * @return 用户对象信息 - */ - SysUserVo selectUserByPhonenumber(String phonenumber); - - /** - * 通过邮箱查询用户 - * - * @param email 邮箱 - * @return 用户对象信息 - */ - SysUserVo selectUserByEmail(String email); - - /** - * 通过用户ID查询用户 - * - * @param userId 用户ID - * @return 用户对象信息 - */ - SysUserVo selectUserById(Long userId); Long countUserById(Long userId); diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/SysLoginService.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/SysLoginService.java index 2919ea3..10c3bbc 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/SysLoginService.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/SysLoginService.java @@ -22,8 +22,6 @@ import com.ruoyi.common.log.event.LogininforEvent; import com.ruoyi.common.redis.utils.RedisUtils; import com.ruoyi.common.satoken.utils.LoginHelper; import com.ruoyi.common.web.config.properties.CaptchaProperties; -import com.ruoyi.system.domain.bo.SysUserBo; -import com.ruoyi.system.domain.entity.SysDept; import com.ruoyi.system.domain.entity.SysUser; import com.ruoyi.system.domain.vo.SysDeptVo; import com.ruoyi.system.domain.vo.SysRoleVo; @@ -125,7 +123,7 @@ public class SysLoginService { String openid = ""; // 框架登录不限制从什么表查询 只要最终构建出 LoginUser 即可 - SysUser user = loadUserByOpenid(openid); + SysUserVo user = loadUserByOpenid(openid); // 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了 XcxLoginUser loginUser = new XcxLoginUser(); @@ -219,9 +217,7 @@ public class SysLoginService { } private SysUserVo loadUserByUsername(String username) { - SysUser user = userMapper.selectOne(new LambdaQueryWrapper() - .select(SysUser::getUserName, SysUser::getStatus) - .eq(SysUser::getUserName, username)); + SysUserVo user = userMapper.selectVoOne(new LambdaQueryWrapper().eq(SysUser::getUserName, username)); if (ObjectUtil.isNull(user)) { log.info("登录用户:{} 不存在.", username); throw new UserException("user.not.exists", username); @@ -229,13 +225,11 @@ public class SysLoginService { log.info("登录用户:{} 已被停用.", username); throw new UserException("user.blocked", username); } - return userMapper.selectUserByUserName(username); + return user; } private SysUserVo loadUserByPhonenumber(String phonenumber) { - SysUser user = userMapper.selectOne(new LambdaQueryWrapper() - .select(SysUser::getPhonenumber, SysUser::getStatus) - .eq(SysUser::getPhonenumber, phonenumber)); + SysUserVo user = userMapper.selectVoOne(new LambdaQueryWrapper().eq(SysUser::getPhonenumber, phonenumber)); if (ObjectUtil.isNull(user)) { log.info("登录用户:{} 不存在.", phonenumber); throw new UserException("user.not.exists", phonenumber); @@ -243,13 +237,11 @@ public class SysLoginService { log.info("登录用户:{} 已被停用.", phonenumber); throw new UserException("user.blocked", phonenumber); } - return userMapper.selectUserByPhonenumber(phonenumber); + return user; } private SysUserVo loadUserByEmail(String email) { - SysUser user = userMapper.selectOne(new LambdaQueryWrapper() - .select(SysUser::getPhonenumber, SysUser::getStatus) - .eq(SysUser::getEmail, email)); + SysUserVo user = userMapper.selectVoOne(new LambdaQueryWrapper().eq(SysUser::getEmail, email)); if (ObjectUtil.isNull(user)) { log.info("登录用户:{} 不存在.", email); throw new UserException("user.not.exists", email); @@ -257,13 +249,13 @@ public class SysLoginService { log.info("登录用户:{} 已被停用.", email); throw new UserException("user.blocked", email); } - return userMapper.selectUserByEmail(email); + return user; } - private SysUser loadUserByOpenid(String openid) { + private SysUserVo loadUserByOpenid(String openid) { // 使用 openid 查询绑定用户 如未绑定用户 则根据业务自行处理 例如 创建默认用户 // todo 自行实现 userService.selectUserByOpenid(openid); - SysUser user = new SysUser(); + SysUserVo user = new SysUserVo(); if (ObjectUtil.isNull(user)) { log.info("登录用户:{} 不存在.", openid); // todo 用户不存在 业务逻辑自行实现 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/SysUserService.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/SysUserService.java index 79493af..4a99f38 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/SysUserService.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/SysUserService.java @@ -132,7 +132,7 @@ public class SysUserService implements UserService { * @return 用户对象信息 */ public SysUserVo selectUserByUserName(String userName) { - return baseMapper.selectUserByUserName(userName); + return baseMapper.selectVoOne(new LambdaQueryWrapper().eq(SysUser::getUserName, userName)); } /** @@ -142,7 +142,7 @@ public class SysUserService implements UserService { * @return 用户对象信息 */ public SysUserVo selectUserByPhonenumber(String phonenumber) { - return baseMapper.selectUserByPhonenumber(phonenumber); + return baseMapper.selectVoOne(new LambdaQueryWrapper().eq(SysUser::getPhonenumber, phonenumber)); } /** diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml index dad3a0c..f696b5d 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysUserMapper.xml @@ -6,61 +6,12 @@ - - - - - - - - - - - - - - select u.user_id, - u.dept_id, - u.user_name, - u.nick_name, - u.user_type, - u.email, - u.avatar, - u.phonenumber, - u.password, - u.sex, - u.status, - u.del_flag, - u.login_ip, - u.login_date, - u.create_by, - u.create_time, - u.remark, - d.dept_id, - d.parent_id, - d.ancestors, - d.dept_name, - d.order_num, - d.leader, - d.status as dept_status, - r.role_id, - r.role_name, - r.role_key, - r.role_sort, - r.data_scope, - r.status as role_status - from sys_user u - left join sys_dept d on u.dept_id = d.dept_id - left join sys_user_role sur on u.user_id = sur.user_id - left join sys_role r on r.role_id = sur.role_id - - - - - - - - -