com.github.rexsheng.springboot.faster.system.log.infrastructure.LogGatewayImpl Maven / Gradle / Ivy
The newest version!
package com.github.rexsheng.springboot.faster.system.log.infrastructure;
import com.github.rexsheng.springboot.faster.common.domain.PagedList;
import com.github.rexsheng.springboot.faster.system.entity.Log;
import com.github.rexsheng.springboot.faster.system.entity.table.LogTableDef;
import com.github.rexsheng.springboot.faster.system.log.domain.SysLog;
import com.github.rexsheng.springboot.faster.system.log.domain.gateway.LogGateway;
import com.github.rexsheng.springboot.faster.system.log.domain.gateway.QueryLogDO;
import com.github.rexsheng.springboot.faster.system.mapper.LogMapper;
import com.github.rexsheng.springboot.faster.system.utils.PageConverter;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.util.StringUtils;
@ConditionalOnClass(BaseMapper.class)
public class LogGatewayImpl implements LogGateway {
@Resource
private LogMapper logMapper;
@Override
public void writeLog(SysLog sysLog) {
logMapper.insertOrDuplicateUpdate(sysLog);
}
@Override
public PagedList paginateLog(QueryLogDO query) {
QueryWrapper queryWrapper=QueryWrapper.create()
.orderBy(LogTableDef.LOG.START_TIME,false);
if(StringUtils.hasText(query.getKeyword())){
queryWrapper.where(LogTableDef.LOG.ERROR_MSG.like(query.getKeyword())
.or(LogTableDef.LOG.REQUEST_PARAM.like(query.getKeyword()))
.or(LogTableDef.LOG.METHOD_NOTE.like(query.getKeyword())));
}
if(query.getStartTime()!=null){
queryWrapper.where(LogTableDef.LOG.START_TIME.ge(query.getStartTime()));
}
if(query.getEndTime()!=null){
queryWrapper.where(LogTableDef.LOG.START_TIME.le(query.getEndTime()));
}
if(StringUtils.hasText(query.getModule())){
queryWrapper.where(LogTableDef.LOG.MODULE.eq(query.getModule()));
}
if(StringUtils.hasText(query.getRequestMethod())){
queryWrapper.where(LogTableDef.LOG.REQUEST_METHOD.eq(query.getRequestMethod()));
}
if(query.getUserId()!=null){
queryWrapper.where(LogTableDef.LOG.USER.eq(query.getUserId()));
}
if(query.getError()!=null){
queryWrapper.where(LogTableDef.LOG.ERROR.eq(query.getError()));
}
queryWrapper.where(LogTableDef.LOG.METHOD_NOTE.isNotNull(query.getSearchNullableMethodNote()!=null && Boolean.FALSE.equals(query.getSearchNullableMethodNote())));
if(StringUtils.hasText(query.getRequestUrl())){
queryWrapper.where(LogTableDef.LOG.REQUEST_URL.like(query.getRequestUrl()));
}
Page sourceList=logMapper.paginate(query.getPageIndex(),query.getPageSize(),queryWrapper);
return PageConverter.convert(sourceList,this::map);
}
private SysLog map(Log entity){
SysLog sysLog=new SysLog();
sysLog.setLogId(entity.getId());
sysLog.setClassName(entity.getClassName());
sysLog.setMethodName(entity.getMethodName());
sysLog.setMethodNote(entity.getMethodNote());
sysLog.setRequestMethod(entity.getRequestMethod());
sysLog.setRequestUrl(entity.getRequestUrl());
sysLog.setRequestIp(entity.getRequestIp());
sysLog.setRequestParam(entity.getRequestParam());
sysLog.setRequestHeader(entity.getRequestHeader());
sysLog.setUserAgent(entity.getUserAgent());
sysLog.setServer(entity.getServer());
sysLog.setModule(entity.getModule());
sysLog.setUser(entity.getUser());
sysLog.setStartTime(entity.getStartTime());
sysLog.setEndTime(entity.getEndTime());
sysLog.setCostTime(entity.getCostTime());
sysLog.setError(entity.getError());
sysLog.setErrorMsg(entity.getErrorMsg());
return sysLog;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy