mirror of https://gitee.com/stylefeng/roses
【log】整理log模块的字段和业务
parent
6f01287ce4
commit
0e7cb3897e
|
@ -33,20 +33,10 @@ public class LogManagerParam extends BaseRequest {
|
||||||
@NotBlank(message = "结束时间不能为空,请检查endDateTime参数", groups = {delete.class})
|
@NotBlank(message = "结束时间不能为空,请检查endDateTime参数", groups = {delete.class})
|
||||||
private String endDateTime;
|
private String endDateTime;
|
||||||
|
|
||||||
/**
|
|
||||||
* 第几页,从1开始
|
|
||||||
*/
|
|
||||||
private Integer pageNo;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 每页大小
|
|
||||||
*/
|
|
||||||
private Integer pageSize;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 日志的名称,一般为业务名称
|
* 日志的名称,一般为业务名称
|
||||||
*/
|
*/
|
||||||
private String name;
|
private String logName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 服务名称,一般为spring.application.name
|
* 服务名称,一般为spring.application.name
|
||||||
|
@ -59,11 +49,6 @@ public class LogManagerParam extends BaseRequest {
|
||||||
*/
|
*/
|
||||||
private String serverIp;
|
private String serverIp;
|
||||||
|
|
||||||
/**
|
|
||||||
* 客户端请求的token
|
|
||||||
*/
|
|
||||||
private String token;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 客户端请求的用户id
|
* 客户端请求的用户id
|
||||||
*/
|
*/
|
||||||
|
@ -77,6 +62,6 @@ public class LogManagerParam extends BaseRequest {
|
||||||
/**
|
/**
|
||||||
* 当前用户请求的url
|
* 当前用户请求的url
|
||||||
*/
|
*/
|
||||||
private String url;
|
private String requestUrl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,15 +5,15 @@ import cn.hutool.core.date.DatePattern;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.stylefeng.roses.kernel.log.db.entity.SysLog;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
||||||
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
|
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
|
||||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||||
import cn.stylefeng.roses.kernel.log.api.LogManagerApi;
|
import cn.stylefeng.roses.kernel.log.api.LogManagerApi;
|
||||||
import cn.stylefeng.roses.kernel.log.api.pojo.manage.LogManagerParam;
|
import cn.stylefeng.roses.kernel.log.api.pojo.manage.LogManagerParam;
|
||||||
import cn.stylefeng.roses.kernel.log.api.pojo.record.LogRecordDTO;
|
import cn.stylefeng.roses.kernel.log.api.pojo.record.LogRecordDTO;
|
||||||
|
import cn.stylefeng.roses.kernel.log.db.entity.SysLog;
|
||||||
import cn.stylefeng.roses.kernel.log.db.service.SysLogService;
|
import cn.stylefeng.roses.kernel.log.db.service.SysLogService;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
@ -103,14 +103,15 @@ public class DbLogManagerServiceImpl implements LogManagerApi {
|
||||||
* @date 2020/11/3 11:22
|
* @date 2020/11/3 11:22
|
||||||
*/
|
*/
|
||||||
private void createQueryCondition(LogManagerParam logManagerParam, LambdaQueryWrapper<SysLog> sysLogLambdaQueryWrapper) {
|
private void createQueryCondition(LogManagerParam logManagerParam, LambdaQueryWrapper<SysLog> sysLogLambdaQueryWrapper) {
|
||||||
|
|
||||||
// 设置查询条件的起始时间和结束时间
|
// 设置查询条件的起始时间和结束时间
|
||||||
sysLogLambdaQueryWrapper.between(SysLog::getDateTime, logManagerParam.getBeginDateTime(), logManagerParam.getEndDateTime());
|
sysLogLambdaQueryWrapper.between(SysLog::getCreateTime, logManagerParam.getBeginDateTime(), logManagerParam.getEndDateTime());
|
||||||
|
|
||||||
// 根据日志名称查询
|
// 根据日志名称查询
|
||||||
String name = logManagerParam.getName();
|
String name = logManagerParam.getLogName();
|
||||||
if (StrUtil.isNotEmpty(name)) {
|
if (StrUtil.isNotEmpty(name)) {
|
||||||
sysLogLambdaQueryWrapper.and(q -> {
|
sysLogLambdaQueryWrapper.and(q -> {
|
||||||
q.eq(SysLog::getName, name);
|
q.eq(SysLog::getLogName, name);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,14 +131,6 @@ public class DbLogManagerServiceImpl implements LogManagerApi {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据客户端请求的token查询
|
|
||||||
String token = logManagerParam.getToken();
|
|
||||||
if (StrUtil.isNotEmpty(token)) {
|
|
||||||
sysLogLambdaQueryWrapper.and(q -> {
|
|
||||||
q.eq(SysLog::getToken, token);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// 根据客户端请求的用户id查询
|
// 根据客户端请求的用户id查询
|
||||||
Long userId = logManagerParam.getUserId();
|
Long userId = logManagerParam.getUserId();
|
||||||
if (userId != null) {
|
if (userId != null) {
|
||||||
|
@ -155,15 +148,15 @@ public class DbLogManagerServiceImpl implements LogManagerApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据当前用户请求的url查询
|
// 根据当前用户请求的url查询
|
||||||
String url = logManagerParam.getUrl();
|
String url = logManagerParam.getRequestUrl();
|
||||||
if (StrUtil.isNotEmpty(clientIp)) {
|
if (StrUtil.isNotEmpty(clientIp)) {
|
||||||
sysLogLambdaQueryWrapper.and(q -> {
|
sysLogLambdaQueryWrapper.and(q -> {
|
||||||
q.like(SysLog::getUrl, url);
|
q.like(SysLog::getRequestUrl, url);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据时间倒序排序
|
// 根据时间倒序排序
|
||||||
sysLogLambdaQueryWrapper.orderByDesc(SysLog::getDateTime);
|
sysLogLambdaQueryWrapper.orderByDesc(SysLog::getCreateTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -87,8 +87,8 @@ public class DbLogRecordServiceImpl implements LogRecordApi {
|
||||||
BeanUtil.copyProperties(logRecordDTO, sysLog);
|
BeanUtil.copyProperties(logRecordDTO, sysLog);
|
||||||
|
|
||||||
// 日志名称为空的话则获取默认日志名称
|
// 日志名称为空的话则获取默认日志名称
|
||||||
if (StrUtil.isEmpty(sysLog.getName())) {
|
if (StrUtil.isEmpty(sysLog.getLogName())) {
|
||||||
sysLog.setName(LogConstants.LOG_DEFAULT_NAME);
|
sysLog.setLogName(LogConstants.LOG_DEFAULT_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 服务名称为空的话则获取默认服务名称
|
// 服务名称为空的话则获取默认服务名称
|
||||||
|
@ -97,9 +97,10 @@ public class DbLogRecordServiceImpl implements LogRecordApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果操作时间为空的话插入当前时间
|
// 如果操作时间为空的话插入当前时间
|
||||||
if (sysLog.getDateTime() == null) {
|
if (sysLog.getCreateTime() == null) {
|
||||||
sysLog.setDateTime(new Date());
|
sysLog.setCreateTime(new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
return sysLog;
|
return sysLog;
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
package cn.stylefeng.roses.kernel.log.db.entity;
|
package cn.stylefeng.roses.kernel.log.db.entity;
|
||||||
|
|
||||||
|
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 日志记录
|
* 日志记录
|
||||||
*
|
*
|
||||||
|
@ -24,20 +22,20 @@ public class SysLog extends BaseEntity {
|
||||||
/**
|
/**
|
||||||
* 主键
|
* 主键
|
||||||
*/
|
*/
|
||||||
@TableId(type = IdType.ASSIGN_ID)
|
@TableId(value = "log_id", type = IdType.ASSIGN_ID)
|
||||||
private Long id;
|
private Long logId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 日志的名称,一般为业务名称
|
* 日志的名称,一般为业务名称
|
||||||
*/
|
*/
|
||||||
@TableField(value = "name")
|
@TableField(value = "log_name")
|
||||||
private String name;
|
private String logName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 日志记录的内容
|
* 日志记录的内容
|
||||||
*/
|
*/
|
||||||
@TableField(value = "content")
|
@TableField(value = "log_content")
|
||||||
private String content;
|
private String logContent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 服务名称,一般为spring.application.name
|
* 服务名称,一般为spring.application.name
|
||||||
|
@ -45,6 +43,12 @@ public class SysLog extends BaseEntity {
|
||||||
@TableField(value = "app_name")
|
@TableField(value = "app_name")
|
||||||
private String appName;
|
private String appName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前用户请求的url
|
||||||
|
*/
|
||||||
|
@TableField(value = "request_url")
|
||||||
|
private String requestUrl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* http或方法的请求参数体
|
* http或方法的请求参数体
|
||||||
*/
|
*/
|
||||||
|
@ -57,30 +61,12 @@ public class SysLog extends BaseEntity {
|
||||||
@TableField(value = "request_result")
|
@TableField(value = "request_result")
|
||||||
private String requestResult;
|
private String requestResult;
|
||||||
|
|
||||||
/**
|
|
||||||
* 操作发生的时间
|
|
||||||
*/
|
|
||||||
@TableField(value = "date_time")
|
|
||||||
private Date dateTime;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当前服务器的ip
|
* 当前服务器的ip
|
||||||
*/
|
*/
|
||||||
@TableField(value = "server_ip")
|
@TableField(value = "server_ip")
|
||||||
private String serverIp;
|
private String serverIp;
|
||||||
|
|
||||||
/**
|
|
||||||
* 客户端请求的token,如果是http请求,并且用户已经登录
|
|
||||||
*/
|
|
||||||
@TableField(value = "token")
|
|
||||||
private String token;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 客户端请求的用户id,如果是http请求,并且用户已经登录
|
|
||||||
*/
|
|
||||||
@TableField(value = "user_id")
|
|
||||||
private Long userId;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 客户端的ip
|
* 客户端的ip
|
||||||
*/
|
*/
|
||||||
|
@ -88,27 +74,27 @@ public class SysLog extends BaseEntity {
|
||||||
private String clientIp;
|
private String clientIp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当前用户请求的url
|
* 用户id
|
||||||
*/
|
*/
|
||||||
@TableField(value = "url")
|
@TableField(value = "user_id")
|
||||||
private String url;
|
private Long userId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 请求方式(GET POST PUT DELETE)
|
* 请求http方法
|
||||||
*/
|
*/
|
||||||
@TableField(value = "http_method")
|
@TableField(value = "http_method")
|
||||||
private String httpMethod;
|
private String httpMethod;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 浏览器,如果是http请求
|
* 客户浏览器标识
|
||||||
*/
|
*/
|
||||||
@TableField(value = "browser")
|
@TableField(value = "client_browser")
|
||||||
private String browser;
|
private String clientBrowser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 操作系统,如果是http请求
|
* 客户操作系统
|
||||||
*/
|
*/
|
||||||
@TableField(value = "os")
|
@TableField(value = "client_os")
|
||||||
private String os;
|
private String clientOs;
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue