package com.tenlionsoft.baselib.core.db.daos;

import com.tenlionsoft.baselib.core.beans.UserDatabaseBean;

import java.util.List;

import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Query;
import io.reactivex.Flowable;

/**
 * 作者: adam
 * 日期: 2021/10/28 - 9:16 上午
 * 邮箱: itgaojian@163.com
 * 描述: 用户表
 */
@Dao
public interface UserDao {


    @Insert
    void insertAll(List<UserDatabaseBean> beans);

    @Query("DELETE FROM db_user")
    void deleteAll();

    @Query("SELECT * FROM db_user")
    List<UserDatabaseBean> getAllUser();

    /**
     * 除了自己其他所有联系人
     *
     * @param id
     * @return
     */
    @Query("SELECT * FROM db_user WHERE userId != (:id)")
    List<UserDatabaseBean> getExceptMineUsers(String id);

    /**
     * 获取联系人数量
     */
    @Query("SELECT COUNT(*) FROM db_user")
    int getCount();

    /**
     * 分页获取联系人
     */
    @Query("SELECT * FROM db_user WHERE userId != (:id) LIMIT (:page),(:rows)")
    List<UserDatabaseBean> getExceptMineUserByPage(String id, int page, int rows);

    /**
     * 在一定范围内的user
     *
     * @param ids
     * @return
     */
    @Query("SELECT * FROM db_user WHERE userId in (:ids)")
    List<UserDatabaseBean> getUsersByIds(String ids);

    /**
     * 根据UserId获取详情
     */
    @Query("SELECT * FROM db_user WHERE userId=(:id)")
    UserDatabaseBean getUserByUserId(String id);

    /**
     * 获取全部常用联系人
     */
    @Query("SELECT * FROM db_user INNER JOIN db_often_contact ON db_often_contact.userId= db_user.userId")
    List<UserDatabaseBean> getAllOftenContact();

    /**
     * Rxjava方式获取全部常用联系人
     */
    @Query("SELECT * FROM db_user INNER JOIN db_often_contact ON db_often_contact.userId= db_user.userId")
    Flowable<List<UserDatabaseBean>> getRxAllOftenContact();

    /**
     * 根据部门Id获取部门下所有人员
     */
    @Query("SELECT * FROM db_user WHERE departmentId = (:deptId)")
    List<UserDatabaseBean> getUsersByDeptId(String deptId);

    @Query("SELECT * FROM db_user WHERE userName LIKE (:name)")
    List<UserDatabaseBean> getUsersLikeName(String name);


    @Query("SELECT * FROM db_user WHERE userName LIKE  '%' || :name || '%'")
    List<UserDatabaseBean> getUsersLikeNameSync(String name);
}
