<?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.FastGptChatKeywordMapper">
    
    <resultMap type="FastGptChatKeyword" id="FastGptChatKeywordResult">
        <result property="keywordId"    column="keyword_id"    />
        <result property="keyword"    column="keyword"    />
        <result property="type"    column="type"    />
        <result property="content"    column="content"    />
        <result property="companyId"    column="company_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="roles"    column="roles"    />
    </resultMap>

    <sql id="selectFastGptChatKeywordVo">
        select keyword_id, keyword, type, content, company_id, create_time, update_time, roles from fastgpt_chat_keyword
    </sql>

    <select id="selectFastGptChatKeywordList" parameterType="FastGptChatKeyword" resultMap="FastGptChatKeywordResult">
        <include refid="selectFastGptChatKeywordVo"/>
        <where>  
            <if test="keyword != null  and keyword != ''"> and keyword = #{keyword}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="roles != null  and roles != ''"> and roles = #{roles}</if>
        </where>
    </select>
    
    <select id="selectFastGptChatKeywordByKeywordId" parameterType="Long" resultMap="FastGptChatKeywordResult">
        <include refid="selectFastGptChatKeywordVo"/>
        where keyword_id = #{keywordId}
    </select>
        
    <insert id="insertFastGptChatKeyword" parameterType="FastGptChatKeyword" useGeneratedKeys="true" keyProperty="keywordId">
        insert into fastgpt_chat_keyword
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="keyword != null">keyword,</if>
            <if test="type != null">type,</if>
            <if test="content != null">content,</if>
            <if test="companyId != null">company_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="roles != null">roles,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="keyword != null">#{keyword},</if>
            <if test="type != null">#{type},</if>
            <if test="content != null">#{content},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="roles != null">#{roles},</if>
         </trim>
    </insert>

    <update id="updateFastGptChatKeyword" parameterType="FastGptChatKeyword">
        update fastgpt_chat_keyword
        <trim prefix="SET" suffixOverrides=",">
            <if test="keyword != null">keyword = #{keyword},</if>
            <if test="type != null">type = #{type},</if>
            <if test="content != null">content = #{content},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="roles != null">roles = #{roles},</if>
        </trim>
        where keyword_id = #{keywordId}
    </update>

    <delete id="deleteFastGptChatKeywordByKeywordId" parameterType="Long">
        delete from fastgpt_chat_keyword where keyword_id = #{keywordId}
    </delete>

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