<?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.taiji.video.mapper.HtDpVideoAnalysisMapper">

    <select id="selectFilter" resultType="AnalysisDTO">
        SELECT type,sum(pic_analysis_total) AS count FROM `ht_dp_video_analysis`
        <where>
        <if test="year != null and year != ''">
            and `year` = #{year}
        </if>
        <if test="yearMonth != null and yearMonth != ''">
            and `year_month` = #{yearMonth}
        </if>
        </where>
        GROUP BY type
    </select>
    <select id="selecttotal" resultType="cn.com.taiji.video.model.VideoAnalysisLineDTO">
        SELECT
        <if test="year != null and year != ''">
            t.`year_month` as time,
            (select sum(pic_analysis_total) / 10000 from `ht_dp_video_analysis` t1 where t1.`year_month` = t.`year_month` and t1.type = 1) as face,
            (select sum(pic_analysis_total) / 10000 from `ht_dp_video_analysis` t1 where t1.`year_month` = t.`year_month` and t1.type = 2) as car,
            (select sum(pic_analysis_total) / 10000 from `ht_dp_video_analysis` t1 where t1.`year_month` = t.`year_month` and t1.type = 3) as body
        </if>
        <if test="yearMonth != null and yearMonth != ''">
            t.stat_date as time,
            (select sum(pic_analysis_total) / 10000 from `ht_dp_video_analysis` t1 where t1.stat_date = t.stat_date and t1.type = 1) as face,
            (select sum(pic_analysis_total) / 10000 from `ht_dp_video_analysis` t1 where t1.stat_date = t.stat_date and t1.type = 2) as car,
            (select sum(pic_analysis_total) / 10000 from `ht_dp_video_analysis` t1 where t1.stat_date = t.stat_date and t1.type = 3) as body
        </if>
        FROM `ht_dp_video_analysis` t
        where
        <if test="year != null and year != ''">
            t.`year` = #{year}
        </if>
        <if test="yearMonth != null and yearMonth != ''">
            t.`year_month` = #{yearMonth}
        </if>
        GROUP BY
        <if test="year != null and year != ''">
            t.`year_month`
        </if>
        <if test="yearMonth != null and yearMonth != ''">
            t.stat_date
        </if>
    </select>
</mapper>