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

    <resultMap type="QwRoom" id="QwRoomResult">
        <result property="id"    column="id"    />
        <result property="roomId"    column="room_id"    />
        <result property="ownerId"    column="owner_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="roomType"    column="room_type"    />
        <result property="roomName"    column="room_name"    />
        <result property="notice"    column="notice"    />
        <result property="adminList"    column="admin_list"    />
        <result property="memberList"    column="member_list"    />
        <result property="homeUserId"    column="home_user_id"    />
    </resultMap>

    <sql id="selectQwRoomVo">
        select id, room_id, owner_id, create_time, room_type, room_name, notice, admin_list, member_list  from qw_room
    </sql>

    <select id="selectQwRoomList" parameterType="QwRoom" resultMap="QwRoomResult">
        <include refid="selectQwRoomVo"/>
        <where>
            <if test="roomId != null "> and room_id = #{roomId}</if>
            <if test="ownerId != null "> and owner_id = #{ownerId}</if>
            <if test="roomType != null "> and room_type = #{roomType}</if>
            <if test="roomName != null  and roomName != ''"> and room_name like concat('%', #{roomName}, '%')</if>
            <if test="notice != null  and notice != ''"> and notice = #{notice}</if>
            <if test="adminList != null  and adminList != ''"> and admin_list = #{adminList}</if>
            <if test="memberList != null  and memberList != ''"> and member_list = #{memberList}</if>
        </where>
    </select>

    <select id="selectQwRoomById" parameterType="Long" resultMap="QwRoomResult">
        <include refid="selectQwRoomVo"/>
        where id = #{id}
    </select>

    <insert id="insertQwRoom" parameterType="QwRoom">
        insert into qw_room
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="roomId != null">room_id,</if>
            <if test="ownerId != null">owner_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="roomType != null">room_type,</if>
            <if test="roomName != null">room_name,</if>
            <if test="notice != null">notice,</if>
            <if test="adminList != null">admin_list,</if>
            <if test="memberList != null">member_list,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="roomId != null">#{roomId},</if>
            <if test="ownerId != null">#{ownerId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="roomType != null">#{roomType},</if>
            <if test="roomName != null">#{roomName},</if>
            <if test="notice != null">#{notice},</if>
            <if test="adminList != null">#{adminList},</if>
            <if test="memberList != null">#{memberList},</if>
        </trim>
    </insert>

    <update id="updateQwRoom" parameterType="QwRoom">
        update qw_room
        <trim prefix="SET" suffixOverrides=",">
            <if test="ownerId != null">owner_id = #{ownerId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="roomType != null">room_type = #{roomType},</if>
            <if test="roomName != null">room_name = #{roomName},</if>
            <if test="notice != null">notice = #{notice},</if>
            <if test="adminList != null">admin_list = #{adminList},</if>
            <if test="memberList != null">member_list = #{memberList},</if>
        </trim>
        where room_id = #{roomId}
    </update>

    <delete id="deleteQwRoomById" parameterType="Long">
        delete from qw_room where id = #{id}
    </delete>

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