package com.reyun.saas.mob.user.dao;

import com.reyun.saas.common.core.Mapper;
import com.reyun.saas.mob.user.domain.User;
import com.reyun.saas.mob.user.dto.user.UserDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface UserMapper extends Mapper<User> {
    /**
     * 根据用户名获取权限
     * @param username
     * @return
     */
    UserDTO getRolesByUsername(@Param("username") String username);


    @Select("SELECT id,oid FROM user WHERE id = #{userId}")
    User findOidById(@Param("userId") Long userId);

    /**
     * 查询角色的数量
     * @param rootParent 主账号id
     * @param roleCategory 角色
     * @param leaderParent 上级账号id 该参数为null则不被拼接到sql中
     * @return
     */
    Long findRoleCount(@Param("rootParent")Long rootParent,@Param("roleCategory")Integer roleCategory,@Param("leaderParent")Long leaderParent);


    /**
     * 根据主账号id查询子账户的状态对应的子账号数量
     * @param rootId 主账户id
     * @return
     */
    List<Map> findStatusCount(@Param("rootId") Long rootId);

    @Select("select id from user where root_parent = #{id} or id = #{id}")
    List<Long> selectBySuperUser(@Param("id") Long id);

    @Select("select id from user where leader_parent = #{id} or id = #{id}")
    List<Long> selectBySubManager(@Param("id")Long id);

    @Select(" SELECT status,count(id) as 'count' FROM user WHERE leader_parent = #{userId} and del_flag is false GROUP BY status")
    List<Map> findStatusCountByManager(@Param("userId") Long userId);
}
