package com.sysu.admin.support.system.user;

import com.xiesx.fastboot.core.jpa.JpaPlusRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;

public interface UserRepository extends JpaPlusRepository<User, Long> {

    @Transactional
    @Modifying
    @Query(value = "update sys_user set is_enable=?1 where id=?2", nativeQuery = true)
    int enable(Integer isEnable, Long userId);

    User findByUsername(String username);


    User findFirstByOrganIdOrderByCreateDateAsc(Long organId);

    /**
     * 查重复username
     * @param username
     * @param id
     * @return
     */
    User findFirstByUsernameAndIdNot(String username, Long id);

    /**
     * @param openId
     * @return
     */
    User findFirstByOpenId(String openId);

    @Query(value = "select * from sys_user where id = 75", nativeQuery = true)
    User findTestUser();
}
