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
d5d48015
Commit
d5d48015
authored
Oct 29, 2019
by
dqjdda
Browse files
角色菜单改造完成,去除权限管理,采用按钮方式显示在菜单管理中
parent
e1366ee4
Changes
31
Hide whitespace changes
Inline
Side-by-side
eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/PermissionDTO.java
deleted
100644 → 0
View file @
e1366ee4
package
me.zhengjie.modules.system.service.dto
;
import
lombok.Getter
;
import
lombok.Setter
;
import
java.sql.Timestamp
;
import
java.util.List
;
/**
* @author Zheng Jie
* @date 2018-12-03
*/
@Getter
@Setter
public
class
PermissionDTO
{
private
Long
id
;
private
String
name
;
private
Long
pid
;
private
String
alias
;
private
List
<
PermissionDTO
>
children
;
private
Timestamp
createTime
;
}
eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/PermissionQueryCriteria.java
deleted
100644 → 0
View file @
e1366ee4
package
me.zhengjie.modules.system.service.dto
;
import
lombok.Data
;
import
me.zhengjie.annotation.Query
;
/**
* 公共查询类
*/
@Data
public
class
PermissionQueryCriteria
{
// 多字段模糊
@Query
(
blurry
=
"name,alias"
)
private
String
blurry
;
}
eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/RoleDTO.java
View file @
d5d48015
...
...
@@ -26,8 +26,6 @@ public class RoleDTO{
private
String
permission
;
private
Set
<
PermissionDTO
>
permissions
;
private
Set
<
MenuDTO
>
menus
;
private
Set
<
DeptDTO
>
depts
;
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/PermissionServiceImpl.java
deleted
100644 → 0
View file @
e1366ee4
package
me.zhengjie.modules.system.service.impl
;
import
me.zhengjie.modules.system.domain.Permission
;
import
me.zhengjie.exception.BadRequestException
;
import
me.zhengjie.exception.EntityExistException
;
import
me.zhengjie.modules.system.repository.PermissionRepository
;
import
me.zhengjie.modules.system.service.PermissionService
;
import
me.zhengjie.modules.system.service.RoleService
;
import
me.zhengjie.modules.system.service.dto.PermissionDTO
;
import
me.zhengjie.modules.system.service.dto.PermissionQueryCriteria
;
import
me.zhengjie.modules.system.service.mapper.PermissionMapper
;
import
me.zhengjie.utils.QueryHelp
;
import
me.zhengjie.utils.ValidationUtil
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Propagation
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.*
;
/**
* @author Zheng Jie
* @date 2018-12-03
*/
@Service
@CacheConfig
(
cacheNames
=
"permission"
)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
PermissionServiceImpl
implements
PermissionService
{
private
final
PermissionRepository
permissionRepository
;
private
final
PermissionMapper
permissionMapper
;
private
final
RoleService
roleService
;
public
PermissionServiceImpl
(
PermissionRepository
permissionRepository
,
PermissionMapper
permissionMapper
,
RoleService
roleService
)
{
this
.
permissionRepository
=
permissionRepository
;
this
.
permissionMapper
=
permissionMapper
;
this
.
roleService
=
roleService
;
}
@Override
@Cacheable
public
List
<
PermissionDTO
>
queryAll
(
PermissionQueryCriteria
criteria
)
{
// Sort sort = new Sort(Sort.Direction.DESC,"id");
return
permissionMapper
.
toDto
(
permissionRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
)));
}
@Override
@Cacheable
(
key
=
"#p0"
)
public
PermissionDTO
findById
(
long
id
)
{
Permission
permission
=
permissionRepository
.
findById
(
id
).
orElseGet
(
Permission:
:
new
);
ValidationUtil
.
isNull
(
permission
.
getId
(),
"Permission"
,
"id"
,
id
);
return
permissionMapper
.
toDto
(
permission
);
}
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
PermissionDTO
create
(
Permission
resources
)
{
if
(
permissionRepository
.
findByName
(
resources
.
getName
())
!=
null
){
throw
new
EntityExistException
(
Permission
.
class
,
"name"
,
resources
.
getName
());
}
return
permissionMapper
.
toDto
(
permissionRepository
.
save
(
resources
));
}
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
update
(
Permission
resources
)
{
Permission
permission
=
permissionRepository
.
findById
(
resources
.
getId
()).
orElseGet
(
Permission:
:
new
);
if
(
resources
.
getId
().
equals
(
resources
.
getPid
()))
{
throw
new
BadRequestException
(
"上级不能为自己"
);
}
ValidationUtil
.
isNull
(
permission
.
getId
(),
"Permission"
,
"id"
,
resources
.
getId
());
Permission
permission1
=
permissionRepository
.
findByName
(
resources
.
getName
());
if
(
permission1
!=
null
&&
!
permission1
.
getId
().
equals
(
permission
.
getId
())){
throw
new
EntityExistException
(
Permission
.
class
,
"name"
,
resources
.
getName
());
}
permission
.
setName
(
resources
.
getName
());
permission
.
setAlias
(
resources
.
getAlias
());
permission
.
setPid
(
resources
.
getPid
());
permissionRepository
.
save
(
permission
);
}
@Override
public
Set
<
Permission
>
getDeletePermission
(
List
<
Permission
>
permissions
,
Set
<
Permission
>
permissionSet
)
{
// 递归找出待删除的菜单
for
(
Permission
permission
:
permissions
)
{
permissionSet
.
add
(
permission
);
List
<
Permission
>
permissionList
=
permissionRepository
.
findByPid
(
permission
.
getId
());
if
(
permissionList
!=
null
&&
permissionList
.
size
()!=
0
){
getDeletePermission
(
permissionList
,
permissionSet
);
}
}
return
permissionSet
;
}
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
delete
(
Set
<
Permission
>
permissions
)
{
for
(
Permission
permission
:
permissions
)
{
roleService
.
untiedPermission
(
permission
.
getId
());
permissionRepository
.
delete
(
permission
);
}
}
@Override
@Cacheable
(
key
=
"'tree'"
)
public
Object
getPermissionTree
(
List
<
Permission
>
permissions
)
{
List
<
Map
<
String
,
Object
>>
list
=
new
LinkedList
<>();
permissions
.
forEach
(
permission
->
{
if
(
permission
!=
null
){
List
<
Permission
>
permissionList
=
permissionRepository
.
findByPid
(
permission
.
getId
());
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"id"
,
permission
.
getId
());
map
.
put
(
"label"
,
permission
.
getAlias
());
if
(
permissionList
!=
null
&&
permissionList
.
size
()!=
0
){
map
.
put
(
"children"
,
getPermissionTree
(
permissionList
));
}
list
.
add
(
map
);
}
}
);
return
list
;
}
@Override
@Cacheable
(
key
=
"'pid:'+#p0"
)
public
List
<
Permission
>
findByPid
(
long
pid
)
{
return
permissionRepository
.
findByPid
(
pid
);
}
@Override
@Cacheable
public
Object
buildTree
(
List
<
PermissionDTO
>
permissionDTOS
)
{
List
<
PermissionDTO
>
trees
=
new
ArrayList
<>();
for
(
PermissionDTO
permissionDTO
:
permissionDTOS
)
{
if
(
"0"
.
equals
(
permissionDTO
.
getPid
().
toString
()))
{
trees
.
add
(
permissionDTO
);
}
for
(
PermissionDTO
it
:
permissionDTOS
)
{
if
(
it
.
getPid
().
equals
(
permissionDTO
.
getId
()))
{
if
(
permissionDTO
.
getChildren
()
==
null
)
{
permissionDTO
.
setChildren
(
new
ArrayList
<>());
}
permissionDTO
.
getChildren
().
add
(
it
);
}
}
}
Integer
totalElements
=
permissionDTOS
.
size
();
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"content"
,
trees
.
size
()
==
0
?
permissionDTOS:
trees
);
map
.
put
(
"totalElements"
,
totalElements
);
return
map
;
}
}
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/RoleServiceImpl.java
View file @
d5d48015
...
...
@@ -102,14 +102,6 @@ public class RoleServiceImpl implements RoleService {
roleRepository
.
save
(
role
);
}
@Override
@CacheEvict
(
allEntries
=
true
)
public
void
updatePermission
(
Role
resources
,
RoleDTO
roleDTO
)
{
Role
role
=
roleMapper
.
toEntity
(
roleDTO
);
role
.
setPermissions
(
resources
.
getPermissions
());
roleRepository
.
save
(
role
);
}
@Override
@CacheEvict
(
allEntries
=
true
)
public
void
updateMenu
(
Role
resources
,
RoleDTO
roleDTO
)
{
...
...
@@ -125,13 +117,6 @@ public class RoleServiceImpl implements RoleService {
roleRepository
.
untiedMenu
(
id
);
}
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
untiedPermission
(
Long
id
)
{
roleRepository
.
untiedPermission
(
id
);
}
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/service/mapper/PermissionMapper.java
deleted
100644 → 0
View file @
e1366ee4
package
me.zhengjie.modules.system.service.mapper
;
import
me.zhengjie.modules.system.domain.Permission
;
import
me.zhengjie.base.BaseMapper
;
import
me.zhengjie.modules.system.service.dto.PermissionDTO
;
import
org.mapstruct.Mapper
;
import
org.mapstruct.ReportingPolicy
;
/**
* @author Zheng Jie
* @date 2018-11-23
*/
@Mapper
(
componentModel
=
"spring"
,
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
public
interface
PermissionMapper
extends
BaseMapper
<
PermissionDTO
,
Permission
>
{
}
eladmin-system/src/main/java/me/zhengjie/modules/system/service/mapper/RoleMapper.java
View file @
d5d48015
...
...
@@ -10,7 +10,7 @@ import org.mapstruct.ReportingPolicy;
* @author Zheng Jie
* @date 2018-11-23
*/
@Mapper
(
componentModel
=
"spring"
,
uses
=
{
PermissionMapper
.
class
,
MenuMapper
.
class
,
DeptMapper
.
class
},
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
@Mapper
(
componentModel
=
"spring"
,
uses
=
{
MenuMapper
.
class
,
DeptMapper
.
class
},
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
public
interface
RoleMapper
extends
BaseMapper
<
RoleDTO
,
Role
>
{
}
eladmin-system/src/main/resources/template/generator/admin/Controller.ftl
View file @
d5d48015
...
...
@@ -30,7 +30,7 @@ public class ${className}Controller {
@
G
etMapping
@
L
og
(
"查询${className}"
)
@
A
piOperation
(
"查询${className}"
)
@
P
reAuthorize
(
"
hasAnyRole('admin','${upperCaseClassName}_ALL','${upperCaseClassName}_SELECT')
"
)
@
P
reAuthorize
(
"
@el.check('${changeClassName}:list'
"
)
public
R
esponseEntity
get
$
{
className
}
s
(
$
{
className
}
Q
ueryCriteria
criteria
,
P
ageable
pageable
){
return
new
R
esponseEntity
<>
(
$
{
changeClassName
}
S
ervice
.queryAll
(
criteria
,
pageable
),
H
ttpStatus
.OK
)
;
}
...
...
@@ -38,7 +38,7 @@ public class ${className}Controller {
@
P
ostMapping
@
L
og
(
"新增${className}"
)
@
A
piOperation
(
"新增${className}"
)
@
P
reAuthorize
(
"
hasAnyRole('admin','${upperCaseClassName}_ALL','${upperCaseClassName}_CREATE
')"
)
@
P
reAuthorize
(
"
@el.check('${changeClassName}:add
')"
)
public
R
esponseEntity
create
(
@
V
alidated
@
R
equestBody
$
{
className
}
resources
){
return
new
R
esponseEntity
<>
(
$
{
changeClassName
}
S
ervice
.create
(
resources
),
H
ttpStatus
.CREATED
)
;
}
...
...
@@ -46,7 +46,7 @@ public class ${className}Controller {
@
P
utMapping
@
L
og
(
"修改${className}"
)
@
A
piOperation
(
"修改${className}"
)
@
P
reAuthorize
(
"
hasAnyRole('admin','${upperCaseClassName}_ALL','${upperCaseClassName}_EDIT
')"
)
@
P
reAuthorize
(
"
@el.check('${changeClassName}:edit
')"
)
public
R
esponseEntity
update
(
@
V
alidated
@
R
equestBody
$
{
className
}
resources
){
$
{
changeClassName
}
S
ervice
.update
(
resources
)
;
return
new
R
esponseEntity
(
H
ttpStatus
.NO_CONTENT
)
;
...
...
@@ -55,7 +55,7 @@ public class ${className}Controller {
@
D
eleteMapping
(
value
=
"/{${pkChangeColName}}"
)
@
L
og
(
"删除${className}"
)
@
A
piOperation
(
"删除${className}"
)
@
P
reAuthorize
(
"
hasAnyRole('admin','${upperCaseClassName}_ALL','${upperCaseClassName}_DELETE
')"
)
@
P
reAuthorize
(
"
@el.check('${changeClassName}:del
')"
)
public
R
esponseEntity
delete
(
@
P
athVariable
$
{
pkColumnType
}
$
{
pkChangeColName
}){
$
{
changeClassName
}
S
ervice
.delete
(
$
{
pkChangeColName
})
;
return
new
R
esponseEntity
(
H
ttpStatus
.OK
)
;
...
...
eladmin-system/src/main/resources/template/generator/front/index.ftl
View file @
d5d48015
...
...
@@ -14,7 +14,7 @@
<!-- 新增 -->
<div style="display: inline-block;margin: 0px 2px;">
<el-button
v-permission="['
ADMIN','$
{
upperCaseClassName
}
_ALL','$
{
upperCas
eClassName
}
_CREATE
']"
v-permission="['
admin','$
{
chang
eClassName
}
:add
']"
class="filter-item"
size="mini"
type="primary"
...
...
@@ -41,11 +41,11 @@
</#if>
</#list>
</#if>
<el-table-column v-if="checkPermission(['
ADMIN','$
{
upperCaseClassName
}
_ALL','$
{
upperCaseClassName
}
_EDIT','$
{
upperCaseClassName
}
_DELETE
'])" label="操作" width="150px" align="center">
<el-table-column v-if="checkPermission(['
admin','$
{
changeClassName
}
:edit','$
{
changeClassName
}
:del
'])" label="操作" width="150px" align="center">
<template slot-scope="scope">
<el-button v-permission="['
ADMIN','$
{
upperCaseClassName
}
_ALL','$
{
upperCas
eClassName
}
_EDIT
']" size="mini" type="primary" icon="el-icon-edit" @click="edit(scope.row)"/>
<el-button v-permission="['
admin','$
{
chang
eClassName
}
:edit
']" size="mini" type="primary" icon="el-icon-edit" @click="edit(scope.row)"/>
<el-popover
v-permission="['
ADMIN','$
{
upperCaseClassName
}
_ALL','$
{
upperCas
eClassName
}
_DELETE
']"
v-permission="['
admin','$
{
chang
eClassName
}
:del
']"
:ref="scope.row.$
{
pkChangeColName
}
"
placement="top"
width="180">
...
...
eladmin-tools/src/main/java/me/zhengjie/rest/LocalStorageController.java
View file @
d5d48015
...
...
@@ -30,21 +30,21 @@ public class LocalStorageController {
@ApiOperation
(
"查询文件"
)
@GetMapping
@PreAuthorize
(
"
hasAnyRole('admin','LOCALSTORAGE_ALL','LOCALSTORAGE_SELECT
')"
)
@PreAuthorize
(
"
@el.check('storage:list
')"
)
public
ResponseEntity
getLocalStorages
(
LocalStorageQueryCriteria
criteria
,
Pageable
pageable
){
return
new
ResponseEntity
<>(
localStorageService
.
queryAll
(
criteria
,
pageable
),
HttpStatus
.
OK
);
}
@ApiOperation
(
"上传文件"
)
@PostMapping
@PreAuthorize
(
"
hasAnyRole('admin','LOCALSTORAGE_ALL','LOCALSTORAGE_CREATE
')"
)
@PreAuthorize
(
"
@el.check('storage:add
')"
)
public
ResponseEntity
create
(
@RequestParam
String
name
,
@RequestParam
(
"file"
)
MultipartFile
file
){
return
new
ResponseEntity
<>(
localStorageService
.
create
(
name
,
file
),
HttpStatus
.
CREATED
);
}
@ApiOperation
(
"修改文件"
)
@PutMapping
@PreAuthorize
(
"
hasAnyRole('admin','LOCALSTORAGE_ALL','LOCALSTORAGE_EDIT
')"
)
@PreAuthorize
(
"
@el.check('storage:edit
')"
)
public
ResponseEntity
update
(
@Validated
@RequestBody
LocalStorage
resources
){
localStorageService
.
update
(
resources
);
return
new
ResponseEntity
(
HttpStatus
.
NO_CONTENT
);
...
...
@@ -52,7 +52,7 @@ public class LocalStorageController {
@ApiOperation
(
"删除文件"
)
@DeleteMapping
(
value
=
"/{id}"
)
@PreAuthorize
(
"
hasAnyRole('admin','LOCALSTORAGE_ALL','LOCALSTORAGE_DELETE
')"
)
@PreAuthorize
(
"
@el.check('storage:del
')"
)
public
ResponseEntity
delete
(
@PathVariable
Long
id
){
localStorageService
.
delete
(
id
);
return
new
ResponseEntity
(
HttpStatus
.
OK
);
...
...
eladmin-tools/src/main/java/me/zhengjie/rest/PictureController.java
View file @
d5d48015
...
...
@@ -32,7 +32,7 @@ public class PictureController {
}
@Log
(
"查询图片"
)
@PreAuthorize
(
"
hasAnyRole('admin','PICTURE_ALL','PICTURE_SELECT
')"
)
@PreAuthorize
(
"
@el.check('pictures:list
')"
)
@GetMapping
@ApiOperation
(
"查询图片"
)
public
ResponseEntity
getRoles
(
PictureQueryCriteria
criteria
,
Pageable
pageable
){
...
...
@@ -40,7 +40,7 @@ public class PictureController {
}
@Log
(
"上传图片"
)
@PreAuthorize
(
"
hasAnyRole('admin','PICTURE_ALL','PICTURE_UPLOAD
')"
)
@PreAuthorize
(
"
@el.check('pictures:add
')"
)
@PostMapping
@ApiOperation
(
"上传图片"
)
public
ResponseEntity
upload
(
@RequestParam
MultipartFile
file
){
...
...
@@ -55,7 +55,7 @@ public class PictureController {
@Log
(
"删除图片"
)
@ApiOperation
(
"删除图片"
)
@PreAuthorize
(
"
hasAnyRole('admin','PICTURE_ALL','PICTURE_DELETE
')"
)
@PreAuthorize
(
"
@el.check('pictures:del
')"
)
@DeleteMapping
(
value
=
"/{id}"
)
public
ResponseEntity
delete
(
@PathVariable
Long
id
)
{
pictureService
.
delete
(
pictureService
.
findById
(
id
));
...
...
@@ -64,7 +64,7 @@ public class PictureController {
@Log
(
"多选删除图片"
)
@ApiOperation
(
"多选删除图片"
)
@PreAuthorize
(
"
hasAnyRole('admin','PICTURE_ALL','PICTURE_DELETE
')"
)
@PreAuthorize
(
"
@el.check('pictures:del
')"
)
@DeleteMapping
public
ResponseEntity
deleteAll
(
@RequestBody
Long
[]
ids
)
{
pictureService
.
deleteAll
(
ids
);
...
...
Prev
1
2
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