Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
usedCarAuction
/
aus
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 05505ab4
authored
Apr 17, 2026
by
杨卫
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat:发拍端pc平台自测提交
1 parent
5a60909d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
344 additions
and
236 deletions
aus-config/src/main/resources/config/common-dev.yaml
aus-core/src/main/java/com/glsx/usedcar/consts/vr/CommonConsts.java
aus-core/src/main/java/com/glsx/usedcar/module/vrsystem/config/VrLoginProperties.java
aus-core/src/main/java/com/glsx/usedcar/module/vrsystem/service/VrLoginService.java
aus-core/src/main/java/com/glsx/usedcar/module/vrsystem/service/VrUserService.java
aus-core/src/main/java/com/glsx/usedcar/module/vrsystem/util/PasswordStrengthUtil.java
aus-core/src/main/java/com/glsx/usedcar/module/vrsystem/util/RedisTokenUtil.java
aus-core/src/main/java/com/glsx/usedcar/module/vrsystem/vo/VrLoginRespVO.java
aus-core/src/main/java/com/glsx/usedcar/module/vrsystem/vo/VrLoginUserVO.java
aus-core/src/main/java/com/glsx/usedcar/module/vrsystem/vo/VrUserAddVO.java
aus-core/src/main/java/com/glsx/usedcar/module/vrsystem/vo/VrUserChangePasswordVO.java
aus-core/src/main/java/com/glsx/usedcar/module/vrsystem/vo/VrUserPasswordVO.java
aus-framework/src/main/java/org/summerframework/core/enums/ErrorCodeEnum.java
aus-vr/src/main/java/com/glsx/usedcar/advice/GlobalExceptionHandler.java
aus-vr/src/main/java/com/glsx/usedcar/config/WebConfig.java
aus-vr/src/main/java/com/glsx/usedcar/controller/HelloController.java
aus-vr/src/main/java/com/glsx/usedcar/controller/VrLoginController.java
aus-vr/src/main/java/com/glsx/usedcar/controller/VrUserController.java
aus-vr/src/main/java/com/glsx/usedcar/interceptor/VrLoginInterceptor.java
aus-vr/src/main/java/com/glsx/usedcar/interceptor/VrTokenInterceptor.java
aus-vr/src/main/java/com/glsx/usedcar/security/SpringSecurityAuditor.java
aus-vr/src/main/java/com/glsx/usedcar/util/RedisTokenUtil.java
aus-config/src/main/resources/config/common-dev.yaml
View file @
05505ab
...
@@ -68,7 +68,7 @@ spring:
...
@@ -68,7 +68,7 @@ spring:
data
:
data
:
redis
:
redis
:
database
:
0
database
:
0
host
:
192.168.3.2
07
host
:
192.168.3.2
26
port
:
6379
port
:
6379
password
:
password
:
# 连接超时时间 单位 ms(毫秒)
# 连接超时时间 单位 ms(毫秒)
...
...
aus-core/src/main/java/com/glsx/usedcar/consts/vr/CommonConsts.java
0 → 100644
View file @
05505ab
package
com
.
glsx
.
usedcar
.
consts
.
vr
;
/**
* 车辆发拍公共常量
* @author yangwei
* @version 1.0
* @since 2026/04/17 16:00
*/
public
interface
CommonConsts
{
/**
* json,字符集为utf8
*/
String
JSON_WITH_UTF8
=
"application/json;charset=utf-8"
;
/**
* 请求头中的授权信息
*/
String
REQUEST_HEAD_AUTHORIZATION
=
"authorization"
;
/**
* 请求头中的授权信息
*/
String
REQUEST_HEAD_AUTHORIZATION_UPPER
=
"Authorization"
;
/**
* Bearer
*/
String
BEARER
=
"Bearer "
;
}
aus-core/src/main/java/com/glsx/usedcar/module/vrsystem/config/VrLoginProperties.java
View file @
05505ab
...
@@ -30,5 +30,5 @@ public class VrLoginProperties {
...
@@ -30,5 +30,5 @@ public class VrLoginProperties {
/**
/**
* 登录接口免拦截路径
* 登录接口免拦截路径
*/
*/
private
String
[]
excludePaths
=
{
"/rest/login"
,
"/
rest/login/**
"
,
"/swagger-ui/**"
,
"/v3/api-docs/**"
};
private
String
[]
excludePaths
=
{
"/rest/login"
,
"/
doc.html
"
,
"/swagger-ui/**"
,
"/v3/api-docs/**"
};
}
}
aus-core/src/main/java/com/glsx/usedcar/module/vrsystem/service/VrLoginService.java
View file @
05505ab
package
com
.
glsx
.
usedcar
.
module
.
vrsystem
.
service
;
package
com
.
glsx
.
usedcar
.
module
.
vrsystem
.
service
;
import
cn.hutool.core.util.StrUtil
;
import
com.glsx.usedcar.module.vrsystem.dto.LoginUserDTO
;
import
com.glsx.usedcar.module.vrsystem.dto.LoginUserDTO
;
import
com.glsx.usedcar.module.vrsystem.entity.VrOrg
;
import
com.glsx.usedcar.module.vrsystem.entity.VrOrg
;
import
com.glsx.usedcar.module.vrsystem.entity.VrRole
;
import
com.glsx.usedcar.module.vrsystem.entity.VrRole
;
import
com.glsx.usedcar.module.vrsystem.entity.VrUser
;
import
com.glsx.usedcar.module.vrsystem.entity.VrUser
;
import
com.glsx.usedcar.module.vrsystem.util.RedisTokenUtil
;
import
com.glsx.usedcar.module.vrsystem.vo.VrLoginReqVO
;
import
com.glsx.usedcar.module.vrsystem.vo.VrLoginReqVO
;
import
com.glsx.usedcar.module.vrsystem.vo.VrLoginRespVO
;
import
com.glsx.usedcar.module.vrsystem.vo.VrLoginRespVO
;
import
com.glsx.usedcar.module.vrsystem.vo.VrLoginUserVO
;
import
com.glsx.usedcar.module.vrsystem.vo.VrLoginUserVO
;
import
com.glsx.usedcar.module.vrsystem.vo.VrRoleRespVO
;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
lombok.Setter
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
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.summerframework.core.enums.ErrorCodeEnum
;
import
org.summerframework.core.enums.ErrorCodeEnum
;
import
org.summerframework.core.exception.BusinessCodeException
;
import
org.summerframework.core.exception.BusinessCodeException
;
import
java.util.
Map
;
import
java.util.
Optional
;
import
java.util.UUID
;
import
java.util.UUID
;
import
java.util.concurrent.ConcurrentHashMap
;
import
java.util.concurrent.CompletableFuture
;
import
java.util.function.Function
;
/**
/**
* VR系统登录服务
* VR系统登录服务
...
@@ -32,14 +33,7 @@ public class VrLoginService {
...
@@ -32,14 +33,7 @@ public class VrLoginService {
private
final
VrRoleService
vrRoleService
;
private
final
VrRoleService
vrRoleService
;
private
final
VrOrgService
vrOrgService
;
private
final
VrOrgService
vrOrgService
;
private
final
PasswordEncoder
passwordEncoder
;
private
final
PasswordEncoder
passwordEncoder
;
private
final
RedisTokenUtil
redisTokenUtil
;
// Token存储回调(由Controller层注入RedisTokenUtil实现)
@Setter
private
Function
<
LoginUserDTO
,
String
>
tokenStoreFunction
;
@Setter
private
Function
<
String
,
Void
>
tokenRemoveFunction
;
@Setter
private
Function
<
String
,
LoginUserDTO
>
tokenGetFunction
;
/**
/**
* 用户登录
* 用户登录
...
@@ -48,19 +42,22 @@ public class VrLoginService {
...
@@ -48,19 +42,22 @@ public class VrLoginService {
// 查询用户
// 查询用户
VrUser
user
=
vrUserService
.
findByPhone
(
loginReqVO
.
getPhone
());
VrUser
user
=
vrUserService
.
findByPhone
(
loginReqVO
.
getPhone
());
if
(
user
==
null
)
{
if
(
user
==
null
)
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
LOGIN_ERROR
,
"手机号或密码错误"
);
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
VR_PHONE_PASSWORD_ERROR
);
}
}
// 检查用户状态
// 检查用户状态
if
(
user
.
getStatus
()
!=
1
)
{
if
(
user
.
getStatus
()
!=
1
)
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
COMMON_ERROR
,
"用户已被禁用"
);
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
VR_ACCOUNT_DISABLED
);
}
}
// 验证密码
// 验证密码
if
(!
passwordEncoder
.
matches
(
loginReqVO
.
getPassword
(),
user
.
getPassword
()))
{
if
(!
passwordEncoder
.
matches
(
loginReqVO
.
getPassword
(),
user
.
getPassword
()))
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
LOGIN_ERROR
,
"手机号或密码错误"
);
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
VR_PHONE_PASSWORD_ERROR
);
}
}
// 登录时清理该用户的过期token(异步)
cleanupExpiredTokensAsync
(
user
.
getPhone
());
// 构建登录用户DTO
// 构建登录用户DTO
LoginUserDTO
userDTO
=
new
LoginUserDTO
();
LoginUserDTO
userDTO
=
new
LoginUserDTO
();
userDTO
.
setUserId
(
user
.
getId
());
userDTO
.
setUserId
(
user
.
getId
());
...
@@ -80,8 +77,10 @@ public class VrLoginService {
...
@@ -80,8 +77,10 @@ public class VrLoginService {
}
}
// 生成并存储Token
// 生成并存储Token
String
token
=
tokenStoreFunction
.
apply
(
userDTO
);
String
token
=
cn
.
hutool
.
core
.
lang
.
UUID
.
randomUUID
().
toString
(
true
);
redisTokenUtil
.
storeToken
(
token
,
userDTO
);
vrUserService
.
updLastLoginTime
(
user
.
getId
());
log
.
info
(
"用户登录成功: phone={}, userId={}"
,
user
.
getPhone
(),
user
.
getId
());
log
.
info
(
"用户登录成功: phone={}, userId={}"
,
user
.
getPhone
(),
user
.
getId
());
// 构建响应
// 构建响应
...
@@ -91,6 +90,7 @@ public class VrLoginService {
...
@@ -91,6 +90,7 @@ public class VrLoginService {
.
phone
(
user
.
getPhone
())
.
phone
(
user
.
getPhone
())
.
userName
(
user
.
getUserName
())
.
userName
(
user
.
getUserName
())
.
roleId
(
role
!=
null
?
role
.
getId
()
:
null
)
.
roleId
(
role
!=
null
?
role
.
getId
()
:
null
)
.
roleCode
(
role
!=
null
?
role
.
getRoleCode
()
:
null
)
.
roleName
(
role
!=
null
?
role
.
getRoleName
()
:
null
)
.
roleName
(
role
!=
null
?
role
.
getRoleName
()
:
null
)
.
orgId
(
org
!=
null
?
org
.
getId
()
:
null
)
.
orgId
(
org
!=
null
?
org
.
getId
()
:
null
)
.
orgName
(
org
!=
null
?
org
.
getOrgName
()
:
null
)
.
orgName
(
org
!=
null
?
org
.
getOrgName
()
:
null
)
...
@@ -100,9 +100,9 @@ public class VrLoginService {
...
@@ -100,9 +100,9 @@ public class VrLoginService {
/**
/**
* 退出登录
* 退出登录
*/
*/
public
void
logout
(
String
token
)
{
public
void
logout
(
String
token
,
LoginUserDTO
userDTO
)
{
if
(
token
!=
null
&&
!
token
.
isEmpty
(
))
{
if
(
StrUtil
.
isNotBlank
(
token
))
{
tokenRemoveFunction
.
apply
(
token
);
redisTokenUtil
.
removeToken
(
token
,
userDTO
);
log
.
info
(
"用户退出登录: token={}"
,
token
);
log
.
info
(
"用户退出登录: token={}"
,
token
);
}
}
}
}
...
@@ -110,32 +110,36 @@ public class VrLoginService {
...
@@ -110,32 +110,36 @@ public class VrLoginService {
/**
/**
* 获取登录用户信息
* 获取登录用户信息
*/
*/
public
VrLoginUserVO
getLoginUserInfo
(
String
token
)
{
public
VrLoginUserVO
getLoginUserInfo
(
LoginUserDTO
userDTO
)
{
LoginUserDTO
userDTO
=
tokenGetFunction
.
apply
(
token
);
if
(
userDTO
==
null
)
{
if
(
userDTO
==
null
)
{
return
null
;
return
null
;
}
}
// 查询角色名称
String
roleName
=
null
;
if
(
userDTO
.
getRoleId
()
!=
null
)
{
roleName
=
vrRoleService
.
getRoleNameById
(
userDTO
.
getRoleId
());
}
// 查询组织名称
// 查询组织名称
String
orgName
=
null
;
String
orgName
=
null
;
if
(
userDTO
.
getOrgId
()
!=
null
)
{
if
(
userDTO
.
getOrgId
()
!=
null
)
{
orgName
=
vrOrgService
.
getOrgNameById
(
userDTO
.
getOrgId
());
orgName
=
vrOrgService
.
getOrgNameById
(
userDTO
.
getOrgId
());
}
}
return
VrLoginUserVO
.
builder
()
VrLoginUserVO
rtn
=
VrLoginUserVO
.
builder
()
.
userId
(
userDTO
.
getUserId
())
.
userId
(
userDTO
.
getUserId
())
.
phone
(
userDTO
.
getPhone
())
.
phone
(
userDTO
.
getPhone
())
.
userName
(
userDTO
.
getUserName
())
.
userName
(
userDTO
.
getUserName
())
.
roleId
(
userDTO
.
getRoleId
())
.
roleId
(
userDTO
.
getRoleId
())
.
roleName
(
roleName
)
.
orgId
(
userDTO
.
getOrgId
())
.
orgId
(
userDTO
.
getOrgId
())
.
orgName
(
orgName
)
.
orgName
(
orgName
)
.
build
();
.
build
();
Optional
.
ofNullable
(
userDTO
.
getRoleId
())
.
map
(
user
->
vrRoleService
.
getRoleById
(
userDTO
.
getRoleId
()))
.
ifPresent
(
vrRoleRespVO
->
rtn
.
setRoleName
(
vrRoleRespVO
.
getRoleName
()));
return
rtn
;
}
/**
* 异步清理过期token
*/
private
void
cleanupExpiredTokensAsync
(
String
phone
)
{
CompletableFuture
.
runAsync
(()
->
redisTokenUtil
.
getUserValidTokens
(
phone
));
}
}
}
}
aus-core/src/main/java/com/glsx/usedcar/module/vrsystem/service/VrUserService.java
View file @
05505ab
...
@@ -5,6 +5,7 @@ import com.glsx.usedcar.converts.VrSystemConverter;
...
@@ -5,6 +5,7 @@ import com.glsx.usedcar.converts.VrSystemConverter;
import
com.glsx.usedcar.enums.common.DeleteFlag
;
import
com.glsx.usedcar.enums.common.DeleteFlag
;
import
com.glsx.usedcar.module.vrsystem.dao.*
;
import
com.glsx.usedcar.module.vrsystem.dao.*
;
import
com.glsx.usedcar.module.vrsystem.entity.*
;
import
com.glsx.usedcar.module.vrsystem.entity.*
;
import
com.glsx.usedcar.module.vrsystem.util.RedisTokenUtil
;
import
com.glsx.usedcar.module.vrsystem.vo.*
;
import
com.glsx.usedcar.module.vrsystem.vo.*
;
import
jakarta.persistence.criteria.Join
;
import
jakarta.persistence.criteria.Join
;
import
jakarta.persistence.criteria.Root
;
import
jakarta.persistence.criteria.Root
;
...
@@ -21,6 +22,7 @@ import org.summerframework.core.exception.BusinessCodeException;
...
@@ -21,6 +22,7 @@ import org.summerframework.core.exception.BusinessCodeException;
import
org.summerframework.orm.paging.Pagination
;
import
org.summerframework.orm.paging.Pagination
;
import
java.time.LocalDate
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
import
java.time.format.DateTimeFormatter
;
import
java.time.format.DateTimeFormatter
;
import
java.util.*
;
import
java.util.*
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
...
@@ -41,6 +43,7 @@ public class VrUserService {
...
@@ -41,6 +43,7 @@ public class VrUserService {
private
final
VrUserOrgRepository
vrUserOrgRepository
;
private
final
VrUserOrgRepository
vrUserOrgRepository
;
private
final
VrSystemConverter
vrSystemConverter
;
private
final
VrSystemConverter
vrSystemConverter
;
private
final
PasswordEncoder
passwordEncoder
;
private
final
PasswordEncoder
passwordEncoder
;
private
final
RedisTokenUtil
redisTokenUtil
;
/**
/**
* 新增用户
* 新增用户
...
@@ -164,21 +167,15 @@ public class VrUserService {
...
@@ -164,21 +167,15 @@ public class VrUserService {
vrUserRepository
.
save
(
user
);
vrUserRepository
.
save
(
user
);
// 如果禁用用户,清除其所有登录token(强制退出登录)
// 如果禁用用户,清除其所有登录token(强制退出登录)
if
(
status
==
0
)
{
if
(
status
==
0
&&
redisTokenUtil
!=
null
)
{
clearUserTokens
(
user
.
getPhone
());
redisTokenUtil
.
kickAllUserTokens
(
user
.
getPhone
());
log
.
info
(
"用户禁用,已清除所有登录token: phone={}"
,
user
.
getPhone
());
}
}
log
.
info
(
"用户状态更新: ID={}, status={}"
,
id
,
status
);
log
.
info
(
"用户状态更新: ID={}, status={}"
,
id
,
status
);
}
}
/**
/**
* 清除用户所有登录token(由子类或外部实现)
*/
protected
void
clearUserTokens
(
String
phone
)
{
// 由 VrLoginService 或 RedisTokenUtil 实现
}
/**
* 根据手机号查询用户
* 根据手机号查询用户
*/
*/
public
VrUser
findByPhone
(
String
phone
)
{
public
VrUser
findByPhone
(
String
phone
)
{
...
@@ -207,6 +204,15 @@ public class VrUserService {
...
@@ -207,6 +204,15 @@ public class VrUserService {
return
null
;
return
null
;
}
}
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
updLastLoginTime
(
Long
userId
)
{
VrUser
user
=
vrUserRepository
.
findByIdAndDeleteFlag
(
userId
,
DeleteFlag
.
NOT_DELETED
.
getCode
()).
orElse
(
null
);
if
(
user
!=
null
)
{
user
.
setLastLoginTime
(
LocalDateTime
.
now
());
vrUserRepository
.
save
(
user
);
}
}
/**
/**
* 重置密码(重置为手机号后6位)
* 重置密码(重置为手机号后6位)
*/
*/
...
@@ -223,20 +229,52 @@ public class VrUserService {
...
@@ -223,20 +229,52 @@ public class VrUserService {
}
}
/**
/**
* 修改密码
* 修改密码
(管理后台用)
*/
*/
@Deprecated
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
updatePassword
(
Long
id
,
VrUserPasswordVO
passwordVO
)
{
public
void
updatePassword
(
Long
id
,
VrUserPasswordVO
passwordVO
)
{
VrUser
user
=
vrUserRepository
.
findByIdAndDeleteFlag
(
id
,
DeleteFlag
.
NOT_DELETED
.
getCode
())
VrUser
user
=
vrUserRepository
.
findByIdAndDeleteFlag
(
id
,
DeleteFlag
.
NOT_DELETED
.
getCode
())
.
orElseThrow
(()
->
new
BusinessCodeException
(
ErrorCodeEnum
.
DATA_NOT_EXIST
,
"用户不存在"
));
.
orElseThrow
(()
->
new
BusinessCodeException
(
ErrorCodeEnum
.
DATA_NOT_EXIST
,
"用户不存在"
));
user
.
setPassword
(
passwordEncoder
.
encode
(
passwordVO
.
getPassword
()));
user
.
setPassword
(
passwordEncoder
.
encode
(
passwordVO
.
getPassword
()));
vrUserRepository
.
save
(
user
);
//
vrUserRepository.save(user);
log
.
info
(
"用户密码修改: ID={}"
,
id
);
log
.
info
(
"用户密码修改: ID={}"
,
id
);
}
}
/**
/**
* 修改密码(用户自用,需验证旧密码,成功后强制退出登录)
*/
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
changePassword
(
Long
userId
,
VrUserChangePasswordVO
passwordVO
)
{
VrUser
user
=
vrUserRepository
.
findByIdAndDeleteFlag
(
userId
,
DeleteFlag
.
NOT_DELETED
.
getCode
())
.
orElseThrow
(()
->
new
BusinessCodeException
(
ErrorCodeEnum
.
DATA_NOT_EXIST
,
"用户不存在"
));
// 1. 验证当前密码
if
(!
passwordEncoder
.
matches
(
passwordVO
.
getCurrentPassword
(),
user
.
getPassword
()))
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
VR_PASSWORD_ERROR
);
}
// 2. 新密码不能与当前密码相同
if
(
passwordEncoder
.
matches
(
passwordVO
.
getNewPassword
(),
user
.
getPassword
()))
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
VR_PASSWORD_SAME
);
}
// 3. 更新密码
user
.
setPassword
(
passwordEncoder
.
encode
(
passwordVO
.
getNewPassword
()));
vrUserRepository
.
save
(
user
);
// 4. 强制退出所有登录(吊销原凭证)
if
(
redisTokenUtil
!=
null
)
{
redisTokenUtil
.
kickAllUserTokens
(
user
.
getPhone
());
log
.
info
(
"用户修改密码,已清除所有登录token: phone={}"
,
user
.
getPhone
());
}
log
.
info
(
"用户密码修改成功: userId={}"
,
userId
);
}
/**
* 分页查询用户(使用 JPA 关联查询)
* 分页查询用户(使用 JPA 关联查询)
*/
*/
public
Page
<
VrUserPageRespVO
>
pageUsers
(
VrUserPageQueryVO
queryVO
)
{
public
Page
<
VrUserPageRespVO
>
pageUsers
(
VrUserPageQueryVO
queryVO
)
{
...
...
aus-core/src/main/java/com/glsx/usedcar/module/vrsystem/util/PasswordStrengthUtil.java
0 → 100644
View file @
05505ab
package
com
.
glsx
.
usedcar
.
module
.
vrsystem
.
util
;
import
lombok.Getter
;
/**
* 密码强度评估工具类
*/
public
class
PasswordStrengthUtil
{
/**
* 密码强度等级
*/
@Getter
public
enum
StrengthLevel
{
WEAK
(
"弱"
,
"red"
),
MEDIUM
(
"中"
,
"orange"
),
STRONG
(
"强"
,
"green"
);
private
final
String
label
;
private
final
String
color
;
StrengthLevel
(
String
label
,
String
color
)
{
this
.
label
=
label
;
this
.
color
=
color
;
}
}
/**
* 评估密码强度
*
* 【弱】:纯数字或纯字母,或长度少于8位
* 【中】:数字加字母组合,或长度在8至11位
* 【强】:数字加字母加特殊字符,且长度大于等于12位
*
* @param password 密码
* @return 强度等级
*/
public
static
StrengthLevel
evaluate
(
String
password
)
{
if
(
password
==
null
||
password
.
isEmpty
())
{
return
StrengthLevel
.
WEAK
;
}
int
length
=
password
.
length
();
boolean
hasDigit
=
false
;
boolean
hasLetter
=
false
;
boolean
hasSpecial
=
false
;
for
(
char
c
:
password
.
toCharArray
())
{
if
(
Character
.
isDigit
(
c
))
{
hasDigit
=
true
;
}
else
if
(
Character
.
isLetter
(
c
))
{
hasLetter
=
true
;
}
else
{
hasSpecial
=
true
;
}
}
// 强:数字+字母+特殊字符,且长度>=12
if
(
hasDigit
&&
hasLetter
&&
hasSpecial
&&
length
>=
12
)
{
return
StrengthLevel
.
STRONG
;
}
// 弱:纯数字 或 纯字母 或 长度<8
if
((!
hasDigit
&&
!
hasSpecial
)
||
(!
hasLetter
&&
!
hasSpecial
)
||
length
<
8
)
{
return
StrengthLevel
.
WEAK
;
}
// 中:其他情况(数字+字母组合,或长度8-11位)
return
StrengthLevel
.
MEDIUM
;
}
/**
* 获取密码强度描述
*/
public
static
String
getStrengthLabel
(
String
password
)
{
return
evaluate
(
password
).
getLabel
();
}
/**
* 获取密码强度颜色
*/
public
static
String
getStrengthColor
(
String
password
)
{
return
evaluate
(
password
).
getColor
();
}
}
aus-core/src/main/java/com/glsx/usedcar/module/vrsystem/util/RedisTokenUtil.java
0 → 100644
View file @
05505ab
This diff is collapsed.
Click to expand it.
aus-core/src/main/java/com/glsx/usedcar/module/vrsystem/vo/VrLoginRespVO.java
View file @
05505ab
...
@@ -33,6 +33,9 @@ public class VrLoginRespVO implements Serializable {
...
@@ -33,6 +33,9 @@ public class VrLoginRespVO implements Serializable {
@Schema
(
description
=
"角色ID"
,
example
=
"1"
)
@Schema
(
description
=
"角色ID"
,
example
=
"1"
)
private
Long
roleId
;
private
Long
roleId
;
@Schema
(
description
=
"角色代码"
,
example
=
"SYSTEM_ADMIN"
)
private
String
roleCode
;
@Schema
(
description
=
"角色名称"
,
example
=
"管理员"
)
@Schema
(
description
=
"角色名称"
,
example
=
"管理员"
)
private
String
roleName
;
private
String
roleName
;
...
...
aus-core/src/main/java/com/glsx/usedcar/module/vrsystem/vo/VrLoginUserVO.java
View file @
05505ab
...
@@ -30,6 +30,9 @@ public class VrLoginUserVO implements Serializable {
...
@@ -30,6 +30,9 @@ public class VrLoginUserVO implements Serializable {
@Schema
(
description
=
"角色ID"
,
example
=
"1"
)
@Schema
(
description
=
"角色ID"
,
example
=
"1"
)
private
Long
roleId
;
private
Long
roleId
;
@Schema
(
description
=
"角色代码"
,
example
=
"SYSTEM_ADMIN"
)
private
String
roleCode
;
@Schema
(
description
=
"角色名称"
,
example
=
"管理员"
)
@Schema
(
description
=
"角色名称"
,
example
=
"管理员"
)
private
String
roleName
;
private
String
roleName
;
...
...
aus-core/src/main/java/com/glsx/usedcar/module/vrsystem/vo/VrUserAddVO.java
View file @
05505ab
...
@@ -37,5 +37,8 @@ public class VrUserAddVO implements Serializable {
...
@@ -37,5 +37,8 @@ public class VrUserAddVO implements Serializable {
private
Long
orgId
;
private
Long
orgId
;
@Schema
(
description
=
"登录密码(可选,默认手机号后6位)"
,
example
=
""
)
@Schema
(
description
=
"登录密码(可选,默认手机号后6位)"
,
example
=
""
)
@Size
(
min
=
6
,
max
=
20
,
message
=
"密码长度必须在{min}至{max}位之间"
)
@Pattern
(
regexp
=
"^[A-Za-z\\d!@#$%^&*()_+\\-=\\[\\]{};':\"\\\\|,.<>\\/?]*$"
,
message
=
"密码只能包含大小写字母、数字及特殊字符"
)
private
String
password
;
private
String
password
;
}
}
aus-core/src/main/java/com/glsx/usedcar/module/vrsystem/vo/VrUserChangePasswordVO.java
0 → 100644
View file @
05505ab
package
com
.
glsx
.
usedcar
.
module
.
vrsystem
.
vo
;
import
io.swagger.v3.oas.annotations.media.Schema
;
import
jakarta.validation.constraints.NotBlank
;
import
jakarta.validation.constraints.Pattern
;
import
jakarta.validation.constraints.Size
;
import
lombok.Data
;
import
java.io.Serial
;
import
java.io.Serializable
;
/**
* 修改密码请求VO
*/
@Data
@Schema
(
description
=
"修改密码请求参数"
)
public
class
VrUserChangePasswordVO
implements
Serializable
{
@Serial
private
static
final
long
serialVersionUID
=
1L
;
@Schema
(
description
=
"当前密码"
,
requiredMode
=
Schema
.
RequiredMode
.
REQUIRED
,
example
=
"OldPass123!"
)
@NotBlank
(
message
=
"当前密码不能为空"
)
private
String
currentPassword
;
@Schema
(
description
=
"新密码"
,
requiredMode
=
Schema
.
RequiredMode
.
REQUIRED
,
example
=
"NewPass456!"
)
@NotBlank
(
message
=
"新密码不能为空"
)
@Size
(
min
=
6
,
max
=
20
,
message
=
"密码长度必须在{min}至{max}位之间"
)
@Pattern
(
regexp
=
"^[A-Za-z\\d!@#$%^&*()_+\\-=\\[\\]{};':\"\\\\|,.<>\\/?]*$"
,
message
=
"密码只能包含大小写字母、数字及特殊字符"
)
private
String
newPassword
;
@Schema
(
description
=
"确认新密码"
,
requiredMode
=
Schema
.
RequiredMode
.
REQUIRED
,
example
=
"NewPass456!"
)
@NotBlank
(
message
=
"确认新密码不能为空"
)
private
String
confirmPassword
;
}
aus-core/src/main/java/com/glsx/usedcar/module/vrsystem/vo/VrUserPasswordVO.java
View file @
05505ab
...
@@ -22,7 +22,7 @@ public class VrUserPasswordVO implements Serializable {
...
@@ -22,7 +22,7 @@ public class VrUserPasswordVO implements Serializable {
@Schema
(
description
=
"新密码"
,
requiredMode
=
Schema
.
RequiredMode
.
REQUIRED
,
example
=
"Abc123!@#"
)
@Schema
(
description
=
"新密码"
,
requiredMode
=
Schema
.
RequiredMode
.
REQUIRED
,
example
=
"Abc123!@#"
)
@NotBlank
(
message
=
"密码不能为空"
)
@NotBlank
(
message
=
"密码不能为空"
)
@Size
(
min
=
6
,
max
=
20
,
message
=
"密码长度必须在{min}至{max}位之间"
)
@Size
(
min
=
6
,
max
=
20
,
message
=
"密码长度必须在{min}至{max}位之间"
)
@Pattern
(
regexp
=
"^
(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[!@#$%^&*()_+\\-=\\[\\]{};':\"\\\\|,.<>/?])[!-~]+
$"
,
@Pattern
(
regexp
=
"^
[A-Za-z\\d!@#$%^&*()_+\\-=\\[\\]{};':\"\\\\|,.<>\\/?]*
$"
,
message
=
"密码
必须包含大小写字母、数字和特殊字符,且只能使用ASCII可打印
字符"
)
message
=
"密码
只能包含大小写字母、数字及特殊
字符"
)
private
String
password
;
private
String
password
;
}
}
aus-framework/src/main/java/org/summerframework/core/enums/ErrorCodeEnum.java
View file @
05505ab
...
@@ -47,8 +47,16 @@ public enum ErrorCodeEnum {
...
@@ -47,8 +47,16 @@ public enum ErrorCodeEnum {
NOT_ABLE_INSPECT
(
1001104
,
"当前工单无法提交检测"
),
NOT_ABLE_INSPECT
(
1001104
,
"当前工单无法提交检测"
),
NODE_CHECK_RULE_ERROR
(
1001105
,
"【{0}】校验规则解析异常"
),
NODE_CHECK_RULE_ERROR
(
1001105
,
"【{0}】校验规则解析异常"
),
NOT_CURR_WORK_INSPECTOR
(
1001106
,
"您不是当前工单的检测师,无法提交!"
)
NOT_CURR_WORK_INSPECTOR
(
1001106
,
"您不是当前工单的检测师,无法提交!"
)
,
/** 1002 发拍模块 */
VR_PHONE_PASSWORD_ERROR
(
1002001
,
"手机号或密码错误"
),
VR_ACCOUNT_DISABLED
(
1002002
,
"该账号或所属集团已被停用"
),
VR_PASSWORD_NOT_SAME
(
1002003
,
"新密码与确认密码不一致"
),
VR_PASSWORD_ERROR
(
1002004
,
"当前密码错误"
),
VR_PASSWORD_SAME
(
1002005
,
"新密码不能与当前密码相同"
),
VR_TOKEN_STORE_ERROR
(
1002006
,
"Failed to store token"
),
;
;
private
final
Integer
code
;
private
final
Integer
code
;
private
final
String
message
;
private
final
String
message
;
...
...
aus-vr/src/main/java/com/glsx/usedcar/advice/GlobalExceptionHandler.java
View file @
05505ab
...
@@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil;
...
@@ -4,6 +4,7 @@ import cn.hutool.core.util.StrUtil;
import
com.glsx.usedcar.resp.BaseResp
;
import
com.glsx.usedcar.resp.BaseResp
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.hibernate.HibernateException
;
import
org.hibernate.HibernateException
;
import
org.springframework.context.support.DefaultMessageSourceResolvable
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.bind.MethodArgumentNotValidException
;
import
org.springframework.web.bind.MethodArgumentNotValidException
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
...
@@ -39,7 +40,7 @@ public class GlobalExceptionHandler {
...
@@ -39,7 +40,7 @@ public class GlobalExceptionHandler {
public
BaseResp
<
Void
>
handleValidationException
(
MethodArgumentNotValidException
e
)
{
public
BaseResp
<
Void
>
handleValidationException
(
MethodArgumentNotValidException
e
)
{
log
.
error
(
"参数校验失败:"
,
e
);
log
.
error
(
"参数校验失败:"
,
e
);
String
errorMsg
=
e
.
getBindingResult
().
getFieldErrors
().
stream
()
String
errorMsg
=
e
.
getBindingResult
().
getFieldErrors
().
stream
()
.
map
(
fieldError
->
fieldError
.
getField
()
+
":"
+
fieldError
.
getDefaultMessage
()
)
.
map
(
DefaultMessageSourceResolvable:
:
getDefaultMessage
)
.
collect
(
Collectors
.
joining
(
","
));
.
collect
(
Collectors
.
joining
(
","
));
return
BaseResp
.
fail
(
"参数错误:"
+
errorMsg
);
return
BaseResp
.
fail
(
"参数错误:"
+
errorMsg
);
}
}
...
...
aus-vr/src/main/java/com/glsx/usedcar/config/WebConfig.java
View file @
05505ab
...
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.datatype.hibernate5.jakarta.Hibernate5JakartaModule
...
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.datatype.hibernate5.jakarta.Hibernate5JakartaModule
import
com.fasterxml.jackson.datatype.jsr310.ser.*
;
import
com.fasterxml.jackson.datatype.jsr310.ser.*
;
import
com.glsx.usedcar.interceptor.VrLoginInterceptor
;
import
com.glsx.usedcar.interceptor.VrLoginInterceptor
;
import
com.glsx.usedcar.interceptor.VrTokenInterceptor
;
import
com.glsx.usedcar.interceptor.VrTokenInterceptor
;
import
com.glsx.usedcar.module.vrsystem.config.VrLoginProperties
;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
org.springframework.context.annotation.*
;
import
org.springframework.context.annotation.*
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Page
;
...
@@ -33,6 +34,7 @@ import static org.summerframework.core.util.DateTimeUtils.*;
...
@@ -33,6 +34,7 @@ import static org.summerframework.core.util.DateTimeUtils.*;
@RequiredArgsConstructor
@RequiredArgsConstructor
public
class
WebConfig
implements
WebMvcConfigurer
{
public
class
WebConfig
implements
WebMvcConfigurer
{
private
final
VrLoginProperties
vrLoginProperties
;
private
final
VrTokenInterceptor
vrTokenInterceptor
;
private
final
VrTokenInterceptor
vrTokenInterceptor
;
private
final
VrLoginInterceptor
vrLoginInterceptor
;
private
final
VrLoginInterceptor
vrLoginInterceptor
;
...
@@ -45,7 +47,7 @@ public class WebConfig implements WebMvcConfigurer {
...
@@ -45,7 +47,7 @@ public class WebConfig implements WebMvcConfigurer {
// 登录拦截器(优先级1):检查登录状态
// 登录拦截器(优先级1):检查登录状态
registry
.
addInterceptor
(
vrLoginInterceptor
)
registry
.
addInterceptor
(
vrLoginInterceptor
)
.
addPathPatterns
(
"/**"
)
.
excludePathPatterns
(
vrLoginProperties
.
getExcludePaths
()
)
.
order
(
1
);
.
order
(
1
);
}
}
...
...
aus-vr/src/main/java/com/glsx/usedcar/controller/HelloController.java
deleted
100644 → 0
View file @
5a60909
package
com
.
glsx
.
usedcar
.
controller
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* @author yangwei
* @version 1.0
* @since 2026/04/17 10:39
*/
@RestController
@RequestMapping
(
"/hello"
)
public
class
HelloController
{
@GetMapping
(
"/world"
)
public
String
sayHello
()
{
return
"Hello, World!"
;
}
}
aus-vr/src/main/java/com/glsx/usedcar/controller/VrLoginController.java
View file @
05505ab
...
@@ -2,22 +2,24 @@ package com.glsx.usedcar.controller;
...
@@ -2,22 +2,24 @@ package com.glsx.usedcar.controller;
import
com.glsx.usedcar.module.vrsystem.dto.LoginUserDTO
;
import
com.glsx.usedcar.module.vrsystem.dto.LoginUserDTO
;
import
com.glsx.usedcar.module.vrsystem.service.VrLoginService
;
import
com.glsx.usedcar.module.vrsystem.service.VrLoginService
;
import
com.glsx.usedcar.module.vrsystem.util.RedisTokenUtil
;
import
com.glsx.usedcar.module.vrsystem.vo.VrLoginReqVO
;
import
com.glsx.usedcar.module.vrsystem.vo.VrLoginReqVO
;
import
com.glsx.usedcar.module.vrsystem.vo.VrLoginRespVO
;
import
com.glsx.usedcar.module.vrsystem.vo.VrLoginRespVO
;
import
com.glsx.usedcar.module.vrsystem.vo.VrLoginUserVO
;
import
com.glsx.usedcar.module.vrsystem.vo.VrLoginUserVO
;
import
com.glsx.usedcar.resp.BaseResp
;
import
com.glsx.usedcar.resp.BaseResp
;
import
com.glsx.usedcar.util.RedisTokenUtil
;
import
com.glsx.usedcar.util.UserContext
;
import
com.glsx.usedcar.util.UserContext
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
jakarta.annotation.PostConstruct
;
import
jakarta.servlet.http.HttpServletRequest
;
import
jakarta.servlet.http.HttpServletRequest
;
import
jakarta.validation.Valid
;
import
jakarta.validation.Valid
;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
org.summerframework.core.enums.ErrorCodeEnum
;
import
org.summerframework.core.exception.BusinessCodeException
;
import
java.util.UUID
;
import
java.util.Optional
;
import
java.util.Set
;
/**
/**
* VR系统登录控制器
* VR系统登录控制器
...
@@ -32,20 +34,6 @@ public class VrLoginController {
...
@@ -32,20 +34,6 @@ public class VrLoginController {
private
final
VrLoginService
vrLoginService
;
private
final
VrLoginService
vrLoginService
;
private
final
RedisTokenUtil
redisTokenUtil
;
private
final
RedisTokenUtil
redisTokenUtil
;
@PostConstruct
public
void
init
()
{
// 注入Token操作函数
vrLoginService
.
setTokenStoreFunction
(
userDTO
->
{
String
token
=
UUID
.
randomUUID
().
toString
().
replace
(
"-"
,
""
);
redisTokenUtil
.
storeToken
(
token
,
userDTO
);
return
token
;
});
vrLoginService
.
setTokenRemoveFunction
(
token
->
{
redisTokenUtil
.
removeToken
(
token
);
return
null
;
});
vrLoginService
.
setTokenGetFunction
(
redisTokenUtil:
:
getUserByToken
);
}
@PostMapping
@PostMapping
@Operation
(
summary
=
"用户登录"
,
description
=
"手机号+密码登录,返回token"
)
@Operation
(
summary
=
"用户登录"
,
description
=
"手机号+密码登录,返回token"
)
...
@@ -57,7 +45,7 @@ public class VrLoginController {
...
@@ -57,7 +45,7 @@ public class VrLoginController {
@Operation
(
summary
=
"退出登录"
,
description
=
"清除token,退出当前账号"
)
@Operation
(
summary
=
"退出登录"
,
description
=
"清除token,退出当前账号"
)
public
BaseResp
<
Void
>
logout
(
HttpServletRequest
request
)
{
public
BaseResp
<
Void
>
logout
(
HttpServletRequest
request
)
{
String
token
=
extractToken
(
request
);
String
token
=
extractToken
(
request
);
vrLoginService
.
logout
(
token
);
vrLoginService
.
logout
(
token
,
Optional
.
ofNullable
(
UserContext
.
getUser
()).
orElseThrow
(()
->
new
BusinessCodeException
(
ErrorCodeEnum
.
LOGIN_ERROR
))
);
return
BaseResp
.
success
();
return
BaseResp
.
success
();
}
}
...
@@ -65,13 +53,24 @@ public class VrLoginController {
...
@@ -65,13 +53,24 @@ public class VrLoginController {
@Operation
(
summary
=
"获取登录用户信息"
,
description
=
"获取当前登录用户的详细信息"
)
@Operation
(
summary
=
"获取登录用户信息"
,
description
=
"获取当前登录用户的详细信息"
)
public
BaseResp
<
VrLoginUserVO
>
getUserInfo
(
HttpServletRequest
request
)
{
public
BaseResp
<
VrLoginUserVO
>
getUserInfo
(
HttpServletRequest
request
)
{
// 优先从上下文获取
// 优先从上下文获取
LoginUserDTO
loginUserDTO
=
Optional
.
ofNullable
(
UserContext
.
getUser
()).
orElseThrow
(()
->
new
BusinessCodeException
(
ErrorCodeEnum
.
LOGIN_ERROR
));
VrLoginUserVO
userVO
=
vrLoginService
.
getLoginUserInfo
(
loginUserDTO
);
return
BaseResp
.
success
(
userVO
);
}
/**
* 获取当前登录设备列表(自动清理过期token)
*/
@GetMapping
(
"/devices"
)
@Operation
(
summary
=
"获取登录设备列表"
,
description
=
"获取当前用户的所有登录设备,自动清理已过期设备"
)
public
BaseResp
<
Set
<
String
>>
getLoginDevices
(
HttpServletRequest
request
)
{
LoginUserDTO
userDTO
=
UserContext
.
getUser
();
LoginUserDTO
userDTO
=
UserContext
.
getUser
();
if
(
userDTO
!=
null
)
{
if
(
userDTO
!=
null
)
{
String
token
=
extractToken
(
request
);
// 调用getUserValidTokens会自动清理过期token
VrLoginUserVO
userVO
=
vrLoginService
.
getLoginUserInfo
(
token
);
Set
<
String
>
devices
=
redisTokenUtil
.
getUserValidTokens
(
userDTO
.
getPhone
()
);
return
BaseResp
.
success
(
userVO
);
return
BaseResp
.
success
(
devices
);
}
}
return
BaseResp
.
fail
(
"401"
,
"用户未登录"
);
return
BaseResp
.
fail
(
ErrorCodeEnum
.
LOGIN_ERROR
);
}
}
private
String
extractToken
(
HttpServletRequest
request
)
{
private
String
extractToken
(
HttpServletRequest
request
)
{
...
@@ -84,4 +83,5 @@ public class VrLoginController {
...
@@ -84,4 +83,5 @@ public class VrLoginController {
}
}
return
token
;
return
token
;
}
}
}
}
aus-vr/src/main/java/com/glsx/usedcar/controller/VrUserController.java
View file @
05505ab
package
com
.
glsx
.
usedcar
.
controller
;
package
com
.
glsx
.
usedcar
.
controller
;
import
com.glsx.usedcar.module.vrsystem.dto.LoginUserDTO
;
import
com.glsx.usedcar.module.vrsystem.service.VrUserService
;
import
com.glsx.usedcar.module.vrsystem.service.VrUserService
;
import
com.glsx.usedcar.module.vrsystem.util.PasswordStrengthUtil
;
import
com.glsx.usedcar.module.vrsystem.vo.*
;
import
com.glsx.usedcar.module.vrsystem.vo.*
;
import
com.glsx.usedcar.resp.BaseResp
;
import
com.glsx.usedcar.resp.BaseResp
;
import
com.glsx.usedcar.util.UserContext
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.Parameter
;
import
io.swagger.v3.oas.annotations.Parameter
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
jakarta.validation.Valid
;
import
jakarta.validation.Valid
;
import
jakarta.validation.constraints.NotBlank
;
import
jakarta.validation.constraints.Size
;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Page
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
org.summerframework.core.enums.ErrorCodeEnum
;
import
org.summerframework.core.exception.BusinessCodeException
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Optional
;
/**
/**
* VR用户管理接口
* VR用户管理接口
...
@@ -57,7 +65,7 @@ public class VrUserController {
...
@@ -57,7 +65,7 @@ public class VrUserController {
}
}
@PostMapping
(
"/updateStatus"
)
@PostMapping
(
"/updateStatus"
)
@Operation
(
summary
=
"启用/停用用户"
,
description
=
"切换用户状态,1=正常 0=停用"
)
@Operation
(
summary
=
"启用/停用用户"
,
description
=
"切换用户状态,1=正常 0=停用
。禁用用户时会强制退出所有登录设备
"
)
public
BaseResp
<
Void
>
updateStatus
(
@Valid
@RequestBody
VrUserStatusVO
statusVO
)
{
public
BaseResp
<
Void
>
updateStatus
(
@Valid
@RequestBody
VrUserStatusVO
statusVO
)
{
vrUserService
.
updateStatus
(
statusVO
.
getId
(),
statusVO
.
getStatus
());
vrUserService
.
updateStatus
(
statusVO
.
getId
(),
statusVO
.
getStatus
());
return
BaseResp
.
success
();
return
BaseResp
.
success
();
...
@@ -72,7 +80,8 @@ public class VrUserController {
...
@@ -72,7 +80,8 @@ public class VrUserController {
}
}
@PostMapping
(
"/updatePassword/{id}"
)
@PostMapping
(
"/updatePassword/{id}"
)
@Operation
(
summary
=
"修改密码"
,
description
=
"修改用户登录密码,密码长度6-20位,支持大小写字母、数字及特殊字符"
)
@Deprecated
@Operation
(
summary
=
"修改密码"
,
description
=
"修改用户登录密码,密码长度6-20位,支持大小写字母、数字及特殊字符"
,
deprecated
=
true
)
public
BaseResp
<
Void
>
updatePassword
(
public
BaseResp
<
Void
>
updatePassword
(
@Parameter
(
description
=
"用户ID"
,
required
=
true
,
example
=
"1"
)
@PathVariable
Long
id
,
@Parameter
(
description
=
"用户ID"
,
required
=
true
,
example
=
"1"
)
@PathVariable
Long
id
,
@Valid
@RequestBody
VrUserPasswordVO
passwordVO
)
{
@Valid
@RequestBody
VrUserPasswordVO
passwordVO
)
{
...
@@ -94,6 +103,40 @@ public class VrUserController {
...
@@ -94,6 +103,40 @@ public class VrUserController {
return
BaseResp
.
success
(
vrUserService
.
summary
());
return
BaseResp
.
success
(
vrUserService
.
summary
());
}
}
/**
* ==================== 当前登录用户接口 ====================
*/
@PostMapping
(
"/changePassword"
)
@Operation
(
summary
=
"修改密码"
,
description
=
"当前登录用户修改自己的密码,需验证旧密码,成功后强制退出所有登录设备"
)
public
BaseResp
<
Void
>
changePassword
(
@Valid
@RequestBody
VrUserChangePasswordVO
passwordVO
)
{
// 前端校验:新密码与确认密码一致性
if
(!
passwordVO
.
getNewPassword
().
equals
(
passwordVO
.
getConfirmPassword
()))
{
throw
new
BusinessCodeException
(
ErrorCodeEnum
.
VR_PASSWORD_NOT_SAME
);
}
// 获取当前登录用户
LoginUserDTO
currentUser
=
Optional
.
ofNullable
(
UserContext
.
getUser
()).
orElseThrow
(()
->
new
BusinessCodeException
(
ErrorCodeEnum
.
LOGIN_ERROR
));
vrUserService
.
changePassword
(
currentUser
.
getUserId
(),
passwordVO
);
return
BaseResp
.
success
();
}
@GetMapping
(
"/passwordStrength"
)
@Operation
(
summary
=
"密码强度评估"
,
description
=
"实时评估密码强度等级:弱(红色)/中(橙色)/强(绿色)"
)
public
BaseResp
<
Map
<
String
,
String
>>
evaluatePasswordStrength
(
@Parameter
(
description
=
"密码"
,
required
=
true
,
example
=
"Pass123!"
)
@NotBlank
(
message
=
"密码不能为空"
)
@Size
(
min
=
6
,
max
=
20
,
message
=
"密码长度必须在6-20个字符之间"
)
@RequestParam
String
password
)
{
PasswordStrengthUtil
.
StrengthLevel
level
=
PasswordStrengthUtil
.
evaluate
(
password
);
return
BaseResp
.
success
(
Map
.
of
(
"level"
,
level
.
name
(),
"label"
,
level
.
getLabel
(),
"color"
,
level
.
getColor
()
));
}
public
static
void
main
(
String
[]
var0
)
{
public
static
void
main
(
String
[]
var0
)
{
BCryptPasswordEncoder
var1
=
new
BCryptPasswordEncoder
();
BCryptPasswordEncoder
var1
=
new
BCryptPasswordEncoder
();
String
[]
var2
=
new
String
[]{
"15770727626"
};
String
[]
var2
=
new
String
[]{
"15770727626"
};
...
...
aus-vr/src/main/java/com/glsx/usedcar/interceptor/VrLoginInterceptor.java
View file @
05505ab
package
com
.
glsx
.
usedcar
.
interceptor
;
package
com
.
glsx
.
usedcar
.
interceptor
;
import
com.alibaba.fastjson2.JSON
;
import
com.alibaba.fastjson2.JSON
;
import
com.glsx.usedcar.consts.vr.CommonConsts
;
import
com.glsx.usedcar.resp.BaseResp
;
import
com.glsx.usedcar.resp.BaseResp
;
import
com.glsx.usedcar.util.UserContext
;
import
com.glsx.usedcar.util.UserContext
;
import
jakarta.servlet.http.HttpServletRequest
;
import
jakarta.servlet.http.HttpServletRequest
;
...
@@ -10,6 +11,7 @@ import lombok.extern.slf4j.Slf4j;
...
@@ -10,6 +11,7 @@ import lombok.extern.slf4j.Slf4j;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.servlet.HandlerInterceptor
;
import
org.springframework.web.servlet.HandlerInterceptor
;
import
org.summerframework.core.enums.ErrorCodeEnum
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.List
;
...
@@ -23,32 +25,13 @@ import java.util.List;
...
@@ -23,32 +25,13 @@ import java.util.List;
@RequiredArgsConstructor
@RequiredArgsConstructor
public
class
VrLoginInterceptor
implements
HandlerInterceptor
{
public
class
VrLoginInterceptor
implements
HandlerInterceptor
{
private
final
List
<
String
>
excludePaths
=
List
.
of
(
"/rest/login"
,
"/rest/login/"
,
"/swagger-ui"
,
"/v3/api-docs"
,
"/doc.html"
,
"/webjars"
,
"/favicon.ico"
);
@Override
@Override
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
throws
IOException
{
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
throws
IOException
{
String
uri
=
request
.
getRequestURI
();
// 排除路径
for
(
String
path
:
excludePaths
)
{
if
(
uri
.
startsWith
(
path
))
{
return
true
;
}
}
// 检查登录状态
// 检查登录状态
if
(
UserContext
.
getUser
()
==
null
)
{
if
(
UserContext
.
getUser
()
==
null
)
{
response
.
setStatus
(
HttpStatus
.
UNAUTHORIZED
.
value
());
response
.
setStatus
(
HttpStatus
.
UNAUTHORIZED
.
value
());
response
.
setContentType
(
"application/json;charset=UTF-8"
);
response
.
setContentType
(
CommonConsts
.
JSON_WITH_UTF8
);
BaseResp
<
Void
>
resp
=
BaseResp
.
fail
(
"401"
,
"用户未登录或登录已过期"
);
BaseResp
<
Void
>
resp
=
BaseResp
.
fail
(
ErrorCodeEnum
.
LOGIN_ERROR
);
response
.
getWriter
().
write
(
JSON
.
toJSONString
(
resp
));
response
.
getWriter
().
write
(
JSON
.
toJSONString
(
resp
));
return
false
;
return
false
;
}
}
...
...
aus-vr/src/main/java/com/glsx/usedcar/interceptor/VrTokenInterceptor.java
View file @
05505ab
package
com
.
glsx
.
usedcar
.
interceptor
;
package
com
.
glsx
.
usedcar
.
interceptor
;
import
com.glsx.usedcar.module.vrsystem.dto.LoginUserDTO
;
import
com.glsx.usedcar.module.vrsystem.dto.LoginUserDTO
;
import
com.glsx.usedcar.util.RedisTokenUtil
;
import
com.glsx.usedcar.
module.vrsystem.
util.RedisTokenUtil
;
import
com.glsx.usedcar.util.UserContext
;
import
com.glsx.usedcar.util.UserContext
;
import
jakarta.servlet.http.HttpServletRequest
;
import
jakarta.servlet.http.HttpServletRequest
;
import
jakarta.servlet.http.HttpServletResponse
;
import
jakarta.servlet.http.HttpServletResponse
;
...
@@ -36,10 +36,13 @@ public class VrTokenInterceptor implements HandlerInterceptor {
...
@@ -36,10 +36,13 @@ public class VrTokenInterceptor implements HandlerInterceptor {
LoginUserDTO
userDTO
=
redisTokenUtil
.
getUserByToken
(
token
);
LoginUserDTO
userDTO
=
redisTokenUtil
.
getUserByToken
(
token
);
if
(
userDTO
!=
null
)
{
if
(
userDTO
!=
null
)
{
// 存入上下文
// 校验token是否在用户的token集合中(只校验,不清理)
UserContext
.
setUser
(
userDTO
);
if
(
redisTokenUtil
.
isTokenInUserSet
(
userDTO
.
getPhone
(),
token
))
{
// 刷新token过期时间
// 存入上下文
redisTokenUtil
.
refreshToken
(
token
,
userDTO
);
UserContext
.
setUser
(
userDTO
);
// 刷新token过期时间
redisTokenUtil
.
refreshToken
(
token
);
}
}
}
}
}
...
...
aus-vr/src/main/java/com/glsx/usedcar/security/SpringSecurityAuditor.java
View file @
05505ab
package
com
.
glsx
.
usedcar
.
security
;
package
com
.
glsx
.
usedcar
.
security
;
import
com.glsx.usedcar.module.inspect.entity.Inspector
;
import
com.glsx.usedcar.module.inspect.entity.Inspector
;
import
com.glsx.usedcar.module.vrsystem.dto.LoginUserDTO
;
import
com.glsx.usedcar.util.UserContext
;
import
org.springframework.data.domain.AuditorAware
;
import
org.springframework.data.domain.AuditorAware
;
import
java.util.Optional
;
import
java.util.Optional
;
...
@@ -9,6 +11,8 @@ public class SpringSecurityAuditor implements AuditorAware<String> {
...
@@ -9,6 +11,8 @@ public class SpringSecurityAuditor implements AuditorAware<String> {
@Override
@Override
public
Optional
<
String
>
getCurrentAuditor
()
{
public
Optional
<
String
>
getCurrentAuditor
()
{
return
Optional
.
of
(
"系统默认"
);
return
Optional
.
ofNullable
(
UserContext
.
getUser
())
.
map
(
LoginUserDTO:
:
getUserName
)
.
or
(
"anonymous"
::
describeConstable
);
}
}
}
}
aus-vr/src/main/java/com/glsx/usedcar/util/RedisTokenUtil.java
deleted
100644 → 0
View file @
5a60909
package
com
.
glsx
.
usedcar
.
util
;
import
com.glsx.usedcar.module.vrsystem.config.VrLoginProperties
;
import
com.glsx.usedcar.module.vrsystem.dto.LoginUserDTO
;
import
lombok.RequiredArgsConstructor
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.stereotype.Component
;
import
java.util.Set
;
import
java.util.concurrent.TimeUnit
;
/**
* Redis Token 工具类
*/
@Component
@RequiredArgsConstructor
public
class
RedisTokenUtil
{
private
final
StringRedisTemplate
redisTemplate
;
private
final
VrLoginProperties
loginProperties
;
/**
* 存储Token
*/
public
void
storeToken
(
String
token
,
LoginUserDTO
userDTO
)
{
String
tokenKey
=
loginProperties
.
getTokenPrefix
()
+
token
;
String
userTokenKey
=
loginProperties
.
getUserTokenPrefix
()
+
userDTO
.
getPhone
();
// 存储token -> 用户信息
redisTemplate
.
opsForValue
().
set
(
tokenKey
,
toJson
(
userDTO
),
loginProperties
.
getTokenExpire
(),
TimeUnit
.
SECONDS
);
// 存储手机号 -> token集合
redisTemplate
.
opsForSet
().
add
(
userTokenKey
,
token
);
redisTemplate
.
expire
(
userTokenKey
,
loginProperties
.
getTokenExpire
(),
TimeUnit
.
SECONDS
);
}
/**
* 根据Token获取用户信息
*/
public
LoginUserDTO
getUserByToken
(
String
token
)
{
String
tokenKey
=
loginProperties
.
getTokenPrefix
()
+
token
;
String
json
=
redisTemplate
.
opsForValue
().
get
(
tokenKey
);
return
json
!=
null
?
fromJson
(
json
)
:
null
;
}
/**
* 刷新Token过期时间
*/
public
void
refreshToken
(
String
token
,
LoginUserDTO
userDTO
)
{
String
tokenKey
=
loginProperties
.
getTokenPrefix
()
+
token
;
String
userTokenKey
=
loginProperties
.
getUserTokenPrefix
()
+
userDTO
.
getPhone
();
redisTemplate
.
expire
(
tokenKey
,
loginProperties
.
getTokenExpire
(),
TimeUnit
.
SECONDS
);
redisTemplate
.
expire
(
userTokenKey
,
loginProperties
.
getTokenExpire
(),
TimeUnit
.
SECONDS
);
}
/**
* 删除Token
*/
public
void
removeToken
(
String
token
)
{
LoginUserDTO
userDTO
=
getUserByToken
(
token
);
if
(
userDTO
!=
null
)
{
String
tokenKey
=
loginProperties
.
getTokenPrefix
()
+
token
;
String
userTokenKey
=
loginProperties
.
getUserTokenPrefix
()
+
userDTO
.
getPhone
();
redisTemplate
.
delete
(
tokenKey
);
redisTemplate
.
opsForSet
().
remove
(
userTokenKey
,
token
);
}
}
/**
* 清除用户所有Token(禁用用户时使用)
*/
public
void
clearUserTokens
(
String
phone
)
{
String
userTokenKey
=
loginProperties
.
getUserTokenPrefix
()
+
phone
;
Set
<
String
>
tokens
=
redisTemplate
.
opsForSet
().
members
(
userTokenKey
);
if
(
tokens
!=
null
&&
!
tokens
.
isEmpty
())
{
// 删除所有token
for
(
String
token
:
tokens
)
{
String
tokenKey
=
loginProperties
.
getTokenPrefix
()
+
token
;
redisTemplate
.
delete
(
tokenKey
);
}
// 删除手机号-token映射
redisTemplate
.
delete
(
userTokenKey
);
}
}
private
String
toJson
(
LoginUserDTO
userDTO
)
{
return
String
.
format
(
"{\"userId\":%d,\"phone\":\"%s\",\"userName\":\"%s\",\"roleId\":%s,\"orgId\":%s}"
,
userDTO
.
getUserId
(),
userDTO
.
getPhone
(),
userDTO
.
getUserName
(),
userDTO
.
getRoleId
()
!=
null
?
userDTO
.
getRoleId
()
:
"null"
,
userDTO
.
getOrgId
()
!=
null
?
userDTO
.
getOrgId
()
:
"null"
);
}
private
LoginUserDTO
fromJson
(
String
json
)
{
LoginUserDTO
dto
=
new
LoginUserDTO
();
json
=
json
.
replaceAll
(
"[{}\\\"]"
,
""
);
String
[]
pairs
=
json
.
split
(
","
);
for
(
String
pair
:
pairs
)
{
String
[]
kv
=
pair
.
split
(
":"
);
if
(
kv
.
length
==
2
)
{
switch
(
kv
[
0
])
{
case
"userId"
->
dto
.
setUserId
(
Long
.
parseLong
(
kv
[
1
]));
case
"phone"
->
dto
.
setPhone
(
kv
[
1
]);
case
"userName"
->
dto
.
setUserName
(
kv
[
1
]);
case
"roleId"
->
dto
.
setRoleId
(
"null"
.
equals
(
kv
[
1
])
?
null
:
Long
.
parseLong
(
kv
[
1
]));
case
"orgId"
->
dto
.
setOrgId
(
"null"
.
equals
(
kv
[
1
])
?
null
:
Long
.
parseLong
(
kv
[
1
]));
}
}
}
return
dto
;
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment