Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Eladmin
Commits
9f43851e
"src/vscode:/vscode.git/clone" did not exist on "cbbd11a751972077a431a8de0e8e85a0f8d85b0e"
Commit
9f43851e
authored
Apr 11, 2019
by
zhengjie
Browse files
1.7版本发布,详情查看版本说明
parent
1402e584
Changes
89
Show whitespace changes
Inline
Side-by-side
eladmin-system/src/main/java/me/zhengjie/modules/system/rest/JobController.java
0 → 100644
View file @
9f43851e
package
me.zhengjie.modules.system.rest
;
import
me.zhengjie.aop.log.Log
;
import
me.zhengjie.config.DataScope
;
import
me.zhengjie.exception.BadRequestException
;
import
me.zhengjie.modules.system.domain.Job
;
import
me.zhengjie.modules.system.service.JobService
;
import
me.zhengjie.modules.system.service.query.JobQueryService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.Set
;
/**
* @author jie
* @date 2019-03-29
*/
@RestController
@RequestMapping
(
"api"
)
public
class
JobController
{
@Autowired
private
JobService
jobService
;
@Autowired
private
JobQueryService
jobQueryService
;
@Autowired
private
DataScope
dataScope
;
private
static
final
String
ENTITY_NAME
=
"job"
;
@Log
(
"查询岗位"
)
@GetMapping
(
value
=
"/job"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','USERJOB_ALL','USERJOB_SELECT','USER_ALL','USER_SELECT')"
)
public
ResponseEntity
getJobs
(
@RequestParam
(
required
=
false
)
String
name
,
@RequestParam
(
required
=
false
)
Long
deptId
,
@RequestParam
(
required
=
false
)
Boolean
enabled
,
Pageable
pageable
){
// 数据权限
Set
<
Long
>
deptIds
=
dataScope
.
getDeptIds
();
return
new
ResponseEntity
(
jobQueryService
.
queryAll
(
name
,
enabled
,
deptIds
,
deptId
,
pageable
),
HttpStatus
.
OK
);
}
@Log
(
"新增岗位"
)
@PostMapping
(
value
=
"/job"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','USERJOB_ALL','USERJOB_CREATE')"
)
public
ResponseEntity
create
(
@Validated
@RequestBody
Job
resources
){
if
(
resources
.
getId
()
!=
null
)
{
throw
new
BadRequestException
(
"A new "
+
ENTITY_NAME
+
" cannot already have an ID"
);
}
return
new
ResponseEntity
(
jobService
.
create
(
resources
),
HttpStatus
.
CREATED
);
}
@Log
(
"修改岗位"
)
@PutMapping
(
value
=
"/job"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','USERJOB_ALL','USERJOB_EDIT')"
)
public
ResponseEntity
update
(
@Validated
(
Job
.
Update
.
class
)
@RequestBody
Job
resources
){
jobService
.
update
(
resources
);
return
new
ResponseEntity
(
HttpStatus
.
NO_CONTENT
);
}
@Log
(
"删除岗位"
)
@DeleteMapping
(
value
=
"/job/{id}"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','USERJOB_ALL','USERJOB_DELETE')"
)
public
ResponseEntity
delete
(
@PathVariable
Long
id
){
jobService
.
delete
(
id
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/modules/system/rest/MenuController.java
View file @
9f43851e
...
@@ -8,6 +8,7 @@ import me.zhengjie.modules.system.service.MenuService;
...
@@ -8,6 +8,7 @@ import me.zhengjie.modules.system.service.MenuService;
import
me.zhengjie.modules.system.service.RoleService
;
import
me.zhengjie.modules.system.service.RoleService
;
import
me.zhengjie.modules.system.service.UserService
;
import
me.zhengjie.modules.system.service.UserService
;
import
me.zhengjie.modules.system.service.dto.MenuDTO
;
import
me.zhengjie.modules.system.service.dto.MenuDTO
;
import
me.zhengjie.modules.system.service.mapper.MenuMapper
;
import
me.zhengjie.modules.system.service.query.MenuQueryService
;
import
me.zhengjie.modules.system.service.query.MenuQueryService
;
import
me.zhengjie.utils.SecurityContextHolder
;
import
me.zhengjie.utils.SecurityContextHolder
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -39,6 +40,9 @@ public class MenuController {
...
@@ -39,6 +40,9 @@ public class MenuController {
@Autowired
@Autowired
private
RoleService
roleService
;
private
RoleService
roleService
;
@Autowired
private
MenuMapper
menuMapper
;
private
static
final
String
ENTITY_NAME
=
"menu"
;
private
static
final
String
ENTITY_NAME
=
"menu"
;
/**
/**
...
@@ -59,7 +63,7 @@ public class MenuController {
...
@@ -59,7 +63,7 @@ public class MenuController {
* @return
* @return
*/
*/
@GetMapping
(
value
=
"/menus/tree"
)
@GetMapping
(
value
=
"/menus/tree"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','MENU_ALL','MENU_
SELEC
T','ROLES_SELECT','ROLES_ALL')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','MENU_ALL','MENU_
CREATE','MENU_EDI
T','ROLES_SELECT','ROLES_ALL')"
)
public
ResponseEntity
getMenuTree
(){
public
ResponseEntity
getMenuTree
(){
return
new
ResponseEntity
(
menuService
.
getMenuTree
(
menuService
.
findByPid
(
0L
)),
HttpStatus
.
OK
);
return
new
ResponseEntity
(
menuService
.
getMenuTree
(
menuService
.
findByPid
(
0L
)),
HttpStatus
.
OK
);
}
}
...
@@ -94,6 +98,14 @@ public class MenuController {
...
@@ -94,6 +98,14 @@ public class MenuController {
@DeleteMapping
(
value
=
"/menus/{id}"
)
@DeleteMapping
(
value
=
"/menus/{id}"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','MENU_ALL','MENU_DELETE')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','MENU_ALL','MENU_DELETE')"
)
public
ResponseEntity
delete
(
@PathVariable
Long
id
){
public
ResponseEntity
delete
(
@PathVariable
Long
id
){
List
<
Menu
>
menuList
=
menuService
.
findByPid
(
id
);
// 特殊情况,对级联删除进行处理
for
(
Menu
menu
:
menuList
)
{
roleService
.
untiedMenu
(
menu
);
menuService
.
delete
(
menu
.
getId
());
}
roleService
.
untiedMenu
(
menuService
.
findOne
(
id
));
menuService
.
delete
(
id
);
menuService
.
delete
(
id
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
}
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/rest/PermissionController.java
View file @
9f43851e
...
@@ -36,8 +36,8 @@ public class PermissionController {
...
@@ -36,8 +36,8 @@ public class PermissionController {
* @return
* @return
*/
*/
@GetMapping
(
value
=
"/permissions/tree"
)
@GetMapping
(
value
=
"/permissions/tree"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','PERMISSION_ALL','PERMISSION_
SELEC
T','ROLES_SELECT','ROLES_ALL')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','PERMISSION_ALL','PERMISSION_
CREATE','PERMISSION_EDI
T','ROLES_SELECT','ROLES_ALL')"
)
public
ResponseEntity
get
Role
Tree
(){
public
ResponseEntity
getTree
(){
return
new
ResponseEntity
(
permissionService
.
getPermissionTree
(
permissionService
.
findByPid
(
0L
)),
HttpStatus
.
OK
);
return
new
ResponseEntity
(
permissionService
.
getPermissionTree
(
permissionService
.
findByPid
(
0L
)),
HttpStatus
.
OK
);
}
}
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/rest/RoleController.java
View file @
9f43851e
...
@@ -40,10 +40,10 @@ public class RoleController {
...
@@ -40,10 +40,10 @@ public class RoleController {
* 返回全部的角色,新增用户时下拉选择
* 返回全部的角色,新增用户时下拉选择
* @return
* @return
*/
*/
@GetMapping
(
value
=
"/roles/
tree
"
)
@GetMapping
(
value
=
"/roles/
all
"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','ROLES_ALL','USER_ALL','USER_
SELEC
T')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','ROLES_ALL','USER_ALL','USER_
CREATE','USER_EDI
T')"
)
public
ResponseEntity
get
RoleTree
(){
public
ResponseEntity
get
All
(){
return
new
ResponseEntity
(
roleService
.
getRoleTree
(),
HttpStatus
.
OK
);
return
new
ResponseEntity
(
role
Query
Service
.
queryAll
(),
HttpStatus
.
OK
);
}
}
@Log
(
"查询角色"
)
@Log
(
"查询角色"
)
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/rest/UserController.java
View file @
9f43851e
package
me.zhengjie.modules.system.rest
;
package
me.zhengjie.modules.system.rest
;
import
me.zhengjie.aop.log.Log
;
import
me.zhengjie.aop.log.Log
;
import
me.zhengjie.config.DataScope
;
import
me.zhengjie.domain.Picture
;
import
me.zhengjie.domain.Picture
;
import
me.zhengjie.domain.VerificationCode
;
import
me.zhengjie.domain.VerificationCode
;
import
me.zhengjie.modules.system.domain.User
;
import
me.zhengjie.modules.system.domain.User
;
import
me.zhengjie.exception.BadRequestException
;
import
me.zhengjie.exception.BadRequestException
;
import
me.zhengjie.modules.s
ecurity.security.JwtUser
;
import
me.zhengjie.modules.s
ystem.service.DeptService
;
import
me.zhengjie.service.PictureService
;
import
me.zhengjie.service.PictureService
;
import
me.zhengjie.service.VerificationCodeService
;
import
me.zhengjie.service.VerificationCodeService
;
import
me.zhengjie.utils.ElAdminConstant
;
import
me.zhengjie.utils.*
;
import
me.zhengjie.utils.EncryptUtils
;
import
me.zhengjie.modules.security.utils.JwtTokenUtil
;
import
me.zhengjie.modules.system.service.UserService
;
import
me.zhengjie.modules.system.service.UserService
;
import
me.zhengjie.modules.system.service.dto.UserDTO
;
import
me.zhengjie.modules.system.service.dto.UserDTO
;
import
me.zhengjie.modules.system.service.query.UserQueryService
;
import
me.zhengjie.modules.system.service.query.UserQueryService
;
import
me.zhengjie.utils.SecurityContextHolder
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.util.HashMap
;
import
java.util.*
;
import
java.util.Map
;
/**
/**
* @author jie
* @author jie
...
@@ -44,14 +41,13 @@ public class UserController {
...
@@ -44,14 +41,13 @@ public class UserController {
private
UserQueryService
userQueryService
;
private
UserQueryService
userQueryService
;
@Autowired
@Autowired
private
JwtTokenUtil
jwtTokenUtil
;
private
PictureService
pictureService
;
@Autowired
@Autowired
@Qualifier
(
"jwtUserDetailsService"
)
private
DataScope
dataScope
;
private
UserDetailsService
userDetailsService
;
@Autowired
@Autowired
private
Picture
Service
picture
Service
;
private
Dept
Service
dept
Service
;
@Autowired
@Autowired
private
VerificationCodeService
verificationCodeService
;
private
VerificationCodeService
verificationCodeService
;
...
@@ -63,7 +59,34 @@ public class UserController {
...
@@ -63,7 +59,34 @@ public class UserController {
@GetMapping
(
value
=
"/users"
)
@GetMapping
(
value
=
"/users"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','USER_ALL','USER_SELECT')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','USER_ALL','USER_SELECT')"
)
public
ResponseEntity
getUsers
(
UserDTO
userDTO
,
Pageable
pageable
){
public
ResponseEntity
getUsers
(
UserDTO
userDTO
,
Pageable
pageable
){
return
new
ResponseEntity
(
userQueryService
.
queryAll
(
userDTO
,
pageable
),
HttpStatus
.
OK
);
Set
<
Long
>
deptSet
=
new
HashSet
<>();
Set
<
Long
>
result
=
new
HashSet
<>();
if
(!
ObjectUtils
.
isEmpty
(
userDTO
.
getDeptId
()))
{
deptSet
.
add
(
userDTO
.
getDeptId
());
deptSet
.
addAll
(
dataScope
.
getDeptChildren
(
deptService
.
findByPid
(
userDTO
.
getDeptId
())));
}
// 数据权限
Set
<
Long
>
deptIds
=
dataScope
.
getDeptIds
();
// 查询条件不为空并且数据权限不为空则取交集
if
(!
CollectionUtils
.
isEmpty
(
deptIds
)
&&
!
CollectionUtils
.
isEmpty
(
deptSet
)){
// 取交集
result
.
addAll
(
deptSet
);
result
.
retainAll
(
deptIds
);
// 若无交集,则代表无数据权限
if
(
result
.
size
()
==
0
){
return
new
ResponseEntity
(
PageUtil
.
toPage
(
null
,
0
),
HttpStatus
.
OK
);
}
else
return
new
ResponseEntity
(
userQueryService
.
queryAll
(
userDTO
,
result
,
pageable
),
HttpStatus
.
OK
);
// 否则取并集
}
else
{
result
.
addAll
(
deptSet
);
result
.
addAll
(
deptIds
);
return
new
ResponseEntity
(
userQueryService
.
queryAll
(
userDTO
,
result
,
pageable
),
HttpStatus
.
OK
);
}
}
}
@Log
(
"新增用户"
)
@Log
(
"新增用户"
)
...
@@ -100,10 +123,9 @@ public class UserController {
...
@@ -100,10 +123,9 @@ public class UserController {
@GetMapping
(
value
=
"/users/validPass/{pass}"
)
@GetMapping
(
value
=
"/users/validPass/{pass}"
)
public
ResponseEntity
validPass
(
@PathVariable
String
pass
){
public
ResponseEntity
validPass
(
@PathVariable
String
pass
){
UserDetails
userDetails
=
SecurityContextHolder
.
getUserDetails
();
UserDetails
userDetails
=
SecurityContextHolder
.
getUserDetails
();
JwtUser
jwtUser
=
(
JwtUser
)
userDetailsService
.
loadUserByUsername
(
userDetails
.
getUsername
());
Map
map
=
new
HashMap
();
Map
map
=
new
HashMap
();
map
.
put
(
"status"
,
200
);
map
.
put
(
"status"
,
200
);
if
(!
jwtUser
.
getPassword
().
equals
(
EncryptUtils
.
encryptPassword
(
pass
))){
if
(!
userDetails
.
getPassword
().
equals
(
EncryptUtils
.
encryptPassword
(
pass
))){
map
.
put
(
"status"
,
400
);
map
.
put
(
"status"
,
400
);
}
}
return
new
ResponseEntity
(
map
,
HttpStatus
.
OK
);
return
new
ResponseEntity
(
map
,
HttpStatus
.
OK
);
...
@@ -117,11 +139,10 @@ public class UserController {
...
@@ -117,11 +139,10 @@ public class UserController {
@GetMapping
(
value
=
"/users/updatePass/{pass}"
)
@GetMapping
(
value
=
"/users/updatePass/{pass}"
)
public
ResponseEntity
updatePass
(
@PathVariable
String
pass
){
public
ResponseEntity
updatePass
(
@PathVariable
String
pass
){
UserDetails
userDetails
=
SecurityContextHolder
.
getUserDetails
();
UserDetails
userDetails
=
SecurityContextHolder
.
getUserDetails
();
JwtUser
jwtUser
=
(
JwtUser
)
userDetailsService
.
loadUserByUsername
(
userDetails
.
getUsername
());
if
(
userDetails
.
getPassword
().
equals
(
EncryptUtils
.
encryptPassword
(
pass
))){
if
(
jwtUser
.
getPassword
().
equals
(
EncryptUtils
.
encryptPassword
(
pass
))){
throw
new
BadRequestException
(
"新密码不能与旧密码相同"
);
throw
new
BadRequestException
(
"新密码不能与旧密码相同"
);
}
}
userService
.
updatePass
(
jwtUser
,
EncryptUtils
.
encryptPassword
(
pass
));
userService
.
updatePass
(
userDetails
.
getUsername
()
,
EncryptUtils
.
encryptPassword
(
pass
));
return
new
ResponseEntity
(
HttpStatus
.
OK
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
}
...
@@ -133,9 +154,8 @@ public class UserController {
...
@@ -133,9 +154,8 @@ public class UserController {
@PostMapping
(
value
=
"/users/updateAvatar"
)
@PostMapping
(
value
=
"/users/updateAvatar"
)
public
ResponseEntity
updateAvatar
(
@RequestParam
MultipartFile
file
){
public
ResponseEntity
updateAvatar
(
@RequestParam
MultipartFile
file
){
UserDetails
userDetails
=
SecurityContextHolder
.
getUserDetails
();
UserDetails
userDetails
=
SecurityContextHolder
.
getUserDetails
();
JwtUser
jwtUser
=
(
JwtUser
)
userDetailsService
.
loadUserByUsername
(
userDetails
.
getUsername
());
Picture
picture
=
pictureService
.
upload
(
file
,
userDetails
.
getUsername
());
Picture
picture
=
pictureService
.
upload
(
file
,
jwtUser
.
getUsername
());
userService
.
updateAvatar
(
userDetails
.
getUsername
(),
picture
.
getUrl
());
userService
.
updateAvatar
(
jwtUser
,
picture
.
getUrl
());
return
new
ResponseEntity
(
HttpStatus
.
OK
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
}
...
@@ -145,16 +165,16 @@ public class UserController {
...
@@ -145,16 +165,16 @@ public class UserController {
* @param user
* @param user
* @return
* @return
*/
*/
@Log
(
"修改邮箱"
)
@PostMapping
(
value
=
"/users/updateEmail/{code}"
)
@PostMapping
(
value
=
"/users/updateEmail/{code}"
)
public
ResponseEntity
updateEmail
(
@PathVariable
String
code
,
@RequestBody
User
user
){
public
ResponseEntity
updateEmail
(
@PathVariable
String
code
,
@RequestBody
User
user
){
UserDetails
userDetails
=
SecurityContextHolder
.
getUserDetails
();
UserDetails
userDetails
=
SecurityContextHolder
.
getUserDetails
();
JwtUser
jwtUser
=
(
JwtUser
)
userDetailsService
.
loadUserByUsername
(
userDetails
.
getUsername
());
if
(!
userDetails
.
getPassword
().
equals
(
EncryptUtils
.
encryptPassword
(
user
.
getPassword
()))){
if
(!
jwtUser
.
getPassword
().
equals
(
EncryptUtils
.
encryptPassword
(
user
.
getPassword
()))){
throw
new
BadRequestException
(
"密码错误"
);
throw
new
BadRequestException
(
"密码错误"
);
}
}
VerificationCode
verificationCode
=
new
VerificationCode
(
code
,
ElAdminConstant
.
RESET_MAIL
,
"email"
,
user
.
getEmail
());
VerificationCode
verificationCode
=
new
VerificationCode
(
code
,
ElAdminConstant
.
RESET_MAIL
,
"email"
,
user
.
getEmail
());
verificationCodeService
.
validated
(
verificationCode
);
verificationCodeService
.
validated
(
verificationCode
);
userService
.
updateEmail
(
jwtUser
,
user
.
getEmail
());
userService
.
updateEmail
(
userDetails
.
getUsername
()
,
user
.
getEmail
());
return
new
ResponseEntity
(
HttpStatus
.
OK
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
}
}
}
}
eladmin-system/src/main/java/me/zhengjie/modules/system/service/DeptService.java
0 → 100644
View file @
9f43851e
package
me.zhengjie.modules.system.service
;
import
me.zhengjie.modules.system.domain.Dept
;
import
me.zhengjie.modules.system.service.dto.DeptDTO
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
import
java.util.List
;
/**
* @author jie
* @date 2019-03-25
*/
@CacheConfig
(
cacheNames
=
"dept"
)
public
interface
DeptService
{
/**
* findById
* @param id
* @return
*/
@Cacheable
(
key
=
"#p0"
)
DeptDTO
findById
(
Long
id
);
/**
* create
* @param resources
* @return
*/
@CacheEvict
(
allEntries
=
true
)
DeptDTO
create
(
Dept
resources
);
/**
* update
* @param resources
*/
@CacheEvict
(
allEntries
=
true
)
void
update
(
Dept
resources
);
/**
* delete
* @param id
*/
@CacheEvict
(
allEntries
=
true
)
void
delete
(
Long
id
);
/**
* buildTree
* @param deptDTOS
* @return
*/
@Cacheable
(
keyGenerator
=
"keyGenerator"
)
Object
buildTree
(
List
<
DeptDTO
>
deptDTOS
);
/**
* findByPid
* @param pid
* @return
*/
@Cacheable
(
keyGenerator
=
"keyGenerator"
)
List
<
Dept
>
findByPid
(
long
pid
);
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/modules/system/service/DictDetailService.java
0 → 100644
View file @
9f43851e
package
me.zhengjie.modules.system.service
;
import
me.zhengjie.modules.system.domain.DictDetail
;
import
me.zhengjie.modules.system.service.dto.DictDetailDTO
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
/**
* @author jie
* @date 2019-04-10
*/
@CacheConfig
(
cacheNames
=
"dictDetail"
)
public
interface
DictDetailService
{
/**
* findById
* @param id
* @return
*/
@Cacheable
(
key
=
"#p0"
)
DictDetailDTO
findById
(
Long
id
);
/**
* create
* @param resources
* @return
*/
@CacheEvict
(
allEntries
=
true
)
DictDetailDTO
create
(
DictDetail
resources
);
/**
* update
* @param resources
*/
@CacheEvict
(
allEntries
=
true
)
void
update
(
DictDetail
resources
);
/**
* delete
* @param id
*/
@CacheEvict
(
allEntries
=
true
)
void
delete
(
Long
id
);
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/modules/system/service/DictService.java
0 → 100644
View file @
9f43851e
package
me.zhengjie.modules.system.service
;
import
me.zhengjie.modules.system.domain.Dict
;
import
me.zhengjie.modules.system.service.dto.DictDTO
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
/**
* @author jie
* @date 2019-04-10
*/
@CacheConfig
(
cacheNames
=
"dict"
)
public
interface
DictService
{
/**
* findById
* @param id
* @return
*/
@Cacheable
(
key
=
"#p0"
)
DictDTO
findById
(
Long
id
);
/**
* create
* @param resources
* @return
*/
@CacheEvict
(
allEntries
=
true
)
DictDTO
create
(
Dict
resources
);
/**
* update
* @param resources
*/
@CacheEvict
(
allEntries
=
true
)
void
update
(
Dict
resources
);
/**
* delete
* @param id
*/
@CacheEvict
(
allEntries
=
true
)
void
delete
(
Long
id
);
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/modules/system/service/JobService.java
0 → 100644
View file @
9f43851e
package
me.zhengjie.modules.system.service
;
import
me.zhengjie.modules.system.domain.Job
;
import
me.zhengjie.modules.system.service.dto.JobDTO
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
/**
* @author jie
* @date 2019-03-29
*/
@CacheConfig
(
cacheNames
=
"job"
)
public
interface
JobService
{
/**
* findById
* @param id
* @return
*/
@Cacheable
(
key
=
"#p0"
)
JobDTO
findById
(
Long
id
);
/**
* create
* @param resources
* @return
*/
@CacheEvict
(
allEntries
=
true
)
JobDTO
create
(
Job
resources
);
/**
* update
* @param resources
*/
@CacheEvict
(
allEntries
=
true
)
void
update
(
Job
resources
);
/**
* delete
* @param id
*/
@CacheEvict
(
allEntries
=
true
)
void
delete
(
Long
id
);
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/modules/system/service/MenuService.java
View file @
9f43851e
...
@@ -74,7 +74,7 @@ public interface MenuService {
...
@@ -74,7 +74,7 @@ public interface MenuService {
* @param roles
* @param roles
* @return
* @return
*/
*/
List
<
MenuDTO
>
findByRoles
(
Se
t
<
Role
>
roles
);
List
<
MenuDTO
>
findByRoles
(
Lis
t
<
Role
>
roles
);
/**
/**
* buildMenus
* buildMenus
...
@@ -82,4 +82,6 @@ public interface MenuService {
...
@@ -82,4 +82,6 @@ public interface MenuService {
* @return
* @return
*/
*/
Object
buildMenus
(
List
<
MenuDTO
>
byRoles
);
Object
buildMenus
(
List
<
MenuDTO
>
byRoles
);
Menu
findOne
(
Long
id
);
}
}
eladmin-system/src/main/java/me/zhengjie/modules/system/service/PermissionService.java
View file @
9f43851e
...
@@ -5,6 +5,8 @@ import me.zhengjie.modules.system.service.dto.PermissionDTO;
...
@@ -5,6 +5,8 @@ import me.zhengjie.modules.system.service.dto.PermissionDTO;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.cache.annotation.Cacheable
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/service/RoleService.java
View file @
9f43851e
package
me.zhengjie.modules.system.service
;
package
me.zhengjie.modules.system.service
;
import
me.zhengjie.modules.system.domain.Menu
;
import
me.zhengjie.modules.system.domain.Role
;
import
me.zhengjie.modules.system.domain.Role
;
import
me.zhengjie.modules.system.service.dto.RoleDTO
;
import
me.zhengjie.modules.system.service.dto.RoleDTO
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.cache.annotation.Cacheable
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.Set
;
/**
/**
...
@@ -45,19 +47,13 @@ public interface RoleService {
...
@@ -45,19 +47,13 @@ public interface RoleService {
@CacheEvict
(
allEntries
=
true
)
@CacheEvict
(
allEntries
=
true
)
void
delete
(
Long
id
);
void
delete
(
Long
id
);
/**
* role tree
* @return
*/
@Cacheable
(
key
=
"'tree'"
)
Object
getRoleTree
();
/**
/**
* findByUsers_Id
* findByUsers_Id
* @param id
* @param id
* @return
* @return
*/
*/
Set
<
Role
>
findByUsers_Id
(
Long
id
);
@Cacheable
(
keyGenerator
=
"keyGenerator"
)
List
<
Role
>
findByUsers_Id
(
Long
id
);
/**
/**
* updatePermission
* updatePermission
...
@@ -74,4 +70,7 @@ public interface RoleService {
...
@@ -74,4 +70,7 @@ public interface RoleService {
*/
*/
@CacheEvict
(
allEntries
=
true
)
@CacheEvict
(
allEntries
=
true
)
void
updateMenu
(
Role
resources
,
RoleDTO
roleDTO
);
void
updateMenu
(
Role
resources
,
RoleDTO
roleDTO
);
@CacheEvict
(
allEntries
=
true
)
void
untiedMenu
(
Menu
menu
);
}
}
eladmin-system/src/main/java/me/zhengjie/modules/system/service/UserService.java
View file @
9f43851e
...
@@ -49,30 +49,30 @@ public interface UserService {
...
@@ -49,30 +49,30 @@ public interface UserService {
* @param userName
* @param userName
* @return
* @return
*/
*/
@Cacheable
(
key
Generator
=
"keyGenerator
"
)
@Cacheable
(
key
=
"'loadUserByUsername:'+#p0
"
)
User
findByName
(
String
userName
);
User
findByName
(
String
userName
);
/**
/**
* 修改密码
* 修改密码
* @param
jwtUser
* @param
username
* @param encryptPassword
* @param encryptPassword
*/
*/
@CacheEvict
(
allEntries
=
true
)
@CacheEvict
(
allEntries
=
true
)
void
updatePass
(
JwtUser
jwtUser
,
String
encryptPassword
);
void
updatePass
(
String
username
,
String
encryptPassword
);
/**
/**
* 修改头像
* 修改头像
* @param
jwtUser
* @param
username
* @param url
* @param url
*/
*/
@CacheEvict
(
allEntries
=
true
)
@CacheEvict
(
allEntries
=
true
)
void
updateAvatar
(
JwtUser
jwtUser
,
String
url
);
void
updateAvatar
(
String
username
,
String
url
);
/**
/**
* 修改邮箱
* 修改邮箱
* @param
jwtUser
* @param
username
* @param email
* @param email
*/
*/
@CacheEvict
(
allEntries
=
true
)
@CacheEvict
(
allEntries
=
true
)
void
updateEmail
(
JwtUser
jwtUser
,
String
email
);
void
updateEmail
(
String
username
,
String
email
);
}
}
eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/DeptDTO.java
0 → 100644
View file @
9f43851e
package
me.zhengjie.modules.system.service.dto
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
lombok.Data
;
import
javax.validation.constraints.NotNull
;
import
java.sql.Timestamp
;
import
java.io.Serializable
;
import
java.util.List
;
/**
* @author jie
* @date 2019-03-25
*/
@Data
public
class
DeptDTO
implements
Serializable
{
/**
* ID
*/
private
Long
id
;
/**
* 名称
*/
private
String
name
;
@NotNull
private
Boolean
enabled
;
/**
* 上级部门
*/
private
Long
pid
;
@JsonInclude
(
JsonInclude
.
Include
.
NON_EMPTY
)
private
List
<
DeptDTO
>
children
;
private
Timestamp
createTime
;
public
String
getLabel
()
{
return
name
;
}
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/DictDTO.java
0 → 100644
View file @
9f43851e
package
me.zhengjie.modules.system.service.dto
;
import
lombok.Data
;
import
java.sql.Timestamp
;
import
java.io.Serializable
;
/**
* @author jie
* @date 2019-04-10
*/
@Data
public
class
DictDTO
implements
Serializable
{
private
Long
id
;
/**
* 字典名称
*/
private
String
name
;
/**
* 描述
*/
private
String
remark
;
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/DictDetailDTO.java
0 → 100644
View file @
9f43851e
package
me.zhengjie.modules.system.service.dto
;
import
lombok.Data
;
import
java.io.Serializable
;
/**
* @author jie
* @date 2019-04-10
*/
@Data
public
class
DictDetailDTO
implements
Serializable
{
private
Long
id
;
/**
* 字典标签
*/
private
String
label
;
/**
* 字典值
*/
private
String
value
;
/**
* 排序
*/
private
String
sort
;
/**
* 字典id
*/
private
String
dictName
;
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/JobDTO.java
0 → 100644
View file @
9f43851e
package
me.zhengjie.modules.system.service.dto
;
import
lombok.Data
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
java.sql.Timestamp
;
import
java.io.Serializable
;
/**
* @author jie
* @date 2019-03-29
*/
@Data
@NoArgsConstructor
public
class
JobDTO
implements
Serializable
{
/**
* ID
*/
private
Long
id
;
private
Long
sort
;
/**
* 名称
*/
private
String
name
;
/**
* 状态
*/
private
Boolean
enabled
;
private
DeptDTO
dept
;
/**
* 创建日期
*/
private
Timestamp
createTime
;
public
JobDTO
(
String
name
,
Boolean
enabled
)
{
this
.
name
=
name
;
this
.
enabled
=
enabled
;
}
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/RoleDTO.java
View file @
9f43851e
...
@@ -16,11 +16,15 @@ public class RoleDTO implements Serializable {
...
@@ -16,11 +16,15 @@ public class RoleDTO implements Serializable {
private
String
name
;
private
String
name
;
private
String
dataScope
;
private
String
remark
;
private
String
remark
;
private
Set
<
PermissionDTO
>
permissions
;
private
Set
<
PermissionDTO
>
permissions
;
private
Set
<
MenuDTO
>
menus
;
private
Set
<
MenuDTO
>
menus
;
private
Set
<
DeptDTO
>
depts
;
private
Timestamp
createTime
;
private
Timestamp
createTime
;
}
}
eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/UserDTO.java
View file @
9f43851e
...
@@ -24,6 +24,8 @@ public class UserDTO implements Serializable {
...
@@ -24,6 +24,8 @@ public class UserDTO implements Serializable {
private
String
email
;
private
String
email
;
private
String
phone
;
private
Boolean
enabled
;
private
Boolean
enabled
;
@JsonIgnore
@JsonIgnore
...
@@ -35,4 +37,11 @@ public class UserDTO implements Serializable {
...
@@ -35,4 +37,11 @@ public class UserDTO implements Serializable {
@ApiModelProperty
(
hidden
=
true
)
@ApiModelProperty
(
hidden
=
true
)
private
Set
<
RoleDTO
>
roles
;
private
Set
<
RoleDTO
>
roles
;
@ApiModelProperty
(
hidden
=
true
)
private
JobDTO
job
;
private
DeptDTO
dept
;
private
Long
deptId
;
}
}
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DeptServiceImpl.java
0 → 100644
View file @
9f43851e
package
me.zhengjie.modules.system.service.impl
;
import
me.zhengjie.exception.BadRequestException
;
import
me.zhengjie.modules.system.domain.Dept
;
import
me.zhengjie.utils.ValidationUtil
;
import
me.zhengjie.modules.system.repository.DeptRepository
;
import
me.zhengjie.modules.system.service.DeptService
;
import
me.zhengjie.modules.system.service.dto.DeptDTO
;
import
me.zhengjie.modules.system.service.mapper.DeptMapper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.CollectionUtils
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* @author jie
* @date 2019-03-25
*/
@Service
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
DeptServiceImpl
implements
DeptService
{
@Autowired
private
DeptRepository
deptRepository
;
@Autowired
private
DeptMapper
deptMapper
;
@Override
public
DeptDTO
findById
(
Long
id
)
{
Optional
<
Dept
>
dept
=
deptRepository
.
findById
(
id
);
ValidationUtil
.
isNull
(
dept
,
"Dept"
,
"id"
,
id
);
return
deptMapper
.
toDto
(
dept
.
get
());
}
@Override
public
List
<
Dept
>
findByPid
(
long
pid
)
{
return
deptRepository
.
findByPid
(
pid
);
}
@Override
public
Object
buildTree
(
List
<
DeptDTO
>
deptDTOS
)
{
Set
<
DeptDTO
>
trees
=
new
LinkedHashSet
<>();
Set
<
DeptDTO
>
depts
=
new
LinkedHashSet
<>();
Boolean
isChild
;
for
(
DeptDTO
deptDTO
:
deptDTOS
)
{
isChild
=
false
;
if
(
"0"
.
equals
(
deptDTO
.
getPid
().
toString
()))
{
trees
.
add
(
deptDTO
);
}
for
(
DeptDTO
it
:
deptDTOS
)
{
if
(
it
.
getPid
().
equals
(
deptDTO
.
getId
()))
{
isChild
=
true
;
if
(
deptDTO
.
getChildren
()
==
null
)
{
deptDTO
.
setChildren
(
new
ArrayList
<
DeptDTO
>());
}
deptDTO
.
getChildren
().
add
(
it
);
}
}
if
(
isChild
)
{
depts
.
add
(
deptDTO
);
}
}
if
(
CollectionUtils
.
isEmpty
(
trees
))
{
trees
=
depts
;
}
Integer
totalElements
=
deptDTOS
!=
null
?
deptDTOS
.
size
():
0
;
Map
map
=
new
HashMap
();
map
.
put
(
"totalElements"
,
totalElements
);
map
.
put
(
"content"
,
CollectionUtils
.
isEmpty
(
trees
)?
deptDTOS:
trees
);
return
map
;
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
DeptDTO
create
(
Dept
resources
)
{
return
deptMapper
.
toDto
(
deptRepository
.
save
(
resources
));
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
update
(
Dept
resources
)
{
if
(
resources
.
getId
().
equals
(
resources
.
getPid
()))
{
throw
new
BadRequestException
(
"上级不能为自己"
);
}
Optional
<
Dept
>
optionalDept
=
deptRepository
.
findById
(
resources
.
getId
());
ValidationUtil
.
isNull
(
optionalDept
,
"Dept"
,
"id"
,
resources
.
getId
());
Dept
dept
=
optionalDept
.
get
();
// 此处需自己修改
resources
.
setId
(
dept
.
getId
());
deptRepository
.
save
(
resources
);
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
delete
(
Long
id
)
{
deptRepository
.
deleteById
(
id
);
}
}
\ No newline at end of file
Prev
1
2
3
4
5
Next
Write
Preview
Supports
Markdown
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