Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
bailuntec-cost
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
huluobin
bailuntec-cost
Commits
fdba55ed
Commit
fdba55ed
authored
Aug 06, 2021
by
liyanlin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加全局请求日志
parent
8e506de9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
177 additions
and
0 deletions
+177
-0
pom.xml
cost-service/pom.xml
+11
-0
UserAgentUtil.java
...rc/main/java/com/blt/other/common/util/UserAgentUtil.java
+30
-0
RequestBakRequestWrapper.java
...om/blt/other/common/wrapper/RequestBakRequestWrapper.java
+24
-0
OperationLogDao.java
...in/java/com/blt/other/module/log/dao/OperationLogDao.java
+13
-0
OperationLog.java
...ain/java/com/blt/other/module/log/model/OperationLog.java
+46
-0
OperationLogService.java
...com/blt/other/module/log/service/OperationLogService.java
+13
-0
OperationLogServiceImpl.java
...ther/module/log/service/impl/OperationLogServiceImpl.java
+32
-0
application-dev.yml
cost-service/src/main/resources/application-dev.yml
+4
-0
application-prod.yml
cost-service/src/main/resources/application-prod.yml
+4
-0
No files found.
cost-service/pom.xml
View file @
fdba55ed
...
@@ -165,6 +165,11 @@
...
@@ -165,6 +165,11 @@
<artifactId>
spring-boot-starter
</artifactId>
<artifactId>
spring-boot-starter
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-mongodb
</artifactId>
</dependency>
<!--mp 增加Mybatis-->
<!--mp 增加Mybatis-->
<dependency>
<dependency>
<groupId>
com.baomidou
</groupId>
<groupId>
com.baomidou
</groupId>
...
@@ -309,6 +314,12 @@
...
@@ -309,6 +314,12 @@
<version>
1.8.1
</version>
<version>
1.8.1
</version>
</dependency>
</dependency>
<dependency>
<groupId>
eu.bitwalker
</groupId>
<artifactId>
UserAgentUtils
</artifactId>
<version>
1.21
</version>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
cost-service/src/main/java/com/blt/other/common/util/UserAgentUtil.java
0 → 100644
View file @
fdba55ed
package
com
.
blt
.
other
.
common
.
util
;
import
eu.bitwalker.useragentutils.Browser
;
import
eu.bitwalker.useragentutils.OperatingSystem
;
import
eu.bitwalker.useragentutils.UserAgent
;
/**
* @Author: li.yanlin
* @Description:
* @Date: Created in
* @Modified by:
*/
public
class
UserAgentUtil
{
public
static
String
getDevice
(
String
userAgent
)
{
//解析agent字符串
UserAgent
ua
=
UserAgent
.
parseUserAgentString
(
userAgent
);
//获取浏览器对象
Browser
browser
=
ua
.
getBrowser
();
//获取操作系统对象
OperatingSystem
os
=
ua
.
getOperatingSystem
();
return
String
.
format
(
"设备类型:%s,操作系统:%s,浏览器:%s,浏览器版本:%s,浏览器引擎:%s,用户代理(User-Agent):[%s]"
,
os
.
getDeviceType
(),
os
.
getName
(),
browser
.
getName
(),
browser
.
getVersion
(
userAgent
),
browser
.
getRenderingEngine
(),
userAgent
);
}
}
cost-service/src/main/java/com/blt/other/common/wrapper/RequestBakRequestWrapper.java
View file @
fdba55ed
package
com
.
blt
.
other
.
common
.
wrapper
;
package
com
.
blt
.
other
.
common
.
wrapper
;
import
com.bailuntec.common.SpringContextUtil
;
import
com.blt.other.common.util.IpUtil
;
import
com.blt.other.common.util.UserAgentUtil
;
import
com.blt.other.module.log.model.OperationLog
;
import
com.blt.other.module.log.service.OperationLogService
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.BeanFactory
;
import
javax.annotation.Resource
;
import
javax.servlet.ServletInputStream
;
import
javax.servlet.ServletInputStream
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequestWrapper
;
import
javax.servlet.http.HttpServletRequestWrapper
;
...
@@ -24,6 +33,7 @@ public class RequestBakRequestWrapper extends HttpServletRequestWrapper {
...
@@ -24,6 +33,7 @@ public class RequestBakRequestWrapper extends HttpServletRequestWrapper {
private
Map
<
String
,
String
[]>
parameterMap
;
private
Map
<
String
,
String
[]>
parameterMap
;
/**
/**
* 对request中的流进行备份
* 对request中的流进行备份
*
*
...
@@ -44,6 +54,20 @@ public class RequestBakRequestWrapper extends HttpServletRequestWrapper {
...
@@ -44,6 +54,20 @@ public class RequestBakRequestWrapper extends HttpServletRequestWrapper {
// 设置输入流为备份流
// 设置输入流为备份流
this
.
inputStream
=
new
RequestBakInputStream
(
new
ByteArrayInputStream
(
cachedContent
.
toByteArray
()));
this
.
inputStream
=
new
RequestBakInputStream
(
new
ByteArrayInputStream
(
cachedContent
.
toByteArray
()));
try
{
OperationLogService
logService
=
SpringContextUtil
.
getBean
(
OperationLogService
.
class
);
OperationLog
log
=
new
OperationLog
().
builder
()
.
sourceFrom
(
request
.
getHeader
(
"sourceFrom"
))
.
userId
(
request
.
getHeader
(
"userId"
))
.
ip
(
IpUtil
.
getIpAddr
(
request
))
.
userAgent
(
UserAgentUtil
.
getDevice
(
request
.
getHeader
(
"User-Agent"
)))
.
url
(
request
.
getRequestURI
())
.
input
(
cachedContent
.
toByteArray
())
.
build
();
logService
.
insert
(
log
);
}
catch
(
Exception
ex
){
ex
.
printStackTrace
();
}
}
}
@Override
@Override
...
...
cost-service/src/main/java/com/blt/other/module/log/dao/OperationLogDao.java
0 → 100644
View file @
fdba55ed
package
com
.
blt
.
other
.
module
.
log
.
dao
;
import
com.blt.other.module.log.model.OperationLog
;
import
org.springframework.data.mongodb.repository.MongoRepository
;
/**
* @Author: li.yanlin
* @Description:
* @Date: Created in
* @Modified by:
*/
public
interface
OperationLogDao
extends
MongoRepository
<
OperationLog
,
String
>
{
}
cost-service/src/main/java/com/blt/other/module/log/model/OperationLog.java
0 → 100644
View file @
fdba55ed
package
com
.
blt
.
other
.
module
.
log
.
model
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
org.bson.codecs.pojo.annotations.BsonId
;
import
org.bson.codecs.pojo.annotations.BsonIgnore
;
import
org.bson.types.ObjectId
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
org.springframework.data.mongodb.core.mapping.MongoId
;
import
java.io.Serializable
;
import
java.time.LocalDateTime
;
/**
* @Author: li.yanlin
* @Description:
* @Date: Created in
* @Modified by:
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Document
public
class
OperationLog
implements
Serializable
{
@MongoId
private
ObjectId
_id
;
private
String
userId
;
private
String
sourceFrom
;
private
String
ip
;
private
String
userAgent
;
private
String
url
;
private
byte
[]
input
;
private
LocalDateTime
createTime
;
}
cost-service/src/main/java/com/blt/other/module/log/service/OperationLogService.java
0 → 100644
View file @
fdba55ed
package
com
.
blt
.
other
.
module
.
log
.
service
;
import
com.blt.other.module.log.model.OperationLog
;
/**
* @Author: li.yanlin
* @Description:
* @Date: Created in
* @Modified by:
*/
public
interface
OperationLogService
{
public
void
insert
(
OperationLog
log
);
}
cost-service/src/main/java/com/blt/other/module/log/service/impl/OperationLogServiceImpl.java
0 → 100644
View file @
fdba55ed
package
com
.
blt
.
other
.
module
.
log
.
service
.
impl
;
import
com.blt.other.module.log.dao.OperationLogDao
;
import
com.blt.other.module.log.model.OperationLog
;
import
com.blt.other.module.log.service.OperationLogService
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.annotation.Resource
;
import
java.time.LocalDateTime
;
/**
* @Author: li.yanlin
* @Description:
* @Date: Created in
* @Modified by:
*/
@Service
@Transactional
public
class
OperationLogServiceImpl
implements
OperationLogService
{
@Resource
private
OperationLogDao
operationLogDao
;
@Override
@Async
public
void
insert
(
OperationLog
log
)
{
log
.
setCreateTime
(
LocalDateTime
.
now
());
operationLogDao
.
insert
(
log
);
}
}
cost-service/src/main/resources/application-dev.yml
View file @
fdba55ed
...
@@ -16,6 +16,10 @@ spring:
...
@@ -16,6 +16,10 @@ spring:
port
:
5672
port
:
5672
username
:
bailun
username
:
bailun
password
:
bailun2019
password
:
bailun2019
data
:
mongodb
:
uri
:
'
mongodb://admin:!%40#blt*mongo123@42.193.191.242:27018/?authSource=admin&readPreference=primary&appname=MongoDB%20Compass&ssl=false'
database
:
bailuntec-cost
# 前端配置
# 前端配置
...
...
cost-service/src/main/resources/application-prod.yml
View file @
fdba55ed
...
@@ -18,6 +18,10 @@ spring:
...
@@ -18,6 +18,10 @@ spring:
mandatory
:
true
mandatory
:
true
publisher-confirms
:
true
publisher-confirms
:
true
publisher-returns
:
true
publisher-returns
:
true
data
:
mongodb
:
uri
:
'
mongodb://admin:!%40#blt*mongo123@10.0.12.3:27018/?authSource=admin&readPreference=primary&appname=MongoDB%20Compass&ssl=false'
database
:
bailuntec-cost
thymeleaf
:
thymeleaf
:
prefix
:
classpath:/templates/
prefix
:
classpath:/templates/
...
...
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