<?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.ChannelSummaryMapper">
    <resultMap type="ChannelSummary" id="ChannelSummaryResultMap">
        <result column="spId" property="spId" />
        <result column="number" property="number" />
        <result column="arrivalNumber" property="arrivalNumber" />
        <result column="monthDay" property="monthDay" />
    </resultMap>
    <resultMap type="ChannelSummaryGroupByChannel" id="ChannelSummaryGroupByChannelResultMap">
        <result column="spId" property="spId" />
        <result column="channelId" property="channelId" />
        <result column="channelName" property="channelName" />
        <result column="number" property="number" />
        <result column="arrivalNumber" property="arrivalNumber" />
        <result column="monthDay" property="monthDay" />
    </resultMap>
    <select id="listChannelSummary" parameterType="cn.roadm.bo.ChannelSummaryQueryParams"
    	resultMap="ChannelSummaryResultMap">
		SELECT any_value(spid) spId, SUM(submit_total) number, SUM(arrive_total) AS arrivalNumber, 
			stat_time monthDay  
		FROM sms_sp_channel_summary 
		WHERE 1=1 
        <if test="spId!=null and spId!=''">
            and spId = #{spId}
        </if>
        <if test="fromDate!=null and fromDate!=''">
	        AND stat_time >= #{fromDate}
        </if>
        <if test="toDate!=null and toDate!=''">
	        AND stat_time &lt;= #{toDate}
        </if>
		GROUP BY stat_time
    </select>

    <select id="getChannelSummaryGroupByChannel" parameterType="cn.roadm.bo.ChannelSummaryQueryParams"
       resultMap="ChannelSummaryGroupByChannelResultMap">
		SELECT s.channelid channelId, p.name channelName, SUM(s.submit_total) number, SUM(s.arrive_total) AS arrivalNumber, 
		s.stat_time monthDay
    	FROM sms_sp_channel_summary s LEFT JOIN sms_carrier_channel_info p
	    	ON s.channelid = p.id 
		WHERE 1=1 
    	<if test="spId!=null and spId!=''">
            and spId = #{spId}
        </if>
        <if test="fromDate!=null and fromDate!=''">
	        AND stat_time >= #{fromDate}
        </if>
        <if test="toDate!=null and toDate!=''">
	        AND stat_time &lt;= #{toDate}
        </if>
    	GROUP BY s.stat_time, s.channelid
    	LIMIT 10
    </select>

</mapper>