package com.ssj.dao.sys.game.dao;

import com.ssj.bean.sys.game.domain.Ranklist;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

/**
 * @author Mount Liu
 * @date 2018/1/22
 */
@Repository
public interface RanklistDao extends JpaRepository<Ranklist, String> {

    /**
     * 分页查询
     *
     * @param specification
     * @param page
     * @return
     */
    Page<Ranklist> findAll(Specification<Ranklist> specification, Pageable page);

    /**
     * 通过userId查找
     *
     * @param userId
     * @return
     */
    Ranklist findByUserId(String userId);

    @Query(nativeQuery = true, value = "update tb_game_record set score =?1 where user_id = ?2 ")
    @Modifying
    void updateScore(double score, String userId);
}
