<?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="room_id_" jdbcType="VARCHAR" property="roomId"/>
        <result column="user_id_" jdbcType="VARCHAR" 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>

    <insert id="insert" keyColumn="id_" keyProperty="id" useGeneratedKeys="true"
            parameterType="com.yonge.cooleshow.biz.dal.entity.ImNetworkRoomMember">
        INSERT INTO im_network_room_member(room_id_, user_id_, join_time_, role_, camera_flag_,
                                           mic_flag_, music_mode_flag_, hand_flag_,username_,avatar_)
        VALUES (#{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_),
        role_ = VALUES(role_)
    </insert>
    <select id="queryByRoomId" resultType="com.yonge.cooleshow.biz.dal.dto.ImNetworkRoomMemberResult">
        SELECT
        a.id_ as id,
        a.room_id_ as roomId,
        a.user_id_ as userId,
        a.username_ as userName,
        a.avatar_ as headUrl,
        unix_timestamp(a.join_time_) * 1000 as joinTime,
        a.role_ as role,
        a.camera_flag_ as camera,
        a.mic_flag_ as microphone,
        a.music_mode_flag_ as musicModeOn,
        a.hand_flag_ as handUpOn
        FROM im_network_room_member a
        WHERE a.room_id_ = #{roomId}
    </select>
</mapper>
