<?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.SpUrlBlackMapper">

    <resultMap type="SpUrlBlackIpdomain" id="SpUrlBlackResultMap">
        <id column="id" property="id" />
        <result column="ip_domain" property="ipDomain" />
        <result column="type" property="type" />
        <result column="strategy" property="strategy" />
        <result column="createtime" property="createtime" />
        <result column="status" property="status" />
    </resultMap>
    <select id="getSpUrlBlack" parameterType="SpUrlBlackIpdomain"
            resultMap="SpUrlBlackResultMap">
        SELECT
        s.id,
        s.ip_domain,
        s.type,
        s.createtime,
        s.strategy,
        s.status
        FROM
        sms_url_black_ipdomain s
        <where>
            s.status = 1
            <if test="ipDomain!=null and ipDomain!=''">
                and s.ip_domain like  '%${ipDomain}%'
            </if>
            <if test="type!=null and type!=''">
                and s.type = #{type}
            </if>
            <if test="strategy !=null and strategy !=''">
                and s.strategy = #{strategy}
            </if>
        </where>
    </select>
    <select id="listSpUrlBlack" parameterType="SpUrlBlackIpdomain"
            resultMap="SpUrlBlackResultMap">
        SELECT
        s.id,
        s.ip_domain,
        s.type,
        s.createtime,
        s.strategy,
        s.status
        FROM
        sms_url_black_ipdomain s
        <where>
            s.status = 1
            <if test="ipDomain !=null and ipDomain !=''">
                and s.ip_domain like  '%${ipDomain}%'
            </if>
            <if test="type !=null and type !=''">
                and s.type = #{type}
            </if>
            <if test="strategy !=null and strategy !=''">
                and s.strategy = #{strategy}
            </if>
        </where>
		order by s.createtime desc
    </select>
    <update id="deleteSpUrlBlack" parameterType="int">
        update sms_url_black_ipdomain set status = 0 where id = #{id}
    </update>
    
    <insert id="insertSpUrlBlack" useGeneratedKeys="true" keyProperty="id" parameterType="SpUrlBlackIpdomain">
        INSERT INTO sms_url_black_ipdomain (ip_domain,type,createtime,strategy,status) VALUES
        (#{ipDomain,jdbcType=VARCHAR},#{type},now(),#{strategy},#{status})
    </insert>
</mapper>