mirror of
https://gitee.com/youlaitech/youlai-mall.git
synced 2025-01-03 09:32:21 +08:00
fix: 用户列表查询问题修复
This commit is contained in:
parent
b46e788ce1
commit
e584768467
@ -105,6 +105,11 @@
|
|||||||
<artifactId>common-apidoc</artifactId>
|
<artifactId>common-apidoc</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.youlai</groupId>
|
||||||
|
<artifactId>common-sms</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- 单元测试 -->
|
<!-- 单元测试 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
@ -6,10 +6,10 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 密码编码器
|
* 密码编码器(修改、重置密码使用)
|
||||||
*
|
*
|
||||||
* @author haoxr
|
* @author haoxr
|
||||||
* @since 2022/10/21
|
* @since 0.0.1
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
public class PasswordEncoderConfig {
|
public class PasswordEncoderConfig {
|
||||||
|
@ -126,8 +126,8 @@ public class SysUserController {
|
|||||||
public Result<UserAuthInfo> getUserAuthInfo(
|
public Result<UserAuthInfo> getUserAuthInfo(
|
||||||
@Parameter(description = "用户名") @PathVariable String username
|
@Parameter(description = "用户名") @PathVariable String username
|
||||||
) {
|
) {
|
||||||
UserAuthInfo userAUthInfo = userService.getUserAuthInfo(username);
|
UserAuthInfo userAuthInfo = userService.getUserAuthInfo(username);
|
||||||
return Result.success(userAUthInfo);
|
return Result.success(userAuthInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "获取登录用户信息")
|
@Operation(summary = "获取登录用户信息")
|
||||||
@ -192,19 +192,10 @@ public class SysUserController {
|
|||||||
|
|
||||||
@Operation(summary = "发送注册短信验证码")
|
@Operation(summary = "发送注册短信验证码")
|
||||||
@PostMapping("/register/sms_code")
|
@PostMapping("/register/sms_code")
|
||||||
public Result sendRegisterSmsCode(
|
public Result sendRegistrationSmsCode(
|
||||||
@Parameter(description = "手机号") @RequestParam String mobile
|
@Parameter(description = "手机号") @RequestParam String mobile
|
||||||
) {
|
) {
|
||||||
boolean result = userService.sendRegisterSmsCode(mobile);
|
boolean result = userService.sendRegistrationSmsCode(mobile);
|
||||||
return Result.judge(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Operation(summary = "发送登录短信验证码")
|
|
||||||
@PostMapping("/login/sms_code")
|
|
||||||
public Result sendLoginSmsCode(
|
|
||||||
@Parameter(description = "手机号") @RequestParam String mobile
|
|
||||||
) {
|
|
||||||
boolean result = userService.sendLoginSmsCode(mobile);
|
|
||||||
return Result.judge(result);
|
return Result.judge(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,4 +206,5 @@ public class SysUserController {
|
|||||||
return Result.success(userProfile);
|
return Result.success(userProfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -124,15 +124,7 @@ public interface SysUserService extends IService<SysUser> {
|
|||||||
* @param mobile 手机号
|
* @param mobile 手机号
|
||||||
* @return {@link Boolean} 是否发送成功
|
* @return {@link Boolean} 是否发送成功
|
||||||
*/
|
*/
|
||||||
boolean sendRegisterSmsCode(String mobile);
|
boolean sendRegistrationSmsCode(String mobile);
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送登录短信验证码
|
|
||||||
*
|
|
||||||
* @param mobile 手机号
|
|
||||||
* @return {@link Boolean} 是否发送成功
|
|
||||||
*/
|
|
||||||
boolean sendLoginSmsCode(String mobile);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,7 +15,8 @@ import com.youlai.common.constant.RedisConstants;
|
|||||||
import com.youlai.common.constant.SystemConstants;
|
import com.youlai.common.constant.SystemConstants;
|
||||||
import com.youlai.common.security.service.PermissionService;
|
import com.youlai.common.security.service.PermissionService;
|
||||||
import com.youlai.common.security.util.SecurityUtils;
|
import com.youlai.common.security.util.SecurityUtils;
|
||||||
import com.youlai.system.config.AliyunSmsProperties;
|
import com.youlai.common.sms.property.AliyunSmsProperties;
|
||||||
|
import com.youlai.common.sms.service.SmsService;
|
||||||
import com.youlai.system.converter.UserConverter;
|
import com.youlai.system.converter.UserConverter;
|
||||||
import com.youlai.system.dto.UserAuthInfo;
|
import com.youlai.system.dto.UserAuthInfo;
|
||||||
import com.youlai.system.mapper.SysUserMapper;
|
import com.youlai.system.mapper.SysUserMapper;
|
||||||
@ -30,13 +31,13 @@ import com.youlai.system.model.vo.UserExportVO;
|
|||||||
import com.youlai.system.model.vo.UserInfoVO;
|
import com.youlai.system.model.vo.UserInfoVO;
|
||||||
import com.youlai.system.model.vo.UserPageVO;
|
import com.youlai.system.model.vo.UserPageVO;
|
||||||
import com.youlai.system.model.vo.UserProfileVO;
|
import com.youlai.system.model.vo.UserProfileVO;
|
||||||
import com.youlai.system.service.SmsService;
|
|
||||||
import com.youlai.system.service.SysRoleService;
|
import com.youlai.system.service.SysRoleService;
|
||||||
import com.youlai.system.service.SysUserRoleService;
|
import com.youlai.system.service.SysUserRoleService;
|
||||||
import com.youlai.system.service.SysUserService;
|
import com.youlai.system.service.SysUserService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@ -70,7 +71,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||||||
|
|
||||||
private final AliyunSmsProperties aliyunSmsProperties;
|
private final AliyunSmsProperties aliyunSmsProperties;
|
||||||
|
|
||||||
private final RedisTemplate<String, Object> redisTemplate;
|
private final StringRedisTemplate redisTemplate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户分页列表
|
* 获取用户分页列表
|
||||||
@ -283,7 +284,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!expireTimeOpt.isPresent()) {
|
if (expireTimeOpt.isEmpty()) {
|
||||||
// token 永不过期则永久加入黑名单
|
// token 永不过期则永久加入黑名单
|
||||||
redisTemplate.opsForValue().set(RedisConstants.TOKEN_BLACKLIST_PREFIX + jti, "");
|
redisTemplate.opsForValue().set(RedisConstants.TOKEN_BLACKLIST_PREFIX + jti, "");
|
||||||
}
|
}
|
||||||
@ -303,7 +304,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||||||
String mobile = userRegisterForm.getMobile();
|
String mobile = userRegisterForm.getMobile();
|
||||||
String code = userRegisterForm.getCode();
|
String code = userRegisterForm.getCode();
|
||||||
// 校验验证码
|
// 校验验证码
|
||||||
String cacheCode = (String) redisTemplate.opsForValue().get(RedisConstants.REGISTER_SMS_CODE_PREFIX + mobile);
|
String cacheCode = redisTemplate.opsForValue().get(RedisConstants.REGISTER_SMS_CODE_PREFIX + mobile);
|
||||||
if (!StrUtil.equals(code, cacheCode)) {
|
if (!StrUtil.equals(code, cacheCode)) {
|
||||||
log.warn("验证码不匹配或不存在: {}", mobile);
|
log.warn("验证码不匹配或不存在: {}", mobile);
|
||||||
return false; // 验证码不匹配或不存在时返回false
|
return false; // 验证码不匹配或不存在时返回false
|
||||||
@ -339,7 +340,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||||||
* @return true|false 是否发送成功
|
* @return true|false 是否发送成功
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean sendRegisterSmsCode(String mobile) {
|
public boolean sendRegistrationSmsCode(String mobile) {
|
||||||
// 获取短信模板代码
|
// 获取短信模板代码
|
||||||
String templateCode = aliyunSmsProperties.getTemplateCodes().get("register");
|
String templateCode = aliyunSmsProperties.getTemplateCodes().get("register");
|
||||||
|
|
||||||
@ -360,33 +361,6 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送登录短信验证码
|
|
||||||
*
|
|
||||||
* @param mobile 手机号
|
|
||||||
* @return true|false 是否发送成功
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean sendLoginSmsCode(String mobile) {
|
|
||||||
// 获取短信模板代码
|
|
||||||
String templateCode = aliyunSmsProperties.getTemplateCodes().get("login");
|
|
||||||
|
|
||||||
// 生成随机4位数验证码
|
|
||||||
String code = RandomUtil.randomNumbers(4);
|
|
||||||
|
|
||||||
// 短信模板: 您的验证码:${code},该验证码5分钟内有效,请勿泄漏于他人。
|
|
||||||
// 其中 ${code} 是模板参数,使用时需要替换为实际值。
|
|
||||||
String templateParams = JSONUtil.toJsonStr(Collections.singletonMap("code", code));
|
|
||||||
|
|
||||||
boolean result = smsService.sendSms(mobile, templateCode, templateParams);
|
|
||||||
if (result) {
|
|
||||||
// 将验证码存入redis,有效期5分钟
|
|
||||||
redisTemplate.opsForValue().set(RedisConstants.REGISTER_SMS_CODE_PREFIX + mobile, code, 5, TimeUnit.MINUTES);
|
|
||||||
|
|
||||||
// TODO 考虑记录每次发送短信的详情,如发送时间、手机号和短信内容等,以便后续审核或分析短信发送效果。
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户个人中心信息
|
* 获取用户个人中心信息
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
LEFT JOIN sys_user_role sur ON u.id = sur.user_id
|
LEFT JOIN sys_user_role sur ON u.id = sur.user_id
|
||||||
LEFT JOIN sys_role r ON sur.role_id = r.id
|
LEFT JOIN sys_role r ON sur.role_id = r.id
|
||||||
<where>
|
<where>
|
||||||
u.deleted = 0 AND u.username != ${@com.youlai.common.constant.SystemConstants@ROOT_ROLE_CODE}
|
u.deleted = 0 AND u.username != '${@com.youlai.common.constant.SystemConstants@ROOT_ROLE_CODE}'
|
||||||
<if test='queryParams.keywords!=null and queryParams.keywords.trim() neq ""'>
|
<if test='queryParams.keywords!=null and queryParams.keywords.trim() neq ""'>
|
||||||
AND (
|
AND (
|
||||||
u.username LIKE CONCAT('%',#{queryParams.keywords},'%')
|
u.username LIKE CONCAT('%',#{queryParams.keywords},'%')
|
||||||
@ -74,17 +74,21 @@
|
|||||||
dept_id
|
dept_id
|
||||||
FROM
|
FROM
|
||||||
sys_user
|
sys_user
|
||||||
WHERE id = #{userId}
|
WHERE
|
||||||
AND deleted = 0
|
id = #{userId} AND deleted = 0
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<!-- 用户认证信息映射 -->
|
<!-- 用户认证信息映射 -->
|
||||||
<resultMap id="UserAuthMap" type="com.youlai.system.dto.UserAuthInfo">
|
<resultMap id="UserAuthMap" type="com.youlai.system.dto.UserAuthInfo">
|
||||||
<id property="userId" column="userId" jdbcType="BIGINT"/>
|
<id property="userId" column="id" jdbcType="BIGINT"/>
|
||||||
<result property="username" column="username" jdbcType="VARCHAR"/>
|
<result property="username" column="username"/>
|
||||||
<result property="password" column="password" jdbcType="VARCHAR"/>
|
<result property="password" column="PASSWORD"/>
|
||||||
<result property="status" column="status" jdbcType="BOOLEAN"/>
|
<result property="status" column="STATUS"/>
|
||||||
<result property="deptId" column="dept_id" jdbcType="BIGINT"/>
|
<result property="deptId" column="dept_id"/>
|
||||||
|
<result property="nickname" column="nickname"/>
|
||||||
|
<result property="mobile" column="mobile"/>
|
||||||
|
<result property="email" column="email"/>
|
||||||
|
<result property="avatar" column="avatar"/>
|
||||||
<collection property="roles" ofType="string" javaType="java.util.Set">
|
<collection property="roles" ofType="string" javaType="java.util.Set">
|
||||||
<result column="code"/>
|
<result column="code"/>
|
||||||
</collection>
|
</collection>
|
||||||
@ -93,13 +97,16 @@
|
|||||||
<!-- 根据用户名获取认证信息 -->
|
<!-- 根据用户名获取认证信息 -->
|
||||||
<select id="getUserAuthInfo" resultMap="UserAuthMap">
|
<select id="getUserAuthInfo" resultMap="UserAuthMap">
|
||||||
SELECT
|
SELECT
|
||||||
t1.id userId,
|
t1.id,
|
||||||
t1.username,
|
t1.username,
|
||||||
t1.nickname,
|
t1.nickname,
|
||||||
t1.PASSWORD,
|
t1.PASSWORD,
|
||||||
t1.STATUS,
|
t1.STATUS,
|
||||||
t1.dept_id ,
|
t1.dept_id,
|
||||||
t3.CODE
|
t3.CODE,
|
||||||
|
t1.avatar,
|
||||||
|
t1.mobile,
|
||||||
|
t1.email
|
||||||
FROM
|
FROM
|
||||||
sys_user t1
|
sys_user t1
|
||||||
LEFT JOIN sys_user_role t2 ON t2.user_id = t1.id
|
LEFT JOIN sys_user_role t2 ON t2.user_id = t1.id
|
||||||
|
Loading…
Reference in New Issue
Block a user