<?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.roadm.mapper.SmsSpDaySummaryMapper">

    <resultMap type="cn.roadm.bo.SmsSpDaySummaryBO" id="SmsSpDaySummaryMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="spid" column="spid" jdbcType="INTEGER"/>
        <result property="statTime" column="stat_time" jdbcType="TIMESTAMP"/>
        <result property="succ" column="succ" jdbcType="INTEGER"/>
        <result property="fail" column="fail" jdbcType="INTEGER"/>
        <result property="arriveSucc" column="arrive_succ" jdbcType="INTEGER"/>
        <result property="arriveFail" column="arrive_fail" jdbcType="INTEGER"/>
        <result property="succPhone" column="succ_phone" jdbcType="INTEGER"/>
        <result property="failPhone" column="fail_phone" jdbcType="INTEGER"/>
        <result property="arriveSuccPhone" column="arrive_succ_phone" jdbcType="INTEGER"/>
        <result property="arriveFailPhone" column="arrive_fail_phone" jdbcType="INTEGER"/>
        <result property="allnumber" column="allnumber" jdbcType="INTEGER"/>
        <result property="total" column="total" jdbcType="INTEGER"/>
    </resultMap>

    <!--查询指定行数据-->
    <select id="listPageSmsSpDaySummaryList" resultMap="SmsSpDaySummaryMap">
        select
        ds.spid,
        <if test="countDay!=null and countDay==1">
            date_format(ds.stat_time,'%Y-%m-%d') stat_time,
        </if>
        sum(ifnull(ds.succ,0)) succ,
        sum(ifnull(ds.fail,0)) fail,
        sum(ifnull(ds.arrive_succ,0)) arrive_succ,
        sum(ifnull(ds.arrive_fail,0)) arrive_fail,
        sum(ifnull(ds.succ_phone,0)) succ_phone,
        sum(ifnull(ds.fail_phone,0)) fail_phone,
        sum(ifnull(ds.arrive_succ_phone,0)) arrive_succ_phone,
        sum(ifnull(ds.arrive_fail_phone,0)) arrive_fail_phone,
        sum(ifnull(ds.push_succ,0)) push_succ,
        sum(ifnull(ss.total,0)) total,
        sum(ifnull(ss.allnumber,0)) allnumber
        from
        sms_sp_day_summary ds
        left join sms_sp_summary ss on
        ss.spid = ds.spid
        and ss.stat_time = ds.stat_time
        <where>
            <if test="spid != null">
                and ds.spid = #{spid}
            </if>
            <if test="statTime != null and statTime!=''">
                and ds.stat_time &gt;=concat(#{statTime},' 00:00:00')
            </if>
            <if test="statTimeEnd != null and statTimeEnd!=''">
                and ds.stat_time &lt;
                DATE_ADD(str_to_date(#{statTimeEnd},'%Y-%m-%d'),INTERVAL
                1 DAY)
            </if>
        </where>
        group by
        ds.spid
        <if test="countDay!=null and countDay==1">
            ,ds.stat_time
            order by ds.stat_time desc
        </if>
    </select>
    <select id="summaryTotal" resultMap="SmsSpDaySummaryMap">
        select
        sum(ifnull(ds.succ,0))succ,
        sum(ifnull(ds.fail,0))fail,
        sum(ifnull(ds.arrive_succ,0))arrive_succ,
        sum(ifnull(ds.arrive_fail,0))arrive_fail,
        sum(ifnull(ds.succ_phone,0))succ_phone,
        sum(ifnull(ds.fail_phone,0))fail_phone,
        sum(ifnull(ds.arrive_succ_phone,0))arrive_succ_phone,
        sum(ifnull(ds.arrive_fail_phone,0))arrive_fail_phone,
        sum(ifnull(ds.push_succ,0)) push_succ,
        sum(ifnull(ss.total,0)) total,
        sum(ifnull(ss.allnumber,0))allnumber
        from
        sms_sp_day_summary ds
        left join sms_sp_summary ss on
        ss.spid = ds.spid
        and ss.stat_time = ds.stat_time
        <where>
            <if test="spid != null">
                and ds.spid = #{spid}
            </if>
            <if test="statTime != null and statTime!=''">
                and ds.stat_time &gt;=concat(#{statTime},' 00:00:00')
            </if>
            <if test="statTimeEnd != null and statTimeEnd!=''">
                and ds.stat_time &lt;
                DATE_ADD(str_to_date(#{statTimeEnd},'%Y-%m-%d'),INTERVAL
                1 DAY)
            </if>
        </where>

    </select>

</mapper>

