<?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="org.springblade.modules.platform.mapper.UserRecomMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="userRecomResultMap" type="org.springblade.modules.platform.entity.UserRecom">
        <id column="id" property="id"/>
        <result column="user_id" property="userId"/>
        <result column="recom_id" property="recomId"/>
        <result column="recom_code" property="recomCode"/>
        <result column="create_time" property="createTime"/>
    </resultMap>

    <!-- 查询团队和直推 -->
    <resultMap id="userRecomVOResultMap" type="org.springblade.modules.platform.vo.UserRecomVO">
        <id column="id" property="id"/>
        <result column="user_id" property="userId"/>
        <result column="recom_id" property="recomId"/>
        <result column="recom_code" property="recomCode"/>
        <result column="avatar" property="avatar"/>
        <result column="state" property="state"/>
        <result column="status" property="status"/>
        <result column="create_time" property="createTime"/>
    </resultMap>


    <select id="selectUserRecomPage" resultMap="userRecomResultMap">
        select * from t_user_recom where is_deleted = 0
    </select>

    <select id="selectUserRecomVoPage" resultMap="userRecomVOResultMap">
        SELECT
        a.user_id,
        a.state,
        u.avatar,
        u.`code`,
        u.`name`,
        r.create_time
        FROM
        blade_user_app a
        RIGHT JOIN blade_user u ON a.user_id = u.id
        RIGHT JOIN t_user_recom r on a.user_id = r.user_id
        WHERE
        u.is_deleted = 0
        <if test="parentId!=null and parentId != ''">
            and a.parent_id = #{parentId}
        </if>
        <if test="parentPath!=null and parentPath != ''">
            and a.parent_path LIKE concat(concat('%', #{parentPath}),'%') and a.parent_id != #{parentId}
        </if>
    </select>

</mapper>
