<?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.fastGpt.mapper.FastGptChatReplaceWordsMapper">

    <resultMap type="FastGptChatReplaceWords" id="FastGptChatReplaceWordsResult">
        <result property="id"    column="id"    />
        <result property="type"    column="type"    />
        <result property="content"    column="content"    />
        <result property="changeCount"    column="change_count"    />
        <result property="status"    column="status"    />
        <result property="sort"    column="sort"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectFastGptChatReplaceWordsVo">
        select id, type, content, change_count, status, sort, create_time from fastgpt_chat_replace_words
    </sql>

    <select id="selectFastGptChatReplaceWordsList" parameterType="FastGptChatReplaceWords" resultMap="FastGptChatReplaceWordsResult">
        <include refid="selectFastGptChatReplaceWordsVo"/>
        <where>
            <if test="type != null "> and type = #{type}</if>
            <if test="content != null  and content != ''"> and content like concat('%', #{content}, '%')</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="sort != null "> and sort = #{sort}</if>
        </where>
        order by sort desc,id desc
    </select>

    <select id="selectFastGptChatReplaceWordsById" parameterType="Long" resultMap="FastGptChatReplaceWordsResult">
        <include refid="selectFastGptChatReplaceWordsVo"/>
        where id = #{id}
    </select>

    <insert id="insertFastGptChatReplaceWords" parameterType="FastGptChatReplaceWords" useGeneratedKeys="true" keyProperty="id">
        insert into fastgpt_chat_replace_words
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="type != null">type,</if>
            <if test="content != null">content,</if>
            <if test="changeCount != null">change_count,</if>
            <if test="status != null">status,</if>
            <if test="sort != null">sort,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="type != null">#{type},</if>
            <if test="content != null">#{content},</if>
            <if test="changeCount != null">#{changeCount},</if>
            <if test="status != null">#{status},</if>
            <if test="sort != null">#{sort},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateFastGptChatReplaceWords" parameterType="FastGptChatReplaceWords">
        update fastgpt_chat_replace_words
        <trim prefix="SET" suffixOverrides=",">
            <if test="type != null">type = #{type},</if>
            <if test="content != null">content = #{content},</if>
            <if test="changeCount != null">change_count = #{changeCount},</if>
            <if test="status != null">status = #{status},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFastGptChatReplaceWordsById" parameterType="Long">
        delete from fastgpt_chat_replace_words where id = #{id}
    </delete>

    <delete id="deleteFastGptChatReplaceWordsByIds" parameterType="String">
        delete from fastgpt_chat_replace_words where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
