Commit 67b8c593 by 袁伟铭

1.0.0

parent 77c5d960
package com.zq.api; package com.zq.api;
import com.zq.common.config.security.SecurityProperties;
import com.zq.common.config.base.SpringContextHolder; import com.zq.common.config.base.SpringContextHolder;
import com.zq.common.config.security.SecurityProperties;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
...@@ -9,7 +9,9 @@ import org.springframework.boot.context.properties.ConfigurationProperties; ...@@ -9,7 +9,9 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;
@EnableAsync
@EnableFeignClients @EnableFeignClients
@MapperScan("com.zq.api.dao") @MapperScan("com.zq.api.dao")
@EnableDiscoveryClient @EnableDiscoveryClient
......
...@@ -106,7 +106,8 @@ public class ApiController { ...@@ -106,7 +106,8 @@ public class ApiController {
+ "\n[time=" + (System.currentTimeMillis() - start) + "ms]"); + "\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; return resp;
} }
......
...@@ -11,6 +11,7 @@ import com.zq.common.entity.ApiLog; ...@@ -11,6 +11,7 @@ import com.zq.common.entity.ApiLog;
import com.zq.common.utils.DateUtils; import com.zq.common.utils.DateUtils;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.lang.reflect.Method; import java.lang.reflect.Method;
...@@ -66,13 +67,15 @@ public class ApiService { ...@@ -66,13 +67,15 @@ public class ApiService {
return (ApiResp) ReflectionUtils.invokeMethod(apiLogic, form.getMethod(), new Class<?>[]{ApiForm.class}, new Object[]{form}); 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() apiLogDao.insert(ApiLog.builder()
.appId(form.getAppId()) .appId(form.getAppId())
.userId(form.getUserId()) .userId(form.getUserId())
.method(form.getMethod()) .method(form.getMethod())
.version(form.getVersion()) .version(form.getVersion())
.bizContent(form.getBizContent()) .bizContent(form.getBizContent())
.ip(ip)
.logType(logType) .logType(logType)
.respMsg(respMsg) .respMsg(respMsg)
.errorInfo(errorInfo) .errorInfo(errorInfo)
......
...@@ -62,6 +62,12 @@ public class ApiLog { ...@@ -62,6 +62,12 @@ public class ApiLog {
private String bizContent; private String bizContent;
/** /**
* IP
*/
@ApiModelProperty("IP")
private String ip;
/**
* 日志类型 * 日志类型
*/ */
@ApiModelProperty("日志类型") @ApiModelProperty("日志类型")
......
...@@ -52,18 +52,19 @@ INSERT INTO `sys_config` VALUES (7, '腾讯云秘钥KEY', 'CLOUD.SECRET.KEY', 'S ...@@ -52,18 +52,19 @@ INSERT INTO `sys_config` VALUES (7, '腾讯云秘钥KEY', 'CLOUD.SECRET.KEY', 'S
DROP TABLE IF EXISTS `t_api_log`; DROP TABLE IF EXISTS `t_api_log`;
CREATE TABLE `t_api_log` ( CREATE TABLE `t_api_log` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID', `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
`app_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL COMMENT 'APPID', `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 NULL COMMENT '用户ID', `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 '调用方法', `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 '版本号', `version` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL COMMENT '版本号',
`biz_content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin 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 '日志类型', `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 '响应信息', `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 '错误信息', `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 '耗时-毫秒', `time_cost` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NULL DEFAULT NULL COMMENT '耗时-毫秒',
`create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间', `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
PRIMARY KEY (`id`) USING BTREE 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 -- Records of t_api_log
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment