Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
王蔡翾
project_assessment
Commits
4b7cd60c
Commit
4b7cd60c
authored
Dec 08, 2025
by
王蔡翾
Browse files
项目和考核
parent
1d964e64
Changes
25
Show whitespace changes
Inline
Side-by-side
project-business/src/main/java/com/platform/projectBusiness/util/JwtUtil.java
View file @
4b7cd60c
...
@@ -49,4 +49,80 @@ public class JwtUtil {
...
@@ -49,4 +49,80 @@ public class JwtUtil {
.
parseClaimsJws
(
token
)
.
parseClaimsJws
(
token
)
.
getBody
();
.
getBody
();
}
}
/**
* 解析 Token 并直接返回 userName
* @param token JWT Token
* @return 用户名
* @throws RuntimeException 当 Token 无效或解析失败时抛出
*/
public
String
getUserNameFromToken
(
String
token
)
{
try
{
Claims
claims
=
parseToken
(
token
);
String
userName
=
claims
.
get
(
"userName"
,
String
.
class
);
if
(
userName
==
null
||
userName
.
trim
().
isEmpty
())
{
throw
new
RuntimeException
(
"Token 中缺少 userName 字段"
);
}
return
userName
;
}
catch
(
io
.
jsonwebtoken
.
ExpiredJwtException
e
)
{
throw
new
RuntimeException
(
"Token 已过期"
);
}
catch
(
io
.
jsonwebtoken
.
MalformedJwtException
e
)
{
throw
new
RuntimeException
(
"Token 格式错误"
);
}
catch
(
io
.
jsonwebtoken
.
SignatureException
e
)
{
throw
new
RuntimeException
(
"Token 签名无效"
);
}
catch
(
io
.
jsonwebtoken
.
UnsupportedJwtException
e
)
{
throw
new
RuntimeException
(
"不支持的 Token 格式"
);
}
catch
(
IllegalArgumentException
e
)
{
throw
new
RuntimeException
(
"Token 参数异常"
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"Token 解析失败: "
+
e
.
getMessage
());
}
}
/**
* 安全版本的解析方法,返回 null 而不是抛出异常
* @param token JWT Token
* @return 用户名,解析失败返回 null
*/
public
String
getUserNameFromTokenSafe
(
String
token
)
{
try
{
return
getUserNameFromToken
(
token
);
}
catch
(
Exception
e
)
{
// 记录日志但不抛出异常
System
.
err
.
println
(
"解析 Token 失败: "
+
e
.
getMessage
());
return
null
;
}
}
/**
* 从 Authorization Header 中提取并解析 userName
* @param authHeader Authorization Header 值(格式:Bearer <token>)
* @return 用户名
* @throws RuntimeException 当 Header 格式错误或 Token 解析失败时抛出
*/
public
String
getUserNameFromAuthHeader
(
String
authHeader
)
{
if
(
authHeader
==
null
||
!
authHeader
.
startsWith
(
"Bearer "
))
{
throw
new
RuntimeException
(
"Authorization Header 格式错误,应为: Bearer <token>"
);
}
String
token
=
authHeader
.
substring
(
7
).
trim
();
return
getUserNameFromToken
(
token
);
}
/**
* 验证 Token 是否有效且包含 userName
* @param token JWT Token
* @return 是否有效
*/
public
boolean
validateTokenAndHasUserName
(
String
token
)
{
try
{
Claims
claims
=
parseToken
(
token
);
String
userName
=
claims
.
get
(
"userName"
,
String
.
class
);
return
userName
!=
null
&&
!
userName
.
trim
().
isEmpty
();
}
catch
(
Exception
e
)
{
return
false
;
}
}
}
}
project-business/src/main/resources/mapper/BsProjectMapper.xml
View file @
4b7cd60c
...
@@ -9,7 +9,8 @@
...
@@ -9,7 +9,8 @@
create_time,
create_time,
delivery_date,
delivery_date,
description,
description,
status
status,
cycle
from
from
bs_project
bs_project
<where>
<where>
...
...
project-business/src/main/resources/mapper/BsProjectPeopleScoreDetailMapper.xml
View file @
4b7cd60c
...
@@ -13,7 +13,8 @@
...
@@ -13,7 +13,8 @@
score,
score,
percentage,
percentage,
level,
level,
status
status,
assessment_id
from
from
bs_project_people_score_detail
bs_project_people_score_detail
<where>
<where>
...
@@ -26,6 +27,9 @@
...
@@ -26,6 +27,9 @@
<if
test=
"status != null and status != ''"
>
<if
test=
"status != null and status != ''"
>
status = #{status}
status = #{status}
</if>
</if>
<if
test=
"assessmentId != null and assessmentId != ''"
>
assessment_id = #{assessmentId}
</if>
</where>
</where>
</select>
</select>
...
...
project-business/src/main/resources/mapper/BsProjectPeopleScoreMapper.xml
View file @
4b7cd60c
...
@@ -19,6 +19,9 @@
...
@@ -19,6 +19,9 @@
<if
test=
"projectPeople != null and projectPeople != ''"
>
<if
test=
"projectPeople != null and projectPeople != ''"
>
project_people = #{projectPeople}
project_people = #{projectPeople}
</if>
</if>
<if
test=
"projectRole != null and projectRole != ''"
>
project_role = #{projectRole}
</if>
<if
test=
"status != null and status != ''"
>
<if
test=
"status != null and status != ''"
>
status = #{status}
status = #{status}
</if>
</if>
...
...
project-business/src/main/resources/mapper/SysUserMapper.xml
View file @
4b7cd60c
...
@@ -4,15 +4,22 @@
...
@@ -4,15 +4,22 @@
<mapper
namespace=
"com.platform.projectBusiness.mapper.SysUserMapper"
>
<mapper
namespace=
"com.platform.projectBusiness.mapper.SysUserMapper"
>
<select
id=
"queryUserList"
resultType=
"com.platform.projectBusiness.model.vo.SysUserVO"
>
<select
id=
"queryUserList"
resultType=
"com.platform.projectBusiness.model.vo.SysUserVO"
>
select
select
id,
su.id as id,
user_name,
su.user_name as userName,
nick_name,
su.nick_name as nickName,
phone,
su.phone as phone,
email,
su.email as email,
password,
su.password as password,
role_id
sr.name as roleName,
sd.name as deptName
from
from
sys_user
sys_user su
left join
sys_role sr
on su.role_id = sr.id
left join
sys_dept sd
on sd.id = sr.dept_id
<where>
<where>
<if
test=
"userName != null and userName != ''"
>
<if
test=
"userName != null and userName != ''"
>
user_name =#{userName}
user_name =#{userName}
...
...
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
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 comment