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
4e0deae1
Commit
4e0deae1
authored
Dec 22, 2019
by
Elune
Browse files
优化代码生成器,优化角色级别配置
parent
5f41318b
Changes
11
Show whitespace changes
Inline
Side-by-side
eladmin-generator/src/main/java/me/zhengjie/service/impl/GenConfigServiceImpl.java
View file @
4e0deae1
...
@@ -3,6 +3,7 @@ package me.zhengjie.service.impl;
...
@@ -3,6 +3,7 @@ package me.zhengjie.service.impl;
import
me.zhengjie.domain.GenConfig
;
import
me.zhengjie.domain.GenConfig
;
import
me.zhengjie.repository.GenConfigRepository
;
import
me.zhengjie.repository.GenConfigRepository
;
import
me.zhengjie.service.GenConfigService
;
import
me.zhengjie.service.GenConfigService
;
import
me.zhengjie.utils.StringUtils
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CachePut
;
import
org.springframework.cache.annotation.CachePut
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.cache.annotation.Cacheable
;
...
@@ -36,7 +37,8 @@ public class GenConfigServiceImpl implements GenConfigService {
...
@@ -36,7 +37,8 @@ public class GenConfigServiceImpl implements GenConfigService {
@Override
@Override
@CachePut
(
key
=
"#p0"
)
@CachePut
(
key
=
"#p0"
)
public
GenConfig
update
(
String
tableName
,
GenConfig
genConfig
)
{
public
GenConfig
update
(
String
tableName
,
GenConfig
genConfig
)
{
// 自动设置Api路径,注释掉前需要同步取消前端的注释
// 如果 api 路径为空,则自动生成路径
if
(
StringUtils
.
isBlank
(
genConfig
.
getApiPath
())){
String
separator
=
File
.
separator
;
String
separator
=
File
.
separator
;
String
[]
paths
;
String
[]
paths
;
String
symbol
=
"\\"
;
String
symbol
=
"\\"
;
...
@@ -55,6 +57,7 @@ public class GenConfigServiceImpl implements GenConfigService {
...
@@ -55,6 +57,7 @@ public class GenConfigServiceImpl implements GenConfigService {
}
}
}
}
genConfig
.
setApiPath
(
api
.
toString
());
genConfig
.
setApiPath
(
api
.
toString
());
}
return
genConfigRepository
.
save
(
genConfig
);
return
genConfigRepository
.
save
(
genConfig
);
}
}
}
}
eladmin-system/src/main/java/me/zhengjie/AppRun.java
View file @
4e0deae1
package
me.zhengjie
;
package
me.zhengjie
;
import
me.zhengjie.annotation.AnonymousAccess
;
import
me.zhengjie.utils.SpringContextHolder
;
import
me.zhengjie.utils.SpringContextHolder
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer
;
import
org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory
;
import
org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory
;
import
org.springframework.boot.web.servlet.server.ServletWebServerFactory
;
import
org.springframework.boot.web.servlet.server.ServletWebServerFactory
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.scheduling.annotation.EnableAsync
;
import
org.springframework.scheduling.annotation.EnableAsync
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RestController
;
/**
/**
* @author Zheng Jie
* @author Zheng Jie
* @date 2018/11/15 9:20:19
* @date 2018/11/15 9:20:19
*/
*/
@EnableAsync
@EnableAsync
@RestController
@SpringBootApplication
@SpringBootApplication
@EnableTransactionManagement
@EnableTransactionManagement
public
class
AppRun
{
public
class
AppRun
{
...
@@ -31,7 +34,17 @@ public class AppRun {
...
@@ -31,7 +34,17 @@ public class AppRun {
@Bean
@Bean
public
ServletWebServerFactory
webServerFactory
()
{
public
ServletWebServerFactory
webServerFactory
()
{
TomcatServletWebServerFactory
fa
=
new
TomcatServletWebServerFactory
();
TomcatServletWebServerFactory
fa
=
new
TomcatServletWebServerFactory
();
fa
.
addConnectorCustomizers
(
(
TomcatConnectorCustomizer
)
connector
->
connector
.
setProperty
(
"relaxedQueryChars"
,
"[]{}"
));
fa
.
addConnectorCustomizers
(
connector
->
connector
.
setProperty
(
"relaxedQueryChars"
,
"[]{}"
));
return
fa
;
return
fa
;
}
}
/**
* 访问首页提示
* @return /
*/
@GetMapping
(
"/"
)
@AnonymousAccess
public
String
index
()
{
return
"Backend service started successfully"
;
}
}
}
eladmin-system/src/main/java/me/zhengjie/modules/system/repository/RoleRepository.java
View file @
4e0deae1
...
@@ -35,4 +35,11 @@ public interface RoleRepository extends JpaRepository<Role, Long>, JpaSpecificat
...
@@ -35,4 +35,11 @@ public interface RoleRepository extends JpaRepository<Role, Long>, JpaSpecificat
@Modifying
@Modifying
@Query
(
value
=
"delete from roles_menus where menu_id = ?1"
,
nativeQuery
=
true
)
@Query
(
value
=
"delete from roles_menus where menu_id = ?1"
,
nativeQuery
=
true
)
void
untiedMenu
(
Long
id
);
void
untiedMenu
(
Long
id
);
/**
* 根据角色权限查询
* @param permission /
* @return /
*/
Role
findByPermission
(
String
permission
);
}
}
eladmin-system/src/main/java/me/zhengjie/modules/system/rest/RoleController.java
View file @
4e0deae1
...
@@ -8,6 +8,7 @@ import me.zhengjie.modules.system.domain.Role;
...
@@ -8,6 +8,7 @@ import me.zhengjie.modules.system.domain.Role;
import
me.zhengjie.exception.BadRequestException
;
import
me.zhengjie.exception.BadRequestException
;
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.RoleDto
;
import
me.zhengjie.modules.system.service.dto.RoleQueryCriteria
;
import
me.zhengjie.modules.system.service.dto.RoleQueryCriteria
;
import
me.zhengjie.modules.system.service.dto.RoleSmallDto
;
import
me.zhengjie.modules.system.service.dto.RoleSmallDto
;
import
me.zhengjie.modules.system.service.dto.UserDto
;
import
me.zhengjie.modules.system.service.dto.UserDto
;
...
@@ -21,7 +22,6 @@ import org.springframework.http.ResponseEntity;
...
@@ -21,7 +22,6 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.security.access.prepost.PreAuthorize
;
import
org.springframework.security.access.prepost.PreAuthorize
;
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.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.Collections
;
import
java.util.Collections
;
...
@@ -81,9 +81,7 @@ public class RoleController {
...
@@ -81,9 +81,7 @@ public class RoleController {
@ApiOperation
(
"获取用户级别"
)
@ApiOperation
(
"获取用户级别"
)
@GetMapping
(
value
=
"/level"
)
@GetMapping
(
value
=
"/level"
)
public
ResponseEntity
<
Object
>
getLevel
(){
public
ResponseEntity
<
Object
>
getLevel
(){
UserDto
user
=
userService
.
findByName
(
SecurityUtils
.
getUsername
());
return
new
ResponseEntity
<>(
Dict
.
create
().
set
(
"level"
,
getLevels
(
null
)),
HttpStatus
.
OK
);
List
<
Integer
>
levels
=
roleService
.
findByUsersId
(
user
.
getId
()).
stream
().
map
(
RoleSmallDto:
:
getLevel
).
collect
(
Collectors
.
toList
());
return
new
ResponseEntity
<>(
Dict
.
create
().
set
(
"level"
,
Collections
.
min
(
levels
)),
HttpStatus
.
OK
);
}
}
@Log
(
"新增角色"
)
@Log
(
"新增角色"
)
...
@@ -94,6 +92,7 @@ public class RoleController {
...
@@ -94,6 +92,7 @@ public class RoleController {
if
(
resources
.
getId
()
!=
null
)
{
if
(
resources
.
getId
()
!=
null
)
{
throw
new
BadRequestException
(
"A new "
+
ENTITY_NAME
+
" cannot already have an ID"
);
throw
new
BadRequestException
(
"A new "
+
ENTITY_NAME
+
" cannot already have an ID"
);
}
}
getLevels
(
resources
.
getLevel
());
return
new
ResponseEntity
<>(
roleService
.
create
(
resources
),
HttpStatus
.
CREATED
);
return
new
ResponseEntity
<>(
roleService
.
create
(
resources
),
HttpStatus
.
CREATED
);
}
}
...
@@ -102,6 +101,7 @@ public class RoleController {
...
@@ -102,6 +101,7 @@ public class RoleController {
@PutMapping
@PutMapping
@PreAuthorize
(
"@el.check('roles:edit')"
)
@PreAuthorize
(
"@el.check('roles:edit')"
)
public
ResponseEntity
<
Object
>
update
(
@Validated
(
Role
.
Update
.
class
)
@RequestBody
Role
resources
){
public
ResponseEntity
<
Object
>
update
(
@Validated
(
Role
.
Update
.
class
)
@RequestBody
Role
resources
){
getLevels
(
resources
.
getLevel
());
roleService
.
update
(
resources
);
roleService
.
update
(
resources
);
return
new
ResponseEntity
<>(
HttpStatus
.
NO_CONTENT
);
return
new
ResponseEntity
<>(
HttpStatus
.
NO_CONTENT
);
}
}
...
@@ -111,7 +111,9 @@ public class RoleController {
...
@@ -111,7 +111,9 @@ public class RoleController {
@PutMapping
(
value
=
"/menu"
)
@PutMapping
(
value
=
"/menu"
)
@PreAuthorize
(
"@el.check('roles:edit')"
)
@PreAuthorize
(
"@el.check('roles:edit')"
)
public
ResponseEntity
<
Object
>
updateMenu
(
@RequestBody
Role
resources
){
public
ResponseEntity
<
Object
>
updateMenu
(
@RequestBody
Role
resources
){
roleService
.
updateMenu
(
resources
,
roleService
.
findById
(
resources
.
getId
()));
RoleDto
role
=
roleService
.
findById
(
resources
.
getId
());
getLevels
(
role
.
getLevel
());
roleService
.
updateMenu
(
resources
,
role
);
return
new
ResponseEntity
<>(
HttpStatus
.
NO_CONTENT
);
return
new
ResponseEntity
<>(
HttpStatus
.
NO_CONTENT
);
}
}
...
@@ -120,7 +122,31 @@ public class RoleController {
...
@@ -120,7 +122,31 @@ public class RoleController {
@DeleteMapping
@DeleteMapping
@PreAuthorize
(
"@el.check('roles:del')"
)
@PreAuthorize
(
"@el.check('roles:del')"
)
public
ResponseEntity
<
Object
>
delete
(
@RequestBody
Set
<
Long
>
ids
){
public
ResponseEntity
<
Object
>
delete
(
@RequestBody
Set
<
Long
>
ids
){
for
(
Long
id
:
ids
)
{
RoleDto
role
=
roleService
.
findById
(
id
);
getLevels
(
role
.
getLevel
());
}
try
{
roleService
.
delete
(
ids
);
roleService
.
delete
(
ids
);
}
catch
(
Throwable
e
){
ThrowableUtil
.
throwForeignKeyException
(
e
,
"所选角色存在用户关联,请取消关联后再试"
);
}
return
new
ResponseEntity
<>(
HttpStatus
.
OK
);
return
new
ResponseEntity
<>(
HttpStatus
.
OK
);
}
}
/**
* 获取用户的角色级别
* @return /
*/
private
int
getLevels
(
Integer
level
){
UserDto
user
=
userService
.
findByName
(
SecurityUtils
.
getUsername
());
List
<
Integer
>
levels
=
roleService
.
findByUsersId
(
user
.
getId
()).
stream
().
map
(
RoleSmallDto:
:
getLevel
).
collect
(
Collectors
.
toList
());
int
min
=
Collections
.
min
(
levels
);
if
(
level
!=
null
){
if
(
level
<
min
){
throw
new
BadRequestException
(
"权限不足,你的角色级别:"
+
min
+
",低于操作的角色级别:"
+
level
);
}
}
return
min
;
}
}
}
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/RoleServiceImpl.java
View file @
4e0deae1
...
@@ -98,12 +98,16 @@ public class RoleServiceImpl implements RoleService {
...
@@ -98,12 +98,16 @@ public class RoleServiceImpl implements RoleService {
if
(
role1
!=
null
&&
!
role1
.
getId
().
equals
(
role
.
getId
())){
if
(
role1
!=
null
&&
!
role1
.
getId
().
equals
(
role
.
getId
())){
throw
new
EntityExistException
(
Role
.
class
,
"username"
,
resources
.
getName
());
throw
new
EntityExistException
(
Role
.
class
,
"username"
,
resources
.
getName
());
}
}
role1
=
roleRepository
.
findByPermission
(
resources
.
getPermission
());
if
(
role1
!=
null
&&
!
role1
.
getId
().
equals
(
role
.
getId
())){
throw
new
EntityExistException
(
Role
.
class
,
"permission"
,
resources
.
getPermission
());
}
role
.
setName
(
resources
.
getName
());
role
.
setName
(
resources
.
getName
());
role
.
setRemark
(
resources
.
getRemark
());
role
.
setRemark
(
resources
.
getRemark
());
role
.
setDataScope
(
resources
.
getDataScope
());
role
.
setDataScope
(
resources
.
getDataScope
());
role
.
setDepts
(
resources
.
getDepts
());
role
.
setDepts
(
resources
.
getDepts
());
role
.
setLevel
(
resources
.
getLevel
());
role
.
setLevel
(
resources
.
getLevel
());
role
.
setPermission
(
resources
.
getPermission
());
roleRepository
.
save
(
role
);
roleRepository
.
save
(
role
);
}
}
...
@@ -127,11 +131,7 @@ public class RoleServiceImpl implements RoleService {
...
@@ -127,11 +131,7 @@ public class RoleServiceImpl implements RoleService {
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
delete
(
Set
<
Long
>
ids
)
{
public
void
delete
(
Set
<
Long
>
ids
)
{
for
(
Long
id
:
ids
)
{
for
(
Long
id
:
ids
)
{
try
{
roleRepository
.
deleteById
(
id
);
roleRepository
.
deleteById
(
id
);
}
catch
(
Throwable
e
){
ThrowableUtil
.
throwForeignKeyException
(
e
,
"该角色存在用户关联,请取消关联后再试"
);
}
}
}
}
}
...
...
eladmin-system/src/main/resources/template/generator/admin/Controller.ftl
View file @
4e0deae1
...
@@ -62,18 +62,9 @@ public class ${className}Controller {
...
@@ -62,18 +62,9 @@ public class ${className}Controller {
return
new
R
esponseEntity
<>
(
H
ttpStatus
.NO_CONTENT
)
;
return
new
R
esponseEntity
<>
(
H
ttpStatus
.NO_CONTENT
)
;
}
}
@
D
eleteMapping
(
value
=
"/{${pkChangeColName}}"
)
@
L
og
(
"删除${apiAlias}"
)
@
L
og
(
"删除${apiAlias}"
)
@
A
piOperation
(
"删除${apiAlias}"
)
@
A
piOperation
(
"删除${apiAlias}"
)
@
P
reAuthorize
(
"@el.check('${changeClassName}:del')"
)
@
P
reAuthorize
(
"@el.check('${changeClassName}:del')"
)
public
R
esponseEntity
<
O
bject
>
delete
(
@
P
athVariable
$
{
pkColumnType
}
$
{
pkChangeColName
}){
$
{
changeClassName
}
S
ervice
.delete
(
$
{
pkChangeColName
})
;
return
new
R
esponseEntity
<>
(
H
ttpStatus
.OK
)
;
}
@
L
og
(
"多选删除${apiAlias}"
)
@
A
piOperation
(
"多选删除${apiAlias}"
)
@
P
reAuthorize
(
"@el.check('${changeClassName}:del')"
)
@
D
eleteMapping
@
D
eleteMapping
public
R
esponseEntity
<
O
bject
>
deleteAll
(
@
R
equestBody
$
{
pkColumnType
}
[]
ids
)
{
public
R
esponseEntity
<
O
bject
>
deleteAll
(
@
R
equestBody
$
{
pkColumnType
}
[]
ids
)
{
$
{
changeClassName
}
S
ervice
.deleteAll
(
ids
)
;
$
{
changeClassName
}
S
ervice
.deleteAll
(
ids
)
;
...
...
eladmin-system/src/main/resources/template/generator/admin/QueryCriteria.ftl
View file @
4e0deae1
...
@@ -38,6 +38,11 @@ public class ${className}QueryCriteria{
...
@@ -38,6 +38,11 @@ public class ${className}QueryCriteria{
@
Q
uery
(
type
=
Q
uery
.Type.NOT_EQUAL
)
@
Q
uery
(
type
=
Q
uery
.Type.NOT_EQUAL
)
private
$
{
column
.columnType
}
$
{
column
.changeColumnName
}
;
private
$
{
column
.columnType
}
$
{
column
.changeColumnName
}
;
</#
if
>
</#
if
>
<#
if
column
.queryType
=
'
N
otNull
'>
/
**
不为空
*
/
@
Q
uery
(
type
=
Q
uery
.Type.NOT_NULL
)
private
$
{
column
.columnType
}
$
{
column
.changeColumnName
}
;
</#
if
>
<#
if
column
.queryType
=
'>='>
<#
if
column
.queryType
=
'>='>
/
**
大于等于
*
/
/
**
大于等于
*
/
@
Q
uery
(
type
=
Q
uery
.Type.GREATER_THAN
)
@
Q
uery
(
type
=
Q
uery
.Type.GREATER_THAN
)
...
...
eladmin-system/src/main/resources/template/generator/admin/Service.ftl
View file @
4e0deae1
...
@@ -50,12 +50,6 @@ public interface ${className}Service {
...
@@ -50,12 +50,6 @@ public interface ${className}Service {
*
/
*
/
void
update
(
$
{
className
}
resources
)
;
void
update
(
$
{
className
}
resources
)
;
/
**
*
删除
*
@
param
$
{
pkChangeColName
}
/
*
/
void
delete
(
$
{
pkColumnType
}
$
{
pkChangeColName
})
;
/
**
/
**
*
多选删除
*
多选删除
*
@
param
ids
/
*
@
param
ids
/
...
...
eladmin-system/src/main/resources/template/generator/admin/ServiceImpl.ftl
View file @
4e0deae1
...
@@ -27,9 +27,10 @@ import cn.hutool.core.util.IdUtil;
...
@@ -27,9 +27,10 @@ import cn.hutool.core.util.IdUtil;
<#
if
!auto && pkColumnType = 'String'>
<#
if
!auto && pkColumnType = 'String'>
import
cn.hutool.core.util.IdUtil;
import
cn.hutool.core.util.IdUtil;
</#
if
>
</#
if
>
import
org.springframework.cache.annotation.CacheConfig;
//
默认不使用缓存
import
org.springframework.cache.annotation.CacheEvict;
//
import
org.springframework.cache.annotation.CacheConfig;
import
org.springframework.cache.annotation.Cacheable;
//
import
org.springframework.cache.annotation.CacheEvict;
//
import
org.springframework.cache.annotation.Cacheable;
import
org.springframework.data.domain.Page;
import
org.springframework.data.domain.Page;
import
org.springframework.data.domain.Pageable;
import
org.springframework.data.domain.Pageable;
import
me.zhengjie.utils.PageUtil;
import
me.zhengjie.utils.PageUtil;
...
@@ -46,7 +47,7 @@ import java.util.LinkedHashMap;
...
@@ -46,7 +47,7 @@ import java.util.LinkedHashMap;
*
@date $
{
date
}
*
@date $
{
date
}
*/
*/
@
Service
@
Service
@
CacheConfig
(
cacheNames
=
"$
{
changeClassName
}
")
//
@
CacheConfig
(
cacheNames
=
"$
{
changeClassName
}
")
@
Transactional
(
propagation
=
Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
@
Transactional
(
propagation
=
Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public
class $
{
className
}
ServiceImpl implements $
{
className
}
Service
{
public
class $
{
className
}
ServiceImpl implements $
{
className
}
Service
{
...
@@ -60,20 +61,20 @@ public class ${className}ServiceImpl implements ${className}Service {
...
@@ -60,20 +61,20 @@ public class ${className}ServiceImpl implements ${className}Service {
}
}
@
O
verride
@
O
verride
@
C
acheable
//
@
C
acheable
public
M
ap
<
S
tring
,
O
bject
>
queryAll
(
$
{
className
}
Q
ueryCriteria
criteria
,
P
ageable
pageable
){
public
M
ap
<
S
tring
,
O
bject
>
queryAll
(
$
{
className
}
Q
ueryCriteria
criteria
,
P
ageable
pageable
){
P
age
<$
{
className
}
>
page
=
$
{
changeClassName
}
R
epository
.findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
Q
ueryHelp
.getPredicate
(
root
,
criteria
,
criteriaBuilder
),
pageable
)
;
P
age
<$
{
className
}
>
page
=
$
{
changeClassName
}
R
epository
.findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
Q
ueryHelp
.getPredicate
(
root
,
criteria
,
criteriaBuilder
),
pageable
)
;
return
P
ageUtil
.toPage
(
page
.map
(
$
{
changeClassName
}
M
apper
::
toDto
))
;
return
P
ageUtil
.toPage
(
page
.map
(
$
{
changeClassName
}
M
apper
::
toDto
))
;
}
}
@
O
verride
@
O
verride
@
C
acheable
//
@
C
acheable
public
L
ist
<$
{
className
}
D
to
>
queryAll
(
$
{
className
}
Q
ueryCriteria
criteria
){
public
L
ist
<$
{
className
}
D
to
>
queryAll
(
$
{
className
}
Q
ueryCriteria
criteria
){
return
$
{
changeClassName
}
M
apper
.toDto
(
$
{
changeClassName
}
R
epository
.findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
Q
ueryHelp
.getPredicate
(
root
,
criteria
,
criteriaBuilder
)))
;
return
$
{
changeClassName
}
M
apper
.toDto
(
$
{
changeClassName
}
R
epository
.findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
Q
ueryHelp
.getPredicate
(
root
,
criteria
,
criteriaBuilder
)))
;
}
}
@
O
verride
@
O
verride
@
C
acheable
(
key
=
"#p0"
)
//
@
C
acheable
(
key
=
"#p0"
)
public
$
{
className
}
D
to
findById
(
$
{
pkColumnType
}
$
{
pkChangeColName
})
{
public
$
{
className
}
D
to
findById
(
$
{
pkColumnType
}
$
{
pkChangeColName
})
{
$
{
className
}
$
{
changeClassName
}
=
$
{
changeClassName
}
R
epository
.findById
(
$
{
pkChangeColName
})
.orElseGet
(
$
{
className
}::
new
)
;
$
{
className
}
$
{
changeClassName
}
=
$
{
changeClassName
}
R
epository
.findById
(
$
{
pkChangeColName
})
.orElseGet
(
$
{
className
}::
new
)
;
V
alidationUtil
.isNull
(
$
{
changeClassName
}
.get
$
{
pkCapitalColName
}(),
"${className}"
,
"${pkChangeColName}"
,
$
{
pkChangeColName
})
;
V
alidationUtil
.isNull
(
$
{
changeClassName
}
.get
$
{
pkCapitalColName
}(),
"${className}"
,
"${pkChangeColName}"
,
$
{
pkChangeColName
})
;
...
@@ -81,7 +82,7 @@ public class ${className}ServiceImpl implements ${className}Service {
...
@@ -81,7 +82,7 @@ public class ${className}ServiceImpl implements ${className}Service {
}
}
@
O
verride
@
O
verride
@
C
acheEvict
(
allEntries
=
true
)
//
@
C
acheEvict
(
allEntries
=
true
)
@
T
ransactional
(
rollbackFor
=
E
xception
.class
)
@
T
ransactional
(
rollbackFor
=
E
xception
.class
)
public
$
{
className
}
D
to
create
(
$
{
className
}
resources
)
{
public
$
{
className
}
D
to
create
(
$
{
className
}
resources
)
{
<#
if
!
auto
&&
pkColumnType
=
'
L
ong
'>
<#
if
!
auto
&&
pkColumnType
=
'
L
ong
'>
...
@@ -104,7 +105,7 @@ public class ${className}ServiceImpl implements ${className}Service {
...
@@ -104,7 +105,7 @@ public class ${className}ServiceImpl implements ${className}Service {
}
}
@
O
verride
@
O
verride
@
C
acheEvict
(
allEntries
=
true
)
//
@
C
acheEvict
(
allEntries
=
true
)
@
T
ransactional
(
rollbackFor
=
E
xception
.class
)
@
T
ransactional
(
rollbackFor
=
E
xception
.class
)
public
void
update
(
$
{
className
}
resources
)
{
public
void
update
(
$
{
className
}
resources
)
{
$
{
className
}
$
{
changeClassName
}
=
$
{
changeClassName
}
R
epository
.findById
(
resources
.get
$
{
pkCapitalColName
}())
.orElseGet
(
$
{
className
}::
new
)
;
$
{
className
}
$
{
changeClassName
}
=
$
{
changeClassName
}
R
epository
.findById
(
resources
.get
$
{
pkCapitalColName
}())
.orElseGet
(
$
{
className
}::
new
)
;
...
@@ -127,14 +128,7 @@ public class ${className}ServiceImpl implements ${className}Service {
...
@@ -127,14 +128,7 @@ public class ${className}ServiceImpl implements ${className}Service {
}
}
@
O
verride
@
O
verride
@
C
acheEvict
(
allEntries
=
true
)
//@
C
acheEvict
(
allEntries
=
true
)
@
T
ransactional
(
rollbackFor
=
E
xception
.class
)
public
void
delete
(
$
{
pkColumnType
}
$
{
pkChangeColName
})
{
$
{
changeClassName
}
R
epository
.deleteById
(
$
{
pkChangeColName
})
;
}
@
O
verride
@
C
acheEvict
(
allEntries
=
true
)
public
void
deleteAll
(
$
{
pkColumnType
}
[]
ids
)
{
public
void
deleteAll
(
$
{
pkColumnType
}
[]
ids
)
{
for
(
$
{
pkColumnType
}
id
:
ids
)
{
for
(
$
{
pkColumnType
}
id
:
ids
)
{
$
{
changeClassName
}
R
epository
.deleteById
(
$
{
pkChangeColName
})
;
$
{
changeClassName
}
R
epository
.deleteById
(
$
{
pkChangeColName
})
;
...
...
eladmin-system/src/main/resources/template/generator/front/api.ftl
View file @
4e0deae1
...
@@ -8,13 +8,7 @@ export function add(data) {
...
@@ -8,13 +8,7 @@ export function add(data) {
})
})
}
}
export
function del($
{
pkChangeColName
}
)
{
export
function del(ids)
{
return
request
({
url
:
'
api
/$
{
changeClassName
}
/'
+
$
{
pkChangeColName
},
method
:
'
delete
'
})
}
export
function delAll(ids)
{
return
request
({
return
request
({
url
:
'
api
/$
{
changeClassName
}
/'
,
url
:
'
api
/$
{
changeClassName
}
/'
,
method
:
'
delete
'
,
method
:
'
delete
'
,
...
@@ -30,4 +24,4 @@ export function edit(data) {
...
@@ -30,4 +24,4 @@ export function edit(data) {
})
})
}
}
export
default
{
add
,
edit
,
del
,
delAll
}
export
default
{
add
,
edit
,
del
}
eladmin-system/src/main/resources/template/generator/front/index.ftl
View file @
4e0deae1
...
@@ -4,12 +4,13 @@
...
@@ -4,12 +4,13 @@
<!--工具栏-->
<!--工具栏-->
<div class="head-container">
<div class="head-container">
<#if hasQuery>
<#if hasQuery>
<div v-if="crud.props.searchToggle">
<!-- 搜索 -->
<!-- 搜索 -->
<el-input v-model="query.value" clearable placeholder="输入搜索内容" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" />
<el-input v-model="query.value" clearable placeholder="输入搜索内容" style="width: 200px;" class="filter-item" @keyup.enter.native="
crud.
toQuery" />
<el-select v-model="query.type" clearable placeholder="类型" class="filter-item" style="width: 130px">
<el-select v-model="query.type" clearable placeholder="类型" class="filter-item" style="width: 130px">
<el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" />
<el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" />
</el-select>
</el-select>
<#
if
betweens??>
<#if betweens??>
<#list betweens as column>
<#list betweens as column>
<#if column.queryType = 'BetWeen'>
<#if column.queryType = 'BetWeen'>
<el-date-picker
<el-date-picker
...
@@ -25,22 +26,19 @@
...
@@ -25,22 +26,19 @@
/>
/>
</#if>
</#if>
</#list>
</#list>
</#
if
>
</#if>
<el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button>
<rrOperation :crud="crud" />
</#if>
</div>
<!-- 新增 -->
</#if>
<el-button v-permission="['admin','$
{
changeClassName
}
:add']" class="filter-item" size="mini" type="primary" icon="el-icon-plus" @click="showAddFormDialog">新增</el-button>
<!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
<!-- 导出 -->
<crudOperation :permission="permission" />
<el-button :loading="downloadLoading" size="mini" class="filter-item" type="warning" icon="el-icon-download" @click="downloadMethod">导出</el-button>
<!-- 多选删除 -->
<el-button v-permission="['admin','$
{
changeClassName
}
:del']" :loading="delAllLoading" :disabled="data.length === 0 || $refs.table.selection.length === 0" class="filter-item" size="mini" type="danger" icon="el-icon-delete" @click="beforeDelAllMethod">删除</el-button>
<!--表单组件-->
<!--表单组件-->
<el-dialog
:append-to-body="true"
:close-on-click-modal="false" :before-close="cancel" :visible.sync="
dialog" :title="getFormT
itle
()
" width="500px">
<el-dialog :close-on-click-modal="false" :before-close="
crud.
cancel
CU
" :visible.sync="
crud.status.cu > 0" :title="crud.status.t
itle" width="500px">
<el-form ref="form" :model="form" <#if isNotNullColumns??>:rules="rules"</#if> size="small" label-width="80px">
<el-form ref="form" :model="form" <#if isNotNullColumns??>:rules="rules"</#if> size="small" label-width="80px">
<#if columns??>
<#if columns??>
<#list columns as column>
<#list columns as column>
<#if column.formShow>
<#if column.formShow>
<el-form-item label="<#if column.remark != ''>$
{
column
.remark
}
<#else>$
{
column
.changeColumnName
}
</#if>"
<#if column.istNotNull>prop="$
{
column
.changeColumnName
}
"</#if>>
<el-form-item label="<#if column.remark != ''>$
{
column
.remark
}
<#else>$
{
column
.changeColumnName
}
</#if>"<#if column.istNotNull>
prop="$
{
column
.changeColumnName
}
"</#if>>
<#if column.formType = 'Input'>
<#if column.formType = 'Input'>
<el-input v-model="form.$
{
column
.changeColumnName
}
" style="width: 370px;" />
<el-input v-model="form.$
{
column
.changeColumnName
}
" style="width: 370px;" />
<#elseif column.formType = 'Textarea'>
<#elseif column.formType = 'Textarea'>
...
@@ -72,26 +70,26 @@
...
@@ -72,26 +70,26 @@
</#if>
</#if>
</el-form>
</el-form>
<div slot="footer" class="dialog-footer">
<div slot="footer" class="dialog-footer">
<el-button type="text" @click="cancel">取消</el-button>
<el-button type="text" @click="
crud.
cancel
CU
">取消</el-button>
<el-button :loading="
loading
" type="primary" @click="submit
Method
">确认</el-button>
<el-button :loading="
crud.cu === 2
" type="primary" @click="
crud.
submit
CU
">确认</el-button>
</div>
</div>
</el-dialog>
</el-dialog>
<!--表格渲染-->
<!--表格渲染-->
<el-table ref="table" v-loading="loading" :data="data" size="small" style="width: 100%;">
<el-table ref="table" v-loading="
crud.
loading" :data="
crud.
data" size="small" style="width: 100%;"
@selection-change="crud.selectionChangeHandler"
>
<el-table-column type="selection" width="55" />
<el-table-column type="selection" width="55" />
<#if columns??>
<#if columns??>
<#list columns as column>
<#list columns as column>
<#if column.columnShow>
<#if column.columnShow>
<#if column.dictName??>
<#if column.dictName??>
<el-table-column prop="$
{
column
.changeColumnName
}
" label="<#if column.remark != ''>$
{
column
.remark
}
<#else>$
{
column
.changeColumnName
}
</#if>">
<el-table-column
v-if="columns.visible('$
{
column
.changeColumnName
}
')"
prop="$
{
column
.changeColumnName
}
" label="<#if column.remark != ''>$
{
column
.remark
}
<#else>$
{
column
.changeColumnName
}
</#if>">
<template slot-scope="scope">
<template slot-scope="scope">
{{
dict
.label
.$
{
column
.dictName
}
[
scope
.row
.$
{
column
.changeColumnName
}
]
}}
{{
dict
.label
.$
{
column
.dictName
}
[
scope
.row
.$
{
column
.changeColumnName
}
]
}}
</template>
</template>
</el-table-column>
</el-table-column>
<#elseif column.columnType != 'Timestamp'>
<#elseif column.columnType != 'Timestamp'>
<el-table-column prop="$
{
column
.changeColumnName
}
" label="<#if column.remark != ''>$
{
column
.remark
}
<#else>$
{
column
.changeColumnName
}
</#if>" />
<el-table-column
v-if="columns.visible('$
{
column
.changeColumnName
}
')"
prop="$
{
column
.changeColumnName
}
" label="<#if column.remark != ''>$
{
column
.remark
}
<#else>$
{
column
.changeColumnName
}
</#if>" />
<#else>
<#else>
<el-table-column prop="$
{
column
.changeColumnName
}
" label="<#if column.remark != ''>$
{
column
.remark
}
<#else>$
{
column
.changeColumnName
}
</#if>">
<el-table-column
v-if="columns.visible('$
{
column
.changeColumnName
}
')"
prop="$
{
column
.changeColumnName
}
" label="<#if column.remark != ''>$
{
column
.remark
}
<#else>$
{
column
.changeColumnName
}
</#if>">
<template slot-scope="scope">
<template slot-scope="scope">
<span>
{{
parseTime
(
scope
.row
.$
{
column
.changeColumnName
})
}}
</span>
<span>
{{
parseTime
(
scope
.row
.$
{
column
.changeColumnName
})
}}
</span>
</template>
</template>
...
@@ -100,51 +98,46 @@
...
@@ -100,51 +98,46 @@
</#if>
</#if>
</#list>
</#list>
</#if>
</#if>
<el-table-column v-
if="checkP
ermission
(
['admin','$
{
changeClassName
}
:edit','$
{
changeClassName
}
:del']
)
" label="操作" width="150px" align="center">
<el-table-column v-
p
ermission
="
['admin','$
{
changeClassName
}
:edit','$
{
changeClassName
}
:del']" label="操作" width="150px" align="center">
<template slot-scope="scope">
<template slot-scope="scope">
<el-button v-permission="['admin','$
{
changeClassName
}
:edit']" size="mini" type="primary" icon="el-icon-edit" @click="showEditFormDialog(scope.row)" />
<udOperation
<el-popover
:data="scope.row"
:ref="scope.row.$
{
pkChangeColName
}
"
:permission="permission"
v-permission="['admin','$
{
changeClassName
}
:del']"
/>
placement="top"
width="180"
>
<p>确定删除本条数据吗?</p>
<div style="text-align: right; margin: 0">
<el-button size="mini" type="text" @click="$refs[scope.row.$
{
pkChangeColName
}
].doClose()">取消</el-button>
<el-button :loading="delLoading" type="primary" size="mini" @click="delMethod(scope.row.$
{
pkChangeColName
}
)">确定</el-button>
</div>
<el-button slot="reference" type="danger" icon="el-icon-delete" size="mini" />
</el-popover>
</template>
</template>
</el-table-column>
</el-table-column>
</el-table>
</el-table>
<!--分页组件-->
<!--分页组件-->
<el-pagination
<pagination />
:total="total"
:current-page="page + 1"
style="margin-top: 8px;"
layout="total, prev, pager, next, sizes"
@size-change="sizeChange"
@current-change="pageChange"
/>
</div>
</div>
</div>
</div>
</
template
>
</
template
>
<
script
>
<
script
>
import
crud from '@/mixins/crud'
import
crud$
{
className
}
from '@/api/$
{
changeClassName
}
'
import
crud$
{
className
}
from '@/api/$
{
changeClassName
}
'
import
CRUD,
{
presenter
,
header
,
form
,
crud
}
from '@crud/crud'
import
rrOperation from '@crud/RR.operation'
import
crudOperation from '@crud/CRUD.operation'
import
udOperation from '@crud/UD.operation'
import
pagination from '@crud/Pagination'
//
crud交由presenter持有
const
defaultCrud = CRUD(
{
title
:
'$
{
apiAlias
}
'
,
url
:
'
api
/$
{
changeClassName
}
'
,
sort
:
'$
{
pkChangeColName
},
desc
'
,
crudMethod
:
{
..
.crud
$
{
className
}
}}
)
const
defaultForm =
{
<#
if
columns
??><#
list
columns
as
column
>$
{
column
.changeColumnName
}:
null
<#
if
column_has_next
>
,
</#
if
></#
list
></#
if
>
}
export
default
{
export
default
{
mixins
:
[
crud
]
,
name
:
'$
{
className
}
'
,
components
:
{
pagination
,
crudOperation
,
rrOperation
,
udOperation
},
mixins
:
[
presenter
(
defaultCrud
),
header
(),
form
(
defaultForm
),
crud
()
]
,
<#
if
hasDict
>
<#
if
hasDict
>
dicts
:
[<#
if
hasDict
??><#
list
dicts
as
dict
>'$
{
dict
}
'<#
if
dict_has_next
>
,
</#
if
></#
list
></#
if
>]
,
dicts
:
[<#
if
hasDict
??><#
list
dicts
as
dict
>'$
{
dict
}
'<#
if
dict_has_next
>
,
</#
if
></#
list
></#
if
>]
,
</#
if
>
</#
if
>
data
()
{
data
()
{
return
{
return
{
title
:
'$
{
apiAlias
}
'
,
permission
:
{
crudMethod
:
{
..
.crud
$
{
className
}
},
add
:
['
admin
'
,
'$
{
changeClassName
}:
add
']
,
form
:
{
<#
if
columns
??><#
list
columns
as
column
>$
{
column
.changeColumnName
}:
null
<#
if
column_has_next
>
,
</#
if
></#
list
></#
if
>
},
edit
:
['
admin
'
,
'$
{
changeClassName
}:
edit
']
,
del
:
['
admin
'
,
'$
{
changeClassName
}:
del
']
},
rules
:
{
rules
:
{
<#
if
isNotNullColumns
??>
<#
if
isNotNullColumns
??>
<#
list
isNotNullColumns
as
column
>
<#
list
isNotNullColumns
as
column
>
...
@@ -168,22 +161,14 @@ export default {
...
@@ -168,22 +161,14 @@ export default {
</#
if
>
</#
if
>
}
}
},
},
created
()
{
this
.
$nextTick
(()
=>
{
this
.init
()
})
},
methods
:
{
methods
:
{
//
获取数据前设置好接口地址
//
获取数据前设置好接口地址
beforeInit
()
{
[
CRUD
.HOOK.beforeRefresh
]
()
{
this
.url
=
'
api
/$
{
changeClassName
}
'
const
sort
=
'$
{
pkChangeColName
},
desc
'
this
.params
=
{
page
:
this
.page
,
size
:
this
.size
,
sort
:
sort
}
<#
if
hasQuery
>
<#
if
hasQuery
>
const
query
=
this
.query
const
query
=
this
.query
const
type
=
query
.
type
if
(
query
.
type
&&
query
.
value
)
{
const
value
=
query
.value
this
.crud.params
[
query
.type
]
=
query
.value
if
(
type
&&
value
)
{
this
.params
[
type
]
= value
}
}
</#
if
>
</#
if
>
return
true
return
true
}
}
...
...
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