<?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.UnionUserMapper">
    <select id="pageAdmin" resultType="com.ruoyi.cai.dto.admin.vo.UnionUserAdminVo">
        select t1.*,t3.name as union_name,
               t2.age,t2.avatar,t2.usercode,t2.nickname,t2.mobile,t2.gender,t2.status,t2.is_anchor
        from cai_union_user t1
        left join cai_user t2 on t1.user_id = t2.id
        left join cai_union t3 on t1.union_id = t3.id
        <where>
            <if test="bo.unionId != null">
                and t1.union_id = #{bo.unionId}
            </if>
            <if test="bo.mobile != null and bo.mobile != ''">
                and t2.mobile = #{bo.mobile}
            </if>
            <if test="bo.usercode != null and bo.usercode != ''">
                and t2.usercode = #{bo.usercode}
            </if>
        </where>
        order by t1.create_time
    </select>
    <select id="countByUnionIds" resultType="com.ruoyi.cai.dto.admin.UnionCountDTO">
        select
            t1.union_id,
            count(t1.id) all_num,
            sum(if(t2.id,1,0)) anchor_num
        from cai_union_user t1
        left join cai_user t2 on t1.user_id = t2.id and t2.is_anchor = 1
        where t1.union_id in
        <foreach collection="unionIds" item="value" open="(" close=")" separator=",">
            #{value}
        </foreach>
        group by t1.union_id;
    </select>


</mapper>
