Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
custom-server
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lizhonghong
custom-server
Commits
e1ab500e
Commit
e1ab500e
authored
Jul 16, 2026
by
Lizh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化原代码中的sql硬编码问题
parent
3eb5fde9
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
153 additions
and
86 deletions
+153
-86
custom-server-app/src/main/java/com/jomalls/custom/app/constant/RoleConstants.java
+5
-0
custom-server-app/src/main/java/com/jomalls/custom/app/service/system/impl/SysDeptServiceImpl.java
+11
-7
custom-server-app/src/main/java/com/jomalls/custom/app/service/system/impl/SysLoginServiceImpl.java
+0
-2
custom-server-app/src/main/java/com/jomalls/custom/app/service/system/impl/SysRoleServiceImpl.java
+25
-32
custom-server-core/src/main/java/com/jomalls/custom/security/TokenHandle.java
+27
-24
custom-server-domain/src/main/java/com/jomalls/custom/dal/mapper/SysUserMapper.java
+21
-0
custom-server-domain/src/main/java/com/jomalls/custom/domain/service/system/SysUserDomainService.java
+13
-0
custom-server-domain/src/main/java/com/jomalls/custom/domain/service/system/impl/SysUserDomainServiceImpl.java
+14
-1
custom-server-domain/src/main/resources/mapper/SysUserMapper.xml
+30
-0
custom-server-starter/src/main/java/com/jomalls/custom/config/CommonExceptionHandlerAdvice.java
+2
-2
custom-server-webapp/src/main/java/com/jomalls/custom/webapp/controller/system/SysRoleController.java
+5
-18
No files found.
custom-server-app/src/main/java/com/jomalls/custom/app/constant/RoleConstants.java
View file @
e1ab500e
...
...
@@ -13,6 +13,11 @@ public class RoleConstants {
public
static
final
String
ADMIN_USER
=
"admin"
;
/**
* 超级管理员admin ID
*/
public
static
final
Long
ADMIN_ID
=
1L
;
/**
* 角色状态
*/
public
static
final
String
STATUS_NORMAL
=
"0"
;
...
...
custom-server-app/src/main/java/com/jomalls/custom/app/service/system/impl/SysDeptServiceImpl.java
View file @
e1ab500e
...
...
@@ -9,6 +9,7 @@ import com.jomalls.custom.app.utils.BeanMapper;
import
com.jomalls.custom.app.vo.system.SysDeptVO
;
import
com.jomalls.custom.dal.entity.SysDeptEntity
;
import
com.jomalls.custom.domain.service.system.SysDeptDomainService
;
import
com.jomalls.custom.domain.service.system.SysUserDomainService
;
import
com.jomalls.custom.security.SecurityUtils
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -28,6 +29,9 @@ import java.util.List;
@RequiredArgsConstructor
public
class
SysDeptServiceImpl
implements
SysDeptService
{
private
final
static
String
CHAR_ZERO
=
"0"
;
private
final
static
long
NUMBER_ZERO
=
0L
;
private
final
SysDeptDomainService
sysDeptDomainService
;
@Override
...
...
@@ -45,8 +49,8 @@ public class SysDeptServiceImpl implements SysDeptService {
return
sysDeptDomainService
.
count
(
new
LambdaQueryWrapper
<
SysDeptEntity
>()
.
eq
(
SysDeptEntity:
:
getParentId
,
deptId
)
.
eq
(
SysDeptEntity:
:
getStatus
,
"0"
)
.
eq
(
SysDeptEntity:
:
getDelFlag
,
"0"
));
.
eq
(
SysDeptEntity:
:
getStatus
,
CHAR_ZERO
)
.
eq
(
SysDeptEntity:
:
getDelFlag
,
CHAR_ZERO
));
}
@Override
...
...
@@ -79,13 +83,13 @@ public class SysDeptServiceImpl implements SysDeptService {
long
count
=
sysDeptDomainService
.
count
(
new
LambdaQueryWrapper
<
SysDeptEntity
>()
.
eq
(
SysDeptEntity:
:
getDeptName
,
dept
.
getDeptName
())
.
eq
(
SysDeptEntity:
:
getParentId
,
dept
.
getParentId
()
!=
null
?
dept
.
getParentId
()
:
0L
)
.
eq
(
SysDeptEntity:
:
getParentId
,
dept
.
getParentId
()
!=
null
?
dept
.
getParentId
()
:
NUMBER_ZERO
)
.
ne
(
dept
.
getDeptId
()
!=
null
,
SysDeptEntity:
:
getDeptId
,
dept
.
getDeptId
()
!=
null
?
dept
.
getDeptId
()
:
-
1L
));
if
(
count
>
0
)
{
throw
new
ServiceException
(
"新增部门'"
+
dept
.
getDeptName
()
+
"'失败,部门名称已存在"
);
}
// 设置祖级列表
if
(
dept
.
getParentId
()
==
null
||
dept
.
getParentId
()
==
0L
)
{
if
(
dept
.
getParentId
()
==
null
||
dept
.
getParentId
()
==
NUMBER_ZERO
)
{
dept
.
setAncestors
(
"0"
);
}
else
{
SysDeptEntity
parentDept
=
sysDeptDomainService
.
getById
(
dept
.
getParentId
());
...
...
@@ -114,7 +118,7 @@ public class SysDeptServiceImpl implements SysDeptService {
long
count
=
sysDeptDomainService
.
count
(
new
LambdaQueryWrapper
<
SysDeptEntity
>()
.
eq
(
SysDeptEntity:
:
getDeptName
,
dept
.
getDeptName
())
.
eq
(
SysDeptEntity:
:
getParentId
,
dept
.
getParentId
()
!=
null
?
dept
.
getParentId
()
:
0L
)
.
eq
(
SysDeptEntity:
:
getParentId
,
dept
.
getParentId
()
!=
null
?
dept
.
getParentId
()
:
NUMBER_ZERO
)
.
ne
(
dept
.
getDeptId
()
!=
null
,
SysDeptEntity:
:
getDeptId
,
dept
.
getDeptId
()
!=
null
?
dept
.
getDeptId
()
:
-
1L
));
if
(
count
>
0
)
{
throw
new
ServiceException
(
"修改部门'"
+
dept
.
getDeptName
()
+
"'失败,部门名称已存在"
);
...
...
@@ -130,8 +134,8 @@ public class SysDeptServiceImpl implements SysDeptService {
boolean
parentChanged
=
dept
.
getParentId
()
!=
null
&&
!
dept
.
getParentId
().
equals
(
oldDept
.
getParentId
());
if
(
parentChanged
)
{
String
newAncestors
;
if
(
dept
.
getParentId
()
==
0L
)
{
newAncestors
=
"0"
;
if
(
dept
.
getParentId
()
==
NUMBER_ZERO
)
{
newAncestors
=
CHAR_ZERO
;
}
else
{
SysDeptEntity
newParent
=
sysDeptDomainService
.
getById
(
dept
.
getParentId
());
if
(
newParent
==
null
)
{
...
...
custom-server-app/src/main/java/com/jomalls/custom/app/service/system/impl/SysLoginServiceImpl.java
View file @
e1ab500e
...
...
@@ -8,7 +8,6 @@ import com.jomalls.custom.app.exception.ServiceException;
import
com.jomalls.custom.app.service.system.SysConfigService
;
import
com.jomalls.custom.app.service.system.SysLoginService
;
import
com.jomalls.custom.app.service.system.SysLogininforService
;
import
com.jomalls.custom.app.service.system.impl.SysPasswordService
;
import
com.jomalls.custom.app.utils.BeanMapper
;
import
com.jomalls.custom.app.utils.Convert
;
import
com.jomalls.custom.app.utils.DateUtils
;
...
...
@@ -24,7 +23,6 @@ import com.jomalls.custom.security.TokenHandle;
import
jakarta.servlet.http.HttpServletRequest
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.jspecify.annotations.Nullable
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.security.crypto.password.PasswordEncoder
;
import
org.springframework.stereotype.Service
;
...
...
custom-server-app/src/main/java/com/jomalls/custom/app/service/system/impl/SysRoleServiceImpl.java
View file @
e1ab500e
...
...
@@ -4,11 +4,14 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.jomalls.custom.app.constant.RoleConstants
;
import
com.jomalls.custom.app.constant.SecurityConstants
;
import
com.jomalls.custom.app.dto.system.SysRoleDataScopeDTO
;
import
com.jomalls.custom.app.dto.system.SysRoleSaveDTO
;
import
com.jomalls.custom.app.dto.system.SysRoleStatusDTO
;
import
com.jomalls.custom.app.dto.system.SysRoleUpdateDTO
;
import
com.jomalls.custom.app.exception.ServiceException
;
import
com.jomalls.custom.app.service.system.SysDeptService
;
import
com.jomalls.custom.app.service.system.SysMenuService
;
import
com.jomalls.custom.app.service.system.SysRoleService
;
import
com.jomalls.custom.app.utils.BeanMapper
;
import
com.jomalls.custom.app.vo.system.SysDeptVO
;
...
...
@@ -16,7 +19,9 @@ import com.jomalls.custom.app.vo.system.SysRoleVO;
import
com.jomalls.custom.app.vo.system.SysUserVO
;
import
com.jomalls.custom.dal.entity.*
;
import
com.jomalls.custom.domain.service.system.*
;
import
com.jomalls.custom.security.LoginUser
;
import
com.jomalls.custom.security.SecurityUtils
;
import
com.jomalls.custom.security.TokenHandle
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
...
...
@@ -42,6 +47,8 @@ public class SysRoleServiceImpl implements SysRoleService {
private
final
SysUserRoleDomainService
sysUserRoleDomainService
;
private
final
SysUserDomainService
sysUserDomainService
;
private
final
SysDeptDomainService
sysDeptDomainService
;
private
final
SysMenuDomainService
sysMenuDomainService
;
private
final
TokenHandle
tokenHandle
;
@Override
public
List
<
SysRoleVO
>
listAllRoles
()
{
...
...
@@ -154,6 +161,16 @@ public class SysRoleServiceImpl implements SysRoleService {
sysRoleMenuDomainService
.
save
(
roleMenu
);
}
}
// 角色修改后,刷新缓存用户权限
LoginUser
loginUser
=
SecurityUtils
.
getLoginUser
();
if
(
loginUser
!=
null
&&
loginUser
.
getUserId
()
!=
null
&&
SecurityConstants
.
ADMIN_USER_ID
.
equals
(
loginUser
.
getUserId
()))
{
// 重新查询权限
Set
<
String
>
perms
=
new
HashSet
<>();
List
<
String
>
permList
=
sysMenuDomainService
.
selectMenuPermsByUserId
(
loginUser
.
getUserId
());
if
(
permList
!=
null
)
perms
.
addAll
(
permList
);
loginUser
.
setPermissions
(
perms
);
tokenHandle
.
refreshToken
(
loginUser
);
}
log
.
info
(
"修改角色成功: roleId={}"
,
role
.
getRoleId
());
}
...
...
@@ -230,42 +247,18 @@ public class SysRoleServiceImpl implements SysRoleService {
@Override
public
IPage
<
SysUserVO
>
allocatedList
(
SysUserVO
user
,
Page
<
SysUserVO
>
page
)
{
LambdaQueryWrapper
<
SysUserEntity
>
wrapper
=
new
LambdaQueryWrapper
<>();
if
(
user
.
getRoleId
()
!=
null
)
{
wrapper
.
inSql
(
SysUserEntity:
:
getUserId
,
"SELECT user_id FROM sys_user_role WHERE role_id = "
+
user
.
getRoleId
());
}
if
(
StringUtils
.
hasText
(
user
.
getUserName
()))
{
wrapper
.
like
(
SysUserEntity:
:
getUserName
,
user
.
getUserName
());
}
if
(
StringUtils
.
hasText
(
user
.
getPhonenumber
()))
{
wrapper
.
like
(
SysUserEntity:
:
getPhonenumber
,
user
.
getPhonenumber
());
}
wrapper
.
eq
(
SysUserEntity:
:
getDelFlag
,
"0"
);
IPage
<
SysUserEntity
>
entityPage
=
sysUserDomainService
.
page
(
new
Page
<>(
page
.
getCurrent
(),
page
.
getSize
()),
wrapper
);
IPage
<
SysUserEntity
>
entityPage
=
sysUserDomainService
.
selectAllocatedByRoleId
(
new
Page
<>(
page
.
getCurrent
(),
page
.
getSize
()),
user
.
getRoleId
(),
user
.
getUserName
(),
user
.
getPhonenumber
());
return
entityPage
.
convert
(
e
->
BeanMapper
.
mapper
().
convert
(
e
,
SysUserVO
.
class
));
}
@Override
public
IPage
<
SysUserVO
>
unallocatedList
(
SysUserVO
user
,
Page
<
SysUserVO
>
page
)
{
LambdaQueryWrapper
<
SysUserEntity
>
wrapper
=
new
LambdaQueryWrapper
<>();
if
(
user
.
getRoleId
()
!=
null
)
{
wrapper
.
apply
(
"user_id NOT IN (SELECT user_id FROM sys_user_role WHERE role_id = {0})"
,
user
.
getRoleId
());
}
if
(
StringUtils
.
hasText
(
user
.
getUserName
()))
{
wrapper
.
like
(
SysUserEntity:
:
getUserName
,
user
.
getUserName
());
}
if
(
StringUtils
.
hasText
(
user
.
getPhonenumber
()))
{
wrapper
.
like
(
SysUserEntity:
:
getPhonenumber
,
user
.
getPhonenumber
());
}
wrapper
.
eq
(
SysUserEntity:
:
getDelFlag
,
"0"
);
IPage
<
SysUserEntity
>
entityPage
=
sysUserDomainService
.
page
(
new
Page
<>(
page
.
getCurrent
(),
page
.
getSize
()),
wrapper
);
// Entity → VO 转换
IPage
<
SysUserVO
>
voPage
=
new
Page
<>(
entityPage
.
getCurrent
(),
entityPage
.
getSize
(),
entityPage
.
getTotal
());
voPage
.
setRecords
(
BeanMapper
.
mapper
().
convertList
(
entityPage
.
getRecords
(),
SysUserVO
.
class
));
return
voPage
;
IPage
<
SysUserEntity
>
entityPage
=
sysUserDomainService
.
selectUnallocatedByRoleId
(
new
Page
<>(
page
.
getCurrent
(),
page
.
getSize
()),
user
.
getRoleId
(),
user
.
getUserName
(),
user
.
getPhonenumber
());
return
entityPage
.
convert
(
e
->
BeanMapper
.
mapper
().
convert
(
e
,
SysUserVO
.
class
));
}
@Override
...
...
@@ -318,7 +311,7 @@ public class SysRoleServiceImpl implements SysRoleService {
* 检查是否允许操作超级管理员角色
*/
private
void
checkRoleAllowed
(
SysRoleEntity
role
)
{
if
(
role
.
getRoleId
()
!=
null
&&
(
role
.
getRoleId
()
==
1L
||
"admin"
.
equals
(
role
.
getRoleKey
())))
{
if
(
role
.
getRoleId
()
!=
null
&&
(
RoleConstants
.
ADMIN_ID
.
equals
(
role
.
getRoleId
())
||
RoleConstants
.
ADMIN_USER
.
equals
(
role
.
getRoleKey
())))
{
throw
new
ServiceException
(
"不允许操作超级管理员角色"
);
}
}
...
...
custom-server-core/src/main/java/com/jomalls/custom/security/TokenHandle.java
View file @
e1ab500e
...
...
@@ -2,11 +2,11 @@ package com.jomalls.custom.security;
import
com.alibaba.fastjson2.JSON
;
import
com.alibaba.fastjson2.JSONObject
;
import
com.fasterxml.jackson.core.json.JsonWriteFeature
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.jomalls.custom.utils.UniqueId
;
import
io.jsonwebtoken.Claims
;
import
io.jsonwebtoken.JwtException
;
import
io.jsonwebtoken.Jwts
;
import
io.jsonwebtoken.security.Keys
;
import
jakarta.servlet.http.HttpServletRequest
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -15,7 +15,8 @@ import org.springframework.data.redis.core.StringRedisTemplate;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.StringUtils
;
import
javax.crypto.SecretKey
;
import
javax.crypto.Mac
;
import
javax.crypto.spec.SecretKeySpec
;
import
java.nio.charset.StandardCharsets
;
import
java.util.*
;
import
java.util.concurrent.TimeUnit
;
...
...
@@ -43,6 +44,13 @@ public class TokenHandle {
/** Redis key 前缀 */
private
static
final
String
REDIS_TOKEN_PREFIX
=
"login_tokens:"
;
/** JWT Base64URL 编码器(线程安全,复用) */
private
static
final
Base64
.
Encoder
B64_ENCODER
=
Base64
.
getUrlEncoder
().
withoutPadding
();
/** Jackson ObjectMapper(线程安全,复用) */
private
static
final
ObjectMapper
JWT_MAPPER
=
new
ObjectMapper
().
configure
(
JsonWriteFeature
.
ESCAPE_NON_ASCII
.
mappedFeature
(),
true
);
@Autowired
private
TokenCompatibilityParser
tokenCompatibilityParser
;
...
...
@@ -79,14 +87,14 @@ public class TokenHandle {
try
{
Claims
claims
=
parseToken
(
token
);
// 优先
走 custom-back 路径:
Redis 获取全量用户信息
// 优先
从
Redis 获取全量用户信息
LoginUser
loginUser
=
tryGetFromRedis
(
claims
);
if
(
loginUser
!=
null
)
{
loginUser
.
setToken
(
token
);
return
loginUser
;
}
//
回退:
从 JWT claims 直接提取
//
redis中未取到用户信息, 再
从 JWT claims 直接提取
loginUser
=
buildFromClaims
(
claims
);
if
(
loginUser
!=
null
)
{
loginUser
.
setToken
(
token
);
...
...
@@ -256,12 +264,12 @@ public class TokenHandle {
);
}
// 手动构建 JWT
(与 custom-back JJWT 0.9.1 HS512 + raw secret 字节级一致)
// 手动构建 JWT
return
buildJwtCompatibly
(
uuid
,
loginUser
);
}
/**
* 手动构建 JWT
(与 custom-back 格式完全一致)
* 手动构建 JWT
, 为了和custom的ts服务兼容, 原custom-back JJWT 0.9.1
* <p>
* Header: {"alg":"HS512"}
* Payload: {"login_user_key":uuid, "sub":username, "account":username, "id":userId, "exp":24h}
...
...
@@ -269,11 +277,9 @@ public class TokenHandle {
*/
private
String
buildJwtCompatibly
(
String
uuid
,
LoginUser
loginUser
)
{
try
{
// Base64URL 编码(与 JJWT 0.9.1 TextCodec.BASE64URL 兼容,适配custom的ts服务 使用同一格式)
Base64
.
Encoder
encoder
=
Base64
.
getUrlEncoder
().
withoutPadding
();
// Header: {"alg":"HS512"}
String
header
=
"{\"alg\":\"HS512\"}"
;
String
headerBase64
=
encoder
.
encodeToString
(
String
headerBase64
=
B64_ENCODER
.
encodeToString
(
header
.
getBytes
(
StandardCharsets
.
UTF_8
));
// Payload:基本标识 + deptId + permissions(前端从 JWT 解析 sysUser 信息)
...
...
@@ -284,27 +290,21 @@ public class TokenHandle {
claims
.
put
(
"id"
,
loginUser
.
getUserId
());
claims
.
put
(
"deptId"
,
loginUser
.
getDeptId
());
claims
.
put
(
"permissions"
,
loginUser
.
getPermissions
());
// JWT 24 小时硬过期(与 custom-back TOKEN_TIMEOUT = 86400000L 一致)
claims
.
put
(
"exp"
,
(
System
.
currentTimeMillis
()
+
86400000L
)
/
1000
);
// 使用 Jackson 序列化 claims,非 ASCII 字符转 \\uXXXX 转义
// 前端 atob() → JSON.parse() 无法正确解码 UTF-8 多字节字符
// \\uXXXX 全为 ASCII,前端可正常 parse
String
payload
=
new
com
.
fasterxml
.
jackson
.
databind
.
ObjectMapper
()
.
configure
(
com
.
fasterxml
.
jackson
.
core
.
json
.
JsonWriteFeature
.
ESCAPE_NON_ASCII
.
mappedFeature
(),
true
)
.
writeValueAsString
(
claims
);
String
payloadBase64
=
encoder
.
encodeToString
(
payload
.
getBytes
(
java
.
nio
.
charset
.
StandardCharsets
.
UTF_8
));
String
payload
=
JWT_MAPPER
.
writeValueAsString
(
claims
);
String
payloadBase64
=
B64_ENCODER
.
encodeToString
(
payload
.
getBytes
(
StandardCharsets
.
UTF_8
));
// HS512 签名(raw secret 字节,与 custom-back 一致)
String
headerPayload
=
headerBase64
+
"."
+
payloadBase64
;
javax
.
crypto
.
Mac
mac
=
javax
.
crypto
.
Mac
.
getInstance
(
"HmacSHA512"
);
javax
.
crypto
.
spec
.
SecretKeySpec
keySpec
=
new
javax
.
crypto
.
spec
.
SecretKeySpec
(
secret
.
getBytes
(
java
.
nio
.
charset
.
StandardCharsets
.
UTF_8
),
"HmacSHA512"
);
Mac
mac
=
Mac
.
getInstance
(
"HmacSHA512"
);
SecretKeySpec
keySpec
=
new
SecretKeySpec
(
secret
.
getBytes
(
StandardCharsets
.
UTF_8
),
"HmacSHA512"
);
mac
.
init
(
keySpec
);
byte
[]
signature
=
mac
.
doFinal
(
headerPayload
.
getBytes
(
java
.
nio
.
charset
.
StandardCharsets
.
UTF_8
));
String
signatureBase64
=
encoder
.
encodeToString
(
signature
);
headerPayload
.
getBytes
(
StandardCharsets
.
UTF_8
));
String
signatureBase64
=
B64_ENCODER
.
encodeToString
(
signature
);
return
headerBase64
+
"."
+
payloadBase64
+
"."
+
signatureBase64
;
}
catch
(
Exception
e
)
{
...
...
@@ -328,6 +328,9 @@ public class TokenHandle {
*/
public
String
getToken
(
HttpServletRequest
request
)
{
String
token
=
request
.
getHeader
(
header
);
if
(
token
==
null
)
{
return
null
;
}
String
[]
parts
=
token
.
trim
().
split
(
SPACE
);
if
(
parts
.
length
>
1
)
{
return
parts
[
parts
.
length
-
1
];
// 取最后一部分
...
...
custom-server-domain/src/main/java/com/jomalls/custom/dal/mapper/SysUserMapper.java
View file @
e1ab500e
package
com
.
jomalls
.
custom
.
dal
.
mapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.jomalls.custom.dal.entity.SysUserEntity
;
import
com.jomalls.custom.mapper.BaseMapper
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
/**
* @author Lizh
...
...
@@ -12,4 +15,22 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public
interface
SysUserMapper
extends
BaseMapper
<
SysUserEntity
>
{
/**
* 查询角色已分配用户(分页,支持按用户名/手机号筛选)
*/
IPage
<
SysUserEntity
>
selectAllocatedByRoleId
(
@Param
(
"page"
)
Page
<
SysUserEntity
>
page
,
@Param
(
"roleId"
)
Long
roleId
,
@Param
(
"userName"
)
String
userName
,
@Param
(
"phonenumber"
)
String
phonenumber
);
/**
* 查询角色未分配用户(分页,支持按用户名/手机号筛选)
*/
IPage
<
SysUserEntity
>
selectUnallocatedByRoleId
(
@Param
(
"page"
)
Page
<
SysUserEntity
>
page
,
@Param
(
"roleId"
)
Long
roleId
,
@Param
(
"userName"
)
String
userName
,
@Param
(
"phonenumber"
)
String
phonenumber
);
}
custom-server-domain/src/main/java/com/jomalls/custom/domain/service/system/SysUserDomainService.java
View file @
e1ab500e
package
com
.
jomalls
.
custom
.
domain
.
service
.
system
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.jomalls.custom.dal.entity.SysUserEntity
;
import
com.jomalls.custom.service.IBaseService
;
...
...
@@ -11,5 +13,16 @@ import com.jomalls.custom.service.IBaseService;
*/
public
interface
SysUserDomainService
extends
IBaseService
<
SysUserEntity
>
{
/**
* 查询角色已分配用户(分页)
*/
IPage
<
SysUserEntity
>
selectAllocatedByRoleId
(
Page
<
SysUserEntity
>
page
,
Long
roleId
,
String
userName
,
String
phonenumber
);
/**
* 查询角色未分配用户(分页)
*/
IPage
<
SysUserEntity
>
selectUnallocatedByRoleId
(
Page
<
SysUserEntity
>
page
,
Long
roleId
,
String
userName
,
String
phonenumber
);
}
custom-server-domain/src/main/java/com/jomalls/custom/domain/service/system/impl/SysUserDomainServiceImpl.java
View file @
e1ab500e
package
com
.
jomalls
.
custom
.
domain
.
service
.
system
.
impl
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.jomalls.custom.dal.entity.SysUserEntity
;
import
com.jomalls.custom.dal.mapper.SysUserMapper
;
import
com.jomalls.custom.domain.service.system.SysUserDomainService
;
...
...
@@ -22,6 +24,16 @@ public class SysUserDomainServiceImpl extends BaseServiceImpl<SysUserMapper, Sys
public
SysUserDomainServiceImpl
(
SqlSessionFactory
sqlSessionFactory
)
{
super
(
sqlSessionFactory
);
}
// 自定义方法或者基础方法重写
@Override
public
IPage
<
SysUserEntity
>
selectAllocatedByRoleId
(
Page
<
SysUserEntity
>
page
,
Long
roleId
,
String
userName
,
String
phonenumber
)
{
return
baseMapper
.
selectAllocatedByRoleId
(
page
,
roleId
,
userName
,
phonenumber
);
}
@Override
public
IPage
<
SysUserEntity
>
selectUnallocatedByRoleId
(
Page
<
SysUserEntity
>
page
,
Long
roleId
,
String
userName
,
String
phonenumber
)
{
return
baseMapper
.
selectUnallocatedByRoleId
(
page
,
roleId
,
userName
,
phonenumber
);
}
}
\ No newline at end of file
custom-server-domain/src/main/resources/mapper/SysUserMapper.xml
View file @
e1ab500e
...
...
@@ -48,4 +48,34 @@
</foreach>
</insert>
<!-- 查询角色已分配用户(分页) -->
<select
id=
"selectAllocatedByRoleId"
resultMap=
"sysUserMap"
>
SELECT
<include
refid=
"tableColumns"
/>
FROM sys_user u
WHERE u.del_flag = '0'
AND u.user_id IN (SELECT user_id FROM sys_user_role WHERE role_id = #{roleId})
<if
test=
"userName != null and userName != ''"
>
AND u.user_name LIKE CONCAT('%', #{userName}, '%')
</if>
<if
test=
"phonenumber != null and phonenumber != ''"
>
AND u.phonenumber LIKE CONCAT('%', #{phonenumber}, '%')
</if>
ORDER BY u.user_id
</select>
<!-- 查询角色未分配用户(分页) -->
<select
id=
"selectUnallocatedByRoleId"
resultMap=
"sysUserMap"
>
SELECT
<include
refid=
"tableColumns"
/>
FROM sys_user u
WHERE u.del_flag = '0'
AND u.user_id NOT IN (SELECT user_id FROM sys_user_role WHERE role_id = #{roleId})
<if
test=
"userName != null and userName != ''"
>
AND u.user_name LIKE CONCAT('%', #{userName}, '%')
</if>
<if
test=
"phonenumber != null and phonenumber != ''"
>
AND u.phonenumber LIKE CONCAT('%', #{phonenumber}, '%')
</if>
ORDER BY u.user_id
</select>
</mapper>
custom-server-starter/src/main/java/com/jomalls/custom/config/CommonExceptionHandlerAdvice.java
View file @
e1ab500e
...
...
@@ -109,7 +109,7 @@ public class CommonExceptionHandlerAdvice {
*/
@ExceptionHandler
(
RuntimeException
.
class
)
public
ResponseEntity
<
R
<
Object
>>
handleRuntimeException
(
Exception
e
)
{
log
.
debug
(
"[ 运行时异常 ] {}"
,
e
.
getMessage
(),
e
);
log
.
warn
(
"[ 运行时异常 ] {}"
,
e
.
getMessage
(),
e
);
return
ResponseEntity
.
status
(
HttpStatus
.
OK
)
.
body
(
R
.
fail
(
e
.
getMessage
()));
}
...
...
@@ -119,7 +119,7 @@ public class CommonExceptionHandlerAdvice {
*/
@ExceptionHandler
(
Exception
.
class
)
public
ResponseEntity
<
R
<
Object
>>
handleException
(
Exception
e
)
{
log
.
debug
(
"[ 未捕获异常 ] {}"
,
e
.
getMessage
(),
e
);
log
.
warn
(
"[ 未捕获异常 ] {}"
,
e
.
getMessage
(),
e
);
return
ResponseEntity
.
status
(
HttpStatus
.
OK
)
.
body
(
R
.
fail
(
CodeEnum
.
FAIL
.
getCode
(),
e
.
getMessage
()));
}
...
...
custom-server-webapp/src/main/java/com/jomalls/custom/webapp/controller/system/SysRoleController.java
View file @
e1ab500e
...
...
@@ -3,28 +3,25 @@ package com.jomalls.custom.webapp.controller.system;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.jomalls.custom.app.annotation.RequiresPermissions
;
import
com.jomalls.custom.app.constant.SecurityConstants
;
import
com.jomalls.custom.app.dto.system.*
;
import
com.jomalls.custom.app.dto.system.SysRoleDataScopeDTO
;
import
com.jomalls.custom.app.dto.system.SysRoleSaveDTO
;
import
com.jomalls.custom.app.dto.system.SysRoleStatusDTO
;
import
com.jomalls.custom.app.dto.system.SysRoleUpdateDTO
;
import
com.jomalls.custom.app.exception.ServiceException
;
import
com.jomalls.custom.app.service.system.SysRoleService
;
import
com.jomalls.custom.app.vo.system.SysDeptVO
;
import
com.jomalls.custom.app.vo.system.SysRoleVO
;
import
com.jomalls.custom.app.vo.system.SysUserVO
;
import
com.jomalls.custom.dal.entity.SysMenuEntity
;
import
com.jomalls.custom.domain.service.system.SysMenuDomainService
;
import
com.jomalls.custom.security.LoginUser
;
import
com.jomalls.custom.security.SecurityUtils
;
import
com.jomalls.custom.security.TokenHandle
;
import
com.jomalls.custom.app.exception.ServiceException
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
/**
* 角色管理 Controller
...
...
@@ -78,16 +75,6 @@ public class SysRoleController {
@PutMapping
public
void
edit
(
@RequestBody
SysRoleUpdateDTO
dto
)
{
sysRoleService
.
edit
(
dto
);
// 角色修改后,刷新缓存用户权限
LoginUser
loginUser
=
SecurityUtils
.
getLoginUser
();
if
(
loginUser
!=
null
&&
loginUser
.
getUserId
()
!=
null
&&
SecurityConstants
.
ADMIN_USER_ID
.
equals
(
loginUser
.
getUserId
()))
{
// 重新查询权限
Set
<
String
>
perms
=
new
HashSet
<>();
List
<
String
>
permList
=
sysMenuDomainService
.
selectMenuPermsByUserId
(
loginUser
.
getUserId
());
if
(
permList
!=
null
)
perms
.
addAll
(
permList
);
loginUser
.
setPermissions
(
perms
);
tokenHandle
.
refreshToken
(
loginUser
);
}
}
@Operation
(
summary
=
"修改角色数据权限"
)
...
...
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