<?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.admin.mapper.StrategyMapper">

    <select id="listChannel"  resultType="cn.roadm.admin.controller.vo.ChannelInfoQueryVO"  >
        SELECT
            a.id channelId,  concat(a.id,' ',a.channel_name) channelName
        FROM
            sms_send_channel_info a
                LEFT JOIN sms_carrier_channel_info b on a.ID = b.id
                LEFT JOIN sms_channel_backup_ip c on c.pa_id = b.id
        where a.`STATUS` = '1' and a.protocol_type &lt; 20
        ORDER BY
            a.id DESC
    </select>

    <select id="listPageBackCode" resultType="cn.roadm.admin.dto.BackCodeDO"  >
        SELECT a.id,a.back_code as backCode ,a.code_type as codeType,a.pa_id as channelId ,a.send_time as sendTime,
        a.`status`,a.descp,a.create_time as createtime ,a.resend_pa as resendPa,a.resend_time,a.sp_id,b.sp_name spName,
        a.mobile_pa,a.unicom_pa ,a.telecom_pa,a.is_triple from sms_back_code as a left join sms_sp_info as b
        on a.sp_id = b.id
        <where>
            <if test="params.backCode != null and params.backCode != ''">
                a.back_code like CONCAT('%',#{params.backCode},'%')
            </if>
            <if test="params.status!=null and params.status!=''">
                and a.`status` = #{params.status}
            </if>
            <if test="params.channelId !=null and params.channelId !=''">
                and a.pa_id = #{params.channelId}
            </if>
            <if test="params.resendChannelId !=null and params.resendChannelId !=''">
                and (
                a.resend_pa = #{params.resendChannelId} or
                a.mobile_pa = #{params.resendChannelId} or
                a.unicom_pa = #{params.resendChannelId} or
                a.telecom_pa = #{params.resendChannelId}
                )
            </if>
            <if test="params.spId !=null and params.spId != ''">
                and a.sp_id = #{params.spId}
            </if>
            <if test="params.spName != null and params.spName!= ''">
                and b.sp_name like CONCAT('%',#{params.spName},'%')
            </if>
            <if test="params.mmsFlag != null and params.mmsFlag == 2">
                and a.mms_flag = 2
            </if>
            <if test=" params.mmsFlag == null or params.mmsFlag != 2">
                and (a.mms_flag is null or a.mms_flag != 2)
            </if>
        </where>
        order by id desc
    </select>

    <select id="getPaGroupConfigById" parameterType="int" resultType="cn.roadm.admin.dto.ChannelGroupDO">
        select * from sms_channel_group g where g.id = #{id}
    </select>

    <select id="listPaGroupConfig"  resultType="cn.roadm.admin.dto.ChannelGroupDO">
        select * from sms_channel_group g
        <where>
            g.status = '1'
            <if test="params.network != null and params.network != ''">
                and g.network = #{network}
            </if>
            <if test="params.name != null and params.name!=''">
                and g.name like CONCAT('%', #{params.name}, '%')
            </if>
            <if test="params.channels!=null and params.channels!=''">
                and CONCAT(',',channels, ',') like CONCAT('%,',#{params.channels}, ',%')
            </if>
        </where>
        order by g.id desc
    </select>


    <select id="getProvinceGroupById" resultType="cn.roadm.admin.dto.SmsProvinceGroupDO">
        select id,name,DATE_FORMAT(createtime, '%Y-%m-%d %H:%i:%s') createtime,`status` from sms_province_group
        <where>
            status=1 and id=#{id}
        </where>
    </select>

    <insert id="saveBackCode" parameterType="cn.roadm.admin.controller.vo.BackCodeSaveReqVO" useGeneratedKeys="true" keyProperty="id">
        insert into sms_back_code (back_code,code_type,pa_id,status,descp,resend_pa,resend_time,sp_id,null_error_code,is_triple,is_group,mobile_pa,unicom_pa,telecom_pa,is_provincial_group,proGroupId,rounting_number_flag,rount_interface,mms_flag,create_time,send_time,sp_white,shunt_white)
        VALUES (#{backCode},#{codeType},#{paId},#{status},#{descp},#{resendPa},#{resendTime},#{spId},#{nullErrorCode},
                #{isTriple},#{isGroup},#{mobilePa},#{unicomPa},#{telecomPa},#{isProvincialGroup},#{proGroupId},#{rountingNumberFlag},#{rountInterface},#{mms_flag},now(),1,0,0)
    </insert>

    <update id="updateBackCodeById" parameterType="cn.roadm.admin.controller.vo.BackCodeSaveReqVO">
        update sms_back_code set back_code = #{backCode},resend_time = #{resendTime},
                                 pa_id = #{paId},status = #{status},descp = #{descp}
                ,resend_pa = #{resendPa} ,sp_id = #{spId},null_error_code=#{nullErrorCode},is_triple=#{isTriple},
                                 is_group=#{isGroup},mobile_pa=#{mobilePa},unicom_pa=#{unicomPa},telecom_pa=#{telecomPa},is_provincial_group=#{isProvincialGroup},proGroupId=#{proGroupId},rounting_number_flag=#{rountingNumberFlag},
                                 rount_interface=#{rountInterface} where id = #{id}
    </update>

    <update id="updateSrcChanneleById" parameterType="cn.roadm.admin.controller.vo.BackCodeSaveReqVO">
        update sms_back_code set pa_id = #{paId} where id = #{id}
    </update>

    <update id="updateReSendChanneleById" parameterType="cn.roadm.admin.controller.vo.BackCodeSaveReqVO">
        update sms_back_code set resend_pa = #{resendPa},mobile_pa=#{mobilePa},unicom_pa=#{unicomPa},telecom_pa=#{telecomPa} where id = #{id}
    </update>


    <delete id="deleteBackCodeById" parameterType="long">
        delete from sms_back_code where id =#{id};
    </delete>

    <select id="findBackCodeId" resultType="cn.roadm.admin.dto.BackCodeDO" parameterType="long">
        SELECT id,back_code as backCode ,code_type as codeType,pa_id as channelId ,resend_time resendTime,send_time sendTime,
               `status`,descp,create_time as createtime,resend_pa as resendPa ,sp_id,null_error_code nullErrorCode,
               is_triple isTriple,is_group isGroup,mobile_pa mobilePa,unicom_pa unicomPa,telecom_pa telecomPa,is_provincial_group isProvincialGroup,proGroupId,rounting_number_flag rountingNumberFlag,rount_interface rountInterface,
               sp_white,shunt_white
        from sms_back_code where id = #{id}
    </select>

    <select id="getProvinceGroupAll" resultType="cn.roadm.admin.dto.SmsProvinceGroupDO">
        select id,name,DATE_FORMAT(createtime, '%Y-%m-%d %H:%i:%s') createtime,`status` from sms_province_group
        <where>
            status=1
        </where>
    </select>

    <select id="listPageBlackObject" resultType="cn.roadm.admin.dto.BlackObjectDO">
        select ot.id,ot.mdn,ot.spid spId,ot.createtime,ot.descption,ot.grade, bt.blacklist_group_name
        from sms_black_object ot,sms_black_phone_type bt where bt.id=ot.grade

        <if test="params.mdn!=null and params.mdn!=''">
            and ot.mdn=#{params.mdn}
        </if>
        <if test="params.spId!=null and params.spId>0">
            and ot.spid=#{params.spId}
        </if>
        <if test="params.grade!=null and params.grade!=-1">
            and ot.grade=#{params.grade}
        </if>
        order by ot.id desc
    </select>

    <select id="listBlackPhoneType" resultType="cn.roadm.admin.dto.BlackPhoneTypeDO">
        select bt.id,
        bt.blacklist_group_name,bt.type
        from sms_black_phone_type bt where 1=1
        <if test="params.type!=null and params.type!=''">
            and type=#{params.type}
        </if>
    </select>


    <select id="listPageBlackPhoneType" resultType="cn.roadm.admin.dto.BlackPhoneTypeDO">
        select bt.id,
        bt.blacklist_group_name,
        bt.createtime,
        bt.descption,
        bt.type,
        bt.price
        from sms_black_phone_type bt where 1=1
        <if test="params.blacklistGroupName!=null and params.blacklistGroupName!=''">
            and bt.blacklist_group_name like CONCAT('%',#{params.blacklistGroupName},'%')
        </if>
        order by bt.id
    </select>

    <select id="selectBlackTemplateList" resultType="cn.roadm.admin.dto.BlackPhoneTypeTemplateDO">
        select
            id, `name`, handler_name handlerName, `template`
        from sms_black_dynamic_param_template
    </select>

    <select id="getBlackPhoneTypeById" parameterType="int"
            resultType="cn.roadm.admin.dto.BlackPhoneTypeDO">
        select bt.id,
               bt.blacklist_group_name,
               bt.createtime,
               bt.descption,
               bt.type,
               round(bt.price/10000,5) price,
               bt.dynamic_param,
               bt.dynamic_param_val,
               dpt.template as templateName,
               dpt.id as template
        from sms_black_phone_type bt left join sms_black_dynamic_param_template dpt
          on bt.dynamic_param = dpt.handler_name  where bt.id=#{id}
    </select>

    <update id="updateBlackPhoneTypeById" >
        update
            sms_black_phone_type set
             blacklist_group_name=#{params.blacklistGroupName},
             descption=#{params.descption},
             type=#{params.type},
             createtime=sysdate(),
             price=round(#{params.price}*10000,1),
             dynamic_param = #{params.dynamicParam},
             dynamic_param_val = #{params.dynamicParamVal}
        where
            id=#{params.id}
    </update>

    <insert id="insertBlackPhoneType"  useGeneratedKeys="true" keyProperty="id"  >
        insert into sms_black_phone_type
        (blacklist_group_name,descption,createtime,type,price,dynamic_param,dynamic_param_val) values
            (#{params.blacklistGroupName,jdbcType=VARCHAR},#{params.descption,jdbcType=VARCHAR},sysdate(),#{params.type},round(#{params.price}*10000,1),
             #{params.dynamicParam,jdbcType=VARCHAR},#{params.dynamicParamVal,jdbcType=VARCHAR})
    </insert>

    <select id="getBlackCountByName" resultType="int">
        select count(1) from sms_black_phone_type bt
        where
            bt.blacklist_group_name=#{params.blacklistGroupName}
    </select>
    <delete id="deleteBlackPhoneTypeById" parameterType="int">
        delete from sms_black_phone_type where id=#{id}
    </delete>

    <select id="getBlackObjectCountByName"
            resultType="int">
        select count(1) from sms_black_object sw
        where
        sw.mdn=#{params.mdn}
        <if test="params.spId!=null and params.spId!=''">
            and sw.spid =#{params.spId}
        </if>
        <if test="params.grade!=null and params.grade!= ''">
            and  grade=#{params.grade}
        </if>
    </select>

    <insert id="insertBlackObject"  useGeneratedKeys="true" keyProperty="id"  parameterType="cn.roadm.admin.controller.vo.BlackObjectReqVO">
        insert into sms_black_object
            (MDN,SPID,DESCPTION,CREATETIME,GRADE) values
            (#{mdn,jdbcType=VARCHAR},#{spId},#{descption,jdbcType=VARCHAR},sysdate(),#{grade})
    </insert>
    <insert  id="addBlackMdnBatch"  useGeneratedKeys="true" keyProperty="id" parameterType="ArrayList">
        <!--  <selectKey resultType="int" order="BEFORE" keyProperty="id">
                select sms_black_object_id.nextval from dual
        </selectKey> -->
        insert into sms_black_object (MDN,SPID,DESCPTION,CREATETIME,GRADE)
        VALUES
        <foreach collection="list" item="black"  index="index"  separator="," >
            (#{black.mdn,jdbcType=VARCHAR},#{black.spId},#{black.descption},sysdate(),#{black.grade})
        </foreach>
    </insert>

    <delete id="deleteBlackObjectById" parameterType="int">
        delete from sms_black_object where id=#{id}
    </delete>
    <select id="getBlackObjectById" parameterType="int" resultType="cn.roadm.admin.dto.BlackObjectDO">
        select ot.id,ot.mdn,ot.spid spId,ot.createtime,ot.descption,ot.grade from sms_black_object ot where
            ot.id=#{id}
    </select>
    <select id="exportBlackObject" resultType="cn.roadm.admin.dto.BlackObjectDO">
        select ot.id,ot.mdn,ot.spid spId,IFNULL(ot.descption,' ') descption ,date_format(ot.createtime,'%Y-%m-%d %H:%i:%S') createtime,ot.grade  from sms_black_object ot where 1=1
        <if test="params.mdn!=null and params.mdn!=''">
            and ot.mdn=#{params.mdn}
        </if>
        <if test="params.spId!=null and params.spId>0">
            and ot.spid=#{params.spId}
        </if>
        <if test="params.grade!=null and params.grade!=-1">
            and ot.grade=#{params.grade}
        </if>
        <if test="params.endId != null">
            and ot.id &lt; #{params.endId}
        </if>
        order by id desc
        <if test="params.limit != null and params.limit > 0">
            limit #{params.limit}
        </if>
    </select>

    <select id="getSpInfoListByGrade" parameterType="integer" resultType="string">
        select id  from sms_sp_info
        where is_audit_black = 0
          and find_in_set(#{gradeId},grade)
          and status = '1'
    </select>

    <select id="listAllSpInfo" resultType="cn.roadm.admin.controller.vo.TransferSelectOptionsVO">
        select sp.id as `key`,concat(sp.sp_name,(case when sp.sp_type=1 then '(行业用户)' else '(营销用户)' end )) as title
        from sms_sp_info sp
        where sp.status = '1'
    </select>

    <select id="getSpDescById" parameterType="integer" resultType="cn.roadm.admin.controller.vo.TransferSelectOptionsVO">
        select ssi.id `key`,grade title from sms_sp_info ssi
        where ssi.id =#{spid}
    </select>

    <select id="getSpInfoListBySensitive" parameterType="integer" resultType="cn.roadm.admin.controller.vo.TransferSelectOptionsVO">
        select id `key`,sensitive_word_type title from sms_sp_info
        where is_audit_word = 1
          and find_in_set(#{sensitiveWordTypeId},sensitive_word_type)
          and status = '1'
    </select>

    <select id="getSpSensitiveById" parameterType="integer" resultType="cn.roadm.admin.controller.vo.TransferSelectOptionsVO">
        select ssi.id `key`,sensitive_word_type title from sms_sp_info ssi
        where ssi.id =#{spid}
    </select>

    <select id="getAllSpInfoListByGrade" parameterType="integer" resultType="cn.roadm.admin.controller.vo.TransferSelectOptionsVO">
        select id `key`,grade title  from sms_sp_info
        where is_audit_black = 0
          and find_in_set(#{gradeId},grade)
          and status = '1'
    </select>

    <update id="updateSpInfoGradeByIds">
        update sms_sp_info sp set sp.grade=#{grade},sp.is_audit_black = 0
        where sp.id=#{spid}
    </update>

    <update id="updateSpInfoSensitiveWordTypeByIds">
        update sms_sp_info sp set sp.sensitive_word_type=#{sensitiveWordType},sp.is_audit_word = 1
        where sp.id=#{spid}
    </update>

    <select id="getSpSensitiveWordTypeById" parameterType="integer" resultType="cn.roadm.admin.controller.vo.TransferSelectOptionsVO">
        select ssi.id `key`,sensitive_word_type title from sms_sp_info ssi
        where ssi.id =#{spid}
    </select>

    <select id="listPageSensitiveWord" resultType="cn.roadm.admin.dto.SensitiveWordDO">
        select
        sw.id,sw.content,sw.create_time createtime,sw.type,sw.spid,sw.strategy,sw.remark,swt.name typeName from sms_sensitive_word sw,
        sms_data_dictionary swt
        where swt.id=sw.type

        <if test="params.content!=null and params.content!=''">
            and sw.content like CONCAT('%',#{params.content},'%')
        </if>
        <if test="params.type!=null  and params.type!='-1'">
            and sw.type = #{params.type}
        </if>
        <if test="params.spId!=null and params.spId!='-1' " >
            and sw.spid = #{params.spId}
        </if>

    </select>

    <select id="listAllSensitiveWordType"  resultType="cn.roadm.admin.dto.SensitiveWordTypeDO"  >
        select c.name,c.id from sms_data_dictionary  c
        where c.status = 1
        order by c.id desc
    </select>

    <select id="listPageSenstiveWordType" resultType="cn.roadm.admin.dto.SensitiveWordTypeDO">
        select c.name,c.id,c.description,c.createtime,c.status,beginTime,endTime,isTongyin,sw.dictionaryNum from sms_data_dictionary  c left join (select count(id) dictionaryNum,type from sms_sensitive_word  group by type) sw
        on c.id=sw.type
        <where>
            <if test="params.name!=null  and params.name!=''">
                and c.name like CONCAT('%',#{params.name},'%')
            </if>
        </where>
    </select>

    <delete id="deleteSensitiveWordTypeById" parameterType="integer">
        delete from sms_data_dictionary where id=#{id}
    </delete>

    <insert id="insertSensitiveWordType" useGeneratedKeys="true" keyProperty="id" parameterType="cn.roadm.admin.controller.vo.SensitiveWordTypeSaveVO">
        insert into sms_data_dictionary
        (NAME,TYPE,DESCRIPTION,CREATETIME,STATUS,VALUE,beginTime,endTime,isTongyin) values
            (#{name,jdbcType=VARCHAR},#{type,jdbcType=VARCHAR},#{description,jdbcType=VARCHAR},sysdate(),#{status,jdbcType=INTEGER},#{value,jdbcType=VARCHAR},#{beginTime,jdbcType=VARCHAR},#{endTime,jdbcType=VARCHAR},#{isTongyin,jdbcType=INTEGER})
    </insert>

    <update id="updateSensitiveWordType" parameterType="cn.roadm.admin.controller.vo.SensitiveWordTypeSaveVO">
        update
            sms_data_dictionary set
                 description=#{description},
                beginTime=#{beginTime},
                endTime=#{endTime},
                isTongyin=#{isTongyin}
        where
            id=#{id}
    </update>

    <delete id="deleteSensitiveWordById" parameterType="int">
        delete from sms_sensitive_word where id=#{id}
    </delete>

    <insert id="insertSensitiveWord" useGeneratedKeys="true" keyProperty="id" parameterType="cn.roadm.admin.controller.vo.SensitiveWordSaveVO">
        insert into sms_sensitive_word
        (CONTENT,CREATEID,ISMOBILE,ISUNICOM,ISTELCOM,TYPE,SPID,create_time,strategy,remark) values
            (#{content,jdbcType=VARCHAR},#{createid},#{isMobile},#{isUnicom},#{isTelcom},#{type},#{spId},sysdate(),#{strategy},#{remark})
    </insert>

    <insert  id="addSenstiveWordBatch" useGeneratedKeys="true" keyProperty="id"  parameterType="java.util.List">
        insert into sms_sensitive_word (CONTENT,ISMOBILE,ISUNICOM,ISTELCOM,CREATEID,TYPE,STRATEGY,create_time,SPID,remark)
        VALUES
        <foreach collection="list" item="item"  index="index"  separator="," >
            (#{item.content,jdbcType=VARCHAR},#{item.isMobile},#{item.isUnicom},#{item.isTelcom},#{item.createid},#{item.type},#{item.strategy},sysdate(),#{item.spId},#{item.remark})
        </foreach>
    </insert>
    <update id="updateSensitiveWordById" parameterType="cn.roadm.admin.controller.vo.SensitiveWordSaveVO">
        update
            sms_sensitive_word set
           content=#{content},
           ismobile=#{isMobile},
           istelcom=#{isTelcom},
           isunicom=#{isUnicom},
           spid=#{spId},
           type=#{type},
           strategy=#{strategy},
           remark=#{remark}
        where
            id=#{id}
    </update>

    <select id="getWordTypeCountByName" parameterType="cn.roadm.admin.controller.vo.SensitiveWordTypeSaveVO"
            resultType="int">
        select count(1) from sms_data_dictionary sw
        where
            sw.name=#{name}
        <if test="id!=null  and id>0">
            and sw.id!=#{id}
        </if>
    </select>
    <select id="getWordCountByName" parameterType="cn.roadm.admin.controller.vo.SensitiveWordSaveVO"
            resultType="int">
        select count(1) from sms_sensitive_word sw
        where
            sw.content=#{content, jdbcType=VARCHAR} and sw.type=#{type} and sw.spid=#{spId}
        <if test="id!=null and id>0">
            and sw.id!=#{id}
        </if>
    </select>

    <select id="listPageSmsPhoneChannel"  resultType="cn.roadm.admin.dto.PhoneShuntDO">
        select id,spId,mdn,channel,oldtype,newtype,DATE_FORMAT(createtime, '%Y-%m-%d %H:%i:%s') createtime,`status` from sms_phone_channel
        <where>
            <if test="params.spId!=null and params.spId>=0">
                and spid=#{params.spId}
            </if>
            <if test="params.status!=null and params.status>=0">
                and status=#{params.status}
            </if>
            <if test="params.mdn!=null and params.mdn!=''">
                and mdn=#{params.mdn}
            </if>
            <if test="params.channel!=null and params.channel!='' and params.channel!='-1'">
                and channel=#{params.channel}
            </if>
            <if test="params.startTime!=null and params.startTime!=''">
                and createtime &gt; #{params.startTime}
            </if>
            <if test="params.endTime!=null and params.endTime!=''">
                and createtime &lt; #{params.endTime}
            </if>
        </where>
    </select>

    <select id="getSmsPhoneChannelById" resultType="cn.roadm.admin.dto.PhoneShuntDO">
        select id,spId,mdn,channel,oldtype,newtype,DATE_FORMAT(createtime, '%Y-%m-%d %H:%i:%s') createtime,`status` from sms_phone_channel
        where id=#{id}
    </select>
    <insert id="insertSmsPhoneChannel" useGeneratedKeys="true" keyProperty="id"  parameterType="cn.roadm.admin.controller.vo.PhoneShuntSaveVO">
        insert into sms_phone_channel(spid,mdn,channel,oldtype,newtype,createtime,`status`) values(#{spId},#{mdn},#{channel},#{oldtype},
                                                                                                   #{newtype},now(),#{status})
    </insert>
    <update id="updateSmsPhoneChannelByMdn" parameterType="cn.roadm.admin.controller.vo.PhoneShuntSaveVO">
        update sms_phone_channel
        <set>
            <if test="channel!=null and channel!=''">
                channel=#{channel},
            </if>
        </set>
        where mdn=#{mdn}
    </update>
    <update id="updateSmsPhoneChannel" parameterType="cn.roadm.admin.controller.vo.PhoneShuntSaveVO">
        update sms_phone_channel
        <set>
            <if test="spId!=null and spId!=''">
                spid=#{spId},
            </if>
            <if test="mdn!=null and mdn!=''">
                mdn=#{mdn},
            </if>
            <if test="channel!=null and channel!=''">
                channel=#{channel},
            </if>
            <if test="newtype!=null and newtype!=''">
                newtype=#{newtype},
            </if>
            <if test="oldtype!=null and oldtype!=''">
                oldtype=#{oldtype},
            </if>
            `status`=#{status}
        </set>
        <where>
            <if test="id!=null and id>0">
                and id=#{id}
            </if>
        </where>
    </update>
    <delete id="delSmsPhoneChannel">
        delete from sms_phone_channel where id=#{id}
    </delete>
    <!--批量导入（新增）-->
<!--    <insert  id="addSmsPhoneChannelBatch"  useGeneratedKeys="true" keyProperty="id" parameterType="java.util.List">-->
<!--        insert into sms_phone_channel (spid,mdn,channel,oldtype,newtype,createtime,status)-->
<!--        values-->
<!--        <foreach collection="list" item="smsPhone"  index="index"  separator=","  >-->
<!--            (#{smsPhone.spId},#{smsPhone.mdn,jdbcType=VARCHAR},#{smsPhone.channel,jdbcType=VARCHAR},-->
<!--            #{smsPhone.oldtype,jdbcType=VARCHAR},#{smsPhone.newtype,jdbcType=VARCHAR},-->
<!--            sysdate(),#{smsPhone.status,jdbcType=VARCHAR})-->
<!--        </foreach>-->
<!--    </insert>-->

    <select id="listPageBypassKeyword" resultType="cn.roadm.admin.dto.KeyWordShuntDO" >
        select ot.id,ot.keyword,ot.createtime,
        (case when ot.description = '0' then "否"
        when ot.description = '1' then "是"
        else "未知" end) description,
        ot.spid spId,ot.mobilechannel,ot.unicomchannel,ot.telecomchannel,status,ot.province_group_id,
        ot.is_city,
        mobile_suffix,
        unicom_suffix,
        telecom_suffix,
        fixed_mobile_suffix,
        fixed_unicom_suffix,
        fixed_telecom_suffix
        from sms_keyword_bypass ot
        where  1=1
        <if test="params.spId!=null and params.spId!='' ">
            and ot.spid=#{params.spId}
        </if>
        <if test="params.keyword!=null and params.keyword!=''">
            and ot.keyword like CONCAT('%', #{params.keyword}, '%')
        </if>
        <if test="params.mobilechannel!=null and params.mobilechannel!='-1' ">
            and ot.mobilechannel=#{params.mobilechannel}
        </if>
        <if test="params.unicomchannel!=null and params.unicomchannel!='-1'  ">
            and ot.unicomchannel=#{params.unicomchannel}
        </if>
        <if test="params.telecomchannel!=null and params.telecomchannel!='-1' ">
            and ot.telecomchannel=#{params.telecomchannel}
        </if>

    </select>
    <insert id="insertKeyword"  useGeneratedKeys="true" keyProperty="id"  parameterType="cn.roadm.admin.controller.vo.KeyWordShuntSaveVO">
        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) values
            (#{keyword,jdbcType=VARCHAR},#{spId},#{description},sysdate(),#{mobilechannel,jdbcType=VARCHAR}
            ,#{unicomchannel,jdbcType=VARCHAR},#{telecomchannel,jdbcType=VARCHAR},#{mobileSuffix},#{unicomSuffix},#{telecomSuffix}
            ,#{fixedMobileSuffix},#{fixedUnicomSuffix},#{fixedTelecomSuffix},#{status},#{provinceGroupId}, #{isCity}, #{cityGroupId})
    </insert>
    <delete id="deleteKeywordById" parameterType="int">
        delete from sms_keyword_bypass where id=#{id}
    </delete>

    <select id="getKeywordCountByName" parameterType="cn.roadm.admin.controller.vo.KeyWordShuntSaveVO"
            resultType="int">
        select count(1) from sms_keyword_bypass sk
        where
        sk.keyword=#{keyword}
        <if test="spId!=null and spId!=' '">
            and sk.spid =#{spId}
        </if>

    </select>

    <select id="exportBypassKeyword" resultType="cn.roadm.admin.dto.KeyWordShuntDO">
        select ot.id,ot.keyword,ot.createtime,
        ot.status,
        ot.spid spId,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="params.spId!=null and params.spId!='' ">
                and ot.spid=#{params.spId}
            </if>
            <if test="params.keyword!=null and params.keyword!=''">
                and ot.keyword like CONCAT('%', #{params.keyword}, '%')
            </if>
            <if test="params.mobilechannel!=null and params.mobilechannel!='-1' ">
                and ot.mobilechannel=#{params.mobilechannel}
            </if>
            <if test="params.unicomchannel!=null and params.unicomchannel!='-1'  ">
                and ot.unicomchannel=#{params.unicomchannel}
            </if>
            <if test="params.telecomchannel!=null and params.telecomchannel!='-1' ">
                and ot.telecomchannel=#{params.telecomchannel}
            </if>
            <if test="params.endId != null">
                and ot.id &lt;  #{params.endId}
            </if>
        </where>
        order by ot.id desc
        <if test="params.limit != null ">
            limit #{params.limit}
        </if>
    </select>

    <select id="listPageSpConfig"  resultType="cn.roadm.admin.dto.SpSendLimitDO">
        select s.sp_name,
        g.sp_id spId,
        g.share_limit_sp,
        g.content_length_limit,
        g.samemdnmaxnum,
        g.sp_audit_number,
        g.SP_AUDIT_TYPE auditType,
        g.samemdn_nday samemdn_nday,
        g.limit_days limit_days,
        g.samemdn_oneday samemdn_oneday,
        g.samemdn_threeday samemdn_threeday,
        g.samemdn_oneminute samemdn_oneminute,
        g.samemdn_onehour samemdn_onehour,
        g.loopsms_sec loopsms_sec,
        g.loopsms_num loopsms_num,
        g.loopsms_strategy loopsms_strategy,
        begin_send_time beginSendTime,
        end_send_time endSendTime,
        g.samemsg_nminute samemsgNminute,
        g.samemsg_nnum samemsgNnum,
        g.same_content_effect_time sameContentEffectTime,
        g.otype_limit otypeLimit,
        g.content_length_limit contentLengthLimit,
        g.day_limit dayLimit,
        g.month_limit monthLimit,
        g.plan_send_time planSendTime,
        g.send_type sendType
        from
        sms_api_setting g, sms_sp_info s
        where s.id = g.sp_id
        and s.status != 2
        <if test="params.spName!=null and params.spName!=''">
            and s.sp_name like CONCAT('%',#{params.spName},'%')
        </if>
        <if test="params.spId!=null and params.spId!=0">
            and s.id=#{params.spId}
        </if>
    </select>

    <select id="getSpSendConfig"  resultType="cn.roadm.admin.dto.SpSendLimitDO">
        select s.sp_name,
        g.sp_id spId,
        g.share_limit_sp,
        g.content_length_limit,
        g.samemdnmaxnum,
        g.sp_audit_number,
        g.SP_AUDIT_TYPE auditType,
        g.samemdn_nday samemdn_nday,
        g.limit_days limit_days,
        g.samemdn_oneday samemdn_oneday,
        g.samemdn_threeday samemdn_threeday,
        g.samemdn_oneminute samemdn_oneminute,
        g.samemdn_onehour samemdn_onehour,
        g.loopsms_sec loopsms_sec,
        g.loopsms_num loopsms_num,
        g.loopsms_strategy loopsms_strategy,
        begin_send_time beginSendTime,
        end_send_time endSendTime,
        g.samemsg_nminute samemsgNminute,
        g.samemsg_nnum samemsgNnum,
        g.same_content_effect_time sameContentEffectTime,
        g.otype_limit otypeLimit,
        g.content_length_limit contentLengthLimit,
        g.day_limit dayLimit,
        g.month_limit monthLimit,
        g.plan_send_time planSendTime,
        g.send_type sendType
        from
        sms_api_setting g, sms_sp_info s
        where s.id = g.sp_id
        and s.status != 2
        and s.id=#{id}
    </select>

    <update id="updateSpSendPhoneNumLimit" parameterType="cn.roadm.admin.controller.vo.SendPhoneNumLimitUpdateVO">
        update sms_api_setting
        <trim prefix="SET" suffixOverrides=",">
            samemdnmaxnum=#{samemdnmaxnum},
            samemdn_nday=#{samemdnNday},
            limit_days=#{limitDays},
            samemdn_oneday=#{samemdnOneday},
            samemdn_threeday=#{samemdnThreeday},
            samemdn_oneminute=#{samemdnOneminute},
            samemdn_onehour=#{samemdnOnehour},
            share_limit_sp=#{shareLimitSp},
            loopsms_sec=#{loopsmsSec},
            loopsms_num=#{loopsmsNum},
            loopsms_strategy=#{loopsmsStrategy}
        </trim>
        where
        sp_id = #{id}
    </update>

    <update id="updateSpAuditStrategy" parameterType="cn.roadm.admin.controller.vo.SpAuditStrategyUpdateVO">
        update sms_api_setting
        <trim prefix="SET" suffixOverrides=",">
            samemsg_nminute =#{samemsgNminute},
            samemsg_nnum =#{samemsgNnum},
            <choose>
                <when  test="spAuditNumber != null and spAuditNumber!= ''">
                    sp_audit_number=#{spAuditNumber},
                </when>
                <otherwise>
                    sp_audit_number = null ,
                </otherwise>
            </choose>
            <if test="auditType != null and auditType!= ''"> SP_AUDIT_TYPE =#{auditType},</if>
            same_content_effect_time=#{sameContentEffectTime}
        </trim>
        where
        sp_id = #{id}
    </update>

    <update id="updateSpSendTimeLimit" parameterType="cn.roadm.admin.controller.vo.SpSendTimeLimitUpdateVO">
        update sms_api_setting
        <trim prefix="SET" suffixOverrides=",">
            day_limit=#{dayLimit},
            month_limit=#{monthLimit},
            content_length_limit=#{contentLengthLimit},
            plan_send_time=#{planSendTime},
            begin_send_time=#{beginSendTime},
            end_send_time=#{endSendTime},
            send_type=#{sendType},
            otype_limit=#{otypeLimit}
        </trim>
        where
        sp_id = #{id}
    </update>

    <insert id="insertSpAlarmDayLimit" parameterType="cn.roadm.admin.controller.vo.SpSendTimeLimitUpdateVO" keyProperty="id">
        insert into alarm_day_limit(sp_id,phone,email,alarm_flag,alarm_type,alarm_content)
        values(#{id},#{phone},#{email},#{alarmFlag},#{alarmType},#{alarmContent})
    </insert>

    <update id="updateSpAlarmDayLimit" parameterType="cn.roadm.admin.controller.vo.SpSendTimeLimitUpdateVO">
        UPDATE alarm_day_limit set
               phone=#{phone},
               email=#{email},
               alarm_flag=#{alarmFlag},
               alarm_content=#{alarmContent},
               alarm_type=#{alarmType} where sp_id=#{id}
    </update>

    <select id="getSpAlarmDayLimit" parameterType="int" resultType="cn.roadm.admin.dto.SpAlarmDayLimitDO">
        select *  from  alarm_day_limit p
        where p.sp_id=#{id} limit 1
    </select>

    <select id="listPageWhiteObject"  resultType="cn.roadm.admin.dto.WhitePhoneDO">
        select ot.id,ot.mdn,ot.spid spId,ot.createtime,ot.descption  from sms_white_object ot left join sms_sp_info sp on ot.spid = sp.id where 1=1
        <if test="params.mdn!=null and params.mdn!=''">
            and ot.mdn like CONCAT('%',#{params.mdn},'%')
        </if>
        <if test="params.spId!=null and params.spId!=''">
            and ot.spid = #{params.spId}
        </if>
        <if test="params.spName!=null and params.spName!=''">
            and sp.sp_name like CONCAT('%',#{params.spName},'%')
        </if>
    </select>

    <insert id="insertWhiteObject"  useGeneratedKeys="true" keyProperty="id"  parameterType="cn.roadm.admin.controller.vo.WhitePhoneSaveReqVO">
        insert into sms_white_object
            (MDN,SPID,DESCPTION,CREATETIME) values
            (#{mdn,jdbcType=VARCHAR},#{spId},#{descption,jdbcType=VARCHAR},sysdate())
    </insert>

    <select id="getWhiteObjectCountByName" parameterType="cn.roadm.admin.controller.vo.WhitePhoneSaveReqVO" resultType="int">
        select count(1) from sms_white_object sw
        where
        sw.mdn=#{mdn}
        <if test="spId!=null and spId!=''">
            and sw.spid =#{spId}
        </if>
    </select>
    <delete id="deleteWhiteObjectById" parameterType="int">
        delete from sms_white_object where id=#{id}
    </delete>
</mapper>
