package cn.palmte.work.model;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;


public interface AdminRepository extends JpaRepository<Admin, Integer> {
    @Query("from Admin where isDeleted=0 AND userName=?1")
    Admin getAdminByUsername(String username);

    @Query("from Admin where isDeleted=0 AND enabled=1 AND userName=?1")
    List<Admin> getAdminByUsernameList(String username);



    @Query("from Admin where isDeleted=0 AND userName=?1")
    List<Admin> getAdminByUsernameListNoEnabled(String username);

    @Query("from Admin where isDeleted=0 AND realName=?1")
    Admin getAdminByRealName(String realName);

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @Transactional
    @Query("from Admin where isDeleted=0 AND id=?1")
    Admin getAdminById(int id);

    @Query("from Admin where isDeleted=0 AND telephone=?1")
    Admin findByTelephone(String phone);

    @Query("from Admin where isDeleted=0 AND empCode=?1")
    Admin findByEmpCode(String empCode);


    /**
     * 查询所有未删除启用的账号
     * @return
     */
    @Query("from Admin where isDeleted=0 AND enabled=1")
    List<Admin> getAllEnable();

}
