Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
O
oms
Project
Project
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
曲欣亮
oms
Commits
a48b99e0
Commit
a48b99e0
authored
Mar 09, 2020
by
Quxl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
x
parent
36ab5c1f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
101 additions
and
97 deletions
+101
-97
OmsApplication.java
src/main/java/com/egolm/oms/OmsApplication.java
+43
-41
LogInterceptor.java
...java/com/egolm/oms/config/interceptor/LogInterceptor.java
+58
-56
No files found.
src/main/java/com/egolm/oms/OmsApplication.java
View file @
a48b99e0
package
com
.
egolm
.
oms
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
@EnableCaching
@EnableSwagger2
@SpringBootApplication
@EnableTransactionManagement
public
class
OmsApplication
{
private
static
ApplicationContext
applicationContext
;
public
static
void
main
(
String
[]
args
)
{
System
.
setProperty
(
"java.io.tmpdir"
,
"temp"
);
applicationContext
=
SpringApplication
.
run
(
OmsApplication
.
class
,
args
);
}
public
static
ApplicationContext
getApplicationContext
()
{
return
applicationContext
;
}
public
static
Object
getBean
(
String
name
){
return
getApplicationContext
().
getBean
(
name
);
}
public
static
<
T
>
T
getBean
(
Class
<
T
>
clazz
){
return
getApplicationContext
().
getBean
(
clazz
);
}
public
static
<
T
>
T
getBean
(
String
name
,
Class
<
T
>
clazz
){
return
getApplicationContext
().
getBean
(
name
,
clazz
);
}
}
package
com
.
egolm
.
oms
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.scheduling.annotation.EnableAsync
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
import
springfox.documentation.swagger2.annotations.EnableSwagger2
;
@EnableAsync
@EnableCaching
@EnableSwagger2
@SpringBootApplication
@EnableTransactionManagement
public
class
OmsApplication
{
private
static
ApplicationContext
applicationContext
;
public
static
void
main
(
String
[]
args
)
{
System
.
setProperty
(
"java.io.tmpdir"
,
"temp"
);
applicationContext
=
SpringApplication
.
run
(
OmsApplication
.
class
,
args
);
}
public
static
ApplicationContext
getApplicationContext
()
{
return
applicationContext
;
}
public
static
Object
getBean
(
String
name
){
return
getApplicationContext
().
getBean
(
name
);
}
public
static
<
T
>
T
getBean
(
Class
<
T
>
clazz
){
return
getApplicationContext
().
getBean
(
clazz
);
}
public
static
<
T
>
T
getBean
(
String
name
,
Class
<
T
>
clazz
){
return
getApplicationContext
().
getBean
(
name
,
clazz
);
}
}
src/main/java/com/egolm/oms/config/interceptor/LogInterceptor.java
View file @
a48b99e0
package
com
.
egolm
.
oms
.
config
.
interceptor
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.servlet.handler.HandlerInterceptorAdapter
;
import
com.alibaba.fastjson.JSON
;
import
com.egolm.common.jdbc.JdbcTemplate
;
import
com.egolm.common.web.ServletUtil
;
@Component
public
class
LogInterceptor
extends
HandlerInterceptorAdapter
{
@Value
(
"${log.isOpen}"
)
private
Boolean
isOpen
;
@Override
public
boolean
preHandle
(
HttpServletRequest
req
,
HttpServletResponse
resp
,
Object
handler
)
throws
Exception
{
this
.
exec
(
req
);
return
super
.
preHandle
(
req
,
resp
,
handler
);
}
@Autowired
@Qualifier
(
"log"
)
private
JdbcTemplate
jdbcTemplate
;
private
void
exec
(
HttpServletRequest
req
)
{
if
(
isOpen
)
{
try
{
String
contextPath
=
req
.
getContextPath
();
String
uri
=
req
.
getRequestURI
().
substring
(
contextPath
.
length
());
String
remoteIp
=
ServletUtil
.
remoteIp
(
req
);
String
params
=
JSON
.
toJSONString
(
req
.
getParameterMap
());
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
map
.
put
(
"sProjectID"
,
"ORDER"
);
map
.
put
(
"sURI"
,
uri
);
map
.
put
(
"sClientIP"
,
remoteIp
);
map
.
put
(
"sParams"
,
params
);
map
.
put
(
"dCreateTime"
,
new
Date
());
jdbcTemplate
.
save
(
"tLog"
,
map
);
}
catch
(
Throwable
e
)
{
e
.
printStackTrace
();
}
}
}
}
package
com
.
egolm
.
oms
.
config
.
interceptor
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.Map
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.servlet.handler.HandlerInterceptorAdapter
;
import
com.alibaba.fastjson.JSON
;
import
com.egolm.common.jdbc.JdbcTemplate
;
import
com.egolm.common.web.ServletUtil
;
@Component
public
class
LogInterceptor
extends
HandlerInterceptorAdapter
{
@Value
(
"${log.isOpen}"
)
private
Boolean
isOpen
;
@Override
public
boolean
preHandle
(
HttpServletRequest
req
,
HttpServletResponse
resp
,
Object
handler
)
throws
Exception
{
this
.
exec
(
req
);
return
super
.
preHandle
(
req
,
resp
,
handler
);
}
@Autowired
@Qualifier
(
"log"
)
private
JdbcTemplate
jdbcTemplate
;
@Async
private
void
exec
(
HttpServletRequest
req
)
{
if
(
isOpen
)
{
try
{
String
contextPath
=
req
.
getContextPath
();
String
uri
=
req
.
getRequestURI
().
substring
(
contextPath
.
length
());
String
remoteIp
=
ServletUtil
.
remoteIp
(
req
);
String
params
=
JSON
.
toJSONString
(
req
.
getParameterMap
());
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
map
.
put
(
"sProjectID"
,
"ORDER"
);
map
.
put
(
"sURI"
,
uri
);
map
.
put
(
"sClientIP"
,
remoteIp
);
map
.
put
(
"sParams"
,
params
);
map
.
put
(
"dCreateTime"
,
new
Date
());
jdbcTemplate
.
save
(
"tLog"
,
map
);
}
catch
(
Throwable
e
)
{
e
.
printStackTrace
();
}
}
}
}
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