<?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.SmsBlackPhoneMapper">
    <select id="listBlackPhoneList" resultType="cn.roadm.admin.table.SmsBlackPhoneTypeTable">
        select bt.id,
               bt.blacklist_group_name,
               bt.type,
               bt.createtime
        from sms_black_phone_type bt
        <where>
            <if test="type != null">
                type = #{type}
            </if>
        </where>
        order by bt.createtime desc
    </select>

    <select id="getBlackPhoneListOptions" resultType="cn.roadm.admin.entity.SpEditInfoSelectorEntity$Options">
        select id as `value`, blacklist_group_name as label from sms_black_phone_type where type = #{type}
    </select>

    <select id="getRemoteBlackPhoneList" resultType="cn.roadm.admin.table.SmsBlackPhoneTypeTable">
        select id , concat(id,' ',blacklist_group_name) as blacklist_group_name from sms_black_phone_type where type = 3
    </select>

    <select id="getBlackTypeListOptions" resultType="cn.roadm.admin.controller.vo.PageSelectOptionsVO">
        select id as `value`, blacklist_group_name as label from sms_black_phone_type
        <where>
            type = #{type}
        </where>
    </select>

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

    <insert id="addBlackPhone">
        insert into sms_black_object
            (MDN, SPID, DESCPTION, CREATETIME, GRADE)
        values (#{mdn,jdbcType=VARCHAR}, #{spId}, #{descption,jdbcType=VARCHAR}, sysdate(), #{grade})
    </insert>

    <select id="getBlackPhoneListCacheOptions" resultType="cn.roadm.admin.entity.SpEditInfoSelectorEntity$Options">
        select concat(id, 'a') as `value`, concat(blacklist_group_name, '缓存') as label from sms_black_phone_type where buffer is not null and buffer = 'open'
    </select>
</mapper>
