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

View File

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

View File

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

View File

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