package cn.ysk.cashier.repository.shop;

import cn.ysk.cashier.pojo.shop.TbPlussShopStaff;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/**
* @website https://eladmin.vip
* @author lyf
* @date 2024-03-01
**/
public interface TbPlussShopStaffRepository extends JpaRepository<TbPlussShopStaff, Integer>, JpaSpecificationExecutor<TbPlussShopStaff> {

    /**
     * 修改密码
     * @param account 用户名
     * @param password 密码
     * @param lastPasswordResetTime 更新时间
     * @param lastPasswordResetTime /
     */
    @Modifying
//    @Query(value = "update tb_pluss_shop_staff set password = ?2 , updated_at = ?3 where account = ?1",nativeQuery = true)
    @Query("update TbPlussShopStaff set password = :password , updatedAt = :lastPasswordResetTime where account = :account")
    void updatePass(String account, String password, Long lastPasswordResetTime);

    @Modifying
    @Query("update TbPlussShopStaff set password = :password , updatedAt = :lastPasswordResetTime where account = :account and shopId=:shopId")
    void updatePassAndShopId(String account, String shopId, String password, Long lastPasswordResetTime);

    @Query("select staff from TbPlussShopStaff as staff  where staff.account = :account")
    TbPlussShopStaff queryByAccount(String account);

    @Query("select staff from TbPlussShopStaff as staff  where staff.account = :account and staff.shopId=:shopId")
    TbPlussShopStaff queryByAccount(String account,String shopId);

    @Modifying
    @Query("update TbPlussShopStaff set name=:name where shopId = :shopId and type='master'")
    void updateNameById(String name, String shopId);
}