🚨 删除api_access_log

This commit is contained in:
b2baccline
2020-06-03 20:46:43 +08:00
parent 2e7961a6d5
commit 409d001d7b
13 changed files with 5 additions and 444 deletions

View File

@@ -1,62 +0,0 @@
package com.hccake.ballcat.admin.modules.log.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hccake.ballcat.common.modules.log.model.entity.ApiAccessLog;
import com.hccake.ballcat.common.modules.log.service.ApiAccessLogService;
import com.hccake.ballcat.common.core.result.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 访问日志
*
* @author hccake
* @date 2019-10-16 16:09:25
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/log/apiaccesslog")
@Api(value = "/log/apiaccesslog", tags = "访问日志管理")
public class ApiAccessLogController {
private final ApiAccessLogService apiAccessLogService;
/**
* 分页查询
*
* @param page 分页对象
* @param apiAccessLog 访问日志
* @return
*/
@ApiOperation(value = "分页查询", notes = "分页查询")
@GetMapping("/page")
@PreAuthorize("@per.hasPermission('log:apiaccesslog:read')")
public R<IPage<ApiAccessLog>> getAccessLogApiPage(
Page<ApiAccessLog> page, ApiAccessLog apiAccessLog) {
return R.ok(apiAccessLogService.page(page, Wrappers.query(apiAccessLog)));
}
/**
* 通过id查询访问日志
*
* @param id id
* @return R
*/
@ApiOperation(value = "通过id查询", notes = "通过id查询")
@GetMapping("/{id}")
@PreAuthorize("@per.hasPermission('log:apiaccesslog:read')")
public R<ApiAccessLog> getById(@PathVariable("id") Long id) {
return R.ok(apiAccessLogService.getById(id));
}
}

View File

