<?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.yonge.cooleshow.biz.dal.dao.ImNetworkRoomMemberDao">
    <resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.ImNetworkRoomMember">
        <id column="id_" jdbcType="INTEGER" property="id"/>
        <result column="course_schedule_id_" jdbcType="INTEGER" property="courseScheduleId"/>
        <result column="room_id_" jdbcType="VARCHAR" property="roomId"/>
        <result column="user_id_" jdbcType="INTEGER" property="userId"/>
        <result column="username_" jdbcType="VARCHAR" property="username"/>
        <result column="avatar_" jdbcType="VARCHAR" property="avatar"/>
        <result column="join_time_" jdbcType="TIMESTAMP" property="joinTime"/>
        <result column="role_" jdbcType="INTEGER" property="role"/>
        <result column="camera_flag_" jdbcType="BOOLEAN" property="cameraFlag"/>
        <result column="mic_flag_" jdbcType="BOOLEAN" property="micFlag"/>
        <result column="music_mode_flag_" jdbcType="BOOLEAN" property="musicModeFlag"/>
        <result column="hand_flag_" jdbcType="BOOLEAN" property="handFlag"/>
    </resultMap>

    <sql id="Base_Column_List">
        id_
        , course_schedule_id_, room_id_, user_id_, join_time_, role_,
        camera_flag_, mic_flag_, music_mode_flag_, hand_flag_,username_,avatar_
    </sql>

    <insert id="insertBatch" keyColumn="id_" keyProperty="id" useGeneratedKeys="true"
            parameterType="com.yonge.cooleshow.biz.dal.entity.ImNetworkRoomMember">
        insert into im_network_room_member(course_schedule_id_, room_id_, user_id_, join_time_, role_, camera_flag_,
        mic_flag_, music_mode_flag_, hand_flag_,username_,avatar_)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.courseScheduleId}, #{entity.roomId}, #{entity.userId}, #{entity.joinTime}, #{entity.role},
            #{entity.cameraFlag}, #{entity.micFlag}, #{entity.musicModeFlag}, #{entity.handFlag}, #{entity.username}, #{entity.avatar})
        </foreach>
    </insert>
    <insert id="insert" keyColumn="id_" keyProperty="id" useGeneratedKeys="true"
            parameterType="com.yonge.cooleshow.biz.dal.entity.ImNetworkRoomMember">
        INSERT INTO im_network_room_member(course_schedule_id_, room_id_, user_id_, join_time_, role_, camera_flag_,
                                           mic_flag_, music_mode_flag_, hand_flag_,username_,avatar_)
        VALUES (#{entity.courseScheduleId}, #{entity.roomId}, #{entity.userId},NOW(), #{entity.role},
                #{entity.cameraFlag}, #{entity.micFlag}, #{entity.musicModeFlag}, #{entity.handFlag}, #{entity.username}, #{entity.avatar})
        ON DUPLICATE KEY UPDATE
        room_id_ = VALUES(room_id_),
        user_id_ = VALUES(user_id_)
    </insert>
    <delete id="delByRidAndUid">
        DELETE FROM im_network_room_member WHERE room_id_ = #{roomId} AND user_id_ = #{userId}
    </delete>
    <select id="findByRidAndUid" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"/> FROM im_network_room_member
        WHERE room_id_ = #{roomId} AND user_id_ = #{userId} LIMIT 1
    </select>
    <select id="queryByRoomId" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"/> FROM im_network_room_member WHERE room_id_ = #{roomId}
    </select>
    <select id="countByRoomId" resultType="java.lang.Integer">
        SELECT COUNT(id_) FROM im_network_room_member WHERE room_id_ = #{roomId}
    </select>
    <select id="findByRoomAndRole" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"/> FROM im_network_room_member WHERE room_id_ = #{roomId} AND role_ = #{role}
    </select>

</mapper>
