<?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="org.dromara.visor.module.asset.dao.TerminalConnectLogDAO">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="org.dromara.visor.module.asset.entity.domain.TerminalConnectLogDO">
        <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="session_id" property="sessionId"/>
        <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>

    <!-- 数量查询映射结果 -->
    <resultMap id="CountResultMap" type="org.dromara.visor.module.asset.entity.po.TerminalConnectLogCountPO">
        <result column="connect_date" property="connectDate"/>
        <result column="type" property="type"/>
        <result column="total_count" property="count"/>
    </resultMap>

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

    <select id="selectConnectLogUserCount" resultMap="CountResultMap">
        SELECT DATE(create_time) connect_date, COUNT(1) total_count
        FROM terminal_connect_log
        WHERE deleted = 0
          AND user_id = #{userId}
          AND create_time BETWEEN #{startTime} AND #{endTime}
        GROUP BY connect_date
    </select>

</mapper>
