<?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.SpConfigMapper">
    
    <resultMap type="SpInfo" id="spInfoAndSpcharge">
        <id column="id" property="spid"/>
        <result column="sp_name" property="sp_name"/>
        <result column="feetype" property="name"/>
    </resultMap>
    
    <resultMap type="SpInfo" id="spInfoAndChannel">
        <id column="id" property="spid"/>
        <result column="sp_name" property="sp_name"/>
        <result column="mobile_prefix" property="mobile_prefix"/>
        <result column="mobile_suffix" property="mobile_suffix"/>
        <result column="mobile_num" property="mobile_num"/>
        <result column="unicom_prefix" property="unicom_prefix"/>
        <result column="unicom_suffix" property="unicom_suffix"/>
        <result column="unicom_num" property="unicom_num"/>
        <result column="telecom_prefix" property="telecom_prefix"/>
        <result column="telecom_suffix" property="telecom_suffix"/>
        <result column="telecom_num" property="telecom_num"/>
        <result column="sp_channelconfig" property="sp_channelconfig"/>
        
    </resultMap>
    
    <resultMap type="ChannelInfo" id="channelResult">
        <id column="id" property="id"/>
        <result column="channel_name" property="channel_name"/>
        <result column="is_support_unicom" property="is_support_unicom"/>
        <result column="is_support_mobile" property="is_support_mobile"/>
        <result column="is_support_telecom" property="is_support_telecom"/>
        <result column="mobile_prefix" property="mobile_prefix"/>
        <result column="unicom_prefix" property="unicom_prefix"/>
        <result column="telecom_prefix" property="telecom_prefix"/>
        
        <result column="is_mobile_extend" property="is_mobile_extend"/>
        <result column="is_unicom_extend" property="is_unicom_extend"/>
        <result column="is_telecom_extend" property="is_telecom_extend"/>
        <result column="ch_desc" property="desc"/>
        
    </resultMap>
    <resultMap type="ChannelConfig" id="ChannelConfigResult">
        <id column="id" property="id"/>
        <result column="opertor_type" property="opertor_type"/>
        <result column="channelid" property="channelId"/>
        <result column="sp_id" property="sp_id"/>
        <result column="createtime" property="createtime"/>
    </resultMap>
    
    
    <select id="getChannelConfigInfo" parameterType="ChannelConfig" resultMap="ChannelConfigResult">
    select
    cg.id, 
    cg.opertor_type,
    cg.channelid, 
    cg.sp_id, 
    cg.createtime
    from sms_chennel_config cg
         where 1=1
        <if test="sp_id!=null and sp_id>0">
        and cg.sp_id = #{sp_id}
        </if>
        <if test="opertor_type!=null and opertor_type>0">
        and cg.opertor_type = #{opertor_type}
        </if>
    </select>


    

    <select id="getChannelInfoById" parameterType="int" resultMap="channelResult">
       select sc.id,
       sc.channel_name,
       sc.is_support_unicom,
       sc.is_support_mobile,
       sc.is_support_telecom,
       sc.mobile_prefix,
       sc.unicom_prefix,
       sc.telecom_prefix,
       sc.is_mobile_extend,
       sc.is_unicom_extend,
       sc.is_telecom_extend,
       sc.ch_desc
       from sms_send_channel_info sc
         where sc.status=1  
        and sc.id = #{channelId}
    
    </select>


    
    <select id="getChannelInfo" parameterType="ChannelInfo" resultMap="channelResult">
       select sc.id,
       sc.channel_name,
       sc.is_support_unicom,
       sc.is_support_mobile,
       sc.is_support_telecom,
       sc.mobile_prefix,
       sc.unicom_prefix,
       sc.telecom_prefix,
       sc.is_mobile_extend,
       sc.is_unicom_extend,
       sc.is_telecom_extend,
       sc.ch_desc
       from sms_send_channel_info sc
         where sc.status=1
        <if test="channel_name!=null">
        and sc.channel_name = #{channel_name} 
        </if>
        <if test="id!=null and id>0">
        and sc.id = #{id}
        </if>
    </select>
    
    <select id="listAllChannelInfo" parameterType="ChannelInfo"  resultMap="channelResult">
         select sc.id,
       sc.channel_name,
       sc.is_support_unicom,
       sc.is_support_international,
       sc.is_support_mobile,
       sc.is_support_telecom,
       sc.mobile_prefix,
       sc.unicom_prefix,
       sc.telecom_prefix,
       sc.is_mobile_extend,
       sc.is_unicom_extend,
       sc.is_telecom_extend,
       sc.ch_desc
       from sms_send_channel_info sc
         where sc.status=1
        <if test="is_support_unicom!=null and is_support_unicom>0">
        and sc.is_support_unicom = #{is_support_unicom} 
        </if>
        <if test="is_support_mobile!=null and is_support_mobile>0">
        and sc.is_support_mobile = #{is_support_mobile} 
        </if>
        <if test="is_support_telecom!=null and is_support_telecom>0">
        and sc.is_support_telecom = #{is_support_telecom} 
        </if>
          <if test="is_support_international !=null and is_support_international >0">
        and sc.is_support_international = #{is_support_international} 
        </if>
    </select>
    
    
    
        
    <select id="getSpBySuffix" parameterType="Map" resultType="int">
       select  count(1) from sms_sp_info s
        <where>
            <if test="spid != null">
             s.id != #{spid}
            </if>
            <if test="unicom_suffix != null">
                <choose>
                    <when test="unicom_suffix != -1">
                        and s.unicom_suffix like CONCAT('%', #{unicom_suffix}, '%')
                    </when>
                    <otherwise>
                        and (s.unicom_suffix is null or s.unicom_suffix = '')
                    </otherwise>
                </choose>
            </if>   
            <if test="telecom_suffix != null">
                <choose>
                    <when test="telecom_suffix != -1">
                        and s.telecom_suffix like CONCAT('%', #{telecom_suffix}, '%') 
                    </when>
                    <otherwise>
                        and (s.telecom_suffix is null or s.telecom_suffix = '')
                    </otherwise>
                </choose>
            </if>   
            <if test="mobile_suffix != null">
                <choose>
                    <when test="mobile_suffix != -1">
                        and s.mobile_suffix like CONCAT('%', #{mobile_suffix}, '%') 
                    </when>
                    <otherwise>
                        and (s.mobile_suffix is null or s.mobile_suffix = '')
                    </otherwise>
                </choose>
            </if>
                    
        </where>
        
    </select>
    



    <insert id="insertChannelConfig"   useGeneratedKeys="true" keyProperty="id" parameterType="ChannelConfig" >
        insert into sms_chennel_config  (opertor_type,channelid,sp_id,createtime) values (#{opertor_type},#{channelId},#{sp_id},sysdate())
    </insert>
    
    <update id="updateChannelConfig" parameterType="ChannelConfig">
	    update  sms_chennel_config
	    set  channelid=#{channelId} where id = #{id} 
    </update>

    <delete id="deleteSpChannel" parameterType="int">
        delete from  sms_chennel_config where sp_id=#{sp_id}
    </delete>   


    <select id="getMmsChannelConfigInfo" parameterType="ChannelConfig" resultMap="ChannelConfigResult">
	    select
	    cg.id, 
	    cg.opertor_type,
	    cg.channelid, 
	    cg.sp_id, 
	    cg.createtime
	    from mms_sp_channel_config cg
	         where 1=1
	        <if test="sp_id!=null and sp_id>0">
	        and cg.sp_id = #{sp_id}
	        </if>
	        <if test="opertor_type!=null and opertor_type>0">
	        and cg.opertor_type = #{opertor_type}
	        </if>
    </select>
        
</mapper>