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
e3cf6a66
Commit
e3cf6a66
authored
May 18, 2022
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
将源码打包进jar包
parent
3b744dbc
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
56 additions
and
60 deletions
+56
-60
AspectFeign.java
.../src/main/java/com/yanzuoguang/cloud/aop/AspectFeign.java
+2
-2
AspectLogBody.java
...rc/main/java/com/yanzuoguang/cloud/aop/AspectLogBody.java
+10
-0
AspectLogUrl.java
...src/main/java/com/yanzuoguang/cloud/aop/AspectLogUrl.java
+30
-12
AspectMq.java
...oud/src/main/java/com/yanzuoguang/cloud/aop/AspectMq.java
+13
-45
AspectWeb.java
...ud/src/main/java/com/yanzuoguang/cloud/aop/AspectWeb.java
+1
-1
No files found.
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/AspectFeign.java
View file @
e3cf6a66
...
...
@@ -51,7 +51,7 @@ public class AspectFeign {
@Around
(
value
=
"feignAspect()"
)
public
Object
requestFeignAround
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
Class
<?>
declaringType
=
joinPoint
.
getSignature
().
getDeclaringType
();
String
url
=
aspectLogUrl
.
getMethodUrl
(
joinPoint
);
String
url
=
aspectLogUrl
.
get
Web
MethodUrl
(
joinPoint
);
Object
requestBody
=
aspectLogBody
.
getRequestBody
(
joinPoint
);
boolean
clear
=
aspectLogStart
.
requestLogInit
();
...
...
@@ -66,7 +66,7 @@ public class AspectFeign {
result
=
joinPoint
.
proceed
();
// 假如是标准格式,则验证接口是否成功,不成功则抛出异常
if
(
result
instanceof
ResponseResult
)
{
ResponseResult
responseResult
=
(
ResponseResult
)
result
;
ResponseResult
<?>
responseResult
=
(
ResponseResult
<?>
)
result
;
if
(!
ResultConstants
.
SUCCESS
.
equals
(
responseResult
.
getCode
()))
{
throw
new
CodeException
(
responseResult
.
getCode
(),
responseResult
.
getMessage
(),
responseResult
.
getTarget
());
}
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/AspectLogBody.java
View file @
e3cf6a66
...
...
@@ -12,6 +12,7 @@ import org.springframework.web.multipart.MultipartFile;
import
javax.servlet.http.HttpServlet
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.nio.charset.StandardCharsets
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -109,4 +110,13 @@ public class AspectLogBody {
return
para
;
}
/**
* 获取消息内容
*
* @param message 消息
* @return 消息内容
*/
public
String
getRequestBody
(
Message
message
)
{
return
new
String
(
message
.
getBody
(),
StandardCharsets
.
UTF_8
);
}
}
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/AspectLogUrl.java
View file @
e3cf6a66
...
...
@@ -32,7 +32,7 @@ public class AspectLogUrl {
*
* @return 方法路径
*/
public
String
getMethodUrl
(
ProceedingJoinPoint
joinPoint
)
{
public
String
get
Web
MethodUrl
(
ProceedingJoinPoint
joinPoint
)
{
String
url
=
StringHelper
.
EMPTY
;
Signature
signature
=
joinPoint
.
getSignature
();
Class
<?>
declaringType
=
signature
.
getDeclaringType
();
...
...
@@ -57,11 +57,6 @@ public class AspectLogUrl {
GetMapping
[]
gets
=
targetMethod
.
getAnnotationsByType
(
GetMapping
.
class
);
url
=
getFeignOrRequestUrl
(
feignClient
,
classRequests
,
classPosts
,
classGets
,
requests
,
posts
,
gets
);
}
else
{
Message
message
=
getMessage
(
joinPoint
.
getArgs
());
if
(
message
!=
null
)
{
url
=
message
.
getMessageProperties
().
getConsumerQueue
();
}
}
if
(
StringHelper
.
isEmpty
(
url
))
{
return
baseUrl
;
...
...
@@ -81,9 +76,7 @@ public class AspectLogUrl {
* @param gets
* @return
*/
private
String
getFeignOrRequestUrl
(
FeignClient
feignClient
,
RequestMapping
[]
classRequests
,
PostMapping
[]
classPosts
,
GetMapping
[]
classGets
,
RequestMapping
[]
requests
,
PostMapping
[]
posts
,
GetMapping
[]
gets
)
{
private
String
getFeignOrRequestUrl
(
FeignClient
feignClient
,
RequestMapping
[]
classRequests
,
PostMapping
[]
classPosts
,
GetMapping
[]
classGets
,
RequestMapping
[]
requests
,
PostMapping
[]
posts
,
GetMapping
[]
gets
)
{
StringBuilder
sb
=
new
StringBuilder
();
if
(
feignClient
!=
null
)
{
sb
.
append
(
feignClient
.
value
());
...
...
@@ -121,11 +114,11 @@ public class AspectLogUrl {
/**
* 根据类型获取对象
*
* @param
args
参数
* @param
joinPoint
参数
* @return 消息实体
*/
public
Message
getMessage
(
Object
[]
args
)
{
for
(
Object
item
:
args
)
{
public
Message
getMessage
(
ProceedingJoinPoint
joinPoint
)
{
for
(
Object
item
:
joinPoint
.
getArgs
()
)
{
if
(
item
instanceof
Message
)
{
return
(
Message
)
item
;
}
...
...
@@ -133,4 +126,29 @@ public class AspectLogUrl {
return
null
;
}
/**
* 获取消息路径
*
* @param joinPoint 函数
* @param message 消息内容
* @return 消息路径
*/
public
String
getMessageUrl
(
ProceedingJoinPoint
joinPoint
,
Message
message
)
{
Signature
signature
=
joinPoint
.
getSignature
();
Class
<?>
declaringType
=
signature
.
getDeclaringType
();
String
name
=
signature
.
getName
();
String
baseUrl
=
String
.
format
(
"%s:%s"
,
declaringType
.
getSimpleName
(),
name
);
String
url
;
if
(
message
!=
null
)
{
url
=
message
.
getMessageProperties
().
getConsumerQueue
();
}
else
{
url
=
StringHelper
.
EMPTY
;
}
if
(
StringHelper
.
isEmpty
(
url
))
{
return
baseUrl
;
}
return
String
.
format
(
"%s:%s"
,
baseUrl
,
url
);
}
}
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/AspectMq.java
View file @
e3cf6a66
package
com
.
yanzuoguang
.
cloud
.
aop
;
import
com.yanzuoguang.mq.plan.YzgMqConsumer
;
import
com.yanzuoguang.mq.service.MessageLogService
;
import
com.yanzuoguang.util.exception.ExceptionHelper
;
import
com.yanzuoguang.util.vo.LogVo
;
...
...
@@ -8,13 +7,9 @@ import org.aspectj.lang.ProceedingJoinPoint;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.aspectj.lang.reflect.MethodSignature
;
import
org.springframework.amqp.core.Message
;
import
org.springframework.amqp.rabbit.annotation.RabbitListener
;
import
org.springframework.stereotype.Component
;
import
java.lang.reflect.Method
;
/**
* LogsAspect(接口请求日志切面)
*
...
...
@@ -33,9 +28,7 @@ public class AspectMq {
private
final
AspectLogStart
aspectLogStart
;
private
final
AspectLogResult
aspectLogResult
;
public
AspectMq
(
MessageLogService
logService
,
AspectLogUrl
aspectLogUrl
,
AspectLogBody
aspectLogBody
,
AspectLogStart
aspectLogStart
,
AspectLogResult
aspectLogResult
)
{
public
AspectMq
(
MessageLogService
logService
,
AspectLogUrl
aspectLogUrl
,
AspectLogBody
aspectLogBody
,
AspectLogStart
aspectLogStart
,
AspectLogResult
aspectLogResult
)
{
this
.
logService
=
logService
;
this
.
aspectLogUrl
=
aspectLogUrl
;
this
.
aspectLogBody
=
aspectLogBody
;
...
...
@@ -46,27 +39,30 @@ public class AspectMq {
/**
* exec aop point aspect
*/
@Pointcut
(
"execution(* *..mq..*Consumer.*(..))"
)
// @Pointcut("execution(* *..mq..*Consumer.*(..))")
@Pointcut
(
"execution(* org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter.onMessage(..))"
)
public
void
mqAspect
()
{
}
/**
* 执行环形切面
*
* @param joinPoint
* @return
* @param joinPoint
方法提
* @return
执行回掉
*/
@Around
(
value
=
"mqAspect()"
)
public
Object
requestMqAround
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
Class
declaringType
=
joinPoint
.
getSignature
().
getDeclaringType
();
String
url
=
aspectLogUrl
.
getMethodUrl
(
joinPoint
);
Object
requestBody
=
aspectLogBody
.
getRequestBody
(
joinPoint
);
boolean
clear
=
isRabbit
(
joinPoint
);
if
(
clear
)
{
clear
=
aspectLogStart
.
requestLogInit
();
Class
<?>
declaringType
=
joinPoint
.
getSignature
().
getDeclaringType
();
Message
message
=
aspectLogUrl
.
getMessage
(
joinPoint
);
if
(
message
==
null
)
{
return
executeMethod
(
joinPoint
);
}
logService
.
logCurrent
(
message
);
String
url
=
aspectLogUrl
.
getMessageUrl
(
joinPoint
,
message
);
String
requestBody
=
aspectLogBody
.
getRequestBody
(
message
);
LogVo
log
=
new
LogVo
();
boolean
clear
=
aspectLogStart
.
requestLogInit
();
aspectLogStart
.
requestLog
(
declaringType
,
TAG
,
url
,
requestBody
,
log
,
clear
);
long
start
=
System
.
currentTimeMillis
();
...
...
@@ -86,34 +82,6 @@ public class AspectMq {
}
}
/**
* 判断是否MQ函数
*
* @param joinPoint 函数
* @return 是否MQ函数
*/
private
boolean
isRabbit
(
ProceedingJoinPoint
joinPoint
)
{
boolean
ret
=
false
;
if
(!(
joinPoint
.
getSignature
()
instanceof
MethodSignature
))
{
return
false
;
}
MethodSignature
methodSignature
=
(
MethodSignature
)
joinPoint
.
getSignature
();
Method
targetMethod
=
methodSignature
.
getMethod
();
Message
message
=
aspectLogUrl
.
getMessage
(
joinPoint
.
getArgs
());
if
(
message
!=
null
)
{
logService
.
logCurrent
(
message
);
}
if
(
YzgMqConsumer
.
class
.
equals
(
targetMethod
.
getDeclaringClass
()))
{
ret
=
false
;
}
else
{
RabbitListener
annotation
=
targetMethod
.
getAnnotation
(
RabbitListener
.
class
);
if
(
annotation
!=
null
||
message
!=
null
)
{
ret
=
true
;
}
}
return
ret
;
}
/**
* 执行函数
*
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/AspectWeb.java
View file @
e3cf6a66
...
...
@@ -82,7 +82,7 @@ public class AspectWeb {
}
Class
declaringType
=
joinPoint
.
getSignature
().
getDeclaringType
();
String
url
=
aspectLogUrl
.
getMethodUrl
(
joinPoint
);
String
url
=
aspectLogUrl
.
get
Web
MethodUrl
(
joinPoint
);
Object
requestBody
=
aspectLogBody
.
getRequestBody
(
joinPoint
);
boolean
clear
=
aspectLogStart
.
requestLogInit
();
LogVo
log
=
new
LogVo
();
...
...
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