<?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="cn.com.ctop.kuaishou.modules.report.mapper.KuaishouVideoEtlInfoMapper">

    <select id="getCompanyNameByUserId" resultType="java.lang.String">
        select company_name
        from user_company
        where user_id = #{planId} limit 1
    </select>

    <select id="getTotal" resultType="java.lang.Long">
        SELECT count(1)
        FROM ctop_etl_kuaishou_account_material_report_daily t1
                 INNER JOIN ctop_kuaishou_video_etl_info t2 ON t1.signature = t2.video_code
        WHERE t1.account_id = #{accountId}
          AND t1.stat_date &gt;= #{startTime}
          AND t1.stat_date &lt;= #{endTime}
    </select>

    <select id="queryPageList" resultType="com.alibaba.fastjson.JSONObject">
        SELECT t1.signature,
               t1.charge as 'charge',
               t1.activation as 'activation',
               t1.photo_show as 'photoShow',
               IFNULL(ROUND(t1.charge / t1.activation, 2),0) as 'activationCost',
               t2.url,
               t2.cover_url as 'coverUrl',
               t2.state_date as 'stateDate'
        FROM ctop_etl_kuaishou_account_material_report_daily t1
                 INNER JOIN ctop_kuaishou_video_etl_info t2 ON t1.signature = t2.video_code
        WHERE t1.account_id = #{accountId}
          AND t1.stat_date &gt;= #{startTime}
          AND t1.stat_date &lt;= #{endTime}
        <if test="sortCode == 'charge' ">
            ORDER BY t1.charge
        </if>
        <if test="sortCode == 'activationCost' ">
            ORDER BY t1.charge / t1.activation
        </if>
        <if test="sortCode == 'photoShow' ">
            ORDER BY t1.photo_show
        </if>
        <if test="sortCode == 'activation' ">
            ORDER BY t1.activation
        </if>
        ${sortType}
    </select>


</mapper>
