<?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.ics.admin.mapper.meeting.RoomItemByRoomMapper">
    
    <resultMap type="com.ics.admin.domain.meeting.RoomItemByRoom" id="RoomItemByRoomResult">
        <result property="roomContentId"    column="room_content_id"    />
        <result property="itemId"    column="item_id"    />
        <result property="num"    column="num"    />
        <result property="createTime"    column="create_time"    />
        <result property="id"    column="id"    />
    </resultMap>

    <sql id="selectRoomItemByRoomVo">
        SELECT room_content_id, item_id, num, create_time, id FROM tb_room_item_by_room
    </sql>

    <select id="selectRoomItemByRoomList" parameterType="RoomItemByRoom" resultMap="RoomItemByRoomResult">
        <include refid="selectRoomItemByRoomVo"/>
        <where>  
        </where>
    </select>
    
    <select id="selectRoomItemByRoomById" parameterType="Long" resultMap="RoomItemByRoomResult">
        <include refid="selectRoomItemByRoomVo"/>
        WHERE id = #{id}
    </select>
    <select id="selectRoomContent" parameterType="RoomItemByRoom" resultMap="RoomItemByRoomResult">
        SELECT
            room_content_id
        FROM tb_room_item_by_room
        WHERE item_id IN
        <foreach item="collect" collection="list" separator="," open="(" close=")" index="">
         #{collect}
         </foreach>

        GROUP BY room_content_id HAVING(COUNT(*)) = #{size}
    </select>

    <insert id="insertRoomItemByRoom" parameterType="RoomItemByRoom" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO tb_room_item_by_room
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="roomContentId != null ">room_content_id,</if>
            <if test="itemId != null ">item_id,</if>
            <if test="num != null ">num,</if>
            <if test="createTime != null ">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="roomContentId != null ">#{roomContentId},</if>
            <if test="itemId != null ">#{itemId},</if>
            <if test="num != null ">#{num},</if>
            <if test="createTime != null ">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateRoomItemByRoom" parameterType="RoomItemByRoom">
        UPDATE tb_room_item_by_room
        <trim prefix="SET" suffixOverrides=",">
            <if test="roomContentId != null ">room_content_id = #{roomContentId},</if>
            <if test="itemId != null ">item_id = #{itemId},</if>
            <if test="num != null ">num = #{num},</if>
            <if test="createTime != null ">create_time = #{createTime},</if>
        </trim>
        WHERE id = #{id}
    </update>

    <delete id="deleteRoomItemByRoomById" parameterType="Long">
        DELETE FROM tb_room_item_by_room WHERE id = #{id}
    </delete>

    <delete id="deleteRoomItemByRoomByIds" parameterType="String">
        DELETE FROM tb_room_item_by_room where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>


</mapper>