<?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.ImLiveRoomBlackDao">
    <resultMap id="BaseResultMap" type="com.ym.mec.biz.dal.entity.ImLiveRoomBlack">
        <id column="id_" jdbcType="INTEGER" property="id"/>
        <result column="room_uid_" jdbcType="VARCHAR" property="roomUid"/>
        <result column="user_id_" jdbcType="INTEGER" property="userId"/>
        <result column="type_" jdbcType="INTEGER" property="type"/>
        <result column="create_by_" jdbcType="INTEGER" property="createBy"/>
        <result column="create_time_" jdbcType="TIMESTAMP" property="createTime"/>
    </resultMap>

    <sql id="Base_Column_List">
        id_
        , room_uid_, user_id_, type_, create_by_, create_time_
    </sql>

    <insert id="insertBatch" keyColumn="id_" keyProperty="id" useGeneratedKeys="true"
            parameterType="com.ym.mec.biz.dal.entity.ImLiveRoomBlack">
        insert into im_live_room_black(room_uid_, user_id_, type_, create_by_, create_time_)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.roomUid}, #{entity.userId}, #{entity.type}, #{entity.createBy}, #{entity.createTime})
        </foreach>
    </insert>

    <select id="queryStudent" parameterType="object" resultType="com.ym.mec.auth.api.entity.SysUser">
        select id_        as id,
        username_  as username,
        real_name_ as realName,
        phone_     as phone
        from sys_user
        where find_in_set('STUDENT', user_type_)
        and lock_flag_ = 0
        and del_flag_ = 0
        and tenant_id_ = 1
        and id_ not in (select user_id_  from im_live_room_black where room_uid_ = #{param.roomUid})
        <if test="param.tenantId != null ">
            and tenant_id_ = #{param.tenantId}
        </if>
        <if test="param.search != null ">
            and (
                 `id_` LIKE CONCAT('%', #{param.search},'%')
                  OR `username_` LIKE CONCAT('%', #{param.search},'%')
                 OR `phone_` LIKE CONCAT('%', #{param.search},'%')
               )
        </if>
    </select>

    <select id="queryBlackList"  parameterType="map" resultType="com.ym.mec.biz.dal.vo.ImLiveRoomBlackVo">
        select a.user_id_,
               b.username_,
               b.real_name_,
               b.phone_,
               a.create_time_
        from im_live_room_black as a
                 left join sys_user as b  on a.user_id_ = b.id_
        where a.type_ = 0
          and a.room_uid_ = #{param.roomUid}
        <if test="param.search != null ">
            and (
            a.`user_id_` LIKE CONCAT('%', #{param.search},'%')
            OR b.`username_` LIKE CONCAT('%', #{param.search},'%')
            OR b.`phone_` LIKE CONCAT('%', #{param.search},'%')
            )
        </if>
    </select>

</mapper>
