<?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="com.fs.live.mapper.LiveSensitiveWordsMapper">

    <resultMap type="LiveSensitiveWords" id="LiveSensitiveWordsResult">
        <result property="wordId"    column="word_id"    />
        <result property="word"    column="word"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectLiveSensitiveWordsVo">
        select word_id, word, create_time from live_sensitive_words
    </sql>

    <select id="selectLiveSensitiveWordsList" parameterType="LiveSensitiveWords" resultMap="LiveSensitiveWordsResult">
        <include refid="selectLiveSensitiveWordsVo"/>
        <where>
            <if test="word != null  and word != ''"> and word = #{word}</if>
            <if test="createTime != null ">and create_time >= #{createTime} and create_time &lt; date_add(#{createTime}, interval 1 day)</if>
        </where>
    </select>

    <select id="selectLiveSensitiveWordsByWordId" parameterType="Long" resultMap="LiveSensitiveWordsResult">
        <include refid="selectLiveSensitiveWordsVo"/>
        where word_id = #{wordId}
    </select>

    <insert id="insertLiveSensitiveWords" parameterType="LiveSensitiveWords" useGeneratedKeys="true" keyProperty="wordId">
        insert into live_sensitive_words
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="word != null and word != ''">word,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="word != null and word != ''">#{word},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateLiveSensitiveWords" parameterType="LiveSensitiveWords">
        update live_sensitive_words
        <trim prefix="SET" suffixOverrides=",">
            <if test="word != null and word != ''">word = #{word},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where word_id = #{wordId}
    </update>

    <delete id="deleteLiveSensitiveWordsByWordId" parameterType="Long">
        delete from live_sensitive_words where word_id = #{wordId}
    </delete>

    <delete id="deleteLiveSensitiveWordsByWordIds" parameterType="String">
        delete from live_sensitive_words where word_id in
        <foreach item="wordId" collection="array" open="(" separator="," close=")">
            #{wordId}
        </foreach>
    </delete>

    <select id="selectAllWords"  resultType="string">
        select word from live_sensitive_words
    </select>
</mapper>
