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
4e39694e
"vscode:/vscode.git/clone" did not exist on "435af8ad55ff81232294e608507bd3c566b06d43"
Commit
4e39694e
authored
Feb 28, 2019
by
zhengjie
Browse files
v1.6 版本发布 ,详情查看版本说明
parent
f63407fd
Changes
46
Show whitespace changes
Inline
Side-by-side
eladmin-system/src/main/java/me/zhengjie/modules/system/domain/vo/MenuMetaVo.java
View file @
4e39694e
...
@@ -3,13 +3,15 @@ package me.zhengjie.modules.system.domain.vo;
...
@@ -3,13 +3,15 @@ package me.zhengjie.modules.system.domain.vo;
import
lombok.AllArgsConstructor
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.Data
;
import
java.io.Serializable
;
/**
/**
* @author jie
* @author jie
* @date 2018-12-20
* @date 2018-12-20
*/
*/
@Data
@Data
@AllArgsConstructor
@AllArgsConstructor
public
class
MenuMetaVo
{
public
class
MenuMetaVo
implements
Serializable
{
private
String
title
;
private
String
title
;
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/domain/vo/MenuVo.java
View file @
4e39694e
...
@@ -3,6 +3,7 @@ package me.zhengjie.modules.system.domain.vo;
...
@@ -3,6 +3,7 @@ package me.zhengjie.modules.system.domain.vo;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
lombok.Data
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -12,7 +13,7 @@ import java.util.List;
...
@@ -12,7 +13,7 @@ import java.util.List;
*/
*/
@Data
@Data
@JsonInclude
(
JsonInclude
.
Include
.
NON_EMPTY
)
@JsonInclude
(
JsonInclude
.
Include
.
NON_EMPTY
)
public
class
MenuVo
{
public
class
MenuVo
implements
Serializable
{
private
String
name
;
private
String
name
;
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/repository/MenuRepository.java
View file @
4e39694e
...
@@ -4,6 +4,9 @@ import me.zhengjie.modules.system.domain.Menu;
...
@@ -4,6 +4,9 @@ import me.zhengjie.modules.system.domain.Menu;
import
me.zhengjie.modules.system.domain.Role
;
import
me.zhengjie.modules.system.domain.Role
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
java.util.Arrays
;
import
java.util.LinkedHashSet
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.Set
;
...
@@ -20,17 +23,12 @@ public interface MenuRepository extends JpaRepository<Menu, Long>, JpaSpecificat
...
@@ -20,17 +23,12 @@ public interface MenuRepository extends JpaRepository<Menu, Long>, JpaSpecificat
*/
*/
Menu
findByName
(
String
name
);
Menu
findByName
(
String
name
);
/**
* findByRoles
* @param roleSet
* @return
*/
Set
<
Menu
>
findByRolesOrderBySort
(
Set
<
Role
>
roleSet
);
/**
/**
* findByPid
* findByPid
* @param pid
* @param pid
* @return
* @return
*/
*/
List
<
Menu
>
findByPid
(
long
pid
);
List
<
Menu
>
findByPid
(
long
pid
);
LinkedHashSet
<
Menu
>
findByRoles_IdOrderBySortAsc
(
Long
id
);
}
}
eladmin-system/src/main/java/me/zhengjie/modules/system/repository/PermissionRepository.java
View file @
4e39694e
...
@@ -4,6 +4,8 @@ import me.zhengjie.modules.system.domain.Permission;
...
@@ -4,6 +4,8 @@ import me.zhengjie.modules.system.domain.Permission;
import
me.zhengjie.modules.system.domain.Role
;
import
me.zhengjie.modules.system.domain.Role
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.Set
;
...
@@ -20,17 +22,12 @@ public interface PermissionRepository extends JpaRepository<Permission, Long>, J
...
@@ -20,17 +22,12 @@ public interface PermissionRepository extends JpaRepository<Permission, Long>, J
*/
*/
Permission
findByName
(
String
name
);
Permission
findByName
(
String
name
);
/**
* findByRoles
* @param roleSet
* @return
*/
Set
<
Permission
>
findByRoles
(
Set
<
Role
>
roleSet
);
/**
/**
* findByPid
* findByPid
* @param pid
* @param pid
* @return
* @return
*/
*/
List
<
Permission
>
findByPid
(
long
pid
);
List
<
Permission
>
findByPid
(
long
pid
);
Set
<
Permission
>
findByRoles_Id
(
Long
id
);
}
}
eladmin-system/src/main/java/me/zhengjie/modules/system/repository/RoleRepository.java
View file @
4e39694e
...
@@ -4,6 +4,8 @@ import me.zhengjie.modules.system.domain.Role;
...
@@ -4,6 +4,8 @@ import me.zhengjie.modules.system.domain.Role;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaRepository
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
java.util.Set
;
/**
/**
* @author jie
* @author jie
* @date 2018-12-03
* @date 2018-12-03
...
@@ -16,4 +18,6 @@ public interface RoleRepository extends JpaRepository<Role, Long>, JpaSpecificat
...
@@ -16,4 +18,6 @@ public interface RoleRepository extends JpaRepository<Role, Long>, JpaSpecificat
* @return
* @return
*/
*/
Role
findByName
(
String
name
);
Role
findByName
(
String
name
);
Set
<
Role
>
findByUsers_Id
(
Long
id
);
}
}
eladmin-system/src/main/java/me/zhengjie/modules/system/repository/UserRepository.java
View file @
4e39694e
...
@@ -5,8 +5,6 @@ import org.springframework.data.jpa.repository.JpaRepository;
...
@@ -5,8 +5,6 @@ import org.springframework.data.jpa.repository.JpaRepository;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.data.jpa.repository.JpaSpecificationExecutor
;
import
org.springframework.data.jpa.repository.Modifying
;
import
org.springframework.data.jpa.repository.Modifying
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.data.jpa.repository.Query
;
import
org.springframework.data.repository.query.Param
;
import
java.util.Date
;
import
java.util.Date
;
/**
/**
...
@@ -20,16 +18,14 @@ public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificat
...
@@ -20,16 +18,14 @@ public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificat
* @param username
* @param username
* @return
* @return
*/
*/
@Query
(
"from User u join fetch u.roles where u.username = :username"
)
User
findByUsername
(
String
username
);
User
findByUsername
(
@Param
(
"username"
)
String
username
);
/**
/**
* findByEmail
* findByEmail
* @param email
* @param email
* @return
* @return
*/
*/
@Query
(
"from User u join fetch u.roles where u.email = :email"
)
User
findByEmail
(
String
email
);
User
findByEmail
(
@Param
(
"email"
)
String
email
);
/**
/**
* 修改密码
* 修改密码
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/rest/MenuController.java
View file @
4e39694e
...
@@ -4,8 +4,8 @@ import me.zhengjie.aop.log.Log;
...
@@ -4,8 +4,8 @@ import me.zhengjie.aop.log.Log;
import
me.zhengjie.modules.system.domain.Menu
;
import
me.zhengjie.modules.system.domain.Menu
;
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.security.utils.JwtTokenUtil
;
import
me.zhengjie.modules.system.service.MenuService
;
import
me.zhengjie.modules.system.service.MenuService
;
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.query.MenuQueryService
;
import
me.zhengjie.modules.system.service.query.MenuQueryService
;
...
@@ -17,7 +17,6 @@ import org.springframework.security.access.prepost.PreAuthorize;
...
@@ -17,7 +17,6 @@ import org.springframework.security.access.prepost.PreAuthorize;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.core.userdetails.UserDetails
;
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
javax.servlet.http.HttpServletRequest
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -28,9 +27,6 @@ import java.util.List;
...
@@ -28,9 +27,6 @@ import java.util.List;
@RequestMapping
(
"api"
)
@RequestMapping
(
"api"
)
public
class
MenuController
{
public
class
MenuController
{
@Autowired
private
JwtTokenUtil
jwtTokenUtil
;
@Autowired
@Autowired
private
MenuService
menuService
;
private
MenuService
menuService
;
...
@@ -40,13 +36,10 @@ public class MenuController {
...
@@ -40,13 +36,10 @@ public class MenuController {
@Autowired
@Autowired
private
UserService
userService
;
private
UserService
userService
;
private
static
final
String
ENTITY_NAME
=
"menu"
;
@Autowired
private
RoleService
roleService
;
@GetMapping
(
value
=
"/menus/{id}"
)
private
static
final
String
ENTITY_NAME
=
"menu"
;
@PreAuthorize
(
"hasAnyRole('ADMIN','MENU_ALL','MENU_SELECT')"
)
public
ResponseEntity
getMenus
(
@PathVariable
Long
id
){
return
new
ResponseEntity
(
menuService
.
findById
(
id
),
HttpStatus
.
OK
);
}
/**
/**
* 构建前端路由所需要的菜单
* 构建前端路由所需要的菜单
...
@@ -56,7 +49,7 @@ public class MenuController {
...
@@ -56,7 +49,7 @@ public class MenuController {
public
ResponseEntity
buildMenus
(){
public
ResponseEntity
buildMenus
(){
UserDetails
userDetails
=
SecurityContextHolder
.
getUserDetails
();
UserDetails
userDetails
=
SecurityContextHolder
.
getUserDetails
();
User
user
=
userService
.
findByName
(
userDetails
.
getUsername
());
User
user
=
userService
.
findByName
(
userDetails
.
getUsername
());
List
<
MenuDTO
>
menuDTOList
=
menuService
.
findByRoles
(
user
.
get
Roles
(
));
List
<
MenuDTO
>
menuDTOList
=
menuService
.
findByRoles
(
roleService
.
findByUsers_Id
(
user
.
get
Id
()
));
List
<
MenuDTO
>
menuDTOTree
=
(
List
<
MenuDTO
>)
menuService
.
buildTree
(
menuDTOList
).
get
(
"content"
);
List
<
MenuDTO
>
menuDTOTree
=
(
List
<
MenuDTO
>)
menuService
.
buildTree
(
menuDTOList
).
get
(
"content"
);
return
new
ResponseEntity
(
menuService
.
buildMenus
(
menuDTOTree
),
HttpStatus
.
OK
);
return
new
ResponseEntity
(
menuService
.
buildMenus
(
menuDTOTree
),
HttpStatus
.
OK
);
}
}
...
@@ -66,7 +59,7 @@ public class MenuController {
...
@@ -66,7 +59,7 @@ public class MenuController {
* @return
* @return
*/
*/
@GetMapping
(
value
=
"/menus/tree"
)
@GetMapping
(
value
=
"/menus/tree"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','MENU_ALL','MENU_SELECT')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','MENU_ALL','MENU_SELECT'
,'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
);
}
}
...
@@ -92,10 +85,7 @@ public class MenuController {
...
@@ -92,10 +85,7 @@ public class MenuController {
@Log
(
"修改菜单"
)
@Log
(
"修改菜单"
)
@PutMapping
(
value
=
"/menus"
)
@PutMapping
(
value
=
"/menus"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','MENU_ALL','MENU_EDIT')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','MENU_ALL','MENU_EDIT')"
)
public
ResponseEntity
update
(
@Validated
@RequestBody
Menu
resources
){
public
ResponseEntity
update
(
@Validated
(
Menu
.
Update
.
class
)
@RequestBody
Menu
resources
){
if
(
resources
.
getId
()
==
null
)
{
throw
new
BadRequestException
(
ENTITY_NAME
+
" ID Can not be empty"
);
}
menuService
.
update
(
resources
);
menuService
.
update
(
resources
);
return
new
ResponseEntity
(
HttpStatus
.
NO_CONTENT
);
return
new
ResponseEntity
(
HttpStatus
.
NO_CONTENT
);
}
}
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/rest/PermissionController.java
View file @
4e39694e
...
@@ -31,12 +31,6 @@ public class PermissionController {
...
@@ -31,12 +31,6 @@ public class PermissionController {
private
static
final
String
ENTITY_NAME
=
"permission"
;
private
static
final
String
ENTITY_NAME
=
"permission"
;
@GetMapping
(
value
=
"/permissions/{id}"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','PERMISSION_ALL','PERMISSION_SELECT')"
)
public
ResponseEntity
getPermissions
(
@PathVariable
Long
id
){
return
new
ResponseEntity
(
permissionService
.
findById
(
id
),
HttpStatus
.
OK
);
}
/**
/**
* 返回全部的权限,新增角色时下拉选择
* 返回全部的权限,新增角色时下拉选择
* @return
* @return
...
@@ -68,10 +62,7 @@ public class PermissionController {
...
@@ -68,10 +62,7 @@ public class PermissionController {
@Log
(
"修改权限"
)
@Log
(
"修改权限"
)
@PutMapping
(
value
=
"/permissions"
)
@PutMapping
(
value
=
"/permissions"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','PERMISSION_ALL','PERMISSION_EDIT')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','PERMISSION_ALL','PERMISSION_EDIT')"
)
public
ResponseEntity
update
(
@Validated
@RequestBody
Permission
resources
){
public
ResponseEntity
update
(
@Validated
(
Permission
.
Update
.
class
)
@RequestBody
Permission
resources
){
if
(
resources
.
getId
()
==
null
)
{
throw
new
BadRequestException
(
ENTITY_NAME
+
" ID Can not be empty"
);
}
permissionService
.
update
(
resources
);
permissionService
.
update
(
resources
);
return
new
ResponseEntity
(
HttpStatus
.
NO_CONTENT
);
return
new
ResponseEntity
(
HttpStatus
.
NO_CONTENT
);
}
}
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/rest/RoleController.java
View file @
4e39694e
...
@@ -41,7 +41,7 @@ public class RoleController {
...
@@ -41,7 +41,7 @@ public class RoleController {
* @return
* @return
*/
*/
@GetMapping
(
value
=
"/roles/tree"
)
@GetMapping
(
value
=
"/roles/tree"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','
MENU_ALL','MENU_SELECT','
ROLES_ALL','USER_ALL','USER_SELECT')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','ROLES_ALL','USER_ALL','USER_SELECT')"
)
public
ResponseEntity
getRoleTree
(){
public
ResponseEntity
getRoleTree
(){
return
new
ResponseEntity
(
roleService
.
getRoleTree
(),
HttpStatus
.
OK
);
return
new
ResponseEntity
(
roleService
.
getRoleTree
(),
HttpStatus
.
OK
);
}
}
...
@@ -66,14 +66,27 @@ public class RoleController {
...
@@ -66,14 +66,27 @@ public class RoleController {
@Log
(
"修改角色"
)
@Log
(
"修改角色"
)
@PutMapping
(
value
=
"/roles"
)
@PutMapping
(
value
=
"/roles"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','ROLES_ALL','ROLES_EDIT')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','ROLES_ALL','ROLES_EDIT')"
)
public
ResponseEntity
update
(
@Validated
@RequestBody
Role
resources
){
public
ResponseEntity
update
(
@Validated
(
Role
.
Update
.
class
)
@RequestBody
Role
resources
){
if
(
resources
.
getId
()
==
null
)
{
throw
new
BadRequestException
(
ENTITY_NAME
+
" ID Can not be empty"
);
}
roleService
.
update
(
resources
);
roleService
.
update
(
resources
);
return
new
ResponseEntity
(
HttpStatus
.
NO_CONTENT
);
return
new
ResponseEntity
(
HttpStatus
.
NO_CONTENT
);
}
}
@Log
(
"修改角色权限"
)
@PutMapping
(
value
=
"/roles/permission"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','ROLES_ALL','ROLES_EDIT')"
)
public
ResponseEntity
updatePermission
(
@RequestBody
Role
resources
){
roleService
.
updatePermission
(
resources
,
roleService
.
findById
(
resources
.
getId
()));
return
new
ResponseEntity
(
HttpStatus
.
NO_CONTENT
);
}
@Log
(
"修改角色菜单"
)
@PutMapping
(
value
=
"/roles/menu"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','ROLES_ALL','ROLES_EDIT')"
)
public
ResponseEntity
updateMenu
(
@RequestBody
Role
resources
){
roleService
.
updateMenu
(
resources
,
roleService
.
findById
(
resources
.
getId
()));
return
new
ResponseEntity
(
HttpStatus
.
NO_CONTENT
);
}
@Log
(
"删除角色"
)
@Log
(
"删除角色"
)
@DeleteMapping
(
value
=
"/roles/{id}"
)
@DeleteMapping
(
value
=
"/roles/{id}"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','ROLES_ALL','ROLES_DELETE')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','ROLES_ALL','ROLES_DELETE')"
)
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/rest/UserController.java
View file @
4e39694e
...
@@ -59,12 +59,6 @@ public class UserController {
...
@@ -59,12 +59,6 @@ public class UserController {
private
static
final
String
ENTITY_NAME
=
"user"
;
private
static
final
String
ENTITY_NAME
=
"user"
;
@GetMapping
(
value
=
"/users/{id}"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','USER_ALL','USER_SELECT')"
)
public
ResponseEntity
getUser
(
@PathVariable
Long
id
){
return
new
ResponseEntity
(
userService
.
findById
(
id
),
HttpStatus
.
OK
);
}
@Log
(
"查询用户"
)
@Log
(
"查询用户"
)
@GetMapping
(
value
=
"/users"
)
@GetMapping
(
value
=
"/users"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','USER_ALL','USER_SELECT')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','USER_ALL','USER_SELECT')"
)
...
@@ -85,10 +79,7 @@ public class UserController {
...
@@ -85,10 +79,7 @@ public class UserController {
@Log
(
"修改用户"
)
@Log
(
"修改用户"
)
@PutMapping
(
value
=
"/users"
)
@PutMapping
(
value
=
"/users"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','USER_ALL','USER_EDIT')"
)
@PreAuthorize
(
"hasAnyRole('ADMIN','USER_ALL','USER_EDIT')"
)
public
ResponseEntity
update
(
@Validated
@RequestBody
User
resources
){
public
ResponseEntity
update
(
@Validated
(
User
.
Update
.
class
)
@RequestBody
User
resources
){
if
(
resources
.
getId
()
==
null
)
{
throw
new
BadRequestException
(
ENTITY_NAME
+
" ID Can not be empty"
);
}
userService
.
update
(
resources
);
userService
.
update
(
resources
);
return
new
ResponseEntity
(
HttpStatus
.
NO_CONTENT
);
return
new
ResponseEntity
(
HttpStatus
.
NO_CONTENT
);
}
}
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/service/MenuService.java
View file @
4e39694e
...
@@ -67,7 +67,6 @@ public interface MenuService {
...
@@ -67,7 +67,6 @@ public interface MenuService {
* @param menuDTOS
* @param menuDTOS
* @return
* @return
*/
*/
@Cacheable
(
keyGenerator
=
"keyGenerator"
)
Map
buildTree
(
List
<
MenuDTO
>
menuDTOS
);
Map
buildTree
(
List
<
MenuDTO
>
menuDTOS
);
/**
/**
...
@@ -82,6 +81,5 @@ public interface MenuService {
...
@@ -82,6 +81,5 @@ public interface MenuService {
* @param byRoles
* @param byRoles
* @return
* @return
*/
*/
@Cacheable
(
keyGenerator
=
"keyGenerator"
)
Object
buildMenus
(
List
<
MenuDTO
>
byRoles
);
Object
buildMenus
(
List
<
MenuDTO
>
byRoles
);
}
}
eladmin-system/src/main/java/me/zhengjie/modules/system/service/RoleService.java
View file @
4e39694e
...
@@ -6,6 +6,8 @@ import org.springframework.cache.annotation.CacheConfig;
...
@@ -6,6 +6,8 @@ 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.Set
;
/**
/**
* @author jie
* @author jie
* @date 2018-12-03
* @date 2018-12-03
...
@@ -49,4 +51,27 @@ public interface RoleService {
...
@@ -49,4 +51,27 @@ public interface RoleService {
*/
*/
@Cacheable
(
key
=
"'tree'"
)
@Cacheable
(
key
=
"'tree'"
)
Object
getRoleTree
();
Object
getRoleTree
();
/**
* findByUsers_Id
* @param id
* @return
*/
Set
<
Role
>
findByUsers_Id
(
Long
id
);
/**
* updatePermission
* @param resources
* @param roleDTO
*/
@CacheEvict
(
allEntries
=
true
)
void
updatePermission
(
Role
resources
,
RoleDTO
roleDTO
);
/**
* updateMenu
* @param resources
* @param roleDTO
*/
@CacheEvict
(
allEntries
=
true
)
void
updateMenu
(
Role
resources
,
RoleDTO
roleDTO
);
}
}
eladmin-system/src/main/java/me/zhengjie/modules/system/service/UserService.java
View file @
4e39694e
...
@@ -49,6 +49,7 @@ public interface UserService {
...
@@ -49,6 +49,7 @@ public interface UserService {
* @param userName
* @param userName
* @return
* @return
*/
*/
@Cacheable
(
keyGenerator
=
"keyGenerator"
)
User
findByName
(
String
userName
);
User
findByName
(
String
userName
);
/**
/**
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/MenuDTO.java
View file @
4e39694e
...
@@ -29,8 +29,6 @@ public class MenuDTO {
...
@@ -29,8 +29,6 @@ public class MenuDTO {
private
String
icon
;
private
String
icon
;
private
Set
<
RoleDTO
>
roles
;
private
List
<
MenuDTO
>
children
;
private
List
<
MenuDTO
>
children
;
private
Timestamp
createTime
;
private
Timestamp
createTime
;
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/RoleDTO.java
View file @
4e39694e
...
@@ -20,5 +20,7 @@ public class RoleDTO implements Serializable {
...
@@ -20,5 +20,7 @@ public class RoleDTO implements Serializable {
private
Set
<
PermissionDTO
>
permissions
;
private
Set
<
PermissionDTO
>
permissions
;
private
Set
<
MenuDTO
>
menus
;
private
Timestamp
createTime
;
private
Timestamp
createTime
;
}
}
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MenuServiceImpl.java
View file @
4e39694e
...
@@ -11,7 +11,6 @@ import me.zhengjie.modules.system.repository.MenuRepository;
...
@@ -11,7 +11,6 @@ import me.zhengjie.modules.system.repository.MenuRepository;
import
me.zhengjie.modules.system.service.MenuService
;
import
me.zhengjie.modules.system.service.MenuService
;
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.mapper.MenuMapper
;
import
me.zhengjie.utils.ListSortUtil
;
import
me.zhengjie.utils.ValidationUtil
;
import
me.zhengjie.utils.ValidationUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -41,9 +40,7 @@ public class MenuServiceImpl implements MenuService {
...
@@ -41,9 +40,7 @@ public class MenuServiceImpl implements MenuService {
public
List
<
MenuDTO
>
findByRoles
(
Set
<
Role
>
roles
)
{
public
List
<
MenuDTO
>
findByRoles
(
Set
<
Role
>
roles
)
{
Set
<
Menu
>
menus
=
new
LinkedHashSet
<>();
Set
<
Menu
>
menus
=
new
LinkedHashSet
<>();
for
(
Role
role
:
roles
)
{
for
(
Role
role
:
roles
)
{
ListSortUtil
<
Menu
>
sortList
=
new
ListSortUtil
<
Menu
>();
List
<
Menu
>
menus1
=
menuRepository
.
findByRoles_IdOrderBySortAsc
(
role
.
getId
()).
stream
().
collect
(
Collectors
.
toList
());
List
<
Menu
>
menus1
=
role
.
getMenus
().
stream
().
collect
(
Collectors
.
toList
());
sortList
.
sort
(
menus1
,
"sort"
,
"asc"
);
menus
.
addAll
(
menus1
);
menus
.
addAll
(
menus1
);
}
}
return
menus
.
stream
().
map
(
menuMapper:
:
toDto
).
collect
(
Collectors
.
toList
());
return
menus
.
stream
().
map
(
menuMapper:
:
toDto
).
collect
(
Collectors
.
toList
());
...
@@ -85,7 +82,6 @@ public class MenuServiceImpl implements MenuService {
...
@@ -85,7 +82,6 @@ public class MenuServiceImpl implements MenuService {
menu
.
setIFrame
(
resources
.
getIFrame
());
menu
.
setIFrame
(
resources
.
getIFrame
());
menu
.
setPid
(
resources
.
getPid
());
menu
.
setPid
(
resources
.
getPid
());
menu
.
setSort
(
resources
.
getSort
());
menu
.
setSort
(
resources
.
getSort
());
menu
.
setRoles
(
resources
.
getRoles
());
menuRepository
.
save
(
menu
);
menuRepository
.
save
(
menu
);
}
}
...
@@ -141,11 +137,9 @@ public class MenuServiceImpl implements MenuService {
...
@@ -141,11 +137,9 @@ public class MenuServiceImpl implements MenuService {
}
}
}
}
}
}
Integer
totalElements
=
menuDTOS
!=
null
?
menuDTOS
.
size
():
0
;
Map
map
=
new
HashMap
();
Map
map
=
new
HashMap
();
map
.
put
(
"content"
,
trees
.
size
()
==
0
?
menuDTOS:
trees
);
map
.
put
(
"content"
,
trees
.
size
()
==
0
?
menuDTOS:
trees
);
map
.
put
(
"totalElements"
,
totalElements
);
map
.
put
(
"totalElements"
,
menuDTOS
!=
null
?
menuDTOS
.
size
():
0
);
return
map
;
return
map
;
}
}
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/PermissionServiceImpl.java
View file @
4e39694e
...
@@ -47,18 +47,19 @@ public class PermissionServiceImpl implements PermissionService {
...
@@ -47,18 +47,19 @@ public class PermissionServiceImpl implements PermissionService {
@Override
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
update
(
Permission
resources
)
{
public
void
update
(
Permission
resources
)
{
Optional
<
Permission
>
optionalPermission
=
permissionRepository
.
findById
(
resources
.
getId
());
ValidationUtil
.
isNull
(
optionalPermission
,
"Permission"
,
"id"
,
resources
.
getId
());
Permission
permission
=
optionalPermission
.
get
();
/**
/**
* 根据实际需求修改
* 根据实际需求修改
*/
*/
if
(
permission
.
getId
().
equals
(
1L
)){
if
(
resources
.
getId
().
equals
(
1L
)){
throw
new
BadRequestException
(
"该权限不能被修改"
);
throw
new
BadRequestException
(
"该权限不能被修改"
);
}
}
Optional
<
Permission
>
optionalPermission
=
permissionRepository
.
findById
(
resources
.
getId
());
ValidationUtil
.
isNull
(
optionalPermission
,
"Permission"
,
"id"
,
resources
.
getId
());
Permission
permission
=
optionalPermission
.
get
();
Permission
permission1
=
permissionRepository
.
findByName
(
resources
.
getName
());
Permission
permission1
=
permissionRepository
.
findByName
(
resources
.
getName
());
if
(
permission1
!=
null
&&
!
permission1
.
getId
().
equals
(
permission
.
getId
())){
if
(
permission1
!=
null
&&
!
permission1
.
getId
().
equals
(
permission
.
getId
())){
...
@@ -80,6 +81,7 @@ public class PermissionServiceImpl implements PermissionService {
...
@@ -80,6 +81,7 @@ public class PermissionServiceImpl implements PermissionService {
if
(
id
.
equals
(
1L
)){
if
(
id
.
equals
(
1L
)){
throw
new
BadRequestException
(
"该权限不能被删除"
);
throw
new
BadRequestException
(
"该权限不能被删除"
);
}
}
List
<
Permission
>
permissionList
=
permissionRepository
.
findByPid
(
id
);
List
<
Permission
>
permissionList
=
permissionRepository
.
findByPid
(
id
);
for
(
Permission
permission
:
permissionList
)
{
for
(
Permission
permission
:
permissionList
)
{
permissionRepository
.
delete
(
permission
);
permissionRepository
.
delete
(
permission
);
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/RoleServiceImpl.java
View file @
4e39694e
...
@@ -47,18 +47,20 @@ public class RoleServiceImpl implements RoleService {
...
@@ -47,18 +47,20 @@ public class RoleServiceImpl implements RoleService {
@Override
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
update
(
Role
resources
)
{
public
void
update
(
Role
resources
)
{
Optional
<
Role
>
optionalRole
=
roleRepository
.
findById
(
resources
.
getId
());
ValidationUtil
.
isNull
(
optionalRole
,
"Role"
,
"id"
,
resources
.
getId
());
Role
role
=
optionalRole
.
get
();
/**
/**
* 根据实际需求修改
* 根据实际需求修改
*/
*/
if
(
r
ole
.
getId
().
equals
(
1L
)){
if
(
r
esources
.
getId
().
equals
(
1L
)){
throw
new
BadRequestException
(
"该角色不能被修改"
);
throw
new
BadRequestException
(
"该角色不能被修改"
);
}
}
Optional
<
Role
>
optionalRole
=
roleRepository
.
findById
(
resources
.
getId
());
ValidationUtil
.
isNull
(
optionalRole
,
"Role"
,
"id"
,
resources
.
getId
());
Role
role
=
optionalRole
.
get
();
Role
role1
=
roleRepository
.
findByName
(
resources
.
getName
());
Role
role1
=
roleRepository
.
findByName
(
resources
.
getName
());
if
(
role1
!=
null
&&
!
role1
.
getId
().
equals
(
role
.
getId
())){
if
(
role1
!=
null
&&
!
role1
.
getId
().
equals
(
role
.
getId
())){
...
@@ -67,14 +69,38 @@ public class RoleServiceImpl implements RoleService {
...
@@ -67,14 +69,38 @@ public class RoleServiceImpl implements RoleService {
role
.
setName
(
resources
.
getName
());
role
.
setName
(
resources
.
getName
());
role
.
setRemark
(
resources
.
getRemark
());
role
.
setRemark
(
resources
.
getRemark
());
roleRepository
.
save
(
role
);
}
@Override
public
void
updatePermission
(
Role
resources
,
RoleDTO
roleDTO
)
{
/**
* 根据实际需求修改
*/
if
(
resources
.
getId
().
equals
(
1L
)){
throw
new
BadRequestException
(
"该角色不可操作"
);
}
Role
role
=
roleMapper
.
toEntity
(
roleDTO
);
role
.
setPermissions
(
resources
.
getPermissions
());
role
.
setPermissions
(
resources
.
getPermissions
());
roleRepository
.
save
(
role
);
roleRepository
.
save
(
role
);
}
}
@Override
public
void
updateMenu
(
Role
resources
,
RoleDTO
roleDTO
)
{
/**
* 根据实际需求修改
*/
if
(
resources
.
getId
().
equals
(
1L
)){
throw
new
BadRequestException
(
"该角色不可操作"
);
}
Role
role
=
roleMapper
.
toEntity
(
roleDTO
);
role
.
setMenus
(
resources
.
getMenus
());
roleRepository
.
save
(
role
);
}
@Override
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
delete
(
Long
id
)
{
public
void
delete
(
Long
id
)
{
/**
/**
* 根据实际需求修改
* 根据实际需求修改
*/
*/
...
@@ -98,4 +124,9 @@ public class RoleServiceImpl implements RoleService {
...
@@ -98,4 +124,9 @@ public class RoleServiceImpl implements RoleService {
}
}
return
list
;
return
list
;
}
}
@Override
public
Set
<
Role
>
findByUsers_Id
(
Long
id
)
{
return
roleRepository
.
findByUsers_Id
(
id
);
}
}
}
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java
View file @
4e39694e
...
@@ -15,7 +15,6 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -15,7 +15,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.Optional
;
import
java.util.Optional
;
...
@@ -59,7 +58,7 @@ public class UserServiceImpl implements UserService {
...
@@ -59,7 +58,7 @@ public class UserServiceImpl implements UserService {
throw
new
BadRequestException
(
"角色不能为空"
);
throw
new
BadRequestException
(
"角色不能为空"
);
}
}
// 默认密码 123456
// 默认密码 123456
,此密码是 MD5加密后的字符
resources
.
setPassword
(
"14e1b600b1fd579f47433b88e8d85291"
);
resources
.
setPassword
(
"14e1b600b1fd579f47433b88e8d85291"
);
resources
.
setAvatar
(
"https://i.loli.net/2018/12/06/5c08894d8de21.jpg"
);
resources
.
setAvatar
(
"https://i.loli.net/2018/12/06/5c08894d8de21.jpg"
);
return
userMapper
.
toDto
(
userRepository
.
save
(
resources
));
return
userMapper
.
toDto
(
userRepository
.
save
(
resources
));
...
@@ -69,18 +68,18 @@ public class UserServiceImpl implements UserService {
...
@@ -69,18 +68,18 @@ public class UserServiceImpl implements UserService {
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
update
(
User
resources
)
{
public
void
update
(
User
resources
)
{
Optional
<
User
>
userOptional
=
userRepository
.
findById
(
resources
.
getId
());
ValidationUtil
.
isNull
(
userOptional
,
"User"
,
"id"
,
resources
.
getId
());
User
user
=
userOptional
.
get
();
/**
/**
* 根据实际需求修改
* 根据实际需求修改
*/
*/
if
(
user
.
getId
().
equals
(
1L
)){
if
(
resources
.
getId
().
equals
(
1L
)){
throw
new
BadRequestException
(
"该账号不能被修改"
);
throw
new
BadRequestException
(
"该账号不能被修改"
);
}
}
Optional
<
User
>
userOptional
=
userRepository
.
findById
(
resources
.
getId
());
ValidationUtil
.
isNull
(
userOptional
,
"User"
,
"id"
,
resources
.
getId
());
User
user
=
userOptional
.
get
();
User
user1
=
userRepository
.
findByUsername
(
user
.
getUsername
());
User
user1
=
userRepository
.
findByUsername
(
user
.
getUsername
());
User
user2
=
userRepository
.
findByEmail
(
user
.
getEmail
());
User
user2
=
userRepository
.
findByEmail
(
user
.
getEmail
());
...
@@ -107,7 +106,6 @@ public class UserServiceImpl implements UserService {
...
@@ -107,7 +106,6 @@ public class UserServiceImpl implements UserService {
@Override
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
delete
(
Long
id
)
{
public
void
delete
(
Long
id
)
{
/**
/**
* 根据实际需求修改
* 根据实际需求修改
*/
*/
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/service/mapper/MenuMapper.java
View file @
4e39694e
...
@@ -10,7 +10,7 @@ import org.mapstruct.ReportingPolicy;
...
@@ -10,7 +10,7 @@ import org.mapstruct.ReportingPolicy;
* @author jie
* @author jie
* @date 2018-12-17
* @date 2018-12-17
*/
*/
@Mapper
(
componentModel
=
"spring"
,
uses
=
{
RoleMapper
.
class
},
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
@Mapper
(
componentModel
=
"spring"
,
uses
=
{},
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
public
interface
MenuMapper
extends
EntityMapper
<
MenuDTO
,
Menu
>
{
public
interface
MenuMapper
extends
EntityMapper
<
MenuDTO
,
Menu
>
{
}
}
Prev
1
2
3
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