<?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.ruoyi.cai.mapper.UserMapper">

    <select id="pageAdmin" resultType="com.ruoyi.cai.dto.admin.vo.UserAdminVo">
        select t1.*,t2.last_login_ip,t2.last_login_time,t2.reg_ip,t2.reg_time
        from cai_user t1
        left join cai_user_info t2 on t1.id = t2.user_id
        <where>
            <if test="query.isAnchor != null">
                and t1.is_anchor = #{query.isAnchor}
            </if>
            <if test="query.nickname != null and query.nickname != ''">
                and t1.nickname like concat('%',#{query.nickname},'%')
            </if>
            <if test="query.mobile != null and query.mobile != ''">
                and t1.mobile = #{query.mobile}
            </if>
            <if test="query.usercode != null and query.usercode != ''">
                and t1.usercode = #{query.usercode}
            </if>
            <if test="query.gender != null">
                and t1.gender  = #{query.gender}
            </if>
            <if test="query.city != null">
                and t1.city  = #{query.city}
            </if>
        </where>
        order by t2.last_login_time desc
    </select>
    <select id="pageApp" resultType="com.ruoyi.cai.dto.app.vo.user.UserListVo">
        select t1.avatar,t1.id as user_id,t1.gender,t1.city,t1.city_id,t1.nickname,t1.usercode,t1.age,t2.last_live_time as bind_time
        from cai_user t1
        join cai_user_online t2 on t1.id = t2.user_id
        where t1.status = 0
        <if test="query.nickname != null and query.nickname != ''">
            and t1.nickname like concat('%',#{query.nickname},'%')
        </if>
        <if test="query.usercode != null and query.usercode != ''">
            and t1.usercode = #{query.usercode}
        </if>
        <if test="query.gender != null">
            and t1.gender = #{query.gender}
        </if>
        order by t2.last_live_time desc
    </select>
    <select id="greetPageApp" resultType="com.ruoyi.cai.dto.app.vo.user.UserListVo">
        select t1.avatar,t1.id as user_id,t1.gender,t1.city,t1.city_id,t1.nickname,t1.usercode,t1.age,t2.last_live_time as bind_time
        from cai_user t1
        join cai_user_online t2 on t1.id = t2.user_id
        where t1.status = 0
        <if test="query.cityId != null and query.cityId != ''">
            and t1.city_id = #{query.cityId}
        </if>
        order by t2.last_live_time desc
    </select>
    <select id="getGreetNumId" resultType="java.lang.Long">
        select t1.id
        from cai_user t1
        where t1.status = 0 and t1.gender = 2 and t1.no_greet = 0
              and not exists(select 1 from cai_user_blacklist p1 where t1.id = p1.user_id)
              and not exists(select 1 from cai_user_blacklist p2 where t1.id = p2.black_uid)
        order by t1.update_time desc
        limit 20
    </select>


</mapper>
