Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
YZG
yzg-util
Commits
b261830f
Commit
b261830f
authored
Jun 27, 2023
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
表结构修改
parent
12ed2d1a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
41 deletions
+49
-41
TokenHelper.java
...l-db/src/main/java/com/yanzuoguang/token/TokenHelper.java
+49
-41
No files found.
yzg-util-db/src/main/java/com/yanzuoguang/token/TokenHelper.java
View file @
b261830f
...
...
@@ -53,6 +53,36 @@ public class TokenHelper {
return
String
.
valueOf
(
Thread
.
currentThread
().
getId
());
}
/**
* 获取当前的登录信息
*
* @return 缓存的数据
*/
public
static
TokenData
getTokenData
(
boolean
readNewToken
)
{
String
id
=
getCurrentId
();
TokenData
cacheTokenData
=
cache
.
get
(
id
);
if
(
cacheTokenData
==
null
)
{
return
null
;
}
// 获取最新的token
if
(!
readNewToken
)
{
return
cacheTokenData
;
}
boolean
isEmpty
=
cacheTokenData
.
getData
()
==
null
||
cacheTokenData
.
getData
().
isEmpty
();
boolean
isExpire
=
cacheTokenData
.
getExpire
()
<
System
.
currentTimeMillis
();
boolean
isToken
=
!
StringHelper
.
isEmpty
(
cacheTokenData
.
getToken
())
&&
(
isEmpty
||
isExpire
);
if
(
isToken
)
{
TokenData
databaseToken
=
tokenLoad
.
load
(
cacheTokenData
.
getToken
());
if
(
databaseToken
==
null
||
databaseToken
.
getData
()
==
null
)
{
return
null
;
}
else
{
cache
.
put
(
id
,
databaseToken
);
}
}
return
cacheTokenData
;
}
/**
* 获取当前的登录信息
*
...
...
@@ -85,33 +115,13 @@ public class TokenHelper {
* @return 缓存的数据
*/
public
static
<
T
extends
Object
>
T
get
(
boolean
checkFlag
,
Class
<
T
>
cls
,
boolean
readNewToken
)
{
String
id
=
getCurrentId
();
TokenData
tokenData
=
cache
.
get
(
id
);
TokenData
tokenData
=
getTokenData
(
readNewToken
);
if
(
tokenData
==
null
)
{
if
(
checkFlag
)
{
throw
YzgError
.
getRuntimeException
(
"061"
);
}
return
null
;
}
// 获取最新的token
if
(
readNewToken
)
{
boolean
isEmpty
=
tokenData
.
getData
()
==
null
||
tokenData
.
getData
().
isEmpty
();
boolean
isExpire
=
tokenData
.
getExpire
()
<
System
.
currentTimeMillis
();
boolean
isToken
=
!
StringHelper
.
isEmpty
(
tokenData
.
getToken
())
&&
(
isEmpty
||
isExpire
);
if
(
isToken
)
{
tokenData
=
tokenLoad
.
load
(
tokenData
.
getToken
());
if
(
tokenData
!=
null
)
{
cache
.
put
(
id
,
tokenData
);
}
}
if
(
tokenData
==
null
||
tokenData
.
getData
()
==
null
)
{
if
(
checkFlag
)
{
throw
YzgError
.
getRuntimeException
(
"061"
);
}
return
null
;
}
}
if
(
ObjectHelper
.
isSub
(
cls
,
tokenData
.
getData
().
getClass
()))
{
return
(
T
)
tokenData
.
getData
();
}
else
{
...
...
@@ -157,7 +167,17 @@ public class TokenHelper {
* @param data 数据时间
*/
public
static
void
write
(
String
token
,
Object
data
)
{
write
(
token
,
StringHelper
.
EMPTY
,
0
,
data
);
write
(
token
,
StringHelper
.
EMPTY
,
null
,
0
,
data
);
}
/**
* 缓存数据
*
* @param token 标记
* @param data 数据时间
*/
public
static
void
write
(
String
token
,
RsaHelper
.
RsaInfo
rsaInfo
,
Object
data
)
{
write
(
token
,
StringHelper
.
EMPTY
,
rsaInfo
,
0
,
data
);
}
/**
...
...
@@ -168,7 +188,7 @@ public class TokenHelper {
* @param data 数据时间
*/
public
static
void
write
(
String
token
,
long
expire
,
Object
data
)
{
write
(
token
,
StringHelper
.
EMPTY
,
expire
,
data
);
write
(
token
,
StringHelper
.
EMPTY
,
null
,
expire
,
data
);
}
/**
...
...
@@ -180,22 +200,7 @@ public class TokenHelper {
* @param data 数据时间
*/
public
static
void
write
(
String
token
,
String
dataPwd
,
long
expire
,
Object
data
)
{
String
id
=
getCurrentId
();
TokenData
tokenData
=
cache
.
get
(
id
);
if
(
tokenData
==
null
)
{
tokenData
=
new
TokenData
();
cache
.
put
(
id
,
tokenData
);
}
tokenData
.
setToken
(
token
);
tokenData
.
setDataPwd
(
dataPwd
);
if
(
expire
>
0
)
{
tokenData
.
setExpire
(
expire
);
}
if
(
tokenData
.
getData
()
==
null
)
{
tokenData
.
setData
(
new
MapRow
());
}
ObjectHelper
.
writeWithFrom
(
tokenData
.
getData
(),
data
);
tokenData
.
setWrite
(
true
);
write
(
token
,
dataPwd
,
null
,
expire
,
data
);
}
...
...
@@ -217,8 +222,10 @@ public class TokenHelper {
}
tokenData
.
setToken
(
token
);
tokenData
.
setDataPwd
(
dataPwd
);
tokenData
.
setPublicKey
(
rsaInfo
.
getPublicKey
());
tokenData
.
setPrivateKey
(
rsaInfo
.
getPrivateKey
());
if
(
rsaInfo
!=
null
)
{
tokenData
.
setPublicKey
(
rsaInfo
.
getPublicKey
());
tokenData
.
setPrivateKey
(
rsaInfo
.
getPrivateKey
());
}
if
(
expire
>
0
)
{
tokenData
.
setExpire
(
expire
);
}
...
...
@@ -256,6 +263,7 @@ public class TokenHelper {
return
JsonHelper
.
serialize
(
tokenData
);
}
/**
* 删除缓存信息
*/
...
...
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