Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
brandkbs2
Overview
Overview
Details
Activity
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
shenjunjie
brandkbs2
Commits
f85f39f3
Commit
f85f39f3
authored
Mar 29, 2023
by
shenjunjie
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature' into 'dev'
权限部分调整6 See merge request
!285
parents
05e95b48
8f7d2c14
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
2 deletions
+13
-2
src/main/java/com/zhiwei/brandkbs2/aop/AopLogRecord.java
+13
-2
No files found.
src/main/java/com/zhiwei/brandkbs2/aop/AopLogRecord.java
View file @
f85f39f3
...
@@ -16,6 +16,8 @@ import io.swagger.annotations.Api;
...
@@ -16,6 +16,8 @@ import io.swagger.annotations.Api;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.collections4.CollectionUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.annotation.AfterReturning
;
import
org.aspectj.lang.annotation.AfterReturning
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Aspect
;
...
@@ -31,7 +33,6 @@ import javax.servlet.ServletRequest;
...
@@ -31,7 +33,6 @@ import javax.servlet.ServletRequest;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
java.net.InetAddress
;
import
java.net.InetAddress
;
import
java.net.UnknownHostException
;
import
java.util.*
;
import
java.util.*
;
import
static
java
.
util
.
Objects
.
nonNull
;
import
static
java
.
util
.
Objects
.
nonNull
;
...
@@ -45,6 +46,8 @@ import static java.util.Objects.nonNull;
...
@@ -45,6 +46,8 @@ import static java.util.Objects.nonNull;
@Aspect
@Aspect
@Component
@Component
public
class
AopLogRecord
{
public
class
AopLogRecord
{
public
static
final
Logger
log
=
LogManager
.
getLogger
(
AopLogRecord
.
class
);
@Value
(
"${jwt.key}"
)
@Value
(
"${jwt.key}"
)
private
String
jwtKey
;
private
String
jwtKey
;
@Resource
(
name
=
"userServiceImpl"
)
@Resource
(
name
=
"userServiceImpl"
)
...
@@ -58,7 +61,8 @@ public class AopLogRecord {
...
@@ -58,7 +61,8 @@ public class AopLogRecord {
private
static
final
List
<
String
>
URL_PATTERNS
=
Arrays
.
asList
(
"/getNewAll"
,
"/getNew"
,
"/schedule"
);
private
static
final
List
<
String
>
URL_PATTERNS
=
Arrays
.
asList
(
"/getNewAll"
,
"/getNew"
,
"/schedule"
);
@AfterReturning
(
value
=
"execution(public * com..controller..admin..*Controller.*(..)) || execution(* com..controller..app..*Controller.*(..)) || execution(* com..controller..LoginController.checkBind())"
,
returning
=
"ResponseResult"
)
@AfterReturning
(
value
=
"execution(public * com..controller..admin..*Controller.*(..)) || execution(* com..controller..app..*Controller.*(..)) || execution(* com..controller..LoginController.checkBind())"
,
returning
=
"ResponseResult"
)
private
void
beforeLog
(
JoinPoint
joinPoint
,
ResponseResult
ResponseResult
)
throws
UnknownHostException
,
ClassNotFoundException
{
private
void
beforeLog
(
JoinPoint
joinPoint
,
ResponseResult
ResponseResult
){
try
{
long
now
=
System
.
currentTimeMillis
();
long
now
=
System
.
currentTimeMillis
();
// RequestContextHolder 顾名思义 持有 request 上下文的容器
// RequestContextHolder 顾名思义 持有 request 上下文的容器
ServletRequestAttributes
requestAttributes
=
(
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
();
ServletRequestAttributes
requestAttributes
=
(
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
();
...
@@ -94,6 +98,10 @@ public class AopLogRecord {
...
@@ -94,6 +98,10 @@ public class AopLogRecord {
String
userId
=
userIdObj
.
toString
();
String
userId
=
userIdObj
.
toString
();
String
projectId
=
request
.
getHeader
(
"pid"
);
String
projectId
=
request
.
getHeader
(
"pid"
);
UserInfo
userInfo
=
userService
.
queryUserInfo
(
userId
,
projectId
);
UserInfo
userInfo
=
userService
.
queryUserInfo
(
userId
,
projectId
);
if
(
null
==
userInfo
)
{
log
.
info
(
"userInfo为null,map:{},userId:{},projectId:{}"
,
JSONObject
.
toJSONString
(
map
),
request
.
getHeader
(
jwtKey
),
request
.
getHeader
(
"pid"
));
return
;
}
String
nickName
=
userInfo
.
getNickname
();
String
nickName
=
userInfo
.
getNickname
();
// 请求地址和服务器地址
// 请求地址和服务器地址
String
severAddress
=
InetAddress
.
getLocalHost
().
getHostAddress
();
String
severAddress
=
InetAddress
.
getLocalHost
().
getHostAddress
();
...
@@ -110,6 +118,9 @@ public class AopLogRecord {
...
@@ -110,6 +118,9 @@ public class AopLogRecord {
behaviorDao
.
insertOneWithoutId
(
behavior
,
collectionName
);
behaviorDao
.
insertOneWithoutId
(
behavior
,
collectionName
);
}
}
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
"beforeLog"
,
e
);
}
}
}
private
UserLogRecord
userLogRecord
(
String
projectId
,
UserInfo
userInfo
,
JoinPoint
joinPoint
,
MethodSignature
methodSignature
,
ResponseResult
responseResult
)
{
private
UserLogRecord
userLogRecord
(
String
projectId
,
UserInfo
userInfo
,
JoinPoint
joinPoint
,
MethodSignature
methodSignature
,
ResponseResult
responseResult
)
{
...
...
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