<?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.github.wxiaoqi.security.admin.mapper.AppUserRelationMapper">


    <select id="selectByLeaderId" resultType="com.github.wxiaoqi.security.admin.entity.AppUserRelation">
        select `parent_id` as `parentId`,`user_id`as `userId`,`bind_time` as `bindTime` from `app_user_relation` where `parent_id`=#{leaderId} and `is_del`=0 order by `bind_time` DESC
    </select>

    <select id="countByParentId" resultType="Integer">
        select count(*)  from `app_user_relation` where
        `parent_id`=#{parentId} and `is_del`=0
         <if test="bindTime!='' and bindTime!=null and bindTime>0">
             and (is_forever=1 or bind_time>#{bindTime})
         </if>
    </select>

    <select id="selectByUserIds" resultType="com.github.wxiaoqi.security.admin.entity.AppUserRelation">
        select  `user_id`,`parent_id` from `app_user_relation` where  `is_del`=0 and `user_id` IN
        <foreach collection="userIds" item="userId" separator="," open="(" close=")">
           #{userId}
        </foreach>
    </select>
</mapper>