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
8a813e40
Commit
8a813e40
authored
Nov 02, 2017
by
Java—红包—徐 然
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改代码
parent
61478609
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
151 additions
and
155 deletions
+151
-155
SessionServiceImpl.java
...ntgroup/xyqb/service/session/impl/SessionServiceImpl.java
+151
-155
No files found.
src/main/java/cn/quantgroup/xyqb/service/session/impl/SessionServiceImpl.java
View file @
8a813e40
...
@@ -18,9 +18,11 @@ import org.apache.commons.lang3.StringUtils;
...
@@ -18,9 +18,11 @@ import org.apache.commons.lang3.StringUtils;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.SetOperations
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.CollectionUtils
;
import
javax.persistence.Cacheable
;
import
java.sql.Timestamp
;
import
java.sql.Timestamp
;
import
java.util.*
;
import
java.util.*
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
...
@@ -41,7 +43,7 @@ public class SessionServiceImpl implements ISessionService {
...
@@ -41,7 +43,7 @@ public class SessionServiceImpl implements ISessionService {
AuthBean
authBean
=
new
AuthBean
();
AuthBean
authBean
=
new
AuthBean
();
LoginProperties
properties
=
new
LoginProperties
();
LoginProperties
properties
=
new
LoginProperties
();
properties
.
setAppChannel
(
appChannel
);
properties
.
setAppChannel
(
appChannel
);
if
(
null
!=
merchant
)
{
if
(
null
!=
merchant
)
{
properties
.
setMerchantName
(
merchant
.
getName
());
properties
.
setMerchantName
(
merchant
.
getName
());
}
}
properties
.
setChannelId
(
channelId
);
properties
.
setChannelId
(
channelId
);
...
@@ -133,27 +135,29 @@ public class SessionServiceImpl implements ISessionService {
...
@@ -133,27 +135,29 @@ public class SessionServiceImpl implements ISessionService {
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
);
setUserIdTokenKeys
(
sessionValue
.
getUser
().
getId
()
,
key
);
}
}
/**
/**
* 设置用户token集合方便注销使用
* 设置用户token集合方便注销使用
* @param sessionValue
*
* @param userId
* @param key
* @param key
*/
*/
private
void
setUserIdTokenKeys
(
SessionValue
sessionValue
,
String
key
)
{
private
void
setUserIdTokenKeys
(
long
userId
,
String
key
)
{
String
useIdKeys
=
stringRedisTemplate
.
opsForValue
().
get
(
Constants
.
Session
.
USER_SESSION_KEY_SET
+
sessionValue
.
getUser
().
getId
());
if
(
0L
!=
userId
)
{
Set
useIdKeySet
=
null
;
try
{
if
(
StringUtils
.
isNotEmpty
(
useIdKeys
))
{
stringRedisTemplate
.
opsForSet
().
add
(
Constants
.
Session
.
USER_SESSION_KEY_SET
+
userId
,
key
);
useIdKeySet
=
JSON
.
parseObject
(
useIdKeys
,
Set
.
class
);
stringRedisTemplate
.
expire
(
Constants
.
Session
.
USER_SESSION_KEY_SET
+
userId
,
Constants
.
Session
.
ONE_DAY
,
TimeUnit
.
SECONDS
);
}
else
{
}
catch
(
Exception
e
)
{
useIdKeySet
=
new
HashSet
();
log
.
error
(
"存储用户注销件失败,userId:{},Exception:{}"
,
userId
,
e
);
}
}
}
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
public
SessionStruct
findSessionBySessionId
(
String
sessionId
)
{
public
SessionStruct
findSessionBySessionId
(
String
sessionId
)
{
String
sessionValue
=
findSessionValueBySessionId
(
sessionId
);
String
sessionValue
=
findSessionValueBySessionId
(
sessionId
);
...
@@ -177,18 +181,10 @@ public class SessionServiceImpl implements ISessionService {
...
@@ -177,18 +181,10 @@ 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) + ":*";
// Set<String> keys = stringRedisTemplate.keys(pattern);
Set
useIdKeys
=
stringRedisTemplate
.
opsForSet
().
members
(
Constants
.
Session
.
USER_SESSION_KEY_SET
+
userId
);
// if (!CollectionUtils.isEmpty(keys)) {
if
(!
CollectionUtils
.
isEmpty
(
useIdKeys
))
{
// log.info("删除用户userId={}的缓存信息,个数:{},keys={}", userId,
useIdKeys
.
forEach
(
key
->
{
// keys.size(),
// Joiner.on(",").join(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
));
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