<?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.FastGptUserMapper">
    
    <resultMap type="FastGptUser" id="FastGptUserResult">
        <result property="uid"    column="uid"    />
        <result property="name"    column="name"    />
        <result property="externalUserid"    column="external_userid"    />
        <result property="avatar"    column="avatar"    />
        <result property="unionid"    column="unionid"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectFastGptUserVo">
        select uid, name, external_userid, avatar, unionid, create_time from fastgpt_user
    </sql>

    <select id="selectFastGptUserList" parameterType="FastGptUser" resultMap="FastGptUserResult">
        <include refid="selectFastGptUserVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="externalUserid != null  and externalUserid != ''"> and external_userid = #{externalUserid}</if>
            <if test="avatar != null  and avatar != ''"> and avatar = #{avatar}</if>
            <if test="unionid != null  and unionid != ''"> and unionid = #{unionid}</if>
        </where>
    </select>
    
    <select id="selectFastGptUserByUid" parameterType="Long" resultMap="FastGptUserResult">
        <include refid="selectFastGptUserVo"/>
        where uid = #{uid}
    </select>
        
    <insert id="insertFastGptUser" parameterType="FastGptUser">
        insert into fastgpt_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="uid != null">uid,</if>
            <if test="name != null">name,</if>
            <if test="externalUserid != null">external_userid,</if>
            <if test="avatar != null">avatar,</if>
            <if test="unionid != null">unionid,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="uid != null">#{uid},</if>
            <if test="name != null">#{name},</if>
            <if test="externalUserid != null">#{externalUserid},</if>
            <if test="avatar != null">#{avatar},</if>
            <if test="unionid != null">#{unionid},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateFastGptUser" parameterType="FastGptUser">
        update fastgpt_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="externalUserid != null">external_userid = #{externalUserid},</if>
            <if test="avatar != null">avatar = #{avatar},</if>
            <if test="unionid != null">unionid = #{unionid},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where uid = #{uid}
    </update>

    <delete id="deleteFastGptUserByUid" parameterType="Long">
        delete from fastgpt_user where uid = #{uid}
    </delete>

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