package com.jy.log.dao;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jy.framework.model.base.BaseDao;
import com.jy.log.mapper.LogAccessMapper;
import com.jy.log.model.dto.LogAccessSelectDto;
import com.jy.log.model.entity.LogAccess;
import com.jy.log.model.table.LogAccessTable;
import com.jy.log.model.vo.LogAccessVo;
import org.springframework.stereotype.Service;

@Service
public class LogAccessDao extends BaseDao<LogAccessMapper, LogAccess> {

    /**
     * 访问日志分页
     */
    public Page<LogAccessVo> getPage(LogAccessSelectDto dto) {
        LogAccessTable la = LogAccessTable.la;

        return sql(LogAccessVo.class)
                .select(
                        la.id,
                        la.username,
                        la.ip,
                        la.location,
                        la.browser,
                        la.os,
                        la.status,
                        la.msg,
                        la.accessTime
                )
                .from(la)
                .where(
                        la.username.like(dto.getUsername()),
                        la.status.eq(dto.getStatus()),
                        la.accessTime.between(dto.getAccessTime())
                )
                .orderBy(la.id.desc())
                .page(dto.getPage());
    }

}
