【log】整理log模块的字段和业务

pull/3/head
fengshuonan 2020-12-19 15:49:21 +08:00
parent 6f01287ce4
commit 0e7cb3897e
4 changed files with 40 additions and 75 deletions

View File

@ -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;
}

View File

@ -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);
}
/**

View File

@ -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());

View File

@ -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;
}