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

    <resultMap type="TransferInterface" id="TransferInterfaceResultMap">
        <id column="id" property="id" />
        <result column="spId" property="spId" />
        <result column="spName" property="spName" />
        <result column="interface_count" property="interfaceCount"/>
        <result column="create_time" property="createTime" />
        <result column="interface_type" property="interfaceType" />
        <result column="counts" property="counts" />
    </resultMap>

    <select id="listPageTransferInterface" parameterType="TransferInterface"
            resultMap="TransferInterfaceResultMap">
        select
        sp.id as spId,
        sp.sp_name as spName,
        SUM(ts.interface_count) AS interfaceCount,
        ts.interface_type as interfaceType,
        <if test="typeDay != null and typeDay == 'day'">
            DATE_FORMAT(ts.create_time, '%Y-%m-%d') as createTime
        </if>
        <if test="typeDay == null or typeDay != 'day'">
            NULL as time
        </if>
        from transfer_interface_summary ts left join sms_sp_info sp on sp.id=ts.spId
        <where>
            <if test="spId != null and spId != ''">
                AND ts.spId LIKE CONCAT('%', #{spId}, '%')
            </if>
            <if test="interfaceType != null and interfaceType != ''">
                AND ts.interface_type LIKE CONCAT('%', #{interfaceType}, '%')
            </if>
            <if test="timeStart != null and timeStart != ''">
                AND ts.create_time &gt;= #{timeStart}
            </if>
            <if test="timeEnd != null and timeEnd != ''">
                AND ts.create_time &lt;= #{timeEnd}
            </if>
        </where>
        group by sp.id,sp.sp_name,ts.interface_type
        <if test="typeDay!=null and typeDay == 'day'">
            ,ts.create_time
        </if>
    </select>


    <select id="listTransferInterfaceCount" parameterType="TransferInterface"
            resultMap="TransferInterfaceResultMap">
        select
        sum(IFNULL(ts.interface_count,0)) as counts
        from transfer_interface_summary ts
        <where>
            <if test="spId != null and spId != ''">
                AND ts.spId LIKE CONCAT('%', #{spId}, '%')
            </if>
            <if test="interfaceType != null and interfaceType != ''">
                AND ts.interface_type LIKE CONCAT('%', #{interfaceType}, '%')
            </if>
            <if test="timeStart != null and timeStart != ''">
                AND ts.create_time &gt;= #{timeStart}
            </if>
            <if test="timeEnd != null and timeEnd != ''">
                AND ts.create_time &lt;= #{timeEnd}
            </if>
        </where>
        order by id desc
    </select>
</mapper>