package com.css.simulation.oauth.client.mapper;

import api.common.pojo.po.log.LogLoginPO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface LogLoginMapper {

    @Select("SELECT" +
            " state" +
            " FROM log_login" +
            " WHERE " +
            " create_time >= (NOW() - INTERVAL #{hours} HOUR)" +
            " and user_id = #{userId}" +
            " ORDER BY create_time DESC" +
            " LIMIT #{counter}")
    @ResultType(LogLoginPO.class)
    List<LogLoginPO> selectLogByUserId(@Param("userId") String userId,@Param("hours") int hours,@Param("counter") int counter);

    @Insert("INSERT INTO log_login(id,user_id,username,ip,state,create_time)" +
            " VALUES(#{log.id}," +
            " #{log.userId}," +
            " #{log.username}," +
            " #{log.ip}," +
            " #{log.state}," +
            " #{log.createTime})")
    void insertLog(@Param("log") LogLoginPO logLoginPO);
}
