Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
有来技术
youlai-mall
提交
742d9b5b
Y
youlai-mall
项目概览
有来技术
/
youlai-mall
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
youlai-mall
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
742d9b5b
编写于
1月 27, 2022
作者:
郝
郝先瑞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(SysDeptServiceImpl): 修复超级管理员部门为null查询部门列表报错问题
上级
92de8e35
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
51 addition
and
9 deletion
+51
-9
youlai-admin/admin-boot/src/main/java/com/youlai/admin/constant/SystemConstants.java
.../main/java/com/youlai/admin/constant/SystemConstants.java
+5
-3
youlai-admin/admin-boot/src/main/java/com/youlai/admin/service/impl/SysDeptServiceImpl.java
...ava/com/youlai/admin/service/impl/SysDeptServiceImpl.java
+19
-3
youlai-common/common-web/src/main/java/com/youlai/common/web/util/JwtUtils.java
...eb/src/main/java/com/youlai/common/web/util/JwtUtils.java
+27
-3
未找到文件。
youlai-admin/admin-boot/src/main/java/com/youlai/admin/constant/SystemConstants.java
浏览文件 @
742d9b5b
...
...
@@ -9,7 +9,7 @@ package com.youlai.admin.constant;
public
interface
SystemConstants
{
/**
*
根部门ID
* 根部门ID
*/
Long
ROOT_DEPT_ID
=
0
l
;
...
...
@@ -23,6 +23,8 @@ public interface SystemConstants {
*/
String
DEFAULT_USER_PASSWORD
=
"123456"
;
/**
* 超级管理员角色编码
*/
String
ROOT_ROLE_CODE
=
"ROOT"
;
}
youlai-admin/admin-boot/src/main/java/com/youlai/admin/service/impl/SysDeptServiceImpl.java
浏览文件 @
742d9b5b
...
...
@@ -120,8 +120,24 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
.
eq
(
SysDept:
:
getStatus
,
GlobalConstants
.
STATUS_YES
)
.
orderByAsc
(
SysDept:
:
getSort
)
);
SysDept
sysDept
=
this
.
getById
(
JwtUtils
.
getJwtPayload
().
getLong
(
"deptId"
));
List
<
IdLabelVO
>
deptSelectList
=
recursionTreeSelectList
(
sysDept
.
getParentId
(),
deptList
);
boolean
isRoot
=
JwtUtils
.
isRoot
();
Long
parentId
;
if
(
isRoot
)
{
// 超级管理员
parentId
=
SystemConstants
.
ROOT_DEPT_ID
;
}
else
{
Long
deptId
=
JwtUtils
.
getDeptId
();
if
(
deptId
==
null
)
{
return
Collections
.
emptyList
();
}
SysDept
dept
=
this
.
getById
(
deptId
);
if
(
dept
==
null
)
{
return
Collections
.
emptyList
();
}
parentId
=
dept
.
getParentId
();
}
List
<
IdLabelVO
>
deptSelectList
=
recursionTreeSelectList
(
parentId
,
deptList
);
return
deptSelectList
;
}
...
...
@@ -161,7 +177,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
// 生成部门树路径
String
treePath
=
generateDeptTreePath
(
dept
);
dept
.
setTreePath
(
treePath
);
boolean
result
=
this
.
saveOrUpdate
(
dept
);
Assert
.
isTrue
(
result
,
"保存部门出错"
);
return
dept
.
getId
();
...
...
youlai-common/common-web/src/main/java/com/youlai/common/web/util/JwtUtils.java
浏览文件 @
742d9b5b
package
com.youlai.common.web.util
;
import
cn.hutool.core.collection.CollectionUtil
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONUtil
;
import
com.youlai.common.constant.SecurityConstants
;
...
...
@@ -11,6 +12,8 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import
java.net.URLDecoder
;
import
java.nio.charset.StandardCharsets
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
/**
...
...
@@ -27,7 +30,7 @@ public class JwtUtils {
if
(
null
==
payload
)
{
throw
new
BizException
(
"请传入认证头"
);
}
JSONObject
jsonObject
=
JSONUtil
.
parseObj
(
URLDecoder
.
decode
(
payload
,
StandardCharsets
.
UTF_8
.
name
()));
JSONObject
jsonObject
=
JSONUtil
.
parseObj
(
URLDecoder
.
decode
(
payload
,
StandardCharsets
.
UTF_8
.
name
()));
return
jsonObject
;
}
...
...
@@ -41,6 +44,16 @@ public class JwtUtils {
return
id
;
}
/**
* 解析JWT获取用户ID
*
* @return
*/
public
static
Long
getDeptId
()
{
Long
id
=
getJwtPayload
().
getLong
(
"deptId"
);
return
id
;
}
/**
* 解析JWT获取获取用户名
*
...
...
@@ -52,18 +65,29 @@ public class JwtUtils {
}
/**
* JWT获取用户角色列表
*
* @return 角色列表
*/
public
static
List
<
String
>
getRoles
()
{
List
<
String
>
roles
=
null
;
List
<
String
>
roles
;
JSONObject
payload
=
getJwtPayload
();
if
(
payload
.
containsKey
(
SecurityConstants
.
JWT_AUTHORITIES_KEY
))
{
roles
=
payload
.
getJSONArray
(
SecurityConstants
.
JWT_AUTHORITIES_KEY
).
toList
(
String
.
class
);
}
else
{
roles
=
Collections
.
emptyList
();
}
return
roles
;
}
/**
* 是否「超级管理员」
*
* @return
*/
public
static
boolean
isRoot
()
{
List
<
String
>
roles
=
getRoles
();
return
CollectionUtil
.
isNotEmpty
(
roles
)
&&
roles
.
contains
(
"ROOT"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录