refactor: 重构日志管理相关接口
This commit is contained in:
parent
8a41b96687
commit
7793f82009
@ -13,12 +13,6 @@
|
||||
<description>系统监控模块(存放系统监控相关业务功能,例如:在线用户、日志管理等)</description>
|
||||
|
||||
<dependencies>
|
||||
<!-- ContiNew Starter 日志模块 - HttpTracePro(Spring Boot Actuator HttpTrace 定制增强版) -->
|
||||
<dependency>
|
||||
<groupId>top.charles7c.continew</groupId>
|
||||
<artifactId>continew-starter-log-httptrace-pro</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 系统管理模块(存放系统管理模块相关功能,例如:部门管理、角色管理、用户管理等) -->
|
||||
<dependency>
|
||||
<groupId>top.charles7c.continew</groupId>
|
||||
|
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* 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.continew.admin.monitor.model.query;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import top.charles7c.continew.starter.data.core.annotation.Query;
|
||||
import top.charles7c.continew.starter.data.core.enums.QueryType;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 登录日志查询条件
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/1/16 23:25
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "登录日志查询条件")
|
||||
public class LoginLogQuery implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 登录状态
|
||||
*/
|
||||
@Schema(description = "登录状态(1:成功;2:失败)", example = "1")
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 登录时间
|
||||
*/
|
||||
@Schema(description = "登录时间", example = "2023-08-08 00:00:00,2023-08-08 23:59:59")
|
||||
@Query(type = QueryType.BETWEEN)
|
||||
@DateTimeFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
|
||||
private List<Date> createTime;
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
/*
|
||||
* 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.continew.admin.monitor.model.query;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import top.charles7c.continew.starter.data.core.annotation.Query;
|
||||
import top.charles7c.continew.starter.data.core.enums.QueryType;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统日志查询条件
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/1/17 23:31
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "系统日志查询条件")
|
||||
public class SystemLogQuery implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 链路 ID
|
||||
*/
|
||||
@Schema(description = "链路 ID", example = "904846526308876288")
|
||||
private String traceId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Schema(description = "创建时间", example = "2023-08-08 00:00:00,2023-08-08 23:59:59")
|
||||
@Query(type = QueryType.BETWEEN)
|
||||
@DateTimeFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
|
||||
private List<Date> createTime;
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
/*
|
||||
* 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.continew.admin.monitor.model.resp;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import top.charles7c.continew.admin.monitor.enums.LogStatusEnum;
|
||||
|
||||
/**
|
||||
* 登录日志信息
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/1/16 23:19
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "登录日志信息")
|
||||
public class LoginLogResp extends LogResp {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 登录行为
|
||||
*/
|
||||
@Schema(description = "登录行为", example = "用户登录")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 登录状态
|
||||
*/
|
||||
@Schema(description = "登录状态(1:成功;2:失败)", type = "Integer", allowableValues = {"1", "2"}, example = "1")
|
||||
private LogStatusEnum status;
|
||||
|
||||
/**
|
||||
* 登录 IP
|
||||
*/
|
||||
@Schema(description = "登录 IP", example = "192.168.0.1")
|
||||
private String ip;
|
||||
|
||||
/**
|
||||
* 登录地点
|
||||
*/
|
||||
@Schema(description = "登录地点", example = "中国北京北京市")
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 浏览器
|
||||
*/
|
||||
@Schema(description = "浏览器", example = "Chrome 115.0.0.0")
|
||||
private String browser;
|
||||
|
||||
/**
|
||||
* 操作系统
|
||||
*/
|
||||
@Schema(description = "操作系统", example = "Windows 10")
|
||||
private String os;
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
*/
|
||||
@Schema(description = "错误信息")
|
||||
private String errorMsg;
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
/*
|
||||
* 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.continew.admin.monitor.model.resp;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import top.charles7c.continew.admin.monitor.enums.LogStatusEnum;
|
||||
|
||||
/**
|
||||
* 操作日志信息
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/1/14 18:27
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "操作日志信息")
|
||||
public class OperationLogResp extends LogResp {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 操作内容
|
||||
*/
|
||||
@Schema(description = "操作内容", example = "新增数据")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 所属模块
|
||||
*/
|
||||
@Schema(description = "所属模块", example = "部门管理")
|
||||
private String module;
|
||||
|
||||
/**
|
||||
* 操作 IP
|
||||
*/
|
||||
@Schema(description = "操作 IP", example = "192.168.0.1")
|
||||
private String ip;
|
||||
|
||||
/**
|
||||
* 操作地点
|
||||
*/
|
||||
@Schema(description = "操作地点", example = "中国北京北京市")
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 浏览器
|
||||
*/
|
||||
@Schema(description = "浏览器", example = "Chrome 115.0.0.0")
|
||||
private String browser;
|
||||
|
||||
/**
|
||||
* 操作状态
|
||||
*/
|
||||
@Schema(description = "操作状态(1:成功;2:失败)", type = "Integer", allowableValues = {"1", "2"}, example = "1")
|
||||
private LogStatusEnum status;
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
*/
|
||||
@Schema(description = "错误信息")
|
||||
private String errorMsg;
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
/*
|
||||
* 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.continew.admin.monitor.model.resp;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
/**
|
||||
* 系统日志信息
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/1/17 23:29
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "系统日志信息")
|
||||
public class SystemLogResp extends LogResp {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 状态码
|
||||
*/
|
||||
@Schema(description = "状态码", example = "200")
|
||||
private Integer statusCode;
|
||||
|
||||
/**
|
||||
* 请求方式
|
||||
*/
|
||||
@Schema(description = "请求方式", example = "POST")
|
||||
private String requestMethod;
|
||||
|
||||
/**
|
||||
* 请求 URL
|
||||
*/
|
||||
@Schema(description = "请求 URL", example = "http://api.charles7c.top/system/dept")
|
||||
private String requestUrl;
|
||||
|
||||
/**
|
||||
* IP
|
||||
*/
|
||||
@Schema(description = "IP", example = "192.168.0.1")
|
||||
private String ip;
|
||||
|
||||
/**
|
||||
* 地址
|
||||
*/
|
||||
@Schema(description = "地址", example = "中国北京北京市")
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 浏览器
|
||||
*/
|
||||
@Schema(description = "浏览器", example = "Chrome 115.0.0.0")
|
||||
private String browser;
|
||||
|
||||
/**
|
||||
* 耗时(ms)
|
||||
*/
|
||||
@Schema(description = "耗时(ms)", example = "58")
|
||||
private Long timeTaken;
|
||||
}
|
@ -1,133 +0,0 @@
|
||||
/*
|
||||
* 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.continew.admin.monitor.service.impl;
|
||||
|
||||
import cn.crane4j.annotation.AutoOperate;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.charles7c.continew.admin.common.constant.SysConstants;
|
||||
import top.charles7c.continew.admin.monitor.mapper.LogMapper;
|
||||
import top.charles7c.continew.admin.monitor.model.entity.LogDO;
|
||||
import top.charles7c.continew.admin.monitor.model.query.LoginLogQuery;
|
||||
import top.charles7c.continew.admin.monitor.model.query.OperationLogQuery;
|
||||
import top.charles7c.continew.admin.monitor.model.query.SystemLogQuery;
|
||||
import top.charles7c.continew.admin.monitor.model.resp.*;
|
||||
import top.charles7c.continew.admin.monitor.service.LogService;
|
||||
import top.charles7c.continew.starter.core.util.ReflectUtils;
|
||||
import top.charles7c.continew.starter.core.util.validate.CheckUtils;
|
||||
import top.charles7c.continew.starter.data.mybatis.plus.query.QueryWrapperHelper;
|
||||
import top.charles7c.continew.starter.extension.crud.model.query.PageQuery;
|
||||
import top.charles7c.continew.starter.extension.crud.model.resp.PageResp;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 系统日志业务实现
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2022/12/23 20:12
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class LogServiceImpl implements LogService {
|
||||
|
||||
private final LogMapper logMapper;
|
||||
|
||||
@Override
|
||||
@AutoOperate(type = OperationLogResp.class, on = "list")
|
||||
public PageResp<OperationLogResp> page(OperationLogQuery query, PageQuery pageQuery) {
|
||||
QueryWrapper<LogDO> queryWrapper = QueryWrapperHelper.build(query);
|
||||
// 限定查询信息
|
||||
List<String> fieldNameList = ReflectUtils.getNonStaticFieldsName(OperationLogResp.class);
|
||||
List<String> columnNameList = fieldNameList.stream()
|
||||
.filter(n -> !n.endsWith(SysConstants.DESCRIPTION_FIELD_SUFFIX))
|
||||
.map(StrUtil::toUnderlineCase)
|
||||
.toList();
|
||||
queryWrapper.select(columnNameList);
|
||||
// 分页查询
|
||||
IPage<LogDO> page = logMapper.selectPage(pageQuery.toPage(), queryWrapper);
|
||||
return PageResp.build(page, OperationLogResp.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@AutoOperate(type = LoginLogResp.class, on = "list")
|
||||
public PageResp<LoginLogResp> page(LoginLogQuery query, PageQuery pageQuery) {
|
||||
QueryWrapper<LogDO> queryWrapper = QueryWrapperHelper.build(query);
|
||||
queryWrapper.eq("module", "登录");
|
||||
// 限定查询信息
|
||||
List<String> fieldNameList = ReflectUtils.getNonStaticFieldsName(LoginLogResp.class);
|
||||
List<String> columnNameList = fieldNameList.stream()
|
||||
.filter(n -> !n.endsWith(SysConstants.DESCRIPTION_FIELD_SUFFIX))
|
||||
.map(StrUtil::toUnderlineCase)
|
||||
.toList();
|
||||
queryWrapper.select(columnNameList);
|
||||
// 分页查询
|
||||
IPage<LogDO> page = logMapper.selectPage(pageQuery.toPage(), queryWrapper);
|
||||
return PageResp.build(page, LoginLogResp.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@AutoOperate(type = SystemLogResp.class, on = "list")
|
||||
public PageResp<SystemLogResp> page(SystemLogQuery query, PageQuery pageQuery) {
|
||||
QueryWrapper<LogDO> queryWrapper = QueryWrapperHelper.build(query);
|
||||
// 限定查询信息
|
||||
List<String> fieldNameList = ReflectUtils.getNonStaticFieldsName(SystemLogResp.class);
|
||||
List<String> columnNameList = fieldNameList.stream()
|
||||
.filter(n -> !n.endsWith(SysConstants.DESCRIPTION_FIELD_SUFFIX))
|
||||
.map(StrUtil::toUnderlineCase)
|
||||
.toList();
|
||||
queryWrapper.select(columnNameList);
|
||||
// 分页查询
|
||||
IPage<LogDO> page = logMapper.selectPage(pageQuery.toPage(), queryWrapper);
|
||||
return PageResp.build(page, SystemLogResp.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@AutoOperate(type = SystemLogDetailResp.class)
|
||||
public SystemLogDetailResp get(Long id) {
|
||||
LogDO logDO = logMapper.selectById(id);
|
||||
CheckUtils.throwIfNotExists(logDO, "LogDO", "ID", id);
|
||||
return BeanUtil.copyProperties(logDO, SystemLogDetailResp.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DashboardTotalResp getDashboardTotal() {
|
||||
return logMapper.selectDashboardTotal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DashboardAccessTrendResp> listDashboardAccessTrend(Integer days) {
|
||||
return logMapper.selectListDashboardAccessTrend(days);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DashboardPopularModuleResp> listDashboardPopularModule() {
|
||||
return logMapper.selectListDashboardPopularModule();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> listDashboardGeoDistribution() {
|
||||
return logMapper.selectListDashboardGeoDistribution();
|
||||
}
|
||||
}
|
@ -13,6 +13,12 @@
|
||||
<description>系统管理模块(存放系统管理相关业务功能,例如:部门管理、角色管理、用户管理等)</description>
|
||||
|
||||
<dependencies>
|
||||
<!-- ContiNew Starter 日志模块 - HttpTracePro(Spring Boot Actuator HttpTrace 定制增强版) -->
|
||||
<dependency>
|
||||
<groupId>top.charles7c.continew</groupId>
|
||||
<artifactId>continew-starter-log-httptrace-pro</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 公共模块(存放公共工具类,公共配置等) -->
|
||||
<dependency>
|
||||
<groupId>top.charles7c.continew</groupId>
|
||||
|
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.continew.admin.system.config;
|
||||
package top.charles7c.continew.admin.system.config.file;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.EscapeUtil;
|
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.continew.admin.system.config;
|
||||
package top.charles7c.continew.admin.system.config.file;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -14,12 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.continew.admin.monitor.config;
|
||||
package top.charles7c.continew.admin.system.config.log;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import top.charles7c.continew.admin.monitor.mapper.LogMapper;
|
||||
import top.charles7c.continew.admin.system.mapper.LogMapper;
|
||||
import top.charles7c.continew.admin.system.service.UserService;
|
||||
import top.charles7c.continew.starter.log.core.dao.LogDao;
|
||||
import top.charles7c.continew.starter.log.httptracepro.autoconfigure.ConditionalOnEnabledLog;
|
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.continew.admin.monitor.config;
|
||||
package top.charles7c.continew.admin.system.config.log;
|
||||
|
||||
import cn.dev33.satoken.SaManager;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
@ -28,9 +28,9 @@ import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import top.charles7c.continew.admin.auth.model.req.AccountLoginReq;
|
||||
import top.charles7c.continew.admin.common.constant.SysConstants;
|
||||
import top.charles7c.continew.admin.monitor.enums.LogStatusEnum;
|
||||
import top.charles7c.continew.admin.monitor.mapper.LogMapper;
|
||||
import top.charles7c.continew.admin.monitor.model.entity.LogDO;
|
||||
import top.charles7c.continew.admin.system.enums.LogStatusEnum;
|
||||
import top.charles7c.continew.admin.system.mapper.LogMapper;
|
||||
import top.charles7c.continew.admin.system.model.entity.LogDO;
|
||||
import top.charles7c.continew.admin.system.service.UserService;
|
||||
import top.charles7c.continew.starter.core.constant.StringConstants;
|
||||
import top.charles7c.continew.starter.core.util.ExceptionUtils;
|
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.continew.admin.monitor.enums;
|
||||
package top.charles7c.continew.admin.system.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
@ -14,19 +14,19 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.continew.admin.monitor.mapper;
|
||||
package top.charles7c.continew.admin.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Constants;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import top.charles7c.continew.admin.system.model.entity.LogDO;
|
||||
import top.charles7c.continew.admin.system.model.resp.*;
|
||||
import top.charles7c.continew.starter.data.mybatis.plus.base.BaseMapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import top.charles7c.continew.admin.monitor.model.entity.LogDO;
|
||||
import top.charles7c.continew.admin.monitor.model.resp.DashboardAccessTrendResp;
|
||||
import top.charles7c.continew.admin.monitor.model.resp.DashboardPopularModuleResp;
|
||||
import top.charles7c.continew.admin.monitor.model.resp.DashboardTotalResp;
|
||||
import top.charles7c.continew.starter.data.mybatis.plus.base.BaseMapper;
|
||||
|
||||
/**
|
||||
* 系统日志 Mapper
|
||||
*
|
||||
@ -35,6 +35,16 @@ import top.charles7c.continew.starter.data.mybatis.plus.base.BaseMapper;
|
||||
*/
|
||||
public interface LogMapper extends BaseMapper<LogDO> {
|
||||
|
||||
/**
|
||||
* 分页查询列表
|
||||
*
|
||||
* @param page 分页条件
|
||||
* @param queryWrapper 查询条件
|
||||
* @return 分页列表信息
|
||||
*/
|
||||
IPage<LogResp> selectLogPage(@Param("page") IPage<LogDO> page,
|
||||
@Param(Constants.WRAPPER) QueryWrapper<LogDO> queryWrapper);
|
||||
|
||||
/**
|
||||
* 查询仪表盘总计信息
|
||||
*
|
||||
@ -46,7 +56,6 @@ public interface LogMapper extends BaseMapper<LogDO> {
|
||||
* 查询仪表盘访问趋势信息
|
||||
*
|
||||
* @param days 日期数
|
||||
*
|
||||
* @return 仪表盘访问趋势信息
|
||||
*/
|
||||
List<DashboardAccessTrendResp> selectListDashboardAccessTrend(@Param("days") Integer days);
|
@ -14,12 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.continew.admin.monitor.model.entity;
|
||||
package top.charles7c.continew.admin.system.model.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import top.charles7c.continew.admin.monitor.enums.LogStatusEnum;
|
||||
import top.charles7c.continew.admin.system.enums.LogStatusEnum;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
@ -14,14 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.continew.admin.monitor.model.query;
|
||||
package top.charles7c.continew.admin.system.model.query;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import top.charles7c.continew.starter.data.core.annotation.Query;
|
||||
import top.charles7c.continew.starter.data.core.enums.QueryType;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
@ -29,43 +27,52 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 操作日志查询条件
|
||||
* 日志查询条件
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/1/15 11:43
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "操作日志查询条件")
|
||||
public class OperationLogQuery implements Serializable {
|
||||
@Schema(description = "日志查询条件")
|
||||
public class LogQuery implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 操作内容
|
||||
* 日志描述
|
||||
*/
|
||||
@Schema(description = "操作内容", example = "新增数据")
|
||||
@Query(type = QueryType.LIKE)
|
||||
@Schema(description = "日志描述", example = "新增数据")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 操作状态
|
||||
* 所属模块
|
||||
*/
|
||||
@Schema(description = "操作状态(1:成功;2:失败)", example = "1")
|
||||
private Integer status;
|
||||
@Schema(description = "所属模块", example = "所属模块")
|
||||
private String module;
|
||||
|
||||
/**
|
||||
* IP
|
||||
*/
|
||||
@Schema(description = "IP", example = "192.168.0.1")
|
||||
private String ip;
|
||||
|
||||
/**
|
||||
* 操作人
|
||||
*/
|
||||
@Schema(description = "操作人", example = "admin")
|
||||
private String createUserString;
|
||||
|
||||
/**
|
||||
* 操作时间
|
||||
*/
|
||||
@Schema(description = "操作时间", example = "2023-08-08 00:00:00,2023-08-08 23:59:59")
|
||||
@Query(type = QueryType.BETWEEN)
|
||||
@DateTimeFormat(pattern = DatePattern.NORM_DATETIME_PATTERN)
|
||||
private List<Date> createTime;
|
||||
|
||||
/**
|
||||
* 操作人
|
||||
* 状态
|
||||
*/
|
||||
@Schema(description = "操作人", example = "张三")
|
||||
@Query(columns = "create_user")
|
||||
private Long uid;
|
||||
@Schema(description = "状态(1:成功;2:失败)", example = "1")
|
||||
private Integer status;
|
||||
}
|
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.continew.admin.monitor.model.resp;
|
||||
package top.charles7c.continew.admin.system.model.resp;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.continew.admin.monitor.model.resp;
|
||||
package top.charles7c.continew.admin.system.model.resp;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.continew.admin.monitor.model.resp;
|
||||
package top.charles7c.continew.admin.system.model.resp;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.continew.admin.monitor.model.resp;
|
||||
package top.charles7c.continew.admin.system.model.resp;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
@ -14,26 +14,40 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.continew.admin.monitor.model.resp;
|
||||
package top.charles7c.continew.admin.system.model.resp;
|
||||
|
||||
import cn.crane4j.annotation.Assemble;
|
||||
import cn.crane4j.annotation.Mapping;
|
||||
import cn.crane4j.annotation.condition.ConditionOnPropertyNotNull;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import top.charles7c.continew.admin.common.constant.ContainerConstants;
|
||||
import top.charles7c.continew.admin.system.enums.LogStatusEnum;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 系统日志详情信息
|
||||
* 日志详情信息
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/1/18 20:19
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "系统日志详情信息")
|
||||
public class SystemLogDetailResp extends LogResp {
|
||||
@Schema(description = "日志详情信息")
|
||||
public class LogDetailResp implements Serializable {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
@Schema(description = "ID", example = "1")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 链路 ID
|
||||
*/
|
||||
@ -41,16 +55,16 @@ public class SystemLogDetailResp extends LogResp {
|
||||
private String traceId;
|
||||
|
||||
/**
|
||||
* 状态码
|
||||
* 日志描述
|
||||
*/
|
||||
@Schema(description = "状态码", example = "200")
|
||||
private Integer statusCode;
|
||||
@Schema(description = "日志描述", example = "新增数据")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 请求方式
|
||||
* 所属模块
|
||||
*/
|
||||
@Schema(description = "请求方式", example = "POST")
|
||||
private String requestMethod;
|
||||
@Schema(description = "所属模块", example = "部门管理")
|
||||
private String module;
|
||||
|
||||
/**
|
||||
* 请求 URL
|
||||
@ -58,6 +72,12 @@ public class SystemLogDetailResp extends LogResp {
|
||||
@Schema(description = "请求 URL", example = "http://api.charles7c.top/system/dept")
|
||||
private String requestUrl;
|
||||
|
||||
/**
|
||||
* 请求方式
|
||||
*/
|
||||
@Schema(description = "请求方式", example = "POST")
|
||||
private String requestMethod;
|
||||
|
||||
/**
|
||||
* 请求头
|
||||
*/
|
||||
@ -70,6 +90,12 @@ public class SystemLogDetailResp extends LogResp {
|
||||
@Schema(description = "请求体", example = "{\"name\": \"测试部\",...}")
|
||||
private String requestBody;
|
||||
|
||||
/**
|
||||
* 状态码
|
||||
*/
|
||||
@Schema(description = "状态码", example = "200")
|
||||
private Integer statusCode;
|
||||
|
||||
/**
|
||||
* 响应头
|
||||
*/
|
||||
@ -82,6 +108,12 @@ public class SystemLogDetailResp extends LogResp {
|
||||
@Schema(description = "响应体", example = "{\"success\":true},...")
|
||||
private String responseBody;
|
||||
|
||||
/**
|
||||
* 耗时(ms)
|
||||
*/
|
||||
@Schema(description = "耗时(ms)", example = "58")
|
||||
private Long timeTaken;
|
||||
|
||||
/**
|
||||
* IP
|
||||
*/
|
||||
@ -89,9 +121,9 @@ public class SystemLogDetailResp extends LogResp {
|
||||
private String ip;
|
||||
|
||||
/**
|
||||
* 地址
|
||||
* IP 归属地
|
||||
*/
|
||||
@Schema(description = "地址", example = "中国北京北京市")
|
||||
@Schema(description = "IP 归属地", example = "中国北京北京市")
|
||||
private String address;
|
||||
|
||||
/**
|
||||
@ -107,8 +139,34 @@ public class SystemLogDetailResp extends LogResp {
|
||||
private String os;
|
||||
|
||||
/**
|
||||
* 耗时(ms)
|
||||
* 状态
|
||||
*/
|
||||
@Schema(description = "耗时(ms)", example = "58")
|
||||
private Long timeTaken;
|
||||
@Schema(description = "状态(1:成功;2:失败)", type = "Integer", allowableValues = {"1", "2"}, example = "1")
|
||||
private LogStatusEnum status;
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
*/
|
||||
@Schema(description = "错误信息")
|
||||
private String errorMsg;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@JsonIgnore
|
||||
@ConditionOnPropertyNotNull
|
||||
@Assemble(container = ContainerConstants.USER_NICKNAME, props = @Mapping(ref = "createUserString"))
|
||||
private Long createUser;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@Schema(description = "创建人", example = "张三")
|
||||
private String createUserString;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Schema(description = "创建时间", example = "2023-08-08 08:08:08", type = "string")
|
||||
private LocalDateTime createTime;
|
||||
}
|
@ -14,27 +14,25 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.continew.admin.monitor.model.resp;
|
||||
package top.charles7c.continew.admin.system.model.resp;
|
||||
|
||||
import cn.crane4j.annotation.Assemble;
|
||||
import cn.crane4j.annotation.Mapping;
|
||||
import cn.crane4j.annotation.condition.ConditionOnPropertyNotNull;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import top.charles7c.continew.admin.common.constant.ContainerConstants;
|
||||
import top.charles7c.continew.admin.system.enums.LogStatusEnum;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 基础日志信息
|
||||
* 日志信息
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/1/17 21:43
|
||||
* @since 2023/1/14 18:27
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "日志信息")
|
||||
public class LogResp implements Serializable {
|
||||
|
||||
@Serial
|
||||
@ -46,12 +44,64 @@ public class LogResp implements Serializable {
|
||||
@Schema(description = "ID", example = "1")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 日志描述
|
||||
*/
|
||||
@Schema(description = "日志描述", example = "新增数据")
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 所属模块
|
||||
*/
|
||||
@Schema(description = "所属模块", example = "部门管理")
|
||||
private String module;
|
||||
|
||||
/**
|
||||
* 耗时(ms)
|
||||
*/
|
||||
@Schema(description = "耗时(ms)", example = "58")
|
||||
private Long timeTaken;
|
||||
|
||||
/**
|
||||
* IP
|
||||
*/
|
||||
@Schema(description = "IP", example = "192.168.0.1")
|
||||
private String ip;
|
||||
|
||||
/**
|
||||
* IP 归属地
|
||||
*/
|
||||
@Schema(description = "IP 归属地", example = "中国北京北京市")
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 浏览器
|
||||
*/
|
||||
@Schema(description = "浏览器", example = "Chrome 115.0.0.0")
|
||||
private String browser;
|
||||
|
||||
/**
|
||||
* 操作系统
|
||||
*/
|
||||
@Schema(description = "操作系统", example = "Windows 10")
|
||||
private String os;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@Schema(description = "状态(1:成功;2:失败)", type = "Integer", allowableValues = {"1", "2"}, example = "1")
|
||||
private LogStatusEnum status;
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
*/
|
||||
@Schema(description = "错误信息")
|
||||
private String errorMsg;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@JsonIgnore
|
||||
@ConditionOnPropertyNotNull
|
||||
@Assemble(container = ContainerConstants.USER_NICKNAME, props = @Mapping(ref = "createUserString"))
|
||||
private Long createUser;
|
||||
|
||||
/**
|
@ -14,16 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.continew.admin.monitor.service;
|
||||
package top.charles7c.continew.admin.system.service;
|
||||
|
||||
import top.charles7c.continew.admin.system.model.resp.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import top.charles7c.continew.admin.monitor.model.resp.DashboardAccessTrendResp;
|
||||
import top.charles7c.continew.admin.monitor.model.resp.DashboardGeoDistributionResp;
|
||||
import top.charles7c.continew.admin.monitor.model.resp.DashboardPopularModuleResp;
|
||||
import top.charles7c.continew.admin.monitor.model.resp.DashboardTotalResp;
|
||||
import top.charles7c.continew.admin.system.model.resp.DashboardAnnouncementResp;
|
||||
|
||||
/**
|
||||
* 仪表盘业务接口
|
||||
*
|
@ -14,12 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.continew.admin.monitor.service;
|
||||
package top.charles7c.continew.admin.system.service;
|
||||
|
||||
import top.charles7c.continew.admin.monitor.model.query.LoginLogQuery;
|
||||
import top.charles7c.continew.admin.monitor.model.query.OperationLogQuery;
|
||||
import top.charles7c.continew.admin.monitor.model.query.SystemLogQuery;
|
||||
import top.charles7c.continew.admin.monitor.model.resp.*;
|
||||
import top.charles7c.continew.admin.system.model.query.LogQuery;
|
||||
import top.charles7c.continew.admin.system.model.resp.*;
|
||||
import top.charles7c.continew.starter.extension.crud.model.query.PageQuery;
|
||||
import top.charles7c.continew.starter.extension.crud.model.resp.PageResp;
|
||||
|
||||
@ -35,39 +33,21 @@ import java.util.Map;
|
||||
public interface LogService {
|
||||
|
||||
/**
|
||||
* 分页查询操作日志列表
|
||||
* 分页查询列表
|
||||
*
|
||||
* @param query 查询条件
|
||||
* @param pageQuery 分页查询条件
|
||||
* @return 操作日志分页信息
|
||||
* @return 分页列表信息
|
||||
*/
|
||||
PageResp<OperationLogResp> page(OperationLogQuery query, PageQuery pageQuery);
|
||||
PageResp<LogResp> page(LogQuery query, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 分页查询登录日志列表
|
||||
* 查看详情
|
||||
*
|
||||
* @param query 查询条件
|
||||
* @param pageQuery 分页查询条件
|
||||
* @return 登录日志分页信息
|
||||
* @param id ID
|
||||
* @return 详情信息
|
||||
*/
|
||||
PageResp<LoginLogResp> page(LoginLogQuery query, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 分页查询系统日志列表
|
||||
*
|
||||
* @param query 查询条件
|
||||
* @param pageQuery 分页查询条件
|
||||
* @return 系统日志分页信息
|
||||
*/
|
||||
PageResp<SystemLogResp> page(SystemLogQuery query, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 查看系统日志详情
|
||||
*
|
||||
* @param logId 日志 ID
|
||||
* @return 系统日志详情
|
||||
*/
|
||||
SystemLogDetailResp get(Long logId);
|
||||
LogDetailResp get(Long id);
|
||||
|
||||
/**
|
||||
* 查询仪表盘总计信息
|
@ -14,20 +14,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.continew.admin.monitor.service.impl;
|
||||
package top.charles7c.continew.admin.system.service.impl;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.charles7c.continew.admin.monitor.model.resp.DashboardAccessTrendResp;
|
||||
import top.charles7c.continew.admin.monitor.model.resp.DashboardGeoDistributionResp;
|
||||
import top.charles7c.continew.admin.monitor.model.resp.DashboardPopularModuleResp;
|
||||
import top.charles7c.continew.admin.monitor.model.resp.DashboardTotalResp;
|
||||
import top.charles7c.continew.admin.monitor.service.DashboardService;
|
||||
import top.charles7c.continew.admin.monitor.service.LogService;
|
||||
import top.charles7c.continew.admin.system.model.resp.DashboardAnnouncementResp;
|
||||
import top.charles7c.continew.admin.system.model.resp.*;
|
||||
import top.charles7c.continew.admin.system.service.AnnouncementService;
|
||||
import top.charles7c.continew.admin.system.service.DashboardService;
|
||||
import top.charles7c.continew.admin.system.service.LogService;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* 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.continew.admin.system.service.impl;
|
||||
|
||||
import cn.crane4j.annotation.AutoOperate;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import top.charles7c.continew.admin.system.mapper.LogMapper;
|
||||
import top.charles7c.continew.admin.system.model.entity.LogDO;
|
||||
import top.charles7c.continew.admin.system.model.query.LogQuery;
|
||||
import top.charles7c.continew.admin.system.model.resp.*;
|
||||
import top.charles7c.continew.admin.system.service.LogService;
|
||||
import top.charles7c.continew.starter.core.util.validate.CheckUtils;
|
||||
import top.charles7c.continew.starter.core.util.validate.ValidationUtils;
|
||||
import top.charles7c.continew.starter.extension.crud.model.query.PageQuery;
|
||||
import top.charles7c.continew.starter.extension.crud.model.resp.PageResp;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 系统日志业务实现
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2022/12/23 20:12
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class LogServiceImpl implements LogService {
|
||||
|
||||
private final LogMapper logMapper;
|
||||
|
||||
@Override
|
||||
public PageResp<LogResp> page(LogQuery query, PageQuery pageQuery) {
|
||||
QueryWrapper<LogDO> queryWrapper = new QueryWrapper<>();
|
||||
// 构建条件
|
||||
String description = query.getDescription();
|
||||
if (StrUtil.isNotBlank(description)) {
|
||||
queryWrapper.and(q -> q.like("t1.description", description).or().like("t1.module", description));
|
||||
}
|
||||
String module = query.getModule();
|
||||
if (StrUtil.isNotBlank(module)) {
|
||||
queryWrapper.eq("t1.module", module);
|
||||
}
|
||||
String ip = query.getIp();
|
||||
if (StrUtil.isNotBlank(ip)) {
|
||||
queryWrapper.and(q -> q.like("t1.ip", ip).or().like("t1.address", ip));
|
||||
}
|
||||
String createUserString = query.getCreateUserString();
|
||||
if (StrUtil.isNotBlank(createUserString)) {
|
||||
queryWrapper.and(q -> q.like("t2.username", createUserString).or().like("t2.nickname", createUserString));
|
||||
}
|
||||
List<Date> createTimeList = query.getCreateTime();
|
||||
if (CollUtil.isNotEmpty(createTimeList)) {
|
||||
ValidationUtils.throwIf(createTimeList.size() != 2, "[{}] 必须是一个范围", "createTime");
|
||||
queryWrapper.between("t1.create_time", createTimeList.get(0), createTimeList.get(1));
|
||||
}
|
||||
Integer status = query.getStatus();
|
||||
if (null != status) {
|
||||
queryWrapper.eq("t1.status", status);
|
||||
}
|
||||
IPage<LogResp> page = logMapper.selectLogPage(pageQuery.toPage(), queryWrapper);
|
||||
return PageResp.build(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
@AutoOperate(type = LogDetailResp.class)
|
||||
public LogDetailResp get(Long id) {
|
||||
LogDO logDO = logMapper.selectById(id);
|
||||
CheckUtils.throwIfNotExists(logDO, "LogDO", "ID", id);
|
||||
return BeanUtil.copyProperties(logDO, LogDetailResp.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DashboardTotalResp getDashboardTotal() {
|
||||
return logMapper.selectDashboardTotal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DashboardAccessTrendResp> listDashboardAccessTrend(Integer days) {
|
||||
return logMapper.selectListDashboardAccessTrend(days);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DashboardPopularModuleResp> listDashboardPopularModule() {
|
||||
return logMapper.selectListDashboardPopularModule();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> listDashboardGeoDistribution() {
|
||||
return logMapper.selectListDashboardGeoDistribution();
|
||||
}
|
||||
}
|
@ -1,7 +1,27 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="top.charles7c.continew.admin.monitor.mapper.LogMapper">
|
||||
<select id="selectDashboardTotal" resultType="top.charles7c.continew.admin.monitor.model.resp.DashboardTotalResp">
|
||||
<mapper namespace="top.charles7c.continew.admin.system.mapper.LogMapper">
|
||||
<select id="selectLogPage" resultType="top.charles7c.continew.admin.system.model.resp.LogResp">
|
||||
SELECT
|
||||
t1.id,
|
||||
t1.description,
|
||||
t1.module,
|
||||
t1.time_taken,
|
||||
t1.ip,
|
||||
t1.address,
|
||||
t1.browser,
|
||||
t1.os,
|
||||
t1.status,
|
||||
t1.error_msg,
|
||||
t1.create_user,
|
||||
t1.create_time,
|
||||
t2.nickname AS createUserString
|
||||
FROM sys_log AS t1
|
||||
LEFT JOIN sys_user AS t2 ON t2.id = t1.create_user
|
||||
${ew.customSqlSegment}
|
||||
</select>
|
||||
|
||||
<select id="selectDashboardTotal" resultType="top.charles7c.continew.admin.system.model.resp.DashboardTotalResp">
|
||||
SELECT
|
||||
(SELECT COUNT(*) FROM sys_log) AS pvCount,
|
||||
(SELECT COUNT(DISTINCT ip) FROM sys_log) AS ipCount,
|
||||
@ -10,7 +30,7 @@
|
||||
</select>
|
||||
|
||||
<select id="selectListDashboardAccessTrend"
|
||||
resultType="top.charles7c.continew.admin.monitor.model.resp.DashboardAccessTrendResp">
|
||||
resultType="top.charles7c.continew.admin.system.model.resp.DashboardAccessTrendResp">
|
||||
SELECT
|
||||
DATE(create_time) AS date,
|
||||
COUNT(*) AS pvCount,
|
||||
@ -23,7 +43,7 @@
|
||||
</select>
|
||||
|
||||
<select id="selectListDashboardPopularModule"
|
||||
resultType="top.charles7c.continew.admin.monitor.model.resp.DashboardPopularModuleResp">
|
||||
resultType="top.charles7c.continew.admin.system.model.resp.DashboardPopularModuleResp">
|
||||
SELECT
|
||||
module,
|
||||
COUNT(*) AS pvCount,
|
@ -31,11 +31,11 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import top.charles7c.continew.admin.common.constant.CacheConstants;
|
||||
import top.charles7c.continew.admin.monitor.model.resp.DashboardAccessTrendResp;
|
||||
import top.charles7c.continew.admin.monitor.model.resp.DashboardGeoDistributionResp;
|
||||
import top.charles7c.continew.admin.monitor.model.resp.DashboardPopularModuleResp;
|
||||
import top.charles7c.continew.admin.monitor.model.resp.DashboardTotalResp;
|
||||
import top.charles7c.continew.admin.monitor.service.DashboardService;
|
||||
import top.charles7c.continew.admin.system.model.resp.DashboardAccessTrendResp;
|
||||
import top.charles7c.continew.admin.system.model.resp.DashboardGeoDistributionResp;
|
||||
import top.charles7c.continew.admin.system.model.resp.DashboardPopularModuleResp;
|
||||
import top.charles7c.continew.admin.system.model.resp.DashboardTotalResp;
|
||||
import top.charles7c.continew.admin.system.service.DashboardService;
|
||||
import top.charles7c.continew.admin.system.model.resp.DashboardAnnouncementResp;
|
||||
import top.charles7c.continew.starter.core.util.validate.ValidationUtils;
|
||||
import top.charles7c.continew.starter.web.model.R;
|
||||
|
@ -1,87 +0,0 @@
|
||||
/*
|
||||
* 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.continew.admin.webapi.monitor;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
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;
|
||||
|
||||
import top.charles7c.continew.admin.monitor.model.query.LoginLogQuery;
|
||||
import top.charles7c.continew.admin.monitor.model.query.OperationLogQuery;
|
||||
import top.charles7c.continew.admin.monitor.model.query.SystemLogQuery;
|
||||
import top.charles7c.continew.admin.monitor.model.resp.LoginLogResp;
|
||||
import top.charles7c.continew.admin.monitor.model.resp.OperationLogResp;
|
||||
import top.charles7c.continew.admin.monitor.model.resp.SystemLogDetailResp;
|
||||
import top.charles7c.continew.admin.monitor.model.resp.SystemLogResp;
|
||||
import top.charles7c.continew.admin.monitor.service.LogService;
|
||||
import top.charles7c.continew.starter.extension.crud.model.query.PageQuery;
|
||||
import top.charles7c.continew.starter.extension.crud.model.resp.PageResp;
|
||||
import top.charles7c.continew.starter.web.model.R;
|
||||
import top.charles7c.continew.starter.log.core.annotation.Log;
|
||||
|
||||
/**
|
||||
* 日志管理 API
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/1/18 23:55
|
||||
*/
|
||||
@Tag(name = "日志管理 API")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/monitor/log")
|
||||
public class LogController {
|
||||
|
||||
private final LogService logService;
|
||||
|
||||
@Log(module = "登录日志")
|
||||
@Operation(summary = "分页查询登录日志列表", description = "分页查询登录日志列表")
|
||||
@GetMapping("/login")
|
||||
public R<PageResp<LoginLogResp>> page(LoginLogQuery query, @Validated PageQuery pageQuery) {
|
||||
return R.ok(logService.page(query, pageQuery));
|
||||
}
|
||||
|
||||
@Log(module = "操作日志")
|
||||
@Operation(summary = "分页查询操作日志列表", description = "分页查询操作日志列表")
|
||||
@GetMapping("/operation")
|
||||
public R<PageResp<OperationLogResp>> page(OperationLogQuery query, @Validated PageQuery pageQuery) {
|
||||
return R.ok(logService.page(query, pageQuery));
|
||||
}
|
||||
|
||||
@Log(module = "系统日志")
|
||||
@Operation(summary = "分页查询系统日志列表", description = "分页查询系统日志列表")
|
||||
@GetMapping("/system")
|
||||
public R<PageResp<SystemLogResp>> page(SystemLogQuery query, @Validated PageQuery pageQuery) {
|
||||
return R.ok(logService.page(query, pageQuery));
|
||||
}
|
||||
|
||||
@Log(module = "系统日志")
|
||||
@Operation(summary = "查看系统日志详情", description = "查看系统日志详情")
|
||||
@Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH)
|
||||
@GetMapping("/system/{id}")
|
||||
public R<SystemLogDetailResp> get(@PathVariable Long id) {
|
||||
return R.ok(logService.get(id));
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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.continew.admin.webapi.system;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.enums.ParameterIn;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
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;
|
||||
import top.charles7c.continew.admin.system.model.query.LogQuery;
|
||||
import top.charles7c.continew.admin.system.model.resp.LogDetailResp;
|
||||
import top.charles7c.continew.admin.system.model.resp.LogResp;
|
||||
import top.charles7c.continew.admin.system.service.LogService;
|
||||
import top.charles7c.continew.starter.extension.crud.model.query.PageQuery;
|
||||
import top.charles7c.continew.starter.extension.crud.model.resp.PageResp;
|
||||
import top.charles7c.continew.starter.web.model.R;
|
||||
|
||||
/**
|
||||
* 日志管理 API
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/1/18 23:55
|
||||
*/
|
||||
@Tag(name = "日志管理 API")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/system/log")
|
||||
public class LogController {
|
||||
|
||||
private final LogService logService;
|
||||
|
||||
@Operation(summary = "分页查询列表", description = "分页查询列表")
|
||||
@GetMapping
|
||||
public R<PageResp<LogResp>> page(LogQuery query, @Validated PageQuery pageQuery) {
|
||||
return R.ok(logService.page(query, pageQuery));
|
||||
}
|
||||
|
||||
@Operation(summary = "查看详情", description = "查看详情")
|
||||
@Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH)
|
||||
@GetMapping("/{id}")
|
||||
public R<LogDetailResp> get(@PathVariable Long id) {
|
||||
return R.ok(logService.get(id));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user