package com.ankaibei.workFlow.webadmin.ankaibei.mapper;

import com.ankaibei.workFlow.webadmin.ankaibei.entity.UserInfoEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

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

/**
 * @author
 * @version 1.0
 * @description:
 * @date 2022/9/5 14:20
 */
public interface UserInfoMapper extends JpaRepository<UserInfoEntity, String>, JpaSpecificationExecutor<UserInfoEntity> {


    @Query(value = "SELECT user.user_id userId,user.show_name userName FROM work_sys_user user WHERE deleted_flag =1 "
           , nativeQuery = true)
    List<Map<String, String>> getProUserAll();

    /**
     * 根据id查询用户信息
     *
     * @return 查询到的用户对象
     */
    @Query(value = "SELECT * FROM work_sys_user where user_id in (?1)"
            , countQuery = "SELECT count(1) FROM work_sys_user where user_id in (?1)", nativeQuery = true)
    List<UserInfoEntity> findAllByUserId(List<String> userIds);

    /**
     * 根据id查询用户信息
     *
     * @param userId
     * @return 查询到的用户对象
     */
    @Query(value = "SELECT * FROM work_sys_user where user_id = ?1"
            , countQuery = "SELECT count(1) FROM work_sys_user where user_id in ?1", nativeQuery = true)
    UserInfoEntity findByUserIdEquals(String userId);


    /**
     * 根据账号查询用户信息
     *
     * @param loginName   用户账号
     * @param deletedFlag 是否已删除
     * @return 查询到的用户对象
     */
    UserInfoEntity findByLoginNameEqualsAndDeletedFlagIs(String loginName, int deletedFlag);

    /**
     * 根据id查询用户信息
     *
     * @param userId      用户id
     * @param deletedFlag 是否已删除
     * @return 查询到的用户对象
     */
    UserInfoEntity findByUserIdEqualsAndDeletedFlagIs(String userId, int deletedFlag);

}
