用户修改
This commit is contained in:
@@ -65,7 +65,7 @@ public interface SysUserService {
|
||||
* @author yslg
|
||||
* @since 2025-11-05
|
||||
*/
|
||||
ResultDomain<TbSysUserDTO> getLoginUser(TbSysUserDTO filter);
|
||||
ResultDomain<SysUserVO> getLoginUser(SysUserVO filter);
|
||||
|
||||
/**
|
||||
* @description 根据条件查询用户列表
|
||||
|
||||
@@ -37,6 +37,9 @@ public class SysUserVO extends BaseVO {
|
||||
@Schema(description = "手机")
|
||||
private String phone;
|
||||
|
||||
@Schema(description = "手机号哈希码")
|
||||
private String phoneHash;
|
||||
|
||||
@Schema(description = "微信ID")
|
||||
private String wechatId;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.xyzh.auth.strategy;
|
||||
|
||||
import org.xyzh.api.system.vo.SysUserVO;
|
||||
import org.xyzh.common.core.domain.LoginParam;
|
||||
import org.xyzh.common.dto.sys.TbSysUserDTO;
|
||||
|
||||
@@ -36,7 +37,7 @@ public interface LoginStrategy {
|
||||
* @author yslg
|
||||
* @since 2025-12-05
|
||||
*/
|
||||
TbSysUserDTO findUser(LoginParam loginParam);
|
||||
SysUserVO findUser(LoginParam loginParam);
|
||||
|
||||
/**
|
||||
* @description 验证凭据(密码或验证码)
|
||||
|
||||
@@ -42,10 +42,10 @@ public class EmailLoginStrategy implements LoginStrategy {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TbSysUserDTO findUser(LoginParam loginParam) {
|
||||
TbSysUserDTO filter = new TbSysUserDTO();
|
||||
public SysUserVO findUser(LoginParam loginParam) {
|
||||
SysUserVO filter = new SysUserVO();
|
||||
filter.setEmail(loginParam.getEmail());
|
||||
TbSysUserDTO user = userService.getLoginUser(filter).getData();
|
||||
SysUserVO user = userService.getLoginUser(filter).getData();
|
||||
if(user == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -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.PhoneValidateMethod;
|
||||
import org.xyzh.api.system.service.SysUserService;
|
||||
import org.xyzh.api.system.vo.SysUserVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -53,8 +54,8 @@ public class PasswordLoginStrategy implements LoginStrategy {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TbSysUserDTO findUser(LoginParam loginParam) {
|
||||
TbSysUserDTO filter = new TbSysUserDTO();
|
||||
public SysUserVO findUser(LoginParam loginParam) {
|
||||
SysUserVO filter = new SysUserVO();
|
||||
EmailValidateMethod emailValidateMethod = new EmailValidateMethod();
|
||||
PhoneValidateMethod phoneValidateMethod = new PhoneValidateMethod();
|
||||
if(emailValidateMethod.validate(loginParam.getUsername())){
|
||||
@@ -66,7 +67,7 @@ public class PasswordLoginStrategy implements LoginStrategy {
|
||||
}
|
||||
// 【优化】删除无用的密码编码,SQL查询不使用password字段
|
||||
// 密码验证在 verifyCredential() 方法中进行
|
||||
TbSysUserDTO user = userService.getLoginUser(filter).getData();
|
||||
SysUserVO user = userService.getLoginUser(filter).getData();
|
||||
if(user == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.xyzh.auth.strategy.LoginStrategy;
|
||||
import org.xyzh.common.core.domain.LoginParam;
|
||||
import org.xyzh.common.dto.sys.TbSysUserDTO;
|
||||
import org.xyzh.api.system.service.SysUserService;
|
||||
import org.xyzh.api.system.vo.SysUserVO;
|
||||
import org.xyzh.common.redis.service.RedisService;
|
||||
|
||||
/**
|
||||
@@ -41,10 +42,10 @@ public class PhoneLoginStrategy implements LoginStrategy {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TbSysUserDTO findUser(LoginParam loginParam) {
|
||||
TbSysUserDTO filter = new TbSysUserDTO();
|
||||
public SysUserVO findUser(LoginParam loginParam) {
|
||||
SysUserVO filter = new SysUserVO();
|
||||
filter.setPhone(loginParam.getPhone());
|
||||
TbSysUserDTO user = userService.getLoginUser(filter).getData();
|
||||
SysUserVO user = userService.getLoginUser(filter).getData();
|
||||
if(user == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.xyzh.auth.strategy.LoginStrategy;
|
||||
import org.xyzh.common.core.domain.LoginParam;
|
||||
import org.xyzh.common.dto.sys.TbSysUserDTO;
|
||||
import org.xyzh.api.system.service.SysUserService;
|
||||
import org.xyzh.api.system.vo.SysUserVO;
|
||||
|
||||
/**
|
||||
* @description UsernameLoginStrategy.java文件描述 用户名登录策略
|
||||
@@ -36,10 +37,10 @@ public class UsernameLoginStrategy implements LoginStrategy {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TbSysUserDTO findUser(LoginParam loginParam) {
|
||||
TbSysUserDTO filter = new TbSysUserDTO();
|
||||
public SysUserVO findUser(LoginParam loginParam) {
|
||||
SysUserVO filter = new SysUserVO();
|
||||
filter.setUsername(loginParam.getUsername());
|
||||
TbSysUserDTO user = userService.getLoginUser(filter).getData();
|
||||
SysUserVO user = userService.getLoginUser(filter).getData();
|
||||
if(user == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.xyzh.auth.strategy.LoginStrategy;
|
||||
import org.xyzh.common.core.domain.LoginParam;
|
||||
import org.xyzh.common.dto.sys.TbSysUserDTO;
|
||||
import org.xyzh.api.system.service.SysUserService;
|
||||
import org.xyzh.api.system.vo.SysUserVO;
|
||||
|
||||
/**
|
||||
* @description WechatLoginStrategy.java文件描述 微信登录策略
|
||||
@@ -32,10 +33,10 @@ public class WechatLoginStrategy implements LoginStrategy {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TbSysUserDTO findUser(LoginParam loginParam) {
|
||||
TbSysUserDTO filter = new TbSysUserDTO();
|
||||
public SysUserVO findUser(LoginParam loginParam) {
|
||||
SysUserVO filter = new SysUserVO();
|
||||
filter.setWechatId(loginParam.getWechatId());
|
||||
TbSysUserDTO user = userService.getLoginUser(filter).getData();
|
||||
SysUserVO user = userService.getLoginUser(filter).getData();
|
||||
if(user == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.xyzh.common.core.domain.LoginDomain;
|
||||
import org.xyzh.common.dto.sys.TbSysUserDTO;
|
||||
import org.xyzh.common.dto.sys.TbSysUserInfoDTO;
|
||||
import org.xyzh.common.utils.IDUtils;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
@@ -43,9 +44,10 @@ public class JwtTokenUtil {
|
||||
public String generateToken(LoginDomain loginDomain) {
|
||||
Map<String, Object> claims = new HashMap<>();
|
||||
TbSysUserDTO user = loginDomain.getUser();
|
||||
TbSysUserInfoDTO userInfoDTO = loginDomain.getUserInfo();
|
||||
|
||||
claims.put("userId", user.getUserId());
|
||||
claims.put("username", user.getUsername());
|
||||
claims.put("username", userInfoDTO.getUsername());
|
||||
claims.put("email", user.getEmail());
|
||||
claims.put("loginType", loginDomain.getLoginType());
|
||||
claims.put("ipAddress", loginDomain.getIpAddress());
|
||||
|
||||
@@ -33,7 +33,7 @@ public class TbSysUserDTO extends BaseDTO {
|
||||
private String phone;
|
||||
|
||||
@Schema(description = "手机号哈希")
|
||||
private String phone_hash;
|
||||
private String phoneHash;
|
||||
|
||||
@Schema(description = "微信ID")
|
||||
private String wechatId;
|
||||
|
||||
@@ -64,7 +64,7 @@ public interface TbSysUserMapper extends BaseMapper<TbSysUserDTO> {
|
||||
* @author yslg
|
||||
* @since 2025-11-07
|
||||
*/
|
||||
List<SysUserVO> getUserByFilter(@Param("filter") TbSysUserDTO filter);
|
||||
List<SysUserVO> getUserByFilter(@Param("filter") SysUserVO filter);
|
||||
|
||||
/**
|
||||
* @description 根据条件查询系统用户分页列表
|
||||
|
||||
@@ -68,7 +68,7 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
public ResultDomain<TbSysUserDTO> registerUser(SysUserVO userVO) {
|
||||
try {
|
||||
logger.info("开始注册用户:{}", userVO.getUsername());
|
||||
|
||||
userVO.setPhone(aesEncryptUtil.decrypt(userVO.getPhone()));
|
||||
// 检查用户是否已存在
|
||||
if (checkUserExists(userVO)) {
|
||||
return ResultDomain.failure("用户已存在");
|
||||
@@ -82,18 +82,20 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
if (StringUtils.isBlank(dto.getUserId())) {
|
||||
dto.setUserId(IDUtils.generateID());
|
||||
}
|
||||
dto.setPhone(aesEncryptUtil.encrypt(userVO.getPhone()));
|
||||
dto.setPhoneHash(AesEncryptUtil.maskPhone(userVO.getPhone()));
|
||||
dto.setCreateTime(now);
|
||||
dto.setDeleted(false);
|
||||
|
||||
// 加密密码
|
||||
if (StringUtils.isNotBlank(dto.getPassword())) {
|
||||
dto.setPassword(passwordEncoder.encode(dto.getPassword()));
|
||||
dto.setPassword(passwordEncoder.encode(aesEncryptUtil.decrypt(dto.getPassword())));
|
||||
}
|
||||
|
||||
// 插入用户主表
|
||||
int rows = userMapper.insertUser(dto);
|
||||
if (rows <= 0) {
|
||||
logger.warn("插入用户失败, username={}", dto.getUsername());
|
||||
logger.warn("插入用户失败, userVO:", userVO.toString());
|
||||
return ResultDomain.failure("插入用户失败");
|
||||
}
|
||||
|
||||
@@ -111,7 +113,6 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
userRole.setCreateTime(now);
|
||||
userRoleMapper.insertUserRole(userRole);
|
||||
|
||||
logger.info("注册用户成功, userId={}, username={}", dto.getUserId(), dto.getUsername());
|
||||
return ResultDomain.success("注册用户成功", dto);
|
||||
|
||||
} catch (Exception e) {
|
||||
@@ -126,7 +127,7 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
* @return true-存在,false-不存在
|
||||
*/
|
||||
private boolean checkUserExists(SysUserVO userVO) {
|
||||
TbSysUserDTO filter = new TbSysUserDTO();
|
||||
SysUserVO filter = new SysUserVO();
|
||||
|
||||
// 检查用户名是否存在
|
||||
if (StringUtils.isNotBlank(userVO.getUsername())) {
|
||||
@@ -140,8 +141,9 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
|
||||
// 检查手机号是否存在
|
||||
if (StringUtils.isNotBlank(userVO.getPhone())) {
|
||||
filter = new TbSysUserDTO();
|
||||
filter.setPhone(userVO.getPhone());
|
||||
filter = new SysUserVO();
|
||||
filter.setPhone(aesEncryptUtil.encrypt(userVO.getPhone()));
|
||||
filter.setPhoneHash(AesEncryptUtil.maskPhone(userVO.getPhone()));
|
||||
List<SysUserVO> users = userMapper.getUserByFilter(filter);
|
||||
if (users != null && !users.isEmpty()) {
|
||||
logger.warn("手机号已存在: {}", userVO.getPhone());
|
||||
@@ -151,7 +153,7 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
|
||||
// 检查邮箱是否存在
|
||||
if (StringUtils.isNotBlank(userVO.getEmail())) {
|
||||
filter = new TbSysUserDTO();
|
||||
filter = new SysUserVO();
|
||||
filter.setEmail(userVO.getEmail());
|
||||
List<SysUserVO> users = userMapper.getUserByFilter(filter);
|
||||
if (users != null && !users.isEmpty()) {
|
||||
@@ -168,18 +170,11 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
if (userVO == null) {
|
||||
return ResultDomain.failure(MSG_USER_PARAM_REQUIRED);
|
||||
}
|
||||
TbSysUserDTO dto = SysUserVO.toDTO(userVO);
|
||||
if (StringUtils.isBlank(dto.getUserId())) {
|
||||
dto.setUserId(IDUtils.generateID());
|
||||
}
|
||||
if (dto.getCreateTime() == null) {
|
||||
dto.setCreateTime(new Date());
|
||||
}
|
||||
if (dto.getDeleted() == null) {
|
||||
dto.setDeleted(false);
|
||||
}
|
||||
int rows = userMapper.insertUser(dto);
|
||||
if (rows > 0) {
|
||||
|
||||
ResultDomain<TbSysUserDTO> rows = registerUser(userVO);
|
||||
TbSysUserDTO dto = rows.getData();
|
||||
|
||||
if (rows.getSuccess()) {
|
||||
logger.info("新增用户成功, userId={}", dto.getUserId());
|
||||
return ResultDomain.success("新增用户成功", dto);
|
||||
}
|
||||
@@ -219,11 +214,10 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
|
||||
@Override
|
||||
public ResultDomain<SysUserVO> getUser(SysUserVO filter) {
|
||||
TbSysUserDTO dto = SysUserVO.toFilter(filter);
|
||||
if (dto == null) {
|
||||
if (filter == null) {
|
||||
return ResultDomain.failure(MSG_QUERY_PARAM_REQUIRED);
|
||||
}
|
||||
List<SysUserVO> list = userMapper.getUserByFilter(dto);
|
||||
List<SysUserVO> list = userMapper.getUserByFilter(filter);
|
||||
if (list == null || list.isEmpty()) {
|
||||
return ResultDomain.failure("未找到用户");
|
||||
}
|
||||
@@ -231,18 +225,19 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysUserDTO> getLoginUser(TbSysUserDTO filter) {
|
||||
public ResultDomain<SysUserVO> getLoginUser(SysUserVO filter) {
|
||||
// 登录查询语义与 getUser 相同(可根据用户名/手机号/邮箱查询)
|
||||
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
|
||||
public ResultDomain<SysUserVO> getUserList(SysUserVO filter) {
|
||||
TbSysUserDTO dto = SysUserVO.toFilter(filter);
|
||||
List<SysUserVO> list = userMapper.getUserByFilter(dto);
|
||||
List<SysUserVO> list = userMapper.getUserByFilter(filter);
|
||||
if (list == null) {
|
||||
list = Collections.emptyList();
|
||||
}
|
||||
@@ -272,9 +267,9 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
if (StringUtils.isBlank(username)) {
|
||||
return ResultDomain.failure("用户名不能为空");
|
||||
}
|
||||
TbSysUserDTO filter = new TbSysUserDTO();
|
||||
filter.setUsername(username);
|
||||
List<SysUserVO> list = userMapper.getUserByFilter(filter);
|
||||
SysUserVO userVO = new SysUserVO();
|
||||
userVO.setUsername(username);
|
||||
List<SysUserVO> list = userMapper.getUserByFilter(userVO);
|
||||
if (list == null || list.isEmpty()) {
|
||||
return ResultDomain.failure("未找到用户");
|
||||
}
|
||||
@@ -370,9 +365,7 @@ public class SysUserServiceImpl implements SysUserService {
|
||||
vo.setUserId(userId);
|
||||
vo.setAvatar(info.getAvatar());
|
||||
vo.setGender(info.getGender());
|
||||
vo.setFamilyName(info.getFamilyName());
|
||||
vo.setGivenName(info.getGivenName());
|
||||
vo.setFullName(info.getFullName());
|
||||
vo.setUsername(info.getUsername());
|
||||
vo.setLevel(info.getLevel());
|
||||
vo.setIdCard(info.getIdCard());
|
||||
vo.setAddress(info.getAddress());
|
||||
|
||||
@@ -153,7 +153,7 @@
|
||||
</select>
|
||||
|
||||
<!-- 根据条件查询用户列表 -->
|
||||
<select id="getUserByFilter" resultMap="UserVOResultMap" parameterType="org.xyzh.common.dto.sys.TbSysUserDTO">
|
||||
<select id="getUserByFilter" resultMap="UserVOResultMap">
|
||||
SELECT
|
||||
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,
|
||||
@@ -170,9 +170,15 @@
|
||||
<if test="filter.phone != null and filter.phone != ''">
|
||||
AND u.phone = #{filter.phone}
|
||||
</if>
|
||||
<if test="filter.phoneHash != null and filter.phoneHash != ''">
|
||||
AND u.phone_hash = #{filter.phoneHash}
|
||||
</if>
|
||||
<if test="filter.status != null and filter.status != ''">
|
||||
AND u.status = #{filter.status}
|
||||
</if>
|
||||
<if test="filter.username !=null and filter.username !=''">
|
||||
AND ui.username = #{filter.username}
|
||||
</if>
|
||||
<!-- username / userType / deptPath 在表中不存在,按 SQL 为准移除相关条件 -->
|
||||
AND (u.deleted IS NULL OR u.deleted = false)
|
||||
</where>
|
||||
|
||||
4
urbanLifelineWeb/.gitignore
vendored
4
urbanLifelineWeb/.gitignore
vendored
@@ -53,4 +53,6 @@ yarn-error.log*
|
||||
|
||||
# Misc
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
Thumbs.db
|
||||
|
||||
packages/hello_uni
|
||||
Reference in New Issue
Block a user