<?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.moka.gdtauto.mapper.TencentConversionMapper">

    <resultMap id="BaseResultMap" type="com.moka.gdtauto.entity.TencentConversion">
        <id column="id" property="id"/>
        <result column="org_account_id" property="orgAccountId"/>
        <result column="account_id" property="accountId"/>
        <result column="conversion_id" property="conversionId"/>
        <result column="conversion_name" property="conversionName"/>
        <result column="conversion_type" property="conversionType"/>
        <result column="access_type" property="accessType"/>
        <result column="claim_type" property="claimType"/>
        <result column="feedback_url" property="feedbackUrl"/>
        <result column="self_attributed_status" property="selfAttributedStatus"/>
        <result column="app_id" property="appId"/>
        <result column="package_id" property="packageId"/>
        <result column="ios_app_id" property="iosAppId"/>
        <result column="universal_link" property="universalLink"/>
        <result column="android_deep_link" property="androidDeepLink"/>
        <result column="ios_deep_link" property="iosDeepLink"/>
        <result column="deep_link_url" property="deepLinkUrl"/>
        <result column="page_url" property="pageUrl"/>
        <result column="created_time" property="createdTime"/>
        <result column="updated_time" property="updatedTime"/>
    </resultMap>

    <!-- 按转化类型统计数量 -->
    <select id="selectCountByType" resultType="map">
        SELECT 
            conversion_type as type,
            COUNT(*) as count
        FROM tencent_conversion 
        GROUP BY conversion_type 
        ORDER BY count DESC
    </select>

    <!-- 按账户统计转化数量 -->
    <select id="selectCountByAccount" resultType="map">
        SELECT 
            account_id as accountId,
            COUNT(*) as count
        FROM tencent_conversion 
        GROUP BY account_id 
        ORDER BY count DESC 
        LIMIT 5
    </select>

    <!-- 统计今日新增转化数量 -->
    <select id="selectTodayCount" resultType="long">
        SELECT COUNT(*) 
        FROM tencent_conversion 
        WHERE created_time BETWEEN #{startTime} AND #{endTime}
    </select>

    <!-- 统计指定时间段内的转化数量 -->
    <select id="selectPeriodCount" resultType="long">
        SELECT COUNT(*) 
        FROM tencent_conversion 
        WHERE created_time BETWEEN #{startTime} AND #{endTime}
    </select>

</mapper>