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
61478609
Commit
61478609
authored
Nov 02, 2017
by
Java—红包—徐 然
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改注销逻辑
parent
3e3e5d54
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
12 deletions
+40
-12
Constants.java
src/main/java/cn/quantgroup/xyqb/Constants.java
+1
-0
SessionServiceImpl.java
...ntgroup/xyqb/service/session/impl/SessionServiceImpl.java
+39
-12
No files found.
src/main/java/cn/quantgroup/xyqb/Constants.java
View file @
61478609
...
@@ -60,6 +60,7 @@ public interface Constants {
...
@@ -60,6 +60,7 @@ public interface Constants {
interface
Session
{
interface
Session
{
String
USER_SESSION_CACHE
=
"user:session:"
;
String
USER_SESSION_CACHE
=
"user:session:"
;
String
USER_SESSION_ID_CACHE
=
"userid-sessionvalue:cache:"
;
String
USER_SESSION_ID_CACHE
=
"userid-sessionvalue:cache:"
;
String
USER_SESSION_KEY_SET
=
"userid-keys:set:"
;
Long
ONE_DAY
=
24
*
60
*
60L
;
Long
ONE_DAY
=
24
*
60
*
60L
;
}
}
...
...
src/main/java/cn/quantgroup/xyqb/service/session/impl/SessionServiceImpl.java
View file @
61478609
...
@@ -10,7 +10,9 @@ import cn.quantgroup.xyqb.model.session.SessionValue;
...
@@ -10,7 +10,9 @@ import cn.quantgroup.xyqb.model.session.SessionValue;
import
cn.quantgroup.xyqb.service.session.ISessionService
;
import
cn.quantgroup.xyqb.service.session.ISessionService
;
import
cn.quantgroup.xyqb.service.session.aspect.UserBtRegisterFill
;
import
cn.quantgroup.xyqb.service.session.aspect.UserBtRegisterFill
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.common.base.Joiner
;
import
com.google.common.base.Joiner
;
import
jdk.nashorn.internal.parser.JSONParser
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -20,10 +22,7 @@ import org.springframework.stereotype.Service;
...
@@ -20,10 +22,7 @@ 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.HashMap
;
import
java.util.*
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.UUID
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
/**
/**
...
@@ -133,6 +132,26 @@ public class SessionServiceImpl implements ISessionService {
...
@@ -133,6 +132,26 @@ public class SessionServiceImpl implements ISessionService {
Constants
.
Session
.
ONE_DAY
,
TimeUnit
.
SECONDS
);
Constants
.
Session
.
ONE_DAY
,
TimeUnit
.
SECONDS
);
String
key
=
generateLoginPropertiesKey
(
sessionValue
.
getUser
().
getId
(),
sessionValue
.
getLoginProperties
());
String
key
=
generateLoginPropertiesKey
(
sessionValue
.
getUser
().
getId
(),
sessionValue
.
getLoginProperties
());
stringRedisTemplate
.
opsForValue
().
set
(
key
,
token
,
Constants
.
Session
.
ONE_DAY
,
TimeUnit
.
SECONDS
);
stringRedisTemplate
.
opsForValue
().
set
(
key
,
token
,
Constants
.
Session
.
ONE_DAY
,
TimeUnit
.
SECONDS
);
setUserIdTokenKeys
(
sessionValue
,
key
);
}
/**
* 设置用户token集合方便注销使用
* @param sessionValue
* @param key
*/
private
void
setUserIdTokenKeys
(
SessionValue
sessionValue
,
String
key
)
{
String
useIdKeys
=
stringRedisTemplate
.
opsForValue
().
get
(
Constants
.
Session
.
USER_SESSION_KEY_SET
+
sessionValue
.
getUser
().
getId
());
Set
useIdKeySet
=
null
;
if
(
StringUtils
.
isNotEmpty
(
useIdKeys
))
{
useIdKeySet
=
JSON
.
parseObject
(
useIdKeys
,
Set
.
class
);
}
else
{
useIdKeySet
=
new
HashSet
();
}
useIdKeySet
.
add
(
key
);
stringRedisTemplate
.
opsForValue
().
set
(
Constants
.
Session
.
USER_SESSION_KEY_SET
+
sessionValue
.
getUser
().
getId
(),
JSONObject
.
toJSONString
(
useIdKeySet
),
Constants
.
Session
.
ONE_DAY
,
TimeUnit
.
SECONDS
);
}
}
@Override
@Override
...
@@ -158,13 +177,21 @@ public class SessionServiceImpl implements ISessionService {
...
@@ -158,13 +177,21 @@ public class SessionServiceImpl implements ISessionService {
@Override
@Override
public
void
deleteByUserId
(
long
userId
)
{
public
void
deleteByUserId
(
long
userId
)
{
String
pattern
=
Constants
.
Session
.
USER_SESSION_ID_CACHE
+
":"
+
String
.
valueOf
(
userId
)
+
":*"
;
// String pattern = Constants.Session.USER_SESSION_ID_CACHE + ":" + String.valueOf(userId) + ":*";
Set
<
String
>
keys
=
stringRedisTemplate
.
keys
(
pattern
);
// Set<String> keys = stringRedisTemplate.keys(pattern);
if
(!
CollectionUtils
.
isEmpty
(
keys
))
{
// if (!CollectionUtils.isEmpty(keys)) {
log
.
info
(
"删除用户userId={}的缓存信息,个数:{},keys={}"
,
userId
,
// log.info("删除用户userId={}的缓存信息,个数:{},keys={}", userId,
keys
.
size
(),
// keys.size(),
Joiner
.
on
(
","
).
join
(
keys
));
// Joiner.on(",").join(keys));
}
// }
stringRedisTemplate
.
delete
(
keys
);
String
useIdKeys
=
stringRedisTemplate
.
opsForValue
().
get
(
Constants
.
Session
.
USER_SESSION_KEY_SET
+
userId
);
if
(
StringUtils
.
isNotEmpty
(
useIdKeys
))
{
Set
useIdKeySet
=
JSON
.
parseObject
(
useIdKeys
,
Set
.
class
);
useIdKeySet
.
forEach
(
key
->
{
stringRedisTemplate
.
delete
(
String
.
valueOf
(
key
));
});
}
}
}
}
}
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