package com.YuyeTech.TPlat.game.gameInfo.repository;

import com.YuyeTech.TPlat.common.repository.CommonRepository;
import com.YuyeTech.TPlat.game.gameInfo.projo.GameInfo;
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author:slambb
 * @date:2020/1/10
 */

//extends JpaRepository<GameInfo,String> , JpaSpecificationExecutor<GameInfo>
@Repository
public interface GameInfoRepository extends CommonRepository<GameInfo,String> {
    /**
     * In查询，根据参数列表顺序返回对象顺序
     * @param gameIdList
     * @return
     */
    @Query(value = "select * from game_info where `game_id` in :gameIdList order by FIELD(`game_id`,:gameIdList)" , nativeQuery = true)
    List<GameInfo> GIRepFindByGameIdInOrderByField(List<String> gameIdList);

    /**
     * In查询，根据参数列表返回对象列表
     * @param gameIdList
     * @return
     */
    @Query(value = "select * from game_info where `game_id` in :gameIdList" , nativeQuery = true)
    List<GameInfo> GIRepFindByGameIdIn(List<String> gameIdList);

    /**
     * 获取游戏详情
     * @param gameId
     * @return
     */
    GameInfo findByGameId(String gameId);

    /**
     * 根据类目查找列表
     * @param categoryType
     * @param pageable
     * @return
     */
    List<GameInfo> findByGameType(Integer categoryType,Pageable pageable);

    /**
     * 根据类目查找列表
     * @param categoryType
     * @param pageable
     * @return
     */
    Page<GameInfo> findPageByGameType(Integer categoryType, Pageable pageable);

    Page<GameInfo> findAllByGameRankingShow(Integer rankingShow, Pageable pageable);

    /**
     * 根据游戏名进行模糊搜索
     * @param pageable
     * @param gameName
     * @return
     */
    @Query(value = "select b from GameInfo b where (b.gameName like %:gameName%)")
    Page<GameInfo> fuzzySearchByUsername(Pageable pageable, @Param("gameName") String gameName);
}
