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
ba8c27ef
Commit
ba8c27ef
authored
May 18, 2022
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
将源码打包进jar包
parent
80f52bb6
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
73 additions
and
38 deletions
+73
-38
AspectLogResult.java
.../main/java/com/yanzuoguang/cloud/aop/AspectLogResult.java
+5
-4
AspectLogStart.java
...c/main/java/com/yanzuoguang/cloud/aop/AspectLogStart.java
+5
-4
DbExecuteImpl.java
.../src/main/java/com/yanzuoguang/db/impl/DbExecuteImpl.java
+14
-2
DbPrintSql.java
...-db/src/main/java/com/yanzuoguang/db/impl/DbPrintSql.java
+2
-4
LogConfig.java
yzg-util-db/src/main/java/com/yanzuoguang/log/LogConfig.java
+24
-0
LogCountTime.java
...il-db/src/main/java/com/yanzuoguang/log/LogCountTime.java
+9
-9
LogPrint.java
yzg-util-db/src/main/java/com/yanzuoguang/log/LogPrint.java
+11
-12
LogUrlCountVo.java
...l-db/src/main/java/com/yanzuoguang/log/LogUrlCountVo.java
+3
-3
No files found.
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/AspectLogResult.java
View file @
ba8c27ef
...
...
@@ -2,6 +2,7 @@ package com.yanzuoguang.cloud.aop;
import
com.yanzuoguang.cloud.CloudConfig
;
import
com.yanzuoguang.cloud.aop.log.LogLocal
;
import
com.yanzuoguang.log.LogCountTime
;
import
com.yanzuoguang.util.exception.ExceptionHelper
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
...
...
@@ -21,16 +22,16 @@ public class AspectLogResult {
private
final
CloudConfig
cloudConfig
;
private
final
LogLocal
logLocal
;
private
final
AspectLogBody
aspectLogBody
;
private
final
AspectLogCountTime
aspectL
ogCountTime
;
private
final
LogCountTime
l
ogCountTime
;
private
final
ResponseResult
<
String
>
responseDefault
=
ResponseResult
.
result
(
"操作成功"
);
public
AspectLogResult
(
CloudConfig
cloudConfig
,
LogLocal
logLocal
,
AspectLogBody
aspectLogBody
,
AspectLogCountTime
aspectL
ogCountTime
)
{
public
AspectLogResult
(
CloudConfig
cloudConfig
,
LogLocal
logLocal
,
AspectLogBody
aspectLogBody
,
LogCountTime
l
ogCountTime
)
{
this
.
cloudConfig
=
cloudConfig
;
this
.
logLocal
=
logLocal
;
this
.
aspectLogBody
=
aspectLogBody
;
this
.
aspectLogCountTime
=
aspectL
ogCountTime
;
this
.
logCountTime
=
l
ogCountTime
;
}
/**
...
...
@@ -59,7 +60,7 @@ public class AspectLogResult {
boolean
isError
=
resultEx
!=
null
;
boolean
isLogDisplay
=
isLogCommon
||
isError
;
// 记录请求时间
aspectL
ogCountTime
.
finish
(
fullUrl
,
time
,
isError
);
l
ogCountTime
.
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 @
ba8c27ef
...
...
@@ -2,6 +2,7 @@ package com.yanzuoguang.cloud.aop;
import
com.yanzuoguang.cloud.CloudConfig
;
import
com.yanzuoguang.cloud.aop.log.LogLocal
;
import
com.yanzuoguang.log.LogCountTime
;
import
com.yanzuoguang.util.log.Log
;
import
com.yanzuoguang.util.vo.LogVo
;
import
org.springframework.stereotype.Component
;
...
...
@@ -17,13 +18,13 @@ public class AspectLogStart {
private
final
CloudConfig
cloudConfig
;
private
final
LogLocal
logLocal
;
private
final
AspectLogBody
aspectLogBody
;
private
final
AspectLogCountTime
aspectL
ogCountTime
;
private
final
LogCountTime
l
ogCountTime
;
public
AspectLogStart
(
CloudConfig
cloudConfig
,
LogLocal
logLocal
,
AspectLogBody
aspectLogBody
,
AspectLogCountTime
aspectL
ogCountTime
)
{
public
AspectLogStart
(
CloudConfig
cloudConfig
,
LogLocal
logLocal
,
AspectLogBody
aspectLogBody
,
LogCountTime
l
ogCountTime
)
{
this
.
cloudConfig
=
cloudConfig
;
this
.
logLocal
=
logLocal
;
this
.
aspectLogBody
=
aspectLogBody
;
this
.
aspectLogCountTime
=
aspectL
ogCountTime
;
this
.
logCountTime
=
l
ogCountTime
;
}
/**
...
...
@@ -40,7 +41,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
);
aspectL
ogCountTime
.
start
(
fullUrl
);
l
ogCountTime
.
start
(
fullUrl
);
String
body
=
aspectLogBody
.
getBodyString
(
requestBody
);
if
(
logFlag
)
{
...
...
yzg-util-db/src/main/java/com/yanzuoguang/db/impl/DbExecuteImpl.java
View file @
ba8c27ef
...
...
@@ -2,6 +2,7 @@ package com.yanzuoguang.db.impl;
import
com.yanzuoguang.db.ConfigDb
;
import
com.yanzuoguang.db.DbExecute
;
import
com.yanzuoguang.log.LogCountTime
;
import
com.yanzuoguang.util.helper.YzgTimeout
;
import
com.yanzuoguang.util.vo.MapRow
;
import
com.yanzuoguang.util.vo.Ref
;
...
...
@@ -24,11 +25,13 @@ public class DbExecuteImpl implements DbExecute {
private
final
JdbcTemplate
jdbcTemplate
;
private
final
DbPrintSql
printSql
;
private
final
ConfigDb
configDb
;
private
final
LogCountTime
logCountTime
;
public
DbExecuteImpl
(
JdbcTemplate
jdbcTemplate
,
DbPrintSql
printSql
,
ConfigDb
configDb
)
{
public
DbExecuteImpl
(
JdbcTemplate
jdbcTemplate
,
DbPrintSql
printSql
,
ConfigDb
configDb
,
LogCountTime
logCountTime
)
{
this
.
jdbcTemplate
=
jdbcTemplate
;
this
.
printSql
=
printSql
;
this
.
configDb
=
configDb
;
this
.
logCountTime
=
logCountTime
;
}
public
JdbcTemplate
getJdbc
()
{
...
...
@@ -151,12 +154,21 @@ public class DbExecuteImpl implements DbExecute {
Ref
<
Integer
>
row
=
new
Ref
<>(
0
);
long
start
=
System
.
currentTimeMillis
();
sqlInfo
.
setSql
(
this
.
handleParas
(
sqlInfo
.
getSql
()));
String
fullUrl
=
String
.
format
(
"Sql:%s:%s"
,
sqlInfo
.
getTargetClass
().
getSimpleName
(),
sqlInfo
.
getSqlName
());
logCountTime
.
start
(
fullUrl
);
boolean
isError
=
false
;
try
{
YzgTimeout
.
timeOut
(
sqlInfo
.
getTargetClass
(),
sqlInfo
.
getSqlName
(),
()
->
{
sqlFunction
.
accept
(
row
,
start
);
});
}
catch
(
Exception
ex
)
{
isError
=
true
;
throw
ex
;
}
finally
{
printSql
.
print
(
sqlInfo
,
start
,
row
.
value
);
long
time
=
System
.
currentTimeMillis
()
-
start
;
logCountTime
.
finish
(
fullUrl
,
time
,
isError
);
printSql
.
print
(
sqlInfo
,
time
,
row
.
value
);
}
}
...
...
yzg-util-db/src/main/java/com/yanzuoguang/db/impl/DbPrintSql.java
View file @
ba8c27ef
...
...
@@ -64,10 +64,10 @@ public class DbPrintSql {
* 打印SQL语句
*
* @param sqlInfo sql语句嘻嘻你
* @param
start 开始执行的语句
* @param
time 执行的时间
* @param row SQL语句
*/
public
void
print
(
SqlInfo
sqlInfo
,
long
start
,
int
row
)
{
public
void
print
(
SqlInfo
sqlInfo
,
long
time
,
int
row
)
{
try
{
// 日志表忽略打印
if
(!
configDb
.
isPrintSql
())
{
...
...
@@ -79,8 +79,6 @@ public class DbPrintSql {
}
}
String
sql
=
getStringSql
(
sqlInfo
.
getSql
(),
sqlInfo
.
getParas
());
long
end
=
System
.
currentTimeMillis
();
long
time
=
end
-
start
;
// 打印SQL语句
String
tag
=
String
.
format
(
"%d row %d ms %s.%s"
,
row
,
time
,
sqlInfo
.
getTargetClass
().
getSimpleName
(),
sqlInfo
.
getSqlName
());
Log
.
infoTag
(
DbPrintSql
.
class
,
tag
,
sql
);
...
...
yzg-util-db/src/main/java/com/yanzuoguang/log/LogConfig.java
0 → 100644
View file @
ba8c27ef
package
com
.
yanzuoguang
.
log
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
/**
* 整个模块的所有配置信息
*
* @author 颜佐光
*/
@Component
public
class
LogConfig
{
public
static
final
int
DEFAULT_PRINT_TIME
=
2
*
60
*
1000
;
/**
* 外网地址
*/
@Value
(
"${yzg.log.print.time:"
+
DEFAULT_PRINT_TIME
+
"}"
)
private
int
logCountTime
;
public
int
getLogCountTime
()
{
return
logCountTime
;
}
}
yzg-util-
cloud/src/main/java/com/yanzuoguang/cloud/aop/Aspect
LogCountTime.java
→
yzg-util-
db/src/main/java/com/yanzuoguang/log/
LogCountTime.java
View file @
ba8c27ef
package
com
.
yanzuoguang
.
cloud
.
aop
;
package
com
.
yanzuoguang
.
log
;
import
com.yanzuoguang.util.cache.MemoryCache
;
import
com.yanzuoguang.util.helper.DateHelper
;
...
...
@@ -11,14 +11,14 @@ import org.springframework.stereotype.Component;
* @author 颜佐光
*/
@Component
public
class
Aspect
LogCountTime
{
public
class
LogCountTime
{
private
static
final
String
URL_PARA_START
=
"?"
;
/**
* 今日缓存,超过时间会自动清空
*/
private
final
MemoryCache
<
Aspect
UrlCountVo
>
todayMemoryCache
=
new
MemoryCache
<>();
private
final
MemoryCache
<
Log
UrlCountVo
>
todayMemoryCache
=
new
MemoryCache
<>();
/**
* 今日日期
*/
...
...
@@ -28,7 +28,7 @@ public class AspectLogCountTime {
*/
private
String
todayTime
;
public
MemoryCache
<
Aspect
UrlCountVo
>
getTodayMemoryCache
()
{
public
MemoryCache
<
Log
UrlCountVo
>
getTodayMemoryCache
()
{
return
todayMemoryCache
;
}
...
...
@@ -56,14 +56,14 @@ public class AspectLogCountTime {
* @param url 地址
* @return 缓存对象
*/
private
Aspect
UrlCountVo
getCount
(
String
url
)
{
private
Log
UrlCountVo
getCount
(
String
url
)
{
// 初始化日期
initToday
();
if
(
url
.
contains
(
URL_PARA_START
))
{
url
=
url
.
substring
(
0
,
url
.
indexOf
(
URL_PARA_START
));
}
// 缓存中获取对象
Aspect
UrlCountVo
ret
=
todayMemoryCache
.
get
(
url
);
Log
UrlCountVo
ret
=
todayMemoryCache
.
get
(
url
);
if
(
ret
!=
null
)
{
return
ret
;
}
...
...
@@ -73,7 +73,7 @@ public class AspectLogCountTime {
if
(
ret
!=
null
)
{
return
ret
;
}
ret
=
new
Aspect
UrlCountVo
(
url
);
ret
=
new
Log
UrlCountVo
(
url
);
todayMemoryCache
.
put
(
url
,
ret
);
return
ret
;
}
...
...
@@ -85,7 +85,7 @@ public class AspectLogCountTime {
* @param url 请求地址
*/
public
void
start
(
String
url
)
{
Aspect
UrlCountVo
count
=
getCount
(
url
);
Log
UrlCountVo
count
=
getCount
(
url
);
count
.
addStart
();
}
...
...
@@ -97,7 +97,7 @@ public class AspectLogCountTime {
* @param isError 是否错误
*/
public
void
finish
(
String
url
,
long
time
,
boolean
isError
)
{
Aspect
UrlCountVo
count
=
getCount
(
url
);
Log
UrlCountVo
count
=
getCount
(
url
);
count
.
addFinish
(
time
,
isError
);
}
}
yzg-util-
cloud/src/main/java/com/yanzuoguang/cloud/aop/Aspect
LogPrint.java
→
yzg-util-
db/src/main/java/com/yanzuoguang/log/
LogPrint.java
View file @
ba8c27ef
package
com
.
yanzuoguang
.
cloud
.
aop
;
package
com
.
yanzuoguang
.
log
;
import
com.yanzuoguang.cloud.CloudConfig
;
import
com.yanzuoguang.util.base.CollectionString
;
import
com.yanzuoguang.util.thread.ThreadNext
;
import
org.springframework.beans.factory.InitializingBean
;
...
...
@@ -17,14 +16,14 @@ import java.util.List;
* @author 颜佐光
*/
@Component
public
class
Aspect
LogPrint
implements
ThreadNext
.
Next
,
InitializingBean
{
public
class
LogPrint
implements
ThreadNext
.
Next
,
InitializingBean
{
private
final
CloudConfig
cloud
Config
;
private
final
AspectLogCountTime
aspectL
ogCountTime
;
private
final
LogConfig
log
Config
;
private
final
LogCountTime
l
ogCountTime
;
public
AspectLogPrint
(
CloudConfig
cloudConfig
,
AspectLogCountTime
aspectL
ogCountTime
)
{
this
.
cloudConfig
=
cloud
Config
;
this
.
aspectLogCountTime
=
aspectL
ogCountTime
;
public
LogPrint
(
LogConfig
logConfig
,
LogCountTime
l
ogCountTime
)
{
this
.
logConfig
=
log
Config
;
this
.
logCountTime
=
l
ogCountTime
;
}
@Override
...
...
@@ -35,22 +34,22 @@ public class AspectLogPrint implements ThreadNext.Next, InitializingBean {
@Override
public
boolean
next
()
{
List
<
AspectUrlCountVo
>
rowList
=
new
ArrayList
<>(
aspectL
ogCountTime
.
getTodayMemoryCache
().
getValues
());
List
<
LogUrlCountVo
>
rowList
=
new
ArrayList
<>(
l
ogCountTime
.
getTodayMemoryCache
().
getValues
());
if
(
rowList
.
isEmpty
())
{
return
true
;
}
// 按照使用总时间升序排序
rowList
.
sort
(
Comparator
.
comparingLong
(
Aspect
UrlCountVo:
:
getTotalTime
));
rowList
.
sort
(
Comparator
.
comparingLong
(
Log
UrlCountVo:
:
getTotalTime
));
// 逆转排序
Collections
.
reverse
(
rowList
);
// 打印日志
System
.
out
.
println
(
CollectionString
.
getCollectionString
(
"
接口从"
+
aspectL
ogCountTime
.
getTodayTime
()
+
"时执行次数:"
,
rowList
));
System
.
out
.
println
(
CollectionString
.
getCollectionString
(
"
从"
+
l
ogCountTime
.
getTodayTime
()
+
"时执行次数:"
,
rowList
));
// 下次继续执行
return
true
;
}
@Override
public
int
getNextTime
()
{
return
cloud
Config
.
getLogCountTime
();
return
log
Config
.
getLogCountTime
();
}
}
yzg-util-
cloud/src/main/java/com/yanzuoguang/cloud/aop/Aspect
UrlCountVo.java
→
yzg-util-
db/src/main/java/com/yanzuoguang/log/Log
UrlCountVo.java
View file @
ba8c27ef
package
com
.
yanzuoguang
.
cloud
.
aop
;
package
com
.
yanzuoguang
.
log
;
/**
* 次数统计
*
* @author 颜佐光
*/
public
class
Aspect
UrlCountVo
{
public
class
Log
UrlCountVo
{
private
final
Object
lockStart
=
new
Object
();
private
final
Object
lockFinish
=
new
Object
();
...
...
@@ -18,7 +18,7 @@ public class AspectUrlCountVo {
private
volatile
long
minTime
=
Long
.
MAX_VALUE
;
private
volatile
long
maxTime
;
public
Aspect
UrlCountVo
(
String
url
)
{
public
Log
UrlCountVo
(
String
url
)
{
this
.
url
=
url
;
}
...
...
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