package com.base.biz.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.base.biz.model.dto.request.LogRecordDTO;
import com.base.biz.model.entity.LogRecordInfo;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
import java.util.List;
import java.util.Objects;


@Mapper
@Repository
public interface LogRecordMapper extends BaseMapper<LogRecordInfo> {

    default List<LogRecordInfo> getLogInfos(LogRecordDTO req) {
        QueryWrapper<LogRecordInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper
                .eq(StringUtils.isNotEmpty(req.getServerName()), "server_name", req.getServerName())
                .eq(StringUtils.isNotEmpty(req.getLoggerName()), "logger_name", req.getLoggerName())
                .ge(Objects.nonNull(req.getStartTime()), "time", req.getStartTime())
                .le(Objects.nonNull(req.getEndTime()), "time", req.getEndTime());
        return this.selectList(queryWrapper);
    }
}
