Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xyqb-user2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
head_group
xyqb-user2
Commits
4a518ace
Commit
4a518ace
authored
Nov 14, 2017
by
技术部-任文超
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
重新优化,重定义缓存Key(读、写时更新缓存)
parent
382d8437
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
18 deletions
+20
-18
ContactServiceImpl.java
...quantgroup/xyqb/service/user/impl/ContactServiceImpl.java
+20
-18
No files found.
src/main/java/cn/quantgroup/xyqb/service/user/impl/ContactServiceImpl.java
View file @
4a518ace
...
@@ -7,16 +7,19 @@ import cn.quantgroup.xyqb.repository.IContactRepository;
...
@@ -7,16 +7,19 @@ import cn.quantgroup.xyqb.repository.IContactRepository;
import
cn.quantgroup.xyqb.service.user.IContactService
;
import
cn.quantgroup.xyqb.service.user.IContactService
;
import
cn.quantgroup.xyqb.util.ValidationUtil
;
import
cn.quantgroup.xyqb.util.ValidationUtil
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.tomcat.util.bcel.classfile.Constant
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.CacheEvict
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.cache.annotation.Caching
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.CollectionUtils
;
import
java.sql.Timestamp
;
import
java.sql.Timestamp
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -29,35 +32,30 @@ public class ContactServiceImpl implements IContactService {
...
@@ -29,35 +32,30 @@ public class ContactServiceImpl implements IContactService {
private
IContactRepository
contactRepository
;
private
IContactRepository
contactRepository
;
@Override
@Override
@Cacheable
(
value
=
"contact"
,
key
=
"'contact:' + #trim + #userId"
,
unless
=
"#result == null or #result.size() == 0"
,
cacheManager
=
"cacheManager"
)
public
List
<
Contact
>
findByUserId
(
Long
userId
,
boolean
trim
)
{
public
List
<
Contact
>
findByUserId
(
Long
userId
,
boolean
trim
)
{
List
<
Contact
>
contacts
=
findByUserId
(
userId
);
List
<
Contact
>
contacts
=
contactRepository
.
findByUserId
(
userId
);
if
(
trim
){
if
(
trim
){
return
trim
(
contacts
);
trim
(
contacts
);
}
}
return
contacts
;
return
contacts
;
}
}
@Cacheable
(
value
=
"contact"
,
key
=
"'contact' + #userId"
,
unless
=
"#result == null or #result.size() == 0"
,
cacheManager
=
"cacheManager"
)
public
List
<
Contact
>
findByUserId
(
Long
userId
)
{
return
contactRepository
.
findByUserId
(
userId
);
}
/**
/**
*
清除
非法联系人记录
*
过滤掉
非法联系人记录
* @param contacts - 包含待清除记录的联系人列表
* @param contacts - 包含待清除记录的联系人列表
* @return 只包含合法联系人记录的列表
*/
*/
private
List
<
Contact
>
trim
(
List
<
Contact
>
contacts
){
private
void
trim
(
List
<
Contact
>
contacts
){
if
(
CollectionUtils
.
isEmpty
(
contacts
)){
if
(
CollectionUtils
.
isEmpty
(
contacts
)){
return
Collections
.
emptyList
()
;
return
;
}
}
List
<
Contact
>
trimList
=
new
ArrayList
<
Contact
>(
contacts
.
size
());
Iterator
<
Contact
>
iterator
=
contacts
.
iterator
();
for
(
Contact
contact
:
contacts
){
while
(
iterator
.
hasNext
()){
if
(
contact
.
valid
())
{
Contact
contact
=
iterator
.
next
();
trimList
.
add
(
contact
);
if
(!
contact
.
valid
())
{
iterator
.
remove
();
}
}
}
}
return
trimList
;
}
}
@Override
@Override
...
@@ -66,7 +64,9 @@ public class ContactServiceImpl implements IContactService {
...
@@ -66,7 +64,9 @@ public class ContactServiceImpl implements IContactService {
}
}
@Override
@Override
@CacheEvict
(
value
=
"contact"
,
key
=
"'contact' + #userId"
,
cacheManager
=
"cacheManager"
)
@Caching
(
evict
=
{
@CacheEvict
(
value
=
"contact"
,
key
=
"'contact:true' + #userId"
,
cacheManager
=
"cacheManager"
),
@CacheEvict
(
value
=
"contact"
,
key
=
"'contact:false' + #userId"
,
cacheManager
=
"cacheManager"
)})
public
List
<
Contact
>
save
(
Long
userId
,
List
<
Contact
>
contacts
)
{
public
List
<
Contact
>
save
(
Long
userId
,
List
<
Contact
>
contacts
)
{
if
(
userId
==
null
){
if
(
userId
==
null
){
return
null
;
return
null
;
...
@@ -77,7 +77,9 @@ public class ContactServiceImpl implements IContactService {
...
@@ -77,7 +77,9 @@ public class ContactServiceImpl implements IContactService {
}
}
@Override
@Override
@CacheEvict
(
value
=
"contact"
,
key
=
"'contact' + #contact.userId"
,
cacheManager
=
"cacheManager"
)
@Caching
(
evict
=
{
@CacheEvict
(
value
=
"contact"
,
key
=
"'contact:true' + #contact.userId"
,
cacheManager
=
"cacheManager"
),
@CacheEvict
(
value
=
"contact"
,
key
=
"'contact:false' + #contact.userId"
,
cacheManager
=
"cacheManager"
)})
public
Contact
save
(
Contact
contact
)
{
public
Contact
save
(
Contact
contact
)
{
return
contactRepository
.
save
(
contact
);
return
contactRepository
.
save
(
contact
);
}
}
...
...
Write
Preview
Markdown
is supported
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