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

    <resultMap type="QwRoomMember" id="QwRoomMemberResult">
        <result property="id"    column="id"    />
        <result property="roomId"    column="room_id"    />
        <result property="userId"    column="user_id"    />
        <result property="admin"    column="admin"    />
        <result property="joinTime"    column="join_time"    />
        <result property="nickName"    column="nick_name"    />
        <result property="userName"    column="user_name"    />
        <result property="corpId"    column="corp_id"    />
        <result property="avatar"    column="avatar"    />
        <result property="sex"    column="sex"    />
        <result property="mobile"    column="mobile"    />
    </resultMap>

    <sql id="selectQwRoomMemberVo">
        select id, room_id, user_id, admin, join_time, nick_name, user_name, corp_id, avatar, sex, mobile from qw_room_member
    </sql>

    <select id="selectQwRoomMemberList" parameterType="QwRoomMember" resultMap="QwRoomMemberResult">
        <include refid="selectQwRoomMemberVo"/>
        <where>
            <if test="roomId != null "> and room_id = #{roomId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="admin != null "> and admin = #{admin}</if>
            <if test="joinTime != null "> and join_time = #{joinTime}</if>
            <if test="nickName != null  and nickName != ''"> and nick_name like concat('%', #{nickName}, '%')</if>
            <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
            <if test="corpId != null "> and corp_id = #{corpId}</if>
            <if test="avatar != null  and avatar != ''"> and avatar = #{avatar}</if>
            <if test="sex != null "> and sex = #{sex}</if>
            <if test="mobile != null  and mobile != ''"> and mobile = #{mobile}</if>
        </where>
    </select>

    <select id="selectQwRoomMemberById" parameterType="Long" resultMap="QwRoomMemberResult">
        <include refid="selectQwRoomMemberVo"/>
        where id = #{id}
    </select>

    <insert id="insertQwRoomMember" parameterType="QwRoomMember" useGeneratedKeys="true" keyProperty="id">
        insert into qw_room_member
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="roomId != null">room_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="admin != null">admin,</if>
            <if test="joinTime != null">join_time,</if>
            <if test="nickName != null">nick_name,</if>
            <if test="userName != null">user_name,</if>
            <if test="corpId != null">corp_id,</if>
            <if test="avatar != null">avatar,</if>
            <if test="sex != null">sex,</if>
            <if test="mobile != null">mobile,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="roomId != null">#{roomId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="admin != null">#{admin},</if>
            <if test="joinTime != null">#{joinTime},</if>
            <if test="nickName != null">#{nickName},</if>
            <if test="userName != null">#{userName},</if>
            <if test="corpId != null">#{corpId},</if>
            <if test="avatar != null">#{avatar},</if>
            <if test="sex != null">#{sex},</if>
            <if test="mobile != null">#{mobile},</if>
        </trim>
    </insert>

    <update id="updateQwRoomMember" parameterType="QwRoomMember">
        update qw_room_member
        <trim prefix="SET" suffixOverrides=",">
            <if test="roomId != null">room_id = #{roomId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="admin != null">admin = #{admin},</if>
            <if test="joinTime != null">join_time = #{joinTime},</if>
            <if test="nickName != null">nick_name = #{nickName},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="corpId != null">corp_id = #{corpId},</if>
            <if test="avatar != null">avatar = #{avatar},</if>
            <if test="sex != null">sex = #{sex},</if>
            <if test="mobile != null">mobile = #{mobile},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteQwRoomMemberById" parameterType="Long">
        delete from qw_room_member where id = #{id}
    </delete>

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