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
602a93df
Commit
602a93df
authored
Nov 08, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
接口文档的支持
parent
3ec864d9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
61 deletions
+17
-61
BaseRequestAspect.java
...ain/java/com/yanzuoguang/cloud/aop/BaseRequestAspect.java
+7
-8
WebAspect.java
...ud/src/main/java/com/yanzuoguang/cloud/aop/WebAspect.java
+10
-53
No files found.
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/BaseRequestAspect.java
View file @
602a93df
...
...
@@ -60,11 +60,6 @@ public class BaseRequestAspect implements ThreadNext.Next {
*/
protected
volatile
LinkedBlockingQueue
<
LogVo
>
cache
=
new
LinkedBlockingQueue
<
LogVo
>();
/**
* 缓存的每次请求的结果
*/
protected
MemoryCache
<
RequestCacheResult
>
cacheResult
=
new
MemoryCache
<>(
cacheTime
);
public
BaseRequestAspect
()
{
ThreadNext
.
start
(
this
,
"save log error"
);
}
...
...
@@ -263,10 +258,14 @@ public class BaseRequestAspect implements ThreadNext.Next {
while
(
cache
.
size
()
>
0
)
{
LogVo
item
=
cache
.
poll
();
if
(
item
!=
null
)
{
try
{
if
(
logFeign
==
null
)
{
logFeign
=
context
.
getBean
(
LogFeign
.
class
);
}
logFeign
.
save
(
item
);
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
}
}
}
return
true
;
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/WebAspect.java
View file @
602a93df
...
...
@@ -36,9 +36,6 @@ public class WebAspect extends BaseRequestAspect {
@Autowired
private
TokenServiceCall
tokenServiceCall
;
@Value
(
"${yzg.reqUrl:}"
)
private
String
reqUrl
;
@Value
(
"${yzg.gateway:^.*gateway.*$}"
)
private
String
gateWay
;
...
...
@@ -58,22 +55,22 @@ public class WebAspect extends BaseRequestAspect {
*/
@Around
(
value
=
"webAspect()"
)
public
Object
requestWebAround
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
Object
result
=
null
;
boolean
isGateWay
=
isGateWay
();
if
(
isGateWay
)
{
result
=
executeMethod
(
joinPoint
);
return
result
;
}
boolean
clear
=
requestLogInit
();
// 用户数据库记录
long
start
=
requestLog
(
TAG
,
joinPoint
);
Object
result
=
null
;
Exception
ex
=
null
;
Ref
<
Boolean
>
flag
=
new
Ref
<>(
false
);
boolean
isGateWay
=
isGateWay
();
boolean
isInit
=
false
;
try
{
if
(!
isGateWay
)
{
isInit
=
tokenServiceCall
.
tokenInit
();
}
result
=
executeMethod
(
joinPoint
);
if
(!
isGateWay
)
{
tokenFinish
(
flag
);
}
return
result
;
}
catch
(
Exception
e
)
{
ex
=
e
;
...
...
@@ -85,9 +82,7 @@ public class WebAspect extends BaseRequestAspect {
}
}
finally
{
if
(
isInit
)
{
if
(!
isGateWay
)
{
tokenFinish
(
flag
);
}
TokenHelper
.
remove
();
}
responseLog
(
clear
,
TAG
,
HttpAspectUtil
.
getHttpRequestUrl
(),
joinPoint
,
start
,
result
,
ex
);
...
...
@@ -153,44 +148,6 @@ public class WebAspect extends BaseRequestAspect {
* @throws Throwable
*/
private
Object
executeMethod
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
List
<
Object
>
dataParas
=
this
.
getDataParameters
(
joinPoint
.
getArgs
());
boolean
dataArgs
=
dataParas
.
isEmpty
();
Method
method
=
getMethod
(
joinPoint
);
boolean
isUrl
=
false
;
if
(!
StringHelper
.
isEmpty
(
reqUrl
))
{
String
[]
urls
=
reqUrl
.
split
(
","
);
for
(
String
url
:
urls
)
{
if
(
method
.
getName
().
matches
(
url
))
{
isUrl
=
true
;
break
;
}
}
}
if
(
dataArgs
||
!
isUrl
)
{
return
joinPoint
.
proceed
();
}
else
{
// 获取请求编号
Object
firstArgs
=
dataParas
.
size
()
>
0
?
dataParas
.
get
(
0
)
:
null
;
String
reqId
=
StringHelper
.
md5
(
JsonHelper
.
serialize
(
firstArgs
));
String
reqFull
=
StringHelper
.
getId
(
reqId
,
HttpAspectUtil
.
getHttpRequestUrl
());
RequestCacheResult
req
=
cacheResult
.
get
(
reqFull
,
new
RequestCacheResult
(
reqFull
));
// 缓存的键值对
if
(
req
.
getResult
()
==
null
)
{
synchronized
(
req
)
{
if
(
req
.
getResult
()
==
null
)
{
try
{
req
.
setResult
(
joinPoint
.
proceed
());
}
catch
(
Exception
ex
)
{
req
.
setResult
(
ex
);
}
}
}
}
Object
result
=
req
.
getResult
();
if
(
result
instanceof
Throwable
)
{
throw
(
Throwable
)
result
;
}
return
result
;
}
}
}
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