<?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.NullInterfaceMapper">

    <resultMap type="NullInterface" id="NullInterfaceResultMap">
        <id column="id" property="id" />
        <result column="sp_id" property="spId" />
        <result column="spName" property="spName" />
        <result column="count" property="count"/>
        <result column="time" property="time" />
        <result column="type" property="type" />
        <result column="counts" property="counts" />

    </resultMap>

    <select id="listPageNullInterface" parameterType="NullInterface"
            resultMap="NullInterfaceResultMap">
        select
            sp.id as spId,
            sp.sp_name as spName,
            SUM(ds.count) AS count,
            ds.type,
            <if test="typeDay != null and typeDay == 'day'">
                DATE_FORMAT(ds.time, '%Y-%m-%d') as time
            </if>
            <if test="typeDay == null or typeDay != 'day'">
                NULL as time
            </if>
        from deduct_null_interface_summary ds left join sms_sp_info sp on sp.id=ds.sp_id
        <where>
            <if test="spId != null and spId != ''">
                AND ds.sp_id LIKE CONCAT('%', #{spId}, '%')
            </if>
            <if test="type != null and type != ''">
                AND ds.type LIKE CONCAT('%', #{type}, '%')
            </if>
            <if test="timeStart != null and timeStart != ''">
                AND ds.time &gt;= #{timeStart}
            </if>
            <if test="timeEnd != null and timeEnd != ''">
                AND ds.time &lt;= #{timeEnd}
            </if>
        </where>
        group by sp.id,sp.sp_name,ds.type
        <if test="typeDay!=null and typeDay == 'day'">
            ,ds.time
        </if>
    </select>


    <select id="listNullInterfaceCount" parameterType="NullInterface"
            resultMap="NullInterfaceResultMap">
        select
            sum(IFNULL(ds.count,0)) as counts
        from deduct_null_interface_summary ds
        <where>
            <if test="spId != null and spId != ''">
                AND ds.sp_id LIKE CONCAT('%', #{spId}, '%')
            </if>
            <if test="type != null and type != ''">
                AND ds.type LIKE CONCAT('%', #{type}, '%')
            </if>
            <if test="timeStart != null and timeStart != ''">
                AND ds.time &gt;= #{timeStart}
            </if>
            <if test="timeEnd != null and timeEnd != ''">
                AND ds.time &lt;= #{timeEnd}
            </if>
        </where>
        order by id desc
    </select>
</mapper>