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
6552c317
Commit
6552c317
authored
Mar 17, 2021
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改公式和计算帮助类
parent
56714b5d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
60 deletions
+47
-60
BaseRequestAspect.java
...ain/java/com/yanzuoguang/cloud/aop/BaseRequestAspect.java
+1
-57
LogLocal.java
...oud/src/main/java/com/yanzuoguang/cloud/aop/LogLocal.java
+46
-3
No files found.
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/BaseRequestAspect.java
View file @
6552c317
package
com
.
yanzuoguang
.
cloud
.
aop
;
import
com.alibaba.fastjson.JSON
;
import
com.rabbitmq.client.Channel
;
import
com.yanzuoguang.util.contants.ResultConstants
;
import
com.yanzuoguang.util.exception.ExceptionHelper
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
...
...
@@ -35,7 +33,6 @@ import java.util.List;
*/
public
class
BaseRequestAspect
{
@Value
(
"${spring.application.name}"
)
protected
String
applicationName
;
...
...
@@ -51,12 +48,6 @@ public class BaseRequestAspect {
@Value
(
"${yzg.reqSize:5000}"
)
private
int
reqSize
=
5000
;
@Value
(
"${yzg.log.notFilter:^.*login.*$}"
)
private
String
notFilter
;
@Value
(
"${yzg.log.filter:^.*log.*$}"
)
private
String
filter
;
@Autowired
private
LogLocal
logLocal
;
...
...
@@ -72,30 +63,6 @@ public class BaseRequestAspect {
return
this
.
logLocal
.
startLog
(
actionKey
,
String
.
format
(
"%s:%s"
,
this
.
applicationName
,
url
),
body
);
}
/**
* 初始化日志Vo
*
* @param url 请求路径
* @param joinPoint 请求参数
* @param responseResult 返回参数
* @return
*/
protected
LogVo
abc
(
String
url
,
ProceedingJoinPoint
joinPoint
,
ResponseResult
responseResult
)
{
LogVo
logInterVo
=
new
LogVo
();
logInterVo
.
setLogId
(
StringHelper
.
getNewID
());
//平台名
logInterVo
.
setActionKey
(
applicationName
);
//请求URL
logInterVo
.
setActionSubKey
(
url
);
Object
paraTo
=
getFirstDataParameter
(
joinPoint
.
getArgs
());
//请求参数
logInterVo
.
setContent
(
JSON
.
toJSONString
(
paraTo
));
//返回参数
logInterVo
.
setResult
(
JSON
.
toJSONString
(
responseResult
));
logInterVo
.
setStatus
(
responseResult
!=
null
?
responseResult
.
getCode
()
:
ResultConstants
.
SUCCESS
);
return
logInterVo
;
}
/**
* 获取请求内容
*
...
...
@@ -242,13 +209,7 @@ public class BaseRequestAspect {
tag
,
name
,
time
,
getMaxString
(
JsonHelper
.
serialize
(
responseResult
)));
}
// 日志请求不记录,防止死循环递归
boolean
isLog
=
isLog
(
name
,
log
.
getActionSubKey
());
if
(
isLog
)
{
logLocal
.
remove
(
log
);
}
else
{
logLocal
.
result
(
log
,
responseResult
.
getCode
(),
JsonHelper
.
serialize
(
responseResult
));
}
logLocal
.
result
(
log
,
name
,
responseResult
.
getCode
(),
JsonHelper
.
serialize
(
responseResult
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
...
...
@@ -258,23 +219,6 @@ public class BaseRequestAspect {
}
}
/**
* 是否属于日志服务
*
* @param name
* @param url
* @return
*/
private
boolean
isLog
(
String
name
,
String
url
)
{
boolean
noFilter
=
applicationName
.
matches
(
notFilter
)
||
name
.
matches
(
notFilter
)
||
url
.
matches
(
notFilter
);
if
(
noFilter
)
{
return
false
;
}
boolean
isLog
=
applicationName
.
matches
(
filter
)
||
name
.
matches
(
filter
)
||
url
.
matches
(
filter
);
return
isLog
;
}
/**
* 获取方法名称
*
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/LogLocal.java
View file @
6552c317
...
...
@@ -18,18 +18,27 @@ import java.util.*;
*/
@Component
public
class
LogLocal
implements
ThreadNext
.
Next
,
InitializingBean
{
/**
* 缓存队列
*/
protected
volatile
Map
<
String
,
Timeout
<
LogVo
>>
cache
=
new
Hashtable
<>();
@Value
(
"${spring.application.name}"
)
protected
String
applicationName
;
/**
* 1个请求最长时间
*/
@Value
(
"${yzg.timeout:300000}"
)
private
int
timeout
;
@Value
(
"${yzg.log.notFilter:^.*login.*$}"
)
private
String
notFilter
;
@Value
(
"${yzg.log.filter:^.*log.*$}"
)
private
String
filter
;
/**
* 超时状态
*/
...
...
@@ -87,9 +96,26 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
* @return
*/
public
void
result
(
LogVo
log
,
String
status
,
String
result
)
{
this
.
result
(
log
,
StringHelper
.
EMPTY
,
status
,
result
);
}
/**
* 写入状态
*
* @param status
* @param result
* @return
*/
public
void
result
(
LogVo
log
,
String
name
,
String
status
,
String
result
)
{
// 日志请求不记录,防止死循环递归
boolean
isLog
=
isLog
(
name
,
log
.
getActionSubKey
());
if
(
isLog
)
{
this
.
remove
(
log
);
}
else
{
Timeout
<
LogVo
>
timeout
=
cache
.
get
(
log
.
getLogId
());
result
(
timeout
,
log
,
status
,
result
,
true
);
}
}
/**
* 写入状态
...
...
@@ -132,6 +158,23 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
result
(
timeout
,
timeout
.
getData
(),
MAX_TIME
,
MAX_TIME_NAME
,
true
);
}
/**
* 是否属于日志服务
*
* @param name
* @param url
* @return
*/
private
boolean
isLog
(
String
name
,
String
url
)
{
boolean
noFilter
=
applicationName
.
matches
(
notFilter
)
||
name
.
matches
(
notFilter
)
||
url
.
matches
(
notFilter
);
if
(
noFilter
)
{
return
false
;
}
boolean
isLog
=
applicationName
.
matches
(
filter
)
||
name
.
matches
(
filter
)
||
url
.
matches
(
filter
);
return
isLog
;
}
/**
* 执行下一个函数,出现异常会继续执行
*
...
...
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