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
bf7c1eeb
Commit
bf7c1eeb
authored
Oct 24, 2019
by
dqjdda
Browse files
代码优化完成,去除大量idea警告,代码生成器优化等
parent
e3c3ebb1
Changes
146
Hide whitespace changes
Inline
Side-by-side
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DeptServiceImpl.java
View file @
bf7c1eeb
...
@@ -9,7 +9,9 @@ import me.zhengjie.modules.system.repository.DeptRepository;
...
@@ -9,7 +9,9 @@ import me.zhengjie.modules.system.repository.DeptRepository;
import
me.zhengjie.modules.system.service.DeptService
;
import
me.zhengjie.modules.system.service.DeptService
;
import
me.zhengjie.modules.system.service.dto.DeptDTO
;
import
me.zhengjie.modules.system.service.dto.DeptDTO
;
import
me.zhengjie.modules.system.service.mapper.DeptMapper
;
import
me.zhengjie.modules.system.service.mapper.DeptMapper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
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
;
...
@@ -22,28 +24,35 @@ import java.util.stream.Collectors;
...
@@ -22,28 +24,35 @@ import java.util.stream.Collectors;
* @date 2019-03-25
* @date 2019-03-25
*/
*/
@Service
@Service
@CacheConfig
(
cacheNames
=
"dept"
)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
DeptServiceImpl
implements
DeptService
{
public
class
DeptServiceImpl
implements
DeptService
{
@Autowired
private
final
DeptRepository
deptRepository
;
private
DeptRepository
deptRepository
;
@Autowired
private
final
DeptMapper
deptMapper
;
private
DeptMapper
deptMapper
;
public
DeptServiceImpl
(
DeptRepository
deptRepository
,
DeptMapper
deptMapper
)
{
this
.
deptRepository
=
deptRepository
;
this
.
deptMapper
=
deptMapper
;
}
@Override
@Override
@Cacheable
public
List
<
DeptDTO
>
queryAll
(
DeptQueryCriteria
criteria
)
{
public
List
<
DeptDTO
>
queryAll
(
DeptQueryCriteria
criteria
)
{
return
deptMapper
.
toDto
(
deptRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
)));
return
deptMapper
.
toDto
(
deptRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
)));
}
}
@Override
@Override
@Cacheable
(
key
=
"#p0"
)
public
DeptDTO
findById
(
Long
id
)
{
public
DeptDTO
findById
(
Long
id
)
{
Optional
<
Dept
>
dept
=
deptRepository
.
findById
(
id
);
Dept
dept
=
deptRepository
.
findById
(
id
)
.
orElseGet
(
Dept:
:
new
)
;
ValidationUtil
.
isNull
(
dept
,
"Dept"
,
"id"
,
id
);
ValidationUtil
.
isNull
(
dept
.
getId
()
,
"Dept"
,
"id"
,
id
);
return
deptMapper
.
toDto
(
dept
.
get
()
);
return
deptMapper
.
toDto
(
dept
);
}
}
@Override
@Override
@Cacheable
public
List
<
Dept
>
findByPid
(
long
pid
)
{
public
List
<
Dept
>
findByPid
(
long
pid
)
{
return
deptRepository
.
findByPid
(
pid
);
return
deptRepository
.
findByPid
(
pid
);
}
}
...
@@ -54,11 +63,12 @@ public class DeptServiceImpl implements DeptService {
...
@@ -54,11 +63,12 @@ public class DeptServiceImpl implements DeptService {
}
}
@Override
@Override
@Cacheable
public
Object
buildTree
(
List
<
DeptDTO
>
deptDTOS
)
{
public
Object
buildTree
(
List
<
DeptDTO
>
deptDTOS
)
{
Set
<
DeptDTO
>
trees
=
new
LinkedHashSet
<>();
Set
<
DeptDTO
>
trees
=
new
LinkedHashSet
<>();
Set
<
DeptDTO
>
depts
=
new
LinkedHashSet
<>();
Set
<
DeptDTO
>
depts
=
new
LinkedHashSet
<>();
List
<
String
>
deptNames
=
deptDTOS
.
stream
().
map
(
DeptDTO:
:
getName
).
collect
(
Collectors
.
toList
());
List
<
String
>
deptNames
=
deptDTOS
.
stream
().
map
(
DeptDTO:
:
getName
).
collect
(
Collectors
.
toList
());
B
oolean
isChild
;
b
oolean
isChild
;
for
(
DeptDTO
deptDTO
:
deptDTOS
)
{
for
(
DeptDTO
deptDTO
:
deptDTOS
)
{
isChild
=
false
;
isChild
=
false
;
if
(
"0"
.
equals
(
deptDTO
.
getPid
().
toString
()))
{
if
(
"0"
.
equals
(
deptDTO
.
getPid
().
toString
()))
{
...
@@ -68,7 +78,7 @@ public class DeptServiceImpl implements DeptService {
...
@@ -68,7 +78,7 @@ public class DeptServiceImpl implements DeptService {
if
(
it
.
getPid
().
equals
(
deptDTO
.
getId
()))
{
if
(
it
.
getPid
().
equals
(
deptDTO
.
getId
()))
{
isChild
=
true
;
isChild
=
true
;
if
(
deptDTO
.
getChildren
()
==
null
)
{
if
(
deptDTO
.
getChildren
()
==
null
)
{
deptDTO
.
setChildren
(
new
ArrayList
<
DeptDTO
>());
deptDTO
.
setChildren
(
new
ArrayList
<>());
}
}
deptDTO
.
getChildren
().
add
(
it
);
deptDTO
.
getChildren
().
add
(
it
);
}
}
...
@@ -83,34 +93,36 @@ public class DeptServiceImpl implements DeptService {
...
@@ -83,34 +93,36 @@ public class DeptServiceImpl implements DeptService {
trees
=
depts
;
trees
=
depts
;
}
}
Integer
totalElements
=
deptDTOS
!=
null
?
deptDTOS
.
size
()
:
0
;
Integer
totalElements
=
deptDTOS
.
size
();
Map
map
=
new
HashMap
();
Map
<
String
,
Object
>
map
=
new
HashMap
<>
();
map
.
put
(
"totalElements"
,
totalElements
);
map
.
put
(
"totalElements"
,
totalElements
);
map
.
put
(
"content"
,
CollectionUtils
.
isEmpty
(
trees
)?
deptDTOS:
trees
);
map
.
put
(
"content"
,
CollectionUtils
.
isEmpty
(
trees
)?
deptDTOS:
trees
);
return
map
;
return
map
;
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
DeptDTO
create
(
Dept
resources
)
{
public
DeptDTO
create
(
Dept
resources
)
{
return
deptMapper
.
toDto
(
deptRepository
.
save
(
resources
));
return
deptMapper
.
toDto
(
deptRepository
.
save
(
resources
));
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
update
(
Dept
resources
)
{
public
void
update
(
Dept
resources
)
{
if
(
resources
.
getId
().
equals
(
resources
.
getPid
()))
{
if
(
resources
.
getId
().
equals
(
resources
.
getPid
()))
{
throw
new
BadRequestException
(
"上级不能为自己"
);
throw
new
BadRequestException
(
"上级不能为自己"
);
}
}
Optional
<
Dept
>
optionalDept
=
deptRepository
.
findById
(
resources
.
getId
());
Dept
dept
=
deptRepository
.
findById
(
resources
.
getId
()).
orElseGet
(
Dept:
:
new
);
ValidationUtil
.
isNull
(
optionalDept
,
"Dept"
,
"id"
,
resources
.
getId
());
ValidationUtil
.
isNull
(
dept
.
getId
(),
"Dept"
,
"id"
,
resources
.
getId
());
Dept
dept
=
optionalDept
.
get
();
resources
.
setId
(
dept
.
getId
());
resources
.
setId
(
dept
.
getId
());
deptRepository
.
save
(
resources
);
deptRepository
.
save
(
resources
);
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
delete
(
Long
id
)
{
public
void
delete
(
Long
id
)
{
deptRepository
.
deleteById
(
id
);
deptRepository
.
deleteById
(
id
);
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DictDetailServiceImpl.java
View file @
bf7c1eeb
...
@@ -9,7 +9,9 @@ import me.zhengjie.modules.system.repository.DictDetailRepository;
...
@@ -9,7 +9,9 @@ import me.zhengjie.modules.system.repository.DictDetailRepository;
import
me.zhengjie.modules.system.service.DictDetailService
;
import
me.zhengjie.modules.system.service.DictDetailService
;
import
me.zhengjie.modules.system.service.dto.DictDetailDTO
;
import
me.zhengjie.modules.system.service.dto.DictDetailDTO
;
import
me.zhengjie.modules.system.service.mapper.DictDetailMapper
;
import
me.zhengjie.modules.system.service.mapper.DictDetailMapper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CacheConfig
;
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
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -24,45 +26,53 @@ import java.util.Optional;
...
@@ -24,45 +26,53 @@ import java.util.Optional;
* @date 2019-04-10
* @date 2019-04-10
*/
*/
@Service
@Service
@CacheConfig
(
cacheNames
=
"dictDetail"
)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
DictDetailServiceImpl
implements
DictDetailService
{
public
class
DictDetailServiceImpl
implements
DictDetailService
{
@Autowired
private
final
DictDetailRepository
dictDetailRepository
;
private
DictDetailRepository
dictDetailRepository
;
@Autowired
private
final
DictDetailMapper
dictDetailMapper
;
private
DictDetailMapper
dictDetailMapper
;
public
DictDetailServiceImpl
(
DictDetailRepository
dictDetailRepository
,
DictDetailMapper
dictDetailMapper
)
{
this
.
dictDetailRepository
=
dictDetailRepository
;
this
.
dictDetailMapper
=
dictDetailMapper
;
}
@Override
@Override
@Cacheable
public
Map
queryAll
(
DictDetailQueryCriteria
criteria
,
Pageable
pageable
)
{
public
Map
queryAll
(
DictDetailQueryCriteria
criteria
,
Pageable
pageable
)
{
Page
<
DictDetail
>
page
=
dictDetailRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
),
pageable
);
Page
<
DictDetail
>
page
=
dictDetailRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
),
pageable
);
return
PageUtil
.
toPage
(
page
.
map
(
dictDetailMapper:
:
toDto
));
return
PageUtil
.
toPage
(
page
.
map
(
dictDetailMapper:
:
toDto
));
}
}
@Override
@Override
@Cacheable
(
key
=
"#p0"
)
public
DictDetailDTO
findById
(
Long
id
)
{
public
DictDetailDTO
findById
(
Long
id
)
{
Optional
<
DictDetail
>
dictDetail
=
dictDetailRepository
.
findById
(
id
);
DictDetail
dictDetail
=
dictDetailRepository
.
findById
(
id
)
.
orElseGet
(
DictDetail:
:
new
)
;
ValidationUtil
.
isNull
(
dictDetail
,
"DictDetail"
,
"id"
,
id
);
ValidationUtil
.
isNull
(
dictDetail
.
getId
()
,
"DictDetail"
,
"id"
,
id
);
return
dictDetailMapper
.
toDto
(
dictDetail
.
get
()
);
return
dictDetailMapper
.
toDto
(
dictDetail
);
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
DictDetailDTO
create
(
DictDetail
resources
)
{
public
DictDetailDTO
create
(
DictDetail
resources
)
{
return
dictDetailMapper
.
toDto
(
dictDetailRepository
.
save
(
resources
));
return
dictDetailMapper
.
toDto
(
dictDetailRepository
.
save
(
resources
));
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
update
(
DictDetail
resources
)
{
public
void
update
(
DictDetail
resources
)
{
Optional
<
DictDetail
>
optionalDictDetail
=
dictDetailRepository
.
findById
(
resources
.
getId
());
DictDetail
dictDetail
=
dictDetailRepository
.
findById
(
resources
.
getId
()).
orElseGet
(
DictDetail:
:
new
);
ValidationUtil
.
isNull
(
optionalDictDetail
,
"DictDetail"
,
"id"
,
resources
.
getId
());
ValidationUtil
.
isNull
(
dictDetail
.
getId
(),
"DictDetail"
,
"id"
,
resources
.
getId
());
DictDetail
dictDetail
=
optionalDictDetail
.
get
();
resources
.
setId
(
dictDetail
.
getId
());
resources
.
setId
(
dictDetail
.
getId
());
dictDetailRepository
.
save
(
resources
);
dictDetailRepository
.
save
(
resources
);
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
delete
(
Long
id
)
{
public
void
delete
(
Long
id
)
{
dictDetailRepository
.
deleteById
(
id
);
dictDetailRepository
.
deleteById
(
id
);
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/DictServiceImpl.java
View file @
bf7c1eeb
...
@@ -9,58 +9,67 @@ import me.zhengjie.modules.system.repository.DictRepository;
...
@@ -9,58 +9,67 @@ import me.zhengjie.modules.system.repository.DictRepository;
import
me.zhengjie.modules.system.service.DictService
;
import
me.zhengjie.modules.system.service.DictService
;
import
me.zhengjie.modules.system.service.dto.DictDTO
;
import
me.zhengjie.modules.system.service.dto.DictDTO
;
import
me.zhengjie.modules.system.service.mapper.DictMapper
;
import
me.zhengjie.modules.system.service.mapper.DictMapper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CacheConfig
;
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
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.Optional
;
/**
/**
* @author Zheng Jie
* @author Zheng Jie
* @date 2019-04-10
* @date 2019-04-10
*/
*/
@Service
@Service
@CacheConfig
(
cacheNames
=
"dict"
)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
DictServiceImpl
implements
DictService
{
public
class
DictServiceImpl
implements
DictService
{
@Autowired
private
final
DictRepository
dictRepository
;
private
DictRepository
dictRepository
;
@Autowired
private
final
DictMapper
dictMapper
;
private
DictMapper
dictMapper
;
public
DictServiceImpl
(
DictRepository
dictRepository
,
DictMapper
dictMapper
)
{
this
.
dictRepository
=
dictRepository
;
this
.
dictMapper
=
dictMapper
;
}
@Override
@Override
@Cacheable
public
Object
queryAll
(
DictQueryCriteria
dict
,
Pageable
pageable
){
public
Object
queryAll
(
DictQueryCriteria
dict
,
Pageable
pageable
){
Page
<
Dict
>
page
=
dictRepository
.
findAll
((
root
,
query
,
cb
)
->
QueryHelp
.
getPredicate
(
root
,
dict
,
cb
),
pageable
);
Page
<
Dict
>
page
=
dictRepository
.
findAll
((
root
,
query
,
cb
)
->
QueryHelp
.
getPredicate
(
root
,
dict
,
cb
),
pageable
);
return
PageUtil
.
toPage
(
page
.
map
(
dictMapper:
:
toDto
));
return
PageUtil
.
toPage
(
page
.
map
(
dictMapper:
:
toDto
));
}
}
@Override
@Override
@Cacheable
(
key
=
"#p0"
)
public
DictDTO
findById
(
Long
id
)
{
public
DictDTO
findById
(
Long
id
)
{
Optional
<
Dict
>
dict
=
dictRepository
.
findById
(
id
);
Dict
dict
=
dictRepository
.
findById
(
id
)
.
orElseGet
(
Dict:
:
new
)
;
ValidationUtil
.
isNull
(
dict
,
"Dict"
,
"id"
,
id
);
ValidationUtil
.
isNull
(
dict
.
getId
()
,
"Dict"
,
"id"
,
id
);
return
dictMapper
.
toDto
(
dict
.
get
()
);
return
dictMapper
.
toDto
(
dict
);
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
DictDTO
create
(
Dict
resources
)
{
public
DictDTO
create
(
Dict
resources
)
{
return
dictMapper
.
toDto
(
dictRepository
.
save
(
resources
));
return
dictMapper
.
toDto
(
dictRepository
.
save
(
resources
));
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
update
(
Dict
resources
)
{
public
void
update
(
Dict
resources
)
{
Optional
<
Dict
>
optionalDict
=
dictRepository
.
findById
(
resources
.
getId
());
Dict
dict
=
dictRepository
.
findById
(
resources
.
getId
()).
orElseGet
(
Dict:
:
new
);
ValidationUtil
.
isNull
(
optionalDict
,
"Dict"
,
"id"
,
resources
.
getId
());
ValidationUtil
.
isNull
(
dict
.
getId
(),
"Dict"
,
"id"
,
resources
.
getId
());
Dict
dict
=
optionalDict
.
get
();
resources
.
setId
(
dict
.
getId
());
resources
.
setId
(
dict
.
getId
());
dictRepository
.
save
(
resources
);
dictRepository
.
save
(
resources
);
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
delete
(
Long
id
)
{
public
void
delete
(
Long
id
)
{
dictRepository
.
deleteById
(
id
);
dictRepository
.
deleteById
(
id
);
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/JobServiceImpl.java
View file @
bf7c1eeb
...
@@ -10,7 +10,9 @@ import me.zhengjie.modules.system.repository.JobRepository;
...
@@ -10,7 +10,9 @@ import me.zhengjie.modules.system.repository.JobRepository;
import
me.zhengjie.modules.system.service.JobService
;
import
me.zhengjie.modules.system.service.JobService
;
import
me.zhengjie.modules.system.service.dto.JobDTO
;
import
me.zhengjie.modules.system.service.dto.JobDTO
;
import
me.zhengjie.modules.system.service.mapper.JobMapper
;
import
me.zhengjie.modules.system.service.mapper.JobMapper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CacheConfig
;
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
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -18,24 +20,27 @@ import org.springframework.transaction.annotation.Propagation;
...
@@ -18,24 +20,27 @@ import org.springframework.transaction.annotation.Propagation;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Optional
;
/**
/**
* @author Zheng Jie
* @author Zheng Jie
* @date 2019-03-29
* @date 2019-03-29
*/
*/
@Service
@Service
@CacheConfig
(
cacheNames
=
"job"
)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
JobServiceImpl
implements
JobService
{
public
class
JobServiceImpl
implements
JobService
{
@Autowired
private
final
JobRepository
jobRepository
;
private
JobRepository
jobRepository
;
@Autowired
private
final
JobMapper
jobMapper
;
private
JobMapper
jobMapper
;
@Autowired
private
final
DeptRepository
deptRepository
;
private
DeptRepository
deptRepository
;
public
JobServiceImpl
(
JobRepository
jobRepository
,
JobMapper
jobMapper
,
DeptRepository
deptRepository
)
{
this
.
jobRepository
=
jobRepository
;
this
.
jobMapper
=
jobMapper
;
this
.
deptRepository
=
deptRepository
;
}
@Override
@Override
public
Object
queryAll
(
JobQueryCriteria
criteria
,
Pageable
pageable
)
{
public
Object
queryAll
(
JobQueryCriteria
criteria
,
Pageable
pageable
)
{
...
@@ -48,30 +53,32 @@ public class JobServiceImpl implements JobService {
...
@@ -48,30 +53,32 @@ public class JobServiceImpl implements JobService {
}
}
@Override
@Override
@Cacheable
(
key
=
"#p0"
)
public
JobDTO
findById
(
Long
id
)
{
public
JobDTO
findById
(
Long
id
)
{
Optional
<
Job
>
job
=
jobRepository
.
findById
(
id
);
Job
job
=
jobRepository
.
findById
(
id
)
.
orElseGet
(
Job:
:
new
)
;
ValidationUtil
.
isNull
(
job
,
"Job"
,
"id"
,
id
);
ValidationUtil
.
isNull
(
job
.
getId
()
,
"Job"
,
"id"
,
id
);
return
jobMapper
.
toDto
(
job
.
get
()
);
return
jobMapper
.
toDto
(
job
);
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
JobDTO
create
(
Job
resources
)
{
public
JobDTO
create
(
Job
resources
)
{
return
jobMapper
.
toDto
(
jobRepository
.
save
(
resources
));
return
jobMapper
.
toDto
(
jobRepository
.
save
(
resources
));
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
update
(
Job
resources
)
{
public
void
update
(
Job
resources
)
{
Optional
<
Job
>
optionalJob
=
jobRepository
.
findById
(
resources
.
getId
());
Job
job
=
jobRepository
.
findById
(
resources
.
getId
()).
orElseGet
(
Job:
:
new
);
ValidationUtil
.
isNull
(
optionalJob
,
"Job"
,
"id"
,
resources
.
getId
());
ValidationUtil
.
isNull
(
job
.
getId
(),
"Job"
,
"id"
,
resources
.
getId
());
Job
job
=
optionalJob
.
get
();
resources
.
setId
(
job
.
getId
());
resources
.
setId
(
job
.
getId
());
jobRepository
.
save
(
resources
);
jobRepository
.
save
(
resources
);
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
delete
(
Long
id
)
{
public
void
delete
(
Long
id
)
{
jobRepository
.
deleteById
(
id
);
jobRepository
.
deleteById
(
id
);
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MenuServiceImpl.java
View file @
bf7c1eeb
package
me.zhengjie.modules.system.service.impl
;
package
me.zhengjie.modules.system.service.impl
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.RandomUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.StrUtil
;
import
me.zhengjie.modules.system.domain.Menu
;
import
me.zhengjie.modules.system.domain.Menu
;
import
me.zhengjie.modules.system.domain.vo.MenuMetaVo
;
import
me.zhengjie.modules.system.domain.vo.MenuMetaVo
;
...
@@ -18,7 +17,9 @@ import me.zhengjie.modules.system.service.mapper.MenuMapper;
...
@@ -18,7 +17,9 @@ import me.zhengjie.modules.system.service.mapper.MenuMapper;
import
me.zhengjie.utils.QueryHelp
;
import
me.zhengjie.utils.QueryHelp
;
import
me.zhengjie.utils.StringUtils
;
import
me.zhengjie.utils.StringUtils
;
import
me.zhengjie.utils.ValidationUtil
;
import
me.zhengjie.utils.ValidationUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
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
;
...
@@ -26,41 +27,48 @@ import java.util.*;
...
@@ -26,41 +27,48 @@ import java.util.*;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
@Service
@Service
@CacheConfig
(
cacheNames
=
"menu"
)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
MenuServiceImpl
implements
MenuService
{
public
class
MenuServiceImpl
implements
MenuService
{
@Autowired
private
final
MenuRepository
menuRepository
;
private
MenuRepository
menuRepository
;
@Autowired
private
final
MenuMapper
menuMapper
;
private
MenuMapper
menuMapper
;
@Autowired
private
final
RoleService
roleService
;
private
RoleService
roleService
;
public
MenuServiceImpl
(
MenuRepository
menuRepository
,
MenuMapper
menuMapper
,
RoleService
roleService
)
{
this
.
menuRepository
=
menuRepository
;
this
.
menuMapper
=
menuMapper
;
this
.
roleService
=
roleService
;
}
@Override
@Override
public
List
queryAll
(
MenuQueryCriteria
criteria
){
@Cacheable
public
List
<
MenuDTO
>
queryAll
(
MenuQueryCriteria
criteria
){
return
menuMapper
.
toDto
(
menuRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
)));
return
menuMapper
.
toDto
(
menuRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
)));
}
}
@Override
@Override
@Cacheable
(
key
=
"#p0"
)
public
MenuDTO
findById
(
long
id
)
{
public
MenuDTO
findById
(
long
id
)
{
Optional
<
Menu
>
menu
=
menuRepository
.
findById
(
id
);
Menu
menu
=
menuRepository
.
findById
(
id
)
.
orElseGet
(
Menu:
:
new
)
;
ValidationUtil
.
isNull
(
menu
,
"Menu"
,
"id"
,
id
);
ValidationUtil
.
isNull
(
menu
.
getId
()
,
"Menu"
,
"id"
,
id
);
return
menuMapper
.
toDto
(
menu
.
get
()
);
return
menuMapper
.
toDto
(
menu
);
}
}
@Override
@Override
public
List
<
MenuDTO
>
findByRoles
(
List
<
RoleSmallDTO
>
roles
)
{
public
List
<
MenuDTO
>
findByRoles
(
List
<
RoleSmallDTO
>
roles
)
{
Set
<
Menu
>
menus
=
new
LinkedHashSet
<>();
Set
<
Menu
>
menus
=
new
LinkedHashSet
<>();
for
(
RoleSmallDTO
role
:
roles
)
{
for
(
RoleSmallDTO
role
:
roles
)
{
List
<
Menu
>
menus1
=
menuRepository
.
findByRoles_IdOrderBySortAsc
(
role
.
getId
())
.
stream
().
collect
(
Collectors
.
toList
()
);
List
<
Menu
>
menus1
=
new
ArrayList
<>(
menuRepository
.
findByRoles_IdOrderBySortAsc
(
role
.
getId
()));
menus
.
addAll
(
menus1
);
menus
.
addAll
(
menus1
);
}
}
return
menus
.
stream
().
map
(
menuMapper:
:
toDto
).
collect
(
Collectors
.
toList
());
return
menus
.
stream
().
map
(
menuMapper:
:
toDto
).
collect
(
Collectors
.
toList
());
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
public
MenuDTO
create
(
Menu
resources
)
{
public
MenuDTO
create
(
Menu
resources
)
{
if
(
menuRepository
.
findByName
(
resources
.
getName
())
!=
null
){
if
(
menuRepository
.
findByName
(
resources
.
getName
())
!=
null
){
throw
new
EntityExistException
(
Menu
.
class
,
"name"
,
resources
.
getName
());
throw
new
EntityExistException
(
Menu
.
class
,
"name"
,
resources
.
getName
());
...
@@ -79,19 +87,19 @@ public class MenuServiceImpl implements MenuService {
...
@@ -79,19 +87,19 @@ public class MenuServiceImpl implements MenuService {
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
public
void
update
(
Menu
resources
)
{
public
void
update
(
Menu
resources
)
{
if
(
resources
.
getId
().
equals
(
resources
.
getPid
()))
{
if
(
resources
.
getId
().
equals
(
resources
.
getPid
()))
{
throw
new
BadRequestException
(
"上级不能为自己"
);
throw
new
BadRequestException
(
"上级不能为自己"
);
}
}
Optional
<
Menu
>
optionalPermission
=
menuRepository
.
findById
(
resources
.
getId
());
Menu
menu
=
menuRepository
.
findById
(
resources
.
getId
())
.
orElseGet
(
Menu:
:
new
)
;
ValidationUtil
.
isNull
(
optionalPermission
,
"Permission"
,
"id"
,
resources
.
getId
());
ValidationUtil
.
isNull
(
menu
.
getId
()
,
"Permission"
,
"id"
,
resources
.
getId
());
if
(
resources
.
getIFrame
()){
if
(
resources
.
getIFrame
()){
if
(!(
resources
.
getPath
().
toLowerCase
().
startsWith
(
"http://"
)||
resources
.
getPath
().
toLowerCase
().
startsWith
(
"https://"
)))
{
if
(!(
resources
.
getPath
().
toLowerCase
().
startsWith
(
"http://"
)||
resources
.
getPath
().
toLowerCase
().
startsWith
(
"https://"
)))
{
throw
new
BadRequestException
(
"外链必须以http://或者https://开头"
);
throw
new
BadRequestException
(
"外链必须以http://或者https://开头"
);
}
}
}
}
Menu
menu
=
optionalPermission
.
get
();
Menu
menu1
=
menuRepository
.
findByName
(
resources
.
getName
());
Menu
menu1
=
menuRepository
.
findByName
(
resources
.
getName
());
if
(
menu1
!=
null
&&
!
menu1
.
getId
().
equals
(
menu
.
getId
())){
if
(
menu1
!=
null
&&
!
menu1
.
getId
().
equals
(
menu
.
getId
())){
...
@@ -131,6 +139,7 @@ public class MenuServiceImpl implements MenuService {
...
@@ -131,6 +139,7 @@ public class MenuServiceImpl implements MenuService {
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
delete
(
Set
<
Menu
>
menuSet
)
{
public
void
delete
(
Set
<
Menu
>
menuSet
)
{
for
(
Menu
menu
:
menuSet
)
{
for
(
Menu
menu
:
menuSet
)
{
...
@@ -140,6 +149,7 @@ public class MenuServiceImpl implements MenuService {
...
@@ -140,6 +149,7 @@ public class MenuServiceImpl implements MenuService {
}
}
@Override
@Override
@Cacheable
(
key
=
"'tree'"
)
public
Object
getMenuTree
(
List
<
Menu
>
menus
)
{
public
Object
getMenuTree
(
List
<
Menu
>
menus
)
{
List
<
Map
<
String
,
Object
>>
list
=
new
LinkedList
<>();
List
<
Map
<
String
,
Object
>>
list
=
new
LinkedList
<>();
menus
.
forEach
(
menu
->
{
menus
.
forEach
(
menu
->
{
...
@@ -159,13 +169,14 @@ public class MenuServiceImpl implements MenuService {
...
@@ -159,13 +169,14 @@ public class MenuServiceImpl implements MenuService {
}
}
@Override
@Override
@Cacheable
(
key
=
"'pid:'+#p0"
)
public
List
<
Menu
>
findByPid
(
long
pid
)
{
public
List
<
Menu
>
findByPid
(
long
pid
)
{
return
menuRepository
.
findByPid
(
pid
);
return
menuRepository
.
findByPid
(
pid
);
}
}
@Override
@Override
public
Map
buildTree
(
List
<
MenuDTO
>
menuDTOS
)
{
public
Map
<
String
,
Object
>
buildTree
(
List
<
MenuDTO
>
menuDTOS
)
{
List
<
MenuDTO
>
trees
=
new
ArrayList
<
MenuDTO
>();
List
<
MenuDTO
>
trees
=
new
ArrayList
<>();
Set
<
Long
>
ids
=
new
HashSet
<>();
Set
<
Long
>
ids
=
new
HashSet
<>();
for
(
MenuDTO
menuDTO
:
menuDTOS
)
{
for
(
MenuDTO
menuDTO
:
menuDTOS
)
{
if
(
menuDTO
.
getPid
()
==
0
)
{
if
(
menuDTO
.
getPid
()
==
0
)
{
...
@@ -174,19 +185,19 @@ public class MenuServiceImpl implements MenuService {
...
@@ -174,19 +185,19 @@ public class MenuServiceImpl implements MenuService {
for
(
MenuDTO
it
:
menuDTOS
)
{
for
(
MenuDTO
it
:
menuDTOS
)
{
if
(
it
.
getPid
().
equals
(
menuDTO
.
getId
()))
{
if
(
it
.
getPid
().
equals
(
menuDTO
.
getId
()))
{
if
(
menuDTO
.
getChildren
()
==
null
)
{
if
(
menuDTO
.
getChildren
()
==
null
)
{
menuDTO
.
setChildren
(
new
ArrayList
<
MenuDTO
>());
menuDTO
.
setChildren
(
new
ArrayList
<>());
}
}
menuDTO
.
getChildren
().
add
(
it
);
menuDTO
.
getChildren
().
add
(
it
);
ids
.
add
(
it
.
getId
());
ids
.
add
(
it
.
getId
());
}
}
}
}
}
}
Map
map
=
new
HashMap
();
Map
<
String
,
Object
>
map
=
new
HashMap
<>
();
if
(
trees
.
size
()
==
0
){
if
(
trees
.
size
()
==
0
){
trees
=
menuDTOS
.
stream
().
filter
(
s
->
!
ids
.
contains
(
s
.
getId
())).
collect
(
Collectors
.
toList
());
trees
=
menuDTOS
.
stream
().
filter
(
s
->
!
ids
.
contains
(
s
.
getId
())).
collect
(
Collectors
.
toList
());
}
}
map
.
put
(
"content"
,
trees
);
map
.
put
(
"content"
,
trees
);
map
.
put
(
"totalElements"
,
menuDTOS
!=
null
?
menuDTOS
.
size
()
:
0
);
map
.
put
(
"totalElements"
,
menuDTOS
.
size
());
return
map
;
return
map
;
}
}
...
@@ -229,7 +240,7 @@ public class MenuServiceImpl implements MenuService {
...
@@ -229,7 +240,7 @@ public class MenuServiceImpl implements MenuService {
menuVo
.
setName
(
null
);
menuVo
.
setName
(
null
);
menuVo
.
setMeta
(
null
);
menuVo
.
setMeta
(
null
);
menuVo
.
setComponent
(
"Layout"
);
menuVo
.
setComponent
(
"Layout"
);
List
<
MenuVo
>
list1
=
new
ArrayList
<
MenuVo
>();
List
<
MenuVo
>
list1
=
new
ArrayList
<>();
list1
.
add
(
menuVo1
);
list1
.
add
(
menuVo1
);
menuVo
.
setChildren
(
list1
);
menuVo
.
setChildren
(
list1
);
}
}
...
@@ -242,8 +253,8 @@ public class MenuServiceImpl implements MenuService {
...
@@ -242,8 +253,8 @@ public class MenuServiceImpl implements MenuService {
@Override
@Override
public
Menu
findOne
(
Long
id
)
{
public
Menu
findOne
(
Long
id
)
{
Optional
<
Menu
>
menu
=
menuRepository
.
findById
(
id
);
Menu
menu
=
menuRepository
.
findById
(
id
)
.
orElseGet
(
Menu:
:
new
)
;
ValidationUtil
.
isNull
(
menu
,
"Menu"
,
"id"
,
id
);
ValidationUtil
.
isNull
(
menu
.
getId
()
,
"Menu"
,
"id"
,
id
);
return
menu
.
get
()
;
return
menu
;
}
}
}
}
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/PermissionServiceImpl.java
View file @
bf7c1eeb
...
@@ -11,7 +11,9 @@ import me.zhengjie.modules.system.service.dto.PermissionQueryCriteria;
...
@@ -11,7 +11,9 @@ import me.zhengjie.modules.system.service.dto.PermissionQueryCriteria;
import
me.zhengjie.modules.system.service.mapper.PermissionMapper
;
import
me.zhengjie.modules.system.service.mapper.PermissionMapper
;
import
me.zhengjie.utils.QueryHelp
;
import
me.zhengjie.utils.QueryHelp
;
import
me.zhengjie.utils.ValidationUtil
;
import
me.zhengjie.utils.ValidationUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CacheConfig
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
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
;
...
@@ -22,31 +24,38 @@ import java.util.*;
...
@@ -22,31 +24,38 @@ import java.util.*;
* @date 2018-12-03
* @date 2018-12-03
*/
*/
@Service
@Service
@CacheConfig
(
cacheNames
=
"permission"
)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
PermissionServiceImpl
implements
PermissionService
{
public
class
PermissionServiceImpl
implements
PermissionService
{
@Autowired
private
final
PermissionRepository
permissionRepository
;
private
PermissionRepository
permissionRepository
;
@Autowired
private
final
PermissionMapper
permissionMapper
;
private
PermissionMapper
permissionMapper
;
@Autowired
private
final
RoleService
roleService
;
private
RoleService
roleService
;
public
PermissionServiceImpl
(
PermissionRepository
permissionRepository
,
PermissionMapper
permissionMapper
,
RoleService
roleService
)
{
this
.
permissionRepository
=
permissionRepository
;
this
.
permissionMapper
=
permissionMapper
;
this
.
roleService
=
roleService
;
}
@Override
@Override
@Cacheable
public
List
<
PermissionDTO
>
queryAll
(
PermissionQueryCriteria
criteria
)
{
public
List
<
PermissionDTO
>
queryAll
(
PermissionQueryCriteria
criteria
)
{
return
permissionMapper
.
toDto
(
permissionRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
)));
return
permissionMapper
.
toDto
(
permissionRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
)));
}
}
@Override
@Override
@Cacheable
(
key
=
"#p0"
)
public
PermissionDTO
findById
(
long
id
)
{
public
PermissionDTO
findById
(
long
id
)
{
Optional
<
Permission
>
permission
=
permissionRepository
.
findById
(
id
);
Permission
permission
=
permissionRepository
.
findById
(
id
)
.
orElseGet
(
Permission:
:
new
)
;
ValidationUtil
.
isNull
(
permission
,
"Permission"
,
"id"
,
id
);
ValidationUtil
.
isNull
(
permission
.
getId
()
,
"Permission"
,
"id"
,
id
);
return
permissionMapper
.
toDto
(
permission
.
get
()
);
return
permissionMapper
.
toDto
(
permission
);
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
PermissionDTO
create
(
Permission
resources
)
{
public
PermissionDTO
create
(
Permission
resources
)
{
if
(
permissionRepository
.
findByName
(
resources
.
getName
())
!=
null
){
if
(
permissionRepository
.
findByName
(
resources
.
getName
())
!=
null
){
...
@@ -56,15 +65,14 @@ public class PermissionServiceImpl implements PermissionService {
...
@@ -56,15 +65,14 @@ public class PermissionServiceImpl implements PermissionService {
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
update
(
Permission
resources
)
{
public
void
update
(
Permission
resources
)
{
Optional
<
Permission
>
optionalP
ermission
=
permissionRepository
.
findById
(
resources
.
getId
());
Permission
p
ermission
=
permissionRepository
.
findById
(
resources
.
getId
())
.
orElseGet
(
Permission:
:
new
)
;
if
(
resources
.
getId
().
equals
(
resources
.
getPid
()))
{
if
(
resources
.
getId
().
equals
(
resources
.
getPid
()))
{
throw
new
BadRequestException
(
"上级不能为自己"
);
throw
new
BadRequestException
(
"上级不能为自己"
);
}
}
ValidationUtil
.
isNull
(
optionalPermission
,
"Permission"
,
"id"
,
resources
.
getId
());
ValidationUtil
.
isNull
(
permission
.
getId
(),
"Permission"
,
"id"
,
resources
.
getId
());
Permission
permission
=
optionalPermission
.
get
();
Permission
permission1
=
permissionRepository
.
findByName
(
resources
.
getName
());
Permission
permission1
=
permissionRepository
.
findByName
(
resources
.
getName
());
...
@@ -92,6 +100,7 @@ public class PermissionServiceImpl implements PermissionService {
...
@@ -92,6 +100,7 @@ public class PermissionServiceImpl implements PermissionService {
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
delete
(
Set
<
Permission
>
permissions
)
{
public
void
delete
(
Set
<
Permission
>
permissions
)
{
for
(
Permission
permission
:
permissions
)
{
for
(
Permission
permission
:
permissions
)
{
...
@@ -101,6 +110,7 @@ public class PermissionServiceImpl implements PermissionService {
...
@@ -101,6 +110,7 @@ public class PermissionServiceImpl implements PermissionService {
}
}
@Override
@Override
@Cacheable
(
key
=
"'tree'"
)
public
Object
getPermissionTree
(
List
<
Permission
>
permissions
)
{
public
Object
getPermissionTree
(
List
<
Permission
>
permissions
)
{
List
<
Map
<
String
,
Object
>>
list
=
new
LinkedList
<>();
List
<
Map
<
String
,
Object
>>
list
=
new
LinkedList
<>();
permissions
.
forEach
(
permission
->
{
permissions
.
forEach
(
permission
->
{
...
@@ -120,14 +130,16 @@ public class PermissionServiceImpl implements PermissionService {
...
@@ -120,14 +130,16 @@ public class PermissionServiceImpl implements PermissionService {
}
}
@Override
@Override
@Cacheable
(
key
=
"'pid:'+#p0"
)
public
List
<
Permission
>
findByPid
(
long
pid
)
{
public
List
<
Permission
>
findByPid
(
long
pid
)
{
return
permissionRepository
.
findByPid
(
pid
);
return
permissionRepository
.
findByPid
(
pid
);
}
}
@Override
@Override
@Cacheable
public
Object
buildTree
(
List
<
PermissionDTO
>
permissionDTOS
)
{
public
Object
buildTree
(
List
<
PermissionDTO
>
permissionDTOS
)
{
List
<
PermissionDTO
>
trees
=
new
ArrayList
<
PermissionDTO
>();
List
<
PermissionDTO
>
trees
=
new
ArrayList
<>();
for
(
PermissionDTO
permissionDTO
:
permissionDTOS
)
{
for
(
PermissionDTO
permissionDTO
:
permissionDTOS
)
{
...
@@ -138,16 +150,16 @@ public class PermissionServiceImpl implements PermissionService {
...
@@ -138,16 +150,16 @@ public class PermissionServiceImpl implements PermissionService {
for
(
PermissionDTO
it
:
permissionDTOS
)
{
for
(
PermissionDTO
it
:
permissionDTOS
)
{
if
(
it
.
getPid
().
equals
(
permissionDTO
.
getId
()))
{
if
(
it
.
getPid
().
equals
(
permissionDTO
.
getId
()))
{
if
(
permissionDTO
.
getChildren
()
==
null
)
{
if
(
permissionDTO
.
getChildren
()
==
null
)
{
permissionDTO
.
setChildren
(
new
ArrayList
<
PermissionDTO
>());
permissionDTO
.
setChildren
(
new
ArrayList
<>());
}
}
permissionDTO
.
getChildren
().
add
(
it
);
permissionDTO
.
getChildren
().
add
(
it
);
}
}
}
}
}
}
Integer
totalElements
=
permissionDTOS
!=
null
?
permissionDTOS
.
size
()
:
0
;
Integer
totalElements
=
permissionDTOS
.
size
();
Map
map
=
new
HashMap
();
Map
<
String
,
Object
>
map
=
new
HashMap
<>
();
map
.
put
(
"content"
,
trees
.
size
()
==
0
?
permissionDTOS:
trees
);
map
.
put
(
"content"
,
trees
.
size
()
==
0
?
permissionDTOS:
trees
);
map
.
put
(
"totalElements"
,
totalElements
);
map
.
put
(
"totalElements"
,
totalElements
);
return
map
;
return
map
;
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/RoleServiceImpl.java
View file @
bf7c1eeb
...
@@ -12,7 +12,9 @@ import me.zhengjie.modules.system.service.mapper.RoleSmallMapper;
...
@@ -12,7 +12,9 @@ import me.zhengjie.modules.system.service.mapper.RoleSmallMapper;
import
me.zhengjie.utils.PageUtil
;
import
me.zhengjie.utils.PageUtil
;
import
me.zhengjie.utils.QueryHelp
;
import
me.zhengjie.utils.QueryHelp
;
import
me.zhengjie.utils.ValidationUtil
;
import
me.zhengjie.utils.ValidationUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CacheConfig
;
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
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -26,42 +28,51 @@ import java.util.stream.Collectors;
...
@@ -26,42 +28,51 @@ import java.util.stream.Collectors;
* @date 2018-12-03
* @date 2018-12-03
*/
*/
@Service
@Service
@CacheConfig
(
cacheNames
=
"role"
)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
RoleServiceImpl
implements
RoleService
{
public
class
RoleServiceImpl
implements
RoleService
{
@Autowired
private
final
RoleRepository
roleRepository
;
private
RoleRepository
roleRepository
;
@Autowired
private
final
RoleMapper
roleMapper
;
private
RoleMapper
roleMapper
;
@Autowired
private
final
RoleSmallMapper
roleSmallMapper
;
private
RoleSmallMapper
roleSmallMapper
;
public
RoleServiceImpl
(
RoleRepository
roleRepository
,
RoleMapper
roleMapper
,
RoleSmallMapper
roleSmallMapper
)
{
this
.
roleRepository
=
roleRepository
;
this
.
roleMapper
=
roleMapper
;
this
.
roleSmallMapper
=
roleSmallMapper
;
}
@Override
@Override
@Cacheable
public
Object
queryAll
(
Pageable
pageable
)
{
public
Object
queryAll
(
Pageable
pageable
)
{
return
roleMapper
.
toDto
(
roleRepository
.
findAll
(
pageable
).
getContent
());
return
roleMapper
.
toDto
(
roleRepository
.
findAll
(
pageable
).
getContent
());
}
}
@Override
@Override
@Cacheable
public
List
<
RoleDTO
>
queryAll
(
RoleQueryCriteria
criteria
)
{
public
List
<
RoleDTO
>
queryAll
(
RoleQueryCriteria
criteria
)
{
return
roleMapper
.
toDto
(
roleRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
)));
return
roleMapper
.
toDto
(
roleRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
)));
}
}
@Override
@Override
@Cacheable
public
Object
queryAll
(
RoleQueryCriteria
criteria
,
Pageable
pageable
)
{
public
Object
queryAll
(
RoleQueryCriteria
criteria
,
Pageable
pageable
)
{
Page
<
Role
>
page
=
roleRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
),
pageable
);
Page
<
Role
>
page
=
roleRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
),
pageable
);
return
PageUtil
.
toPage
(
page
.
map
(
roleMapper:
:
toDto
));
return
PageUtil
.
toPage
(
page
.
map
(
roleMapper:
:
toDto
));
}
}
@Override
@Override
@Cacheable
(
key
=
"#p0"
)
public
RoleDTO
findById
(
long
id
)
{
public
RoleDTO
findById
(
long
id
)
{
Optional
<
Role
>
role
=
roleRepository
.
findById
(
id
);
Role
role
=
roleRepository
.
findById
(
id
)
.
orElseGet
(
Role:
:
new
)
;
ValidationUtil
.
isNull
(
role
,
"Role"
,
"id"
,
id
);
ValidationUtil
.
isNull
(
role
.
getId
()
,
"Role"
,
"id"
,
id
);
return
roleMapper
.
toDto
(
role
.
get
()
);
return
roleMapper
.
toDto
(
role
);
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
RoleDTO
create
(
Role
resources
)
{
public
RoleDTO
create
(
Role
resources
)
{
if
(
roleRepository
.
findByName
(
resources
.
getName
())
!=
null
){
if
(
roleRepository
.
findByName
(
resources
.
getName
())
!=
null
){
...
@@ -71,13 +82,11 @@ public class RoleServiceImpl implements RoleService {
...
@@ -71,13 +82,11 @@ public class RoleServiceImpl implements RoleService {
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
update
(
Role
resources
)
{
public
void
update
(
Role
resources
)
{
Role
role
=
roleRepository
.
findById
(
resources
.
getId
()).
orElseGet
(
Role:
:
new
);
Optional
<
Role
>
optionalRole
=
roleRepository
.
findById
(
resources
.
getId
());
ValidationUtil
.
isNull
(
role
.
getId
(),
"Role"
,
"id"
,
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
());
...
@@ -94,6 +103,7 @@ public class RoleServiceImpl implements RoleService {
...
@@ -94,6 +103,7 @@ public class RoleServiceImpl implements RoleService {
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
public
void
updatePermission
(
Role
resources
,
RoleDTO
roleDTO
)
{
public
void
updatePermission
(
Role
resources
,
RoleDTO
roleDTO
)
{
Role
role
=
roleMapper
.
toEntity
(
roleDTO
);
Role
role
=
roleMapper
.
toEntity
(
roleDTO
);
role
.
setPermissions
(
resources
.
getPermissions
());
role
.
setPermissions
(
resources
.
getPermissions
());
...
@@ -101,6 +111,7 @@ public class RoleServiceImpl implements RoleService {
...
@@ -101,6 +111,7 @@ public class RoleServiceImpl implements RoleService {
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
public
void
updateMenu
(
Role
resources
,
RoleDTO
roleDTO
)
{
public
void
updateMenu
(
Role
resources
,
RoleDTO
roleDTO
)
{
Role
role
=
roleMapper
.
toEntity
(
roleDTO
);
Role
role
=
roleMapper
.
toEntity
(
roleDTO
);
role
.
setMenus
(
resources
.
getMenus
());
role
.
setMenus
(
resources
.
getMenus
());
...
@@ -108,29 +119,34 @@ public class RoleServiceImpl implements RoleService {
...
@@ -108,29 +119,34 @@ public class RoleServiceImpl implements RoleService {
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
untiedMenu
(
Long
id
)
{
public
void
untiedMenu
(
Long
id
)
{
roleRepository
.
untiedMenu
(
id
);
roleRepository
.
untiedMenu
(
id
);
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
untiedPermission
(
Long
id
)
{
public
void
untiedPermission
(
Long
id
)
{
roleRepository
.
untiedPermission
(
id
);
roleRepository
.
untiedPermission
(
id
);
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
delete
(
Long
id
)
{
public
void
delete
(
Long
id
)
{
roleRepository
.
deleteById
(
id
);
roleRepository
.
deleteById
(
id
);
}
}
@Override
@Override
@Cacheable
(
key
=
"'findByUsers_Id:' + #p0"
)
public
List
<
RoleSmallDTO
>
findByUsers_Id
(
Long
id
)
{
public
List
<
RoleSmallDTO
>
findByUsers_Id
(
Long
id
)
{
return
roleSmallMapper
.
toDto
(
roleRepository
.
findByUsers_Id
(
id
)
.
stream
().
collect
(
Collectors
.
toList
()
));
return
roleSmallMapper
.
toDto
(
new
ArrayList
<>(
roleRepository
.
findByUsers_Id
(
id
)));
}
}
@Override
@Override
@Cacheable
public
Integer
findByRoles
(
Set
<
Role
>
roles
)
{
public
Integer
findByRoles
(
Set
<
Role
>
roles
)
{
Set
<
RoleDTO
>
roleDTOS
=
new
HashSet
<>();
Set
<
RoleDTO
>
roleDTOS
=
new
HashSet
<>();
for
(
Role
role
:
roles
)
{
for
(
Role
role
:
roles
)
{
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/UserServiceImpl.java
View file @
bf7c1eeb
package
me.zhengjie.modules.system.service.impl
;
package
me.zhengjie.modules.system.service.impl
;
import
cn.hutool.core.io.IoUtil
;
import
cn.hutool.poi.excel.ExcelUtil
;
import
cn.hutool.poi.excel.ExcelWriter
;
import
me.zhengjie.modules.monitor.service.RedisService
;
import
me.zhengjie.modules.monitor.service.RedisService
;
import
me.zhengjie.modules.system.domain.User
;
import
me.zhengjie.modules.system.domain.User
;
import
me.zhengjie.exception.EntityExistException
;
import
me.zhengjie.exception.EntityExistException
;
...
@@ -16,16 +13,16 @@ import me.zhengjie.modules.system.service.dto.UserDTO;
...
@@ -16,16 +13,16 @@ import me.zhengjie.modules.system.service.dto.UserDTO;
import
me.zhengjie.modules.system.service.dto.UserQueryCriteria
;
import
me.zhengjie.modules.system.service.dto.UserQueryCriteria
;
import
me.zhengjie.modules.system.service.mapper.UserMapper
;
import
me.zhengjie.modules.system.service.mapper.UserMapper
;
import
me.zhengjie.utils.*
;
import
me.zhengjie.utils.*
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.cache.annotation.CacheConfig
;
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
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
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.ServletOutputStream
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
...
@@ -37,44 +34,52 @@ import java.util.stream.Collectors;
...
@@ -37,44 +34,52 @@ import java.util.stream.Collectors;
* @date 2018-11-23
* @date 2018-11-23
*/
*/
@Service
@Service
@CacheConfig
(
cacheNames
=
"user"
)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
@Transactional
(
propagation
=
Propagation
.
SUPPORTS
,
readOnly
=
true
,
rollbackFor
=
Exception
.
class
)
public
class
UserServiceImpl
implements
UserService
{
public
class
UserServiceImpl
implements
UserService
{
@Autowired
private
final
UserRepository
userRepository
;
private
UserRepository
userRepository
;
@Autowired
private
final
UserMapper
userMapper
;
private
UserMapper
userMapper
;
@Autowired
private
final
RedisService
redisService
;
private
RedisService
redisService
;
@Autowired
private
final
UserAvatarRepository
userAvatarRepository
;
private
UserAvatarRepository
userAvatarRepository
;
@Value
(
"${file.avatar}"
)
@Value
(
"${file.avatar}"
)
private
String
avatar
;
private
String
avatar
;
public
UserServiceImpl
(
UserRepository
userRepository
,
UserMapper
userMapper
,
RedisService
redisService
,
UserAvatarRepository
userAvatarRepository
)
{
this
.
userRepository
=
userRepository
;
this
.
userMapper
=
userMapper
;
this
.
redisService
=
redisService
;
this
.
userAvatarRepository
=
userAvatarRepository
;
}
@Override
@Override
@Cacheable
public
Object
queryAll
(
UserQueryCriteria
criteria
,
Pageable
pageable
)
{
public
Object
queryAll
(
UserQueryCriteria
criteria
,
Pageable
pageable
)
{
Page
<
User
>
page
=
userRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
),
pageable
);
Page
<
User
>
page
=
userRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
),
pageable
);
return
PageUtil
.
toPage
(
page
.
map
(
userMapper:
:
toDto
));
return
PageUtil
.
toPage
(
page
.
map
(
userMapper:
:
toDto
));
}
}
@Override
@Override
@Cacheable
public
List
<
UserDTO
>
queryAll
(
UserQueryCriteria
criteria
)
{
public
List
<
UserDTO
>
queryAll
(
UserQueryCriteria
criteria
)
{
List
<
User
>
users
=
userRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
));
List
<
User
>
users
=
userRepository
.
findAll
((
root
,
criteriaQuery
,
criteriaBuilder
)
->
QueryHelp
.
getPredicate
(
root
,
criteria
,
criteriaBuilder
));
return
userMapper
.
toDto
(
users
);
return
userMapper
.
toDto
(
users
);
}
}
@Override
@Override
@Cacheable
(
key
=
"#p0"
)
public
UserDTO
findById
(
long
id
)
{
public
UserDTO
findById
(
long
id
)
{
Optional
<
User
>
user
=
userRepository
.
findById
(
id
);
User
user
=
userRepository
.
findById
(
id
)
.
orElseGet
(
User:
:
new
)
;
ValidationUtil
.
isNull
(
user
,
"User"
,
"id"
,
id
);
ValidationUtil
.
isNull
(
user
.
getId
()
,
"User"
,
"id"
,
id
);
return
userMapper
.
toDto
(
user
.
get
()
);
return
userMapper
.
toDto
(
user
);
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
UserDTO
create
(
User
resources
)
{
public
UserDTO
create
(
User
resources
)
{
...
@@ -92,13 +97,11 @@ public class UserServiceImpl implements UserService {
...
@@ -92,13 +97,11 @@ public class UserServiceImpl implements UserService {
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
@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
());
User
user
=
userRepository
.
findById
(
resources
.
getId
()).
orElseGet
(
User:
:
new
);
ValidationUtil
.
isNull
(
userOptional
,
"User"
,
"id"
,
resources
.
getId
());
ValidationUtil
.
isNull
(
user
.
getId
(),
"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
());
...
@@ -129,14 +132,16 @@ public class UserServiceImpl implements UserService {
...
@@ -129,14 +132,16 @@ public class UserServiceImpl implements UserService {
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
delete
(
Long
id
)
{
public
void
delete
(
Long
id
)
{
userRepository
.
deleteById
(
id
);
userRepository
.
deleteById
(
id
);
}
}
@Override
@Override
@Cacheable
(
key
=
"'loadUserByUsername:'+#p0"
)
public
UserDTO
findByName
(
String
userName
)
{
public
UserDTO
findByName
(
String
userName
)
{
User
user
=
null
;
User
user
;
if
(
ValidationUtil
.
isEmail
(
userName
)){
if
(
ValidationUtil
.
isEmail
(
userName
)){
user
=
userRepository
.
findByEmail
(
userName
);
user
=
userRepository
.
findByEmail
(
userName
);
}
else
{
}
else
{
...
@@ -150,12 +155,14 @@ public class UserServiceImpl implements UserService {
...
@@ -150,12 +155,14 @@ public class UserServiceImpl implements UserService {
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
updatePass
(
String
username
,
String
pass
)
{
public
void
updatePass
(
String
username
,
String
pass
)
{
userRepository
.
updatePass
(
username
,
pass
,
new
Date
());
userRepository
.
updatePass
(
username
,
pass
,
new
Date
());
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
updateAvatar
(
MultipartFile
multipartFile
)
{
public
void
updateAvatar
(
MultipartFile
multipartFile
)
{
User
user
=
userRepository
.
findByUsername
(
SecurityUtils
.
getUsername
());
User
user
=
userRepository
.
findByUsername
(
SecurityUtils
.
getUsername
());
...
@@ -165,6 +172,7 @@ public class UserServiceImpl implements UserService {
...
@@ -165,6 +172,7 @@ public class UserServiceImpl implements UserService {
oldPath
=
userAvatar
.
getPath
();
oldPath
=
userAvatar
.
getPath
();
}
}
File
file
=
FileUtil
.
upload
(
multipartFile
,
avatar
);
File
file
=
FileUtil
.
upload
(
multipartFile
,
avatar
);
assert
file
!=
null
;
userAvatar
=
userAvatarRepository
.
save
(
new
UserAvatar
(
userAvatar
,
file
.
getName
(),
file
.
getPath
(),
FileUtil
.
getSize
(
multipartFile
.
getSize
())));
userAvatar
=
userAvatarRepository
.
save
(
new
UserAvatar
(
userAvatar
,
file
.
getName
(),
file
.
getPath
(),
FileUtil
.
getSize
(
multipartFile
.
getSize
())));
user
.
setUserAvatar
(
userAvatar
);
user
.
setUserAvatar
(
userAvatar
);
userRepository
.
save
(
user
);
userRepository
.
save
(
user
);
...
@@ -174,6 +182,7 @@ public class UserServiceImpl implements UserService {
...
@@ -174,6 +182,7 @@ public class UserServiceImpl implements UserService {
}
}
@Override
@Override
@CacheEvict
(
allEntries
=
true
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
updateEmail
(
String
username
,
String
email
)
{
public
void
updateEmail
(
String
username
,
String
email
)
{
userRepository
.
updateEmail
(
username
,
email
);
userRepository
.
updateEmail
(
username
,
email
);
...
@@ -184,7 +193,7 @@ public class UserServiceImpl implements UserService {
...
@@ -184,7 +193,7 @@ public class UserServiceImpl implements UserService {
List
<
Map
<
String
,
Object
>>
list
=
new
ArrayList
<>();
List
<
Map
<
String
,
Object
>>
list
=
new
ArrayList
<>();
for
(
UserDTO
userDTO
:
queryAll
)
{
for
(
UserDTO
userDTO
:
queryAll
)
{
List
roles
=
userDTO
.
getRoles
().
stream
().
map
(
RoleSmallDTO:
:
getName
).
collect
(
Collectors
.
toList
());
List
roles
=
userDTO
.
getRoles
().
stream
().
map
(
RoleSmallDTO:
:
getName
).
collect
(
Collectors
.
toList
());
Map
map
=
new
LinkedHashMap
();
Map
<
String
,
Object
>
map
=
new
LinkedHashMap
<>
();
map
.
put
(
"用户名"
,
userDTO
.
getUsername
());
map
.
put
(
"用户名"
,
userDTO
.
getUsername
());
map
.
put
(
"头像"
,
userDTO
.
getAvatar
());
map
.
put
(
"头像"
,
userDTO
.
getAvatar
());
map
.
put
(
"邮箱"
,
userDTO
.
getEmail
());
map
.
put
(
"邮箱"
,
userDTO
.
getEmail
());
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/service/mapper/DeptMapper.java
View file @
bf7c1eeb
...
@@ -10,7 +10,7 @@ import org.mapstruct.ReportingPolicy;
...
@@ -10,7 +10,7 @@ import org.mapstruct.ReportingPolicy;
* @author Zheng Jie
* @author Zheng Jie
* @date 2019-03-25
* @date 2019-03-25
*/
*/
@Mapper
(
componentModel
=
"spring"
,
uses
=
{},
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
@Mapper
(
componentModel
=
"spring"
,
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
public
interface
DeptMapper
extends
EntityMapper
<
DeptDTO
,
Dept
>
{
public
interface
DeptMapper
extends
EntityMapper
<
DeptDTO
,
Dept
>
{
}
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/modules/system/service/mapper/DeptSmallMapper.java
View file @
bf7c1eeb
...
@@ -10,7 +10,7 @@ import org.mapstruct.ReportingPolicy;
...
@@ -10,7 +10,7 @@ import org.mapstruct.ReportingPolicy;
* @author Zheng Jie
* @author Zheng Jie
* @date 2019-03-25
* @date 2019-03-25
*/
*/
@Mapper
(
componentModel
=
"spring"
,
uses
=
{},
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
@Mapper
(
componentModel
=
"spring"
,
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
public
interface
DeptSmallMapper
extends
EntityMapper
<
DeptSmallDTO
,
Dept
>
{
public
interface
DeptSmallMapper
extends
EntityMapper
<
DeptSmallDTO
,
Dept
>
{
}
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/modules/system/service/mapper/DictDetailMapper.java
View file @
bf7c1eeb
...
@@ -10,7 +10,7 @@ import org.mapstruct.ReportingPolicy;
...
@@ -10,7 +10,7 @@ import org.mapstruct.ReportingPolicy;
* @author Zheng Jie
* @author Zheng Jie
* @date 2019-04-10
* @date 2019-04-10
*/
*/
@Mapper
(
componentModel
=
"spring"
,
uses
=
{},
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
@Mapper
(
componentModel
=
"spring"
,
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
public
interface
DictDetailMapper
extends
EntityMapper
<
DictDetailDTO
,
DictDetail
>
{
public
interface
DictDetailMapper
extends
EntityMapper
<
DictDetailDTO
,
DictDetail
>
{
}
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/modules/system/service/mapper/DictMapper.java
View file @
bf7c1eeb
...
@@ -10,7 +10,7 @@ import org.mapstruct.ReportingPolicy;
...
@@ -10,7 +10,7 @@ import org.mapstruct.ReportingPolicy;
* @author Zheng Jie
* @author Zheng Jie
* @date 2019-04-10
* @date 2019-04-10
*/
*/
@Mapper
(
componentModel
=
"spring"
,
uses
=
{},
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
@Mapper
(
componentModel
=
"spring"
,
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
public
interface
DictMapper
extends
EntityMapper
<
DictDTO
,
Dict
>
{
public
interface
DictMapper
extends
EntityMapper
<
DictDTO
,
Dict
>
{
}
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/modules/system/service/mapper/JobSmallMapper.java
View file @
bf7c1eeb
...
@@ -10,7 +10,7 @@ import org.mapstruct.ReportingPolicy;
...
@@ -10,7 +10,7 @@ import org.mapstruct.ReportingPolicy;
* @author Zheng Jie
* @author Zheng Jie
* @date 2019-03-29
* @date 2019-03-29
*/
*/
@Mapper
(
componentModel
=
"spring"
,
uses
=
{},
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
@Mapper
(
componentModel
=
"spring"
,
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
public
interface
JobSmallMapper
extends
EntityMapper
<
JobSmallDTO
,
Job
>
{
public
interface
JobSmallMapper
extends
EntityMapper
<
JobSmallDTO
,
Job
>
{
}
}
\ No newline at end of file
eladmin-system/src/main/java/me/zhengjie/modules/system/service/mapper/MenuMapper.java
View file @
bf7c1eeb
...
@@ -10,7 +10,7 @@ import org.mapstruct.ReportingPolicy;
...
@@ -10,7 +10,7 @@ import org.mapstruct.ReportingPolicy;
* @author Zheng Jie
* @author Zheng Jie
* @date 2018-12-17
* @date 2018-12-17
*/
*/
@Mapper
(
componentModel
=
"spring"
,
uses
=
{},
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
@Mapper
(
componentModel
=
"spring"
,
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
public
interface
MenuMapper
extends
EntityMapper
<
MenuDTO
,
Menu
>
{
public
interface
MenuMapper
extends
EntityMapper
<
MenuDTO
,
Menu
>
{
}
}
eladmin-system/src/main/java/me/zhengjie/modules/system/service/mapper/RoleSmallMapper.java
View file @
bf7c1eeb
...
@@ -11,7 +11,7 @@ import org.mapstruct.ReportingPolicy;
...
@@ -11,7 +11,7 @@ import org.mapstruct.ReportingPolicy;
* @author Zheng Jie
* @author Zheng Jie
* @date 2019-5-23
* @date 2019-5-23
*/
*/
@Mapper
(
componentModel
=
"spring"
,
uses
=
{},
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
@Mapper
(
componentModel
=
"spring"
,
unmappedTargetPolicy
=
ReportingPolicy
.
IGNORE
)
public
interface
RoleSmallMapper
extends
EntityMapper
<
RoleSmallDTO
,
Role
>
{
public
interface
RoleSmallMapper
extends
EntityMapper
<
RoleSmallDTO
,
Role
>
{
}
}
eladmin-system/src/main/resources/config/application-dev.yml
View file @
bf7c1eeb
...
@@ -47,11 +47,6 @@ jwt:
...
@@ -47,11 +47,6 @@ jwt:
secret
:
mySecret
secret
:
mySecret
# token 过期时间 6个小时
# token 过期时间 6个小时
expiration
:
21000000
expiration
:
21000000
auth
:
# 授权路径
path
:
/login
# 获取用户信息
account
:
/info
#是否允许生成代码,生产环境设置为false
#是否允许生成代码,生产环境设置为false
generator
:
generator
:
...
...
eladmin-system/src/main/resources/config/application-prod.yml
View file @
bf7c1eeb
...
@@ -49,11 +49,6 @@ jwt:
...
@@ -49,11 +49,6 @@ jwt:
secret
:
mySecret
secret
:
mySecret
# token 过期时间 2个小时
# token 过期时间 2个小时
expiration
:
7200000
expiration
:
7200000
auth
:
# 授权路径
path
:
/login
# 获取用户信息
account
:
/info
#是否允许生成代码,生产环境设置为false
#是否允许生成代码,生产环境设置为false
generator
:
generator
:
...
...
eladmin-system/src/main/resources/template/generator/admin/Controller.ftl
View file @
bf7c1eeb
...
@@ -4,7 +4,6 @@ import me.zhengjie.aop.log.Log;
...
@@ -4,7 +4,6 @@ import me.zhengjie.aop.log.Log;
import
$
{
package
}
.domain.$
{
className
}
;
import
$
{
package
}
.domain.$
{
className
}
;
import
$
{
package
}
.service.$
{
className
}
Service;
import
$
{
package
}
.service.$
{
className
}
Service;
import
$
{
package
}
.service.dto.$
{
className
}
QueryCriteria;
import
$
{
package
}
.service.dto.$
{
className
}
QueryCriteria;
import
org.springframework.beans.factory.annotation.Autowired;
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;
...
@@ -19,40 +18,43 @@ import io.swagger.annotations.*;
...
@@ -19,40 +18,43 @@ import io.swagger.annotations.*;
*/
*/
@
Api
(
tags
=
"$
{
className
}
管理")
@
Api
(
tags
=
"$
{
className
}
管理")
@
RestController
@
RestController
@
RequestMapping
("
api
")
@
RequestMapping
("
/
api
/${
changeClassName
}
")
public
class $
{
className
}
Controller
{
public
class $
{
className
}
Controller
{
@
A
utowired
private
final
$
{
className
}
S
ervice
$
{
changeClassName
}
S
ervice
;
private
$
{
className
}
S
ervice
$
{
changeClassName
}
S
ervice
;
public
$
{
className
}
C
ontroller
(
$
{
className
}
S
ervice
$
{
changeClassName
}
S
ervice
)
{
this
.$
{
changeClassName
}
S
ervice
=
$
{
changeClassName
}
S
ervice
;
}
@
G
etMapping
@
L
og
(
"查询${className}"
)
@
L
og
(
"查询${className}"
)
@
A
piOperation
(
value
=
"查询${className}"
)
@
A
piOperation
(
"查询${className}"
)
@
G
etMapping
(
value
=
"/${changeClassName}"
)
@
P
reAuthorize
(
"hasAnyRole('ADMIN','${upperCaseClassName}_ALL','${upperCaseClassName}_SELECT')"
)
@
P
reAuthorize
(
"hasAnyRole('ADMIN','${upperCaseClassName}_ALL','${upperCaseClassName}_SELECT')"
)
public
R
esponseEntity
get
$
{
className
}
s
(
$
{
className
}
Q
ueryCriteria
criteria
,
P
ageable
pageable
){
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
)
;
return
new
R
esponseEntity
<>
(
$
{
changeClassName
}
S
ervice
.queryAll
(
criteria
,
pageable
),
H
ttpStatus
.OK
)
;
}
}
@
P
ostMapping
@
L
og
(
"新增${className}"
)
@
L
og
(
"新增${className}"
)
@
A
piOperation
(
value
=
"新增${className}"
)
@
A
piOperation
(
"新增${className}"
)
@
P
ostMapping
(
value
=
"/${changeClassName}"
)
@
P
reAuthorize
(
"hasAnyRole('ADMIN','${upperCaseClassName}_ALL','${upperCaseClassName}_CREATE')"
)
@
P
reAuthorize
(
"hasAnyRole('ADMIN','${upperCaseClassName}_ALL','${upperCaseClassName}_CREATE')"
)
public
R
esponseEntity
create
(
@
V
alidated
@
R
equestBody
$
{
className
}
resources
){
public
R
esponseEntity
create
(
@
V
alidated
@
R
equestBody
$
{
className
}
resources
){
return
new
R
esponseEntity
(
$
{
changeClassName
}
S
ervice
.create
(
resources
),
H
ttpStatus
.CREATED
)
;
return
new
R
esponseEntity
<>
(
$
{
changeClassName
}
S
ervice
.create
(
resources
),
H
ttpStatus
.CREATED
)
;
}
}
@
P
utMapping
@
L
og
(
"修改${className}"
)
@
L
og
(
"修改${className}"
)
@
A
piOperation
(
value
=
"修改${className}"
)
@
A
piOperation
(
"修改${className}"
)
@
P
utMapping
(
value
=
"/${changeClassName}"
)
@
P
reAuthorize
(
"hasAnyRole('ADMIN','${upperCaseClassName}_ALL','${upperCaseClassName}_EDIT')"
)
@
P
reAuthorize
(
"hasAnyRole('ADMIN','${upperCaseClassName}_ALL','${upperCaseClassName}_EDIT')"
)
public
R
esponseEntity
update
(
@
V
alidated
@
R
equestBody
$
{
className
}
resources
){
public
R
esponseEntity
update
(
@
V
alidated
@
R
equestBody
$
{
className
}
resources
){
$
{
changeClassName
}
S
ervice
.update
(
resources
)
;
$
{
changeClassName
}
S
ervice
.update
(
resources
)
;
return
new
R
esponseEntity
(
H
ttpStatus
.NO_CONTENT
)
;
return
new
R
esponseEntity
(
H
ttpStatus
.NO_CONTENT
)
;
}
}
@
D
eleteMapping
(
value
=
"/{${pkChangeColName}}"
)
@
L
og
(
"删除${className}"
)
@
L
og
(
"删除${className}"
)
@
A
piOperation
(
value
=
"删除${className}"
)
@
A
piOperation
(
"删除${className}"
)
@
D
eleteMapping
(
value
=
"/${changeClassName}/{${pkChangeColName}}"
)
@
P
reAuthorize
(
"hasAnyRole('ADMIN','${upperCaseClassName}_ALL','${upperCaseClassName}_DELETE')"
)
@
P
reAuthorize
(
"hasAnyRole('ADMIN','${upperCaseClassName}_ALL','${upperCaseClassName}_DELETE')"
)
public
R
esponseEntity
delete
(
@
P
athVariable
$
{
pkColumnType
}
$
{
pkChangeColName
}){
public
R
esponseEntity
delete
(
@
P
athVariable
$
{
pkColumnType
}
$
{
pkChangeColName
}){
$
{
changeClassName
}
S
ervice
.delete
(
$
{
pkChangeColName
})
;
$
{
changeClassName
}
S
ervice
.delete
(
$
{
pkChangeColName
})
;
...
...
eladmin-system/src/main/resources/template/generator/admin/Mapper.ftl
View file @
bf7c1eeb
...
@@ -10,7 +10,7 @@ import org.mapstruct.ReportingPolicy;
...
@@ -10,7 +10,7 @@ import org.mapstruct.ReportingPolicy;
*
@author $
{
author
}
*
@author $
{
author
}
*
@date $
{
date
}
*
@date $
{
date
}
*/
*/
@
Mapper
(
componentModel
=
"spring",
uses =
{}
,
unmappedTargetPolicy = ReportingPolicy.IGNORE)
@
Mapper
(
componentModel
=
"spring",
unmappedTargetPolicy = ReportingPolicy.IGNORE)
public
interface $
{
className
}
Mapper extends EntityMapper<$
{
className
}
DTO, $
{
className
}
>
{
public
interface $
{
className
}
Mapper extends EntityMapper<$
{
className
}
DTO, $
{
className
}
>
{
}
}
\ No newline at end of file
eladmin-system/src/main/resources/template/generator/admin/QueryCriteria.ftl
View file @
bf7c1eeb
package
$
{
package
}
.service.dto;
package
$
{
package
}
.service.dto;
import
lombok.Data;
import
lombok.Data;
<#
if
h
asTimestamp>
<#
if
queryH
asTimestamp>
import
java.sql.Timestamp;
import
java.sql.Timestamp;
</#
if
>
</#
if
>
<#
if
h
asBigDecimal>
<#
if
queryH
asBigDecimal>
import
java.math.BigDecimal;
import
java.math.BigDecimal;
</#
if
>
</#
if
>
<#
if
queryColumns??>
<#
if
queryColumns??>
...
...
Prev
1
2
3
4
5
6
7
8
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