<?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.crawler.modules.pangolin.mapper.PangolinReportBillMonthMapper">
    <select id="checkAppList" resultType="cn.com.ctop.crawler.modules.pangolin.vo.PangolinReportAppMonthVO">
        select
       bill.date,
        <if test="appId == null">
            '-' as 'app_name',
        </if>
        <if test="appId != null">
            app.name as 'app_name',
        </if>
       bill.os as 'operate_system',
       sum(bill.sum_internal_activations) as 'sum_internal_activations',
       sum(bill.estimated_total_price) as 'estimated_total_price',
       round(avg(bill.account_quality_score),2) as 'account_quality_score',
       sum(bill.actual_total_price) as 'actual_total_price'
from ctop_pangolin_report_bill_month bill
         left join ctop_pangolin_app app on app.id = bill.app_id
         left join ctop_bind_account_login login on login.account_name = app.account_name
         where 1=1
         <if test="userId!=null">
             and login.user_id = #{userId}
         </if>
         <if test="appId!=null">
             and app.id = #{appId}
         </if>
        <if test="startDate!=null">
            and bill.date &gt;= #{startDate}
        </if>
        <if test="endDate!=null">
           and  bill.date &lt;= #{endDate}
        </if>
        <if test="operateSystem!=null">
           and bill.os = #{operateSystem}
        </if>
        group by bill.date,bill.os order by bill.date desc
    </select>
</mapper>
