<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.orion.visor.module.asset.dao.HostConnectLogDAO">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.orion.visor.module.asset.entity.domain.HostConnectLogDO">
        <id column="id" property="id"/>
        <result column="user_id" property="userId"/>
        <result column="username" property="username"/>
        <result column="host_id" property="hostId"/>
        <result column="host_name" property="hostName"/>
        <result column="host_address" property="hostAddress"/>
        <result column="type" property="type"/>
        <result column="token" property="token"/>
        <result column="status" property="status"/>
        <result column="start_time" property="startTime"/>
        <result column="end_time" property="endTime"/>
        <result column="extra_info" property="extraInfo"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <result column="deleted" property="deleted"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, user_id, username, host_id, host_name, host_address, type, token, status, start_time, end_time, extra_info, create_time, update_time, deleted
    </sql>

    <select id="selectLatestConnectHostId" resultType="java.lang.Long">
        SELECT host_id
        FROM host_connect_log
        WHERE deleted = 0
          AND type = #{type}
          AND user_id = #{userId}
        ORDER BY id DESC
        LIMIT #{limit}
    </select>

</mapper>
