<?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.ym.mec.biz.dal.dao.ImLiveBroadcastRoomDataDao">
    <resultMap id="BaseResultMap" type="com.ym.mec.biz.dal.entity.ImLiveBroadcastRoomData">
        <id column="id_" jdbcType="INTEGER" property="id"/>
        <result column="tenant_id_" jdbcType="INTEGER" property="tenantId"/>
        <result column="room_uid_" jdbcType="VARCHAR" property="roomUid"/>
        <result column="like_num_" jdbcType="INTEGER" property="likeNum"/>
        <result column="look_user_num_" jdbcType="INTEGER" property="lookUserNum"/>
        <result column="total_user_num_" jdbcType="INTEGER" property="totalUserNum"/>
        <result column="updated_time_" jdbcType="TIMESTAMP" property="updatedTime"/>
        <result column="live_time_" jdbcType="INTEGER" property="liveTime"/>
    </resultMap>

    <sql id="Base_Column_List">
        id_
        , tenant_id_, room_uid_, like_num_, look_user_num_, total_user_num_, updated_time_, live_time_
    </sql>

    <insert id="insertBatch" keyColumn="id_" keyProperty="id" useGeneratedKeys="true"
            parameterType="com.ym.mec.biz.dal.entity.ImLiveBroadcastRoomData">
        insert into im_live_broadcast_room_data(tenant_id_, room_uid_, like_num_, look_user_num_, total_user_num_,
        updated_time_, live_time_)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.tenantId}, #{entity.roomUid}, #{entity.likeNum}, #{entity.lookUserNum}, #{entity.totalUserNum},
            #{entity.updatedTime}, #{entity.liveTime})
        </foreach>
    </insert>

    <select id="queryByRoomUid" resultType="com.ym.mec.biz.dal.vo.ImLiveBroadcastRoomDetailVo">
        select a.room_uid_                 as roomUid,
               r.room_title_               as roomTitle,
               b.real_name_                AS speakerName,
               r.live_remark_              AS liveRemark,
               ifnull(a.total_user_num_, 0) AS totalLookNum,
               ifnull(a.like_num_, 0)      as totalLikeNum,
               ifnull(a.live_time_, 0)     as totalLiveTime,
               r.live_start_time_      as liveStartTime,
               r.live_end_time_      as liveEndTime,
               r.live_state_      as liveState
        from im_live_broadcast_room_data as a
                 left join im_live_broadcast_room AS r on a.room_uid_ = r.room_uid_
                 left join sys_user AS b on r.speaker_id_ = b.id_
        where a.room_uid_ = #{roomUid}
    </select>

</mapper>
