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
a0cff7f2
Commit
a0cff7f2
authored
May 13, 2022
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复等待时间
parent
e1979def
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
76 additions
and
35 deletions
+76
-35
CloudConfig.java
...loud/src/main/java/com/yanzuoguang/cloud/CloudConfig.java
+11
-0
AspectLogCountTime.java
...in/java/com/yanzuoguang/cloud/aop/AspectLogCountTime.java
+7
-27
AspectLogPrint.java
...c/main/java/com/yanzuoguang/cloud/aop/AspectLogPrint.java
+50
-0
AspectLogResult.java
.../main/java/com/yanzuoguang/cloud/aop/AspectLogResult.java
+4
-4
AspectLogStart.java
...c/main/java/com/yanzuoguang/cloud/aop/AspectLogStart.java
+4
-4
No files found.
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/CloudConfig.java
View file @
a0cff7f2
...
...
@@ -16,6 +16,8 @@ import java.util.Date;
@Component
public
class
CloudConfig
{
public
static
final
int
DEFAULT_PRINT_TIME
=
2
*
60
*
1000
;
@Value
(
"${spring.application.name}"
)
protected
String
applicationName
;
...
...
@@ -70,6 +72,11 @@ public class CloudConfig {
@Value
(
"${yzg.gateway:^.*gateway.*$}"
)
private
String
gateWay
;
/**
* 外网地址
*/
@Value
(
"${yzg.count.print.time:"
+
DEFAULT_PRINT_TIME
+
"}"
)
private
int
logCountTime
;
public
String
getApplicationName
()
{
return
applicationName
;
...
...
@@ -152,4 +159,8 @@ public class CloudConfig {
public
boolean
isGateWay
()
{
return
this
.
applicationName
.
toLowerCase
().
matches
(
this
.
gateWay
);
}
public
int
getLogCountTime
()
{
return
logCountTime
;
}
}
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/AspectLogTime.java
→
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/AspectLog
Count
Time.java
View file @
a0cff7f2
package
com
.
yanzuoguang
.
cloud
.
aop
;
import
com.yanzuoguang.util.base.CollectionString
;
import
com.yanzuoguang.util.cache.MemoryCache
;
import
com.yanzuoguang.util.helper.DateHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.thread.ThreadNext
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.stereotype.Component
;
import
java.util.ArrayList
;
import
java.util.Comparator
;
import
java.util.List
;
/**
* 日志时间
*
* @author 颜佐光
*/
@Component
public
class
AspectLog
Time
implements
ThreadNext
.
Next
,
InitializingBean
{
public
class
AspectLog
CountTime
{
private
static
final
String
URL_PARA_START
=
"?"
;
...
...
@@ -35,9 +28,12 @@ public class AspectLogTime implements ThreadNext.Next, InitializingBean {
*/
private
String
todayTime
;
@Override
public
void
afterPropertiesSet
()
{
ThreadNext
.
start
(
this
,
"aspectLogTime"
);
public
MemoryCache
<
AspectUrlCountVo
>
getTodayMemoryCache
()
{
return
todayMemoryCache
;
}
public
String
getTodayTime
()
{
return
todayTime
;
}
private
void
initToday
()
{
...
...
@@ -104,20 +100,4 @@ public class AspectLogTime implements ThreadNext.Next, InitializingBean {
AspectUrlCountVo
count
=
getCount
(
url
);
count
.
addFinish
(
time
,
isError
);
}
@Override
public
boolean
next
()
{
List
<
AspectUrlCountVo
>
rowList
=
new
ArrayList
<>(
todayMemoryCache
.
getValues
());
if
(
rowList
.
isEmpty
())
{
return
true
;
}
rowList
.
sort
(
Comparator
.
comparingLong
(
AspectUrlCountVo:
:
getTotalTime
));
System
.
out
.
println
(
CollectionString
.
getCollectionString
(
"接口从"
+
todayTime
+
"时执行次数:"
,
rowList
));
return
true
;
}
@Override
public
int
getNextTime
()
{
return
2
*
60
*
1000
;
}
}
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/AspectLogPrint.java
0 → 100644
View file @
a0cff7f2
package
com
.
yanzuoguang
.
cloud
.
aop
;
import
com.yanzuoguang.cloud.CloudConfig
;
import
com.yanzuoguang.util.base.CollectionString
;
import
com.yanzuoguang.util.thread.ThreadNext
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.stereotype.Component
;
import
java.util.ArrayList
;
import
java.util.Comparator
;
import
java.util.List
;
/**
* 将请求次数日志输出
*
* @author 颜佐光
*/
@Component
public
class
AspectLogPrint
implements
ThreadNext
.
Next
,
InitializingBean
{
private
final
CloudConfig
cloudConfig
;
private
final
AspectLogCountTime
aspectLogCountTime
;
public
AspectLogPrint
(
CloudConfig
cloudConfig
,
AspectLogCountTime
aspectLogCountTime
)
{
this
.
cloudConfig
=
cloudConfig
;
this
.
aspectLogCountTime
=
aspectLogCountTime
;
}
@Override
public
void
afterPropertiesSet
()
{
ThreadNext
.
start
(
this
,
"aspectLogTime"
);
}
@Override
public
boolean
next
()
{
List
<
AspectUrlCountVo
>
rowList
=
new
ArrayList
<>(
aspectLogCountTime
.
getTodayMemoryCache
().
getValues
());
if
(
rowList
.
isEmpty
())
{
return
true
;
}
rowList
.
sort
(
Comparator
.
comparingLong
(
AspectUrlCountVo:
:
getTotalTime
));
System
.
out
.
println
(
CollectionString
.
getCollectionString
(
"接口从"
+
aspectLogCountTime
.
getTodayTime
()
+
"时执行次数:"
,
rowList
));
return
true
;
}
@Override
public
int
getNextTime
()
{
return
cloudConfig
.
getLogCountTime
();
}
}
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/AspectLogResult.java
View file @
a0cff7f2
...
...
@@ -21,16 +21,16 @@ public class AspectLogResult {
private
final
CloudConfig
cloudConfig
;
private
final
LogLocal
logLocal
;
private
final
AspectLogBody
aspectLogBody
;
private
final
AspectLog
Time
aspectLog
Time
;
private
final
AspectLog
CountTime
aspectLogCount
Time
;
private
final
ResponseResult
<
String
>
responseDefault
=
ResponseResult
.
result
(
"操作成功"
);
public
AspectLogResult
(
CloudConfig
cloudConfig
,
LogLocal
logLocal
,
AspectLogBody
aspectLogBody
,
AspectLog
Time
aspectLog
Time
)
{
public
AspectLogResult
(
CloudConfig
cloudConfig
,
LogLocal
logLocal
,
AspectLogBody
aspectLogBody
,
AspectLog
CountTime
aspectLogCount
Time
)
{
this
.
cloudConfig
=
cloudConfig
;
this
.
logLocal
=
logLocal
;
this
.
aspectLogBody
=
aspectLogBody
;
this
.
aspectLog
Time
=
aspectLog
Time
;
this
.
aspectLog
CountTime
=
aspectLogCount
Time
;
}
/**
...
...
@@ -59,7 +59,7 @@ public class AspectLogResult {
boolean
isError
=
resultEx
!=
null
;
boolean
isLogDisplay
=
isLogCommon
||
isError
;
// 记录请求时间
aspectLogTime
.
finish
(
fullUrl
,
time
,
isError
);
aspectLog
Count
Time
.
finish
(
fullUrl
,
time
,
isError
);
// ThreadHelper.waitRun(WAIT_MAX, WAIT_ITEM, k -> StringHelper.isEmpty(log.getLogId()))
if
(
StringHelper
.
isEmpty
(
log
.
getLogId
())
||
!
isLogDisplay
)
{
return
;
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/AspectLogStart.java
View file @
a0cff7f2
...
...
@@ -17,13 +17,13 @@ public class AspectLogStart {
private
final
CloudConfig
cloudConfig
;
private
final
LogLocal
logLocal
;
private
final
AspectLogBody
aspectLogBody
;
private
final
AspectLog
Time
aspectLog
Time
;
private
final
AspectLog
CountTime
aspectLogCount
Time
;
public
AspectLogStart
(
CloudConfig
cloudConfig
,
LogLocal
logLocal
,
AspectLogBody
aspectLogBody
,
AspectLog
Time
aspectLog
Time
)
{
public
AspectLogStart
(
CloudConfig
cloudConfig
,
LogLocal
logLocal
,
AspectLogBody
aspectLogBody
,
AspectLog
CountTime
aspectLogCount
Time
)
{
this
.
cloudConfig
=
cloudConfig
;
this
.
logLocal
=
logLocal
;
this
.
aspectLogBody
=
aspectLogBody
;
this
.
aspectLog
Time
=
aspectLog
Time
;
this
.
aspectLog
CountTime
=
aspectLogCount
Time
;
}
/**
...
...
@@ -40,7 +40,7 @@ public class AspectLogStart {
public
void
requestLog
(
Class
<?>
cls
,
String
tag
,
String
url
,
Object
requestBody
,
LogVo
log
,
boolean
logFlag
)
{
try
{
String
fullUrl
=
String
.
format
(
"%s:%s"
,
tag
,
url
);
aspectLogTime
.
start
(
fullUrl
);
aspectLog
Count
Time
.
start
(
fullUrl
);
String
body
=
aspectLogBody
.
getBodyString
(
requestBody
);
if
(
logFlag
)
{
...
...
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