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>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.youlai</groupId>
|
||||
<artifactId>common-sms</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 单元测试 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
@ -6,10 +6,10 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
/**
|
||||
* 密码编码器
|
||||
* 密码编码器(修改、重置密码使用)
|
||||
*
|
||||
* @author haoxr
|
||||
* @since 2022/10/21
|
||||
* @since 0.0.1
|
||||
*/
|
||||
@Configuration
|
||||
public class PasswordEncoderConfig {
|
||||
|
@ -126,8 +126,8 @@ public class SysUserController {
|
||||
public Result<UserAuthInfo> getUserAuthInfo(
|
||||
@Parameter(description = "用户名") @PathVariable String username
|
||||
) {
|
||||
UserAuthInfo userAUthInfo = userService.getUserAuthInfo(username);
|
||||
return Result.success(userAUthInfo);
|
||||
UserAuthInfo userAuthInfo = userService.getUserAuthInfo(username);
|
||||
return Result.success(userAuthInfo);
|
||||
}
|
||||
|
||||
@Operation(summary = "获取登录用户信息")
|
||||
@ -192,19 +192,10 @@ public class SysUserController {
|
||||
|
||||
@Operation(summary = "发送注册短信验证码")
|
||||
@PostMapping("/register/sms_code")
|
||||
public Result sendRegisterSmsCode(
|
||||
public Result sendRegistrationSmsCode(
|
||||
@Parameter(description = "手机号") @RequestParam String mobile
|
||||
) {
|
||||
boolean result = userService.sendRegisterSmsCode(mobile);
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@Operation(summary = "发送登录短信验证码")
|
||||
@PostMapping("/login/sms_code")
|
||||
public Result sendLoginSmsCode(
|
||||
@Parameter(description = "手机号") @RequestParam String mobile
|
||||
) {
|
||||
boolean result = userService.sendLoginSmsCode(mobile);
|
||||
boolean result = userService.sendRegistrationSmsCode(mobile);
|
||||
return Result.judge(result);
|
||||
}
|
||||
|
||||
@ -215,4 +206,5 @@ public class SysUserController {
|
||||
return Result.success(userProfile);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -124,15 +124,7 @@ public interface SysUserService extends IService<SysUser> {
|
||||
* @param mobile 手机号
|
||||
* @return {@link Boolean} 是否发送成功
|
||||
*/
|
||||
boolean sendRegisterSmsCode(String mobile);
|
||||
|
||||
/**
|
||||
* 发送登录短信验证码
|
||||
*
|
||||
* @param mobile 手机号
|
||||
* @return {@link Boolean} 是否发送成功
|
||||
*/
|
||||
boolean sendLoginSmsCode(String mobile);
|
||||
boolean sendRegistrationSmsCode(String mobile);
|
||||
|
||||
|
||||
/**
|
||||
|
@ -15,7 +15,8 @@ import com.youlai.common.constant.RedisConstants;
|
||||
import com.youlai.common.constant.SystemConstants;
|
||||
import com.youlai.common.security.service.PermissionService;
|
||||
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.dto.UserAuthInfo;
|
||||
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.UserPageVO;
|
||||
import com.youlai.system.model.vo.UserProfileVO;
|
||||
import com.youlai.system.service.SmsService;
|
||||
import com.youlai.system.service.SysRoleService;
|
||||
import com.youlai.system.service.SysUserRoleService;
|
||||
import com.youlai.system.service.SysUserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -70,7 +71,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
|
||||
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 永不过期则永久加入黑名单
|
||||
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 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)) {
|
||||
log.warn("验证码不匹配或不存在: {}", mobile);
|
||||
return false; // 验证码不匹配或不存在时返回false
|
||||
@ -339,7 +340,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
* @return true|false 是否发送成功
|
||||
*/
|
||||
@Override
|
||||
public boolean sendRegisterSmsCode(String mobile) {
|
||||
public boolean sendRegistrationSmsCode(String mobile) {
|
||||
// 获取短信模板代码
|
||||
String templateCode = aliyunSmsProperties.getTemplateCodes().get("register");
|
||||
|
||||
@ -360,33 +361,6 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
||||
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_role r ON sur.role_id = r.id
|
||||
<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 ""'>
|
||||
AND (
|
||||
u.username LIKE CONCAT('%',#{queryParams.keywords},'%')
|
||||
@ -74,17 +74,21 @@
|
||||
dept_id
|
||||
FROM
|
||||
sys_user
|
||||
WHERE id = #{userId}
|
||||
AND deleted = 0
|
||||
WHERE
|
||||
id = #{userId} AND deleted = 0
|
||||
</select>
|
||||
|
||||
<!-- 用户认证信息映射 -->
|
||||
<resultMap id="UserAuthMap" type="com.youlai.system.dto.UserAuthInfo">
|
||||
<id property="userId" column="userId" jdbcType="BIGINT"/>
|
||||
<result property="username" column="username" jdbcType="VARCHAR"/>
|
||||
<result property="password" column="password" jdbcType="VARCHAR"/>
|
||||
<result property="status" column="status" jdbcType="BOOLEAN"/>
|
||||
<result property="deptId" column="dept_id" jdbcType="BIGINT"/>
|
||||
<id property="userId" column="id" jdbcType="BIGINT"/>
|
||||
<result property="username" column="username"/>
|
||||
<result property="password" column="PASSWORD"/>
|
||||
<result property="status" column="STATUS"/>
|
||||
<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">
|
||||
<result column="code"/>
|
||||
</collection>
|
||||
@ -93,13 +97,16 @@
|
||||
<!-- 根据用户名获取认证信息 -->
|
||||
<select id="getUserAuthInfo" resultMap="UserAuthMap">
|
||||
SELECT
|
||||
t1.id userId,
|
||||
t1.id,
|
||||
t1.username,
|
||||
t1.nickname,
|
||||
t1.PASSWORD,
|
||||
t1.STATUS,
|
||||
t1.dept_id,
|
||||
t3.CODE
|
||||
t3.CODE,
|
||||
t1.avatar,
|
||||
t1.mobile,
|
||||
t1.email
|
||||
FROM
|
||||
sys_user t1
|
||||
LEFT JOIN sys_user_role t2 ON t2.user_id = t1.id
|
||||
|
Loading…
Reference in New Issue
Block a user