<?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.xyzh.system.mapper.SysVisitStatisticsMapper">

    <!-- 基础结果映射 -->
    <resultMap id="BaseResultMap" type="org.xyzh.common.dto.system.TbSysVisitStatistics">
        <id column="id" property="id" jdbcType="VARCHAR"/>
        <result column="stat_date" property="statDate" jdbcType="DATE"/>
        <result column="total_visits" property="totalVisits" jdbcType="INTEGER"/>
        <result column="unique_visitors" property="uniqueVisitors" jdbcType="INTEGER"/>
        <result column="new_users" property="newUsers" jdbcType="INTEGER"/>
        <result column="active_users" property="activeUsers" jdbcType="INTEGER"/>
        <result column="page_views" property="pageViews" jdbcType="INTEGER"/>
        <result column="avg_visit_duration" property="avgVisitDuration" jdbcType="INTEGER"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    </resultMap>

    <!-- 基础字段 -->
    <sql id="Base_Column_List">
        id, stat_date, total_visits, unique_visitors, new_users, active_users, 
        page_views, avg_visit_duration, create_time, update_time
    </sql>

    <!-- 通用条件 -->
    <sql id="Where_Clause">
        <where>
            <if test="statDate != null">
                AND stat_date = #{statDate}
            </if>
        </where>
    </sql>

    <!-- selectSysVisitStatistics -->
    <select id="selectSysVisitStatistics" resultMap="BaseResultMap">
        SELECT 
        <include refid="Base_Column_List"/>
        FROM tb_sys_visit_statistics
        <include refid="Where_Clause"/>
        ORDER BY stat_date DESC
    </select>

</mapper>
