package org.jebot.repository.jebot;

import org.jebot.models.jebot.BotUser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Component;

import javax.transaction.Transactional;

@Component
public interface BotUserRepository extends JpaRepository<BotUser, Long> {

    //通过用户名查询用户
    BotUser findByUserName(@Param("userName") String userName);

    @Modifying
    @Transactional
    @Query("UPDATE bot_user u SET u.userId = :userId WHERE u.userName = :userName")
    void updateUserIdByUserName(@Param("userId") Long userId, @Param("userName") String userName);

}