@@ -1,6 +1,5 @@
package com.hccake.ballcat.api;
import com.hccake.ballcat.commom.log.access.annotation.EnableAccessLog;
import com.hccake.ballcat.common.job.annotation.EnableXxlJob;
import com.hccake.ballcat.common.swagger.annotation.EnableSwagger2Provider;
import org.mybatis.spring.annotation.MapperScan;
@@ -9,7 +8,6 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@EnableXxlJob
@EnableSwagger2Provider
@EnableAccessLog
@SpringBootApplication
@MapperScan(basePackages = {"com.hccake.ballcat.**.mapper"})
public class ApiApplication {

View File

@@ -1,12 +1,7 @@
package com.hccake.ballcat.api.modules.api.controller;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hccake.ballcat.common.modules.log.model.entity.ApiAccessLog;
import com.hccake.ballcat.common.modules.log.service.ApiAccessLogService;
import com.hccake.ballcat.common.core.exception.BusinessException;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDate;
@@ -19,9 +14,7 @@ import java.time.LocalDateTime;
*/
@RequestMapping
@RestController
@RequiredArgsConstructor
public class TestController {
private final ApiAccessLogService apiAccessLogService;
@ApiOperation("测试地址")
@@ -37,17 +30,6 @@ public class TestController {
}
@GetMapping("/test/page")
public String page(){
apiAccessLogService.page(new Page<>(), Wrappers.<ApiAccessLog>query().eq("id", 1));
apiAccessLogService.page(new Page<>(), Wrappers.<ApiAccessLog>lambdaQuery().eq(ApiAccessLog::getId, 1));
return "Hello word!";
}
@PostMapping("/formdata")
public String test1(@RequestParam("formdata")String formdata){
return formdata;

View File

@@ -1,75 +0,0 @@
package com.hccake.ballcat.api.modules.log.service;
import cn.hutool.core.util.URLUtil;
import cn.hutool.json.JSONUtil;
import com.hccake.ballcat.common.modules.log.model.entity.ApiAccessLog;
import com.hccake.ballcat.api.modules.log.thread.ApiAccessLogSaveThread;
import com.hccake.ballcat.commom.log.access.handler.AccessLogHandler;
import com.hccake.ballcat.commom.log.util.LogUtils;
import com.hccake.ballcat.common.core.util.IPUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.HandlerMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDateTime;
import java.util.Optional;
/**
* 访问日志
*
* @author hccake
* @date 2019-10-16 16:09:25
*/
@Slf4j
@Service
@RequiredArgsConstructor
public class ApiAccessLogHandler implements AccessLogHandler<ApiAccessLog> {
private final ApiAccessLogSaveThread apiAccessLogSaveThread;
/**
* 生产一个日志
*
* @return accessLog
* @param request 请求信息
* @param response 响应信息
* @param executionTime 执行时长
* @param throwable 异常
*/
@Override
public ApiAccessLog prodLog(HttpServletRequest request, HttpServletResponse response, Long executionTime, Throwable throwable) {
ApiAccessLog apiAccessLog = new ApiAccessLog()
.setCreateTime(LocalDateTime.now())
.setTime(executionTime)
.setIp(IPUtil.getIpAddr(request))
.setMethod(request.getMethod())
.setUserAgent(request.getHeader("user-agent"))
.setUri(URLUtil.getPath(request.getRequestURI()))
.setMatchingPattern(String.valueOf(request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE)))
.setErrorMsg(Optional.ofNullable(throwable).map(Throwable::getMessage).orElse(null))
.setHttpStatus(response.getStatus())
.setReqParams(JSONUtil.toJsonStr(request.getParameterMap()));
// 非文件上传请求记录body
if (!LogUtils.isMultipartContent(request)){
apiAccessLog.setReqBody(LogUtils.getRequestBody(request));
}
return apiAccessLog;
}
/**
* 记录日志
*
* @param accessLog 访问日志
*/
@Override
public void saveLog(ApiAccessLog accessLog) {
apiAccessLogSaveThread.putObject(accessLog);
}
}

View File

@@ -1,51 +0,0 @@
package com.hccake.ballcat.api.modules.log.thread;
import com.hccake.ballcat.common.modules.log.model.entity.ApiAccessLog;
import com.hccake.ballcat.common.modules.log.service.ApiAccessLogService;
import com.hccake.ballcat.common.core.thread.AbstractQueueThread;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @author Hccake
* @version 1.0
* @date 2019/10/16 15:30
*/
@Slf4j
@Component
@RequiredArgsConstructor
public class ApiAccessLogSaveThread extends AbstractQueueThread<ApiAccessLog> {
private final ApiAccessLogService apiAccessLogService;
/**
* 线程启动时的日志打印
*/
@Override
public void startLog() {
log.info("访问日志存储线程已启动===");
}
/**
* 错误日志打印
*
* @param e
* @param list
*/
@Override
public void errorLog(Throwable e, List<ApiAccessLog> list) {
log.error("访问日志记录异常, [msg]:{}, [data]:{}", e.getMessage(), list);
}
/**
* 数据保存
*
* @param list
*/
@Override
public void save(List<ApiAccessLog> list) throws Exception {
apiAccessLogService.saveBatch(list);
}
}

View File

@@ -1,40 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ballcat-common</artifactId>
<groupId>com.hccake</groupId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ballcat-common-modules</artifactId>
<dependencies>
<dependency>
<groupId>com.hccake</groupId>
<artifactId>ballcat-common-core</artifactId>
</dependency>
<dependency>
<groupId>com.hccake</groupId>
<artifactId>ballcat-common-log</artifactId>
</dependency>
<!--mybatis plus-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-extension</artifactId>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@@ -1,13 +0,0 @@
package com.hccake.ballcat.common.modules;
import org.springframework.context.annotation.ComponentScan;
/**
* @author Hccake
* @version 1.0
* @date 2019/8/9 16:07
* 用于自动扫描common包下所有组件
*/
@ComponentScan
public class AutoScanConfig {
}

View File

@@ -1,14 +0,0 @@
package com.hccake.ballcat.common.modules.log.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hccake.ballcat.common.modules.log.model.entity.ApiAccessLog;
/**
* 访问日志
*
* @author hccake
* @date 2019-10-16 16:09:25
*/
public interface ApiAccessLogMapper extends BaseMapper<ApiAccessLog> {
}

View File

@@ -1,99 +0,0 @@
package com.hccake.ballcat.common.modules.log.model.entity;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.time.LocalDateTime;
/**
* 访问日志
*
* @author hccake
* @date 2019-10-16 16:09:25
*/
@Data
@TableName("api_access_log")
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@ApiModel(value = "访问日志")
public class ApiAccessLog extends Model<ApiAccessLog> {
private static final long serialVersionUID = 1L;
/**
* 编号
*/
@TableId
@ApiModelProperty(value = "编号")
private Long id;
/**
* 用户ID
*/
@ApiModelProperty(value = "用户ID")
private Long userId;
/**
* 用户名
*/
@ApiModelProperty(value = "用户名")
private String username;
/**
* 访问IP地址
*/
@ApiModelProperty(value = "访问IP地址")
private String ip;
/**
* 用户代理
*/
@ApiModelProperty(value = "用户代理")
private String userAgent;
/**
* 请求URI
*/
@ApiModelProperty(value = "请求URI")
private String uri;
/**
* 请求映射地址
*/
@ApiModelProperty(value = "请求映射地址")
private String matchingPattern;
/**
* 操作方式
*/
@ApiModelProperty(value = "操作方式")
private String method;
/**
* 请求参数
*/
@ApiModelProperty(value = "请求参数")
private String reqParams;
/**
* 请求body
*/
@ApiModelProperty(value = "请求body")
private String reqBody;
/**
* 响应状态码
*/
@ApiModelProperty(value = "响应状态码")
private Integer httpStatus;
/**
* 错误消息
*/
@ApiModelProperty(value = "错误消息")
private String errorMsg;
/**
* 执行时长
*/
@ApiModelProperty(value = "执行时长")
private Long time;
/**
* 创建时间
*/
@ApiModelProperty(value = "创建时间")
private LocalDateTime createTime;
}

View File

@@ -1,14 +0,0 @@
package com.hccake.ballcat.common.modules.log.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.hccake.ballcat.common.modules.log.model.entity.ApiAccessLog;
/**
* 访问日志
*
* @author hccake
* @date 2019-10-16 16:09:25
*/
public interface ApiAccessLogService extends IService<ApiAccessLog> {
}

View File

@@ -1,20 +0,0 @@
package com.hccake.ballcat.common.modules.log.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hccake.ballcat.common.modules.log.mapper.ApiAccessLogMapper;
import com.hccake.ballcat.common.modules.log.model.entity.ApiAccessLog;
import com.hccake.ballcat.common.modules.log.service.ApiAccessLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* 访问日志
*
* @author hccake
* @date 2019-10-16 16:09:25
*/
@Slf4j
@Service
public class ApiAccessLogServiceImpl extends ServiceImpl<ApiAccessLogMapper, ApiAccessLog> implements ApiAccessLogService {
}

View File

@@ -1,2 +0,0 @@
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.hccake.ballcat.common.modules.AutoScanConfig

View File

@@ -51,33 +51,6 @@ CREATE TABLE `admin_operation_log` (
INDEX `create_time`(`create_time`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 3332 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '操作日志' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for api_access_log
-- ----------------------------
DROP TABLE IF EXISTS `api_access_log`;
CREATE TABLE `api_access_log` (
`id` bigint(64) NOT NULL AUTO_INCREMENT COMMENT '编号',
`user_id` bigint(16) NULL DEFAULT NULL COMMENT '用户ID',
`username` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '用户名',
`ip` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '访问IP地址',
`user_agent` varchar(1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '用户代理',
`uri` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '请求URI',
`matching_pattern` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '请求映射路径',
`method` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '操作方式',
`req_params` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '请求参数',
`req_body` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '请求body',
`http_status` int(5) NULL DEFAULT NULL COMMENT '响应状态码',
`error_msg` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '错误消息',
`time` bigint(64) NULL DEFAULT NULL COMMENT '执行时长',
`create_time` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '创建时间',
PRIMARY KEY (`id`) USING BTREE,
INDEX `user_id`(`user_id`) USING BTREE,
INDEX `user_name`(`username`) USING BTREE,
INDEX `uri`(`uri`) USING BTREE,
INDEX `httpStatus`(`http_status`) USING BTREE,
INDEX `create_time`(`create_time`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 318 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '访问日志' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Table structure for oauth_client_details
-- ----------------------------
@@ -234,8 +207,6 @@ INSERT INTO `sys_permission` VALUES (100504, '字典删除', 'sys:dict:del', NUL
INSERT INTO `sys_permission` VALUES (110000, '日志管理', NULL, '', 'log', 'layouts/RouteView', '/log/adminoperationlog', NULL, 0, 'file-search', 9, 0, 0, 0, 0, NULL, '2019-10-16 18:30:07');
INSERT INTO `sys_permission` VALUES (110100, '操作日志', NULL, '/log/adminoperationlog', 'adminOperationLog', 'log/adminoperationlog/AdminOperationLogPage', NULL, NULL, 110000, NULL, 1, 0, 0, 1, 0, NULL, '2019-10-13 22:00:24');
INSERT INTO `sys_permission` VALUES (110101, '操作日志查询', 'log:adminoperationlog:read', NULL, NULL, NULL, NULL, NULL, 110100, NULL, 0, 0, 0, 2, 0, '2019-10-13 22:00:24', '2019-10-15 14:14:03');
INSERT INTO `sys_permission` VALUES (110200, '访问日志(接口)', NULL, '/log/apiaccesslog', 'apiAccessLog', 'log/apiaccesslog/ApiAccessLogPage', NULL, NULL, 110000, NULL, 1, 0, 0, 1, 0, NULL, '2019-10-13 22:00:24');
INSERT INTO `sys_permission` VALUES (110201, '访问日志(接口)查询', 'log:apiaccesslog:read', NULL, NULL, NULL, NULL, NULL, 110200, NULL, 0, 0, 0, 2, 0, '2019-10-13 22:00:24', '2019-10-15 14:14:03');
INSERT INTO `sys_permission` VALUES (110300, '访问日志(后台)', NULL, '/log/adminaccesslog', 'adminAccessLog', 'log/adminaccesslog/AdminAccessLogPage', NULL, NULL, 110000, NULL, 1, 0, 0, 1, 0, NULL, '2019-10-13 22:00:24');
INSERT INTO `sys_permission` VALUES (110301, '访问日志(后台)查询', 'log:adminaccesslog:read', NULL, NULL, NULL, NULL, NULL, 110300, NULL, 0, 0, 0, 2, 0, '2019-10-13 22:00:24', '2019-10-15 14:14:03');
INSERT INTO `sys_permission` VALUES (990000, '开发平台', '', '', 'develop', 'layouts/RouteView', '', NULL, 0, 'desktop', 99, 0, 0, 0, 0, NULL, '2019-11-22 16:49:56');
@@ -472,10 +443,10 @@ INSERT INTO `sys_user_role` VALUES (18, 14);
INSERT INTO `sys_user_role` VALUES (19, 14);
-- ----------------------------
-- Table structure for tbl_base_config
-- Table structure for tbl_sys_config
-- ----------------------------
DROP TABLE IF EXISTS `tbl_base_config`;
CREATE TABLE `tbl_base_config` (
DROP TABLE IF EXISTS `tbl_sys_config`;
CREATE TABLE `tbl_sys_config` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '配置名称',
`conf_key` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '配置在缓存中的key名',
@@ -489,8 +460,8 @@ CREATE TABLE `tbl_base_config` (
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '基础配置' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of tbl_base_config
-- Records of tbl_sys_config
-- ----------------------------
INSERT INTO `tbl_base_config` VALUES (4, '网站弹窗开关', 'site_popup', '1', 'group', '宣传网站是否弹出框的控制开关。\n1开启 0关闭', '2020-02-27 15:06:28', '2019-10-15 16:45:55');
INSERT INTO `tbl_sys_config` VALUES (4, '网站弹窗开关', 'site_popup', '1', 'group', '宣传网站是否弹出框的控制开关。\n1开启 0关闭', '2020-02-27 15:06:28', '2019-10-15 16:45:55');
SET FOREIGN_KEY_CHECKS = 1;