package com.izouma.nineth.repo.rewardpoints;

import com.izouma.nineth.domain.UserIntegral;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.Optional;

public interface UserIntegralRepo extends JpaRepository<UserIntegral, Long>, JpaSpecificationExecutor<UserIntegral> {

    /**
     * 获取用户积分
     * @param userId
     * @return
     */
    Optional<UserIntegral> findByUserId(Long userId);

    /**
     * 获取可用积分
     * @param userId
     * @return
     */
    @Query("select ui.availableIntegral from UserIntegral ui where ui.userId = ?1 ")
    Long getAvailableIntegral(Long userId);

}
