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

    <resultMap type="SmsBypass" id="bypassResultMap">
        <id column="id" property="id" />
        <result column="keyword" property="keyword" />
        <result column="description" property="description" />
        <result column="createtime" property="createtime" />
        <result column="sp_id" property="sp_id" />
        <result column="telecomchannel" property="telecomchannel" />
        <result column="unicomchannel" property="unicomchannel" />
        <result column="mobilechannel" property="mobilechannel" />
        <result column="template" property="template" />
        <result column="opertor_type" property="opertor_type" />
        <result column="channelid" property="channelid" />
        <result column="sp_name" property="sp_name" />
        <result column="mobile_suffix" property="mobile_suffix" />
        <result column="unicom_suffix" property="unicom_suffix" />
        <result column="telecom_suffix" property="telecom_suffix" />
        <result column="reporting_status" property="reportingStatus"/>
        <result column="fixed_mobile_suffix" property="fixed_mobile_suffix" />
        <result column="extend_type" property="extendType"/>
        <result column="sign_flag" property="signFlag"/>
        <result column="user_suffix" property="user_suffix"/>
        <result column="class_id" property="classId"/>
        <result column="name" property="className"/>
        <result column="isBeforeProvince" property="isBeforeProvince"/>
        <result column="domain" property="domain"/>
        <result column="phones" property="phones"/>
        <result column="sms_template" property="smsTemplate"/>
        <result column="auto_test" property="autoTest"/>
    </resultMap>

    <resultMap type="WhiteObject" id="exportWordResultMap">
        <id column="id" property="id" />
        <id column="mdn" property="mdn" />
        <id column="spid" property="sp_id" />
        <result column="createtime" property="createtime" />
        <result column="descption" property="descption" />
    </resultMap>

    <resultMap type="keywordBypass" id="keywordBypassResultMap">
        <id column="id" property="id" />
        <result column="keyword" property="keyword" />
        <result column="description" property="description" />
        <result column="createtime" property="createtime" />
        <result column="sp_id" property="sp_id" />
        <result column="telecomchannel" property="telecomchannel" />
        <result column="unicomchannel" property="unicomchannel" />
        <result column="mobilechannel" property="mobilechannel" />
        <result column="template" property="template" />
        <result column="sp_name" property="sp_name" />
        <result column="spid" property="spid" />
        <result column="mobile_suffix" property="mobile_suffix" />
        <result column="unicom_suffix" property="unicom_suffix" />
        <result column="telecom_suffix" property="telecom_suffix" />
        <result column="keyword_id" property="keyword_id" />
        <result column="city" property="city" />

    </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="exportWord" parameterType="WhiteObject"
            resultType="Map">
        select ot.id,ot.mdn,ot.spid,IFNULL(ot.descption,' ')descption ,date_format(ot.createtime,'%Y-%m-%d %H:%i:%S') createtime  from sms_white_object ot where 1=1
        <if test="mdn!=null and mdn!=''">
            and ot.mdn like CONCAT('%',#{mdn},'%')
        </if>
    </select>

    <select id="listPageBypassKeyword" parameterType="SmsBypass"
            resultMap="bypassResultMap">
        select ot.id,ot.keyword,ot.createtime,
        (case when ot.description = '0' then "否"
        when ot.description = '1' then "是"
        else "未知" end) description,
        ot.spid sp_id,ot.mobilechannel,ot.unicomchannel,ot.telecomchannel,status,ot.province_group_id,
        ot.is_city, ot.isBeforeProvince
        from sms_keyword_bypass ot
        where  1=1
        <if test="sp_id!=null and sp_id!='' ">
            and ot.spid=#{sp_id}
        </if>
        <if test="keyword!=null and keyword!=''">
            and ot.keyword like CONCAT('%', #{keyword}, '%')
        </if>
        <if test="mobilechannel!=null and mobilechannel!='-1' ">
            and ot.mobilechannel=#{mobilechannel}
        </if>
        <if test="unicomchannel!=null and unicomchannel!='-1'  ">
            and ot.unicomchannel=#{unicomchannel}
        </if>
        <if test="telecomchannel!=null and telecomchannel!='-1' ">
            and ot.telecomchannel=#{telecomchannel}
        </if>
        order by ot.createtime desc
    </select>

    <select id="exportBypassKeyword" parameterType="SmsBypass"
            resultType="Map">
        select ot.id,ot.keyword,ot.createtime,
        (case when ot.status = 0 then "未生效"
        when ot.status = 1 then "生效"
         end) status,
        ot.spid sp_id,ot.mobilechannel,ot.unicomchannel,ot.telecomchannel,ot.province_group_id,
        ot.is_city,mobile_suffix,unicom_suffix,telecom_suffix
        from sms_keyword_bypass ot
        <where>
        <if test="sp_id!=null and sp_id!='' ">
            and ot.spid=#{sp_id}
        </if>
        <if test="keyword!=null and keyword!=''">
            and ot.keyword like CONCAT('%', #{keyword}, '%')
        </if>
        <if test="mobilechannel!=null and mobilechannel!='-1' ">
            and ot.mobilechannel=#{mobilechannel}
        </if>
        <if test="unicomchannel!=null and unicomchannel!='-1'  ">
            and ot.unicomchannel=#{unicomchannel}
        </if>
        <if test="telecomchannel!=null and telecomchannel!='-1' ">
            and ot.telecomchannel=#{telecomchannel}
        </if>
        <if test="endId != null">
            and ot.id &lt;  #{endId}
        </if>
        </where>
        order by ot.id desc
        <if test="exportExcelSize != null ">
            limit #{exportExcelSize}
        </if>
    </select>

    <select id="getKeywordById" parameterType="int"
            resultMap="bypassResultMap">
            select ot.id,ot.keyword,ot.spid sp_id,ot.createtime,ot.description,ot.mobilechannel,ot.unicomchannel,ot.telecomchannel,status,
            ot.mobile_suffix,
            ot.unicom_suffix,
            ot.telecom_suffix,ot.fixed_mobile_suffix,ot.fixed_unicom_suffix,ot.fixed_telecom_suffix,ot.province_group_id,
            ot.is_city, ot.city_group_id, ot.isBeforeProvince
            from sms_keyword_bypass ot
            where ot.id=#{id}
    </select>
    <select id="getKeywordCountByName" parameterType="SmsBypass"
            resultType="int">
        select count(1) from sms_keyword_bypass sk
        where
        sk.keyword=#{keyword}
        <if test="sp_id!=null and sp_id!=' '">
            and sk.spid =#{sp_id}
        </if>

    </select>
    <select id="getKeywordCountByChannel" parameterType="SmsBypass"
            resultType="SmsBypass">
        select id, keyword, spid as sp_id,sk.mobilechannel,sk.unicomchannel,sk.telecomchannel from sms_keyword_bypass sk
        <where>
            <if test="mobilechannel!=null and mobilechannel!=''">
                and sk.mobilechannel =#{mobilechannel}
            </if>
            <if test="unicomchannel!=null and unicomchannel!=''">
                and sk.unicomchannel =#{unicomchannel}
            </if>
            <if test="telecomchannel!=null and telecomchannel!=''">
                and sk.telecomchannel =#{telecomchannel}
            </if>
            <if test="keyword!=null and keyword!=''">
                and sk.keyword =#{keyword,jdbcType=VARCHAR}
            </if>
            <if test="id!=null">
                and sk.id =#{id}
            </if>
            <if test="sp_id!=null">
                and sk.spid =#{sp_id}
            </if>
        </where>
    </select>

    <update id="updateKeywordByKey" parameterType="SmsBypass">
        update
            sms_keyword_bypass
        <set>
            <if test="mobilechannel!=null and mobilechannel!=''">
                mobilechannel=#{mobilechannel},
            </if>
            <if test="unicomchannel!=null and unicomchannel!=''">
                unicomchannel=#{unicomchannel},
            </if>
            <if test="telecomchannel!=null and telecomchannel!=''">
                telecomchannel=#{telecomchannel},
            </if>
        </set>
        where
        id=#{id}
        and spid=#{sp_id}
    </update>

    <update id="updateKeywordById" parameterType="SmsBypass">
        update
        sms_keyword_bypass
        set
                spid=#{sp_ids},
                keyword=#{keyword},
                description=#{description},
                mobilechannel=#{mobilechannel},
                unicomchannel=#{unicomchannel},
                telecomchannel=#{telecomchannel},
                mobile_suffix=#{mobile_suffix},
                unicom_suffix=#{unicom_suffix},
                telecom_suffix=#{telecom_suffix},
            fixed_telecom_suffix=#{fixed_telecom_suffix},
            fixed_unicom_suffix=#{fixed_unicom_suffix},
            fixed_mobile_suffix=#{fixed_mobile_suffix},
            status=#{status},
            createtime = now(),
            province_group_id=#{province_group_id},
            is_city= #{is_city},
            city_group_id=#{city_group_id}
        where
        id=#{id}
    </update>

    <update id="updateKeywordBySpidAndKeyWord" parameterType="SmsBypass">
        update
            sms_keyword_bypass
        set
            description=#{description},
            mobilechannel=#{mobilechannel},
            unicomchannel=#{unicomchannel},
            telecomchannel=#{telecomchannel},
            mobile_suffix=#{mobile_suffix},
            unicom_suffix=#{unicom_suffix},
            telecom_suffix=#{telecom_suffix},
            fixed_telecom_suffix=#{fixed_telecom_suffix},
            fixed_unicom_suffix=#{fixed_unicom_suffix},
            fixed_mobile_suffix=#{fixed_mobile_suffix},
            status=#{status},
            createtime = now(),
            province_group_id=#{province_group_id},
            is_city= #{is_city},
            city_group_id=#{city_group_id}
        where
            keyword=#{keyword}
            and spid=#{sp_id}
    </update>


    <insert id="insertKeyword"  useGeneratedKeys="true" keyProperty="id"  parameterType="SmsBypass">
        insert into sms_keyword_bypass
        (keyword,SPID,description,CREATETIME,mobilechannel,unicomchannel,telecomchannel,mobile_suffix,unicom_suffix,telecom_suffix
        ,fixed_mobile_suffix,fixed_unicom_suffix,fixed_telecom_suffix,status,province_group_id, is_city, city_group_id, isBeforeProvince) values
        (#{keyword,jdbcType=VARCHAR},#{sp_id},#{description},sysdate(),#{mobilechannel,jdbcType=VARCHAR}
        ,#{unicomchannel,jdbcType=VARCHAR},#{telecomchannel,jdbcType=VARCHAR},#{mobile_suffix},#{unicom_suffix},#{telecom_suffix}
        ,#{fixed_mobile_suffix},#{fixed_unicom_suffix},#{fixed_telecom_suffix},#{status},#{province_group_id}, #{is_city}, #{city_group_id}, #{isBeforeProvince})
    </insert>

<insert id="insertSignChannel"  useGeneratedKeys="true" keyProperty="id"  parameterType="SmsBypass">
        insert into sms_sign_bypass
        (sign,CREATETIME,mobilechannel,unicomchannel,telecomchannel,mobile_suffix,unicom_suffix,telecom_suffix,status
        ,fixed_mobile_suffix,fixed_unicom_suffix,fixed_telecom_suffix,reporting_status,batch_no, extend_type, sign_flag, user_suffix, class_id,domain,phones,sms_template,auto_test) values
        (#{sign,jdbcType=VARCHAR},sysdate(),#{mobilechannel,jdbcType=VARCHAR}
        ,#{unicomchannel,jdbcType=VARCHAR},#{telecomchannel,jdbcType=VARCHAR},#{mobile_suffix},#{unicom_suffix},#{telecom_suffix}
        ,#{status},#{fixed_mobile_suffix},#{fixed_unicom_suffix},#{fixed_telecom_suffix},#{reportingStatus},#{batch_no}, #{extendType}, #{signFlag}, #{user_suffix}, #{classId},#{domain},#{phones},#{smsTemplate},#{autoTest})
    </insert>

    <insert  id="addBatch"  useGeneratedKeys="true" keyProperty="id" parameterType="ArrayList">
        <!--  <selectKey resultType="int" order="BEFORE" keyProperty="id">
                select sms_white_object_id.nextval from dual
        </selectKey> -->
        insert into sms_keyword_bypass (keyword,SPID,description,CREATETIME,mobilechannel,unicomchannel,telecomchannel
        ,mobile_suffix,unicom_suffix,telecom_suffix,fixed_mobile_suffix,fixed_unicom_suffix,fixed_telecom_suffix,status)
        select A.* from(
        <foreach collection="list" item="white"  index="index"  separator="UNION"  >
            SELECT #{white.keyword},#{white.sp_id},#{white.description,jdbcType=VARCHAR},sysdate(),#{white.mobilechannel,jdbcType=VARCHAR}
            ,#{white.unicomchannel,jdbcType=VARCHAR},#{white.telecomchannel,jdbcType=VARCHAR},#{white.mobile_suffix,jdbcType=VARCHAR}
            ,#{white.unicom_suffix,jdbcType=VARCHAR},#{white.telecom_suffix,jdbcType=VARCHAR},#{white.fixed_mobile_suffix}
            ,#{white.fixed_unicom_suffix},#{white.fixed_telecom_suffix},#{white.status}

             FROM DUAL
        </foreach>
        ) A
    </insert>


    <delete id="deleteKeywordById" parameterType="int">
        delete from sms_keyword_bypass where id=#{id}
    </delete>


    <select id="listPageBypassTemplate" parameterType="SmsBypass"
            resultMap="bypassResultMap">
        select ot.id,ot.template,ot.createtime,ot.description ,ot.spid sp_id
        ,ot.mobilechannel,ot.unicomchannel,ot.telecomchannel
        from sms_template_bypass ot where 1=1
        <if test="template!=null and template!=''">
            and ot.template like CONCAT('%',#{template},'%')
        </if>
        order by ot.createtime desc
    </select>

    <delete id="deleteTemplateById" parameterType="int">
        delete from sms_template_bypass where id=#{id}
    </delete>

    <select id="getTemplateCountByName" parameterType="SmsBypass"
            resultType="int">
        select count(1) from sms_template_bypass sk
        where
        sk.template=#{template}
        <if test="sp_id!=null and sp_id!=' '">
            and sk.spid =#{sp_id}
        </if>

    </select>

    <insert id="insertTemplate"  useGeneratedKeys="true" keyProperty="id"  parameterType="SmsBypass">
        insert into sms_template_bypass
        (template,SPID,description,CREATETIME,mobilechannel,unicomchannel,telecomchannel) values
        (#{template,jdbcType=VARCHAR},#{sp_id},#{description,jdbcType=VARCHAR},sysdate(),#{mobilechannel,jdbcType=VARCHAR}
        ,#{unicomchannel,jdbcType=VARCHAR},#{telecomchannel,jdbcType=VARCHAR})
    </insert>

    <update id="updateTemplateById" parameterType="SmsBypass">
        update
        sms_template_bypass
        <set>
            <if test="sp_ids !=null and sp_ids != '' ">
                spid=#{sp_ids},
            </if>
            <if test="template!=null and template!= ''">
                template=#{template},
            </if>
            <if test="description!=null and description!= ''">
                description=#{description},
            </if>
            <if test="mobilechannel!=null and mobilechannel!= ''">
                mobilechannel=#{mobilechannel},
            </if>
            <if test="unicomchannel!=null and unicomchannel!= ''">
                unicomchannel=#{unicomchannel},
            </if>
            <if test="telecomchannel!=null and telecomchannel!= ''">
                telecomchannel=#{telecomchannel},
            </if>
            createtime = now()
        </set>
        where
        id=#{id}
    </update>

    <select id="getTemplateById" parameterType="int"
            resultMap="bypassResultMap">
            select ot.id,ot.template,ot.spid sp_id,ot.createtime,ot.description,ot.mobilechannel,ot.unicomchannel,ot.telecomchannel  from sms_template_bypass ot where
         ot.id=#{id}
    </select>

    <select id="getSpKeywordProvinceConfig" parameterType="KeywordBypass" resultMap="keywordBypassResultMap">
        select
        kb.id,
        kb.mobilechannel,
        kb.unicomchannel,
        kb.telecomchannel,
        kb.province,
        kb.keyword_id,
        kb.mobile_suffix,
        kb.unicom_suffix,
        kb.telecom_suffix,
        sk.keyword,
        sk.spId
        from sms_keyword_bypass_province kb,  sms_keyword_bypass sk
        where kb.keyword_id = sk.id
        <if test = "province != null">
            and kb.province=#{province}
        </if>
        <if test = "spId != null and spId!='' ">
            and sk.spId=#{spId}
        </if>
        <if test = "keyword != null and keyword!='' ">
            and sk.keyword =#{keyword}
        </if>
        <if test = "keyword_id != null and keyword_id!='' ">
            and kb.keyword_id =#{keyword_id}
        </if>
        <if test = "id != null and id!='' ">
            and kb.id =#{id}
        </if>
        <if test="mobilechannel!=null and mobilechannel!=''">
            and kb.mobilechannel=#{mobilechannel}
        </if>
        <if test="unicomchannel!=null and unicomchannel!=''">
            and kb.unicomchannel=#{unicomchannel}
        </if>
        <if test="telecomchannel!=null and telecomchannel!=''">
            and kb.telecomchannel=#{telecomchannel}
        </if>
    </select>

    <select id="getSpKeywordCityConfig" parameterType="KeywordBypass" resultMap="keywordBypassResultMap">
        select
        kb.id,
        kb.mobilechannel,
        kb.unicomchannel,
        kb.telecomchannel,
        kb.city,
        kb.keyword_id,
        kb.mobile_suffix,
        kb.unicom_suffix,
        kb.telecom_suffix,
        sk.keyword,
        sk.spId
        from sms_keyword_bypass_city kb,  sms_keyword_bypass sk
        where kb.keyword_id = sk.id
        <if test = "city != null and city!=null">
            and kb.city=#{city}
        </if>
        <if test = "spId != null and spId!='' ">
            and sk.spId=#{spId}
        </if>
        <if test = "keyword != null and keyword!='' ">
            and sk.keyword =#{keyword}
        </if>
        <if test = "keyword_id != null and keyword_id!='' ">
            and kb.keyword_id =#{keyword_id}
        </if>
        <if test = "id != null and id!='' ">
            and kb.id =#{id}
        </if>
        <if test="mobilechannel!=null and mobilechannel!=''">
            and kb.mobilechannel=#{mobilechannel}
        </if>
        <if test="unicomchannel!=null and unicomchannel!=''">
            and kb.unicomchannel=#{unicomchannel}
        </if>
        <if test="telecomchannel!=null and telecomchannel!=''">
            and kb.telecomchannel=#{telecomchannel}
        </if>
    </select>

    <insert id="insertSpKeywordProvinceConfig" useGeneratedKeys="true" keyProperty="id" parameterType="KeywordBypass">
	    insert into sms_keyword_bypass_province(mobilechannel,unicomchannel,telecomchannel,province,mobile_suffix,unicom_suffix,telecom_suffix,keyword_id)
	    values( #{mobilechannel}, #{unicomchannel},#{telecomchannel},#{province},#{mobile_suffix},#{unicom_suffix},#{telecom_suffix},#{keyword_id})
    </insert>

    <insert id="insertSpKeywordCityConfig" useGeneratedKeys="true" keyProperty="id" parameterType="KeywordBypass">
	    insert into sms_keyword_bypass_city(mobilechannel,unicomchannel,telecomchannel,city,mobile_suffix,unicom_suffix,telecom_suffix,keyword_id)
	    values( #{mobilechannel}, #{unicomchannel},#{telecomchannel},#{city},#{mobile_suffix},#{unicom_suffix},#{telecom_suffix},#{keyword_id})
    </insert>

    <update id="updateSpKeywordProvinceConfig" parameterType="KeywordBypass">
	    update  sms_keyword_bypass_province
	    set  mobilechannel=#{mobilechannel},unicomchannel=#{unicomchannel},telecomchannel=#{telecomchannel},
	    mobile_suffix=#{mobile_suffix},unicom_suffix=#{unicom_suffix},telecom_suffix=#{telecom_suffix} where id=#{id}
    </update>
    <update id="updateSpKeywordProvinceByKey" parameterType="KeywordBypass">
        update
        sms_keyword_bypass_province
        <set>
            <if test="mobilechannel!=null and mobilechannel!=''">
                mobilechannel=#{mobilechannel},
            </if>
            <if test="unicomchannel!=null and unicomchannel!=''">
                unicomchannel=#{unicomchannel},
            </if>
            <if test="telecomchannel!=null and telecomchannel!=''">
                telecomchannel=#{telecomchannel},
            </if>
        </set>
        where
        id=#{id}
    </update>
     <update id="updateSpKeywordCityConfig" parameterType="KeywordBypass">
	    update  sms_keyword_bypass_city
	    set  mobilechannel=#{mobilechannel},unicomchannel=#{unicomchannel},telecomchannel=#{telecomchannel},
	    mobile_suffix=#{mobile_suffix},unicom_suffix=#{unicom_suffix},telecom_suffix=#{telecom_suffix} where id=#{id}
    </update>
    <update id="updateSpKeywordCityByKey" parameterType="KeywordBypass">
        update
        sms_keyword_bypass_city
        <set>
            <if test="mobilechannel!=null and mobilechannel!=''">
                mobilechannel=#{mobilechannel},
            </if>
            <if test="unicomchannel!=null and unicomchannel!=''">
                unicomchannel=#{unicomchannel},
            </if>
            <if test="telecomchannel!=null and telecomchannel!=''">
                telecomchannel=#{telecomchannel},
            </if>
        </set>
        where
        id=#{id}
    </update>
    <delete id="deleteSpKeywordProvinceConfig" parameterType="KeywordBypass">
    	delete from sms_keyword_bypass_province where id=#{id}
    </delete>

    <delete id="deleteSpKeywordCityConfig" parameterType="KeywordBypass">
    	delete from sms_keyword_bypass_city where id=#{id}
    </delete>


    <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 cg.sp_id = #{sp_id}
        </if>
        <if test="opertor_type!=null and opertor_type>0">
            and cg.opertor_type = #{opertor_type}
        </if>
    </select>

      <update id="updateSpKeywordStatus" parameterType="SmsBypass">
	    update  sms_keyword_bypass
	    set  status= 1
          <where>
              <if test="sp_id != null">
                  spid = #{sp_id}
              </if>
              and createtime&gt;=str_to_date(#{starttime},'%Y-%m-%d %H:%i:%S')
              and createtime&lt;=str_to_date(#{endtime},'%Y-%m-%d %H:%i:%S')
          </where>
    </update>

    <!--关键字失效（将status设置为0）-->
    <update id="updateSpKeywordStatusAndDisabled" parameterType="SmsBypass">
        update  sms_keyword_bypass
        set  status= 0
        <where>
            <if test="sp_id != null">
                spid = #{sp_id}
            </if>
            and createtime&gt;=str_to_date(#{starttime},'%Y-%m-%d %H:%i:%S')
            and createtime&lt;=str_to_date(#{endtime},'%Y-%m-%d %H:%i:%S')
        </where>
    </update>

    <select id="searchPageBypassSign" parameterType="cn.roadm.bo.SmsBypassSearchPage"
            resultMap="bypassResultMap">
        select ot.id,ot.sign,ot.createtime,
        <!-- (case when ot.description = '0' then "否"
        when ot.description = '1' then "是"
        else "未知" end) description, -->
        ot.mobilechannel,ot.unicomchannel,ot.telecomchannel,ot.status,
        ot.mobile_suffix,ot.unicom_suffix,ot.telecom_suffix,ot.reporting_status,ot.batch_no,ot.extend_type,ot.user_suffix,ot.class_id, g.name,
        ot.domain,ot.phones,ot.sms_template,ot.auto_test
        from sms_sign_bypass ot
        left join sms_sign_bypass_group g on g.id = ot.class_id
        <where>
        <if test="sign !=null and sign !=''">
            BINARY ot.sign like CONCAT('%',#{sign},'%')
        </if>
        <if test="mobilechannel!=null and mobilechannel!='-1' ">
            and ot.mobilechannel=#{mobilechannel}
        </if>
        <if test="unicomchannel!=null and unicomchannel!='-1'  ">
            and ot.unicomchannel=#{unicomchannel}
        </if>
        <if test="telecomchannel!=null and telecomchannel!='-1' ">
            and ot.telecomchannel=#{telecomchannel}
        </if>
        <if test="mobile_suffix !=null and mobile_suffix !='' ">
            and ot.mobile_suffix=#{mobile_suffix}
        </if>
        <if test="extendType != null and extendType != 0">
            and ot.extend_type=#{extendType}
        </if>
        <if test="classId != null and classId != ''">
            and ot.class_id=#{classId}
        </if>
        <if test="autoTest != null">
            <choose>
                <when test="autoTest == 1">
                    and ot.auto_test = 1
                </when>
                <otherwise>
                    and (ot.auto_test = 0 or ot.auto_test is null)
                </otherwise>
            </choose>
        </if>
        <if test="status != null">
            and ot.status = #{status}
        </if>
        <if test="startTime!=null and startTime!=''">
            and ot.createtime&gt;=str_to_date(#{startTime},'%Y-%m-%d')
        </if>
        <if test="reportingStatus!=null and reportingStatus!=''">
            and ot.reporting_status=#{reportingStatus}
        </if>
        <if test="batch_no!=null and batch_no!=''">
            and ot.batch_no=#{batch_no}
        </if>
        <if test="domain!=null and domain!=''">
            and ot.domain like CONCAT('%',#{domain},'%')
        </if>
        <if test="phones!=null and phones!=''">
            and ot.phones like CONCAT('%',#{phones},'%')
        </if>
        <if test="endTime!=null and endTime!=''">
            and
            ot.createtime&lt;DATE_ADD(str_to_date(#{endTime},'%Y-%m-%d'),INTERVAL
            1 DAY)
        </if>
        </where>
        order by ot.id desc
    </select>

    <select id="getBypassSign" parameterType="SmsBypass"
            resultMap="bypassResultMap">
        select ot.id,ot.sign,ot.createtime,
        <!-- (case when ot.description = '0' then "否"
        when ot.description = '1' then "是"
        else "未知" end) description, -->
        ot.mobilechannel,ot.unicomchannel,ot.telecomchannel,ot.status,
        ot.mobile_suffix,ot.unicom_suffix,ot.telecom_suffix,ot.reporting_status, ot.extend_type, ot.user_suffix, ot.class_id, g.name,
        ot.domain,ot.phones,ot.sms_template,ot.auto_test
        from sms_sign_bypass ot
        left join sms_sign_bypass_group g on g.id = ot.class_id
        <where>
        <if test="sign !=null and sign !=''">
            BINARY ot.sign like CONCAT('%',#{sign},'%')
        </if>
        <if test="mobilechannel!=null and mobilechannel!='-1' ">
            and ot.mobilechannel=#{mobilechannel}
        </if>
        <if test="unicomchannel!=null and unicomchannel!='-1'  ">
            and ot.unicomchannel=#{unicomchannel}
        </if>
        <if test="telecomchannel!=null and telecomchannel!='-1' ">
            and ot.telecomchannel=#{telecomchannel}
        </if>
        <if test="mobile_suffix !=null and mobile_suffix !='' ">
            and ot.mobile_suffix=#{mobile_suffix}
        </if>
        <if test="reportingStatus!=null and reportingStatus!=''">
            and ot.reporting_status=#{reportingStatus}
        </if>
        <if test="classId != null and classId != ''">
            and ot.class_id=#{classId}
        </if>
        <if test="autoTest != null">
            <choose>
                <when test="autoTest == 1">
                    and ot.auto_test = 1
                </when>
                <otherwise>
                    and (ot.auto_test = 0 or ot.auto_test is null)
                </otherwise>
            </choose>
        </if>
        <if test="status != null">
            and ot.status = #{status}
        </if>
        <if test="startTime!=null and startTime!=''">
            and ot.createtime&gt;=str_to_date(#{startTime},'%Y-%m-%d')
        </if>
        <if test="extendType != null and extendType != 0">
            and ot.extend_type = #{extendType}
        </if>
        <if test="domain!=null and domain!=''">
            and ot.domain like CONCAT('%',#{domain},'%')
        </if>
        <if test="phones!=null and phones!=''">
            and ot.phones like CONCAT('%',#{phones},'%')
        </if>
        <if test="endTime!=null and endTime!=''">
            and
            ot.createtime&lt;DATE_ADD(str_to_date(#{endTime},'%Y-%m-%d'),INTERVAL
            1 DAY)
        </if>
        <if test="endId != null">
            and ot.id &lt;  #{endId}
        </if>
        </where>
        order by ot.id desc
        <if test="exportExcelSize != null ">
            limit #{exportExcelSize}
        </if>
    </select>

    <select id="getSignChannelByChannelId" parameterType="SmsBypass"
            resultMap="bypassResultMap">
        select ot.sign,ot.mobilechannel,ot.mobile_suffix,ot.fixed_mobile_suffix
        from sms_sign_bypass ot
        where ot.status=1 and ot.mobilechannel=#{mobilechannel}
    </select>

    <select id="bypassSignCount" parameterType="SmsBypass"
            resultType="long">
        select count(ot.id) count
        from sms_sign_bypass ot
        left join sms_sign_bypass_group g on g.id = ot.class_id
        <where>
        <if test="sign !=null and sign !=''">
            BINARY ot.sign like CONCAT('%',#{sign},'%')
        </if>
        <if test="mobilechannel!=null and mobilechannel!='-1' ">
            and ot.mobilechannel=#{mobilechannel}
        </if>
        <if test="unicomchannel!=null and unicomchannel!='-1'  ">
            and ot.unicomchannel=#{unicomchannel}
        </if>
        <if test="telecomchannel!=null and telecomchannel!='-1' ">
            and ot.telecomchannel=#{telecomchannel}
        </if>
        <if test="mobile_suffix !=null and mobile_suffix !='' ">
            and ot.mobile_suffix=#{mobile_suffix}
        </if>
        <if test="classId != null and classId != ''">
            and ot.class_id=#{classId}
        </if>
        <if test="autoTest != null">
            <choose>
                <when test="autoTest == 1">
                    and ot.auto_test = 1
                </when>
                <otherwise>
                    and (ot.auto_test = 0 or ot.auto_test is null)
                </otherwise>
            </choose>
        </if>
        <if test="reportingStatus!=null and reportingStatus!=''">
            and ot.reporting_status=#{reportingStatus}
        </if>
        <if test="startTime!=null and startTime!=''">
            and ot.createtime&gt;=str_to_date(#{startTime},'%Y-%m-%d')
        </if>
        <if test="extendType != null and extendType != 0">
            and ot.extend_type = #{extendType}
        </if>
        <if test="domain!=null and domain!=''">
            and ot.domain like CONCAT('%',#{domain},'%')
        </if>
        <if test="phones!=null and phones!=''">
            and ot.phones like CONCAT('%',#{phones},'%')
        </if>
        <if test="endTime!=null and endTime!=''">
            and
            ot.createtime&lt;DATE_ADD(str_to_date(#{endTime},'%Y-%m-%d'),INTERVAL
            1 DAY)
        </if>
        </where>
        order by ot.createtime desc
    </select>

     <select id="getSignById" parameterType="int"
            resultMap="bypassResultMap">
            select ot.id,ot.sign,ot.createtime,ot.description,ot.mobilechannel,ot.unicomchannel,ot.telecomchannel,ot.status,
            ot.mobile_suffix,
            ot.unicom_suffix,
            ot.telecom_suffix
            ,ot.fixed_mobile_suffix,ot.fixed_unicom_suffix,ot.fixed_telecom_suffix,ot.reporting_status,ot.extend_type, ot.sign_flag,ot.user_suffix,
                ot.class_id, g.name,ot.domain,ot.phones,ot.sms_template,ot.auto_test
             from sms_sign_bypass ot left join sms_sign_bypass_group g on g.id = ot.class_id where
         ot.id=#{id}
    </select>

    <insert id="insertSign"  useGeneratedKeys="true" keyProperty="id"  parameterType="SmsBypass">
        insert into sms_sign_bypass
        (sign,CREATETIME,mobilechannel,unicomchannel,telecomchannel,status,mobile_suffix,unicom_suffix,telecom_suffix
        ,fixed_mobile_suffix,fixed_unicom_suffix,fixed_telecom_suffix,reporting_status,extend_type,sign_flag, user_suffix, class_id,domain,phones,sms_template,auto_test) values
        (#{sign,jdbcType=VARCHAR},sysdate(),#{mobilechannel,jdbcType=VARCHAR}
        ,#{unicomchannel,jdbcType=VARCHAR},#{telecomchannel,jdbcType=VARCHAR},#{status},#{mobile_suffix},#{unicom_suffix},#{telecom_suffix}
        ,#{fixed_mobile_suffix},#{fixed_unicom_suffix},#{fixed_telecom_suffix},#{reportingStatus}, #{extendType},#{signFlag}, #{user_suffix}, #{classId},#{domain},#{phones},#{smsTemplate},#{autoTest})
    </insert>

    <update id="updateSign" parameterType="SmsBypass">
        update
            sms_sign_bypass
        set sign=#{sign},
            status=#{status},
            mobile_suffix=#{mobile_suffix},
            unicom_suffix=#{unicom_suffix},
            telecom_suffix=#{telecom_suffix},
            mobilechannel=#{mobilechannel},
            unicomchannel=#{unicomchannel},
            telecomchannel=#{telecomchannel},
            telecomchannel=#{telecomchannel},
            reporting_status=#{reportingStatus},
            fixed_unicom_suffix=#{fixed_unicom_suffix},
            fixed_mobile_suffix=#{fixed_mobile_suffix},
            extend_type=#{extendType},
            sign_flag=#{signFlag},
            user_suffix=#{user_suffix},
            class_id=#{classId},
            domain=#{domain},
            phones=#{phones},
            sms_template=#{smsTemplate},
            auto_test=#{autoTest}
        where id = #{id}
    </update>

    <update id="updateReportSignById">
        update
            sms_sign_bypass
        set
            reporting_status = '1'
        where mobilechannel=#{mobilechannel} and sign in
            <foreach collection="ids" item="item" open="(" close=")" separator=",">
                #{item,,jdbcType=VARCHAR}
            </foreach>
    </update>

    <select id="getSignBySign" parameterType="SmsBypass"
            resultMap="bypassResultMap">
        select ot.id,
               ot.sign,
               ot.createtime,
               ot.description,
               ot.mobilechannel,
               ot.unicomchannel,
               ot.telecomchannel,
               ot.status,
               ot.mobile_suffix,
               ot.unicom_suffix,
               ot.telecom_suffix
                ,
               ot.fixed_mobile_suffix,
               ot.fixed_unicom_suffix,
               ot.fixed_telecom_suffix
        from sms_sign_bypass ot
        <where>
            ot.sign = #{sign}
              and mobilechannel = #{mobilechannel}
            <if test="id != null and id != ''">
                and (id &lt; #{id} or id &gt; #{id})
            </if>
            <if test="mobile_suffix != null and mobile_suffix != ''">
                and ot.mobile_suffix=#{mobile_suffix}
            </if>
        </where>
    </select>
    <select id="getSignByChannel" parameterType="SmsBypass"
            resultMap="bypassResultMap">
            select ot.id,ot.sign,ot.createtime,ot.description,ot.mobilechannel,ot.unicomchannel,ot.telecomchannel,ot.status,
            ot.mobile_suffix,
            ot.unicom_suffix,
            ot.telecom_suffix
            ,ot.fixed_mobile_suffix,ot.fixed_unicom_suffix,ot.fixed_telecom_suffix
             from sms_sign_bypass ot where mobilechannel=#{mobilechannel}

    </select>
    <delete id="deleteSignById" parameterType="int">
        delete from sms_sign_bypass where id=#{id}
    </delete>
    <delete id="deleteSignBySearch" parameterType="SmsBypass">
        delete from sms_sign_bypass  where 1=1
        <if test="sign !=null and sign !=''">
            and BINARY sign =#{sign}
        </if>
        <if test="mobilechannel!=null and mobilechannel!='-1' ">
            and mobilechannel=#{mobilechannel}
        </if>
        <if test="unicomchannel!=null and unicomchannel!='-1'  ">
            and unicomchannel=#{unicomchannel}
        </if>
        <if test="telecomchannel!=null and telecomchannel!='-1' ">
            and telecomchannel=#{telecomchannel}
        </if>
        <if test="mobile_suffix !=null and mobile_suffix !='' ">
            and mobile_suffix=#{mobile_suffix}
        </if>
        <if test="starttime !=null and starttime !='' ">
            and createtime&gt;=str_to_date(#{starttime},'%Y-%m-%d %H:%i:%S')
        </if>
        <if test="endtime !=null and endtime !='' ">
            and createtime&lt;=str_to_date(#{endtime},'%Y-%m-%d %H:%i:%S')
        </if>
        <if test="batch_no!=null and batch_no!=''">
            and batch_no=#{batch_no}
        </if>

    </delete>

    <delete id="deleteKeywordBySearch" parameterType="SmsBypass">
        delete from sms_keyword_bypass where 1=1
        <if test="keyword !=null and keyword !=''">
            and BINARY keyword=#{keyword}
        </if>
        <if test="sp_id !=null and sp_id !=''">
            and spid=#{sp_id}
        </if>
        <if test="mobilechannel!=null and mobilechannel!='-1' ">
            and mobilechannel=#{mobilechannel}
        </if>
        <if test="unicomchannel!=null and unicomchannel!='-1'  ">
            and unicomchannel=#{unicomchannel}
        </if>
        <if test="telecomchannel!=null and telecomchannel!='-1' ">
            and telecomchannel=#{telecomchannel}
        </if>
        <if test="starttime !=null and starttime !='' ">
            and createtime&gt;=str_to_date(#{starttime},'%Y-%m-%d %H:%i:%S')
        </if>
        <if test="endtime !=null and endtime !='' ">
            and createtime&lt;=str_to_date(#{endtime},'%Y-%m-%d %H:%i:%S')
        </if>

    </delete>

    <delete id="deleteKeywordByIdAndSpId">
        delete from sms_keyword_bypass
        <where>
            id =#{id}
            <if test="sp_id != null">
                and spid = #{sp_id}
            </if>
            <if test="starttime !=null and starttime !='' ">
                and createtime&gt;=str_to_date(#{starttime},'%Y-%m-%d %H:%i:%S')
            </if>
            <if test="endtime !=null and endtime !='' ">
                and createtime&lt;=str_to_date(#{endtime},'%Y-%m-%d %H:%i:%S')
            </if>
        </where>
    </delete>

    <select id="getSignListCount" resultType="long">
          select count(1) from sms_sign_bypass ot
        <where>
        <if test="sign !=null and sign !=''">
            and BINARY ot.sign like CONCAT('%',#{sign},'%')
        </if>
        <if test="mobilechannel!=null and mobilechannel!='-1' ">
            and ot.mobilechannel=#{mobilechannel}
        </if>
        <if test="unicomchannel!=null and unicomchannel!='-1'  ">
            and ot.unicomchannel=#{unicomchannel}
        </if>
        <if test="telecomchannel!=null and telecomchannel!='-1' ">
            and ot.telecomchannel=#{telecomchannel}
        </if>
        <if test="mobile_suffix !=null and mobile_suffix !='' ">
            and ot.mobile_suffix=#{mobile_suffix}
        </if>
        <if test="startTime!=null and startTime!=''">
            and ot.createtime&gt;=str_to_date(#{startTime},'%Y-%m-%d')
        </if>
        <if test="reportingStatus!=null and reportingStatus!=''">
            and ot.reporting_status=#{reportingStatus}
        </if>
        <if test="batch_no!=null and batch_no!=''">
            and ot.batch_no=#{batch_no}
        </if>
        <if test="status != null">
            and ot.status = #{status}
        </if>
        <if test="domain!=null and domain!=''">
            and ot.domain like CONCAT('%',#{domain},'%')
        </if>
        <if test="phones!=null and phones!=''">
            and ot.phones like CONCAT('%',#{phones},'%')
        </if>
            <if test="extendType != null and extendType != 0">
                and ot.extend_type = #{extendType}
            </if>
        <if test="endTime!=null and endTime!=''">
            and
            ot.createtime&lt;DATE_ADD(str_to_date(#{endTime},'%Y-%m-%d'),INTERVAL
            1 DAY)
        </if>
        </where>
    </select>

    <select id="selectSignsBySignAndChannel" resultType="java.lang.String">
        select sign from `sms_sign_bypass` where mobilechannel = #{channelId} and sign in
        <foreach collection="batch" item="sign" open="(" separator="," close=")">
            #{sign}
        </foreach>
    </select>

    <select id="getChannelIsOpenExtendType" resultType="java.lang.Integer">
        select use_extend_type from sms_send_channel_info where id = #{channelId}
    </select>

    <select id="selectExtendNumsByChannelSign" resultType="java.lang.String">
        select mobile_suffix from sms_sign_bypass where mobilechannel = #{channelId} and sign = #{sign}
    </select>

    <select id="selectSignsBeforeDelete" resultType="cn.roadm.bo.SmsBypass">
        select sign,
               description,
               createtime,
               mobilechannel,
               mobile_suffix,
               fixed_mobile_suffix,
               status,
               reporting_status as reportingStatus,
               batch_no,
               sign_flag as signFlag,
               extend_type as extendType
        from sms_sign_bypass
        <where>
            <if test="sign != null and sign != ''">
                and BINARY sign = #{sign}
            </if>
            <if test="mobilechannel != null and mobilechannel != '-1'">
                and mobilechannel = #{mobilechannel}
            </if>
            <if test="unicomchannel != null and unicomchannel != '-1'">
                and unicomchannel = #{unicomchannel}
            </if>
            <if test="telecomchannel != null and telecomchannel != '-1'">
                and telecomchannel = #{telecomchannel}
            </if>
            <if test="mobile_suffix != null and mobile_suffix != ''">
                and mobile_suffix = #{mobile_suffix}
            </if>
            <if test="starttime != null and starttime != ''">
                and createtime &gt;= str_to_date(#{starttime}, '%Y-%m-%d %H:%i:%S')
            </if>
            <if test="endtime != null and endtime != ''">
                and createtime &lt;= str_to_date(#{endtime}, '%Y-%m-%d %H:%i:%S')
            </if>
            <if test="batch_no != null and batch_no != ''">
                and batch_no = #{batch_no}
            </if>
        </where>
    </select>

    <select id="getSignCountByChannelId" resultType="java.lang.Integer">
        select count(1) from sms_sign_bypass where mobilechannel = #{channelId} and sign = #{sign}
    </select>

    <select id="selectChannelSignCount" resultType="java.lang.Integer">
        select count(1) from sms_sign_bypass where mobilechannel = #{channelId}
    </select>


    <select id="queryBypassBySubPort" resultType="cn.roadm.bo.SmsBypass">
        select
            id,sign,description,createtime,mobilechannel,mobile_suffix,
            fixed_mobile_suffix,status,reporting_status as reportingStatus,batch_no,sign_flag as signFlag,
            extend_type as extendType,user_suffix,class_id,domain,phones,sms_template as smsTemplate,auto_test
        from sms_sign_bypass
        where mobilechannel = #{channelId}
          and mobile_suffix = #{subPort}
          and status = 1
    </select>

    <select id="selectSubPortInfo" resultType="cn.roadm.bo.SmsBypass">
        select a.id,a.sign,a.mobilechannel,a.mobile_suffix,a.status,a.reporting_status as reportingStatus,a.sign_flag as signFlag,
        a.extend_type as extendType,a.domain,a.phones,a.sms_template as smsTemplate,b.MOBILE_PREFIX as port
        from sms_sign_bypass a left join sms_send_channel_info b on a.mobilechannel = b.id
        where a.id = #{id}
    </select>

    <insert id="insertBypassBak" parameterType="cn.roadm.bo.SmsBypass">
        insert into sms_sign_bypass_bak(sign,mobilechannel,mobile_suffix,`status`,reporting_status,sign_flag,
        extend_type,domain,phones,sms_template,data_status,create_time) value(#{sign},#{mobilechannel},#{mobile_suffix},
        #{status},#{reportingStatus},#{signFlag},#{extendType},#{domain},#{phones},#{smsTemplate},1,now())
    </insert>

    <update id="updateUploadSignSubPortStatus">
        update upload_sign_status set is_deleted = 1,update_time = now() where channel_id = #{channelId} and sub_port = #{subPort}
    </update>

    <select id="selectSignBySearch" parameterType="cn.roadm.bo.SmsBypass" resultType="cn.roadm.bo.SmsBypass">
        select a.id,a.sign,a.mobilechannel,a.mobile_suffix,a.status,a.reporting_status as reportingStatus,a.sign_flag as signFlag,
        a.extend_type  as extendType ,a.domain,a.phones,a.sms_template as smsTemplate,b.MOBILE_PREFIX as port
        from sms_sign_bypass a left join sms_send_channel_info b on a.mobilechannel = b.id
        where 1=1
        <if test="sign !=null and sign !=''">
            and BINARY a.sign =#{sign}
        </if>
        <if test="mobilechannel!=null and mobilechannel!='-1' ">
            and a.mobilechannel=#{mobilechannel}
        </if>
        <if test="unicomchannel!=null and unicomchannel!='-1'  ">
            and a.unicomchannel=#{unicomchannel}
        </if>
        <if test="telecomchannel!=null and telecomchannel!='-1' ">
            and a.telecomchannel=#{telecomchannel}
        </if>
        <if test="mobile_suffix !=null and mobile_suffix !='' ">
            and a.mobile_suffix=#{mobile_suffix}
        </if>
        <if test="starttime !=null and starttime !='' ">
            and a.createtime&gt;=str_to_date(#{starttime},'%Y-%m-%d %H:%i:%S')
        </if>
        <if test="endtime !=null and endtime !='' ">
            and a.createtime&lt;=str_to_date(#{endtime},'%Y-%m-%d %H:%i:%S')
        </if>
        <if test="batch_no!=null and batch_no!=''">
            and a.batch_no=#{batch_no}
        </if>

    </select>

    <update id="batchUpdateSignStatus">
        update sms_sign_bypass
        set status = #{status}
        where id in
        <foreach collection="ids" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </update>

</mapper>
