<?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.generator.mapper.community.CommunityUserInfoMapper">
    <select id="selectUserBySearchValue" resultType="com.ruoyi.generator.vo.CommunityUserInfoVo">
        select
        b.id as id,
        a.nick_name as nickName,
        a.avatar as avatar,
        (select count(1) as fansCount from community_user_like c where c.like_user_id = a.user_id) as fansCount,
        (select count(1) as articleCount from community_article d where d.user_id = a.user_id) as articleCount
        from sys_user a
        left join community_user_info b on a.user_id = b.user_id
        <if test="searchValue != null and searchValue != ''">
            <where>
                a.nick_name like concat('%', #{searchValue}, '%')
                or b.user_id like concat('%', #{searchValue}, '%')
            </where>
        </if>

    </select>
    <select id="selectUsersByAccountOrName" resultType="com.ruoyi.generator.vo.CommunityUserInfoVo">
        select
        b.id as id,
        a.nick_name as nickName,
        a.avatar as avatar,
        (select count(1) as fansCount from community_user_like c where c.like_user_id = a.user_id) as fansCount,
        (select count(1) as articleCount from community_article d where d.user_id = a.user_id) as articleCount
        from sys_user a
        left join community_user_info b on a.user_id = b.user_id
        left join community_user_privacy c on a.user_id  = c.user_id
        <if test="searchValue != null and searchValue != ''">
            <where>
                IFNULL(c.is_accounts,0)= 0 and a.user_name like concat('%', #{searchValue}, '%')
            </where>
        </if>
        union all
        select
        b.id as id,
        a.nick_name as nickName,
        a.avatar as avatar,
        (select count(1) as fansCount from community_user_like c where c.like_user_id = a.user_id) as fansCount,
        (select count(1) as articleCount from community_article d where d.user_id = a.user_id) as articleCount
        from sys_user a
        left join community_user_info b on a.user_id = b.user_id
        left join community_user_privacy c on a.user_id  = c.user_id
        <if test="searchValue != null and searchValue != ''">
            <where>
                IFNULL(c.is_names,0)  = 0 and  a.nick_name like concat('%', #{searchValue}, '%')
            </where>
        </if>
    </select>
</mapper>
