<?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.QwUserMapper">

    <resultMap type="QwUser" id="QwUserResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="avatar"    column="avatar"    />
        <result property="corpId"    column="corp_id"    />
        <result property="corpName"    column="corp_name"    />
        <result property="nickName"    column="nick_name"    />
        <result property="seq"    column="seq"    />
        <result property="roomSeq"    column="room_seq"    />
        <result property="innerSeq"    column="inner_seq"    />
        <result property="deviceId"    column="device_id"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectQwUserVo">
        select user_id, avatar, corp_id, corp_name, nick_name, device_id,create_time,seq,room_seq,inner_seq  from qw_user
    </sql>

    <select id="selectQwUserList" parameterType="QwUser" resultMap="QwUserResult">
        <include refid="selectQwUserVo"/>
        <where>
            <if test="avatar != null  and avatar != ''"> and avatar = #{avatar}</if>
            <if test="corpId != null "> and corp_id = #{corpId}</if>
            <if test="seq != null "> and seq = #{seq}</if>
            <if test="corpName != null  and corpName != ''"> and corp_name like concat('%', #{corpName}, '%')</if>
            <if test="nickName != null  and nickName != ''"> and nick_name like concat('%', #{nickName}, '%')</if>
            <if test="deviceId != null "> and device_id = #{deviceId}</if>
        </where>
    </select>

    <select id="selectQwUserById" parameterType="Long" resultMap="QwUserResult">
        <include refid="selectQwUserVo"/>
        where user_id = #{userId}
    </select>

    <insert id="insertQwUser" parameterType="QwUser">
        insert into qw_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="avatar != null">avatar,</if>
            <if test="corpId != null">corp_id,</if>
            <if test="corpName != null">corp_name,</if>
            <if test="nickName != null">nick_name,</if>
            <if test="seq != null">seq,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="roomSeq != null">room_seq,</if>
            <if test="innerSeq != null">inner_seq,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="avatar != null">#{avatar},</if>
            <if test="corpId != null">#{corpId},</if>
            <if test="corpName != null">#{corpName},</if>
            <if test="nickName != null">#{nickName},</if>
            <if test="seq != null">#{seq},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="roomSeq != null">#{roomSeq},</if>
            <if test="innerSeq != null">#{innerSeq},</if>
        </trim>
    </insert>

    <update id="updateQwUser" parameterType="QwUser">
        update qw_user
        <trim prefix="SET" suffixOverrides=",">
            <if test="avatar != null">avatar = #{avatar},</if>
            <if test="corpId != null">corp_id = #{corpId},</if>
            <if test="seq != null">seq = #{seq},</if>
            <if test="roomSeq != null">room_seq = #{roomSeq},</if>
            <if test="innerSeq != null">inner_seq = #{innerSeq},</if>
            <if test="corpName != null">corp_name = #{corpName},</if>
            <if test="nickName != null">nick_name = #{nickName},</if>
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where user_id = #{userId}
    </update>

    <delete id="deleteQwUserById" parameterType="Long">
        delete from qw_user where user_id = #{userId}
    </delete>

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