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})
|
||||
private String endDateTime;
|
||||
|
||||
/**
|
||||
* 第几页,从1开始
|
||||
*/
|
||||
private Integer pageNo;
|
||||
|
||||
/**
|
||||
* 每页大小
|
||||
*/
|
||||
private Integer pageSize;
|
||||
|
||||
/**
|
||||
* 日志的名称,一般为业务名称
|
||||
*/
|
||||
private String name;
|
||||
private String logName;
|
||||
|
||||
/**
|
||||
* 服务名称,一般为spring.application.name
|
||||
|
@ -59,11 +49,6 @@ public class LogManagerParam extends BaseRequest {
|
|||
*/
|
||||
private String serverIp;
|
||||
|
||||
/**
|
||||
* 客户端请求的token
|
||||
*/
|
||||
private String token;
|
||||
|
||||
/**
|
||||
* 客户端请求的用户id
|
||||
*/
|
||||
|
@ -77,6 +62,6 @@ public class LogManagerParam extends BaseRequest {
|
|||
/**
|
||||
* 当前用户请求的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.util.ObjectUtil;
|
||||
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.pojo.page.PageResult;
|
||||
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.record.LogRecordDTO;
|
||||
import cn.stylefeng.roses.kernel.log.db.entity.SysLog;
|
||||
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 org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -103,14 +103,15 @@ public class DbLogManagerServiceImpl implements LogManagerApi {
|
|||
* @date 2020/11/3 11:22
|
||||
*/
|
||||
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)) {
|
||||
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查询
|
||||
Long userId = logManagerParam.getUserId();
|
||||
if (userId != null) {
|
||||
|
@ -155,15 +148,15 @@ public class DbLogManagerServiceImpl implements LogManagerApi {
|
|||
}
|
||||
|
||||
// 根据当前用户请求的url查询
|
||||
String url = logManagerParam.getUrl();
|
||||
String url = logManagerParam.getRequestUrl();
|
||||
if (StrUtil.isNotEmpty(clientIp)) {
|
||||
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);
|
||||
|
||||
// 日志名称为空的话则获取默认日志名称
|
||||
if (StrUtil.isEmpty(sysLog.getName())) {
|
||||
sysLog.setName(LogConstants.LOG_DEFAULT_NAME);
|
||||
if (StrUtil.isEmpty(sysLog.getLogName())) {
|
||||
sysLog.setLogName(LogConstants.LOG_DEFAULT_NAME);
|
||||
}
|
||||
|
||||
// 服务名称为空的话则获取默认服务名称
|
||||
|
@ -97,9 +97,10 @@ public class DbLogRecordServiceImpl implements LogRecordApi {
|
|||
}
|
||||
|
||||
// 如果操作时间为空的话插入当前时间
|
||||
if (sysLog.getDateTime() == null) {
|
||||
sysLog.setDateTime(new Date());
|
||||
if (sysLog.getCreateTime() == null) {
|
||||
sysLog.setCreateTime(new Date());
|
||||
}
|
||||
|
||||
return sysLog;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
|
|
|
@ -1,15 +1,13 @@
|
|||
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.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 日志记录
|
||||
*
|
||||
|
@ -24,20 +22,20 @@ public class SysLog extends BaseEntity {
|
|||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
@TableId(value = "log_id", type = IdType.ASSIGN_ID)
|
||||
private Long logId;
|
||||
|
||||
/**
|
||||
* 日志的名称,一般为业务名称
|
||||
*/
|
||||
@TableField(value = "name")
|
||||
private String name;
|
||||
@TableField(value = "log_name")
|
||||
private String logName;
|
||||
|
||||
/**
|
||||
* 日志记录的内容
|
||||
*/
|
||||
@TableField(value = "content")
|
||||
private String content;
|
||||
@TableField(value = "log_content")
|
||||
private String logContent;
|
||||
|
||||
/**
|
||||
* 服务名称,一般为spring.application.name
|
||||
|
@ -45,6 +43,12 @@ public class SysLog extends BaseEntity {
|
|||
@TableField(value = "app_name")
|
||||
private String appName;
|
||||
|
||||
/**
|
||||
* 当前用户请求的url
|
||||
*/
|
||||
@TableField(value = "request_url")
|
||||
private String requestUrl;
|
||||
|
||||
/**
|
||||
* http或方法的请求参数体
|
||||
*/
|
||||
|
@ -57,30 +61,12 @@ public class SysLog extends BaseEntity {
|
|||
@TableField(value = "request_result")
|
||||
private String requestResult;
|
||||
|
||||
/**
|
||||
* 操作发生的时间
|
||||
*/
|
||||
@TableField(value = "date_time")
|
||||
private Date dateTime;
|
||||
|
||||
/**
|
||||
* 当前服务器的ip
|
||||
*/
|
||||
@TableField(value = "server_ip")
|
||||
private String serverIp;
|
||||
|
||||
/**
|
||||
* 客户端请求的token,如果是http请求,并且用户已经登录
|
||||
*/
|
||||
@TableField(value = "token")
|
||||
private String token;
|
||||
|
||||
/**
|
||||
* 客户端请求的用户id,如果是http请求,并且用户已经登录
|
||||
*/
|
||||
@TableField(value = "user_id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 客户端的ip
|
||||
*/
|
||||
|
@ -88,27 +74,27 @@ public class SysLog extends BaseEntity {
|
|||
private String clientIp;
|
||||
|
||||
/**
|
||||
* 当前用户请求的url
|
||||
* 用户id
|
||||
*/
|
||||
@TableField(value = "url")
|
||||
private String url;
|
||||
@TableField(value = "user_id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 请求方式(GET POST PUT DELETE)
|
||||
* 请求http方法
|
||||
*/
|
||||
@TableField(value = "http_method")
|
||||
private String httpMethod;
|
||||
|
||||
/**
|
||||
* 浏览器,如果是http请求
|
||||
* 客户浏览器标识
|
||||
*/
|
||||
@TableField(value = "browser")
|
||||
private String browser;
|
||||
@TableField(value = "client_browser")
|
||||
private String clientBrowser;
|
||||
|
||||
/**
|
||||
* 操作系统,如果是http请求
|
||||
* 客户操作系统
|
||||
*/
|
||||
@TableField(value = "os")
|
||||
private String os;
|
||||
@TableField(value = "client_os")
|
||||
private String clientOs;
|
||||
|
||||
}
|
Loading…
Reference in New Issue