mirror of
https://github.com/zccbbg/wms-ruoyi.git
synced 2024-11-10 09:02:51 +08:00
update: userMapper sql 简化
This commit is contained in:
parent
11201848ec
commit
294e2a328e
4 changed files with 11 additions and 118 deletions
|
@ -62,37 +62,6 @@ public interface SysUserMapper extends BaseMapperPlus<SysUser, SysUserVo> {
|
|||
})
|
||||
Page<SysUserVo> selectUnallocatedList(@Param("page") Page<SysUser> page, @Param(Constants.WRAPPER) Wrapper<SysUser> 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);
|
||||
|
||||
|
|
|
@ -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<SysUser>()
|
||||
.select(SysUser::getUserName, SysUser::getStatus)
|
||||
.eq(SysUser::getUserName, username));
|
||||
SysUserVo user = userMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().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<SysUser>()
|
||||
.select(SysUser::getPhonenumber, SysUser::getStatus)
|
||||
.eq(SysUser::getPhonenumber, phonenumber));
|
||||
SysUserVo user = userMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().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<SysUser>()
|
||||
.select(SysUser::getPhonenumber, SysUser::getStatus)
|
||||
.eq(SysUser::getEmail, email));
|
||||
SysUserVo user = userMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().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 用户不存在 业务逻辑自行实现
|
||||
|
|
|
@ -132,7 +132,7 @@ public class SysUserService implements UserService {
|
|||
* @return 用户对象信息
|
||||
*/
|
||||
public SysUserVo selectUserByUserName(String userName) {
|
||||
return baseMapper.selectUserByUserName(userName);
|
||||
return baseMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().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<SysUser>().eq(SysUser::getPhonenumber, phonenumber));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,61 +6,12 @@
|
|||
|
||||
<resultMap type="com.ruoyi.system.domain.vo.SysUserVo" id="SysUserResult">
|
||||
<id property="userId" column="user_id"/>
|
||||
<collection property="roles" javaType="java.util.List" resultMap="RoleResult"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap type="com.ruoyi.system.domain.vo.SysUserExportVo" id="SysUserExportResult">
|
||||
<id property="userId" column="user_id"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="deptResult" type="com.ruoyi.system.domain.entity.SysDept">
|
||||
<id property="deptId" column="dept_id"/>
|
||||
<id property="email" column="dept_email"/>
|
||||
<id property="status" column="dept_status"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="RoleResult" type="com.ruoyi.system.domain.vo.SysRoleVo">
|
||||
<id property="roleId" column="role_id"/>
|
||||
<id property="status" column="role_status"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectUserVo">
|
||||
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
|
||||
</sql>
|
||||
|
||||
<select id="selectPageUserList" resultMap="SysUserResult">
|
||||
select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex,
|
||||
u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark
|
||||
|
@ -93,25 +44,6 @@
|
|||
${ew.getCustomSqlSegment}
|
||||
</select>
|
||||
|
||||
<select id="selectUserByUserName" parameterType="String" resultMap="SysUserResult">
|
||||
<include refid="selectUserVo"/>
|
||||
where u.del_flag = '0' and u.user_name = #{userName}
|
||||
</select>
|
||||
|
||||
<select id="selectUserByPhonenumber" parameterType="String" resultMap="SysUserResult">
|
||||
<include refid="selectUserVo"/>
|
||||
where u.del_flag = '0' and u.phonenumber = #{phonenumber}
|
||||
</select>
|
||||
|
||||
<select id="selectUserByEmail" parameterType="String" resultMap="SysUserResult">
|
||||
<include refid="selectUserVo"/>
|
||||
where u.del_flag = '0' and u.email = #{email}
|
||||
</select>
|
||||
|
||||
<select id="selectUserById" parameterType="Long" resultMap="SysUserResult">
|
||||
<include refid="selectUserVo"/>
|
||||
where u.del_flag = '0' and u.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<select id="countUserById" resultType="Long">
|
||||
select count(*) from sys_user where del_flag = '0' and user_id = #{userId}
|
||||
|
|
Loading…
Reference in a new issue