初始化访问日志、异常日志的插入

pull/2/head
YunaiV 2021-09-27 09:12:43 +08:00
parent c81c275a97
commit 15e2c0945d
14 changed files with 400 additions and 6 deletions

View File

@ -32,10 +32,9 @@ public class InfApiAccessLogServiceImpl implements InfApiAccessLogService {
@Override
@Async
public Future<Boolean> createApiAccessLogAsync(ApiAccessLogCreateDTO createDTO) {
// 插入
InfApiAccessLogDO apiAccessLog = InfApiAccessLogConvert.INSTANCE.convert(createDTO);
int insert = apiAccessLogMapper.insert(apiAccessLog);
return new AsyncResult<>(insert == 1);
return new AsyncResult<>(insert > 1);
}
@Override

View File

@ -0,0 +1,20 @@
package cn.iocoder.yudao.userserver.modules.infra.convert.logger;
import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateDTO;
import cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger.InfApiAccessLogDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
/**
* API 访 Convert
*
* @author
*/
@Mapper
public interface InfApiAccessLogConvert {
InfApiAccessLogConvert INSTANCE = Mappers.getMapper(InfApiAccessLogConvert.class);
InfApiAccessLogDO convert(ApiAccessLogCreateDTO bean);
}

View File

@ -0,0 +1,20 @@
package cn.iocoder.yudao.userserver.modules.infra.convert.logger;
import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateDTO;
import cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger.InfApiErrorLogDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
/**
* API Convert
*
* @author
*/
@Mapper
public interface InfApiErrorLogConvert {
InfApiErrorLogConvert INSTANCE = Mappers.getMapper(InfApiErrorLogConvert.class);
InfApiErrorLogDO convert(ApiErrorLogCreateDTO bean);
}

View File

@ -0,0 +1,6 @@
/**
* POJO
*
* 使 MapStruct
*/
package cn.iocoder.yudao.userserver.modules.infra.convert;

View File

@ -0,0 +1 @@
<http://www.iocoder.cn/Spring-Boot/MapStruct/?yudao>

View File

@ -0,0 +1,107 @@
package cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger;
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
import java.util.Date;
/**
* API 访
*
* @author
*/
@TableName("inf_api_access_log")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class InfApiAccessLogDO extends BaseDO {
/**
*
*/
@TableId
private Integer id;
/**
*
*
* 访logger
*/
private String traceId;
/**
*
*/
private Long userId;
/**
*
*
* {@link UserTypeEnum}
*/
private Integer userType;
/**
*
*
* `spring.application.name`
*/
private String applicationName;
// ========== 请求相关字段 ==========
/**
*
*/
private String requestMethod;
/**
* 访
*/
private String requestUrl;
/**
*
*
* query: Query String
* body: Quest Body
*/
private String requestParams;
/**
* IP
*/
private String userIp;
/**
* UA
*/
private String userAgent;
// ========== 执行相关字段 ==========
/**
*
*/
private Date beginTime;
/**
*
*/
private Date endTime;
/**
*
*/
private Integer duration;
/**
*
*
* 使 {@link CommonResult#getCode()}
*/
private Integer resultCode;
/**
*
*
* 使 {@link CommonResult#getMsg()}
*/
private String resultMsg;
}

View File

@ -0,0 +1,152 @@
package cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger;
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.yudao.userserver.modules.infra.enums.logger.InfApiErrorLogProcessStatusEnum;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.*;
import java.util.Date;
/**
* API
*
* @author
*/
@TableName("inf_api_error_log")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class InfApiErrorLogDO extends BaseDO {
/**
*
*/
private Long id;
/**
*
*/
private Long userId;
/**
*
*
* 访logger
*/
private String traceId;
/**
*
*
* {@link UserTypeEnum}
*/
private Integer userType;
/**
*
*
* spring.application.name
*/
private String applicationName;
// ========== 请求相关字段 ==========
/**
*
*/
private String requestMethod;
/**
* 访
*/
private String requestUrl;
/**
*
*
* query: Query String
* body: Quest Body
*/
private String requestParams;
/**
* IP
*/
private String userIp;
/**
* UA
*/
private String userAgent;
// ========== 异常相关字段 ==========
/**
*
*/
private Date exceptionTime;
/**
*
*
* {@link Throwable#getClass()}
*/
private String exceptionName;
/**
*
*
* {@link cn.hutool.core.exceptions.ExceptionUtil#getMessage(Throwable)}
*/
private String exceptionMessage;
/**
*
*
* {@link cn.hutool.core.exceptions.ExceptionUtil#getRootCauseMessage(Throwable)}
*/
private String exceptionRootCauseMessage;
/**
*
*
* {@link org.apache.commons.lang3.exception.ExceptionUtils#getStackTrace(Throwable)}
*/
private String exceptionStackTrace;
/**
*
*
* {@link StackTraceElement#getClassName()}
*/
private String exceptionClassName;
/**
*
*
* {@link StackTraceElement#getFileName()}
*/
private String exceptionFileName;
/**
*
*
* {@link StackTraceElement#getMethodName()}
*/
private String exceptionMethodName;
/**
*
*
* {@link StackTraceElement#getLineNumber()}
*/
private Integer exceptionLineNumber;
// ========== 处理相关字段 ==========
/**
*
*
* {@link InfApiErrorLogProcessStatusEnum}
*/
private Integer processStatus;
/**
*
*/
private Date processTime;
/**
*
*
* cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.user.SysUserDO.SysUserDO#getId()
*/
private Long processUserId;
}

View File

@ -0,0 +1,16 @@
package cn.iocoder.yudao.userserver.modules.infra.dal.mysql.logger;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger.InfApiAccessLogDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* API 访 Mapper
*
* @author
*/
@Mapper
public interface InfApiAccessLogMapper extends BaseMapperX<InfApiAccessLogDO> {
}

View File

@ -0,0 +1,14 @@
package cn.iocoder.yudao.userserver.modules.infra.dal.mysql.logger;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger.InfApiErrorLogDO;
import org.apache.ibatis.annotations.Mapper;
/**
* API Mapper
*
* @author
*/
@Mapper
public interface InfApiErrorLogMapper extends BaseMapperX<InfApiErrorLogDO> {
}

View File

@ -0,0 +1,28 @@
package cn.iocoder.yudao.userserver.modules.infra.enums.logger;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* API
*
* @author
*/
@AllArgsConstructor
@Getter
public enum InfApiErrorLogProcessStatusEnum {
INIT(0, "未处理"),
DONE(1, "已处理"),
IGNORE(2, "已忽略");
/**
*
*/
private final Integer status;
/**
*
*/
private final String name;
}

View File

@ -0,0 +1,4 @@
/**
*
*/
package cn.iocoder.yudao.userserver.modules.infra.enums;

View File

@ -1,12 +1,16 @@
package cn.iocoder.yudao.userserver.modules.infra.service.logger.impl;
import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiAccessLogCreateDTO;
import cn.iocoder.yudao.userserver.modules.infra.convert.logger.InfApiAccessLogConvert;
import cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger.InfApiAccessLogDO;
import cn.iocoder.yudao.userserver.modules.infra.dal.mysql.logger.InfApiAccessLogMapper;
import cn.iocoder.yudao.userserver.modules.infra.service.logger.InfApiAccessLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.concurrent.Future;
/**
@ -19,9 +23,14 @@ import java.util.concurrent.Future;
@Slf4j
public class InfApiAccessLogServiceImpl implements InfApiAccessLogService {
@Resource
private InfApiAccessLogMapper apiAccessLogMapper;
@Override
public Future<Boolean> createApiAccessLogAsync(ApiAccessLogCreateDTO createDTO) {
log.debug("{}", createDTO);
return new AsyncResult<>(true);
InfApiAccessLogDO apiAccessLog = InfApiAccessLogConvert.INSTANCE.convert(createDTO);
int insert = apiAccessLogMapper.insert(apiAccessLog);
return new AsyncResult<>(insert > 1);
}
}

View File

@ -1,12 +1,17 @@
package cn.iocoder.yudao.userserver.modules.infra.service.logger.impl;
import cn.iocoder.yudao.framework.apilog.core.service.dto.ApiErrorLogCreateDTO;
import cn.iocoder.yudao.userserver.modules.infra.convert.logger.InfApiErrorLogConvert;
import cn.iocoder.yudao.userserver.modules.infra.dal.dataobject.logger.InfApiErrorLogDO;
import cn.iocoder.yudao.userserver.modules.infra.dal.mysql.logger.InfApiErrorLogMapper;
import cn.iocoder.yudao.userserver.modules.infra.enums.logger.InfApiErrorLogProcessStatusEnum;
import cn.iocoder.yudao.userserver.modules.infra.service.logger.InfApiErrorLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.concurrent.Future;
/**
@ -19,9 +24,15 @@ import java.util.concurrent.Future;
@Slf4j
public class InfApiErrorLogServiceImpl implements InfApiErrorLogService {
@Resource
private InfApiErrorLogMapper apiErrorLogMapper;
@Override
public Future<Boolean> createApiErrorLogAsync(ApiErrorLogCreateDTO createDTO) {
log.debug("{}", createDTO);
return new AsyncResult<>(true);
InfApiErrorLogDO apiErrorLog = InfApiErrorLogConvert.INSTANCE.convert(createDTO);
apiErrorLog.setProcessStatus(InfApiErrorLogProcessStatusEnum.INIT.getStatus());
int insert = apiErrorLogMapper.insert(apiErrorLog);
return new AsyncResult<>(insert == 1);
}
}

View File

@ -0,0 +1,7 @@
/**
* system
*
*
* sys
*/
package cn.iocoder.yudao.userserver.modules.system;