新增:个人中心新增查询操作日志功能,优化日志表结构,并支持关闭记录内网 IP 操作

This commit is contained in:
2023-01-16 00:18:53 +08:00
parent 79c741b68e
commit f4ea2d44d6
36 changed files with 1272 additions and 119 deletions

View File

@@ -49,12 +49,6 @@ limitations under the License.
<groupId>top.charles7c</groupId>
<artifactId>continew-admin-monitor</artifactId>
</dependency>
<!-- 系统管理模块(存放系统管理模块相关功能,例如:部门管理、角色管理、用户管理等) -->
<dependency>
<groupId>top.charles7c</groupId>
<artifactId>continew-admin-system</artifactId>
</dependency>
</dependencies>
<build>

View File

@@ -0,0 +1,58 @@
/*
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package top.charles7c.cnadmin.webapi.controller.monitor;
import lombok.RequiredArgsConstructor;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.charles7c.cnadmin.common.model.query.PageQuery;
import top.charles7c.cnadmin.common.model.vo.PageInfo;
import top.charles7c.cnadmin.common.model.vo.R;
import top.charles7c.cnadmin.monitor.model.query.OperationLogQuery;
import top.charles7c.cnadmin.monitor.model.vo.OperationLogVO;
import top.charles7c.cnadmin.monitor.service.OperationLogService;
/**
* 操作日志 API
*
* @author Charles7c
* @since 2023/1/14 18:09
*/
@Tag(name = "操作日志 API")
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/monitor/log/operation", produces = MediaType.APPLICATION_JSON_VALUE)
public class OperationLogController {
private final OperationLogService operationLogService;
@Operation(summary = "分页查询操作日志列表")
@GetMapping
public R<PageInfo<OperationLogVO>> list(@Validated OperationLogQuery query, @Validated PageQuery pageQuery) {
PageInfo<OperationLogVO> pageInfo = operationLogService.list(query, pageQuery);
return R.ok(pageInfo);
}
}

View File

@@ -20,7 +20,7 @@ continew-admin:
name: Apache-2.0
url: https://github.com/Charles7c/continew-admin/blob/dev/LICENSE
# 是否本地解析 IP 归属地
ipAddrLocalParseEnabled: false
ipAddrLocalParseEnabled: true
--- ### 日志配置(重叠部分,优先级高于 logback-spring.xml 中的配置)
logging:
@@ -29,11 +29,13 @@ logging:
file:
path: @logging.file.path@
config: classpath:logback-spring.xml
## 操作日志配置
operation:
# 是否启用操作日志
## 系统日志配置
system:
# 是否启用系统日志
enabled: true
# 不记录操作日志的请求方式
# 是否记录内网 IP 操作
includeInnerIp: false
# 哪些请求方式不记录系统日志
#excludeMethods:
# - GET
# 脱敏字段

View File

@@ -26,7 +26,6 @@ CREATE TABLE IF NOT EXISTS `sys_user` (
CREATE TABLE IF NOT EXISTS `sys_log` (
`log_id` bigint(20) unsigned AUTO_INCREMENT COMMENT '日志ID',
`log_level` varchar(255) DEFAULT NULL COMMENT '日志级别',
`description` varchar(255) DEFAULT NULL COMMENT '日志描述',
`request_url` varchar(512) NOT NULL DEFAULT '' COMMENT '请求URL',
`request_method` varchar(10) DEFAULT NULL COMMENT '请求方式',
@@ -34,14 +33,15 @@ CREATE TABLE IF NOT EXISTS `sys_log` (
`request_body` text DEFAULT NULL COMMENT '请求体',
`status_code` int(11) unsigned DEFAULT NULL COMMENT '状态码',
`response_header` text DEFAULT NULL COMMENT '响应头',
`response_body` text DEFAULT NULL COMMENT '响应体',
`response_body` mediumtext DEFAULT NULL COMMENT '响应体',
`elapsed_time` bigint(20) unsigned DEFAULT NULL COMMENT '请求耗时ms',
`request_ip` varchar(255) DEFAULT NULL COMMENT '请求IP',
`location` varchar(512) DEFAULT NULL COMMENT '操作地址',
`result` tinyint(1) unsigned DEFAULT 1 COMMENT '操作结果1成功 2失败',
`request_ip` varchar(255) DEFAULT NULL COMMENT '操作IP',
`location` varchar(512) DEFAULT NULL COMMENT '操作地点',
`browser` varchar(255) DEFAULT NULL COMMENT '浏览器',
`exception` text DEFAULT NULL COMMENT '异常',
`exception` mediumtext DEFAULT NULL COMMENT '异常',
`create_user` bigint(20) unsigned DEFAULT NULL COMMENT '操作人',
`create_time` datetime NOT NULL COMMENT '操作时间',
PRIMARY KEY (`log_id`) USING BTREE,
INDEX `idx_createUser`(`create_user`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='操作日志表';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='系统日志表';