用户修改

This commit is contained in:
2025-12-09 17:01:34 +08:00
parent 5d8d1dd320
commit e242ff172c
14 changed files with 67 additions and 56 deletions

View File

@@ -65,7 +65,7 @@ public interface SysUserService {
* @author yslg * @author yslg
* @since 2025-11-05 * @since 2025-11-05
*/ */
ResultDomain<TbSysUserDTO> getLoginUser(TbSysUserDTO filter); ResultDomain<SysUserVO> getLoginUser(SysUserVO filter);
/** /**
* @description 根据条件查询用户列表 * @description 根据条件查询用户列表

View File

@@ -37,6 +37,9 @@ public class SysUserVO extends BaseVO {
@Schema(description = "手机") @Schema(description = "手机")
private String phone; private String phone;
@Schema(description = "手机号哈希码")
private String phoneHash;
@Schema(description = "微信ID") @Schema(description = "微信ID")
private String wechatId; private String wechatId;

View File

@@ -1,5 +1,6 @@
package org.xyzh.auth.strategy; package org.xyzh.auth.strategy;
import org.xyzh.api.system.vo.SysUserVO;
import org.xyzh.common.core.domain.LoginParam; import org.xyzh.common.core.domain.LoginParam;
import org.xyzh.common.dto.sys.TbSysUserDTO; import org.xyzh.common.dto.sys.TbSysUserDTO;
@@ -36,7 +37,7 @@ public interface LoginStrategy {
* @author yslg * @author yslg
* @since 2025-12-05 * @since 2025-12-05
*/ */
TbSysUserDTO findUser(LoginParam loginParam); SysUserVO findUser(LoginParam loginParam);
/** /**
* @description 验证凭据(密码或验证码) * @description 验证凭据(密码或验证码)

View File

@@ -42,10 +42,10 @@ public class EmailLoginStrategy implements LoginStrategy {
} }
@Override @Override
public TbSysUserDTO findUser(LoginParam loginParam) { public SysUserVO findUser(LoginParam loginParam) {
TbSysUserDTO filter = new TbSysUserDTO(); SysUserVO filter = new SysUserVO();
filter.setEmail(loginParam.getEmail()); filter.setEmail(loginParam.getEmail());
TbSysUserDTO user = userService.getLoginUser(filter).getData(); SysUserVO user = userService.getLoginUser(filter).getData();
if(user == null) { if(user == null) {
return null; return null;
} }

View File

@@ -10,6 +10,7 @@ import org.xyzh.common.utils.NonUtils;
import org.xyzh.common.utils.validation.method.EmailValidateMethod; import org.xyzh.common.utils.validation.method.EmailValidateMethod;
import org.xyzh.common.utils.validation.method.PhoneValidateMethod; import org.xyzh.common.utils.validation.method.PhoneValidateMethod;
import org.xyzh.api.system.service.SysUserService; import org.xyzh.api.system.service.SysUserService;
import org.xyzh.api.system.vo.SysUserVO;
import java.util.List; import java.util.List;
@@ -53,8 +54,8 @@ public class PasswordLoginStrategy implements LoginStrategy {
} }
@Override @Override
public TbSysUserDTO findUser(LoginParam loginParam) { public SysUserVO findUser(LoginParam loginParam) {
TbSysUserDTO filter = new TbSysUserDTO(); SysUserVO filter = new SysUserVO();
EmailValidateMethod emailValidateMethod = new EmailValidateMethod(); EmailValidateMethod emailValidateMethod = new EmailValidateMethod();
PhoneValidateMethod phoneValidateMethod = new PhoneValidateMethod(); PhoneValidateMethod phoneValidateMethod = new PhoneValidateMethod();
if(emailValidateMethod.validate(loginParam.getUsername())){ if(emailValidateMethod.validate(loginParam.getUsername())){
@@ -66,7 +67,7 @@ public class PasswordLoginStrategy implements LoginStrategy {
} }
// 【优化】删除无用的密码编码SQL查询不使用password字段 // 【优化】删除无用的密码编码SQL查询不使用password字段
// 密码验证在 verifyCredential() 方法中进行 // 密码验证在 verifyCredential() 方法中进行
TbSysUserDTO user = userService.getLoginUser(filter).getData(); SysUserVO user = userService.getLoginUser(filter).getData();
if(user == null) { if(user == null) {
return null; return null;
} }

View File

@@ -7,6 +7,7 @@ import org.xyzh.auth.strategy.LoginStrategy;
import org.xyzh.common.core.domain.LoginParam; import org.xyzh.common.core.domain.LoginParam;
import org.xyzh.common.dto.sys.TbSysUserDTO; import org.xyzh.common.dto.sys.TbSysUserDTO;
import org.xyzh.api.system.service.SysUserService; import org.xyzh.api.system.service.SysUserService;
import org.xyzh.api.system.vo.SysUserVO;
import org.xyzh.common.redis.service.RedisService; import org.xyzh.common.redis.service.RedisService;
/** /**
@@ -41,10 +42,10 @@ public class PhoneLoginStrategy implements LoginStrategy {
} }
@Override @Override
public TbSysUserDTO findUser(LoginParam loginParam) { public SysUserVO findUser(LoginParam loginParam) {
TbSysUserDTO filter = new TbSysUserDTO(); SysUserVO filter = new SysUserVO();
filter.setPhone(loginParam.getPhone()); filter.setPhone(loginParam.getPhone());
TbSysUserDTO user = userService.getLoginUser(filter).getData(); SysUserVO user = userService.getLoginUser(filter).getData();
if(user == null) { if(user == null) {
return null; return null;
} }

View File

@@ -7,6 +7,7 @@ import org.xyzh.auth.strategy.LoginStrategy;
import org.xyzh.common.core.domain.LoginParam; import org.xyzh.common.core.domain.LoginParam;
import org.xyzh.common.dto.sys.TbSysUserDTO; import org.xyzh.common.dto.sys.TbSysUserDTO;
import org.xyzh.api.system.service.SysUserService; import org.xyzh.api.system.service.SysUserService;
import org.xyzh.api.system.vo.SysUserVO;
/** /**
* @description UsernameLoginStrategy.java文件描述 用户名登录策略 * @description UsernameLoginStrategy.java文件描述 用户名登录策略
@@ -36,10 +37,10 @@ public class UsernameLoginStrategy implements LoginStrategy {
} }
@Override @Override
public TbSysUserDTO findUser(LoginParam loginParam) { public SysUserVO findUser(LoginParam loginParam) {
TbSysUserDTO filter = new TbSysUserDTO(); SysUserVO filter = new SysUserVO();
filter.setUsername(loginParam.getUsername()); filter.setUsername(loginParam.getUsername());
TbSysUserDTO user = userService.getLoginUser(filter).getData(); SysUserVO user = userService.getLoginUser(filter).getData();
if(user == null) { if(user == null) {
return null; return null;
} }

View File

@@ -6,6 +6,7 @@ import org.xyzh.auth.strategy.LoginStrategy;
import org.xyzh.common.core.domain.LoginParam; import org.xyzh.common.core.domain.LoginParam;
import org.xyzh.common.dto.sys.TbSysUserDTO; import org.xyzh.common.dto.sys.TbSysUserDTO;
import org.xyzh.api.system.service.SysUserService; import org.xyzh.api.system.service.SysUserService;
import org.xyzh.api.system.vo.SysUserVO;
/** /**
* @description WechatLoginStrategy.java文件描述 微信登录策略 * @description WechatLoginStrategy.java文件描述 微信登录策略
@@ -32,10 +33,10 @@ public class WechatLoginStrategy implements LoginStrategy {
} }
@Override @Override
public TbSysUserDTO findUser(LoginParam loginParam) { public SysUserVO findUser(LoginParam loginParam) {
TbSysUserDTO filter = new TbSysUserDTO(); SysUserVO filter = new SysUserVO();
filter.setWechatId(loginParam.getWechatId()); filter.setWechatId(loginParam.getWechatId());
TbSysUserDTO user = userService.getLoginUser(filter).getData(); SysUserVO user = userService.getLoginUser(filter).getData();
if(user == null) { if(user == null) {
return null; return null;
} }

View File

@@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.xyzh.common.core.domain.LoginDomain; import org.xyzh.common.core.domain.LoginDomain;
import org.xyzh.common.dto.sys.TbSysUserDTO; import org.xyzh.common.dto.sys.TbSysUserDTO;
import org.xyzh.common.dto.sys.TbSysUserInfoDTO;
import org.xyzh.common.utils.IDUtils; import org.xyzh.common.utils.IDUtils;
import javax.crypto.SecretKey; import javax.crypto.SecretKey;
@@ -43,9 +44,10 @@ public class JwtTokenUtil {
public String generateToken(LoginDomain loginDomain) { public String generateToken(LoginDomain loginDomain) {
Map<String, Object> claims = new HashMap<>(); Map<String, Object> claims = new HashMap<>();
TbSysUserDTO user = loginDomain.getUser(); TbSysUserDTO user = loginDomain.getUser();
TbSysUserInfoDTO userInfoDTO = loginDomain.getUserInfo();
claims.put("userId", user.getUserId()); claims.put("userId", user.getUserId());
claims.put("username", user.getUsername()); claims.put("username", userInfoDTO.getUsername());
claims.put("email", user.getEmail()); claims.put("email", user.getEmail());
claims.put("loginType", loginDomain.getLoginType()); claims.put("loginType", loginDomain.getLoginType());
claims.put("ipAddress", loginDomain.getIpAddress()); claims.put("ipAddress", loginDomain.getIpAddress());

View File

@@ -33,7 +33,7 @@ public class TbSysUserDTO extends BaseDTO {
private String phone; private String phone;
@Schema(description = "手机号哈希") @Schema(description = "手机号哈希")
private String phone_hash; private String phoneHash;
@Schema(description = "微信ID") @Schema(description = "微信ID")
private String wechatId; private String wechatId;

View File

@@ -64,7 +64,7 @@ public interface TbSysUserMapper extends BaseMapper<TbSysUserDTO> {
* @author yslg * @author yslg
* @since 2025-11-07 * @since 2025-11-07
*/ */
List<SysUserVO> getUserByFilter(@Param("filter") TbSysUserDTO filter); List<SysUserVO> getUserByFilter(@Param("filter") SysUserVO filter);
/** /**
* @description 根据条件查询系统用户分页列表 * @description 根据条件查询系统用户分页列表

View File

@@ -68,7 +68,7 @@ public class SysUserServiceImpl implements SysUserService {
public ResultDomain<TbSysUserDTO> registerUser(SysUserVO userVO) { public ResultDomain<TbSysUserDTO> registerUser(SysUserVO userVO) {
try { try {
logger.info("开始注册用户:{}", userVO.getUsername()); logger.info("开始注册用户:{}", userVO.getUsername());
userVO.setPhone(aesEncryptUtil.decrypt(userVO.getPhone()));
// 检查用户是否已存在 // 检查用户是否已存在
if (checkUserExists(userVO)) { if (checkUserExists(userVO)) {
return ResultDomain.failure("用户已存在"); return ResultDomain.failure("用户已存在");
@@ -82,18 +82,20 @@ public class SysUserServiceImpl implements SysUserService {
if (StringUtils.isBlank(dto.getUserId())) { if (StringUtils.isBlank(dto.getUserId())) {
dto.setUserId(IDUtils.generateID()); dto.setUserId(IDUtils.generateID());
} }
dto.setPhone(aesEncryptUtil.encrypt(userVO.getPhone()));
dto.setPhoneHash(AesEncryptUtil.maskPhone(userVO.getPhone()));
dto.setCreateTime(now); dto.setCreateTime(now);
dto.setDeleted(false); dto.setDeleted(false);
// 加密密码 // 加密密码
if (StringUtils.isNotBlank(dto.getPassword())) { if (StringUtils.isNotBlank(dto.getPassword())) {
dto.setPassword(passwordEncoder.encode(dto.getPassword())); dto.setPassword(passwordEncoder.encode(aesEncryptUtil.decrypt(dto.getPassword())));
} }
// 插入用户主表 // 插入用户主表
int rows = userMapper.insertUser(dto); int rows = userMapper.insertUser(dto);
if (rows <= 0) { if (rows <= 0) {
logger.warn("插入用户失败, username={}", dto.getUsername()); logger.warn("插入用户失败, userVO:", userVO.toString());
return ResultDomain.failure("插入用户失败"); return ResultDomain.failure("插入用户失败");
} }
@@ -111,7 +113,6 @@ public class SysUserServiceImpl implements SysUserService {
userRole.setCreateTime(now); userRole.setCreateTime(now);
userRoleMapper.insertUserRole(userRole); userRoleMapper.insertUserRole(userRole);
logger.info("注册用户成功, userId={}, username={}", dto.getUserId(), dto.getUsername());
return ResultDomain.success("注册用户成功", dto); return ResultDomain.success("注册用户成功", dto);
} catch (Exception e) { } catch (Exception e) {
@@ -126,7 +127,7 @@ public class SysUserServiceImpl implements SysUserService {
* @return true-存在false-不存在 * @return true-存在false-不存在
*/ */
private boolean checkUserExists(SysUserVO userVO) { private boolean checkUserExists(SysUserVO userVO) {
TbSysUserDTO filter = new TbSysUserDTO(); SysUserVO filter = new SysUserVO();
// 检查用户名是否存在 // 检查用户名是否存在
if (StringUtils.isNotBlank(userVO.getUsername())) { if (StringUtils.isNotBlank(userVO.getUsername())) {
@@ -140,8 +141,9 @@ public class SysUserServiceImpl implements SysUserService {
// 检查手机号是否存在 // 检查手机号是否存在
if (StringUtils.isNotBlank(userVO.getPhone())) { if (StringUtils.isNotBlank(userVO.getPhone())) {
filter = new TbSysUserDTO(); filter = new SysUserVO();
filter.setPhone(userVO.getPhone()); filter.setPhone(aesEncryptUtil.encrypt(userVO.getPhone()));
filter.setPhoneHash(AesEncryptUtil.maskPhone(userVO.getPhone()));
List<SysUserVO> users = userMapper.getUserByFilter(filter); List<SysUserVO> users = userMapper.getUserByFilter(filter);
if (users != null && !users.isEmpty()) { if (users != null && !users.isEmpty()) {
logger.warn("手机号已存在: {}", userVO.getPhone()); logger.warn("手机号已存在: {}", userVO.getPhone());
@@ -151,7 +153,7 @@ public class SysUserServiceImpl implements SysUserService {
// 检查邮箱是否存在 // 检查邮箱是否存在
if (StringUtils.isNotBlank(userVO.getEmail())) { if (StringUtils.isNotBlank(userVO.getEmail())) {
filter = new TbSysUserDTO(); filter = new SysUserVO();
filter.setEmail(userVO.getEmail()); filter.setEmail(userVO.getEmail());
List<SysUserVO> users = userMapper.getUserByFilter(filter); List<SysUserVO> users = userMapper.getUserByFilter(filter);
if (users != null && !users.isEmpty()) { if (users != null && !users.isEmpty()) {
@@ -168,18 +170,11 @@ public class SysUserServiceImpl implements SysUserService {
if (userVO == null) { if (userVO == null) {
return ResultDomain.failure(MSG_USER_PARAM_REQUIRED); return ResultDomain.failure(MSG_USER_PARAM_REQUIRED);
} }
TbSysUserDTO dto = SysUserVO.toDTO(userVO);
if (StringUtils.isBlank(dto.getUserId())) { ResultDomain<TbSysUserDTO> rows = registerUser(userVO);
dto.setUserId(IDUtils.generateID()); TbSysUserDTO dto = rows.getData();
}
if (dto.getCreateTime() == null) { if (rows.getSuccess()) {
dto.setCreateTime(new Date());
}
if (dto.getDeleted() == null) {
dto.setDeleted(false);
}
int rows = userMapper.insertUser(dto);
if (rows > 0) {
logger.info("新增用户成功, userId={}", dto.getUserId()); logger.info("新增用户成功, userId={}", dto.getUserId());
return ResultDomain.success("新增用户成功", dto); return ResultDomain.success("新增用户成功", dto);
} }
@@ -219,11 +214,10 @@ public class SysUserServiceImpl implements SysUserService {
@Override @Override
public ResultDomain<SysUserVO> getUser(SysUserVO filter) { public ResultDomain<SysUserVO> getUser(SysUserVO filter) {
TbSysUserDTO dto = SysUserVO.toFilter(filter); if (filter == null) {
if (dto == null) {
return ResultDomain.failure(MSG_QUERY_PARAM_REQUIRED); return ResultDomain.failure(MSG_QUERY_PARAM_REQUIRED);
} }
List<SysUserVO> list = userMapper.getUserByFilter(dto); List<SysUserVO> list = userMapper.getUserByFilter(filter);
if (list == null || list.isEmpty()) { if (list == null || list.isEmpty()) {
return ResultDomain.failure("未找到用户"); return ResultDomain.failure("未找到用户");
} }
@@ -231,18 +225,19 @@ public class SysUserServiceImpl implements SysUserService {
} }
@Override @Override
public ResultDomain<TbSysUserDTO> getLoginUser(TbSysUserDTO filter) { public ResultDomain<SysUserVO> getLoginUser(SysUserVO filter) {
// 登录查询语义与 getUser 相同(可根据用户名/手机号/邮箱查询) // 登录查询语义与 getUser 相同(可根据用户名/手机号/邮箱查询)
if(NonUtils.isNotNull(filter.getPhone())){ if(NonUtils.isNotNull(filter.getPhone())){
filter.setPhone_hash(aesEncryptUtil.encrypt(filter.getPhone())); filter.setPhone(aesEncryptUtil.encrypt(filter.getPhone()));
filter.setPhoneHash(AesEncryptUtil.maskPhone(filter.getPhone()));
} }
return null; SysUserVO userVO = userMapper.getUserByFilter(filter).get(0);
return ResultDomain.success("查询成功", userVO);
} }
@Override @Override
public ResultDomain<SysUserVO> getUserList(SysUserVO filter) { public ResultDomain<SysUserVO> getUserList(SysUserVO filter) {
TbSysUserDTO dto = SysUserVO.toFilter(filter); List<SysUserVO> list = userMapper.getUserByFilter(filter);
List<SysUserVO> list = userMapper.getUserByFilter(dto);
if (list == null) { if (list == null) {
list = Collections.emptyList(); list = Collections.emptyList();
} }
@@ -272,9 +267,9 @@ public class SysUserServiceImpl implements SysUserService {
if (StringUtils.isBlank(username)) { if (StringUtils.isBlank(username)) {
return ResultDomain.failure("用户名不能为空"); return ResultDomain.failure("用户名不能为空");
} }
TbSysUserDTO filter = new TbSysUserDTO(); SysUserVO userVO = new SysUserVO();
filter.setUsername(username); userVO.setUsername(username);
List<SysUserVO> list = userMapper.getUserByFilter(filter); List<SysUserVO> list = userMapper.getUserByFilter(userVO);
if (list == null || list.isEmpty()) { if (list == null || list.isEmpty()) {
return ResultDomain.failure("未找到用户"); return ResultDomain.failure("未找到用户");
} }
@@ -370,9 +365,7 @@ public class SysUserServiceImpl implements SysUserService {
vo.setUserId(userId); vo.setUserId(userId);
vo.setAvatar(info.getAvatar()); vo.setAvatar(info.getAvatar());
vo.setGender(info.getGender()); vo.setGender(info.getGender());
vo.setFamilyName(info.getFamilyName()); vo.setUsername(info.getUsername());
vo.setGivenName(info.getGivenName());
vo.setFullName(info.getFullName());
vo.setLevel(info.getLevel()); vo.setLevel(info.getLevel());
vo.setIdCard(info.getIdCard()); vo.setIdCard(info.getIdCard());
vo.setAddress(info.getAddress()); vo.setAddress(info.getAddress());

View File

@@ -153,7 +153,7 @@
</select> </select>
<!-- 根据条件查询用户列表 --> <!-- 根据条件查询用户列表 -->
<select id="getUserByFilter" resultMap="UserVOResultMap" parameterType="org.xyzh.common.dto.sys.TbSysUserDTO"> <select id="getUserByFilter" resultMap="UserVOResultMap">
SELECT SELECT
u.user_id, u.username, u.password, u.email, u.phone, u.wechat_id, u.status, u.user_type, u.user_id, u.username, u.password, u.email, u.phone, u.wechat_id, u.status, u.user_type,
u.optsn, u.creator, u.updater, u.dept_path, u.remark, u.create_time, u.update_time, u.delete_time, u.deleted, u.optsn, u.creator, u.updater, u.dept_path, u.remark, u.create_time, u.update_time, u.delete_time, u.deleted,
@@ -170,9 +170,15 @@
<if test="filter.phone != null and filter.phone != ''"> <if test="filter.phone != null and filter.phone != ''">
AND u.phone = #{filter.phone} AND u.phone = #{filter.phone}
</if> </if>
<if test="filter.phoneHash != null and filter.phoneHash != ''">
AND u.phone_hash = #{filter.phoneHash}
</if>
<if test="filter.status != null and filter.status != ''"> <if test="filter.status != null and filter.status != ''">
AND u.status = #{filter.status} AND u.status = #{filter.status}
</if> </if>
<if test="filter.username !=null and filter.username !=''">
AND ui.username = #{filter.username}
</if>
<!-- username / userType / deptPath 在表中不存在,按 SQL 为准移除相关条件 --> <!-- username / userType / deptPath 在表中不存在,按 SQL 为准移除相关条件 -->
AND (u.deleted IS NULL OR u.deleted = false) AND (u.deleted IS NULL OR u.deleted = false)
</where> </where>

View File

@@ -53,4 +53,6 @@ yarn-error.log*
# Misc # Misc
.DS_Store .DS_Store
Thumbs.db Thumbs.db
packages/hello_uni