<?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.qw.mapper.QwWorkUserMapper">

    <resultMap type="QwWorkUser" id="QwWorkUserResult">
        <result property="id"    column="id"    />
        <result property="linkId"    column="link_id"    />
        <result property="externalUserid"    column="external_userid"    />
        <result property="userid"    column="userid"    />
        <result property="chatStatus"    column="chat_status"    />
        <result property="state"    column="state"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectQwWorkUserVo">
        select id, link_id, external_userid, userid, chat_status, state, create_time, create_by, update_by, update_time, remark from qw_work_user
    </sql>

    <select id="selectQwWorkUserList" parameterType="QwWorkUser" resultMap="QwWorkUserResult">
        <include refid="selectQwWorkUserVo"/>
        <where>
            <if test="linkId != null "> and link_id = #{linkId}</if>
            <if test="externalUserid != null  and externalUserid != ''"> and external_userid = #{externalUserid}</if>
            <if test="userid != null  and userid != ''"> and userid = #{userid}</if>
            <if test="chatStatus != null  and chatStatus != ''"> and chat_status = #{chatStatus}</if>
            <if test="state != null  and state != ''"> and state = #{state}</if>
        </where>
    </select>

    <select id="selectQwWorkUserById" parameterType="Long" resultMap="QwWorkUserResult">
        <include refid="selectQwWorkUserVo"/>
        where id = #{id}
    </select>

    <insert id="insertQwWorkUser" parameterType="QwWorkUser" useGeneratedKeys="true" keyProperty="id">
        insert into qw_work_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="linkId != null">link_id,</if>
            <if test="externalUserid != null">external_userid,</if>
            <if test="userid != null">userid,</if>
            <if test="chatStatus != null">chat_status,</if>
            <if test="state != null">state,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="linkId != null">#{linkId},</if>
            <if test="externalUserid != null">#{externalUserid},</if>
            <if test="userid != null">#{userid},</if>
            <if test="chatStatus != null">#{chatStatus},</if>
            <if test="state != null">#{state},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateQwWorkUser" parameterType="QwWorkUser">
        update qw_work_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="linkId != null">link_id = #{linkId},</if>
            <if test="externalUserid != null">external_userid = #{externalUserid},</if>
            <if test="userid != null">userid = #{userid},</if>
            <if test="chatStatus != null">chat_status = #{chatStatus},</if>
            <if test="state != null">state = #{state},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQwWorkUserById" parameterType="Long">
        delete from qw_work_user where id = #{id}
    </delete>

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