Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cloud-backend
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
framework
cloud-backend
Commits
67b8c593
Commit
67b8c593
authored
Apr 26, 2021
by
袁伟铭
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.0.0
parent
77c5d960
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
19 additions
and
6 deletions
+19
-6
api-server/src/main/java/com/zq/api/ApiApplication.java
+3
-1
api-server/src/main/java/com/zq/api/controller/ApiController.java
+2
-1
api-server/src/main/java/com/zq/api/service/ApiService.java
+4
-1
common-utils/src/main/java/com/zq/common/entity/ApiLog.java
+6
-0
config/sql/init.sql
+4
-3
No files found.
api-server/src/main/java/com/zq/api/ApiApplication.java
View file @
67b8c593
package
com
.
zq
.
api
;
import
com.zq.common.config.security.SecurityProperties
;
import
com.zq.common.config.base.SpringContextHolder
;
import
com.zq.common.config.security.SecurityProperties
;
import
org.mybatis.spring.annotation.MapperScan
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
...
...
@@ -9,7 +9,9 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import
org.springframework.cloud.client.discovery.EnableDiscoveryClient
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.scheduling.annotation.EnableAsync
;
@EnableAsync
@EnableFeignClients
@MapperScan
(
"com.zq.api.dao"
)
@EnableDiscoveryClient
...
...
api-server/src/main/java/com/zq/api/controller/ApiController.java
View file @
67b8c593
...
...
@@ -106,7 +106,8 @@ public class ApiController {
+
"\n[time="
+
(
System
.
currentTimeMillis
()
-
start
)
+
"ms]"
);
}
apiService
.
addLog
(
form
,
logType
,
resp
.
getMsg
(),
errorInfo
,
System
.
currentTimeMillis
()
-
start
);
String
clientIP
=
ServletUtil
.
getClientIP
(
request
);
apiService
.
addLog
(
form
,
clientIP
,
logType
,
resp
.
getMsg
(),
errorInfo
,
System
.
currentTimeMillis
()
-
start
);
return
resp
;
}
...
...
api-server/src/main/java/com/zq/api/service/ApiService.java
View file @
67b8c593
...
...
@@ -11,6 +11,7 @@ import com.zq.common.entity.ApiLog;
import
com.zq.common.utils.DateUtils
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.scheduling.annotation.Async
;
import
org.springframework.stereotype.Service
;
import
java.lang.reflect.Method
;
...
...
@@ -66,13 +67,15 @@ public class ApiService {
return
(
ApiResp
)
ReflectionUtils
.
invokeMethod
(
apiLogic
,
form
.
getMethod
(),
new
Class
<?>[]{
ApiForm
.
class
},
new
Object
[]{
form
});
}
public
void
addLog
(
ApiForm
form
,
String
logType
,
String
respMsg
,
String
errorInfo
,
Long
timeCost
)
{
@Async
public
void
addLog
(
ApiForm
form
,
String
ip
,
String
logType
,
String
respMsg
,
String
errorInfo
,
Long
timeCost
)
{
apiLogDao
.
insert
(
ApiLog
.
builder
()
.
appId
(
form
.
getAppId
())
.
userId
(
form
.
getUserId
())
.
method
(
form
.
getMethod
())
.
version
(
form
.
getVersion
())
.
bizContent
(
form
.
getBizContent
())
.
ip
(
ip
)
.
logType
(
logType
)
.
respMsg
(
respMsg
)
.
errorInfo
(
errorInfo
)
...
...
common-utils/src/main/java/com/zq/common/entity/ApiLog.java
View file @
67b8c593
...
...
@@ -62,6 +62,12 @@ public class ApiLog {
private
String
bizContent
;
/**
* IP
*/
@ApiModelProperty
(
"IP"
)
private
String
ip
;
/**
* 日志类型
*/
@ApiModelProperty
(
"日志类型"
)
...
...
config/sql/init.sql
View file @
67b8c593
...
...
@@ -52,18 +52,19 @@ INSERT INTO `sys_config` VALUES (7, '腾讯云秘钥KEY', 'CLOUD.SECRET.KEY', 'S
DROP
TABLE
IF
EXISTS
`t_api_log`
;
CREATE
TABLE
`t_api_log`
(
`id`
bigint
(
20
)
NOT
NULL
AUTO_INCREMENT
COMMENT
'ID'
,
`app_id`
varchar
(
255
)
CHARACTER
SET
utf8mb4
COLLATE
utf8mb4_bin
NULL
DEFAULT
NULL
COMMENT
'APPID'
,
`user_id`
varchar
(
255
)
CHARACTER
SET
utf8mb4
COLLATE
utf8mb4_bin
NULL
DEFAULT
NULL
COMMENT
'用户ID'
,
`app_id`
varchar
(
255
)
CHARACTER
SET
utf8mb4
COLLATE
utf8mb4_bin
NULL
DEFAULT
''
COMMENT
'APPID'
,
`user_id`
varchar
(
255
)
CHARACTER
SET
utf8mb4
COLLATE
utf8mb4_bin
NULL
DEFAULT
''
COMMENT
'用户ID'
,
`method`
varchar
(
255
)
CHARACTER
SET
utf8mb4
COLLATE
utf8mb4_bin
NULL
DEFAULT
NULL
COMMENT
'调用方法'
,
`version`
varchar
(
255
)
CHARACTER
SET
utf8mb4
COLLATE
utf8mb4_bin
NULL
DEFAULT
NULL
COMMENT
'版本号'
,
`biz_content`
text
CHARACTER
SET
utf8mb4
COLLATE
utf8mb4_bin
NULL
COMMENT
'业务参数'
,
`ip`
varchar
(
255
)
CHARACTER
SET
utf8mb4
COLLATE
utf8mb4_bin
NULL
DEFAULT
NULL
COMMENT
'IP'
,
`log_type`
varchar
(
255
)
CHARACTER
SET
utf8mb4
COLLATE
utf8mb4_bin
NULL
DEFAULT
NULL
COMMENT
'日志类型'
,
`resp_msg`
varchar
(
255
)
CHARACTER
SET
utf8mb4
COLLATE
utf8mb4_bin
NULL
DEFAULT
NULL
COMMENT
'响应信息'
,
`error_info`
longtext
CHARACTER
SET
utf8mb4
COLLATE
utf8mb4_bin
NULL
COMMENT
'错误信息'
,
`time_cost`
varchar
(
255
)
CHARACTER
SET
utf8mb4
COLLATE
utf8mb4_bin
NULL
DEFAULT
NULL
COMMENT
'耗时-毫秒'
,
`create_time`
datetime
(
0
)
NULL
DEFAULT
NULL
COMMENT
'创建时间'
,
PRIMARY
KEY
(
`id`
)
USING
BTREE
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
3
CHARACTER
SET
=
utf8mb4
COLLATE
=
utf8mb4_bin
ROW_FORMAT
=
Dynamic
;
)
ENGINE
=
InnoDB
AUTO_INCREMENT
=
1
CHARACTER
SET
=
utf8mb4
COLLATE
=
utf8mb4_bin
COMMENT
=
'api调用记录'
ROW_FORMAT
=
Dynamic
;
-- ----------------------------
-- Records of t_api_log
...
...
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