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
e9e9ac98
Commit
e9e9ac98
authored
Jan 12, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
6c15a836
26ad40c3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
33 deletions
+63
-33
DateHelper.java
...src/main/java/com/yanzuoguang/util/helper/DateHelper.java
+42
-0
WebAspect.java
...ud/src/main/java/com/yanzuoguang/cloud/aop/WebAspect.java
+1
-16
TokenServiceCall.java
.../java/com/yanzuoguang/cloud/service/TokenServiceCall.java
+20
-17
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/DateHelper.java
View file @
e9e9ac98
...
...
@@ -584,6 +584,48 @@ public class DateHelper {
return
cal
.
getTime
();
}
/**
* 增加小时处理
*
* @param date 当前日期
* @param hour 需要增加的小时
* @return 增加之后的值
*/
public
static
Date
addHour
(
Date
date
,
int
hour
)
{
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
date
);
cal
.
add
(
Calendar
.
HOUR
,
hour
);
return
cal
.
getTime
();
}
/**
* 增加分钟处理
*
* @param date 当前日期
* @param minute 需要增加的分钟
* @return 增加之后的值
*/
public
static
Date
addMinute
(
Date
date
,
int
minute
)
{
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
date
);
cal
.
add
(
Calendar
.
MINUTE
,
minute
);
return
cal
.
getTime
();
}
/**
* 增加秒处理
*
* @param date 当前日期
* @param second 需要增加的分钟
* @return 增加之后的值
*/
public
static
Date
addSecond
(
Date
date
,
int
second
)
{
Calendar
cal
=
Calendar
.
getInstance
();
cal
.
setTime
(
date
);
cal
.
add
(
Calendar
.
MINUTE
,
second
);
return
cal
.
getTime
();
}
/**
* 获取当前时间,精准到秒,格式为: yyyy-MM-dd HH:mm:ss
*
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/WebAspect.java
View file @
e9e9ac98
...
...
@@ -68,12 +68,10 @@ public class WebAspect extends BaseRequestAspect {
// 用户数据库记录
long
start
=
requestLog
(
TAG
,
joinPoint
);
Exception
ex
=
null
;
Ref
<
Boolean
>
flag
=
new
Ref
<>(
false
);
boolean
isInit
=
false
;
try
{
isInit
=
tokenServiceCall
.
tokenInit
();
result
=
executeMethod
(
joinPoint
);
tokenFinish
(
flag
);
return
result
;
}
catch
(
Exception
e
)
{
ex
=
e
;
...
...
@@ -84,8 +82,8 @@ public class WebAspect extends BaseRequestAspect {
throw
e
;
}
}
finally
{
tokenServiceCall
.
tokenFinish
();
if
(
isInit
)
{
tokenFinish
(
flag
);
TokenHelper
.
remove
();
}
responseLog
(
logWeb
,
clear
,
TAG
,
HttpAspectUtil
.
getHttpRequestUrl
(),
joinPoint
,
start
,
result
,
ex
);
...
...
@@ -101,19 +99,6 @@ public class WebAspect extends BaseRequestAspect {
return
this
.
applicationName
.
matches
(
this
.
gateWay
);
}
/**
* 执行结束函数
*
* @param flag 结束函数
* @return 结束函数
*/
private
void
tokenFinish
(
Ref
<
Boolean
>
flag
)
{
if
(
flag
.
value
==
true
)
{
return
;
}
flag
.
value
=
true
;
tokenServiceCall
.
tokenFinish
();
}
/**
* 获取返回的至类型
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/service/TokenServiceCall.java
View file @
e9e9ac98
...
...
@@ -6,7 +6,6 @@ import com.yanzuoguang.token.TokenLoad;
import
com.yanzuoguang.util.cache.MemoryCache
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.log.Log
;
import
com.yanzuoguang.util.thread.ThreadHelper
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.stereotype.Component
;
...
...
@@ -26,7 +25,7 @@ public class TokenServiceCall implements TokenLoad {
private
int
flagCount
=
3
;
private
MemoryCache
<
Boolean
>
countCache
=
new
MemoryCache
<>();
private
MemoryCache
<
Integer
>
countCache
=
new
MemoryCache
<>();
public
TokenServiceCall
()
{
TokenHelper
.
setTokenLoad
(
this
);
...
...
@@ -56,12 +55,11 @@ public class TokenServiceCall implements TokenLoad {
if
(
tokenService
==
null
)
{
return
false
;
}
if
(
isHave
())
{
return
false
;
if
(
addHave
()
==
1
)
{
tokenService
.
tokenInit
();
return
true
;
}
tokenService
.
tokenInit
();
setHave
();
return
true
;
return
false
;
}
/**
...
...
@@ -72,8 +70,9 @@ public class TokenServiceCall implements TokenLoad {
if
(
tokenService
==
null
)
{
return
;
}
tokenService
.
tokenFinish
();
removeHave
();
if
(
subHave
()
==
0
)
{
tokenService
.
tokenFinish
();
}
}
/**
...
...
@@ -91,18 +90,22 @@ public class TokenServiceCall implements TokenLoad {
return
tokenService
.
load
(
token
);
}
private
boolean
isHave
(
)
{
private
int
addHave
(
int
flag
)
{
String
id
=
StringHelper
.
toString
(
Thread
.
currentThread
().
getId
());
return
StringHelper
.
toBoolean
(
countCache
.
get
(
id
));
int
from
=
StringHelper
.
toInt
(
countCache
.
get
(
id
));
int
to
=
from
+
flag
;
countCache
.
put
(
id
,
to
);
if
(
to
==
0
)
{
countCache
.
remove
(
id
);
}
return
to
;
}
private
void
setHave
()
{
String
id
=
StringHelper
.
toString
(
Thread
.
currentThread
().
getId
());
countCache
.
put
(
id
,
true
);
private
int
addHave
()
{
return
addHave
(
1
);
}
private
void
removeHave
()
{
String
id
=
StringHelper
.
toString
(
Thread
.
currentThread
().
getId
());
countCache
.
remove
(
id
);
private
int
subHave
()
{
return
addHave
(-
1
);
}
}
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