StatisticAnalysisCommonSQLMapper.xml 10.5 KB
Newer Older
shenggui.li committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "http://mybatis.org/dtd/mybatis-3-mapper.dtd" "mybatis-3-mapper.dtd" >
<mapper namespace="com.reyun.saas.report.data.dao.DataInfoDayMapper">
    <!--
        volume_dose	总量
        volume_dose_normal	正常总量
        rate_volume_dose_normal	正常总量占比
        volume_dose_exception	异常总量
        rate_volume_dose_exception	异常总量占比
        volume_dose_potential_risk	潜在风险总量
        rate_volume_dose_potential_risk	潜在风险总量占比

        added	新增
        added_normal	正常新增
        added_exception	异常新增
        rate_added_exception	异常新增占比

        dau	DAU
        dau_normal	正常DAU
        dau_exception	异常DAU
        rate_dau_exception	异常DAU占比

        update	更新
        update_normal	正常更新
        update_exception	异常更新
        rate_update_exception	异常更新占比

        cheat_total	作弊总数
        rate_cheat_total	作弊总数占比

    -->

    <sql id="commonStatisticAnalysisDataSQL">
        <if test="params.volume_dose!=null or params.rate_volume_dose_exception!=null or params.rate_volume_dose_potential_risk!=null or params.rate_volume_dose_normal!=null or params.cheat_total!=null or params.rate_cheat_total!=null">
            ,distinct_count_num as volume_dose
        </if>
        <if test="params.volume_dose_normal!=null or params.rate_volume_dose_normal!=null">
            ,case WHEN quantity = '1' then distinct_count_num else 0 end volume_dose_normal
        </if>
        <if test="params.volume_dose_exception!=null or params.rate_volume_dose_exception!=null">
            ,case WHEN quantity = '2' then distinct_count_num else 0 end volume_dose_exception
        </if>
        <if test="data.os==2">
            <if test="params.volume_dose_potential_risk!=null or params.rate_volume_dose_potential_risk!=null">
                ,case WHEN quantity = '5' then distinct_count_num else 0 end  volume_dose_potential_risk
            </if>
            <if test="params.cheat_total!=null or params.rate_cheat_total!=null">
                ,case WHEN quantity = '5' or quantity = '2' then distinct_count_num else 0 end  cheat_total
            </if>
            <if test="params.added_risk!=null or params.rate_added_risk!=null">
                ,case WHEN device_status = '1' and quantity = '2' then distinct_count_num else 0 end  added_risk
            </if>
            <if test="params.dau_risk!=null or params.rate_dau_risk!=null">
                ,case WHEN device_status = '2' and quantity = '2' then distinct_count_num else 0 end  dau_risk
            </if>
            <if test="params.update_risk!=null or params.rate_update_risk!=null">
                ,case WHEN appIsUpdate = '1' and quantity = '2'
                <choose>
                    <when test="params.idColumn=='app_version'">
                        and update_type = '1'
                    </when>
                    <when test="params.idColumn=='sdk_version'">
                        and update_type = '2'
                    </when>
                    <when test="params.idColumn=='system_version'">
                        and update_type = '3'
                    </when>
                </choose>
                then distinct_count_num else 0 end  update_risk
            </if>
        </if>

        <if test="params.added!=null or params.rate_added_exception!=null or params.rate_added_risk!=null">
            ,case WHEN device_status = '1' then distinct_count_num else 0 end added
        </if>
        <if test="params.added_normal!=null">
            ,case WHEN device_status = '1' and quantity = '1' then distinct_count_num else 0 end added_normal
        </if>
        <if test="params.added_exception!=null or params.rate_added_exception!=null">
            ,case WHEN device_status = '1' and quantity = '2' then distinct_count_num else 0 end added_exception
        </if>

        <if test="params.dau!=null or params.rate_dau_exception!=null or params.rate_dau_risk!=null">
            ,case WHEN device_status = '2'  then distinct_count_num else 0 end dau
        </if>
        <if test="params.dau_normal!=null">
            ,case WHEN device_status = '2' and quantity = '1' then distinct_count_num else 0 end dau_normal
        </if>
        <if test="params.dau_exception!=null or params.rate_dau_exception!=null">
           ,case WHEN device_status = '2' and quantity = '2' then distinct_count_num else 0 end dau_exception
        </if>

        <if test="params.update!=null or params.rate_update_exception!=null or params.rate_update_risk!=null">
            ,case WHEN appIsUpdate = '1'
            <choose>
                <when test="params.idColumn=='app_version'">
                    and update_type = '1'
                </when>
                <when test="params.idColumn=='sdk_version'">
                    and update_type = '2'
                </when>
                <when test="params.idColumn=='system_version'">
                    and update_type = '3'
                </when>
            </choose>
             then distinct_count_num else 0 end `update`
        </if>
        <if test="params.update_normal!=null">
            ,case WHEN appIsUpdate = '1' and quantity = '1'
            <choose>
                <when test="params.idColumn=='app_version'">
                    and update_type = '1'
                </when>
                <when test="params.idColumn=='sdk_version'">
                    and update_type = '2'
                </when>
                <when test="params.idColumn=='system_version'">
                    and update_type = '3'
                </when>
                <!--<otherwise>
                    and update_type = '0'
                </otherwise>-->
            </choose>
            then distinct_count_num else 0 end update_normal
        </if>
        <if test="params.update_exception!=null or params.rate_update_exception!=null">
            ,case WHEN appIsUpdate = '1' and quantity = '2'
            <choose>
                <when test="params.idColumn=='app_version'">
                    and update_type = '1'
                </when>
                <when test="params.idColumn=='sdk_version'">
                    and update_type = '2'
                </when>
                <when test="params.idColumn=='system_version'">
                    and update_type = '3'
                </when>
                <!--<otherwise>-->
                    <!--and update_type = '0'-->
                <!--</otherwise>-->
            </choose>
            then distinct_count_num else 0 end update_exception
        </if>
    </sql>




    <sql id="commonStatisticAnalysisSumSQL">
        <if test="params.volume_dose!=null">
            ,sum(volume_dose) as volume_dose
        </if>
        <if test="params.volume_dose_normal!=null">
            ,sum(volume_dose_normal) as volume_dose_normal
        </if>
        <if test="params.rate_volume_dose_normal!=null">
            ,case WHEN sum(volume_dose) = 0 or sum(volume_dose) is null then 0 else (sum(volume_dose_normal) / sum(volume_dose) * 100.0) end rate_volume_dose_normal
        </if>
        <if test="params.volume_dose_exception!=null">
            ,sum(volume_dose_exception) as volume_dose_exception
        </if>
        <if test="params.rate_volume_dose_exception!=null">
            ,case WHEN sum(volume_dose) = 0 then 0 else (sum(volume_dose_exception) / sum(volume_dose) * 100.0) end rate_volume_dose_exception
        </if>
        <if test="data.os==2">
            <if test="params.volume_dose_potential_risk!=null">
                ,sum(volume_dose_potential_risk) as volume_dose_potential_risk
            </if>
            <if test="params.rate_volume_dose_potential_risk!=null">
                ,case WHEN sum(volume_dose) = 0 then 0 else (sum(volume_dose_potential_risk) / sum(volume_dose) * 100.0) end rate_volume_dose_potential_risk
            </if>

            <if test="params.cheat_total!=null">
                ,sum(cheat_total) as cheat_total
            </if>
            <if test="params.rate_cheat_total!=null">
                ,case WHEN sum(volume_dose) = 0 then 0 else (sum(cheat_total) / sum(volume_dose) * 100.0) end rate_cheat_total
            </if>

            <if test="params.added_risk!=null">
                ,sum(added_risk) as added_risk
            </if>
            <if test="params.rate_added_risk!=null">
                ,case WHEN sum(added) = 0 then 0 else (sum(added_risk) / sum(added) * 100.0) end rate_added_risk
            </if>
            <if test="params.dau_risk!=null">
                ,sum(dau_risk) as dau_risk
            </if>
            <if test="params.rate_dau_risk!=null">
                ,case WHEN sum(dau) = 0 then 0 else (sum(dau_risk) / sum(dau) * 100.0) end rate_dau_risk
            </if>
            <if test="params.update_risk!=null">
                ,sum(update_risk) as update_risk
            </if>
            <if test="params.rate_update_risk!=null">
                ,case WHEN sum(`update`) = 0 then 0 else (sum(update_risk) / sum(`update`) * 100.0) end rate_update_risk
            </if>
        </if>

        <if test="params.added!=null">
            ,sum(added) as added
        </if>
        <if test="params.added_normal!=null">
            ,sum(added_normal) as added_normal
        </if>
        <if test="params.added_exception!=null">
            ,sum(added_exception) as added_exception
        </if>
        <if test="params.rate_added_exception!=null">
            ,CASE WHEN sum(added) = 0  then 0 else (sum(added_exception) / sum(added) * 100.0) end rate_added_exception
        </if>

        <if test="params.dau!=null">
            ,sum(dau) as dau
        </if>
        <if test="params.dau_normal!=null">
            ,sum(dau_normal) as dau_normal
        </if>
        <if test="params.dau_exception!=null">
            ,sum(dau_exception) as dau_exception
        </if>
        <if test="params.rate_dau_exception!=null">
            ,CASE WHEN sum(dau) = 0 then 0 else (sum(dau_exception) / sum(dau) * 100.0) end rate_dau_exception
        </if>

        <if test="params.update!=null">
            ,sum(`update`) as `update`
        </if>
        <if test="params.update_normal!=null">
            ,sum(update_normal) as update_normal
        </if>
        <if test="params.update_exception!=null">
            ,sum(update_exception) as update_exception
        </if>
        <if test="params.rate_update_exception!=null">
            ,CASE WHEN sum(`update`) = 0 then 0 else (sum(update_exception) / sum(`update`) * 100.0) end rate_update_exception
        </if>
    </sql>

</mapper>