<?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.ai.mapper.KuaishouAccountSpeedExploreLogMapper">

    <select id="getSpeedExploreGroupVosByParams"
            resultType="cn.com.ctop.kuaishou.modules.ai.vo.SpeedExploreGroupVO">
        select *from (select report.account_id,
                report.unit_id,
                report.campaign_id,
                report.charge,
                report.activation,
                report.bclick,
                report.form_count,
                report.event_pay,
        <if test="convertType=180">
            (case when activation=0 then 0 else round(report.charge/report.activation,2) end)as account,
        </if>
        <if test="convertType=2">
            (case when bclick=0 then 0 else round(report.charge/report.bclick,2) end)as account,
        </if>
        <if test="convertType=53">
            (case when form_count=0 then 0 else round(report.charge/report.form_count,2) end)as account,
        </if>
        <if test="convertType=190">
            (case when event_pay=0 then 0 else round(report.charge/report.event_pay,2) end)as account,
        </if>
        round(g.cpa_bid/1000,2) as cpaBid
         from ctop_kuaishou_group g
                  left join ctop_kuaishou_report_daily_group report
                            on report.unit_id = g.unit_id and report.stat_date = #{date}
         where g.study_status = 1
           and g.group_create_time like '2021-03-10%'
           and g.account_id = #{accountId}
           and report.account_id is not null
        <if test="convertType=180">
            and report.activation >= #{convertCount}
        </if>
        <if test="convertType=2">
            and report.bclick >= #{convertCount}
        </if>
        <if test="convertType=53">
            and report.form_count >= #{convertCount}
        </if>
        <if test="convertType=190">
            and report.event_pay >= #{convertCount}
        </if>) a
where a.cpaBid>a.activation_account order by a.account limit #{groupCount}
    </select>
</mapper>
